From 4c0f34d7ef3d083a3db21820b3803c5fb273a528 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sun, 2 Nov 2025 10:32:56 -0800 Subject: [PATCH] fix(wm): simplify stack-all command Implements the equivalent of https://github.com/LGUG2Z/komorebi/commit/18ee6678962bc31a39ce59fd4a1f6a9ee752ac5c This commit makes the `stack-all` command simpler, by simply making a `VecDeque` with all the tiled windows of the workspace, then it creates a new container with that `VecDeque` and changes the workspace containers to be just this new container which has all the windows in it. Then and only then do we focus and show the previously focused window and hide all the rest. This way we don't have a bunch of `FocusChange`/`Cloak`/`Uncloak` events coming up which might conflict with each other when the user has transparency and animations enabled. With this commit, there will only be one focus event for the focused window and one cloak event for each of the other windows. --- komorebi/src/window_manager.rs | 35 ++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 6ce82a8c..34a3f1c4 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -50,6 +50,7 @@ use objc2_core_foundation::CFRunLoop; use parking_lot::Mutex; use std::collections::HashMap; use std::collections::HashSet; +use std::collections::VecDeque; use std::collections::hash_map::Entry; use std::io::ErrorKind; use std::net::Shutdown; @@ -2279,29 +2280,39 @@ impl WindowManager { #[tracing::instrument(skip(self))] pub fn stack_all(&mut self) -> eyre::Result<()> { - self.unstack_all(false)?; - tracing::info!("stacking all windows on workspace"); let workspace = self.focused_workspace_mut()?; + let window_hiding_position = workspace.globals.window_hiding_position; - let mut focused_window_id = None; + let mut focused_hwnd = None; if let Some(container) = workspace.focused_container() && let Some(window) = container.focused_window() { - focused_window_id = Some(window.id); + focused_hwnd = Some(window.id); } - workspace.focus_container(workspace.containers().len().saturating_sub(1)); - while workspace.focused_container_idx() > 0 { - workspace.move_window_to_container(0)?; - workspace.focus_container(workspace.containers().len().saturating_sub(1)); - } + let workspace_hwnds = + workspace + .containers() + .iter() + .fold(VecDeque::new(), |mut hwnds, c| { + hwnds.extend(c.windows().clone()); + hwnds + }); - if let Some(window_id) = focused_window_id { - workspace.focus_container_by_window(window_id)?; - } + let mut container = Container::default(); + *container.windows_mut() = workspace_hwnds; + *workspace.containers_mut() = VecDeque::from([container]); + workspace.focus_container(0); + if let Some(hwnd) = focused_hwnd + && let Some(c) = workspace.focused_container_mut() + && let Some(w_idx_to_focus) = c.idx_for_window(hwnd) + { + c.focus_window(w_idx_to_focus); + c.load_focused_window(window_hiding_position)?; + } self.update_focused_workspace(self.mouse_follows_focus, true) }