From ca95dd464676d7fa89a0d2b44da3a43c3cd79fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 30 Jul 2026 00:47:02 +0300 Subject: [PATCH] feat(niri): make Mod+Up/Down vertical, matching Left/Right being horizontal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.kdl | 13 ++++++--- .config/scripts/niri/workspace_nav.sh | 40 ++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/.config/niri/config.kdl b/.config/niri/config.kdl index 5aa8917..aac061a 100644 --- a/.config/niri/config.kdl +++ b/.config/niri/config.kdl @@ -254,10 +254,15 @@ binds { // ─── focus ────────────────────────────────────────────────────────────── // Mod+H is the waybar toggle and Mod+L is the locker, so the stock vim-nav // binds for those two are gone; arrows still navigate. + // + // Left/Right move between columns. Up/Down are vertical in niri's sense: + // the next window in the column when the column has one, otherwise the + // workspace above/below (workspaces stack vertically). Mod+J/K stay + // strictly in-column. Mod+Left { focus-column-left; } Mod+Right { focus-column-right; } - Mod+Up { focus-window-up; } - Mod+Down { focus-window-down; } + Mod+Up { spawn-sh "~/.config/scripts/niri/workspace_nav.sh up"; } + Mod+Down { spawn-sh "~/.config/scripts/niri/workspace_nav.sh down"; } Mod+J { focus-window-down; } Mod+K { focus-window-up; } Mod+Home { focus-column-first; } @@ -268,8 +273,8 @@ binds { // ─── move windows ─────────────────────────────────────────────────────── Mod+Ctrl+Left { move-column-left; } Mod+Ctrl+Right { move-column-right; } - Mod+Ctrl+Up { move-window-up; } - Mod+Ctrl+Down { move-window-down; } + Mod+Ctrl+Up { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move-up"; } + Mod+Ctrl+Down { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move-down"; } Mod+Ctrl+H { move-column-left; } Mod+Ctrl+L { move-column-right; } Mod+Ctrl+J { move-window-down; } diff --git a/.config/scripts/niri/workspace_nav.sh b/.config/scripts/niri/workspace_nav.sh index 9163ef1..bab1c0d 100755 --- a/.config/scripts/niri/workspace_nav.sh +++ b/.config/scripts/niri/workspace_nav.sh @@ -5,6 +5,9 @@ # workspace_nav.sh move move focused column to it # workspace_nav.sh next|prev focus the next/previous plain one # workspace_nav.sh move-next|move-prev +# workspace_nav.sh up|down focus within the column, else the +# workspace above/below +# workspace_nav.sh move-up|move-down same, moving the window # # Why this exists: niri workspace numbers are indices into each output's live # workspace list, and the named app workspaces (code, github, ...) live in that @@ -18,7 +21,42 @@ # is always at least one target. set -euo pipefail -action="${1:?usage: workspace_nav.sh focus|move|next|prev|move-next|move-prev [N]}" +action="${1:?usage: workspace_nav.sh focus|move|next|prev|move-next|move-prev|up|down|move-up|move-down [N]}" + +# Vertical motion: niri stacks workspaces vertically, so "down" means the next +# window in the column when there is one, and otherwise the workspace below. +# Whether the in-column action did anything is decided by comparing the focused +# window's row before and after — cheaper and more robust than reimplementing +# niri's column arithmetic. +if [ "$action" = "up" ] || [ "$action" = "down" ] || [ "$action" = "move-up" ] || [ "$action" = "move-down" ]; then + row_of_focused() { + niri msg -j windows | jq -r '.[] | select(.is_focused == true) | .layout.pos_in_scrolling_layout | "\(.[0]),\(.[1])"' + } + + before=$(row_of_focused) + + case "$action" in + up) niri msg action focus-window-up >/dev/null 2>&1 || true ;; + down) niri msg action focus-window-down >/dev/null 2>&1 || true ;; + move-up) niri msg action move-window-up >/dev/null 2>&1 || true ;; + move-down) niri msg action move-window-down >/dev/null 2>&1 || true ;; + esac + + after=$(row_of_focused) + + if [ -n "$before" ] && [ "$before" != "$after" ]; then + exit 0 # the in-column move worked + fi + + # Nowhere to go inside the column: fall through to the workspace above/below, + # which is the plain-workspace navigation below. + case "$action" in + up) action="prev" ;; + down) action="next" ;; + move-up) action="move-prev" ;; + move-down) action="move-next" ;; + esac +fi ws_json=$(niri msg -j workspaces) output=$(jq -r '.[] | select(.is_focused == true) | .output' <<<"$ws_json")