forge
Explore
Log in

Don't you dare go Hollow

Hide app workspaces from number and directional navigation

Browse files at this commit

d8992e15a9ca1a27c9b96cec4e79602b07122407Ahmet Kaan GümüşParent: 30226ea
  • feat
    • hide app workspaces from number and directional navigation
Show full message
feat(niri): hide app workspaces from number and directional navigation

The named app workspaces (code, github, ...) shared niri's per-output index
space, so Mod+3 could land on "discord" and Mod+U/PageDown/wheel walked through
them. They are meant to be reachable only by their own Alt+<letter> binds.

scripts/niri/workspace_nav.sh indexes the PLAIN (unnamed) workspaces of the
focused output instead, and all of Mod+1..0, Mod+Shift+1..0, Mod+Ctrl+1..9,
Mod+U/I, Mod+Page_Up/Down and Mod+[Ctrl+]WheelScroll now route through it.
N past the end clamps to the last plain workspace; niri always keeps one empty
unnamed workspace per output, so a target always exists.

Verified on HDMI-A-1 with named workspaces at idx 2-6: `focus 1`/`focus 2` hit
idx 1 and 7, and next/prev jump 1 <-> 7 without stopping in between.

niri's own move-workspace-down/up stay native on Mod+Shift+U/I and
Mod+Shift+Page_Up/Down, since those reorder the list rather than navigate it.
.config/niri/config.kdlmodified+58 -50
@@ -146,8 +146,10 @@ window-rule {
146146 open-floating true
147147 }
148148
149-// App workspaces, replacing Hyprland's 100/200-206. Not pinned to an output
150-// (no open-on-output), so they follow the monitor you are on.
149+// App workspaces, replacing Hyprland's 100/200-206. Reachable ONLY by their
150+// Alt+<letter> binds: number, direction and wheel navigation all go through
151+// workspace_nav.sh, which skips named workspaces entirely. Each one homes itself
152+// on the monitor of its first launch (see workspace_app.sh).
151153 workspace "code"
152154 workspace "github"
153155 workspace "whatsapp"
@@ -176,10 +178,10 @@ binds {
176178 Shift+Alt+F hotkey-overlay-title="Browser (incognito, outside VPN)" { spawn-sh "mullvad-exclude flatpak run org.chromium.Chromium --incognito --enable-features=MiddleClickAutoscroll,AllowLegacyMV2Extensions --disable-features=ExtensionManifestV2Unsupported,ExtensionManifestV2Disabled,ExtensionsManifestV3Only"; }
177179
178180 // ─── app workspaces ─────────────────────────────────────────────────────
179- // workspace_app.sh emulates Hyprland's on-created-empty, which niri lacks:
180- // it pulls the workspace to the focused monitor, then launches the app only
181- // if that workspace is empty. webapp.sh builds the Chromium web-app command
182- // from a URL + profile id.
181+ // workspace_app.sh emulates Hyprland's on-created-empty, which niri lacks.
182+ // An empty workspace moves to the monitor you are on and the app launches
183+ // there; once it holds windows the key only moves focus to it. webapp.sh
184+ // builds the Chromium web-app command from a URL + profile id.
183185 Alt+C hotkey-overlay-title="Workspace: code" { spawn-sh "~/.config/scripts/niri/workspace_app.sh code zed"; }
184186 Alt+G hotkey-overlay-title="Workspace: github" { spawn-sh "~/.config/scripts/niri/workspace_app.sh github ~/.config/scripts/shared/webapp.sh https://github.com/ FCF18Wmt"; }
185187 Alt+W hotkey-overlay-title="Workspace: whatsapp" { spawn-sh "~/.config/scripts/niri/workspace_app.sh whatsapp ~/.config/scripts/shared/webapp.sh --mullvad https://web.whatsapp.com/ aW2IMaZ8"; }
@@ -282,56 +284,62 @@ binds {
282284 // niri workspaces are per-monitor already, which is what hyprsplit gave
283285 // Hyprland. Mod+Shift+N is Hyprland's send-to-workspace; the stock
284286 // Mod+Ctrl+N binds do the same and are kept as well.
285- Mod+1 { focus-workspace 1; }
286- Mod+2 { focus-workspace 2; }
287- Mod+3 { focus-workspace 3; }
288- Mod+4 { focus-workspace 4; }
289- Mod+5 { focus-workspace 5; }
290- Mod+6 { focus-workspace 6; }
291- Mod+7 { focus-workspace 7; }
292- Mod+8 { focus-workspace 8; }
293- Mod+9 { focus-workspace 9; }
294- Mod+0 { focus-workspace 10; }
295-
296- Mod+Shift+1 { move-column-to-workspace 1; }
297- Mod+Shift+2 { move-column-to-workspace 2; }
298- Mod+Shift+3 { move-column-to-workspace 3; }
299- Mod+Shift+4 { move-column-to-workspace 4; }
300- Mod+Shift+5 { move-column-to-workspace 5; }
301- Mod+Shift+6 { move-column-to-workspace 6; }
302- Mod+Shift+7 { move-column-to-workspace 7; }
303- Mod+Shift+8 { move-column-to-workspace 8; }
304- Mod+Shift+9 { move-column-to-workspace 9; }
305- Mod+Shift+0 { move-column-to-workspace 10; }
306-
307- Mod+Ctrl+1 { move-column-to-workspace 1; }
308- Mod+Ctrl+2 { move-column-to-workspace 2; }
309- Mod+Ctrl+3 { move-column-to-workspace 3; }
310- Mod+Ctrl+4 { move-column-to-workspace 4; }
311- Mod+Ctrl+5 { move-column-to-workspace 5; }
312- Mod+Ctrl+6 { move-column-to-workspace 6; }
313- Mod+Ctrl+7 { move-column-to-workspace 7; }
314- Mod+Ctrl+8 { move-column-to-workspace 8; }
315- Mod+Ctrl+9 { move-column-to-workspace 9; }
316-
317- Mod+Page_Down { focus-workspace-down; }
318- Mod+Page_Up { focus-workspace-up; }
319- Mod+U { focus-workspace-down; }
320- Mod+I { focus-workspace-up; }
321- Mod+Ctrl+Page_Down { move-column-to-workspace-down; }
322- Mod+Ctrl+Page_Up { move-column-to-workspace-up; }
323- Mod+Ctrl+U { move-column-to-workspace-down; }
324- Mod+Ctrl+I { move-column-to-workspace-up; }
287+ //
288+ // All of these go through workspace_nav.sh rather than niri's own
289+ // focus-workspace: niri numbers are indices into each output's live
290+ // workspace list, and the named app workspaces live in that same list, so
291+ // Mod+3 could land on "discord". The script indexes the PLAIN workspaces
292+ // only. N past the end clamps to the last one.
293+ Mod+1 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh focus 1"; }
294+ Mod+2 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh focus 2"; }
295+ Mod+3 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh focus 3"; }
296+ Mod+4 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh focus 4"; }
297+ Mod+5 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh focus 5"; }
298+ Mod+6 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh focus 6"; }
299+ Mod+7 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh focus 7"; }
300+ Mod+8 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh focus 8"; }
301+ Mod+9 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh focus 9"; }
302+ Mod+0 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh focus 10"; }
303+
304+ Mod+Shift+1 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 1"; }
305+ Mod+Shift+2 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 2"; }
306+ Mod+Shift+3 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 3"; }
307+ Mod+Shift+4 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 4"; }
308+ Mod+Shift+5 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 5"; }
309+ Mod+Shift+6 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 6"; }
310+ Mod+Shift+7 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 7"; }
311+ Mod+Shift+8 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 8"; }
312+ Mod+Shift+9 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 9"; }
313+ Mod+Shift+0 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 10"; }
314+
315+ Mod+Ctrl+1 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 1"; }
316+ Mod+Ctrl+2 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 2"; }
317+ Mod+Ctrl+3 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 3"; }
318+ Mod+Ctrl+4 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 4"; }
319+ Mod+Ctrl+5 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 5"; }
320+ Mod+Ctrl+6 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 6"; }
321+ Mod+Ctrl+7 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 7"; }
322+ Mod+Ctrl+8 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 8"; }
323+ Mod+Ctrl+9 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move 9"; }
324+
325+ Mod+Page_Down { spawn-sh "~/.config/scripts/niri/workspace_nav.sh next"; }
326+ Mod+Page_Up { spawn-sh "~/.config/scripts/niri/workspace_nav.sh prev"; }
327+ Mod+U { spawn-sh "~/.config/scripts/niri/workspace_nav.sh next"; }
328+ Mod+I { spawn-sh "~/.config/scripts/niri/workspace_nav.sh prev"; }
329+ Mod+Ctrl+Page_Down { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move-next"; }
330+ Mod+Ctrl+Page_Up { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move-prev"; }
331+ Mod+Ctrl+U { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move-next"; }
332+ Mod+Ctrl+I { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move-prev"; }
325333 Mod+Shift+Page_Down { move-workspace-down; }
326334 Mod+Shift+Page_Up { move-workspace-up; }
327335 Mod+Shift+U { move-workspace-down; }
328336 Mod+Shift+I { move-workspace-up; }
329337
330338 // ─── scroll wheel ───────────────────────────────────────────────────────
331- Mod+WheelScrollDown cooldown-ms=150 { focus-workspace-down; }
332- Mod+WheelScrollUp cooldown-ms=150 { focus-workspace-up; }
333- Mod+Ctrl+WheelScrollDown cooldown-ms=150 { move-column-to-workspace-down; }
334- Mod+Ctrl+WheelScrollUp cooldown-ms=150 { move-column-to-workspace-up; }
339+ Mod+WheelScrollDown cooldown-ms=150 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh next"; }
340+ Mod+WheelScrollUp cooldown-ms=150 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh prev"; }
341+ Mod+Ctrl+WheelScrollDown cooldown-ms=150 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move-next"; }
342+ Mod+Ctrl+WheelScrollUp cooldown-ms=150 { spawn-sh "~/.config/scripts/niri/workspace_nav.sh move-prev"; }
335343 Mod+WheelScrollRight { focus-column-right; }
336344 Mod+WheelScrollLeft { focus-column-left; }
337345 Mod+Ctrl+WheelScrollRight { move-column-right; }
.config/scripts/niri/workspace_nav.shadded+85 -0
@@ -0,0 +1,85 @@
1+#!/usr/bin/env bash
2+# Navigate only the PLAIN (unnamed) workspaces, skipping the named app ones.
3+#
4+# usage: workspace_nav.sh focus <N> focus the Nth plain workspace
5+# workspace_nav.sh move <N> move focused column to it
6+# workspace_nav.sh next|prev focus the next/previous plain one
7+# workspace_nav.sh move-next|move-prev
8+#
9+# 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 that
11+# same list — so Mod+3 could land on "discord". The app workspaces are reachable
12+# by their own Alt+<letter> binds, and should be invisible to number and
13+# directional navigation.
14+#
15+# Everything is scoped to the focused output, matching niri's own per-output
16+# indices. N beyond the number of plain workspaces clamps to the last one; niri
17+# always keeps one empty unnamed workspace at the end of each output, so there
18+# is always at least one target.
19+set -euo pipefail
20+
21+action="${1:?usage: workspace_nav.sh focus|move|next|prev|move-next|move-prev [N]}"
22+
23+ws_json=$(niri msg -j workspaces)
24+output=$(jq -r '.[] | select(.is_focused == true) | .output' <<<"$ws_json")
25+
26+# Indices of the plain workspaces on this output, in list order.
27+mapfile -t plain < <(jq -r --arg o "$output" '
28+ [ .[] | select(.output == $o and .name == null) ] | sort_by(.idx) | .[] | .idx
29+' <<<"$ws_json")
30+
31+[ "${#plain[@]}" -gt 0 ] || exit 0
32+
33+# Where the currently focused workspace sits among them (-1 if it is a named one).
34+current_idx=$(jq -r --arg o "$output" '.[] | select(.output == $o and .is_active == true) | .idx' <<<"$ws_json")
35+pos=-1
36+for i in "${!plain[@]}"; do
37+ if [ "${plain[$i]}" = "$current_idx" ]; then
38+ pos=$i
39+ break
40+ fi
41+done
42+
43+target=""
44+
45+case "$action" in
46+focus | move)
47+ n="${2:?need a workspace number}"
48+ i=$((n - 1))
49+ [ "$i" -lt 0 ] && i=0
50+ [ "$i" -ge "${#plain[@]}" ] && i=$((${#plain[@]} - 1))
51+ target="${plain[$i]}"
52+ ;;
53+next | move-next)
54+ # From a named workspace, "next" means the first plain one.
55+ if [ "$pos" -lt 0 ]; then
56+ target="${plain[0]}"
57+ else
58+ i=$((pos + 1))
59+ [ "$i" -ge "${#plain[@]}" ] && i=$((${#plain[@]} - 1))
60+ target="${plain[$i]}"
61+ fi
62+ ;;
63+prev | move-prev)
64+ if [ "$pos" -lt 0 ]; then
65+ target="${plain[0]}"
66+ else
67+ i=$((pos - 1))
68+ [ "$i" -lt 0 ] && i=0
69+ target="${plain[$i]}"
70+ fi
71+ ;;
72+*)
73+ echo "unknown action: $action" >&2
74+ exit 1
75+ ;;
76+esac
77+
78+case "$action" in
79+focus | next | prev)
80+ niri msg action focus-workspace "$target"
81+ ;;
82+move | move-next | move-prev)
83+ niri msg action move-column-to-workspace "$target"
84+ ;;
85+esac