Added Commnads to focus windows or Monitors above/below the active window (#497)
Browse files at this commit4 changed files +101 -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 +59 -0
niri-config/src/lib.rsmodified+4 -0
| @@ -949,6 +949,8 @@ pub enum Action { | ||
| 949 | 949 | FocusColumnLast, |
| 950 | 950 | FocusColumnRightOrFirst, |
| 951 | 951 | FocusColumnLeftOrLast, |
| 952 | + FocusWindowOrMonitorUp, | |
| 953 | + FocusWindowOrMonitorDown, | |
| 952 | 954 | FocusColumnOrMonitorLeft, |
| 953 | 955 | FocusColumnOrMonitorRight, |
| 954 | 956 | FocusWindowDown, |
| @@ -1027,6 +1029,8 @@ impl From<niri_ipc::Action> for Action { | ||
| 1027 | 1029 | niri_ipc::Action::FocusColumnLast => Self::FocusColumnLast, |
| 1028 | 1030 | niri_ipc::Action::FocusColumnRightOrFirst => Self::FocusColumnRightOrFirst, |
| 1029 | 1031 | niri_ipc::Action::FocusColumnLeftOrLast => Self::FocusColumnLeftOrLast, |
| 1032 | + niri_ipc::Action::FocusWindowOrMonitorUp => Self::FocusWindowOrMonitorUp, | |
| 1033 | + niri_ipc::Action::FocusWindowOrMonitorDown => Self::FocusWindowOrMonitorDown, | |
| 1030 | 1034 | niri_ipc::Action::FocusColumnOrMonitorLeft => Self::FocusColumnOrMonitorLeft, |
| 1031 | 1035 | niri_ipc::Action::FocusColumnOrMonitorRight => Self::FocusColumnOrMonitorRight, |
| 1032 | 1036 | niri_ipc::Action::FocusWindowDown => Self::FocusWindowDown, |
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 window or the monitor above. | |
| 124 | + FocusWindowOrMonitorUp, | |
| 125 | + /// Focus the window or the monitor below. | |
| 126 | + FocusWindowOrMonitorDown, | |
| 123 | 127 | /// Focus the column or the monitor to the left. |
| 124 | 128 | FocusColumnOrMonitorLeft, |
| 125 | 129 | /// Focus the column or the monitor to the right. |
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::FocusWindowOrMonitorUp => { | |
| 600 | + if let Some(output) = self.niri.output_up() { | |
| 601 | + if self.niri.layout.focus_window_up_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_up(); | |
| 610 | + self.maybe_warp_cursor_to_focus(); | |
| 611 | + } | |
| 612 | + | |
| 613 | + // FIXME: granular | |
| 614 | + self.niri.queue_redraw_all(); | |
| 615 | + } | |
| 616 | + Action::FocusWindowOrMonitorDown => { | |
| 617 | + if let Some(output) = self.niri.output_down() { | |
| 618 | + if self.niri.layout.focus_window_down_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_down(); | |
| 627 | + self.maybe_warp_cursor_to_focus(); | |
| 628 | + } | |
| 629 | + | |
| 630 | + // FIXME: granular | |
| 631 | + self.niri.queue_redraw_all(); | |
| 632 | + } | |
| 599 | 633 | Action::FocusColumnOrMonitorLeft => { |
| 600 | 634 | if let Some(output) = self.niri.output_left() { |
| 601 | 635 | if self.niri.layout.focus_column_left_or_output(&output) |
src/layout/mod.rsmodified+59 -0
| @@ -1264,6 +1264,43 @@ impl<W: LayoutElement> Layout<W> { | ||
| 1264 | 1264 | monitor.focus_column_left_or_last(); |
| 1265 | 1265 | } |
| 1266 | 1266 | |
| 1267 | + pub fn focus_window_up_or_output(&mut self, output: &Output) -> bool { | |
| 1268 | + if let Some(monitor) = self.active_monitor() { | |
| 1269 | + let workspace = monitor.active_workspace(); | |
| 1270 | + | |
| 1271 | + if !workspace.columns.is_empty() { | |
| 1272 | + let curr_idx = workspace.columns[workspace.active_column_idx].active_tile_idx; | |
| 1273 | + let new_idx = curr_idx.saturating_sub(1); | |
| 1274 | + if curr_idx != new_idx { | |
| 1275 | + workspace.focus_up(); | |
| 1276 | + return false; | |
| 1277 | + } | |
| 1278 | + } | |
| 1279 | + } | |
| 1280 | + | |
| 1281 | + self.focus_output(output); | |
| 1282 | + true | |
| 1283 | + } | |
| 1284 | + | |
| 1285 | + pub fn focus_window_down_or_output(&mut self, output: &Output) -> bool { | |
| 1286 | + if let Some(monitor) = self.active_monitor() { | |
| 1287 | + let workspace = monitor.active_workspace(); | |
| 1288 | + | |
| 1289 | + if !workspace.columns.is_empty() { | |
| 1290 | + let column = &workspace.columns[workspace.active_column_idx]; | |
| 1291 | + let curr_idx = column.active_tile_idx; | |
| 1292 | + let new_idx = min(column.active_tile_idx + 1, column.tiles.len() - 1); | |
| 1293 | + if curr_idx != new_idx { | |
| 1294 | + workspace.focus_down(); | |
| 1295 | + return false; | |
| 1296 | + } | |
| 1297 | + } | |
| 1298 | + } | |
| 1299 | + | |
| 1300 | + self.focus_output(output); | |
| 1301 | + true | |
| 1302 | + } | |
| 1303 | + | |
| 1267 | 1304 | pub fn focus_column_left_or_output(&mut self, output: &Output) -> bool { |
| 1268 | 1305 | if let Some(monitor) = self.active_monitor() { |
| 1269 | 1306 | let workspace = monitor.active_workspace(); |
| @@ -2728,6 +2765,8 @@ mod tests { | ||
| 2728 | 2765 | FocusColumnLast, |
| 2729 | 2766 | FocusColumnRightOrFirst, |
| 2730 | 2767 | FocusColumnLeftOrLast, |
| 2768 | + FocusWindowOrMonitorUp(#[proptest(strategy = "1..=2u8")] u8), | |
| 2769 | + FocusWindowOrMonitorDown(#[proptest(strategy = "1..=2u8")] u8), | |
| 2731 | 2770 | FocusColumnOrMonitorLeft(#[proptest(strategy = "1..=2u8")] u8), |
| 2732 | 2771 | FocusColumnOrMonitorRight(#[proptest(strategy = "1..=2u8")] u8), |
| 2733 | 2772 | FocusWindowDown, |
| @@ -3055,6 +3094,22 @@ mod tests { | ||
| 3055 | 3094 | Op::FocusColumnLast => layout.focus_column_last(), |
| 3056 | 3095 | Op::FocusColumnRightOrFirst => layout.focus_column_right_or_first(), |
| 3057 | 3096 | Op::FocusColumnLeftOrLast => layout.focus_column_left_or_last(), |
| 3097 | + Op::FocusWindowOrMonitorUp(id) => { | |
| 3098 | + let name = format!("output{id}"); | |
| 3099 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 3100 | + return; | |
| 3101 | + }; | |
| 3102 | + | |
| 3103 | + layout.focus_window_up_or_output(&output); | |
| 3104 | + } | |
| 3105 | + Op::FocusWindowOrMonitorDown(id) => { | |
| 3106 | + let name = format!("output{id}"); | |
| 3107 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 3108 | + return; | |
| 3109 | + }; | |
| 3110 | + | |
| 3111 | + layout.focus_window_down_or_output(&output); | |
| 3112 | + } | |
| 3058 | 3113 | Op::FocusColumnOrMonitorLeft(id) => { |
| 3059 | 3114 | let name = format!("output{id}"); |
| 3060 | 3115 | let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { |
| @@ -3299,6 +3354,8 @@ mod tests { | ||
| 3299 | 3354 | Op::FocusColumnRight, |
| 3300 | 3355 | Op::FocusColumnRightOrFirst, |
| 3301 | 3356 | Op::FocusColumnLeftOrLast, |
| 3357 | + Op::FocusWindowOrMonitorUp(0), | |
| 3358 | + Op::FocusWindowOrMonitorDown(1), | |
| 3302 | 3359 | Op::FocusColumnOrMonitorLeft(0), |
| 3303 | 3360 | Op::FocusColumnOrMonitorRight(1), |
| 3304 | 3361 | Op::FocusWindowUp, |
| @@ -3476,6 +3533,8 @@ mod tests { | ||
| 3476 | 3533 | Op::FocusColumnRight, |
| 3477 | 3534 | Op::FocusColumnRightOrFirst, |
| 3478 | 3535 | Op::FocusColumnLeftOrLast, |
| 3536 | + Op::FocusWindowOrMonitorUp(0), | |
| 3537 | + Op::FocusWindowOrMonitorDown(1), | |
| 3479 | 3538 | Op::FocusColumnOrMonitorLeft(0), |
| 3480 | 3539 | Op::FocusColumnOrMonitorRight(1), |
| 3481 | 3540 | Op::FocusWindowUp, |