Add focus-column (by index) action
Browse files at this commita5d58d670bde166ff8bca8a83bb6f1136c7fa67bParent: b4922087 changed files +41 -0
- niri-config/src/lib.rs +2 -0
- niri-ipc/src/lib.rs +8 -0
- src/input/mod.rs +7 -0
- src/layout/mod.rs +7 -0
- src/layout/scrolling.rs +8 -0
- src/layout/tests.rs +2 -0
- src/layout/workspace.rs +7 -0
niri-config/src/lib.rsmodified+2 -0
| @@ -1486,6 +1486,7 @@ pub enum Action { | |||
| 1486 | FocusColumnLast, | 1486 | FocusColumnLast, |
| 1487 | FocusColumnRightOrFirst, | 1487 | FocusColumnRightOrFirst, |
| 1488 | FocusColumnLeftOrLast, | 1488 | FocusColumnLeftOrLast, |
| 1489 | + FocusColumn(#[knuffel(argument)] usize), | ||
| 1489 | FocusWindowOrMonitorUp, | 1490 | FocusWindowOrMonitorUp, |
| 1490 | FocusWindowOrMonitorDown, | 1491 | FocusWindowOrMonitorDown, |
| 1491 | FocusColumnOrMonitorLeft, | 1492 | FocusColumnOrMonitorLeft, |
| @@ -1682,6 +1683,7 @@ impl From<niri_ipc::Action> for Action { | |||
| 1682 | niri_ipc::Action::FocusColumnLast {} => Self::FocusColumnLast, | 1683 | niri_ipc::Action::FocusColumnLast {} => Self::FocusColumnLast, |
| 1683 | niri_ipc::Action::FocusColumnRightOrFirst {} => Self::FocusColumnRightOrFirst, | 1684 | niri_ipc::Action::FocusColumnRightOrFirst {} => Self::FocusColumnRightOrFirst, |
| 1684 | niri_ipc::Action::FocusColumnLeftOrLast {} => Self::FocusColumnLeftOrLast, | 1685 | niri_ipc::Action::FocusColumnLeftOrLast {} => Self::FocusColumnLeftOrLast, |
| 1686 | + niri_ipc::Action::FocusColumn { index } => Self::FocusColumn(index), | ||
| 1685 | niri_ipc::Action::FocusWindowOrMonitorUp {} => Self::FocusWindowOrMonitorUp, | 1687 | niri_ipc::Action::FocusWindowOrMonitorUp {} => Self::FocusWindowOrMonitorUp, |
| 1686 | niri_ipc::Action::FocusWindowOrMonitorDown {} => Self::FocusWindowOrMonitorDown, | 1688 | niri_ipc::Action::FocusWindowOrMonitorDown {} => Self::FocusWindowOrMonitorDown, |
| 1687 | niri_ipc::Action::FocusColumnOrMonitorLeft {} => Self::FocusColumnOrMonitorLeft, | 1689 | niri_ipc::Action::FocusColumnOrMonitorLeft {} => Self::FocusColumnOrMonitorLeft, |
niri-ipc/src/lib.rsmodified+8 -0
| @@ -249,6 +249,14 @@ pub enum Action { | |||
| 249 | FocusColumnRightOrFirst {}, | 249 | FocusColumnRightOrFirst {}, |
| 250 | /// Focus the next column to the left, looping if at start. | 250 | /// Focus the next column to the left, looping if at start. |
| 251 | FocusColumnLeftOrLast {}, | 251 | FocusColumnLeftOrLast {}, |
| 252 | + /// Focus a column by index. | ||
| 253 | + FocusColumn { | ||
| 254 | + /// Index of the column to focus. | ||
| 255 | + /// | ||
| 256 | + /// The index starts from 1 for the first column. | ||
| 257 | + #[cfg_attr(feature = "clap", arg())] | ||
| 258 | + index: usize, | ||
| 259 | + }, | ||
| 252 | /// Focus the window or the monitor above. | 260 | /// Focus the window or the monitor above. |
| 253 | FocusWindowOrMonitorUp {}, | 261 | FocusWindowOrMonitorUp {}, |
| 254 | /// Focus the window or the monitor below. | 262 | /// Focus the window or the monitor below. |
src/input/mod.rsmodified+7 -0
| @@ -882,6 +882,13 @@ impl State { | |||
| 882 | // FIXME: granular | 882 | // FIXME: granular |
| 883 | self.niri.queue_redraw_all(); | 883 | self.niri.queue_redraw_all(); |
| 884 | } | 884 | } |
| 885 | + Action::FocusColumn(index) => { | ||
| 886 | + self.niri.layout.focus_column(index); | ||
| 887 | + self.maybe_warp_cursor_to_focus(); | ||
| 888 | + self.niri.layer_shell_on_demand_focus = None; | ||
| 889 | + // FIXME: granular | ||
| 890 | + self.niri.queue_redraw_all(); | ||
| 891 | + } | ||
| 885 | Action::FocusWindowOrMonitorUp => { | 892 | Action::FocusWindowOrMonitorUp => { |
| 886 | if let Some(output) = self.niri.output_up() { | 893 | if let Some(output) = self.niri.output_up() { |
| 887 | if self.niri.layout.focus_window_up_or_output(&output) | 894 | if self.niri.layout.focus_window_up_or_output(&output) |
src/layout/mod.rsmodified+7 -0
| @@ -1946,6 +1946,13 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1946 | workspace.focus_column_left_or_last(); | 1946 | workspace.focus_column_left_or_last(); |
| 1947 | } | 1947 | } |
| 1948 | 1948 | ||
| 1949 | + pub fn focus_column(&mut self, index: usize) { | ||
| 1950 | + let Some(workspace) = self.active_workspace_mut() else { | ||
| 1951 | + return; | ||
| 1952 | + }; | ||
| 1953 | + workspace.focus_column(index); | ||
| 1954 | + } | ||
| 1955 | + | ||
| 1949 | pub fn focus_window_up_or_output(&mut self, output: &Output) -> bool { | 1956 | pub fn focus_window_up_or_output(&mut self, output: &Output) -> bool { |
| 1950 | if let Some(workspace) = self.active_workspace_mut() { | 1957 | if let Some(workspace) = self.active_workspace_mut() { |
| 1951 | if workspace.focus_up() { | 1958 | if workspace.focus_up() { |
src/layout/scrolling.rsmodified+8 -0
| @@ -1491,6 +1491,14 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 1491 | self.activate_column(self.columns.len() - 1); | 1491 | self.activate_column(self.columns.len() - 1); |
| 1492 | } | 1492 | } |
| 1493 | 1493 | ||
| 1494 | + pub fn focus_column(&mut self, index: usize) { | ||
| 1495 | + if self.columns.is_empty() { | ||
| 1496 | + return; | ||
| 1497 | + } | ||
| 1498 | + | ||
| 1499 | + self.activate_column(index.saturating_sub(1).min(self.columns.len() - 1)); | ||
| 1500 | + } | ||
| 1501 | + | ||
| 1494 | pub fn focus_window_in_column(&mut self, index: u8) { | 1502 | pub fn focus_window_in_column(&mut self, index: u8) { |
| 1495 | if self.columns.is_empty() { | 1503 | if self.columns.is_empty() { |
| 1496 | return; | 1504 | return; |
src/layout/tests.rsmodified+2 -0
| @@ -374,6 +374,7 @@ enum Op { | |||
| 374 | FocusColumnLast, | 374 | FocusColumnLast, |
| 375 | FocusColumnRightOrFirst, | 375 | FocusColumnRightOrFirst, |
| 376 | FocusColumnLeftOrLast, | 376 | FocusColumnLeftOrLast, |
| 377 | + FocusColumn(#[proptest(strategy = "1..=5usize")] usize), | ||
| 377 | FocusWindowOrMonitorUp(#[proptest(strategy = "1..=2u8")] u8), | 378 | FocusWindowOrMonitorUp(#[proptest(strategy = "1..=2u8")] u8), |
| 378 | FocusWindowOrMonitorDown(#[proptest(strategy = "1..=2u8")] u8), | 379 | FocusWindowOrMonitorDown(#[proptest(strategy = "1..=2u8")] u8), |
| 379 | FocusColumnOrMonitorLeft(#[proptest(strategy = "1..=2u8")] u8), | 380 | FocusColumnOrMonitorLeft(#[proptest(strategy = "1..=2u8")] u8), |
| @@ -907,6 +908,7 @@ impl Op { | |||
| 907 | Op::FocusColumnLast => layout.focus_column_last(), | 908 | Op::FocusColumnLast => layout.focus_column_last(), |
| 908 | Op::FocusColumnRightOrFirst => layout.focus_column_right_or_first(), | 909 | Op::FocusColumnRightOrFirst => layout.focus_column_right_or_first(), |
| 909 | Op::FocusColumnLeftOrLast => layout.focus_column_left_or_last(), | 910 | Op::FocusColumnLeftOrLast => layout.focus_column_left_or_last(), |
| 911 | + Op::FocusColumn(index) => layout.focus_column(index), | ||
| 910 | Op::FocusWindowOrMonitorUp(id) => { | 912 | Op::FocusWindowOrMonitorUp(id) => { |
| 911 | let name = format!("output{id}"); | 913 | let name = format!("output{id}"); |
| 912 | let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | 914 | let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { |
src/layout/workspace.rsmodified+7 -0
| @@ -850,6 +850,13 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 850 | } | 850 | } |
| 851 | } | 851 | } |
| 852 | 852 | ||
| 853 | + pub fn focus_column(&mut self, index: usize) { | ||
| 854 | + if self.floating_is_active.get() { | ||
| 855 | + self.focus_tiling(); | ||
| 856 | + } | ||
| 857 | + self.scrolling.focus_column(index); | ||
| 858 | + } | ||
| 859 | + | ||
| 853 | pub fn focus_window_in_column(&mut self, index: u8) { | 860 | pub fn focus_window_in_column(&mut self, index: u8) { |
| 854 | if self.floating_is_active.get() { | 861 | if self.floating_is_active.get() { |
| 855 | return; | 862 | return; |