Expose DBus protocol with signals indicating when shown/hidden
This commit is contained in:
parent
d3fc7a2815
commit
c9a69bdfdb
4 changed files with 63 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1264,6 +1264,7 @@ dependencies = [
|
|||
"rustix 1.1.2",
|
||||
"tokio",
|
||||
"wayland-protocols",
|
||||
"zbus 5.11.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
37
src/dbus.rs
Normal file
37
src/dbus.rs
Normal file
|
|
@ -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<Self> {
|
||||
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
|
||||
}
|
||||
}
|
||||
24
src/main.rs
24
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<dbus::Interface>),
|
||||
Ignore,
|
||||
}
|
||||
|
||||
|
|
@ -192,6 +194,7 @@ struct App {
|
|||
core: cosmic::app::Core,
|
||||
drop_target: Option<DropTarget>,
|
||||
scroll: Option<(f32, Instant)>,
|
||||
dbus_interface: Option<dbus::Interface>,
|
||||
}
|
||||
|
||||
#[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<cosmic::Action<Msg>> {
|
||||
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<cosmic::Action<Msg>> {
|
||||
Task::perform(dbus::Interface::new(conn), Msg::DbusInterface).map(cosmic::Action::App)
|
||||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Msg> {
|
||||
let events = iced::event::listen_with(|evt, _, _| match evt {
|
||||
iced::Event::PlatformSpecific(iced::event::PlatformSpecific::Wayland(evt)) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue