From 85fe582d1db8269b7c535c8fcd8ba26ad10d44f1 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 8 Jul 2022 23:22:08 +0200 Subject: [PATCH 1/5] workspaces: Update to cosmic-protocols --- Cargo.lock | 50 ++- applets/cosmic-applet-workspaces/Cargo.toml | 8 +- applets/cosmic-applet-workspaces/build.rs | 9 - .../src/ext-workspace-unstable-v1.xml | 306 ------------------ .../cosmic-applet-workspaces/src/wayland.rs | 97 +++--- 5 files changed, 78 insertions(+), 392 deletions(-) delete mode 100644 applets/cosmic-applet-workspaces/src/ext-workspace-unstable-v1.xml diff --git a/Cargo.lock b/Cargo.lock index a16f7ff4..48655d91 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -430,6 +430,7 @@ dependencies = [ "calloop", "cascade", "cosmic-panel-config", + "cosmic-protocols", "gio 0.15.12", "gtk4", "i18n-embed", @@ -441,9 +442,8 @@ dependencies = [ "rust-embed", "tokio", "wayland-backend", - "wayland-client 0.30.0-beta.5", + "wayland-client 0.30.0-beta.7", "wayland-commons", - "wayland-scanner 0.30.0-beta.5", ] [[package]] @@ -478,18 +478,30 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel#791937b3515534f4df9bb47c1a6bd5189ff00644" +source = "git+https://github.com/pop-os/cosmic-panel#c0b4c8b42616dfc8c49f96f0c7adcab364287925" dependencies = [ "anyhow", "gtk4", "ron", "serde", "slog", - "wayland-protocols", + "wayland-protocols 0.29.4", "xdg", "xdg-shell-wrapper-config", ] +[[package]] +name = "cosmic-protocols" +version = "0.1.0" +source = "git+https://github.com/pop-os/cosmic-protocols#1962ffdca3d9c914929eea358ebeab61ff2217a8" +dependencies = [ + "bitflags", + "wayland-backend", + "wayland-client 0.30.0-beta.7", + "wayland-protocols 0.30.0-beta.7", + "wayland-scanner 0.30.0-beta.7", +] + [[package]] name = "cpufeatures" version = "0.2.2" @@ -2756,9 +2768,9 @@ checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" [[package]] name = "wayland-backend" -version = "0.1.0-beta.5" +version = "0.1.0-beta.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96e1d0d399007c9f43d313eff1120caa96c8cbb92470f8bf645e9af08368589c" +checksum = "a861eb7cd51f67de60f228a570f142396d94759babcb427f861071ffb0757c9e" dependencies = [ "cc", "downcast-rs", @@ -2786,9 +2798,9 @@ dependencies = [ [[package]] name = "wayland-client" -version = "0.30.0-beta.5" +version = "0.30.0-beta.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b415e9f804abeb39d800f5cc2dfec90bfd19822acfcabdae490b1fcdfaf9e5d0" +checksum = "2dca5290499da69c21fcf64b4021886963511b888af056dbfb6bebfb7e1587e6" dependencies = [ "bitflags", "futures-channel", @@ -2797,7 +2809,7 @@ dependencies = [ "nix 0.24.1", "thiserror", "wayland-backend", - "wayland-scanner 0.30.0-beta.5", + "wayland-scanner 0.30.0-beta.7", ] [[package]] @@ -2824,6 +2836,18 @@ dependencies = [ "wayland-scanner 0.29.4", ] +[[package]] +name = "wayland-protocols" +version = "0.30.0-beta.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d64adbf2e145b9da69ff0e9bb72fc513182978c826fc6f704c05f0f80b663a6d" +dependencies = [ + "bitflags", + "wayland-backend", + "wayland-client 0.30.0-beta.7", + "wayland-scanner 0.30.0-beta.7", +] + [[package]] name = "wayland-scanner" version = "0.29.4" @@ -2837,9 +2861,9 @@ dependencies = [ [[package]] name = "wayland-scanner" -version = "0.30.0-beta.5" +version = "0.30.0-beta.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3db6ef8dd5a77ff178149e071269de02594de0abd2595190ac3f2f91f25aacd" +checksum = "e3baff545c2f5a0c32d796595d0b3c8fafccf29e72e557ff1969fe552ff093d6" dependencies = [ "proc-macro2", "quote", @@ -2972,10 +2996,10 @@ dependencies = [ [[package]] name = "xdg-shell-wrapper-config" version = "0.1.0" -source = "git+https://github.com/pop-os/xdg-shell-wrapper#e523530fd900ae1985e664cce84c4066b23afea1" +source = "git+https://github.com/pop-os/xdg-shell-wrapper#f93027e8e52106852bff5b38e8676b9ca465b725" dependencies = [ "serde", - "wayland-protocols", + "wayland-protocols 0.29.4", ] [[package]] diff --git a/applets/cosmic-applet-workspaces/Cargo.toml b/applets/cosmic-applet-workspaces/Cargo.toml index 0e93d347..f45b6c3d 100644 --- a/applets/cosmic-applet-workspaces/Cargo.toml +++ b/applets/cosmic-applet-workspaces/Cargo.toml @@ -7,7 +7,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel", features = ["gtk4"] } +cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", default-features = false, features = ["client"] } +cosmic-panel-config = { git = "https://github.com/pop-os/cosmic-panel", features = ["gtk4"] } cascade = "1.0.0" gtk4 = { git = "https://github.com/gtk-rs/gtk4-rs", features = ["v4_4"] } once_cell = "1.9.0" @@ -18,9 +19,8 @@ i18n-embed-fl = "0.6.4" rust-embed = "6.3.0" tokio = { version = "1.16.1", features = ["sync"] } wayland-commons = "0.29.4" -wayland-backend = { version = "=0.1.0-beta.5" } -wayland-scanner = { version = "=0.30.0-beta.5" } -wayland-client = { version = "0.30.0-beta.5" } +wayland-backend = { version = "0.1.0-beta.7" } +wayland-client = { version = "0.30.0-beta.7" } calloop = "*" nix = "*" log = "0.4" diff --git a/applets/cosmic-applet-workspaces/build.rs b/applets/cosmic-applet-workspaces/build.rs index 8f6b0f74..410ea0f7 100644 --- a/applets/cosmic-applet-workspaces/build.rs +++ b/applets/cosmic-applet-workspaces/build.rs @@ -1,5 +1,4 @@ use std::{env, path::PathBuf, process::Command}; -// use wayland_scanner::{generate_client_code}; fn main() { if let Some(output) = Command::new("git") @@ -15,12 +14,4 @@ fn main() { "data/resources/resources.gresource.xml", "compiled.gresource", ); - // let dest = PathBuf::from(&env::var("OUT_DIR").unwrap()); - // // Location of the xml file, relative to the `Cargo.toml` - // let ext_workspace_protocol_file = "data/resources/ext-workspace-unstable-v1.xml"; - // // Target directory for the generate files - // generate_client_code!( - // ext_workspace_protocol_file, - // &dest.join("ext_workspace.rs"), - // ); } diff --git a/applets/cosmic-applet-workspaces/src/ext-workspace-unstable-v1.xml b/applets/cosmic-applet-workspaces/src/ext-workspace-unstable-v1.xml deleted file mode 100644 index 24410b62..00000000 --- a/applets/cosmic-applet-workspaces/src/ext-workspace-unstable-v1.xml +++ /dev/null @@ -1,306 +0,0 @@ - - - - Copyright © 2019 Christopher Billington - Copyright © 2020 Ilia Bozhinov - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that copyright notice and this permission - notice appear in supporting documentation, and that the name of - the copyright holders not be used in advertising or publicity - pertaining to distribution of the software without specific, - written prior permission. The copyright holders make no - representations about the suitability of this software for any - purpose. It is provided "as is" without express or implied - warranty. - - THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS - SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY - SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN - AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, - ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF - THIS SOFTWARE. - - - - - Workspaces, also called virtual desktops, are groups of surfaces. A - compositor with a concept of workspaces may only show some such groups of - surfaces (those of 'active' workspaces) at a time. 'Activating' a - workspace is a request for the compositor to display that workspace's - surfaces as normal, whereas the compositor may hide or otherwise - de-emphasise surfaces that are associated only with 'inactive' workspaces. - Workspaces are grouped by which sets of outputs they correspond to, and - may contain surfaces only from those outputs. In this way, it is possible - for each output to have its own set of workspaces, or for all outputs (or - any other arbitrary grouping) to share workspaces. Compositors may - optionally conceptually arrange each group of workspaces in an - N-dimensional grid. - - The purpose of this protocol is to enable the creation of taskbars and - docks by providing them with a list of workspaces and their properties, - and allowing them to activate and deactivate workspaces. - - After a client binds the zext_workspace_manager_v1, each workspace will be - sent via the workspace event. - - - - - This event is emitted whenever a new workspace group has been created. - - All initial details of the workspace group (workspaces, outputs) will be - sent immediately after this event via the corresponding events in - zext_workspace_group_handle_v1. - - - - - - - The client must send this request after it has finished sending other - requests. The compositor must process a series of requests preceding a - commit request atomically. - - This allows changes to the workspace properties to be seen as atomic, - even if they happen via multiple events, and even if they involve - multiple zext_workspace_handle_v1 objects, for example, deactivating one - workspace and activating another. - - - - - - This event is sent after all changes in all workspace groups have been - sent. - - This allows changes to one or more zext_workspace_group_handle_v1 - properties to be seen as atomic, even if they happen via multiple - events. In particular, an output moving from one workspace group to - another sends an output_enter event and an output_leave event to the two - zext_workspace_group_handle_v1 objects in question. The compositor sends - the done event only after updating the output information in both - workspace groups. - - - - - - This event indicates that the compositor is done sending events to the - zext_workspace_manager_v1. The server will destroy the object - immediately after sending this request, so it will become invalid and - the client should free any resources associated with it. - - - - - - Indicates the client no longer wishes to receive events for new - workspace groups. However the compositor may emit further workspace - events, until the finished event is emitted. - - The client must not send any more requests after this one. - - - - - - - A zext_workspace_group_handle_v1 object represents a a workspace group - that is assigned a set of outputs and contains a number of workspaces. - - The set of outputs assigned to the workspace group is conveyed to the client via - output_enter and output_leave events, and its workspaces are conveyed with - workspace events. - - For example, a compositor which has a set of workspaces for each output may - advertise a workspace group (and its workspaces) per output, whereas a compositor - where a workspace spans all outputs may advertise a single workspace group for all - outputs. - - - - - This event is emitted whenever an output is assigned to the workspace - group. - - - - - - - This event is emitted whenever an output is removed from the workspace - group. - - - - - - - This event is emitted whenever a new workspace has been created. - - All initial details of the workspace (name, coordinates, state) will - be sent immediately after this event via the corresponding events in - zext_workspace_handle_v1. - - - - - - - This event means the zext_workspace_group_handle_v1 has been destroyed. - It is guaranteed there won't be any more events for this - zext_workspace_group_handle_v1. The zext_workspace_group_handle_v1 becomes - inert so any requests will be ignored except the destroy request. - - The compositor must remove all workspaces belonging to a workspace group - before removing the workspace group. - - - - - - Request that the compositor create a new workspace with the given name. - - There is no guarantee that the compositor will create a new workspace, - or that the created workspace will have the provided name. - - - - - - - Destroys the zext_workspace_handle_v1 object. - - This request should be called either when the client does not want to - use the workspace object any more or after the remove event to finalize - the destruction of the object. - - - - - - - A zext_workspace_handle_v1 object represents a a workspace that handles a - group of surfaces. - - Each workspace has a name, conveyed to the client with the name event; a - list of states, conveyed to the client with the state event; and - optionally a set of coordinates, conveyed to the client with the - coordinates event. The client may request that the compositor activate or - deactivate the workspace. - - Each workspace can belong to only a single workspace group. - Depepending on the compositor policy, there might be workspaces with - the same name in different workspace groups, but these workspaces are still - separate (e.g. one of them might be active while the other is not). - - - - - This event is emitted immediately after the zext_workspace_handle_v1 is - created and whenever the name of the workspace changes. - - - - - - - This event is used to organize workspaces into an N-dimensional grid - within a workspace group, and if supported, is emitted immediately after - the zext_workspace_handle_v1 is created and whenever the coordinates of - the workspace change. Compositors may not send this event if they do not - conceptually arrange workspaces in this way. If compositors simply - number workspaces, without any geometric interpretation, they may send - 1D coordinates, which clients should not interpret as implying any - geometry. Sending an empty array means that the compositor no longer - orders the workspace geometrically. - - Coordinates have an arbitrary number of dimensions N with an uint32 - position along each dimension. By convention if N > 1, the first - dimension is X, the second Y, the third Z, and so on. The compositor may - chose to utilize these events for a more novel workspace layout - convention, however. No guarantee is made about the grid being filled or - bounded; there may be a workspace at coordinate 1 and another at - coordinate 1000 and none in between. Within a workspace group, however, - workspaces must have unique coordinates of equal dimensionality. - - - - - - - This event is emitted immediately after the zext_workspace_handle_v1 is - created and each time the workspace state changes, either because of a - compositor action or because of a request in this protocol. - - - - - - - The different states that a workspace can have. - - - - - - - The workspace is not visible in its workspace group, and clients - attempting to visualize the compositor workspace state should not - display such workspaces. - - - - - - - This event means the zext_workspace_handle_v1 has been destroyed. It is - guaranteed there won't be any more events for this - zext_workspace_handle_v1. The zext_workspace_handle_v1 becomes inert so - any requests will be ignored except the destroy request. - - - - - - Destroys the zext_workspace_handle_v1 object. - - This request should be called either when the client does not want to - use the workspace object any more or after the remove event to finalize - the destruction of the object. - - - - - - Request that this workspace be activated. - - There is no guarantee the workspace will be actually activated, and - behaviour may be compositor-dependent. For example, activating a - workspace may or may not deactivate all other workspaces in the same - group. - - - - - - Request that this workspace be deactivated. - - There is no guarantee the workspace will be actually deactivated. - - - - - - Request that this workspace be removed. - - There is no guarantee the workspace will be actually removed. - - - - diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 5c98deb3..955aeacd 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -1,6 +1,5 @@ use crate::{ utils::{Activate, WorkspaceEvent}, - wayland::generated::client::zext_workspace_manager_v1::ZextWorkspaceManagerV1, wayland_source::WaylandSource, }; use cosmic_panel_config::CosmicPanelConfig; @@ -19,36 +18,12 @@ use wayland_client::{ }, ConnectError, Proxy, }; - -use wayland_client::{Connection, Dispatch, QueueHandle}; - -/// Generated protocol definitions -mod generated { - #![allow(dead_code, non_camel_case_types, unused_unsafe, unused_variables)] - #![allow(non_upper_case_globals, non_snake_case, unused_imports)] - #![allow(missing_docs, clippy::all)] - - pub mod client { - //! Client-side API of this protocol - use wayland_client; - use wayland_client::protocol::*; - - pub mod __interfaces { - use wayland_client::protocol::__interfaces::*; - wayland_scanner::generate_interfaces!("src/ext-workspace-unstable-v1.xml"); - } - use self::__interfaces::*; - - wayland_scanner::generate_client_code!("src/ext-workspace-unstable-v1.xml"); - } -} - -use generated::client::zext_workspace_manager_v1; - -use self::generated::client::{ - zext_workspace_group_handle_v1::{self, ZextWorkspaceGroupHandleV1}, - zext_workspace_handle_v1::{self, ZextWorkspaceHandleV1}, +use cosmic_protocols::workspace::v1::client::{ + zcosmic_workspace_manager_v1::{self, ZcosmicWorkspaceManagerV1}, + zcosmic_workspace_group_handle_v1::{self, ZcosmicWorkspaceGroupHandleV1}, + zcosmic_workspace_handle_v1::{self, ZcosmicWorkspaceHandleV1}, }; +use wayland_client::{Connection, Dispatch, QueueHandle}; use calloop::channel::*; pub fn spawn_workspaces(tx: glib::Sender) -> SyncSender { @@ -166,7 +141,7 @@ pub struct State { tx: glib::Sender, configured_output: String, expected_output: Option, - workspace_manager: Option, + workspace_manager: Option, workspace_groups: Vec, } @@ -188,14 +163,14 @@ impl State { #[derive(Debug, Clone)] struct WorkspaceGroup { - workspace_group_handle: ZextWorkspaceGroupHandleV1, + workspace_group_handle: ZcosmicWorkspaceGroupHandleV1, output: Option, workspaces: Vec, } #[derive(Debug, Clone)] struct Workspace { - workspace_handle: ZextWorkspaceHandleV1, + workspace_handle: ZcosmicWorkspaceHandleV1, name: String, coordinates: Vec, state: u32, @@ -217,9 +192,9 @@ impl Dispatch for State { } = event { match &interface[..] { - "zext_workspace_manager_v1" => { + "zcosmic_workspace_manager_v1" => { let workspace_manager = registry - .bind::( + .bind::( name, 1, qh, @@ -237,49 +212,49 @@ impl Dispatch for State { } } -impl Dispatch for State { +impl Dispatch for State { fn event( &mut self, - _: &zext_workspace_manager_v1::ZextWorkspaceManagerV1, - event: zext_workspace_manager_v1::Event, + _: &ZcosmicWorkspaceManagerV1, + event: zcosmic_workspace_manager_v1::Event, _: &(), _: &Connection, _: &QueueHandle, ) { match event { - zext_workspace_manager_v1::Event::WorkspaceGroup { workspace_group } => { + zcosmic_workspace_manager_v1::Event::WorkspaceGroup { workspace_group } => { self.workspace_groups.push(WorkspaceGroup { workspace_group_handle: workspace_group, output: None, workspaces: Vec::new(), }); } - zext_workspace_manager_v1::Event::Done => { + zcosmic_workspace_manager_v1::Event::Done => { let _ = self.tx.send(self.clone()); } - zext_workspace_manager_v1::Event::Finished => { + zcosmic_workspace_manager_v1::Event::Finished => { self.workspace_manager.take(); } + _ => {} } - // wl_compositor has no event } - event_created_child!(State, ZextWorkspaceManagerV1, [ - 0 => (ZextWorkspaceGroupHandleV1, ()) + event_created_child!(State, ZcosmicWorkspaceManagerV1, [ + 0 => (ZcosmicWorkspaceGroupHandleV1, ()) ]); } -impl Dispatch for State { +impl Dispatch for State { fn event( &mut self, - group: &ZextWorkspaceGroupHandleV1, - event: zext_workspace_group_handle_v1::Event, + group: &ZcosmicWorkspaceGroupHandleV1, + event: zcosmic_workspace_group_handle_v1::Event, _: &(), _: &Connection, _: &QueueHandle, ) { match event { - zext_workspace_group_handle_v1::Event::OutputEnter { output } => { + zcosmic_workspace_group_handle_v1::Event::OutputEnter { output } => { if let Some(group) = self .workspace_groups .iter_mut() @@ -288,14 +263,14 @@ impl Dispatch for State { group.output = Some(output); } } - zext_workspace_group_handle_v1::Event::OutputLeave { output } => { + zcosmic_workspace_group_handle_v1::Event::OutputLeave { output } => { if let Some(group) = self.workspace_groups.iter_mut().find(|g| { &g.workspace_group_handle == group && g.output.as_ref() == Some(&output) }) { group.output = None; } } - zext_workspace_group_handle_v1::Event::Workspace { workspace } => { + zcosmic_workspace_group_handle_v1::Event::Workspace { workspace } => { if let Some(group) = self .workspace_groups .iter_mut() @@ -309,7 +284,7 @@ impl Dispatch for State { }) } } - zext_workspace_group_handle_v1::Event::Remove => { + zcosmic_workspace_group_handle_v1::Event::Remove => { if let Some(group) = self .workspace_groups .iter() @@ -318,25 +293,26 @@ impl Dispatch for State { self.workspace_groups.remove(group); } } + _ => {} } } - event_created_child!(State, ZextWorkspaceGroupHandleV1, [ - 2 => (ZextWorkspaceHandleV1, ()) + event_created_child!(State, ZcosmicWorkspaceGroupHandleV1, [ + 3 => (ZcosmicWorkspaceHandleV1, ()) ]); } -impl Dispatch for State { +impl Dispatch for State { fn event( &mut self, - workspace: &ZextWorkspaceHandleV1, - event: zext_workspace_handle_v1::Event, + workspace: &ZcosmicWorkspaceHandleV1, + event: zcosmic_workspace_handle_v1::Event, _: &(), _: &Connection, _: &QueueHandle, ) { match event { - zext_workspace_handle_v1::Event::Name { name } => { + zcosmic_workspace_handle_v1::Event::Name { name } => { if let Some(w) = self.workspace_groups.iter_mut().find_map(|g| { g.workspaces .iter_mut() @@ -345,7 +321,7 @@ impl Dispatch for State { w.name = name; } } - zext_workspace_handle_v1::Event::Coordinates { coordinates } => { + zcosmic_workspace_handle_v1::Event::Coordinates { coordinates } => { if let Some(w) = self.workspace_groups.iter_mut().find_map(|g| { g.workspaces .iter_mut() @@ -354,7 +330,7 @@ impl Dispatch for State { w.coordinates = coordinates; } } - zext_workspace_handle_v1::Event::State { state } => { + zcosmic_workspace_handle_v1::Event::State { state } => { if let Some(w) = self.workspace_groups.iter_mut().find_map(|g| { g.workspaces .iter_mut() @@ -368,7 +344,7 @@ impl Dispatch for State { } } } - zext_workspace_handle_v1::Event::Remove => { + zcosmic_workspace_handle_v1::Event::Remove => { if let Some((g, w_i)) = self.workspace_groups.iter_mut().find_map(|g| { g.workspaces .iter_mut() @@ -378,6 +354,7 @@ impl Dispatch for State { g.workspaces.remove(w_i); } } + _ => {} } } } From 30a184fe36739af3402fa6d4a5765f73c337ad15 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 8 Jul 2022 23:22:25 +0200 Subject: [PATCH 2/5] workspaces: Correctly parse and handle states --- .../cosmic-applet-workspaces/src/wayland.rs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 955aeacd..5167b8cc 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -87,7 +87,7 @@ pub fn spawn_workspaces(tx: glib::Sender) -> SyncSender { .find_map(|(g_i, g)| { g.workspaces .iter() - .position(|w| w.state == 0) + .position(|w| w.states.contains(&zcosmic_workspace_handle_v1::State::Active)) .map(|w_i| (g, w_i)) }) { @@ -152,7 +152,12 @@ impl State { .iter() .filter_map(|g| { if g.output == self.expected_output { - Some(g.workspaces.iter().map(|w| (w.name.clone(), w.state))) + Some(g.workspaces.iter().map(|w| dbg!((w.name.clone(), match &w.states { + x if x.contains(&zcosmic_workspace_handle_v1::State::Active) => 0, + x if x.contains(&zcosmic_workspace_handle_v1::State::Urgent) => 1, + x if x.contains(&zcosmic_workspace_handle_v1::State::Hidden) => 2, + _ => 3, + })))) } else { None } @@ -173,7 +178,7 @@ struct Workspace { workspace_handle: ZcosmicWorkspaceHandleV1, name: String, coordinates: Vec, - state: u32, + states: Vec, } impl Dispatch for State { @@ -280,7 +285,7 @@ impl Dispatch for State { workspace_handle: workspace, name: String::new(), coordinates: Vec::new(), - state: 4, + states: Vec::new(), }) } } @@ -336,12 +341,8 @@ impl Dispatch for State { .iter_mut() .find(|w| &w.workspace_handle == workspace) }) { - if state.len() == 4 { - // XXX is it little endian?? - w.state = u32::from_le_bytes(state.try_into().unwrap()); - } else { - w.state = 3; - } + // wayland is host byte order + w.states = state.chunks(4).map(|chunk| zcosmic_workspace_handle_v1::State::try_from(u32::from_ne_bytes(chunk.try_into().unwrap())).unwrap()).collect(); } } zcosmic_workspace_handle_v1::Event::Remove => { From cc2eec2b2ea23417df496cc114547cd8764b666a Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 8 Jul 2022 23:36:34 +0200 Subject: [PATCH 3/5] workspaces: Fix handling of coordinates --- applets/cosmic-applet-workspaces/src/wayland.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 5167b8cc..1519ae47 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -177,7 +177,7 @@ struct WorkspaceGroup { struct Workspace { workspace_handle: ZcosmicWorkspaceHandleV1, name: String, - coordinates: Vec, + coordinates: Vec, states: Vec, } @@ -235,6 +235,15 @@ impl Dispatch for State { }); } zcosmic_workspace_manager_v1::Event::Done => { + for group in &mut self.workspace_groups { + group.workspaces.sort_by(|w1, w2| { + w1.coordinates.iter().zip(w2.coordinates.iter()) + .skip_while(|(coord1, coord2)| coord1 == coord2) + .next() + .map(|(coord1, coord2)| coord1.cmp(coord2)) + .unwrap_or(std::cmp::Ordering::Equal) + }); + } let _ = self.tx.send(self.clone()); } zcosmic_workspace_manager_v1::Event::Finished => { @@ -332,7 +341,8 @@ impl Dispatch for State { .iter_mut() .find(|w| &w.workspace_handle == workspace) }) { - w.coordinates = coordinates; + // wayland is host byte order + w.coordinates = coordinates.chunks(4).map(|chunk| u32::from_ne_bytes(chunk.try_into().unwrap())).collect(); } } zcosmic_workspace_handle_v1::Event::State { state } => { From 83572e2eca8bf3f8df0fa209dfc4dc791a89fbc2 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 8 Jul 2022 23:47:46 +0200 Subject: [PATCH 4/5] workspaces: Fix scrolling on secondary outputs --- applets/cosmic-applet-workspaces/src/wayland.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 1519ae47..6d2b8e1d 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -83,8 +83,10 @@ pub fn spawn_workspaces(tx: glib::Sender) -> SyncSender { if let Some((w_g, w_i)) = state .workspace_groups .iter() - .enumerate() - .find_map(|(g_i, g)| { + .find_map(|g| { + if g.output != state.expected_output { + return None; + } g.workspaces .iter() .position(|w| w.states.contains(&zcosmic_workspace_handle_v1::State::Active)) From 373d795f49f4972c29a7f1f1e0d10d99c52f515b Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Tue, 12 Jul 2022 13:09:50 +0200 Subject: [PATCH 5/5] workspace: Remove left over and spammy dbg!-statement --- applets/cosmic-applet-workspaces/src/wayland.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/applets/cosmic-applet-workspaces/src/wayland.rs b/applets/cosmic-applet-workspaces/src/wayland.rs index 6d2b8e1d..2e7d7401 100644 --- a/applets/cosmic-applet-workspaces/src/wayland.rs +++ b/applets/cosmic-applet-workspaces/src/wayland.rs @@ -154,12 +154,12 @@ impl State { .iter() .filter_map(|g| { if g.output == self.expected_output { - Some(g.workspaces.iter().map(|w| dbg!((w.name.clone(), match &w.states { + Some(g.workspaces.iter().map(|w| (w.name.clone(), match &w.states { x if x.contains(&zcosmic_workspace_handle_v1::State::Active) => 0, x if x.contains(&zcosmic_workspace_handle_v1::State::Urgent) => 1, x if x.contains(&zcosmic_workspace_handle_v1::State::Hidden) => 2, _ => 3, - })))) + }))) } else { None }