From 31864b157030ae406bb6b43455828d163fb2fc7b Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Mon, 17 Jun 2024 20:09:50 -0700 Subject: [PATCH] fix(ffm): follow focus across monitor boundaries This commit ensures that when the komorebi focus follows mouse implementation is enabled, the focus will follow the mouse across monitor bounadries. --- komorebi/src/window_manager.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 2ce7a298..cf1d2cfe 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -614,6 +614,7 @@ impl WindowManager { let mut hwnd = None; let workspace = self.focused_workspace()?; + // first check the focused workspace if let Some(container_idx) = workspace.container_idx_from_current_point() { if let Some(container) = workspace.containers().get(container_idx) { if let Some(window) = container.focused_window() { @@ -622,6 +623,34 @@ impl WindowManager { } } + // then check all workspaces + if hwnd.is_none() { + for monitor in self.monitors() { + for ws in monitor.workspaces() { + if let Some(container_idx) = ws.container_idx_from_current_point() { + if let Some(container) = ws.containers().get(container_idx) { + if let Some(window) = container.focused_window() { + hwnd = Some(window.hwnd); + } + } + } + } + } + } + + // finally try matching the other way using a hwnd returned from the cursor pos + if hwnd.is_none() { + let cursor_pos_hwnd = WindowsApi::window_at_cursor_pos()?; + + for monitor in self.monitors() { + for ws in monitor.workspaces() { + if ws.container_for_window(cursor_pos_hwnd).is_some() { + hwnd = Some(cursor_pos_hwnd); + } + } + } + } + if let Some(hwnd) = hwnd { if self.has_pending_raise_op || self.focused_window()?.hwnd == hwnd