feat: hook up workspace list to be displayed in the UI
This commit is contained in:
parent
0d93231453
commit
dba44d579f
5 changed files with 29 additions and 6 deletions
|
|
@ -57,17 +57,18 @@ fn main() {
|
||||||
|
|
||||||
app.connect_activate(|app| {
|
app.connect_activate(|app| {
|
||||||
load_css();
|
load_css();
|
||||||
let (tx, mut rx) = MainContext::channel(Priority::default());
|
let (tx, rx) = MainContext::channel(Priority::default());
|
||||||
|
|
||||||
let wayland_tx = wayland::spawn_workspaces(tx.clone());
|
let wayland_tx = wayland::spawn_workspaces(tx.clone());
|
||||||
let window = CosmicWorkspacesWindow::new(app);
|
let window = CosmicWorkspacesWindow::new(app);
|
||||||
|
|
||||||
TX.set(wayland_tx).unwrap();
|
TX.set(wayland_tx).unwrap();
|
||||||
|
|
||||||
rx.attach(None, |workspace_event| {
|
rx.attach(None, glib::clone!(@weak window => @default-return glib::prelude::Continue(true), move |workspace_event| {
|
||||||
dbg!(workspace_event);
|
dbg!(&workspace_event);
|
||||||
|
window.set_workspaces(workspace_event);
|
||||||
glib::prelude::Continue(true)
|
glib::prelude::Continue(true)
|
||||||
});
|
}));
|
||||||
|
|
||||||
window.show();
|
window.show();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,12 @@ pub struct State {
|
||||||
workspace_groups: Vec<WorkspaceGroup>,
|
workspace_groups: Vec<WorkspaceGroup>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl State {
|
||||||
|
pub fn workspace_list(&self) -> impl Iterator<Item=(String, bool)> + '_ {
|
||||||
|
self.workspace_groups.iter().map(|g| g.workspaces.iter().map(|w| (w.name.clone(), false))).flatten()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct WorkspaceGroup {
|
struct WorkspaceGroup {
|
||||||
workspace_group_handle: ZextWorkspaceGroupHandleV1,
|
workspace_group_handle: ZextWorkspaceGroupHandleV1,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// SPDX-License-Identifier: MPL-2.0-only
|
// SPDX-License-Identifier: MPL-2.0-only
|
||||||
|
|
||||||
use crate::{fl, utils::Activate, workspace_list::WorkspaceList};
|
use crate::{fl, utils::Activate, workspace_list::WorkspaceList, wayland::State};
|
||||||
use cascade::cascade;
|
use cascade::cascade;
|
||||||
use cosmic_panel_config::config::CosmicPanelConfig;
|
use cosmic_panel_config::config::CosmicPanelConfig;
|
||||||
use gtk4::{
|
use gtk4::{
|
||||||
|
|
@ -43,4 +43,9 @@ impl CosmicWorkspacesWindow {
|
||||||
|
|
||||||
self_
|
self_
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_workspaces(&self, workspaces: State) {
|
||||||
|
let imp = imp::CosmicWorkspacesWindow::from_instance(&self);
|
||||||
|
imp.inner.get().unwrap().set_workspaces(workspaces);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// SPDX-License-Identifier: MPL-2.0-only
|
// SPDX-License-Identifier: MPL-2.0-only
|
||||||
|
|
||||||
use crate::utils::Activate;
|
use crate::utils::Activate;
|
||||||
|
use crate::wayland::State;
|
||||||
use crate::workspace_button::WorkspaceButton;
|
use crate::workspace_button::WorkspaceButton;
|
||||||
use crate::workspace_object::WorkspaceObject;
|
use crate::workspace_object::WorkspaceObject;
|
||||||
use cascade::cascade;
|
use cascade::cascade;
|
||||||
|
|
@ -48,6 +49,17 @@ impl WorkspaceList {
|
||||||
imp.list_view.set(list_view).unwrap();
|
imp.list_view.set(list_view).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_workspaces(&self, workspaces: State) {
|
||||||
|
let imp = imp::WorkspaceList::from_instance(&self);
|
||||||
|
let model = imp.model.get().unwrap();
|
||||||
|
|
||||||
|
let model_len = model.n_items();
|
||||||
|
let new_results: Vec<glib::Object> = workspaces.workspace_list()
|
||||||
|
.into_iter()
|
||||||
|
.map(|w| WorkspaceObject::from_id_active(w.0, w.1).upcast())
|
||||||
|
.collect();
|
||||||
|
model.splice(0, model_len, &new_results[..]); }
|
||||||
|
|
||||||
fn setup_model(&self) {
|
fn setup_model(&self) {
|
||||||
let imp = imp::WorkspaceList::from_instance(self);
|
let imp = imp::WorkspaceList::from_instance(self);
|
||||||
let model = gio::ListStore::new(WorkspaceObject::static_type());
|
let model = gio::ListStore::new(WorkspaceObject::static_type());
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ use std::cell::{RefCell, Cell};
|
||||||
use glib::{ParamFlags, ParamSpec, Value};
|
use glib::{ParamFlags, ParamSpec, Value};
|
||||||
use gtk4::gdk::glib::ParamSpecBoolean;
|
use gtk4::gdk::glib::ParamSpecBoolean;
|
||||||
use gtk4::glib::{self, ParamSpecString};
|
use gtk4::glib::{self, ParamSpecString};
|
||||||
use gtk4::glib::ParamSpecUInt;
|
|
||||||
use gtk4::prelude::*;
|
use gtk4::prelude::*;
|
||||||
use gtk4::subclass::prelude::*;
|
use gtk4::subclass::prelude::*;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue