Make Mod+Up/Down vertical, matching Left/Right being horizontal
Browse files at this commitca95dd464676d7fa89a0d2b44da3a43c3cd79fd0Parent: 182dcbc- feat
- make Mod+Up/Down vertical, matching Left/Right being horizontal
2 changed files +48 -5
.config/niri/config.kdlmodified+9 -4
| @@ -254,10 +254,15 @@ binds { | ||
| 254 | 254 | // ─── focus ────────────────────────────────────────────────────────────── |
| 255 | 255 | // Mod+H is the waybar toggle and Mod+L is the locker, so the stock vim-nav |
| 256 | 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 | 262 | Mod+Left { focus-column-left; } |
| 258 | 263 | Mod+Right { focus-column-right; } |
| 259 | - Mod+Up { focus-window-up; } | |
| 260 | - Mod+Down { focus-window-down; } | |
| 264 | + Mod+Up { spawn-sh "~/.config/scripts/niri/workspace_nav.sh up"; } | |
| 265 | + Mod+Down { spawn-sh "~/.config/scripts/niri/workspace_nav.sh down"; } | |
| 261 | 266 | Mod+J { focus-window-down; } |
| 262 | 267 | Mod+K { focus-window-up; } |
| 263 | 268 | Mod+Home { focus-column-first; } |
| @@ -268,8 +273,8 @@ binds { | ||
| 268 | 273 | // ─── move windows ─────────────────────────────────────────────────────── |
| 269 | 274 | Mod+Ctrl+Left { move-column-left; } |
| 270 | 275 | Mod+Ctrl+Right { move-column-right; } |
| 271 | - Mod+Ctrl+Up { move-window-up; } | |
| 272 | - Mod+Ctrl+Down { move-window-down; } | |
| 276 | + Mod+Ctrl+Up { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move-up"; } | |
| 277 | + Mod+Ctrl+Down { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move-down"; } | |
| 273 | 278 | Mod+Ctrl+H { move-column-left; } |
| 274 | 279 | Mod+Ctrl+L { move-column-right; } |
| 275 | 280 | Mod+Ctrl+J { move-window-down; } |
.config/scripts/niri/workspace_nav.shmodified+39 -1
| @@ -5,6 +5,9 @@ | ||
| 5 | 5 | # workspace_nav.sh move <N> move focused column to it |
| 6 | 6 | # workspace_nav.sh next|prev focus the next/previous plain one |
| 7 | 7 | # 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 | 12 | # Why this exists: niri workspace numbers are indices into each output's live |
| 10 | 13 | # workspace list, and the named app workspaces (code, github, ...) live in that |
| @@ -18,7 +21,42 @@ | ||
| 18 | 21 | # is always at least one target. |
| 19 | 22 | 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 | 61 | ws_json=$(niri msg -j workspaces) |
| 24 | 62 | output=$(jq -r '.[] | select(.is_focused == true) | .output' <<<"$ws_json") |