fix: use app container created by window & only create dock object from window list if a matching app info is found
This commit is contained in:
parent
adc02df64f
commit
83fc8893ec
5 changed files with 18 additions and 20 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -2141,7 +2141,7 @@ checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "relm4"
|
name = "relm4"
|
||||||
version = "0.5.0-beta.1"
|
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 = [
|
dependencies = [
|
||||||
"async-broadcast",
|
"async-broadcast",
|
||||||
"async-oneshot",
|
"async-oneshot",
|
||||||
|
|
@ -2158,7 +2158,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "relm4-macros"
|
name = "relm4-macros"
|
||||||
version = "0.5.0-beta.1"
|
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 = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ use gtk4::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
subclass::prelude::*,
|
subclass::prelude::*,
|
||||||
};
|
};
|
||||||
use tokio::sync::mpsc;
|
|
||||||
|
|
||||||
mod imp;
|
mod imp;
|
||||||
|
|
||||||
|
|
@ -43,6 +42,10 @@ impl CosmicAppListWindow {
|
||||||
self_
|
self_
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn apps_container(&self) -> &AppsContainer {
|
||||||
|
imp::CosmicAppListWindow::from_instance(&self).inner.get().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
fn setup_shortcuts(&self) {
|
fn setup_shortcuts(&self) {
|
||||||
let window = self.clone().upcast::<gtk4::Window>();
|
let window = self.clone().upcast::<gtk4::Window>();
|
||||||
let action_quit = gio::SimpleAction::new("quit", None);
|
let action_quit = gio::SimpleAction::new("quit", None);
|
||||||
|
|
|
||||||
|
|
@ -78,9 +78,9 @@ impl DockObject {
|
||||||
imp.saved.replace(is_saved);
|
imp.saved.replace(is_saved);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_window_list(results: BoxedWindowList) -> Self {
|
pub fn from_window_list(results: BoxedWindowList) -> Option<Self> {
|
||||||
let appinfo = if let Some(first) = results.0.get(0) {
|
if let Some(first) = results.0.get(0) {
|
||||||
xdg::BaseDirectories::new()
|
return xdg::BaseDirectories::new()
|
||||||
.expect("could not access XDG Base directory")
|
.expect("could not access XDG Base directory")
|
||||||
.get_data_dirs()
|
.get_data_dirs()
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
|
|
@ -100,7 +100,8 @@ impl DockObject {
|
||||||
.file_stem()
|
.file_stem()
|
||||||
.and_then(|s| s.to_str().map(|s| s.to_string()))).as_ref()
|
.and_then(|s| s.to_str().map(|s| s.to_string()))).as_ref()
|
||||||
{
|
{
|
||||||
return Some(app_info);
|
return Some(Object::new(&[("appinfo", &app_info), ("active", &results)])
|
||||||
|
.expect("Failed to create `DockObject`."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -108,13 +109,9 @@ impl DockObject {
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
})
|
})
|
||||||
.next()
|
.next();
|
||||||
} else {
|
}
|
||||||
None
|
None
|
||||||
};
|
|
||||||
|
|
||||||
Object::new(&[("appinfo", &appinfo), ("active", &results)])
|
|
||||||
.expect("Failed to create `DockObject`.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_popover(&self, b: bool) {
|
pub fn set_popover(&self, b: bool) {
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,6 @@ fn main() {
|
||||||
let (tx, rx) = glib::MainContext::channel(glib::Priority::default());
|
let (tx, rx) = glib::MainContext::channel(glib::Priority::default());
|
||||||
|
|
||||||
let window = CosmicAppListWindow::new(app);
|
let window = CosmicAppListWindow::new(app);
|
||||||
let apps_container = apps_container::AppsContainer::new();
|
|
||||||
let wayland_tx = wayland::spawn_toplevels();
|
let wayland_tx = wayland::spawn_toplevels();
|
||||||
|
|
||||||
WAYLAND_TX.set(wayland_tx).unwrap();
|
WAYLAND_TX.set(wayland_tx).unwrap();
|
||||||
|
|
@ -78,6 +77,7 @@ fn main() {
|
||||||
TX.set(tx.clone()).unwrap();
|
TX.set(tx.clone()).unwrap();
|
||||||
|
|
||||||
rx.attach(None, glib::clone!(@weak window => @default-return glib::prelude::Continue(true), move |event| {
|
rx.attach(None, glib::clone!(@weak window => @default-return glib::prelude::Continue(true), move |event| {
|
||||||
|
let apps_container = window.apps_container();
|
||||||
let should_apply_changes = match event {
|
let should_apply_changes = match event {
|
||||||
AppListEvent::Favorite((name, should_favorite)) => {
|
AppListEvent::Favorite((name, should_favorite)) => {
|
||||||
let saved_app_model = apps_container.model(DockListType::Saved);
|
let saved_app_model = apps_container.model(DockListType::Saved);
|
||||||
|
|
@ -184,7 +184,7 @@ fn main() {
|
||||||
let model_len = active_app_model.n_items();
|
let model_len = active_app_model.n_items();
|
||||||
let new_results: Vec<glib::Object> = stack_active
|
let new_results: Vec<glib::Object> = stack_active
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|v| DockObject::from_window_list(v).upcast())
|
.filter_map(|v| DockObject::from_window_list(v).map(|o| o.upcast()))
|
||||||
.collect();
|
.collect();
|
||||||
active_app_model.splice(0, model_len, &new_results[..]);
|
active_app_model.splice(0, model_len, &new_results[..]);
|
||||||
true
|
true
|
||||||
|
|
@ -210,7 +210,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if should_apply_changes {
|
if should_apply_changes {
|
||||||
dbg!(&cached_results);
|
// dbg!(&cached_results);
|
||||||
// build active app stacks for each app
|
// build active app stacks for each app
|
||||||
let stack_active = cached_results.iter().fold(
|
let stack_active = cached_results.iter().fold(
|
||||||
BTreeMap::new(),
|
BTreeMap::new(),
|
||||||
|
|
@ -271,9 +271,8 @@ fn main() {
|
||||||
let model_len = active_app_model.n_items();
|
let model_len = active_app_model.n_items();
|
||||||
let new_results: Vec<glib::Object> = stack_active
|
let new_results: Vec<glib::Object> = stack_active
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|v| DockObject::from_window_list(v).upcast())
|
.filter_map(|v| DockObject::from_window_list(v).map(|o| o.upcast()))
|
||||||
.collect();
|
.collect();
|
||||||
dbg!(&new_results);
|
|
||||||
|
|
||||||
active_app_model.splice(0, model_len, &new_results[..]);
|
active_app_model.splice(0, model_len, &new_results[..]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -238,7 +238,6 @@ impl Dispatch<ZcosmicToplevelInfoV1, ()> for State {
|
||||||
_: &Connection,
|
_: &Connection,
|
||||||
_: &QueueHandle<Self>,
|
_: &QueueHandle<Self>,
|
||||||
) {
|
) {
|
||||||
dbg!(&event);
|
|
||||||
match event {
|
match event {
|
||||||
zcosmic_toplevel_info_v1::Event::Toplevel { toplevel } => {
|
zcosmic_toplevel_info_v1::Event::Toplevel { toplevel } => {
|
||||||
state.toplevels.push(Toplevel {
|
state.toplevels.push(Toplevel {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue