mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 13:51:19 +01:00
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<String>), 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.
This commit is contained in:
1 parent
e4d97c87ed
commit
b2ba3847cb
2 files changed
+47
No files matched your search
@@ -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<String>;
|
||||
|
||||
/// The file name of the executable that owns the window.
|
||||
fn exe(&self) -> Option<String>;
|
||||
|
||||
/// The window class (the `app_id` on KDE, the Win32 class on Windows).
|
||||
fn class(&self) -> Option<String>;
|
||||
|
||||
/// The full path of the executable that owns the window.
|
||||
fn path(&self) -> Option<String>;
|
||||
}
|
||||
|
||||
/// 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<String> {
|
||||
Some(format!("title{}", self.0))
|
||||
}
|
||||
|
||||
fn exe(&self) -> Option<String> {
|
||||
self.exe_name()
|
||||
}
|
||||
|
||||
fn class(&self) -> Option<String> {
|
||||
Some("class".to_string())
|
||||
}
|
||||
|
||||
fn path(&self) -> Option<String> {
|
||||
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<Stub> {
|
||||
let mut container = Container::default();
|
||||
for id in ids {
|
||||
|
||||
@@ -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;
|
||||
Reference in new issue
Block a user