Add focus-window-in-column (by index) action
Browse files at this commita444efd0ebee8e203877daedc7bc65584f72dabaParent: c41f93a8 changed files +49 -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/monitor.rs +4 -0
- src/layout/scrolling.rs +12 -0
- src/layout/tests.rs +2 -0
- src/layout/workspace.rs +7 -0
niri-config/src/lib.rsmodified+2 -0
| @@ -1323,6 +1323,7 @@ pub enum Action { | |||
| 1323 | FullscreenWindowById(u64), | 1323 | FullscreenWindowById(u64), |
| 1324 | #[knuffel(skip)] | 1324 | #[knuffel(skip)] |
| 1325 | FocusWindow(u64), | 1325 | FocusWindow(u64), |
| 1326 | + FocusWindowInColumn(#[knuffel(argument)] u8), | ||
| 1326 | FocusWindowPrevious, | 1327 | FocusWindowPrevious, |
| 1327 | FocusColumnLeft, | 1328 | FocusColumnLeft, |
| 1328 | FocusColumnRight, | 1329 | FocusColumnRight, |
| @@ -1506,6 +1507,7 @@ impl From<niri_ipc::Action> for Action { | |||
| 1506 | niri_ipc::Action::FullscreenWindow { id: None } => Self::FullscreenWindow, | 1507 | niri_ipc::Action::FullscreenWindow { id: None } => Self::FullscreenWindow, |
| 1507 | niri_ipc::Action::FullscreenWindow { id: Some(id) } => Self::FullscreenWindowById(id), | 1508 | niri_ipc::Action::FullscreenWindow { id: Some(id) } => Self::FullscreenWindowById(id), |
| 1508 | niri_ipc::Action::FocusWindow { id } => Self::FocusWindow(id), | 1509 | niri_ipc::Action::FocusWindow { id } => Self::FocusWindow(id), |
| 1510 | + niri_ipc::Action::FocusWindowInColumn { index } => Self::FocusWindowInColumn(index), | ||
| 1509 | niri_ipc::Action::FocusWindowPrevious {} => Self::FocusWindowPrevious, | 1511 | niri_ipc::Action::FocusWindowPrevious {} => Self::FocusWindowPrevious, |
| 1510 | niri_ipc::Action::FocusColumnLeft {} => Self::FocusColumnLeft, | 1512 | niri_ipc::Action::FocusColumnLeft {} => Self::FocusColumnLeft, |
| 1511 | niri_ipc::Action::FocusColumnRight {} => Self::FocusColumnRight, | 1513 | niri_ipc::Action::FocusColumnRight {} => Self::FocusColumnRight, |
niri-ipc/src/lib.rsmodified+8 -0
| @@ -215,6 +215,14 @@ pub enum Action { | |||
| 215 | #[cfg_attr(feature = "clap", arg(long))] | 215 | #[cfg_attr(feature = "clap", arg(long))] |
| 216 | id: u64, | 216 | id: u64, |
| 217 | }, | 217 | }, |
| 218 | + /// Focus a window in the focused column by index. | ||
| 219 | + FocusWindowInColumn { | ||
| 220 | + /// Index of the window in the column. | ||
| 221 | + /// | ||
| 222 | + /// The index starts from 1 for the topmost window. | ||
| 223 | + #[cfg_attr(feature = "clap", arg())] | ||
| 224 | + index: u8, | ||
| 225 | + }, | ||
| 218 | /// Focus the previously focused window. | 226 | /// Focus the previously focused window. |
| 219 | FocusWindowPrevious {}, | 227 | FocusWindowPrevious {}, |
| 220 | /// Focus the column to the left. | 228 | /// Focus the column to the left. |
src/input/mod.rsmodified+7 -0
| @@ -681,6 +681,13 @@ impl State { | |||
| 681 | self.focus_window(&window); | 681 | self.focus_window(&window); |
| 682 | } | 682 | } |
| 683 | } | 683 | } |
| 684 | + Action::FocusWindowInColumn(index) => { | ||
| 685 | + self.niri.layout.focus_window_in_column(index); | ||
| 686 | + self.maybe_warp_cursor_to_focus(); | ||
| 687 | + self.niri.layer_shell_on_demand_focus = None; | ||
| 688 | + // FIXME: granular | ||
| 689 | + self.niri.queue_redraw_all(); | ||
| 690 | + } | ||
| 684 | Action::FocusWindowPrevious => { | 691 | Action::FocusWindowPrevious => { |
| 685 | if let Some(window) = self.niri.previously_focused_window.clone() { | 692 | if let Some(window) = self.niri.previously_focused_window.clone() { |
| 686 | self.focus_window(&window); | 693 | self.focus_window(&window); |
src/layout/mod.rsmodified+7 -0
| @@ -1893,6 +1893,13 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1893 | true | 1893 | true |
| 1894 | } | 1894 | } |
| 1895 | 1895 | ||
| 1896 | + pub fn focus_window_in_column(&mut self, index: u8) { | ||
| 1897 | + let Some(monitor) = self.active_monitor() else { | ||
| 1898 | + return; | ||
| 1899 | + }; | ||
| 1900 | + monitor.focus_window_in_column(index); | ||
| 1901 | + } | ||
| 1902 | + | ||
| 1896 | pub fn focus_down(&mut self) { | 1903 | pub fn focus_down(&mut self) { |
| 1897 | let Some(monitor) = self.active_monitor() else { | 1904 | let Some(monitor) = self.active_monitor() else { |
| 1898 | return; | 1905 | return; |
src/layout/monitor.rsmodified+4 -0
| @@ -457,6 +457,10 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 457 | self.active_workspace().focus_column_left_or_last(); | 457 | self.active_workspace().focus_column_left_or_last(); |
| 458 | } | 458 | } |
| 459 | 459 | ||
| 460 | + pub fn focus_window_in_column(&mut self, index: u8) { | ||
| 461 | + self.active_workspace().focus_window_in_column(index); | ||
| 462 | + } | ||
| 463 | + | ||
| 460 | pub fn focus_down(&mut self) -> bool { | 464 | pub fn focus_down(&mut self) -> bool { |
| 461 | self.active_workspace().focus_down() | 465 | self.active_workspace().focus_down() |
| 462 | } | 466 | } |
src/layout/scrolling.rsmodified+12 -0
| @@ -1362,6 +1362,14 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 1362 | self.activate_column(self.columns.len() - 1); | 1362 | self.activate_column(self.columns.len() - 1); |
| 1363 | } | 1363 | } |
| 1364 | 1364 | ||
| 1365 | + pub fn focus_window_in_column(&mut self, index: u8) { | ||
| 1366 | + if self.columns.is_empty() { | ||
| 1367 | + return; | ||
| 1368 | + } | ||
| 1369 | + | ||
| 1370 | + self.columns[self.active_column_idx].focus_index(index); | ||
| 1371 | + } | ||
| 1372 | + | ||
| 1365 | pub fn focus_down(&mut self) -> bool { | 1373 | pub fn focus_down(&mut self) -> bool { |
| 1366 | if self.columns.is_empty() { | 1374 | if self.columns.is_empty() { |
| 1367 | return false; | 1375 | return false; |
| @@ -3614,6 +3622,10 @@ impl<W: LayoutElement> Column<W> { | |||
| 3614 | .unwrap() | 3622 | .unwrap() |
| 3615 | } | 3623 | } |
| 3616 | 3624 | ||
| 3625 | + fn focus_index(&mut self, index: u8) { | ||
| 3626 | + self.active_tile_idx = min(usize::from(index.saturating_sub(1)), self.tiles.len() - 1); | ||
| 3627 | + } | ||
| 3628 | + | ||
| 3617 | fn focus_up(&mut self) -> bool { | 3629 | fn focus_up(&mut self) -> bool { |
| 3618 | if self.active_tile_idx == 0 { | 3630 | if self.active_tile_idx == 0 { |
| 3619 | return false; | 3631 | return false; |
src/layout/tests.rsmodified+2 -0
| @@ -380,6 +380,7 @@ enum Op { | |||
| 380 | FocusWindowOrWorkspaceDown, | 380 | FocusWindowOrWorkspaceDown, |
| 381 | FocusWindowOrWorkspaceUp, | 381 | FocusWindowOrWorkspaceUp, |
| 382 | FocusWindow(#[proptest(strategy = "1..=5usize")] usize), | 382 | FocusWindow(#[proptest(strategy = "1..=5usize")] usize), |
| 383 | + FocusWindowInColumn(#[proptest(strategy = "1..=5u8")] u8), | ||
| 383 | FocusWindowTop, | 384 | FocusWindowTop, |
| 384 | FocusWindowBottom, | 385 | FocusWindowBottom, |
| 385 | FocusWindowDownOrTop, | 386 | FocusWindowDownOrTop, |
| @@ -928,6 +929,7 @@ impl Op { | |||
| 928 | Op::FocusWindowOrWorkspaceDown => layout.focus_window_or_workspace_down(), | 929 | Op::FocusWindowOrWorkspaceDown => layout.focus_window_or_workspace_down(), |
| 929 | Op::FocusWindowOrWorkspaceUp => layout.focus_window_or_workspace_up(), | 930 | Op::FocusWindowOrWorkspaceUp => layout.focus_window_or_workspace_up(), |
| 930 | Op::FocusWindow(id) => layout.activate_window(&id), | 931 | Op::FocusWindow(id) => layout.activate_window(&id), |
| 932 | + Op::FocusWindowInColumn(index) => layout.focus_window_in_column(index), | ||
| 931 | Op::FocusWindowTop => layout.focus_window_top(), | 933 | Op::FocusWindowTop => layout.focus_window_top(), |
| 932 | Op::FocusWindowBottom => layout.focus_window_bottom(), | 934 | Op::FocusWindowBottom => layout.focus_window_bottom(), |
| 933 | Op::FocusWindowDownOrTop => layout.focus_window_down_or_top(), | 935 | Op::FocusWindowDownOrTop => layout.focus_window_down_or_top(), |
src/layout/workspace.rsmodified+7 -0
| @@ -848,6 +848,13 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 848 | } | 848 | } |
| 849 | } | 849 | } |
| 850 | 850 | ||
| 851 | + pub fn focus_window_in_column(&mut self, index: u8) { | ||
| 852 | + if self.floating_is_active.get() { | ||
| 853 | + return; | ||
| 854 | + } | ||
| 855 | + self.scrolling.focus_window_in_column(index); | ||
| 856 | + } | ||
| 857 | + | ||
| 851 | pub fn focus_down(&mut self) -> bool { | 858 | pub fn focus_down(&mut self) -> bool { |
| 852 | if self.floating_is_active.get() { | 859 | if self.floating_is_active.get() { |
| 853 | self.floating.focus_down() | 860 | self.floating.focus_down() |