forge
Explore
Log in

Don't you dare go Hollow

App workspaces stay on the monitor they were launched on

Browse files at this commit

30226eabae5ad0c48a19ca036a639ef77c724c57Ahmet Kaan GümüşParent: 3fdedf2
  • fix
    • app workspaces stay on the monitor they were launched on
Show full message
fix(niri): app workspaces stay on the monitor they were launched on

Pressing Alt+G once the app is running now moves focus to that monitor,
instead of dragging the workspace onto whichever monitor is focused. Only an
empty (never-used) workspace is moved, so the first launch still happens where
you are and the workspace homes itself there.
.config/scripts/niri/workspace_app.shmodified+19 -12
@@ -3,10 +3,14 @@
3 #3 #
4 # usage: workspace_app.sh <workspace-name> <command> [args...]4 # usage: workspace_app.sh <workspace-name> <command> [args...]
5 #5 #
6-# Focuses the named workspace, then launches the command only if that6+# Focuses the named workspace, then launches the command only if that workspace
7-# workspace currently holds no windows. niri has no on-created-empty, and7+# currently holds no windows. niri has no on-created-empty, and named workspaces
8-# named workspaces declared in the config are persistent (never "created"),8+# declared in the config are persistent (never "created"), so the emptiness check
9-# so the emptiness check is what makes this lazy instead of duplicating apps.9+# is what makes this lazy instead of duplicating apps.
10+#
11+# An app's workspace sticks to the monitor it was first launched on. Pressing the
12+# key again moves FOCUS there rather than pulling the workspace to the monitor
13+# you happen to be on.
10 set -euo pipefail14 set -euo pipefail
11 15
12 ws="$1"16 ws="$1"
@@ -21,22 +25,25 @@ if [ -z "$id" ]; then
21 exit 125 exit 1
22 fi26 fi
23 27
24-# Named workspaces live on whichever output they were created on, and28+count=$(niri msg -j windows | jq --argjson id "$id" '[.[] | select(.workspace_id == $id)] | length')
25-# focus-workspace jumps focus to THAT output instead of bringing the workspace29+
26-# to you. So move it here FIRST, with --reference so the move needs no focus
27-# change: focusing it on the other monitor and dragging it away afterwards
28-# leaves that monitor stranded on some unrelated workspace.
29 here=$(jq -r '.[] | select(.is_focused == true) | .output' <<<"$ws_json")30 here=$(jq -r '.[] | select(.is_focused == true) | .output' <<<"$ws_json")
30 there=$(jq -r --arg w "$ws" '.[] | select(.name == $w) | .output' <<<"$ws_json")31 there=$(jq -r --arg w "$ws" '.[] | select(.name == $w) | .output' <<<"$ws_json")
31 32
32-if [ -n "$here" ] && [ "$here" != "$there" ]; then33+# The app's workspace HOME is the monitor it was first launched on, and it stays
34+# there: pressing the key again just sends focus to that monitor instead of
35+# dragging the workspace over. Only an empty (never-used) workspace gets moved,
36+# so a first launch happens where you are.
37+#
38+# --reference avoids a focus change for the move: focusing it on the other
39+# monitor and dragging it away afterwards leaves that monitor stranded on some
40+# unrelated workspace.
41+if [ "$count" -eq 0 ] && [ -n "$here" ] && [ "$here" != "$there" ]; then
33 niri msg action move-workspace-to-monitor --reference "$ws" "$here"42 niri msg action move-workspace-to-monitor --reference "$ws" "$here"
34 fi43 fi
35 44
36 niri msg action focus-workspace "$ws"45 niri msg action focus-workspace "$ws"
37 46
38-count=$(niri msg -j windows | jq --argjson id "$id" '[.[] | select(.workspace_id == $id)] | length')
39-
40 if [ "$count" -eq 0 ]; then47 if [ "$count" -eq 0 ]; then
41 setsid "$@" >/dev/null 2>&1 &48 setsid "$@" >/dev/null 2>&1 &
42 fi49 fi