From b867db190052168c39cb9a74616ca6c201b6753b Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 30 Jul 2021 14:41:57 -0700 Subject: [PATCH] fix(wm): switch to focused workspace This commit fixes corruption of workspace state when clicking a link brings to the foreground a window in a different workspace, and also ensures that the workspace containing the window coming to the foreground will be focused and switched to as part of the Show event. --- komorebi/src/process_event.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index 3c442ff8..c4aeb3eb 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -31,6 +31,7 @@ pub fn listen_for_events(wm: Arc>) { } impl WindowManager { + #[allow(clippy::too_many_lines)] pub fn process_event(&mut self, event: &mut WindowManagerEvent) -> Result<()> { if self.is_paused { tracing::info!("ignoring events while paused"); @@ -105,6 +106,21 @@ impl WindowManager { .focus_container_by_window(window.hwnd)?; } WindowManagerEvent::Show(_, window) => { + let mut switch_to = None; + for (i, monitors) in self.monitors().iter().enumerate() { + for (j, workspace) in monitors.workspaces().iter().enumerate() { + if workspace.contains_window(window.hwnd) { + switch_to = Some((i, j)); + } + } + } + + if let Some(indices) = switch_to { + self.focus_monitor(indices.0)?; + self.focus_workspace(indices.1)?; + return Ok(()); + } + let workspace = self.focused_workspace_mut()?; if workspace.containers().is_empty() || !workspace.contains_window(window.hwnd) {