Update libcosmic/iced for advanced text rebase
This commit is contained in:
parent
60a4a2fa63
commit
078fc31713
5 changed files with 851 additions and 557 deletions
|
|
@ -1,52 +1,31 @@
|
|||
use cosmic::iced::{self, futures::StreamExt, subscription};
|
||||
use futures_channel::mpsc;
|
||||
use cosmic::iced::{
|
||||
self,
|
||||
futures::{channel::mpsc, future, SinkExt},
|
||||
subscription,
|
||||
};
|
||||
use std::fmt::Debug;
|
||||
use zbus::{dbus_interface, Connection, ConnectionBuilder};
|
||||
use zbus::{dbus_interface, ConnectionBuilder};
|
||||
|
||||
pub fn subscription() -> iced::Subscription<Event> {
|
||||
subscription::unfold("workspaces-dbus", State::Ready, move |state| {
|
||||
start_listening(state)
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum State {
|
||||
Ready,
|
||||
Waiting(Connection, mpsc::UnboundedReceiver<Event>),
|
||||
Finished,
|
||||
}
|
||||
|
||||
async fn start_listening(state: State) -> (Option<Event>, State) {
|
||||
match state {
|
||||
State::Ready => {
|
||||
let (tx, rx) = mpsc::unbounded();
|
||||
if let Some(conn) = ConnectionBuilder::session()
|
||||
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 },
|
||||
)
|
||||
.ok()
|
||||
.and_then(|conn| conn.name("com.system76.CosmicWorkspaces").ok())
|
||||
.and_then(|conn| {
|
||||
conn.serve_at(
|
||||
"/com/system76/CosmicWorkspaces",
|
||||
CosmicWorkspacesServer { tx },
|
||||
)
|
||||
.ok()
|
||||
})
|
||||
.map(|conn| conn.build())
|
||||
{
|
||||
if let Ok(conn) = conn.await {
|
||||
return (None, State::Waiting(conn, rx));
|
||||
}
|
||||
}
|
||||
(None, State::Finished)
|
||||
})
|
||||
.map(|conn| conn.build())
|
||||
{
|
||||
let _conn = conn.await;
|
||||
future::pending().await
|
||||
} else {
|
||||
future::pending().await
|
||||
}
|
||||
State::Waiting(conn, mut rx) => {
|
||||
if let Some(Event::Toggle) = rx.next().await {
|
||||
(Some(Event::Toggle), State::Waiting(conn, rx))
|
||||
} else {
|
||||
(None, State::Finished)
|
||||
}
|
||||
}
|
||||
State::Finished => iced::futures::future::pending().await,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
|
@ -56,12 +35,12 @@ pub enum Event {
|
|||
|
||||
#[derive(Debug)]
|
||||
struct CosmicWorkspacesServer {
|
||||
tx: mpsc::UnboundedSender<Event>,
|
||||
sender: mpsc::Sender<Event>,
|
||||
}
|
||||
|
||||
#[dbus_interface(name = "com.system76.CosmicWorkspaces")]
|
||||
impl CosmicWorkspacesServer {
|
||||
async fn toggle(&self) {
|
||||
self.tx.unbounded_send(Event::Toggle).unwrap();
|
||||
self.sender.clone().send(Event::Toggle).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue