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;