From 69073153d964a57194455539c357606899b741cc Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 09:54:46 -0700 Subject: [PATCH] refactor(windows): give Window the shared operation names Window already had focus, raise, hide, restore, minimize and close under the names of the shared Backend trait (docs/dev/seam.md section 2). Add the four that were missing as thin delegates: set_rect (set_position with top = false), alive (is_window), window_rect (WindowsApi::window_rect) and unminimize (WindowsApi::restore_window). No call site changes; the unused-by-the-daemon WindowsBackend now calls the new names. Not a behaviour change. Verified: Windows clippy -D warnings via tools/fast-check PASS. --- komorebi/src/window.rs | 25 +++++++++++++++++++++++++ komorebi/src/windows_backend.rs | 8 ++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index e864086e..576067a0 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -725,6 +725,31 @@ impl Window { WindowsApi::is_window(self.hwnd) } + // The operation names of the shared `komorebi_backend::Backend` (docs/dev/seam.md, section 2). + // `set_rect`, `alive`, `window_rect` and `unminimize` only delegate; `focus`, `raise`, `hide`, + // `restore`, `minimize` and `close` above already carry the shared name. + + /// Set frame: `set_position` without raising the window to the front. + pub fn set_rect(self, rect: &Rect) -> eyre::Result<()> { + self.set_position(rect, false) + } + + /// Alive check: Windows still has the window (`IsWindow`). + pub fn alive(self) -> bool { + self.is_window() + } + + /// Frame query: the visible bounds (without the shadow), see `WindowsApi::window_rect`. + pub fn window_rect(self) -> eyre::Result { + WindowsApi::window_rect(self.hwnd) + } + + /// Windows has no unminimize of its own: `SW_SHOWNOACTIVATE`, as `restore` ends in for the + /// `Hide` and `Minimize` hiding behaviours, without the `HIDDEN_HWNDS` and border bookkeeping. + pub fn unminimize(self) { + WindowsApi::restore_window(self.hwnd); + } + pub fn remove_title_bar(self) -> eyre::Result<()> { let mut style = self.style()?; style.remove(WindowStyle::CAPTION); diff --git a/komorebi/src/windows_backend.rs b/komorebi/src/windows_backend.rs index 7df5c753..b8d4b3b0 100644 --- a/komorebi/src/windows_backend.rs +++ b/komorebi/src/windows_backend.rs @@ -54,7 +54,7 @@ fn platform(report: eyre::Report) -> Error { impl WindowsBackend { fn info(window: Window) -> Option { let hwnd = window.hwnd; - if !WindowsApi::is_window(hwnd) { + if !window.alive() { return None; } @@ -63,7 +63,7 @@ impl WindowsBackend { pid: i32::try_from(window.process_id()).unwrap_or_default(), // Windows reports the visible bounds (without the shadow); an error leaves the // default, which a caller cannot tell from a window at the origin: see seam.md 9 - rect: WindowsApi::window_rect(hwnd).unwrap_or_default(), + rect: window.window_rect().unwrap_or_default(), minimized: window.is_miminized(), alive: true, title: window.title().ok(), @@ -136,7 +136,7 @@ impl Backend for WindowsBackend { // contract does not have: it is false here and a caller raises with `raise`. // `Window::set_position` also keeps its animation, slide-in and live-resize guards // and skips the write when the frame is already right: see seam.md 9. - window.set_position(rect, false).map_err(|e| failed(id, e)) + window.set_rect(rect).map_err(|e| failed(id, e)) } fn focus(&self, id: WindowId, mouse_follows_focus: bool) -> Result<()> { @@ -172,7 +172,7 @@ impl Backend for WindowsBackend { // for the `Hide` and `Minimize` hiding behaviours, and without the HIDDEN_HWNDS and // border bookkeeping of `Window::restore` live(id)?; - WindowsApi::restore_window(id.to_hwnd()); + Window::from(id.to_hwnd()).unminimize(); Ok(()) }