wip fix: use app id for grouping window lists & replace top level if it already exists & show separator for active and saved app lists
This commit is contained in:
parent
e7f9e95440
commit
223c7855cf
5 changed files with 38 additions and 30 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -2141,7 +2141,7 @@ checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
|
|||
[[package]]
|
||||
name = "relm4"
|
||||
version = "0.5.0-beta.1"
|
||||
source = "git+https://github.com/relm4/relm4?branch=next#746d244004e23764294b23519f6f8be1002c1ceb"
|
||||
source = "git+https://github.com/Relm4/Relm4.git?branch=next#746d244004e23764294b23519f6f8be1002c1ceb"
|
||||
dependencies = [
|
||||
"async-broadcast",
|
||||
"async-oneshot",
|
||||
|
|
@ -2158,7 +2158,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "relm4-macros"
|
||||
version = "0.5.0-beta.1"
|
||||
source = "git+https://github.com/relm4/relm4?branch=next#746d244004e23764294b23519f6f8be1002c1ceb"
|
||||
source = "git+https://github.com/Relm4/Relm4.git?branch=next#746d244004e23764294b23519f6f8be1002c1ceb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use crate::dock_list::DockListType;
|
|||
use crate::utils::AppListEvent;
|
||||
use cascade::cascade;
|
||||
use cosmic_panel_config::{PanelAnchor, CosmicPanelConfig};
|
||||
use gtk4::Separator;
|
||||
use gtk4::prelude::*;
|
||||
use gtk4::subclass::prelude::*;
|
||||
use gtk4::Orientation;
|
||||
|
|
@ -38,21 +39,21 @@ impl AppsContainer {
|
|||
let saved_app_list_view = DockList::new(DockListType::Saved, config.clone());
|
||||
self_.append(&saved_app_list_view);
|
||||
|
||||
// let separator_container = cascade! {
|
||||
// gtk4::Box::new(Orientation::Vertical, 0);
|
||||
// ..set_margin_top(8);
|
||||
// ..set_margin_bottom(8);
|
||||
// ..set_vexpand(true);
|
||||
// };
|
||||
// self_.append(&separator_container);
|
||||
// let separator = cascade! {
|
||||
// Separator::new(Orientation::Vertical);
|
||||
// ..set_margin_start(8);
|
||||
// ..set_margin_end(8);
|
||||
// ..set_vexpand(true);
|
||||
// ..add_css_class("dock_separator");
|
||||
// };
|
||||
// separator_container.append(&separator);
|
||||
let separator_container = cascade! {
|
||||
gtk4::Box::new(Orientation::Vertical, 0);
|
||||
..set_margin_top(8);
|
||||
..set_margin_bottom(8);
|
||||
..set_vexpand(true);
|
||||
};
|
||||
self_.append(&separator_container);
|
||||
let separator = cascade! {
|
||||
Separator::new(Orientation::Vertical);
|
||||
..set_margin_start(8);
|
||||
..set_margin_end(8);
|
||||
..set_vexpand(true);
|
||||
..add_css_class("dock_separator");
|
||||
};
|
||||
separator_container.append(&separator);
|
||||
let active_app_list_view = DockList::new(DockListType::Active, config.clone());
|
||||
self_.append(&active_app_list_view);
|
||||
// self_.connect_orientation_notify(glib::clone!(@weak separator => move |c| {
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ impl DockList {
|
|||
}
|
||||
|
||||
fn restore_data(&self) {
|
||||
// TODO use IDs instead of names
|
||||
if let Ok(file) = File::open(data_path()) {
|
||||
if let Ok(data) = serde_json::from_reader::<_, Vec<String>>(file) {
|
||||
// dbg!(&data);
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ impl DockObject {
|
|||
imp.saved.replace(is_saved);
|
||||
}
|
||||
|
||||
pub fn from_search_results(results: BoxedWindowList) -> Self {
|
||||
pub fn from_window_list(results: BoxedWindowList) -> Self {
|
||||
let appinfo = if let Some(first) = results.0.get(0) {
|
||||
xdg::BaseDirectories::new()
|
||||
.expect("could not access XDG Base directory")
|
||||
|
|
@ -95,7 +95,7 @@ impl DockObject {
|
|||
if let Some(path) = path.to_str() {
|
||||
if let Some(app_info) = gio::DesktopAppInfo::new(path) {
|
||||
if app_info.should_show()
|
||||
&& first.name.as_str() == app_info.name().as_str()
|
||||
&& Some(&first.app_id) == app_info.id().map(|s| s.to_string()).as_ref()
|
||||
{
|
||||
return Some(app_info);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,11 +125,11 @@ fn main() {
|
|||
let stack_active = cached_results.iter().fold(
|
||||
BTreeMap::new(),
|
||||
|mut acc: BTreeMap<String, BoxedWindowList>, elem: &Toplevel| {
|
||||
if let Some(v) = acc.get_mut(&elem.name) {
|
||||
if let Some(v) = acc.get_mut(&elem.app_id) {
|
||||
v.0.push(elem.clone());
|
||||
} else {
|
||||
acc.insert(
|
||||
elem.name.clone(),
|
||||
elem.app_id.clone(),
|
||||
BoxedWindowList(vec![elem.clone()]),
|
||||
);
|
||||
}
|
||||
|
|
@ -152,7 +152,7 @@ fn main() {
|
|||
if let Some((i, _s)) = stack_active
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_i, s)| s.0[0].name == cur_app_info.name())
|
||||
.find(|(_i, s)| Some(&s.0[0].app_id) == cur_app_info.id().map(|s| s.to_string()).as_ref())
|
||||
{
|
||||
// println!(
|
||||
// "found active saved app {} at {}",
|
||||
|
|
@ -163,7 +163,7 @@ fn main() {
|
|||
saved_app_model.items_changed(saved_i, 0, 0);
|
||||
} else if cached_results
|
||||
.iter()
|
||||
.any(|s| s.name == cur_app_info.name())
|
||||
.any(|s| Some(&s.app_id) == cur_app_info.id().map(|s| s.to_string()).as_ref())
|
||||
{
|
||||
dock_obj.set_property(
|
||||
"active",
|
||||
|
|
@ -180,7 +180,7 @@ fn main() {
|
|||
let model_len = active_app_model.n_items();
|
||||
let new_results: Vec<glib::Object> = stack_active
|
||||
.into_iter()
|
||||
.map(|v| DockObject::from_search_results(v).upcast())
|
||||
.map(|v| DockObject::from_window_list(v).upcast())
|
||||
.collect();
|
||||
active_app_model.splice(0, model_len, &new_results[..]);
|
||||
true
|
||||
|
|
@ -197,7 +197,11 @@ fn main() {
|
|||
}
|
||||
AppListEvent::Add(top_level) => {
|
||||
// sort to make comparison with cache easier
|
||||
cached_results.push(top_level);
|
||||
if let Some(i) = cached_results.iter().position(|t| t.toplevel_handle == top_level.toplevel_handle) {
|
||||
cached_results[i] = top_level;
|
||||
} else {
|
||||
cached_results.push(top_level);
|
||||
}
|
||||
true
|
||||
}
|
||||
};
|
||||
|
|
@ -207,11 +211,11 @@ fn main() {
|
|||
let stack_active = cached_results.iter().fold(
|
||||
BTreeMap::new(),
|
||||
|mut acc: BTreeMap<String, BoxedWindowList>, elem| {
|
||||
if let Some(v) = acc.get_mut(&elem.name) {
|
||||
if let Some(v) = acc.get_mut(&elem.app_id) {
|
||||
v.0.push(elem.clone());
|
||||
} else {
|
||||
acc.insert(
|
||||
elem.name.clone(),
|
||||
elem.app_id.clone(),
|
||||
BoxedWindowList(vec![elem.clone()]),
|
||||
);
|
||||
}
|
||||
|
|
@ -234,7 +238,7 @@ fn main() {
|
|||
if let Some((i, _s)) = stack_active
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_i, s)| s.0[0].app_id == cur_app_info.name())
|
||||
.find(|(_i, s)| Some(&s.0[0].app_id) == cur_app_info.id().map(|s| s.to_string()).as_ref())
|
||||
{
|
||||
// println!("found active saved app {} at {}", s.0[0].name, i);
|
||||
let active = stack_active.remove(i);
|
||||
|
|
@ -242,7 +246,7 @@ fn main() {
|
|||
saved_app_model.items_changed(saved_i, 0, 0);
|
||||
} else if cached_results
|
||||
.iter()
|
||||
.any(|s| s.app_id == cur_app_info.name())
|
||||
.any(|s| Some(&s.app_id) == cur_app_info.id().map(|s| s.to_string()).as_ref())
|
||||
{
|
||||
dock_obj.set_property(
|
||||
"active",
|
||||
|
|
@ -259,8 +263,10 @@ fn main() {
|
|||
let model_len = active_app_model.n_items();
|
||||
let new_results: Vec<glib::Object> = stack_active
|
||||
.into_iter()
|
||||
.map(|v| DockObject::from_search_results(v).upcast())
|
||||
.map(|v| DockObject::from_window_list(v).upcast())
|
||||
.collect();
|
||||
dbg!(&new_results);
|
||||
|
||||
active_app_model.splice(0, model_len, &new_results[..]);
|
||||
}
|
||||
glib::prelude::Continue(true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue