Expose DBus protocol with signals indicating when shown/hidden

This commit is contained in:
Ian Douglas Scott 2025-07-21 14:06:47 -07:00 committed by Ian Douglas Scott
parent d3fc7a2815
commit c9a69bdfdb
4 changed files with 63 additions and 0 deletions

View file

@ -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)) => {