From 86b4d239e7ec4b8e1342e0d0dc83897d90ad15b4 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 21 Jan 2023 18:33:51 -0800 Subject: [PATCH] fix(wm): allow focusing monitor with empty ws This commit ensures that when the focus is changed to a monitor with an empty workspace with the focus-monitor or cycle-monitor commands, subsequent commands such as focus-workspace will operate successfully on the chosen monitor. fix #148 --- komorebi/src/process_command.rs | 15 ++++++--------- komorebi/src/window_manager.rs | 3 +++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index af2a464a..fbf25ba5 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -396,11 +396,9 @@ impl WindowManager { // This is to ensure that even on an empty workspace on a secondary monitor, the // secondary monitor where the cursor is focused will be used as the target for // the workspace switch op - let monitor_idx = self.monitor_idx_from_current_pos().ok_or_else(|| { - anyhow!("there is no monitor associated with the current cursor position") - })?; - - self.focus_monitor(monitor_idx)?; + if let Some(monitor_idx) = self.monitor_idx_from_current_pos() { + self.focus_monitor(monitor_idx)?; + } let focused_monitor = self .focused_monitor() @@ -421,11 +419,10 @@ impl WindowManager { // This is to ensure that even on an empty workspace on a secondary monitor, the // secondary monitor where the cursor is focused will be used as the target for // the workspace switch op - let monitor_idx = self.monitor_idx_from_current_pos().ok_or_else(|| { - anyhow!("there is no monitor associated with the current cursor position") - })?; + if let Some(monitor_idx) = self.monitor_idx_from_current_pos() { + self.focus_monitor(monitor_idx)?; + } - self.focus_monitor(monitor_idx)?; self.focus_workspace(workspace_idx)?; } SocketMessage::FocusMonitorWorkspaceNumber(monitor_idx, workspace_idx) => { diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 84934d33..c4ebedf5 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -811,6 +811,9 @@ impl WindowManager { hwnd: WindowsApi::desktop_window()?, }; + let rect = self.focused_monitor_size()?; + WindowsApi::center_cursor_in_rect(&rect)?; + // Calling this directly instead of the window.focus() wrapper because trying to // attach to the thread of the desktop window always seems to result in "Access is // denied (os error 5)"