forge
Explore
Log in

Don't you dare go Hollow

Make Mod+Up/Down vertical, matching Left/Right being horizontal

Browse files at this commit

ca95dd464676d7fa89a0d2b44da3a43c3cd79fd0Ahmet Kaan GümüşParent: 182dcbc
  • feat
    • make Mod+Up/Down vertical, matching Left/Right being horizontal
Show full message
feat(niri): make Mod+Up/Down vertical, matching Left/Right being horizontal

Left/Right move between columns, but Up/Down only moved inside a column, which
does nothing when the column holds a single window. niri stacks workspaces
vertically, so vertical motion should continue into them.

workspace_nav.sh gains up/down and move-up/move-down: try the in-column move
first, and if the focused window's row did not change, fall through to the
workspace above/below — still skipping the named app workspaces. Comparing the
row before and after is simpler and less brittle than reimplementing niri's
column arithmetic.

Mod+J/K keep the strictly in-column behaviour.

Verified with a two-window column: down goes row 1 -> row 2, a second down
crosses to the next plain workspace, and up returns to row 2 of that column.
.config/niri/config.kdlmodified+9 -4
@@ -254,10 +254,15 @@ binds {
254 // ─── focus ──────────────────────────────────────────────────────────────254 // ─── focus ──────────────────────────────────────────────────────────────
255 // Mod+H is the waybar toggle and Mod+L is the locker, so the stock vim-nav255 // Mod+H is the waybar toggle and Mod+L is the locker, so the stock vim-nav
256 // binds for those two are gone; arrows still navigate.256 // binds for those two are gone; arrows still navigate.
257+ //
258+ // Left/Right move between columns. Up/Down are vertical in niri's sense:
259+ // the next window in the column when the column has one, otherwise the
260+ // workspace above/below (workspaces stack vertically). Mod+J/K stay
261+ // strictly in-column.
257 Mod+Left { focus-column-left; }262 Mod+Left { focus-column-left; }
258 Mod+Right { focus-column-right; }263 Mod+Right { focus-column-right; }
259- Mod+Up { focus-window-up; }264+ Mod+Up { spawn-sh "~/.config/scripts/niri/workspace_nav.sh up"; }
260- Mod+Down { focus-window-down; }265+ Mod+Down { spawn-sh "~/.config/scripts/niri/workspace_nav.sh down"; }
261 Mod+J { focus-window-down; }266 Mod+J { focus-window-down; }
262 Mod+K { focus-window-up; }267 Mod+K { focus-window-up; }
263 Mod+Home { focus-column-first; }268 Mod+Home { focus-column-first; }
@@ -268,8 +273,8 @@ binds {
268 // ─── move windows ───────────────────────────────────────────────────────273 // ─── move windows ───────────────────────────────────────────────────────
269 Mod+Ctrl+Left { move-column-left; }274 Mod+Ctrl+Left { move-column-left; }
270 Mod+Ctrl+Right { move-column-right; }275 Mod+Ctrl+Right { move-column-right; }
271- Mod+Ctrl+Up { move-window-up; }276+ Mod+Ctrl+Up { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move-up"; }
272- Mod+Ctrl+Down { move-window-down; }277+ Mod+Ctrl+Down { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move-down"; }
273 Mod+Ctrl+H { move-column-left; }278 Mod+Ctrl+H { move-column-left; }
274 Mod+Ctrl+L { move-column-right; }279 Mod+Ctrl+L { move-column-right; }
275 Mod+Ctrl+J { move-window-down; }280 Mod+Ctrl+J { move-window-down; }
.config/scripts/niri/workspace_nav.shmodified+39 -1
@@ -5,6 +5,9 @@
5 # workspace_nav.sh move <N> move focused column to it5 # workspace_nav.sh move <N> move focused column to it
6 # workspace_nav.sh next|prev focus the next/previous plain one6 # workspace_nav.sh next|prev focus the next/previous plain one
7 # workspace_nav.sh move-next|move-prev7 # workspace_nav.sh move-next|move-prev
8+# workspace_nav.sh up|down focus within the column, else the
9+# workspace above/below
10+# workspace_nav.sh move-up|move-down same, moving the window
8 #11 #
9 # Why this exists: niri workspace numbers are indices into each output's live12 # Why this exists: niri workspace numbers are indices into each output's live
10 # workspace list, and the named app workspaces (code, github, ...) live in that13 # workspace list, and the named app workspaces (code, github, ...) live in that
@@ -18,7 +21,42 @@
18 # is always at least one target.21 # is always at least one target.
19 set -euo pipefail22 set -euo pipefail
20 23
21-action="${1:?usage: workspace_nav.sh focus|move|next|prev|move-next|move-prev [N]}"24+action="${1:?usage: workspace_nav.sh focus|move|next|prev|move-next|move-prev|up|down|move-up|move-down [N]}"
25+
26+# Vertical motion: niri stacks workspaces vertically, so "down" means the next
27+# window in the column when there is one, and otherwise the workspace below.
28+# Whether the in-column action did anything is decided by comparing the focused
29+# window's row before and after — cheaper and more robust than reimplementing
30+# niri's column arithmetic.
31+if [ "$action" = "up" ] || [ "$action" = "down" ] || [ "$action" = "move-up" ] || [ "$action" = "move-down" ]; then
32+ row_of_focused() {
33+ niri msg -j windows | jq -r '.[] | select(.is_focused == true) | .layout.pos_in_scrolling_layout | "\(.[0]),\(.[1])"'
34+ }
35+
36+ before=$(row_of_focused)
37+
38+ case "$action" in
39+ up) niri msg action focus-window-up >/dev/null 2>&1 || true ;;
40+ down) niri msg action focus-window-down >/dev/null 2>&1 || true ;;
41+ move-up) niri msg action move-window-up >/dev/null 2>&1 || true ;;
42+ move-down) niri msg action move-window-down >/dev/null 2>&1 || true ;;
43+ esac
44+
45+ after=$(row_of_focused)
46+
47+ if [ -n "$before" ] && [ "$before" != "$after" ]; then
48+ exit 0 # the in-column move worked
49+ fi
50+
51+ # Nowhere to go inside the column: fall through to the workspace above/below,
52+ # which is the plain-workspace navigation below.
53+ case "$action" in
54+ up) action="prev" ;;
55+ down) action="next" ;;
56+ move-up) action="move-prev" ;;
57+ move-down) action="move-next" ;;
58+ esac
59+fi
22 60
23 ws_json=$(niri msg -j workspaces)61 ws_json=$(niri msg -j workspaces)
24 output=$(jq -r '.[] | select(.is_focused == true) | .output' <<<"$ws_json")62 output=$(jq -r '.[] | select(.is_focused == true) | .output' <<<"$ws_json")