diff --git a/Cargo.lock b/Cargo.lock index d9daebb3..8ff3ab2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -394,7 +394,7 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel/#8787823d807ea9a9d7b96ecacf017d695ba7b58a" +source = "git+https://github.com/pop-os/cosmic-panel#8787823d807ea9a9d7b96ecacf017d695ba7b58a" dependencies = [ "anyhow", "gtk4", diff --git a/applets/cosmic-applet-workspaces/data/resources/style.css b/applets/cosmic-applet-workspaces/data/resources/style.css index e69de29b..7484d22f 100644 --- a/applets/cosmic-applet-workspaces/data/resources/style.css +++ b/applets/cosmic-applet-workspaces/data/resources/style.css @@ -0,0 +1,4 @@ +*.alert { + background-color: #aa3000; + color: white; +} \ No newline at end of file diff --git a/applets/cosmic-applet-workspaces/src/main.rs b/applets/cosmic-applet-workspaces/src/main.rs index cf426325..42e28e01 100644 --- a/applets/cosmic-applet-workspaces/src/main.rs +++ b/applets/cosmic-applet-workspaces/src/main.rs @@ -65,7 +65,6 @@ fn main() { TX.set(wayland_tx).unwrap(); rx.attach(None, glib::clone!(@weak window => @default-return glib::prelude::Continue(true), move |workspace_event| { - dbg!(&workspace_event); window.set_workspaces(workspace_event); glib::prelude::Continue(true) })); diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 3d19642b..9008b8e5 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -1,5 +1,5 @@ use crate::{utils::{Activate}, wayland::generated::client::zext_workspace_manager_v1::ZextWorkspaceManagerV1}; -use std::{env, os::unix::net::UnixStream, path::PathBuf, sync::Arc}; +use std::{env, os::unix::net::UnixStream, path::PathBuf, sync::Arc, mem}; use gtk4::glib; use tokio::sync::mpsc; use wayland_backend::client::ObjectData; @@ -10,6 +10,11 @@ use wayland_client::{ use wayland_client::{Connection, Dispatch, QueueHandle}; +pub enum WorkspaceState { + +} + + /// Generated protocol definitions mod generated { #![allow(dead_code, non_camel_case_types, unused_unsafe, unused_variables)] @@ -67,7 +72,19 @@ pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender { }; while state.running { - event_queue.blocking_dispatch(&mut state).unwrap(); + while let Ok(request) = workspaces_rx.try_recv() { + dbg!(&request); + if let Some(w) = state.workspace_groups.iter().find_map(|g| { + g.workspaces + .iter() + .find(|w| w.name == request) + }) { + println!("sending request"); + w.workspace_handle.activate(); + } + } + event_queue.sync_roundtrip(&mut state).unwrap(); + } }); } else { @@ -87,8 +104,9 @@ pub struct State { } impl State { - pub fn workspace_list(&self) -> impl Iterator + '_ { - self.workspace_groups.iter().map(|g| g.workspaces.iter().map(|w| (w.name.clone(), false))).flatten() + // XXX + pub fn workspace_list(&self) -> impl Iterator + '_ { + self.workspace_groups.iter().map(|g| g.workspaces.iter().map(|w| (w.name.clone(), w.state))).flatten() } } @@ -104,7 +122,7 @@ struct Workspace { workspace_handle: ZextWorkspaceHandleV1, name: String, coordinates: Vec, - state: Vec, + state: u32, } impl Dispatch for State { @@ -216,7 +234,7 @@ impl Dispatch for State { workspace_handle: workspace, name: String::new(), coordinates: Vec::new(), - state: Vec::new(), + state: 4, }) } } @@ -271,7 +289,11 @@ impl Dispatch for State { .iter_mut() .find(|w| &w.workspace_handle == workspace) }) { - w.state = state; + dbg!(&state); + if state.len() == 4 { + // XXX is it little endian?? + w.state = u32::from_le_bytes(state.try_into().unwrap()); + } } } zext_workspace_handle_v1::Event::Remove => { diff --git a/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs b/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs index 73c9cee6..16683355 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_button/mod.rs @@ -30,10 +30,16 @@ impl WorkspaceButton { let id = obj.id(); let new_button = ToggleButton::with_label(&id); - new_button.set_active(obj.active()); + new_button.set_active(obj.active() == 0); + if obj.active() == 1 { + new_button.add_css_class("alert"); + } self.append(&new_button); new_button.connect_clicked(move |_| { - let _ = TX.get().unwrap().send(id.clone()); + let id_clone = id.clone(); + glib::MainContext::default().spawn_local(async move { + TX.get().unwrap().send(id_clone).await.unwrap(); + }); }); imp.button.replace(new_button); diff --git a/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs b/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs index a1a865aa..8fc312dc 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_object/imp.rs @@ -4,7 +4,7 @@ use std::cell::{RefCell, Cell}; use glib::{ParamFlags, ParamSpec, Value}; use gtk4::gdk::glib::ParamSpecBoolean; -use gtk4::glib::{self, ParamSpecString}; +use gtk4::glib::{self, ParamSpecString, ParamSpecUInt}; use gtk4::prelude::*; use gtk4::subclass::prelude::*; use once_cell::sync::Lazy; @@ -13,7 +13,7 @@ use once_cell::sync::Lazy; #[derive(Default)] pub struct WorkspaceObject { pub(crate) id: RefCell, - pub(crate) active: Cell, + pub(crate) active: Cell, } // The central trait for subclassing a GObject @@ -41,11 +41,13 @@ impl ObjectImpl for WorkspaceObject { // The property can be read and written to ParamFlags::READWRITE, ), - ParamSpecBoolean::new( + ParamSpecUInt::new( "active", "active", "Indicates whether workspace is active", - false, + 0, + 4, + 0, ParamFlags::READWRITE, ), ] diff --git a/applets/cosmic-applet-workspaces/src/workspace_object/mod.rs b/applets/cosmic-applet-workspaces/src/workspace_object/mod.rs index ed66f62a..2688bb2f 100644 --- a/applets/cosmic-applet-workspaces/src/workspace_object/mod.rs +++ b/applets/cosmic-applet-workspaces/src/workspace_object/mod.rs @@ -13,7 +13,7 @@ impl WorkspaceObject { glib::Object::new(&[]).unwrap() } - pub fn from_id_active(id: String, active: bool) -> Self { + pub fn from_id_active(id: String, active: u32) -> Self { glib::Object::new(&[("id", &id), ("active", &active)]).unwrap() } @@ -21,7 +21,7 @@ impl WorkspaceObject { imp::WorkspaceObject::from_instance(&self).id.borrow().clone() } - pub fn active(&self) -> bool { + pub fn active(&self) -> u32 { imp::WorkspaceObject::from_instance(&self).active.get() } }