From 0d9323145345beac1f651901faded67ef515c9e6 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 16 Jun 2022 13:00:27 -0400 Subject: [PATCH] use glib channel --- Cargo.lock | 2 +- applets/cosmic-applet-workspaces/src/main.rs | 12 ++++++------ applets/cosmic-applet-workspaces/src/wayland.rs | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8ff3ab2f..d9daebb3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -394,7 +394,7 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel#8787823d807ea9a9d7b96ecacf017d695ba7b58a" +source = "git+https://github.com/pop-os/cosmic-panel/#8787823d807ea9a9d7b96ecacf017d695ba7b58a" dependencies = [ "anyhow", "gtk4", diff --git a/applets/cosmic-applet-workspaces/src/main.rs b/applets/cosmic-applet-workspaces/src/main.rs index 0eb046d0..ab83028c 100644 --- a/applets/cosmic-applet-workspaces/src/main.rs +++ b/applets/cosmic-applet-workspaces/src/main.rs @@ -3,7 +3,7 @@ use gtk4::{ gdk::Display, gio::{self, ApplicationFlags}, - glib, + glib::{self, MainContext, Priority}, prelude::*, CssProvider, StyleContext, }; @@ -57,18 +57,18 @@ fn main() { app.connect_activate(|app| { load_css(); - let (tx, mut rx) = mpsc::channel::(100); + let (tx, mut rx) = MainContext::channel(Priority::default()); let wayland_tx = wayland::spawn_workspaces(tx.clone()); let window = CosmicWorkspacesWindow::new(app); TX.set(wayland_tx).unwrap(); - let _ = glib::MainContext::default().spawn_local(async move { - while let Some(workspace_list) = rx.recv().await { - // TODO update the model with the new workspace list - } + rx.attach(None, |workspace_event| { + dbg!(workspace_event); + glib::prelude::Continue(true) }); + window.show(); }); app.run(); diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 27ab2268..dcf808e5 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -1,5 +1,6 @@ use crate::{utils::{Activate}, wayland::generated::client::zext_workspace_manager_v1::ZextWorkspaceManagerV1}; use std::{env, os::unix::net::UnixStream, path::PathBuf, sync::Arc}; +use gtk4::glib; use tokio::sync::mpsc; use wayland_backend::client::ObjectData; use wayland_client::{ @@ -37,7 +38,7 @@ use self::generated::client::{ zext_workspace_handle_v1::{self, ZextWorkspaceHandleV1}, }; -pub fn spawn_workspaces(tx: mpsc::Sender) -> mpsc::Sender { +pub fn spawn_workspaces(tx: glib::Sender) -> mpsc::Sender { let (workspaces_tx, mut workspaces_rx) = mpsc::channel(100); if let Ok(Ok(conn)) = std::env::var("HOST_WAYLAND_DISPLAY") .map_err(anyhow::Error::msg) @@ -80,7 +81,7 @@ pub fn spawn_workspaces(tx: mpsc::Sender) -> mpsc::Sender { #[derive(Debug, Clone)] pub struct State { running: bool, - tx: mpsc::Sender, + tx: glib::Sender, workspace_manager: Option, workspace_groups: Vec, }