forge
Explore
Log in

Don't you dare go Hollow

Add focus-window-top/bottom/down-or-top/up-or-bottom actions

Browse files at this commit

c41f93a468c4d04e16f8c89736cc48cd4ab4c623Ivan MolodetskikhParent: 900da59
niri-config/src/lib.rsmodified+8 -0
@@ -1342,6 +1342,10 @@ pub enum Action {
1342 FocusWindowUpOrColumnRight,1342 FocusWindowUpOrColumnRight,
1343 FocusWindowOrWorkspaceDown,1343 FocusWindowOrWorkspaceDown,
1344 FocusWindowOrWorkspaceUp,1344 FocusWindowOrWorkspaceUp,
1345+ FocusWindowTop,
1346+ FocusWindowBottom,
1347+ FocusWindowDownOrTop,
1348+ FocusWindowUpOrBottom,
1345 MoveColumnLeft,1349 MoveColumnLeft,
1346 MoveColumnRight,1350 MoveColumnRight,
1347 MoveColumnToFirst,1351 MoveColumnToFirst,
@@ -1521,6 +1525,10 @@ impl From<niri_ipc::Action> for Action {
1521 niri_ipc::Action::FocusWindowUpOrColumnRight {} => Self::FocusWindowUpOrColumnRight,1525 niri_ipc::Action::FocusWindowUpOrColumnRight {} => Self::FocusWindowUpOrColumnRight,
1522 niri_ipc::Action::FocusWindowOrWorkspaceDown {} => Self::FocusWindowOrWorkspaceDown,1526 niri_ipc::Action::FocusWindowOrWorkspaceDown {} => Self::FocusWindowOrWorkspaceDown,
1523 niri_ipc::Action::FocusWindowOrWorkspaceUp {} => Self::FocusWindowOrWorkspaceUp,1527 niri_ipc::Action::FocusWindowOrWorkspaceUp {} => Self::FocusWindowOrWorkspaceUp,
1528+ niri_ipc::Action::FocusWindowTop {} => Self::FocusWindowTop,
1529+ niri_ipc::Action::FocusWindowBottom {} => Self::FocusWindowBottom,
1530+ niri_ipc::Action::FocusWindowDownOrTop {} => Self::FocusWindowDownOrTop,
1531+ niri_ipc::Action::FocusWindowUpOrBottom {} => Self::FocusWindowUpOrBottom,
1524 niri_ipc::Action::MoveColumnLeft {} => Self::MoveColumnLeft,1532 niri_ipc::Action::MoveColumnLeft {} => Self::MoveColumnLeft,
1525 niri_ipc::Action::MoveColumnRight {} => Self::MoveColumnRight,1533 niri_ipc::Action::MoveColumnRight {} => Self::MoveColumnRight,
1526 niri_ipc::Action::MoveColumnToFirst {} => Self::MoveColumnToFirst,1534 niri_ipc::Action::MoveColumnToFirst {} => Self::MoveColumnToFirst,
niri-ipc/src/lib.rsmodified+8 -0
@@ -253,6 +253,14 @@ pub enum Action {
253 FocusWindowOrWorkspaceDown {},253 FocusWindowOrWorkspaceDown {},
254 /// Focus the window or the workspace above.254 /// Focus the window or the workspace above.
255 FocusWindowOrWorkspaceUp {},255 FocusWindowOrWorkspaceUp {},
256+ /// Focus the topmost window.
257+ FocusWindowTop {},
258+ /// Focus the bottommost window.
259+ FocusWindowBottom {},
260+ /// Focus the window below or the topmost window.
261+ FocusWindowDownOrTop {},
262+ /// Focus the window above or the bottommost window.
263+ FocusWindowUpOrBottom {},
256 /// Move the focused column to the left.264 /// Move the focused column to the left.
257 MoveColumnLeft {},265 MoveColumnLeft {},
258 /// Move the focused column to the right.266 /// Move the focused column to the right.
src/input/mod.rsmodified+28 -0
@@ -987,6 +987,34 @@ impl State {
987 // FIXME: granular987 // FIXME: granular
988 self.niri.queue_redraw_all();988 self.niri.queue_redraw_all();
989 }989 }
990+ Action::FocusWindowTop => {
991+ self.niri.layout.focus_window_top();
992+ self.maybe_warp_cursor_to_focus();
993+ self.niri.layer_shell_on_demand_focus = None;
994+ // FIXME: granular
995+ self.niri.queue_redraw_all();
996+ }
997+ Action::FocusWindowBottom => {
998+ self.niri.layout.focus_window_bottom();
999+ self.maybe_warp_cursor_to_focus();
1000+ self.niri.layer_shell_on_demand_focus = None;
1001+ // FIXME: granular
1002+ self.niri.queue_redraw_all();
1003+ }
1004+ Action::FocusWindowDownOrTop => {
1005+ self.niri.layout.focus_window_down_or_top();
1006+ self.maybe_warp_cursor_to_focus();
1007+ self.niri.layer_shell_on_demand_focus = None;
1008+ // FIXME: granular
1009+ self.niri.queue_redraw_all();
1010+ }
1011+ Action::FocusWindowUpOrBottom => {
1012+ self.niri.layout.focus_window_up_or_bottom();
1013+ self.maybe_warp_cursor_to_focus();
1014+ self.niri.layer_shell_on_demand_focus = None;
1015+ // FIXME: granular
1016+ self.niri.queue_redraw_all();
1017+ }
990 Action::MoveWindowToWorkspaceDown => {1018 Action::MoveWindowToWorkspaceDown => {
991 self.niri.layout.move_to_workspace_down();1019 self.niri.layout.move_to_workspace_down();
992 self.maybe_warp_cursor_to_focus();1020 self.maybe_warp_cursor_to_focus();
src/layout/floating.rsmodified+20 -0
@@ -833,6 +833,26 @@ impl<W: LayoutElement> FloatingSpace<W> {
833 }833 }
834 }834 }
835 835
836+ pub fn focus_topmost(&mut self) {
837+ let result = self
838+ .tiles_with_offsets()
839+ .min_by(|(_, pos_a), (_, pos_b)| f64::total_cmp(&pos_a.y, &pos_b.y));
840+ if let Some((tile, _)) = result {
841+ let id = tile.window().id().clone();
842+ self.activate_window(&id);
843+ }
844+ }
845+
846+ pub fn focus_bottommost(&mut self) {
847+ let result = self
848+ .tiles_with_offsets()
849+ .max_by(|(_, pos_a), (_, pos_b)| f64::total_cmp(&pos_a.y, &pos_b.y));
850+ if let Some((tile, _)) = result {
851+ let id = tile.window().id().clone();
852+ self.activate_window(&id);
853+ }
854+ }
855+
836 fn move_to(&mut self, idx: usize, new_pos: Point<f64, Logical>, animate: bool) {856 fn move_to(&mut self, idx: usize, new_pos: Point<f64, Logical>, animate: bool) {
837 if animate {857 if animate {
838 self.move_and_animate(idx, new_pos);858 self.move_and_animate(idx, new_pos);
src/layout/mod.rsmodified+28 -0
@@ -1949,6 +1949,34 @@ impl<W: LayoutElement> Layout<W> {
1949 monitor.focus_window_or_workspace_up();1949 monitor.focus_window_or_workspace_up();
1950 }1950 }
1951 1951
1952+ pub fn focus_window_top(&mut self) {
1953+ let Some(monitor) = self.active_monitor() else {
1954+ return;
1955+ };
1956+ monitor.focus_window_top();
1957+ }
1958+
1959+ pub fn focus_window_bottom(&mut self) {
1960+ let Some(monitor) = self.active_monitor() else {
1961+ return;
1962+ };
1963+ monitor.focus_window_bottom();
1964+ }
1965+
1966+ pub fn focus_window_down_or_top(&mut self) {
1967+ let Some(monitor) = self.active_monitor() else {
1968+ return;
1969+ };
1970+ monitor.focus_window_down_or_top();
1971+ }
1972+
1973+ pub fn focus_window_up_or_bottom(&mut self) {
1974+ let Some(monitor) = self.active_monitor() else {
1975+ return;
1976+ };
1977+ monitor.focus_window_up_or_bottom();
1978+ }
1979+
1952 pub fn move_to_workspace_up(&mut self) {1980 pub fn move_to_workspace_up(&mut self) {
1953 let Some(monitor) = self.active_monitor() else {1981 let Some(monitor) = self.active_monitor() else {
1954 return;1982 return;
src/layout/monitor.rsmodified+16 -0
@@ -493,6 +493,22 @@ impl<W: LayoutElement> Monitor<W> {
493 }493 }
494 }494 }
495 495
496+ pub fn focus_window_top(&mut self) {
497+ self.active_workspace().focus_window_top();
498+ }
499+
500+ pub fn focus_window_bottom(&mut self) {
501+ self.active_workspace().focus_window_bottom();
502+ }
503+
504+ pub fn focus_window_down_or_top(&mut self) {
505+ self.active_workspace().focus_window_down_or_top();
506+ }
507+
508+ pub fn focus_window_up_or_bottom(&mut self) {
509+ self.active_workspace().focus_window_up_or_bottom();
510+ }
511+
496 pub fn move_to_workspace_up(&mut self) {512 pub fn move_to_workspace_up(&mut self) {
497 let source_workspace_idx = self.active_workspace_idx;513 let source_workspace_idx = self.active_workspace_idx;
498 514
src/layout/scrolling.rsmodified+24 -0
@@ -1422,6 +1422,22 @@ impl<W: LayoutElement> ScrollingSpace<W> {
1422 }1422 }
1423 }1423 }
1424 1424
1425+ pub fn focus_top(&mut self) {
1426+ if self.columns.is_empty() {
1427+ return;
1428+ }
1429+
1430+ self.columns[self.active_column_idx].focus_top()
1431+ }
1432+
1433+ pub fn focus_bottom(&mut self) {
1434+ if self.columns.is_empty() {
1435+ return;
1436+ }
1437+
1438+ self.columns[self.active_column_idx].focus_bottom()
1439+ }
1440+
1425 fn move_column_to(&mut self, new_idx: usize) {1441 fn move_column_to(&mut self, new_idx: usize) {
1426 if self.active_column_idx == new_idx {1442 if self.active_column_idx == new_idx {
1427 return;1443 return;
@@ -3616,6 +3632,14 @@ impl<W: LayoutElement> Column<W> {
3616 true3632 true
3617 }3633 }
3618 3634
3635+ fn focus_top(&mut self) {
3636+ self.active_tile_idx = 0;
3637+ }
3638+
3639+ fn focus_bottom(&mut self) {
3640+ self.active_tile_idx = self.tiles.len() - 1;
3641+ }
3642+
3619 fn move_up(&mut self) -> bool {3643 fn move_up(&mut self) -> bool {
3620 let new_idx = self.active_tile_idx.saturating_sub(1);3644 let new_idx = self.active_tile_idx.saturating_sub(1);
3621 if self.active_tile_idx == new_idx {3645 if self.active_tile_idx == new_idx {
src/layout/tests.rsmodified+8 -0
@@ -380,6 +380,10 @@ 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+ FocusWindowTop,
384+ FocusWindowBottom,
385+ FocusWindowDownOrTop,
386+ FocusWindowUpOrBottom,
383 MoveColumnLeft,387 MoveColumnLeft,
384 MoveColumnRight,388 MoveColumnRight,
385 MoveColumnToFirst,389 MoveColumnToFirst,
@@ -924,6 +928,10 @@ impl Op {
924 Op::FocusWindowOrWorkspaceDown => layout.focus_window_or_workspace_down(),928 Op::FocusWindowOrWorkspaceDown => layout.focus_window_or_workspace_down(),
925 Op::FocusWindowOrWorkspaceUp => layout.focus_window_or_workspace_up(),929 Op::FocusWindowOrWorkspaceUp => layout.focus_window_or_workspace_up(),
926 Op::FocusWindow(id) => layout.activate_window(&id),930 Op::FocusWindow(id) => layout.activate_window(&id),
931+ Op::FocusWindowTop => layout.focus_window_top(),
932+ Op::FocusWindowBottom => layout.focus_window_bottom(),
933+ Op::FocusWindowDownOrTop => layout.focus_window_down_or_top(),
934+ Op::FocusWindowUpOrBottom => layout.focus_window_up_or_bottom(),
927 Op::MoveColumnLeft => layout.move_left(),935 Op::MoveColumnLeft => layout.move_left(),
928 Op::MoveColumnRight => layout.move_right(),936 Op::MoveColumnRight => layout.move_right(),
929 Op::MoveColumnToFirst => layout.move_column_to_first(),937 Op::MoveColumnToFirst => layout.move_column_to_first(),
src/layout/workspace.rsmodified+28 -0
@@ -896,6 +896,34 @@ impl<W: LayoutElement> Workspace<W> {
896 }896 }
897 }897 }
898 898
899+ pub fn focus_window_top(&mut self) {
900+ if self.floating_is_active.get() {
901+ self.floating.focus_topmost();
902+ } else {
903+ self.scrolling.focus_top();
904+ }
905+ }
906+
907+ pub fn focus_window_bottom(&mut self) {
908+ if self.floating_is_active.get() {
909+ self.floating.focus_bottommost();
910+ } else {
911+ self.scrolling.focus_bottom();
912+ }
913+ }
914+
915+ pub fn focus_window_down_or_top(&mut self) {
916+ if !self.focus_down() {
917+ self.focus_window_top();
918+ }
919+ }
920+
921+ pub fn focus_window_up_or_bottom(&mut self) {
922+ if !self.focus_up() {
923+ self.focus_window_bottom();
924+ }
925+ }
926+
899 pub fn move_left(&mut self) -> bool {927 pub fn move_left(&mut self) -> bool {
900 if self.floating_is_active.get() {928 if self.floating_is_active.get() {
901 self.floating.move_left();929 self.floating.move_left();