use glib channel

This commit is contained in:
Ashley Wulber 2022-06-16 13:00:27 -04:00
parent 8aee896d38
commit 0d93231453
3 changed files with 10 additions and 9 deletions

2
Cargo.lock generated
View file

@ -394,7 +394,7 @@ dependencies = [
[[package]] [[package]]
name = "cosmic-panel-config" name = "cosmic-panel-config"
version = "0.1.0" 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 = [ dependencies = [
"anyhow", "anyhow",
"gtk4", "gtk4",

View file

@ -3,7 +3,7 @@
use gtk4::{ use gtk4::{
gdk::Display, gdk::Display,
gio::{self, ApplicationFlags}, gio::{self, ApplicationFlags},
glib, glib::{self, MainContext, Priority},
prelude::*, prelude::*,
CssProvider, StyleContext, CssProvider, StyleContext,
}; };
@ -57,18 +57,18 @@ fn main() {
app.connect_activate(|app| { app.connect_activate(|app| {
load_css(); load_css();
let (tx, mut rx) = mpsc::channel::<State>(100); let (tx, mut rx) = MainContext::channel(Priority::default());
let wayland_tx = wayland::spawn_workspaces(tx.clone()); let wayland_tx = wayland::spawn_workspaces(tx.clone());
let window = CosmicWorkspacesWindow::new(app); let window = CosmicWorkspacesWindow::new(app);
TX.set(wayland_tx).unwrap(); TX.set(wayland_tx).unwrap();
let _ = glib::MainContext::default().spawn_local(async move { rx.attach(None, |workspace_event| {
while let Some(workspace_list) = rx.recv().await { dbg!(workspace_event);
// TODO update the model with the new workspace list glib::prelude::Continue(true)
}
}); });
window.show(); window.show();
}); });
app.run(); app.run();

View file

@ -1,5 +1,6 @@
use crate::{utils::{Activate}, wayland::generated::client::zext_workspace_manager_v1::ZextWorkspaceManagerV1}; use crate::{utils::{Activate}, wayland::generated::client::zext_workspace_manager_v1::ZextWorkspaceManagerV1};
use std::{env, os::unix::net::UnixStream, path::PathBuf, sync::Arc}; use std::{env, os::unix::net::UnixStream, path::PathBuf, sync::Arc};
use gtk4::glib;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use wayland_backend::client::ObjectData; use wayland_backend::client::ObjectData;
use wayland_client::{ use wayland_client::{
@ -37,7 +38,7 @@ use self::generated::client::{
zext_workspace_handle_v1::{self, ZextWorkspaceHandleV1}, zext_workspace_handle_v1::{self, ZextWorkspaceHandleV1},
}; };
pub fn spawn_workspaces(tx: mpsc::Sender<State>) -> mpsc::Sender<Activate> { pub fn spawn_workspaces(tx: glib::Sender<State>) -> mpsc::Sender<Activate> {
let (workspaces_tx, mut workspaces_rx) = mpsc::channel(100); let (workspaces_tx, mut workspaces_rx) = mpsc::channel(100);
if let Ok(Ok(conn)) = std::env::var("HOST_WAYLAND_DISPLAY") if let Ok(Ok(conn)) = std::env::var("HOST_WAYLAND_DISPLAY")
.map_err(anyhow::Error::msg) .map_err(anyhow::Error::msg)
@ -80,7 +81,7 @@ pub fn spawn_workspaces(tx: mpsc::Sender<State>) -> mpsc::Sender<Activate> {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct State { pub struct State {
running: bool, running: bool,
tx: mpsc::Sender<State>, tx: glib::Sender<State>,
workspace_manager: Option<zext_workspace_manager_v1::ZextWorkspaceManagerV1>, workspace_manager: Option<zext_workspace_manager_v1::ZextWorkspaceManagerV1>,
workspace_groups: Vec<WorkspaceGroup>, workspace_groups: Vec<WorkspaceGroup>,
} }