From a4eb149816f09a7ce7b0ec90d5bd4da9f0b3727a Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Mon, 24 Mar 2025 12:22:02 +0000 Subject: [PATCH] build: decouple `workspace` and `keyboard` modules Fixes #862 --- src/clients/compositor/mod.rs | 12 +++++++++++- src/clients/mod.rs | 6 +++--- src/image/gtk.rs | 18 ++++++++++++++---- src/image/mod.rs | 9 +++++++-- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/clients/compositor/mod.rs b/src/clients/compositor/mod.rs index db45052..4c574fa 100644 --- a/src/clients/compositor/mod.rs +++ b/src/clients/compositor/mod.rs @@ -66,6 +66,7 @@ impl Compositor { } } + #[cfg(feature = "keyboard")] pub fn create_keyboard_layout_client( clients: &mut super::Clients, ) -> ClientResult { @@ -78,7 +79,11 @@ impl Compositor { .map(|client| client as Arc), #[cfg(feature = "keyboard+hyprland")] Self::Hyprland => Ok(clients.hyprland()), - Self::Niri | Self::Unsupported => Err(Report::msg("Unsupported compositor").note( + #[cfg(feature = "workspaces")] + Self::Niri => Err(Report::msg("Unsupported compositor").note( + "Currently keyboard layout functionality are only supported by Sway and Hyprland", + )), + Self::Unsupported => Err(Report::msg("Unsupported compositor").note( "Currently keyboard layout functionality are only supported by Sway and Hyprland", )), } @@ -86,6 +91,7 @@ impl Compositor { /// Creates a new instance of /// the workspace client for the current compositor. + #[cfg(feature = "workspaces")] pub fn create_workspace_client( clients: &mut super::Clients, ) -> Result> { @@ -183,6 +189,7 @@ pub enum WorkspaceUpdate { Unknown, } +#[cfg(feature = "workspaces")] pub trait WorkspaceClient: Debug + Send + Sync { /// Requests the workspace with this id is focused. fn focus(&self, id: i64); @@ -191,8 +198,10 @@ pub trait WorkspaceClient: Debug + Send + Sync { fn subscribe(&self) -> broadcast::Receiver; } +#[cfg(feature = "workspaces")] register_fallible_client!(dyn WorkspaceClient, workspaces); +#[cfg(feature = "keyboard")] pub trait KeyboardLayoutClient: Debug + Send + Sync { /// Switches to the next layout. fn set_next_active(&self); @@ -201,4 +210,5 @@ pub trait KeyboardLayoutClient: Debug + Send + Sync { fn subscribe(&self) -> broadcast::Receiver; } +#[cfg(feature = "keyboard")] register_fallible_client!(dyn KeyboardLayoutClient, keyboard_layout); diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 6410e80..5fab5a5 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -7,7 +7,7 @@ use std::sync::Arc; #[cfg(feature = "clipboard")] pub mod clipboard; -#[cfg(feature = "workspaces")] +#[cfg(any(feature = "keyboard", feature = "workspaces"))] pub mod compositor; #[cfg(feature = "keyboard")] pub mod libinput; @@ -46,7 +46,7 @@ pub struct Clients { clipboard: Option>, #[cfg(feature = "keyboard")] libinput: HashMap, Arc>, - #[cfg(any(feature = "keyboard+sway", feature = "keyboard+hyprland"))] + #[cfg(feature = "keyboard")] keyboard_layout: Option>, #[cfg(feature = "cairo")] lua: Option>, @@ -101,7 +101,7 @@ impl Clients { Ok(client) } - #[cfg(any(feature = "keyboard+sway", feature = "keyboard+hyprland"))] + #[cfg(feature = "keyboard")] pub fn keyboard_layout(&mut self) -> ClientResult { let client = if let Some(keyboard_layout) = &self.keyboard_layout { keyboard_layout.clone() diff --git a/src/image/gtk.rs b/src/image/gtk.rs index f2d2f83..687428e 100644 --- a/src/image/gtk.rs +++ b/src/image/gtk.rs @@ -4,14 +4,24 @@ use gtk::prelude::*; use gtk::{Button, IconTheme, Image, Label, Orientation}; use std::ops::Deref; -#[cfg(any(feature = "music", feature = "workspaces", feature = "clipboard"))] #[derive(Debug, Clone)] +#[cfg(any( + feature = "clipboard", + feature = "keyboard", + feature = "music", + feature = "workspaces" +))] pub struct IconButton { button: Button, label: Label, } -#[cfg(any(feature = "music", feature = "workspaces", feature = "clipboard"))] +#[cfg(any( + feature = "clipboard", + feature = "keyboard", + feature = "music", + feature = "workspaces" +))] impl IconButton { pub fn new(input: &str, icon_theme: &IconTheme, size: i32) -> Self { let button = Button::new(); @@ -55,7 +65,7 @@ impl Deref for IconButton { } } -#[cfg(any(feature = "music", feature = "keyboard"))] +#[cfg(any(feature = "keyboard", feature = "music", feature = "workspaces"))] pub struct IconLabel { container: gtk::Box, label: Label, @@ -65,7 +75,7 @@ pub struct IconLabel { size: i32, } -#[cfg(any(feature = "music", feature = "keyboard"))] +#[cfg(any(feature = "keyboard", feature = "music", feature = "workspaces"))] impl IconLabel { pub fn new(input: &str, icon_theme: &IconTheme, size: i32) -> Self { let container = gtk::Box::new(Orientation::Horizontal, 0); diff --git a/src/image/mod.rs b/src/image/mod.rs index b7dac37..c361cf3 100644 --- a/src/image/mod.rs +++ b/src/image/mod.rs @@ -1,7 +1,12 @@ -#[cfg(any(feature = "music", feature = "workspaces", feature = "clipboard"))] +#[cfg(any( + feature = "clipboard", + feature = "keyboard", + feature = "music", + feature = "workspaces" +))] mod gtk; mod provider; -#[cfg(any(feature = "music", feature = "workspaces"))] +#[cfg(any(feature = "keyboard", feature = "music", feature = "workspaces"))] pub use self::gtk::*; pub use provider::ImageProvider;