From 88afd37d3625a5ccb12960e2dde80c29a904feab Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 12:04:50 -0700 Subject: [PATCH] feat(core): WorkspaceGlobals moves into komorebi-core The plain data a monitor gives the workspaces it shows (padding, border width and offset, work area, offsets, floating layer behaviour), moved from komorebi-for-kde/komorebi/src/workspace.rs (the Windows struct is the same nine fields with the same derives) into komorebi-core, with the KDE doc comments and two unit tests. komorebi-core now depends on komorebi-config (for FloatingLayerBehaviour, default features off) and komorebi-layouts (for Rect); its schemars feature enables theirs. The struct derives JsonSchema under the feature, as Windows' did; a workspace skips the field when serialised and in its schema, so no schema changes. No daemon uses it yet: the next two revisions converge KDE and Windows. Verified: cargo test -p komorebi-core --features schemars (native): 15 passed, 0 failed. Not run: the daemons. --- Cargo.lock | 2 + crates/komorebi-core/Cargo.toml | 9 ++++- crates/komorebi-core/src/globals.rs | 61 +++++++++++++++++++++++++++++ crates/komorebi-core/src/lib.rs | 2 + 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 crates/komorebi-core/src/globals.rs diff --git a/Cargo.lock b/Cargo.lock index 6195435c..bc786b39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3496,6 +3496,8 @@ name = "komorebi-core" version = "0.1.42" dependencies = [ "komorebi-collections", + "komorebi-config", + "komorebi-layouts", "nanoid", "schemars 1.2.3", "serde", diff --git a/crates/komorebi-core/Cargo.toml b/crates/komorebi-core/Cargo.toml index 5dd1d918..f17a00e9 100644 --- a/crates/komorebi-core/Cargo.toml +++ b/crates/komorebi-core/Cargo.toml @@ -6,6 +6,8 @@ edition = "2024" [dependencies] komorebi-collections = { path = "../komorebi-collections" } +komorebi-config = { path = "../komorebi-config", default-features = false } +komorebi-layouts = { path = "../../komorebi-layouts" } nanoid = "0.5" schemars = { workspace = true, optional = true } serde = { workspace = true } @@ -16,4 +18,9 @@ serde_json = { workspace = true, features = ["preserve_order"] } [features] # derives `schemars::JsonSchema` for the model types -schemars = ["dep:schemars", "komorebi-collections/schemars"] +schemars = [ + "dep:schemars", + "komorebi-collections/schemars", + "komorebi-config/schemars", + "komorebi-layouts/schemars", +] diff --git a/crates/komorebi-core/src/globals.rs b/crates/komorebi-core/src/globals.rs new file mode 100644 index 00000000..470d0b91 --- /dev/null +++ b/crates/komorebi-core/src/globals.rs @@ -0,0 +1,61 @@ +//! [`WorkspaceGlobals`], what a monitor gives the workspaces it shows. + +use komorebi_config::behaviour::FloatingLayerBehaviour; +use komorebi_layouts::Rect; +use serde::Deserialize; +use serde::Serialize; + +/// The work area a monitor gives the workspace it shows, the padding and the offset the workspace +/// falls back to when it sets none of its own, the monitor's window-based offset, and the room +/// around each window that a border takes. +/// +/// Set by the parent monitor or by the window manager, never read from a file: a workspace skips +/// it when it is serialised. +#[derive(Debug, Default, Copy, Clone, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +pub struct WorkspaceGlobals { + /// The container padding of the monitor. + pub container_padding: Option, + /// The workspace padding of the monitor. + pub workspace_padding: Option, + /// The width of the border around each window, 0 when none is drawn. + pub border_width: i32, + /// The offset of the border from the window. + pub border_offset: i32, + /// The work area of the monitor. + pub work_area: Rect, + /// The offset of the work area, if any. + pub work_area_offset: Option, + /// The offset the monitor has asked for according to its windows. + pub window_based_work_area_offset: Option, + /// The most windows the window-based offset is applied for. + pub window_based_work_area_offset_limit: isize, + /// The floating layer behaviour of the monitor, which the workspace's own overrides + pub floating_layer_behaviour: Option, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn the_default_globals_ask_for_nothing() { + let globals = WorkspaceGlobals::default(); + + assert_eq!(globals.container_padding, None); + assert_eq!(globals.border_width, 0); + assert_eq!(globals.work_area, Rect::default()); + assert_eq!(globals.window_based_work_area_offset_limit, 0); + } + + #[test] + fn globals_are_a_copy_that_compares_by_value() { + let a = WorkspaceGlobals { + border_width: 8, + ..Default::default() + }; + let b = a; + + assert_eq!(a, b); + } +} diff --git a/crates/komorebi-core/src/lib.rs b/crates/komorebi-core/src/lib.rs index e96cf123..9050f306 100644 --- a/crates/komorebi-core/src/lib.rs +++ b/crates/komorebi-core/src/lib.rs @@ -8,8 +8,10 @@ #![deny(missing_docs)] mod container; +mod globals; pub use container::Container; pub use container::ContainerWindow; +pub use globals::WorkspaceGlobals; pub use komorebi_collections::Lockable; pub use komorebi_collections::ring;