diff options
| author | Annika Hannig <annika@hannig.cc> | 2025-02-20 20:25:43 +0100 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-03-10 23:17:36 -0700 |
| commit | 993c5ce8afc78229fa42c2c7f90813eb40c34c54 (patch) | |
| tree | 7cd666d7a1c6f241ac11a9fb6777690d0cd744af | |
| parent | 47dd338340e2c8c17ce210579bcdcf8f320d755e (diff) | |
| download | niri-993c5ce8afc78229fa42c2c7f90813eb40c34c54.tar.gz niri-993c5ce8afc78229fa42c2c7f90813eb40c34c54.tar.bz2 niri-993c5ce8afc78229fa42c2c7f90813eb40c34c54.zip | |
Implement focus-monitor to focus a specific monitor by output.
| -rw-r--r-- | niri-config/src/lib.rs | 21 | ||||
| -rw-r--r-- | niri-ipc/src/lib.rs | 6 | ||||
| -rw-r--r-- | src/input/mod.rs | 9 |
3 files changed, 36 insertions, 0 deletions
diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs index b95d70cf..fca9313e 100644 --- a/niri-config/src/lib.rs +++ b/niri-config/src/lib.rs @@ -1568,6 +1568,7 @@ pub enum Action { FocusMonitorUp, FocusMonitorPrevious, FocusMonitorNext, + FocusMonitor(#[knuffel(argument)] String), MoveWindowToMonitorLeft, MoveWindowToMonitorRight, MoveWindowToMonitorDown, @@ -1770,6 +1771,7 @@ impl From<niri_ipc::Action> for Action { niri_ipc::Action::FocusMonitorUp {} => Self::FocusMonitorUp, niri_ipc::Action::FocusMonitorPrevious {} => Self::FocusMonitorPrevious, niri_ipc::Action::FocusMonitorNext {} => Self::FocusMonitorNext, + niri_ipc::Action::FocusMonitor { output } => Self::FocusMonitor(output), niri_ipc::Action::MoveWindowToMonitorLeft {} => Self::MoveWindowToMonitorLeft, niri_ipc::Action::MoveWindowToMonitorRight {} => Self::MoveWindowToMonitorRight, niri_ipc::Action::MoveWindowToMonitorDown {} => Self::MoveWindowToMonitorDown, @@ -3770,6 +3772,7 @@ mod tests { Mod+T allow-when-locked=true { spawn "alacritty"; } Mod+Q hotkey-overlay-title=null { close-window; } Mod+Shift+H { focus-monitor-left; } + Mod+Shift+O { focus-monitor "eDP-1"; } Mod+Ctrl+Shift+L { move-window-to-monitor-right; } Mod+Comma { consume-window-into-column; } Mod+1 { focus-workspace 1; } @@ -4609,6 +4612,24 @@ mod tests { Bind { key: Key { trigger: Keysym( + XK_o, + ), + modifiers: Modifiers( + SHIFT | COMPOSITOR, + ), + }, + action: FocusMonitor( + "eDP-1", + ), + repeat: true, + cooldown: None, + allow_when_locked: false, + allow_inhibiting: true, + hotkey_overlay_title: None, + }, + Bind { + key: Key { + trigger: Keysym( XK_l, ), modifiers: Modifiers( diff --git a/niri-ipc/src/lib.rs b/niri-ipc/src/lib.rs index 5d4bee78..444349ec 100644 --- a/niri-ipc/src/lib.rs +++ b/niri-ipc/src/lib.rs @@ -457,6 +457,12 @@ pub enum Action { FocusMonitorPrevious {}, /// Focus the next monitor. FocusMonitorNext {}, + /// Focus a monitor by name. + FocusMonitor { + /// Name of the output to focus. + #[cfg_attr(feature = "clap", arg())] + output: String, + }, /// Move the focused window to the monitor to the left. MoveWindowToMonitorLeft {}, /// Move the focused window to the monitor to the right. diff --git a/src/input/mod.rs b/src/input/mod.rs index 55d06c7e..badf7cd8 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1386,6 +1386,15 @@ impl State { self.niri.layer_shell_on_demand_focus = None; } } + Action::FocusMonitor(output) => { + if let Some(output) = self.niri.output_by_name_match(&output).cloned() { + self.niri.layout.focus_output(&output); + if !self.maybe_warp_cursor_to_focus_centered() { + self.move_cursor_to_output(&output); + } + self.niri.layer_shell_on_demand_focus = None; + } + } Action::MoveWindowToMonitorLeft => { if let Some(output) = self.niri.output_left() { self.niri.layout.move_to_output(None, &output, None); |
