From 9f16894a09e4793fe7c1a29bd70e2c0bb3adf240 Mon Sep 17 00:00:00 2001 From: alex-ds13 <145657253+alex-ds13@users.noreply.github.com> Date: Mon, 17 Mar 2025 11:09:38 +0000 Subject: [PATCH] fix(wm): correct workspace restore + remove workarounds This commit removes some workarounds on the `update_focused_workspace` function that were there to fix issues related to some bugs on the `workspace.restore()` function. This commit fixes the bugs on the `restore` function instead. The `update_focused_workspace` function should be used only to update a workspace layout. --- komorebi/src/window_manager.rs | 20 -------------------- komorebi/src/workspace.rs | 8 +++++++- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index fa5d2a17..fd353800 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -1383,26 +1383,6 @@ impl WindowManager { } } } - - // This is to correctly restore and focus when switching to a workspace which - // contains a managed maximized window - if let Some(window) = self.focused_workspace()?.maximized_window() { - window.restore(); - if trigger_focus { - window.focus(self.mouse_follows_focus)?; - } - } - - // This is to correctly remove focus from the previous when changing focused workspace - // to a workspace which only contains floating windows and no other kind of managed window - if self.focused_workspace()?.containers().is_empty() - && self.focused_workspace()?.monocle_container().is_none() - && self.focused_workspace()?.maximized_window().is_none() - { - if let Some(window) = self.focused_workspace()?.floating_windows().first() { - window.focus(self.mouse_follows_focus)?; - } - } } Ok(()) diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 68e7cca5..1fdfe37a 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -282,7 +282,7 @@ impl Workspace { } pub fn restore(&mut self, mouse_follows_focus: bool) -> Result<()> { - if let Some(container) = self.monocle_container_mut() { + if let Some(container) = self.monocle_container() { if let Some(window) = container.focused_window() { container.restore(); window.focus(mouse_follows_focus)?; @@ -318,10 +318,16 @@ impl Workspace { if self.maximized_window().is_none() && matches!(self.layer, WorkspaceLayer::Tiling) { window.focus(mouse_follows_focus)?; } else if let Some(maximized_window) = self.maximized_window() { + maximized_window.restore(); maximized_window.focus(mouse_follows_focus)?; } else if let Some(floating_window) = self.floating_windows().first() { floating_window.focus(mouse_follows_focus)?; } + } else if let Some(maximized_window) = self.maximized_window() { + maximized_window.restore(); + maximized_window.focus(mouse_follows_focus)?; + } else if let Some(floating_window) = self.floating_windows().first() { + floating_window.focus(mouse_follows_focus)?; } Ok(())