Skip to content

Commit

Permalink
fix(wm): allow focusing monitor with empty ws
Browse files Browse the repository at this point in the history
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
  • Loading branch information
LGUG2Z committed Jan 22, 2023
1 parent 925f3bd commit 86b4d23
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
15 changes: 6 additions & 9 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) => {
Expand Down
3 changes: 3 additions & 0 deletions komorebi/src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down

0 comments on commit 86b4d23

Please sign in to comment.