From 98c5ab3b9b24d74c16adfafae93ae0dccfc3fa3c Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Wed, 4 Jun 2025 15:51:03 -0700 Subject: [PATCH] fix(wm): prevent stack-all issues with n>1 stacks on ws This commit ensures that unstack_all is called on a workspace before attempting to proceed with stack_all to avoid stacking loops that can occur when there are multiple pre-existing stacks already created on the workspace. --- komorebi/src/process_command.rs | 2 +- komorebi/src/window_manager.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 13d41ca7..42a5f51a 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -349,7 +349,7 @@ impl WindowManager { SocketMessage::StackWindow(direction) => self.add_window_to_container(direction)?, SocketMessage::UnstackWindow => self.remove_window_from_container()?, SocketMessage::StackAll => self.stack_all()?, - SocketMessage::UnstackAll => self.unstack_all()?, + SocketMessage::UnstackAll => self.unstack_all(true)?, SocketMessage::CycleStack(direction) => { self.cycle_container_window_in_direction(direction)?; } diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 4b7d71dc..4ea65707 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -2960,6 +2960,8 @@ impl WindowManager { #[tracing::instrument(skip(self))] pub fn stack_all(&mut self) -> Result<()> { + self.unstack_all(false)?; + self.handle_unmanaged_window_behaviour()?; tracing::info!("stacking all windows on workspace"); @@ -2986,7 +2988,7 @@ impl WindowManager { } #[tracing::instrument(skip(self))] - pub fn unstack_all(&mut self) -> Result<()> { + pub fn unstack_all(&mut self, update_workspace: bool) -> Result<()> { self.handle_unmanaged_window_behaviour()?; tracing::info!("unstacking all windows in container"); @@ -3016,7 +3018,11 @@ impl WindowManager { workspace.focus_container_by_window(hwnd)?; } - self.update_focused_workspace(self.mouse_follows_focus, true) + if update_workspace { + self.update_focused_workspace(self.mouse_follows_focus, true)?; + } + + Ok(()) } #[tracing::instrument(skip(self))]