Implement focus-monitor to focus a specific monitor by output.
Browse files at this commit993c5ce8afc78229fa42c2c7f90813eb40c34c54Parent: 47dd3383 changed files +36 -0
- niri-config/src/lib.rs +21 -0
- niri-ipc/src/lib.rs +6 -0
- src/input/mod.rs +9 -0
niri-config/src/lib.rsmodified+21 -0
| @@ -1568,6 +1568,7 @@ pub enum Action { | ||
| 1568 | 1568 | FocusMonitorUp, |
| 1569 | 1569 | FocusMonitorPrevious, |
| 1570 | 1570 | FocusMonitorNext, |
| 1571 | + FocusMonitor(#[knuffel(argument)] String), | |
| 1571 | 1572 | MoveWindowToMonitorLeft, |
| 1572 | 1573 | MoveWindowToMonitorRight, |
| 1573 | 1574 | MoveWindowToMonitorDown, |
| @@ -1770,6 +1771,7 @@ impl From<niri_ipc::Action> for Action { | ||
| 1770 | 1771 | niri_ipc::Action::FocusMonitorUp {} => Self::FocusMonitorUp, |
| 1771 | 1772 | niri_ipc::Action::FocusMonitorPrevious {} => Self::FocusMonitorPrevious, |
| 1772 | 1773 | niri_ipc::Action::FocusMonitorNext {} => Self::FocusMonitorNext, |
| 1774 | + niri_ipc::Action::FocusMonitor { output } => Self::FocusMonitor(output), | |
| 1773 | 1775 | niri_ipc::Action::MoveWindowToMonitorLeft {} => Self::MoveWindowToMonitorLeft, |
| 1774 | 1776 | niri_ipc::Action::MoveWindowToMonitorRight {} => Self::MoveWindowToMonitorRight, |
| 1775 | 1777 | niri_ipc::Action::MoveWindowToMonitorDown {} => Self::MoveWindowToMonitorDown, |
| @@ -3770,6 +3772,7 @@ mod tests { | ||
| 3770 | 3772 | Mod+T allow-when-locked=true { spawn "alacritty"; } |
| 3771 | 3773 | Mod+Q hotkey-overlay-title=null { close-window; } |
| 3772 | 3774 | Mod+Shift+H { focus-monitor-left; } |
| 3775 | + Mod+Shift+O { focus-monitor "eDP-1"; } | |
| 3773 | 3776 | Mod+Ctrl+Shift+L { move-window-to-monitor-right; } |
| 3774 | 3777 | Mod+Comma { consume-window-into-column; } |
| 3775 | 3778 | Mod+1 { focus-workspace 1; } |
| @@ -4606,6 +4609,24 @@ mod tests { | ||
| 4606 | 4609 | allow_inhibiting: true, |
| 4607 | 4610 | hotkey_overlay_title: None, |
| 4608 | 4611 | }, |
| 4612 | + Bind { | |
| 4613 | + key: Key { | |
| 4614 | + trigger: Keysym( | |
| 4615 | + XK_o, | |
| 4616 | + ), | |
| 4617 | + modifiers: Modifiers( | |
| 4618 | + SHIFT | COMPOSITOR, | |
| 4619 | + ), | |
| 4620 | + }, | |
| 4621 | + action: FocusMonitor( | |
| 4622 | + "eDP-1", | |
| 4623 | + ), | |
| 4624 | + repeat: true, | |
| 4625 | + cooldown: None, | |
| 4626 | + allow_when_locked: false, | |
| 4627 | + allow_inhibiting: true, | |
| 4628 | + hotkey_overlay_title: None, | |
| 4629 | + }, | |
| 4609 | 4630 | Bind { |
| 4610 | 4631 | key: Key { |
| 4611 | 4632 | trigger: Keysym( |
niri-ipc/src/lib.rsmodified+6 -0
| @@ -457,6 +457,12 @@ pub enum Action { | ||
| 457 | 457 | FocusMonitorPrevious {}, |
| 458 | 458 | /// Focus the next monitor. |
| 459 | 459 | FocusMonitorNext {}, |
| 460 | + /// Focus a monitor by name. | |
| 461 | + FocusMonitor { | |
| 462 | + /// Name of the output to focus. | |
| 463 | + #[cfg_attr(feature = "clap", arg())] | |
| 464 | + output: String, | |
| 465 | + }, | |
| 460 | 466 | /// Move the focused window to the monitor to the left. |
| 461 | 467 | MoveWindowToMonitorLeft {}, |
| 462 | 468 | /// Move the focused window to the monitor to the right. |
src/input/mod.rsmodified+9 -0
| @@ -1386,6 +1386,15 @@ impl State { | ||
| 1386 | 1386 | self.niri.layer_shell_on_demand_focus = None; |
| 1387 | 1387 | } |
| 1388 | 1388 | } |
| 1389 | + Action::FocusMonitor(output) => { | |
| 1390 | + if let Some(output) = self.niri.output_by_name_match(&output).cloned() { | |
| 1391 | + self.niri.layout.focus_output(&output); | |
| 1392 | + if !self.maybe_warp_cursor_to_focus_centered() { | |
| 1393 | + self.move_cursor_to_output(&output); | |
| 1394 | + } | |
| 1395 | + self.niri.layer_shell_on_demand_focus = None; | |
| 1396 | + } | |
| 1397 | + } | |
| 1389 | 1398 | Action::MoveWindowToMonitorLeft => { |
| 1390 | 1399 | if let Some(output) = self.niri.output_left() { |
| 1391 | 1400 | self.niri.layout.move_to_output(None, &output, None); |