From 2da90fc625725c6d3465c920826e2718579cfb40 Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Wed, 12 Apr 2023 12:05:08 +0300 Subject: WIP: hyprland support --- protocols/ext-workspace-unstable-v1.xml | 306 +++++++++++++++++++++++++ src/protocol.rs | 1 + src/wm_info_provider.rs | 27 ++- src/wm_info_provider/ext_workspace_unstable.rs | 203 ++++++++++++++++ 4 files changed, 530 insertions(+), 7 deletions(-) create mode 100644 protocols/ext-workspace-unstable-v1.xml create mode 100644 src/wm_info_provider/ext_workspace_unstable.rs diff --git a/protocols/ext-workspace-unstable-v1.xml b/protocols/ext-workspace-unstable-v1.xml new file mode 100644 index 0000000..24410b6 --- /dev/null +++ b/protocols/ext-workspace-unstable-v1.xml @@ -0,0 +1,306 @@ + + + + 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/src/protocol.rs b/src/protocol.rs index 5b30463..c393850 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -4,3 +4,4 @@ pub use wayrs_protocols::viewporter::*; pub use wayrs_protocols::wlr_layer_shell_unstable_v1::*; wayrs_client::scanner::generate!("protocols/river-status-unstable-v1.xml"); wayrs_client::scanner::generate!("protocols/river-control-unstable-v1.xml"); +wayrs_client::scanner::generate!("protocols/ext-workspace-unstable-v1.xml"); diff --git a/src/wm_info_provider.rs b/src/wm_info_provider.rs index 12e4fb8..7f2d941 100644 --- a/src/wm_info_provider.rs +++ b/src/wm_info_provider.rs @@ -1,3 +1,4 @@ +mod ext_workspace_unstable; mod river; use wayrs_client::connection::Connection; @@ -6,10 +7,13 @@ use wayrs_client::global::*; use crate::pointer_btn::PointerBtn; use crate::protocol::*; use crate::state::State; +use ext_workspace_unstable::*; +use river::*; pub enum WmInfoProvider { None, - River(river::RiverInfoProvider), + River(RiverInfoProvider), + EWU(ExtWorkspaceUnstable), } pub type WmInfoCallback = fn(&mut Connection, &mut State, WlOutput, WmInfo); @@ -20,21 +24,28 @@ impl WmInfoProvider { globals: &Globals, callback: WmInfoCallback, ) -> WmInfoProvider { - let Some(river) = river::RiverInfoProvider::bind(conn, globals, callback) else { return Self::None }; - Self::River(river) + if let Some(river) = RiverInfoProvider::bind(conn, globals, callback) { + Self::River(river) + } else if let Some(ext_wp_u) = ExtWorkspaceUnstable::bind(conn, globals, callback) { + Self::EWU(ext_wp_u) + } else { + Self::None + } } pub fn new_ouput(&mut self, conn: &mut Connection, output: WlOutput) { match self { Self::None => (), - Self::River(river) => river.new_output(conn, output), + Self::River(x) => x.new_output(conn, output), + Self::EWU(x) => x.new_ouput(conn, output), } } pub fn output_removed(&mut self, conn: &mut Connection, output: WlOutput) { match self { Self::None => (), - Self::River(river) => river.output_removed(conn, output), + Self::River(x) => x.output_removed(conn, output), + Self::EWU(x) => x.output_removed(conn, output), } } @@ -48,17 +59,19 @@ impl WmInfoProvider { ) { match self { Self::None => (), - Self::River(river) => river.click_on_tag(conn, output, seat, tag, btn), + Self::River(x) => x.click_on_tag(conn, output, seat, tag, btn), + Self::EWU(x) => x.click_on_tag(conn, output, seat, tag, btn), } } } -#[derive(Default)] +#[derive(Default, Debug)] pub struct WmInfo { pub layout_name: Option, pub tags: Vec, } +#[derive(Debug)] pub struct Tag { pub name: String, pub is_focused: bool, diff --git a/src/wm_info_provider/ext_workspace_unstable.rs b/src/wm_info_provider/ext_workspace_unstable.rs new file mode 100644 index 0000000..68238d0 --- /dev/null +++ b/src/wm_info_provider/ext_workspace_unstable.rs @@ -0,0 +1,203 @@ +use wayrs_client::connection::Connection; +use wayrs_client::global::*; +use wayrs_client::object::ObjectId; +use wayrs_client::proxy::Proxy; + +use super::*; +use crate::protocol::*; +use crate::state::State; + +pub struct ExtWorkspaceUnstable { + groups: Vec, + known_outputs: Vec, + callback: WmInfoCallback, +} + +#[derive(Debug)] +struct Group { + group_handle: ZextWorkspaceGroupHandleV1, + workspaces: Vec, + outputs: Vec, +} + +#[derive(Debug)] +struct Workspace { + workspace_handle: ZextWorkspaceHandleV1, + name: Option, + is_focused: bool, + is_urgent: bool, +} + +impl ExtWorkspaceUnstable { + pub fn bind( + conn: &mut Connection, + globals: &Globals, + callback: WmInfoCallback, + ) -> Option { + let _: ZextWorkspaceManagerV1 = globals.bind_with_cb(conn, 1..=1, manager_cb).ok()?; + Some(Self { + groups: Vec::new(), + known_outputs: Vec::new(), + callback, + }) + } +} + +impl ExtWorkspaceUnstable { + pub fn new_ouput(&mut self, _: &mut Connection, output: WlOutput) { + self.known_outputs.push(output); + } + + pub fn output_removed(&mut self, _: &mut Connection, output: WlOutput) { + self.known_outputs.retain(|&o| o != output); + for group in &mut self.groups { + group.outputs.retain(|&id| id != output.id()); + } + } + + pub fn click_on_tag( + &mut self, + _: &mut Connection, + _: WlOutput, + _: WlSeat, + _: &str, + _: PointerBtn, + ) { + } +} + +fn manager_cb( + conn: &mut Connection, + s: &mut State, + _: ZextWorkspaceManagerV1, + event: zext_workspace_manager_v1::Event, +) { + let WmInfoProvider::EWU(state) = &mut s.shared_state.wm_info_provider else { unreachable!() }; + + match event { + zext_workspace_manager_v1::Event::WorkspaceGroup(group_handle) => { + conn.set_callback_for(group_handle, group_cb); + state.groups.push(Group { + group_handle, + workspaces: Vec::new(), + outputs: Vec::new(), + }); + } + zext_workspace_manager_v1::Event::Done => { + let mut events = Vec::new(); + for &output in &state.known_outputs { + if let Some(group) = state + .groups + .iter() + .find(|g| g.outputs.contains(&output.id())) + { + let mut tags: Vec<_> = group + .workspaces + .iter() + .flat_map(|w| { + let name = w.name.clone()?; + Some(Tag { + name, + is_focused: w.is_focused, + is_active: true, + is_urgent: w.is_urgent, + }) + }) + .collect(); + tags.sort_unstable_by(|a, b| a.name.cmp(&b.name)); + events.push((output, tags)); + } + } + + let cb = state.callback; + for (output, tags) in events { + let info = WmInfo { + layout_name: None, + tags, + }; + (cb)(conn, s, output, info); + } + } + zext_workspace_manager_v1::Event::Finished => unreachable!(), + } +} + +fn group_cb( + conn: &mut Connection, + state: &mut State, + group_handle: ZextWorkspaceGroupHandleV1, + event: zext_workspace_group_handle_v1::Event, +) { + let WmInfoProvider::EWU(state) = &mut state.shared_state.wm_info_provider else { unreachable!() }; + let group = state + .groups + .iter_mut() + .find(|g| g.group_handle == group_handle) + .unwrap(); + + match event { + zext_workspace_group_handle_v1::Event::OutputEnter(output) => { + group.outputs.push(output); + } + zext_workspace_group_handle_v1::Event::OutputLeave(_) => todo!(), + zext_workspace_group_handle_v1::Event::Workspace(workspace_handle) => { + conn.set_callback_for(workspace_handle, workspace_cb); + group.workspaces.push(Workspace { + workspace_handle, + name: None, + is_focused: false, + is_urgent: false, + }); + } + zext_workspace_group_handle_v1::Event::Remove => { + todo!(); + } + } +} + +fn workspace_cb( + conn: &mut Connection, + state: &mut State, + workspace_handle: ZextWorkspaceHandleV1, + event: zext_workspace_handle_v1::Event, +) { + let WmInfoProvider::EWU(state) = &mut state.shared_state.wm_info_provider else { unreachable!() }; + let group = state + .groups + .iter_mut() + .find(|g| { + g.workspaces + .iter() + .any(|w| w.workspace_handle == workspace_handle) + }) + .unwrap(); + let workspace = group + .workspaces + .iter_mut() + .find(|w| w.workspace_handle == workspace_handle) + .unwrap(); + + match event { + zext_workspace_handle_v1::Event::Name(name) => { + workspace.name = Some(name.to_string_lossy().into_owned()); + } + zext_workspace_handle_v1::Event::Coordinates(_) => (), + zext_workspace_handle_v1::Event::State(state) => { + workspace.is_focused = false; + workspace.is_urgent = false; + for state in state + .chunks_exact(4) + .map(|b| u32::from_ne_bytes(b.try_into().unwrap())) + { + workspace.is_focused |= state == zext_workspace_handle_v1::State::Active as u32; + workspace.is_urgent |= state == zext_workspace_handle_v1::State::Urgent as u32; + } + } + zext_workspace_handle_v1::Event::Remove => { + group + .workspaces + .retain(|w| w.workspace_handle != workspace_handle); + workspace_handle.destroy(conn); + } + } +} -- cgit v1.3.1 From fa9135b5d1a459f91ac47f5c03214d836475473c Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Mon, 17 Apr 2023 13:38:20 +0300 Subject: ext_workspace_unstable: send activate request even though it is ignored by hyprland --- src/pointer_btn.rs | 2 +- src/wm_info_provider/ext_workspace_unstable.rs | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/pointer_btn.rs b/src/pointer_btn.rs index 829fc9c..e5e0722 100644 --- a/src/pointer_btn.rs +++ b/src/pointer_btn.rs @@ -10,7 +10,7 @@ const BTN_FORWARD: u32 = 0x115; const BTN_BACK: u32 = 0x116; // const BTN_TASK: u32 = 0x117; -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum PointerBtn { Left, Middle, diff --git a/src/wm_info_provider/ext_workspace_unstable.rs b/src/wm_info_provider/ext_workspace_unstable.rs index 68238d0..dbf6bf7 100644 --- a/src/wm_info_provider/ext_workspace_unstable.rs +++ b/src/wm_info_provider/ext_workspace_unstable.rs @@ -57,12 +57,23 @@ impl ExtWorkspaceUnstable { pub fn click_on_tag( &mut self, - _: &mut Connection, + conn: &mut Connection, _: WlOutput, _: WlSeat, - _: &str, - _: PointerBtn, + tag: &str, + btn: PointerBtn, ) { + if btn != PointerBtn::Left { + return; + } + + let Some(ws) = self + .groups + .iter() + .find_map(|g| g.workspaces.iter().find(|w| w.name.as_deref() == Some(tag))) + else { return }; + + ws.workspace_handle.activate(conn); } } -- cgit v1.3.1 From 44fa43c97bb7a11311c7f860eb8cb2f94ace5216 Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Thu, 20 Apr 2023 14:17:03 +0300 Subject: temporary hack --- src/text.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/text.rs b/src/text.rs index 61bf5ca..bc1516d 100644 --- a/src/text.rs +++ b/src/text.rs @@ -106,7 +106,8 @@ impl ComputedText { context, 0.0, 0.0, - self.width + options.overlap, + // HACK: this `+ 0.5` fixes some artifacts of fractional scaling + self.width + options.overlap + 0.5, options.bar_height, options.r_left, options.r_right, -- cgit v1.3.1 From 0fa82a3280083c7ef098609990a7177625a4cbd4 Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Thu, 1 Jun 2023 13:53:04 +0300 Subject: hyprland: fix click-to-focus --- src/wm_info_provider/ext_workspace_unstable.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wm_info_provider/ext_workspace_unstable.rs b/src/wm_info_provider/ext_workspace_unstable.rs index dbf6bf7..7b482da 100644 --- a/src/wm_info_provider/ext_workspace_unstable.rs +++ b/src/wm_info_provider/ext_workspace_unstable.rs @@ -8,6 +8,7 @@ use crate::protocol::*; use crate::state::State; pub struct ExtWorkspaceUnstable { + manager: ZextWorkspaceManagerV1, groups: Vec, known_outputs: Vec, callback: WmInfoCallback, @@ -34,8 +35,8 @@ impl ExtWorkspaceUnstable { globals: &Globals, callback: WmInfoCallback, ) -> Option { - let _: ZextWorkspaceManagerV1 = globals.bind_with_cb(conn, 1..=1, manager_cb).ok()?; Some(Self { + manager: globals.bind_with_cb(conn, 1..=1, manager_cb).ok()?, groups: Vec::new(), known_outputs: Vec::new(), callback, @@ -74,6 +75,7 @@ impl ExtWorkspaceUnstable { else { return }; ws.workspace_handle.activate(conn); + self.manager.commit(conn); } } -- cgit v1.3.1 From 2c9bc7c4b6609bf6b840f6494618034a6dd3cafc Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Thu, 1 Jun 2023 13:55:13 +0300 Subject: fix clippy lint --- src/wm_info_provider.rs | 10 +++++----- src/wm_info_provider/ext_workspace_unstable.rs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/wm_info_provider.rs b/src/wm_info_provider.rs index 7f2d941..134bc77 100644 --- a/src/wm_info_provider.rs +++ b/src/wm_info_provider.rs @@ -13,7 +13,7 @@ use river::*; pub enum WmInfoProvider { None, River(RiverInfoProvider), - EWU(ExtWorkspaceUnstable), + Ewu(ExtWorkspaceUnstable), } pub type WmInfoCallback = fn(&mut Connection, &mut State, WlOutput, WmInfo); @@ -27,7 +27,7 @@ impl WmInfoProvider { if let Some(river) = RiverInfoProvider::bind(conn, globals, callback) { Self::River(river) } else if let Some(ext_wp_u) = ExtWorkspaceUnstable::bind(conn, globals, callback) { - Self::EWU(ext_wp_u) + Self::Ewu(ext_wp_u) } else { Self::None } @@ -37,7 +37,7 @@ impl WmInfoProvider { match self { Self::None => (), Self::River(x) => x.new_output(conn, output), - Self::EWU(x) => x.new_ouput(conn, output), + Self::Ewu(x) => x.new_ouput(conn, output), } } @@ -45,7 +45,7 @@ impl WmInfoProvider { match self { Self::None => (), Self::River(x) => x.output_removed(conn, output), - Self::EWU(x) => x.output_removed(conn, output), + Self::Ewu(x) => x.output_removed(conn, output), } } @@ -60,7 +60,7 @@ impl WmInfoProvider { match self { Self::None => (), Self::River(x) => x.click_on_tag(conn, output, seat, tag, btn), - Self::EWU(x) => x.click_on_tag(conn, output, seat, tag, btn), + Self::Ewu(x) => x.click_on_tag(conn, output, seat, tag, btn), } } } diff --git a/src/wm_info_provider/ext_workspace_unstable.rs b/src/wm_info_provider/ext_workspace_unstable.rs index 7b482da..793f78f 100644 --- a/src/wm_info_provider/ext_workspace_unstable.rs +++ b/src/wm_info_provider/ext_workspace_unstable.rs @@ -85,7 +85,7 @@ fn manager_cb( _: ZextWorkspaceManagerV1, event: zext_workspace_manager_v1::Event, ) { - let WmInfoProvider::EWU(state) = &mut s.shared_state.wm_info_provider else { unreachable!() }; + let WmInfoProvider::Ewu(state) = &mut s.shared_state.wm_info_provider else { unreachable!() }; match event { zext_workspace_manager_v1::Event::WorkspaceGroup(group_handle) => { @@ -141,7 +141,7 @@ fn group_cb( group_handle: ZextWorkspaceGroupHandleV1, event: zext_workspace_group_handle_v1::Event, ) { - let WmInfoProvider::EWU(state) = &mut state.shared_state.wm_info_provider else { unreachable!() }; + let WmInfoProvider::Ewu(state) = &mut state.shared_state.wm_info_provider else { unreachable!() }; let group = state .groups .iter_mut() @@ -174,7 +174,7 @@ fn workspace_cb( workspace_handle: ZextWorkspaceHandleV1, event: zext_workspace_handle_v1::Event, ) { - let WmInfoProvider::EWU(state) = &mut state.shared_state.wm_info_provider else { unreachable!() }; + let WmInfoProvider::Ewu(state) = &mut state.shared_state.wm_info_provider else { unreachable!() }; let group = state .groups .iter_mut() -- cgit v1.3.1 From 13c08ca31ee1ccbbeceb8962d739a077048d59ac Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Thu, 1 Jun 2023 16:32:34 +0300 Subject: pub hyprland support behind feature flag --- Cargo.toml | 3 +++ README.md | 4 ++++ src/protocol.rs | 2 ++ src/wm_info_provider.rs | 26 ++++++++++++++++++-------- src/wm_info_provider/ext_workspace_unstable.rs | 1 - src/wm_info_provider/river.rs | 1 - 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 68e91ec..d2ba84b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,9 @@ edition = "2021" license = "GPL-3.0-only" authors = ["MaxVerevkin "] +[features] +hyprland = [] + [dependencies] anyhow = "1" toml = { version = "0.7", default-features = false, features = ["parse"] } diff --git a/README.md b/README.md index 9fc5f2b..f1cf446 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,10 @@ A list of things that are missing (for now): - Support for rounded corners - Show/hide with `pkill -SIGUSR1 i3bar-river` +## Hyprland support + +Hyprland/wlr_ext_workspaces support is experimental and is behind `hyprland` feature flag. Build with `-F hyprland` to enable it. + ## Installation ### Arch diff --git a/src/protocol.rs b/src/protocol.rs index c393850..d14d92a 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -4,4 +4,6 @@ pub use wayrs_protocols::viewporter::*; pub use wayrs_protocols::wlr_layer_shell_unstable_v1::*; wayrs_client::scanner::generate!("protocols/river-status-unstable-v1.xml"); wayrs_client::scanner::generate!("protocols/river-control-unstable-v1.xml"); + +#[cfg(feature = "hyprland")] wayrs_client::scanner::generate!("protocols/ext-workspace-unstable-v1.xml"); diff --git a/src/wm_info_provider.rs b/src/wm_info_provider.rs index 134bc77..e11e48e 100644 --- a/src/wm_info_provider.rs +++ b/src/wm_info_provider.rs @@ -1,18 +1,22 @@ -mod ext_workspace_unstable; -mod river; - use wayrs_client::connection::Connection; use wayrs_client::global::*; use crate::pointer_btn::PointerBtn; use crate::protocol::*; use crate::state::State; + +#[cfg(feature = "hyprland")] +mod ext_workspace_unstable; +#[cfg(feature = "hyprland")] use ext_workspace_unstable::*; + +mod river; use river::*; pub enum WmInfoProvider { None, River(RiverInfoProvider), + #[cfg(feature = "hyprland")] Ewu(ExtWorkspaceUnstable), } @@ -25,18 +29,22 @@ impl WmInfoProvider { callback: WmInfoCallback, ) -> WmInfoProvider { if let Some(river) = RiverInfoProvider::bind(conn, globals, callback) { - Self::River(river) - } else if let Some(ext_wp_u) = ExtWorkspaceUnstable::bind(conn, globals, callback) { - Self::Ewu(ext_wp_u) - } else { - Self::None + return Self::River(river); } + + #[cfg(feature = "hyprland")] + if let Some(ext_wp_u) = ExtWorkspaceUnstable::bind(conn, globals, callback) { + return Self::Ewu(ext_wp_u); + } + + Self::None } pub fn new_ouput(&mut self, conn: &mut Connection, output: WlOutput) { match self { Self::None => (), Self::River(x) => x.new_output(conn, output), + #[cfg(feature = "hyprland")] Self::Ewu(x) => x.new_ouput(conn, output), } } @@ -45,6 +53,7 @@ impl WmInfoProvider { match self { Self::None => (), Self::River(x) => x.output_removed(conn, output), + #[cfg(feature = "hyprland")] Self::Ewu(x) => x.output_removed(conn, output), } } @@ -60,6 +69,7 @@ impl WmInfoProvider { match self { Self::None => (), Self::River(x) => x.click_on_tag(conn, output, seat, tag, btn), + #[cfg(feature = "hyprland")] Self::Ewu(x) => x.click_on_tag(conn, output, seat, tag, btn), } } diff --git a/src/wm_info_provider/ext_workspace_unstable.rs b/src/wm_info_provider/ext_workspace_unstable.rs index 793f78f..0af550b 100644 --- a/src/wm_info_provider/ext_workspace_unstable.rs +++ b/src/wm_info_provider/ext_workspace_unstable.rs @@ -4,7 +4,6 @@ use wayrs_client::object::ObjectId; use wayrs_client::proxy::Proxy; use super::*; -use crate::protocol::*; use crate::state::State; pub struct ExtWorkspaceUnstable { diff --git a/src/wm_info_provider/river.rs b/src/wm_info_provider/river.rs index c7740a3..82fa5d8 100644 --- a/src/wm_info_provider/river.rs +++ b/src/wm_info_provider/river.rs @@ -4,7 +4,6 @@ use wayrs_client::connection::Connection; use wayrs_client::{cstr, global::*}; use super::*; -use crate::protocol::*; use crate::state::State; pub struct RiverInfoProvider { -- cgit v1.3.1