From be8af2b314cfe21e0451e6d39e24cd2df210db3f Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Mon, 27 Jan 2025 16:59:35 -0800 Subject: [PATCH] feat(cli): add focus-monitor-at-cursor cmd This commit adds a new komorebic command, focus-monitor-at-cursor, which can optionally be chained with the focus-workspace command in keybindings to reproduce the previous default behaviour of auto-focusing whichever monitor the cursor was on before attempting to change the focused workspace. --- komorebi/src/core/mod.rs | 1 + komorebi/src/process_command.rs | 5 +++++ komorebic/src/main.rs | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/komorebi/src/core/mod.rs b/komorebi/src/core/mod.rs index 5288e86e..56cdfc40 100644 --- a/komorebi/src/core/mod.rs +++ b/komorebi/src/core/mod.rs @@ -119,6 +119,7 @@ pub enum SocketMessage { CycleFocusMonitor(CycleDirection), CycleFocusWorkspace(CycleDirection), FocusMonitorNumber(usize), + FocusMonitorAtCursor, FocusLastWorkspace, CloseWorkspace, FocusWorkspaceNumber(usize), diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index ca330266..6db8996a 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -735,6 +735,11 @@ impl WindowManager { self.focus_monitor(monitor_idx)?; self.update_focused_workspace(self.mouse_follows_focus, true)?; } + SocketMessage::FocusMonitorAtCursor => { + if let Some(monitor_idx) = self.monitor_idx_from_current_pos() { + self.focus_monitor(monitor_idx)?; + } + } SocketMessage::Retile => { border_manager::destroy_all_borders()?; self.retile_all(false)? diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 161a9037..de3405c8 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -1108,6 +1108,8 @@ enum SubCommand { /// Focus the specified monitor #[clap(arg_required_else_help = true)] FocusMonitor(FocusMonitor), + /// Focus the monitor at the current cursor location + FocusMonitorAtCursor, /// Focus the last focused workspace on the focused monitor FocusLastWorkspace, /// Focus the specified workspace on the focused monitor @@ -2588,6 +2590,9 @@ if (Get-Command Get-CimInstance -ErrorAction SilentlyContinue) { SubCommand::FocusMonitor(arg) => { send_message(&SocketMessage::FocusMonitorNumber(arg.target))?; } + SubCommand::FocusMonitorAtCursor => { + send_message(&SocketMessage::FocusMonitorAtCursor)?; + } SubCommand::FocusLastWorkspace => { send_message(&SocketMessage::FocusLastWorkspace)?; }