Add `focus-column-or-monitor-left`, `focus-column-or-monitor-right` (#456)
Browse files at this commit- feat
- add `focus-column-or-monitor-left`, `focus-column-or-monitor-right` (#456)
4 changed files +95 -0
- niri-config/src/lib.rs +4 -0
- niri-ipc/src/lib.rs +4 -0
- src/input/mod.rs +34 -0
- src/layout/mod.rs +53 -0
niri-config/src/lib.rsmodified+4 -0
| @@ -946,6 +946,8 @@ pub enum Action { | ||
| 946 | 946 | FocusColumnLast, |
| 947 | 947 | FocusColumnRightOrFirst, |
| 948 | 948 | FocusColumnLeftOrLast, |
| 949 | + FocusColumnOrMonitorLeft, | |
| 950 | + FocusColumnOrMonitorRight, | |
| 949 | 951 | FocusWindowDown, |
| 950 | 952 | FocusWindowUp, |
| 951 | 953 | FocusWindowDownOrColumnLeft, |
| @@ -1022,6 +1024,8 @@ impl From<niri_ipc::Action> for Action { | ||
| 1022 | 1024 | niri_ipc::Action::FocusColumnLast => Self::FocusColumnLast, |
| 1023 | 1025 | niri_ipc::Action::FocusColumnRightOrFirst => Self::FocusColumnRightOrFirst, |
| 1024 | 1026 | niri_ipc::Action::FocusColumnLeftOrLast => Self::FocusColumnLeftOrLast, |
| 1027 | + niri_ipc::Action::FocusColumnOrMonitorLeft => Self::FocusColumnOrMonitorLeft, | |
| 1028 | + niri_ipc::Action::FocusColumnOrMonitorRight => Self::FocusColumnOrMonitorRight, | |
| 1025 | 1029 | niri_ipc::Action::FocusWindowDown => Self::FocusWindowDown, |
| 1026 | 1030 | niri_ipc::Action::FocusWindowUp => Self::FocusWindowUp, |
| 1027 | 1031 | niri_ipc::Action::FocusWindowDownOrColumnLeft => Self::FocusWindowDownOrColumnLeft, |
niri-ipc/src/lib.rsmodified+4 -0
| @@ -120,6 +120,10 @@ pub enum Action { | ||
| 120 | 120 | FocusColumnRightOrFirst, |
| 121 | 121 | /// Focus the next column to the left, looping if at start. |
| 122 | 122 | FocusColumnLeftOrLast, |
| 123 | + /// Focus the column or the monitor to the left. | |
| 124 | + FocusColumnOrMonitorLeft, | |
| 125 | + /// Focus the column or the monitor to the right. | |
| 126 | + FocusColumnOrMonitorRight, | |
| 123 | 127 | /// Focus the window below. |
| 124 | 128 | FocusWindowDown, |
| 125 | 129 | /// Focus the window above. |
src/input/mod.rsmodified+34 -0
| @@ -596,6 +596,40 @@ impl State { | ||
| 596 | 596 | // FIXME: granular |
| 597 | 597 | self.niri.queue_redraw_all(); |
| 598 | 598 | } |
| 599 | + Action::FocusColumnOrMonitorLeft => { | |
| 600 | + if let Some(output) = self.niri.output_left() { | |
| 601 | + if self.niri.layout.focus_column_left_or_output(&output) | |
| 602 | + && !self.maybe_warp_cursor_to_focus_centered() | |
| 603 | + { | |
| 604 | + self.move_cursor_to_output(&output); | |
| 605 | + } else { | |
| 606 | + self.maybe_warp_cursor_to_focus(); | |
| 607 | + } | |
| 608 | + } else { | |
| 609 | + self.niri.layout.focus_left(); | |
| 610 | + self.maybe_warp_cursor_to_focus(); | |
| 611 | + } | |
| 612 | + | |
| 613 | + // FIXME: granular | |
| 614 | + self.niri.queue_redraw_all(); | |
| 615 | + } | |
| 616 | + Action::FocusColumnOrMonitorRight => { | |
| 617 | + if let Some(output) = self.niri.output_right() { | |
| 618 | + if self.niri.layout.focus_column_right_or_output(&output) | |
| 619 | + && !self.maybe_warp_cursor_to_focus_centered() | |
| 620 | + { | |
| 621 | + self.move_cursor_to_output(&output); | |
| 622 | + } else { | |
| 623 | + self.maybe_warp_cursor_to_focus(); | |
| 624 | + } | |
| 625 | + } else { | |
| 626 | + self.niri.layout.focus_right(); | |
| 627 | + self.maybe_warp_cursor_to_focus(); | |
| 628 | + } | |
| 629 | + | |
| 630 | + // FIXME: granular | |
| 631 | + self.niri.queue_redraw_all(); | |
| 632 | + } | |
| 599 | 633 | Action::FocusWindowDown => { |
| 600 | 634 | self.niri.layout.focus_down(); |
| 601 | 635 | self.maybe_warp_cursor_to_focus(); |
src/layout/mod.rsmodified+53 -0
| @@ -1264,6 +1264,37 @@ impl<W: LayoutElement> Layout<W> { | ||
| 1264 | 1264 | monitor.focus_column_left_or_last(); |
| 1265 | 1265 | } |
| 1266 | 1266 | |
| 1267 | + pub fn focus_column_left_or_output(&mut self, output: &Output) -> bool { | |
| 1268 | + if let Some(monitor) = self.active_monitor() { | |
| 1269 | + let workspace = monitor.active_workspace(); | |
| 1270 | + let curr_idx = workspace.active_column_idx; | |
| 1271 | + | |
| 1272 | + if !workspace.columns.is_empty() && curr_idx != 0 { | |
| 1273 | + monitor.focus_left(); | |
| 1274 | + return false; | |
| 1275 | + } | |
| 1276 | + } | |
| 1277 | + | |
| 1278 | + self.focus_output(output); | |
| 1279 | + true | |
| 1280 | + } | |
| 1281 | + | |
| 1282 | + pub fn focus_column_right_or_output(&mut self, output: &Output) -> bool { | |
| 1283 | + if let Some(monitor) = self.active_monitor() { | |
| 1284 | + let workspace = monitor.active_workspace(); | |
| 1285 | + let curr_idx = workspace.active_column_idx; | |
| 1286 | + let columns = &workspace.columns; | |
| 1287 | + | |
| 1288 | + if !workspace.columns.is_empty() && curr_idx != columns.len() - 1 { | |
| 1289 | + monitor.focus_right(); | |
| 1290 | + return false; | |
| 1291 | + } | |
| 1292 | + } | |
| 1293 | + | |
| 1294 | + self.focus_output(output); | |
| 1295 | + true | |
| 1296 | + } | |
| 1297 | + | |
| 1267 | 1298 | pub fn focus_down(&mut self) { |
| 1268 | 1299 | let Some(monitor) = self.active_monitor() else { |
| 1269 | 1300 | return; |
| @@ -2697,6 +2728,8 @@ mod tests { | ||
| 2697 | 2728 | FocusColumnLast, |
| 2698 | 2729 | FocusColumnRightOrFirst, |
| 2699 | 2730 | FocusColumnLeftOrLast, |
| 2731 | + FocusColumnOrMonitorLeft(#[proptest(strategy = "1..=2u8")] u8), | |
| 2732 | + FocusColumnOrMonitorRight(#[proptest(strategy = "1..=2u8")] u8), | |
| 2700 | 2733 | FocusWindowDown, |
| 2701 | 2734 | FocusWindowUp, |
| 2702 | 2735 | FocusWindowDownOrColumnLeft, |
| @@ -3022,6 +3055,22 @@ mod tests { | ||
| 3022 | 3055 | Op::FocusColumnLast => layout.focus_column_last(), |
| 3023 | 3056 | Op::FocusColumnRightOrFirst => layout.focus_column_right_or_first(), |
| 3024 | 3057 | Op::FocusColumnLeftOrLast => layout.focus_column_left_or_last(), |
| 3058 | + Op::FocusColumnOrMonitorLeft(id) => { | |
| 3059 | + let name = format!("output{id}"); | |
| 3060 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 3061 | + return; | |
| 3062 | + }; | |
| 3063 | + | |
| 3064 | + layout.focus_column_left_or_output(&output); | |
| 3065 | + } | |
| 3066 | + Op::FocusColumnOrMonitorRight(id) => { | |
| 3067 | + let name = format!("output{id}"); | |
| 3068 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 3069 | + return; | |
| 3070 | + }; | |
| 3071 | + | |
| 3072 | + layout.focus_column_right_or_output(&output); | |
| 3073 | + } | |
| 3025 | 3074 | Op::FocusWindowDown => layout.focus_down(), |
| 3026 | 3075 | Op::FocusWindowUp => layout.focus_up(), |
| 3027 | 3076 | Op::FocusWindowDownOrColumnLeft => layout.focus_down_or_left(), |
| @@ -3250,6 +3299,8 @@ mod tests { | ||
| 3250 | 3299 | Op::FocusColumnRight, |
| 3251 | 3300 | Op::FocusColumnRightOrFirst, |
| 3252 | 3301 | Op::FocusColumnLeftOrLast, |
| 3302 | + Op::FocusColumnOrMonitorLeft(0), | |
| 3303 | + Op::FocusColumnOrMonitorRight(1), | |
| 3253 | 3304 | Op::FocusWindowUp, |
| 3254 | 3305 | Op::FocusWindowUpOrColumnLeft, |
| 3255 | 3306 | Op::FocusWindowUpOrColumnRight, |
| @@ -3425,6 +3476,8 @@ mod tests { | ||
| 3425 | 3476 | Op::FocusColumnRight, |
| 3426 | 3477 | Op::FocusColumnRightOrFirst, |
| 3427 | 3478 | Op::FocusColumnLeftOrLast, |
| 3479 | + Op::FocusColumnOrMonitorLeft(0), | |
| 3480 | + Op::FocusColumnOrMonitorRight(1), | |
| 3428 | 3481 | Op::FocusWindowUp, |
| 3429 | 3482 | Op::FocusWindowUpOrColumnLeft, |
| 3430 | 3483 | Op::FocusWindowUpOrColumnRight, |