1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-08-17 14:51:04 +02:00

Merge pull request #910 from JakeStanger/build/workspace-keyboard

build: decouple `workspace` and `keyboard` modules
This commit is contained in:
Jake Stanger 2025-03-24 12:26:50 +00:00 committed by GitHub
commit 66bdac52d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 35 additions and 10 deletions

View file

@ -66,6 +66,7 @@ impl Compositor {
} }
} }
#[cfg(feature = "keyboard")]
pub fn create_keyboard_layout_client( pub fn create_keyboard_layout_client(
clients: &mut super::Clients, clients: &mut super::Clients,
) -> ClientResult<dyn KeyboardLayoutClient + Send + Sync> { ) -> ClientResult<dyn KeyboardLayoutClient + Send + Sync> {
@ -78,7 +79,11 @@ impl Compositor {
.map(|client| client as Arc<dyn KeyboardLayoutClient + Send + Sync>), .map(|client| client as Arc<dyn KeyboardLayoutClient + Send + Sync>),
#[cfg(feature = "keyboard+hyprland")] #[cfg(feature = "keyboard+hyprland")]
Self::Hyprland => Ok(clients.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", "Currently keyboard layout functionality are only supported by Sway and Hyprland",
)), )),
} }
@ -86,6 +91,7 @@ impl Compositor {
/// Creates a new instance of /// Creates a new instance of
/// the workspace client for the current compositor. /// the workspace client for the current compositor.
#[cfg(feature = "workspaces")]
pub fn create_workspace_client( pub fn create_workspace_client(
clients: &mut super::Clients, clients: &mut super::Clients,
) -> Result<Arc<dyn WorkspaceClient + Send + Sync>> { ) -> Result<Arc<dyn WorkspaceClient + Send + Sync>> {
@ -183,6 +189,7 @@ pub enum WorkspaceUpdate {
Unknown, Unknown,
} }
#[cfg(feature = "workspaces")]
pub trait WorkspaceClient: Debug + Send + Sync { pub trait WorkspaceClient: Debug + Send + Sync {
/// Requests the workspace with this id is focused. /// Requests the workspace with this id is focused.
fn focus(&self, id: i64); fn focus(&self, id: i64);
@ -191,8 +198,10 @@ pub trait WorkspaceClient: Debug + Send + Sync {
fn subscribe(&self) -> broadcast::Receiver<WorkspaceUpdate>; fn subscribe(&self) -> broadcast::Receiver<WorkspaceUpdate>;
} }
#[cfg(feature = "workspaces")]
register_fallible_client!(dyn WorkspaceClient, workspaces); register_fallible_client!(dyn WorkspaceClient, workspaces);
#[cfg(feature = "keyboard")]
pub trait KeyboardLayoutClient: Debug + Send + Sync { pub trait KeyboardLayoutClient: Debug + Send + Sync {
/// Switches to the next layout. /// Switches to the next layout.
fn set_next_active(&self); fn set_next_active(&self);
@ -201,4 +210,5 @@ pub trait KeyboardLayoutClient: Debug + Send + Sync {
fn subscribe(&self) -> broadcast::Receiver<KeyboardLayoutUpdate>; fn subscribe(&self) -> broadcast::Receiver<KeyboardLayoutUpdate>;
} }
#[cfg(feature = "keyboard")]
register_fallible_client!(dyn KeyboardLayoutClient, keyboard_layout); register_fallible_client!(dyn KeyboardLayoutClient, keyboard_layout);

View file

@ -7,7 +7,7 @@ use std::sync::Arc;
#[cfg(feature = "clipboard")] #[cfg(feature = "clipboard")]
pub mod clipboard; pub mod clipboard;
#[cfg(feature = "workspaces")] #[cfg(any(feature = "keyboard", feature = "workspaces"))]
pub mod compositor; pub mod compositor;
#[cfg(feature = "keyboard")] #[cfg(feature = "keyboard")]
pub mod libinput; pub mod libinput;
@ -46,7 +46,7 @@ pub struct Clients {
clipboard: Option<Arc<clipboard::Client>>, clipboard: Option<Arc<clipboard::Client>>,
#[cfg(feature = "keyboard")] #[cfg(feature = "keyboard")]
libinput: HashMap<Box<str>, Arc<libinput::Client>>, libinput: HashMap<Box<str>, Arc<libinput::Client>>,
#[cfg(any(feature = "keyboard+sway", feature = "keyboard+hyprland"))] #[cfg(feature = "keyboard")]
keyboard_layout: Option<Arc<dyn compositor::KeyboardLayoutClient>>, keyboard_layout: Option<Arc<dyn compositor::KeyboardLayoutClient>>,
#[cfg(feature = "cairo")] #[cfg(feature = "cairo")]
lua: Option<Rc<lua::LuaEngine>>, lua: Option<Rc<lua::LuaEngine>>,
@ -101,7 +101,7 @@ impl Clients {
Ok(client) Ok(client)
} }
#[cfg(any(feature = "keyboard+sway", feature = "keyboard+hyprland"))] #[cfg(feature = "keyboard")]
pub fn keyboard_layout(&mut self) -> ClientResult<dyn compositor::KeyboardLayoutClient> { pub fn keyboard_layout(&mut self) -> ClientResult<dyn compositor::KeyboardLayoutClient> {
let client = if let Some(keyboard_layout) = &self.keyboard_layout { let client = if let Some(keyboard_layout) = &self.keyboard_layout {
keyboard_layout.clone() keyboard_layout.clone()

View file

@ -4,14 +4,24 @@ use gtk::prelude::*;
use gtk::{Button, IconTheme, Image, Label, Orientation}; use gtk::{Button, IconTheme, Image, Label, Orientation};
use std::ops::Deref; use std::ops::Deref;
#[cfg(any(feature = "music", feature = "workspaces", feature = "clipboard"))]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[cfg(any(
feature = "clipboard",
feature = "keyboard",
feature = "music",
feature = "workspaces"
))]
pub struct IconButton { pub struct IconButton {
button: Button, button: Button,
label: Label, label: Label,
} }
#[cfg(any(feature = "music", feature = "workspaces", feature = "clipboard"))] #[cfg(any(
feature = "clipboard",
feature = "keyboard",
feature = "music",
feature = "workspaces"
))]
impl IconButton { impl IconButton {
pub fn new(input: &str, icon_theme: &IconTheme, size: i32) -> Self { pub fn new(input: &str, icon_theme: &IconTheme, size: i32) -> Self {
let button = Button::new(); 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 { pub struct IconLabel {
container: gtk::Box, container: gtk::Box,
label: Label, label: Label,
@ -65,7 +75,7 @@ pub struct IconLabel {
size: i32, size: i32,
} }
#[cfg(any(feature = "music", feature = "keyboard"))] #[cfg(any(feature = "keyboard", feature = "music", feature = "workspaces"))]
impl IconLabel { impl IconLabel {
pub fn new(input: &str, icon_theme: &IconTheme, size: i32) -> Self { pub fn new(input: &str, icon_theme: &IconTheme, size: i32) -> Self {
let container = gtk::Box::new(Orientation::Horizontal, 0); let container = gtk::Box::new(Orientation::Horizontal, 0);

View file

@ -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 gtk;
mod provider; mod provider;
#[cfg(any(feature = "music", feature = "workspaces"))] #[cfg(any(feature = "keyboard", feature = "music", feature = "workspaces"))]
pub use self::gtk::*; pub use self::gtk::*;
pub use provider::ImageProvider; pub use provider::ImageProvider;