From b2ba3847cb98d5b82b129e35c2a3f759750b0e48 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 12:31:37 -0700 Subject: [PATCH] feat(core): WorkspaceWindow, what a workspace asks of a window A supertrait of ContainerWindow with the four lookups the shared workspace code makes (title, exe, class, path, each Option), for the functions that move into komorebi-core next. The crate's stub window implements it and a test checks the four answers. Nothing uses it yet. Verified: cargo test -p komorebi-core --features schemars (native): 16 passed, 0 failed. Not run: the daemons. --- crates/komorebi-core/src/container.rs | 46 +++++++++++++++++++++++++++ crates/komorebi-core/src/lib.rs | 1 + 2 files changed, 47 insertions(+) diff --git a/crates/komorebi-core/src/container.rs b/crates/komorebi-core/src/container.rs index 3b48d2f6..52301814 100644 --- a/crates/komorebi-core/src/container.rs +++ b/crates/komorebi-core/src/container.rs @@ -47,6 +47,24 @@ pub trait ContainerWindow: Copy + PartialEq { fn restore_stacked(&self); } +/// What a workspace asks of a platform window, besides what a container asks. +/// +/// The four lookups answer from what the platform knows about the window and are `None` when it +/// cannot say (the window is gone, or the platform has no source for the field). +pub trait WorkspaceWindow: ContainerWindow { + /// The window's title. + fn title(&self) -> Option; + + /// The file name of the executable that owns the window. + fn exe(&self) -> Option; + + /// The window class (the `app_id` on KDE, the Win32 class on Windows). + fn class(&self) -> Option; + + /// The full path of the executable that owns the window. + fn path(&self) -> Option; +} + /// A ring of windows that share one tile of a workspace's layout. /// /// The serialised form is `{"id", "locked", "windows": {"elements", "focused"}}`, which is what @@ -284,6 +302,34 @@ mod tests { } } + impl WorkspaceWindow for Stub { + fn title(&self) -> Option { + Some(format!("title{}", self.0)) + } + + fn exe(&self) -> Option { + self.exe_name() + } + + fn class(&self) -> Option { + Some("class".to_string()) + } + + fn path(&self) -> Option { + None + } + } + + #[test] + fn a_workspace_window_answers_the_four_lookups() { + let window = Stub(3); + + assert_eq!(window.title().as_deref(), Some("title3")); + assert_eq!(WorkspaceWindow::exe(&window).as_deref(), Some("exe3")); + assert_eq!(window.class().as_deref(), Some("class")); + assert_eq!(window.path(), None); + } + fn container_of(ids: &[u32]) -> Container { let mut container = Container::default(); for id in ids { diff --git a/crates/komorebi-core/src/lib.rs b/crates/komorebi-core/src/lib.rs index 9050f306..a2d5a46d 100644 --- a/crates/komorebi-core/src/lib.rs +++ b/crates/komorebi-core/src/lib.rs @@ -12,6 +12,7 @@ mod globals; pub use container::Container; pub use container::ContainerWindow; +pub use container::WorkspaceWindow; pub use globals::WorkspaceGlobals; pub use komorebi_collections::Lockable; pub use komorebi_collections::ring;