From 4acd408b889ff1e2db4271c902112961ebabfdb7 Mon Sep 17 00:00:00 2001 From: alex-ds13 <145657253+alex-ds13@users.noreply.github.com> Date: Mon, 21 Oct 2024 19:48:55 +0100 Subject: [PATCH] fix(wm): focus single window on show event This commit makes sure we refocus the window on `Show` event when it is the only window on the workspace. This is needed because some windows send the `FocusChange` event before the `Show` event and on the first event we will be focusing the desktop window to unfocus any previous window from other workspace because the workspace will still be empty. So after adding the window, we need to focus it again. --- komorebi/src/process_event.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index 97ff56b0..e286bb74 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -387,6 +387,21 @@ impl WindowManager { } } } + + if (self.focused_workspace()?.containers().len() == 1 + && self.focused_workspace()?.floating_windows().is_empty()) + || (self.focused_workspace()?.containers().is_empty() + && self.focused_workspace()?.floating_windows().len() == 1) + { + // If after adding this window the workspace only contains 1 window, it + // means it was previously empty and we focused the desktop to unfocus + // any previous window from other workspace, so now we need to focus + // this window again. This is needed because sometimes some windows + // first send the `FocusChange` event and only the `Show` event after + // and we will be focusing the desktop on the `FocusChange` event since + // it is still empty. + window.focus(self.mouse_follows_focus)?; + } } if workspace_contains_window {