2023-05-12 13:25:19 -07:00
|
|
|
use cosmic::iced::{
|
|
|
|
|
self,
|
|
|
|
|
futures::{channel::mpsc, future, SinkExt},
|
|
|
|
|
subscription,
|
|
|
|
|
};
|
2023-02-09 14:29:34 -08:00
|
|
|
use std::fmt::Debug;
|
2023-05-12 13:25:19 -07:00
|
|
|
use zbus::{dbus_interface, ConnectionBuilder};
|
2023-01-19 16:29:20 -08:00
|
|
|
|
|
|
|
|
pub fn subscription() -> iced::Subscription<Event> {
|
2023-05-12 13:25:19 -07:00
|
|
|
subscription::channel("workspaces-dbus", 64, move |sender| async {
|
|
|
|
|
if let Some(conn) = ConnectionBuilder::session()
|
|
|
|
|
.ok()
|
|
|
|
|
.and_then(|conn| conn.name("com.system76.CosmicWorkspaces").ok())
|
|
|
|
|
.and_then(|conn| {
|
|
|
|
|
conn.serve_at(
|
|
|
|
|
"/com/system76/CosmicWorkspaces",
|
|
|
|
|
CosmicWorkspacesServer { sender },
|
|
|
|
|
)
|
2023-01-19 16:29:20 -08:00
|
|
|
.ok()
|
2023-05-12 13:25:19 -07:00
|
|
|
})
|
|
|
|
|
.map(|conn| conn.build())
|
|
|
|
|
{
|
|
|
|
|
let _conn = conn.await;
|
|
|
|
|
future::pending().await
|
|
|
|
|
} else {
|
|
|
|
|
future::pending().await
|
2023-01-19 16:29:20 -08:00
|
|
|
}
|
2023-05-12 13:25:19 -07:00
|
|
|
})
|
2023-01-19 16:29:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
|
pub enum Event {
|
|
|
|
|
Toggle,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
struct CosmicWorkspacesServer {
|
2023-05-12 13:25:19 -07:00
|
|
|
sender: mpsc::Sender<Event>,
|
2023-01-19 16:29:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[dbus_interface(name = "com.system76.CosmicWorkspaces")]
|
|
|
|
|
impl CosmicWorkspacesServer {
|
|
|
|
|
async fn toggle(&self) {
|
2023-05-12 13:25:19 -07:00
|
|
|
self.sender.clone().send(Event::Toggle).await.unwrap();
|
2023-01-19 16:29:20 -08:00
|
|
|
}
|
|
|
|
|
}
|