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

feat(keyboard): ability to display and switch kb layout (#836)

This extends the existing `keys` module to be able to show the current keyboard layout, and cycle between layouts (using the `next` command) by clicking. The `keys` module has been renamed to `keyboard` to more accurately reflect its extended featureset.
This commit is contained in:
kuzy000 2025-02-04 00:19:30 +03:00 committed by GitHub
parent ee19176a2c
commit 03e6f10141
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 552 additions and 202 deletions

View file

@ -54,6 +54,26 @@ impl Compositor {
}
}
pub fn create_keyboard_layout_client(
clients: &mut super::Clients,
) -> Result<Arc<dyn KeyboardLayoutClient + Send + Sync>> {
let current = Self::get_current();
debug!("Getting keyboard_layout client for: {current}");
match current {
#[cfg(feature = "keyboard+sway")]
Self::Sway => clients
.sway()
.map(|client| client as Arc<dyn KeyboardLayoutClient + Send + Sync>),
#[cfg(feature = "keyboard+hyprland")]
Self::Hyprland => clients
.hyprland()
.map(|client| client as Arc<dyn KeyboardLayoutClient + Send + Sync>),
Self::Unsupported => Err(Report::msg("Unsupported compositor").note(
"Currently keyboard layout functionality are only supported by Sway and Hyprland",
)),
}
}
/// Creates a new instance of
/// the workspace client for the current compositor.
pub fn create_workspace_client(
@ -67,7 +87,9 @@ impl Compositor {
.sway()
.map(|client| client as Arc<dyn WorkspaceClient + Send + Sync>),
#[cfg(feature = "workspaces+hyprland")]
Self::Hyprland => Ok(Arc::new(hyprland::Client::new())),
Self::Hyprland => clients
.hyprland()
.map(|client| client as Arc<dyn WorkspaceClient + Send + Sync>),
Self::Unsupported => Err(Report::msg("Unsupported compositor")
.note("Currently workspaces are only supported by Sway and Hyprland")),
}
@ -112,6 +134,9 @@ impl Visibility {
}
}
#[derive(Debug, Clone)]
pub struct KeyboardLayoutUpdate(pub String);
#[derive(Debug, Clone)]
pub enum WorkspaceUpdate {
/// Provides an initial list of workspaces.
@ -146,10 +171,20 @@ pub enum WorkspaceUpdate {
pub trait WorkspaceClient: Debug + Send + Sync {
/// Requests the workspace with this name is focused.
fn focus(&self, name: String) -> Result<()>;
fn focus(&self, name: String);
/// Creates a new to workspace event receiver.
fn subscribe_workspace_change(&self) -> broadcast::Receiver<WorkspaceUpdate>;
fn subscribe(&self) -> broadcast::Receiver<WorkspaceUpdate>;
}
register_fallible_client!(dyn WorkspaceClient, workspaces);
pub trait KeyboardLayoutClient: Debug + Send + Sync {
/// Switches to the next layout.
fn set_next_active(&self);
/// Creates a new to keyboard layout event receiver.
fn subscribe(&self) -> broadcast::Receiver<KeyboardLayoutUpdate>;
}
register_fallible_client!(dyn KeyboardLayoutClient, keyboard_layout);