workspace state handling
This commit is contained in:
parent
dba44d579f
commit
2417ff6e31
7 changed files with 50 additions and 17 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
*.alert {
|
||||
background-color: #aa3000;
|
||||
color: white;
|
||||
}
|
||||
|
|
@ -65,7 +65,6 @@ fn main() {
|
|||
TX.set(wayland_tx).unwrap();
|
||||
|
||||
rx.attach(None, glib::clone!(@weak window => @default-return glib::prelude::Continue(true), move |workspace_event| {
|
||||
dbg!(&workspace_event);
|
||||
window.set_workspaces(workspace_event);
|
||||
glib::prelude::Continue(true)
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
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, mem};
|
||||
use gtk4::glib;
|
||||
use tokio::sync::mpsc;
|
||||
use wayland_backend::client::ObjectData;
|
||||
|
|
@ -10,6 +10,11 @@ use wayland_client::{
|
|||
|
||||
use wayland_client::{Connection, Dispatch, QueueHandle};
|
||||
|
||||
pub enum WorkspaceState {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Generated protocol definitions
|
||||
mod generated {
|
||||
#![allow(dead_code, non_camel_case_types, unused_unsafe, unused_variables)]
|
||||
|
|
@ -67,7 +72,19 @@ pub fn spawn_workspaces(tx: glib::Sender<State>) -> mpsc::Sender<Activate> {
|
|||
};
|
||||
|
||||
while state.running {
|
||||
event_queue.blocking_dispatch(&mut state).unwrap();
|
||||
while let Ok(request) = workspaces_rx.try_recv() {
|
||||
dbg!(&request);
|
||||
if let Some(w) = state.workspace_groups.iter().find_map(|g| {
|
||||
g.workspaces
|
||||
.iter()
|
||||
.find(|w| w.name == request)
|
||||
}) {
|
||||
println!("sending request");
|
||||
w.workspace_handle.activate();
|
||||
}
|
||||
}
|
||||
event_queue.sync_roundtrip(&mut state).unwrap();
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
@ -87,8 +104,9 @@ pub struct State {
|
|||
}
|
||||
|
||||
impl State {
|
||||
pub fn workspace_list(&self) -> impl Iterator<Item=(String, bool)> + '_ {
|
||||
self.workspace_groups.iter().map(|g| g.workspaces.iter().map(|w| (w.name.clone(), false))).flatten()
|
||||
// XXX
|
||||
pub fn workspace_list(&self) -> impl Iterator<Item=(String, u32)> + '_ {
|
||||
self.workspace_groups.iter().map(|g| g.workspaces.iter().map(|w| (w.name.clone(), w.state))).flatten()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +122,7 @@ struct Workspace {
|
|||
workspace_handle: ZextWorkspaceHandleV1,
|
||||
name: String,
|
||||
coordinates: Vec<u8>,
|
||||
state: Vec<u8>,
|
||||
state: u32,
|
||||
}
|
||||
|
||||
impl Dispatch<wl_registry::WlRegistry, ()> for State {
|
||||
|
|
@ -216,7 +234,7 @@ impl Dispatch<ZextWorkspaceGroupHandleV1, ()> for State {
|
|||
workspace_handle: workspace,
|
||||
name: String::new(),
|
||||
coordinates: Vec::new(),
|
||||
state: Vec::new(),
|
||||
state: 4,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -271,7 +289,11 @@ impl Dispatch<ZextWorkspaceHandleV1, ()> for State {
|
|||
.iter_mut()
|
||||
.find(|w| &w.workspace_handle == workspace)
|
||||
}) {
|
||||
w.state = state;
|
||||
dbg!(&state);
|
||||
if state.len() == 4 {
|
||||
// XXX is it little endian??
|
||||
w.state = u32::from_le_bytes(state.try_into().unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
zext_workspace_handle_v1::Event::Remove => {
|
||||
|
|
|
|||
|
|
@ -30,10 +30,16 @@ impl WorkspaceButton {
|
|||
|
||||
let id = obj.id();
|
||||
let new_button = ToggleButton::with_label(&id);
|
||||
new_button.set_active(obj.active());
|
||||
new_button.set_active(obj.active() == 0);
|
||||
if obj.active() == 1 {
|
||||
new_button.add_css_class("alert");
|
||||
}
|
||||
self.append(&new_button);
|
||||
new_button.connect_clicked(move |_| {
|
||||
let _ = TX.get().unwrap().send(id.clone());
|
||||
let id_clone = id.clone();
|
||||
glib::MainContext::default().spawn_local(async move {
|
||||
TX.get().unwrap().send(id_clone).await.unwrap();
|
||||
});
|
||||
});
|
||||
|
||||
imp.button.replace(new_button);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use std::cell::{RefCell, Cell};
|
|||
|
||||
use glib::{ParamFlags, ParamSpec, Value};
|
||||
use gtk4::gdk::glib::ParamSpecBoolean;
|
||||
use gtk4::glib::{self, ParamSpecString};
|
||||
use gtk4::glib::{self, ParamSpecString, ParamSpecUInt};
|
||||
use gtk4::prelude::*;
|
||||
use gtk4::subclass::prelude::*;
|
||||
use once_cell::sync::Lazy;
|
||||
|
|
@ -13,7 +13,7 @@ use once_cell::sync::Lazy;
|
|||
#[derive(Default)]
|
||||
pub struct WorkspaceObject {
|
||||
pub(crate) id: RefCell<String>,
|
||||
pub(crate) active: Cell<bool>,
|
||||
pub(crate) active: Cell<u32>,
|
||||
}
|
||||
|
||||
// The central trait for subclassing a GObject
|
||||
|
|
@ -41,11 +41,13 @@ impl ObjectImpl for WorkspaceObject {
|
|||
// The property can be read and written to
|
||||
ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpecBoolean::new(
|
||||
ParamSpecUInt::new(
|
||||
"active",
|
||||
"active",
|
||||
"Indicates whether workspace is active",
|
||||
false,
|
||||
0,
|
||||
4,
|
||||
0,
|
||||
ParamFlags::READWRITE,
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ impl WorkspaceObject {
|
|||
glib::Object::new(&[]).unwrap()
|
||||
}
|
||||
|
||||
pub fn from_id_active(id: String, active: bool) -> Self {
|
||||
pub fn from_id_active(id: String, active: u32) -> Self {
|
||||
glib::Object::new(&[("id", &id), ("active", &active)]).unwrap()
|
||||
}
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ impl WorkspaceObject {
|
|||
imp::WorkspaceObject::from_instance(&self).id.borrow().clone()
|
||||
}
|
||||
|
||||
pub fn active(&self) -> bool {
|
||||
pub fn active(&self) -> u32 {
|
||||
imp::WorkspaceObject::from_instance(&self).active.get()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue