diff --git a/Cargo.lock b/Cargo.lock index 649b0ec..0fc2ef9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1264,6 +1264,7 @@ dependencies = [ "rustix 1.1.2", "tokio", "wayland-protocols", + "zbus 5.11.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 23d09b7..1edffcf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ rustix = { version = "1.1.2", features = ["fs", "shm"] } calloop-wayland-source = "0.4.1" aliasable = "0.1.3" futures-executor = { version = "0.3.31", features = ["thread-pool"] } +zbus = "5.9.0" [dependencies.i18n-embed] version = "0.16" diff --git a/src/dbus.rs b/src/dbus.rs new file mode 100644 index 0000000..fdb1f35 --- /dev/null +++ b/src/dbus.rs @@ -0,0 +1,37 @@ +struct CosmicWorkspaces; + +#[zbus::interface(name = "com.system76.CosmicWorkspaces")] +impl CosmicWorkspaces { + #[zbus(signal)] + async fn shown(&self, _emitter: &zbus::object_server::SignalEmitter<'_>) -> zbus::Result<()>; + #[zbus(signal)] + async fn hidden(&self, _emitter: &zbus::object_server::SignalEmitter<'_>) -> zbus::Result<()>; +} + +#[derive(Clone, Debug)] +pub struct Interface { + emitter: zbus::object_server::SignalEmitter<'static>, +} + +impl Interface { + pub async fn new(conn: zbus::Connection) -> zbus::Result { + conn.object_server() + .at("/com/system76/CosmicWorkspaces", CosmicWorkspaces) + .await?; + Ok(Interface { + emitter: zbus::object_server::SignalEmitter::new( + &conn, + "/com/system76/CosmicWorkspaces", + ) + .unwrap(), + }) + } + + pub async fn shown(&self) -> zbus::Result<()> { + CosmicWorkspaces.shown(&self.emitter).await + } + + pub async fn hidden(&self) -> zbus::Result<()> { + CosmicWorkspaces.hidden(&self.emitter).await + } +} diff --git a/src/main.rs b/src/main.rs index f89c956..2a3c7f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,6 +40,7 @@ use std::{ time::{Duration, Instant}, }; +mod dbus; mod desktop_info; #[macro_use] mod localize; @@ -114,6 +115,7 @@ enum Msg { OnScroll(wl_output::WlOutput, ScrollDelta), TogglePinned(ExtWorkspaceHandleV1), EnteredWorkspaceSidebarEntry(ExtWorkspaceHandleV1, bool), + DbusInterface(zbus::Result), Ignore, } @@ -192,6 +194,7 @@ struct App { core: cosmic::app::Core, drop_target: Option, scroll: Option<(f32, Instant)>, + dbus_interface: Option, } #[derive(Debug, Default)] @@ -277,6 +280,12 @@ impl App { ); self.update_capture_filter(); + if let Some(interface) = self.dbus_interface.clone() { + tokio::spawn(async move { + let _ = interface.shown().await; + }); + } + cmd } else { Task::none() @@ -285,6 +294,12 @@ impl App { // Close all shell surfaces fn hide(&mut self) -> Task> { + if let Some(interface) = self.dbus_interface.clone() { + tokio::spawn(async move { + let _ = interface.hidden().await; + }); + } + self.visible = false; self.update_capture_filter(); self.drag_surface = None; @@ -708,6 +723,11 @@ impl Application for App { workspace.has_cursor = entered; } } + Msg::DbusInterface(interface) => { + if let Ok(interface) = interface { + self.dbus_interface = Some(interface); + } + } Msg::Ignore => {} } @@ -721,6 +741,10 @@ impl Application for App { } } + fn dbus_connection(&mut self, conn: zbus::Connection) -> Task> { + Task::perform(dbus::Interface::new(conn), Msg::DbusInterface).map(cosmic::Action::App) + } + fn subscription(&self) -> Subscription { let events = iced::event::listen_with(|evt, _, _| match evt { iced::Event::PlatformSpecific(iced::event::PlatformSpecific::Wayland(evt)) => {