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
This commit is contained in:
LGUG2Z
2023-01-21 18:33:51 -08:00
parent 925f3bd87b
commit 86b4d239e7
2 changed files with 9 additions and 9 deletions

View File

@@ -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) => {

View File

@@ -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)"