From fad90dbd3eda707603aba7dfe75edc5b6f30a187 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 10:11:28 -0700 Subject: [PATCH] refactor(windows): plain hide and restore go through backend() The 23 window.hide() and window.restore() calls (container, workspace, monitor, process_command, process_event, window_manager) become let _ = backend().hide(..) / restore(..): WindowsBackend runs Window::hide and Window::restore, so hiding behaviour (cloak, hide, minimize), border and HIDDEN_HWNDS bookkeeping are the same. Not switched: hide_with_border and restore_with_border (the shared trait has no border flag), the animation transition and ghost dispatcher calls (they run inside the slide-in machinery), minimize, close, raise and maximize (to follow). BEHAVIOUR: a window that is already gone is skipped (IsWindow first), so it is no longer added to HIDDEN_HWNDS or shown; the result is ignored as before. e2e gate needed: commands, workspaces, stacking, lifecycle_hidden, minimize/monitor scenarios. Verified: Windows clippy -D warnings via tools/fast-check PASS; e2e not run. --- komorebi/src/container.rs | 8 +++++--- komorebi/src/monitor.rs | 4 +++- komorebi/src/process_command.rs | 6 +++--- komorebi/src/process_event.rs | 6 +++--- komorebi/src/window_manager.rs | 10 +++++----- komorebi/src/workspace.rs | 14 +++++++------- 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/komorebi/src/container.rs b/komorebi/src/container.rs index 2e56eef1..ebb9707a 100644 --- a/komorebi/src/container.rs +++ b/komorebi/src/container.rs @@ -5,6 +5,8 @@ use serde::Serialize; use crate::Lockable; use crate::ring::Ring; use crate::window::Window; +use crate::windows_backend::backend; +use komorebi_backend::WindowId; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] @@ -63,14 +65,14 @@ impl Container { } if should_hide { - window.hide(); + let _ = backend().hide(WindowId::from_hwnd(window.hwnd)); } } } pub fn restore(&self) { if let Some(window) = self.focused_window() { - window.restore(); + let _ = backend().restore(WindowId::from_hwnd(window.hwnd)); } } @@ -151,7 +153,7 @@ impl Container { for (i, window) in self.windows().iter().enumerate() { if i != focused_window_idx { - window.hide(); + let _ = backend().hide(WindowId::from_hwnd(window.hwnd)); } } } diff --git a/komorebi/src/monitor.rs b/komorebi/src/monitor.rs index 945c70ae..ee4d2c53 100644 --- a/komorebi/src/monitor.rs +++ b/komorebi/src/monitor.rs @@ -12,6 +12,8 @@ use crate::border_manager::BORDER_ENABLED; use crate::border_manager::BORDER_OFFSET; use crate::border_manager::BORDER_WIDTH; use crate::core::Rect; +use crate::windows_backend::backend; +use komorebi_backend::WindowId; use crate::DEFAULT_CONTAINER_PADDING; use crate::DEFAULT_WORKSPACE_PADDING; @@ -438,7 +440,7 @@ impl Monitor { } for window in target_workspace.floating_windows_mut() { - window.restore(); + let _ = backend().restore(WindowId::from_hwnd(window.hwnd)); } target_workspace.reintegrate_monocle_container()?; diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index a3fd6d66..e81d69c3 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -1308,7 +1308,7 @@ impl WindowManager { if i == focused_idx { to_focus = Some(*window); } else { - window.restore(); + let _ = backend().restore(WindowId::from_hwnd(window.hwnd)); window.raise()?; } } @@ -1316,7 +1316,7 @@ impl WindowManager { if let Some(focused_window) = &to_focus { // The focused window should be the last one raised to make sure it is // on top - focused_window.restore(); + let _ = backend().restore(WindowId::from_hwnd(focused_window.hwnd)); focused_window.raise()?; } @@ -1341,7 +1341,7 @@ impl WindowManager { window.raise()?; } for window in workspace.floating_windows() { - window.hide(); + let _ = backend().hide(WindowId::from_hwnd(window.hwnd)); } } else { let focused_container_idx = workspace.focused_container_idx(); diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index bb011c40..6c00c302 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -511,7 +511,7 @@ impl WindowManager { "ignoring show event for window already associated with another workspace" ); - window.hide(); + let _ = backend().hide(WindowId::from_hwnd(window.hwnd)); proceed = false; } @@ -643,7 +643,7 @@ impl WindowManager { if !(monocle_window_event || workspace.layer != WorkspaceLayer::Tiling) && monocle_container.is_some() { - window.hide(); + let _ = backend().hide(WindowId::from_hwnd(window.hwnd)); } } } @@ -1063,7 +1063,7 @@ impl WindowManager { container.restore(); } for window in workspace.floating_windows_mut() { - window.restore(); + let _ = backend().restore(WindowId::from_hwnd(window.hwnd)); } workspace.reintegrate_monocle_container()?; } diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 15d02218..85bc4fea 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -702,7 +702,7 @@ impl WindowManager { // Hide the window we are about to remove if it is on the currently focused workspace if op.is_origin(focused_monitor_idx, focused_workspace_idx) { - window.hide(); + let _ = backend().hide(WindowId::from_hwnd(window.hwnd)); should_update_focused_workspace = true; } @@ -1510,7 +1510,7 @@ impl WindowManager { } if !ignore_restore { - window.restore(); + let _ = backend().restore(WindowId::from_hwnd(window.hwnd)); } } } @@ -1758,7 +1758,7 @@ impl WindowManager { } for window in target_workspace.floating_windows_mut() { - window.restore(); + let _ = backend().restore(WindowId::from_hwnd(window.hwnd)); } target_workspace.reintegrate_monocle_container()?; @@ -3160,7 +3160,7 @@ impl WindowManager { } for window in workspace.floating_windows_mut() { - window.hide(); + let _ = backend().hide(WindowId::from_hwnd(window.hwnd)); } Ok(()) @@ -3177,7 +3177,7 @@ impl WindowManager { } for window in workspace.floating_windows_mut() { - window.restore(); + let _ = backend().restore(WindowId::from_hwnd(window.hwnd)); } workspace.reintegrate_monocle_container() diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index dd242c4d..ec69d747 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -408,7 +408,7 @@ impl Workspace { } if should_hide { - window.hide(); + let _ = backend().hide(WindowId::from_hwnd(window.hwnd)); } } @@ -417,7 +417,7 @@ impl Workspace { } if let Some(window) = self.maximized_window { - window.hide(); + let _ = backend().hide(WindowId::from_hwnd(window.hwnd)); } if let Some(container) = &self.monocle_container { @@ -577,7 +577,7 @@ impl Workspace { } for window in self.floating_windows() { - window.restore(); + let _ = backend().restore(WindowId::from_hwnd(window.hwnd)); } // Do this here to make sure that an error doesn't stop the restoration of other windows @@ -587,7 +587,7 @@ impl Workspace { if self.maximized_window.is_none() && matches!(self.layer, WorkspaceLayer::Tiling) { backend().focus(WindowId::from_hwnd(window.hwnd), mouse_follows_focus)?; } else if let Some(maximized_window) = self.maximized_window { - maximized_window.restore(); + let _ = backend().restore(WindowId::from_hwnd(maximized_window.hwnd)); backend().focus( WindowId::from_hwnd(maximized_window.hwnd), mouse_follows_focus, @@ -599,7 +599,7 @@ impl Workspace { )?; } } else if let Some(maximized_window) = self.maximized_window { - maximized_window.restore(); + let _ = backend().restore(WindowId::from_hwnd(maximized_window.hwnd)); backend().focus( WindowId::from_hwnd(maximized_window.hwnd), mouse_follows_focus, @@ -840,14 +840,14 @@ impl Workspace { } if hidden.get(i).copied().unwrap_or_default() { // it is seen on another monitor wherever it rests here - window.hide(); + let _ = backend().hide(WindowId::from_hwnd(window.hwnd)); } else { if crate::scrolling::should_restore_when_placed( window.hwnd, container.focused_window().map(|w| w.hwnd), &HIDDEN_HWNDS.lock(), ) { - window.restore(); + let _ = backend().restore(WindowId::from_hwnd(window.hwnd)); } backend().set_rect(WindowId::from_hwnd(window.hwnd), layout)?;