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

feat(workspaces): niri support

Co-authored-by: Jake Stanger <mail@jstanger.dev>
This commit is contained in:
Anant Sharma 2024-09-08 18:44:54 +01:00 committed by Jake Stanger
parent 57bfab1dcc
commit 02a8ddabf0
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
12 changed files with 367 additions and 31 deletions

View file

@ -8,6 +8,8 @@ use tracing::debug;
#[cfg(feature = "workspaces+hyprland")]
pub mod hyprland;
#[cfg(feature = "workspaces+niri")]
pub mod niri;
#[cfg(feature = "workspaces+sway")]
pub mod sway;
@ -16,6 +18,8 @@ pub enum Compositor {
Sway,
#[cfg(feature = "workspaces+hyprland")]
Hyprland,
#[cfg(feature = "workspaces+niri")]
Niri,
Unsupported,
}
@ -29,6 +33,8 @@ impl Display for Compositor {
Self::Sway => "Sway",
#[cfg(feature = "workspaces+hyprland")]
Self::Hyprland => "Hyprland",
#[cfg(feature = "workspaces+niri")]
Self::Niri => "Niri",
Self::Unsupported => "Unsupported",
}
)
@ -49,6 +55,11 @@ impl Compositor {
if #[cfg(feature = "workspaces+hyprland")] { Self::Hyprland }
else { tracing::error!("Not compiled with Hyprland support"); Self::Unsupported }
}
} else if std::env::var("NIRI_SOCKET").is_ok() {
cfg_if! {
if #[cfg(feature = "workspaces+niri")] { Self::Niri }
else {tracing::error!("Not compiled with Niri support"); Self::Unsupported }
}
} else {
Self::Unsupported
}
@ -68,7 +79,7 @@ impl Compositor {
Self::Hyprland => clients
.hyprland()
.map(|client| client as Arc<dyn KeyboardLayoutClient + Send + Sync>),
Self::Unsupported => Err(Report::msg("Unsupported compositor").note(
Self::Niri | Self::Unsupported => Err(Report::msg("Unsupported compositor").note(
"Currently keyboard layout functionality are only supported by Sway and Hyprland",
)),
}
@ -90,8 +101,10 @@ impl Compositor {
Self::Hyprland => clients
.hyprland()
.map(|client| client as Arc<dyn WorkspaceClient + Send + Sync>),
#[cfg(feature = "workspaces+niri")]
Self::Niri => Ok(Arc::new(niri::Client::new())),
Self::Unsupported => Err(Report::msg("Unsupported compositor")
.note("Currently workspaces are only supported by Sway and Hyprland")),
.note("Currently workspaces are only supported by Sway, Niri and Hyprland")),
}
}
}
@ -125,6 +138,10 @@ impl Visibility {
Self::Visible { focused: true }
}
pub fn is_visible(self) -> bool {
matches!(self, Self::Visible { .. })
}
pub fn is_focused(self) -> bool {
if let Self::Visible { focused } = self {
focused
@ -170,8 +187,8 @@ pub enum WorkspaceUpdate {
}
pub trait WorkspaceClient: Debug + Send + Sync {
/// Requests the workspace with this name is focused.
fn focus(&self, name: String);
/// Requests the workspace with this id is focused.
fn focus(&self, id: i64);
/// Creates a new to workspace event receiver.
fn subscribe(&self) -> broadcast::Receiver<WorkspaceUpdate>;