From 5146b807a2363584e7c2210e3b5129d63bb4a6bf Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 13 Oct 2026 17:32:21 +0900 Subject: [PATCH] Change no saved layouts when the workspaces cannot be read Without the workspace list, every workspace looked empty, so a failed hyprctl or unreadable output erased every saved layout, those of workspaces with windows included. The default command now stops and changes nothing. Co-Authored-By: Claude Opus 5.5 --- bin/omarchy-hyprland-workspace-layout-default | 8 +++++++- test/shell.d/hyprland-floating-workspaces-test.sh | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/bin/omarchy-hyprland-workspace-layout-default b/bin/omarchy-hyprland-workspace-layout-default index 35040628c4ab..19eff30dd69b 100755 --- a/bin/omarchy-hyprland-workspace-layout-default +++ b/bin/omarchy-hyprland-workspace-layout-default @@ -42,7 +42,13 @@ mkdir -p "$MODES_DIR" # default never rearranges work in progress: it is saved as that workspace's # own layout. Every other workspace, empty or not opened yet, takes the new # default, including one given a layout of its own with Super + L. -busy=$(hyprctl workspaces -j | jq -r '.[] | select(.id >= 1 and (.windows // 0) > 0) | .id') +# Without a list of workspaces nothing can tell busy from empty, so nothing is +# changed rather than every saved layout taken for an empty workspace's. +if ! workspaces=$(hyprctl workspaces -j) || + ! busy=$(jq -r 'if type == "array" then .[] | select(.id >= 1 and (.windows // 0) > 0) | .id else error("not a workspace list") end' <<<"$workspaces"); then + echo "omarchy-hyprland-workspace-layout-default: could not read the workspaces, so nothing was changed" >&2 + exit 1 +fi while read -r workspace; do [[ -n $workspace && ! -f $MODES_DIR/$workspace.lua ]] || continue diff --git a/test/shell.d/hyprland-floating-workspaces-test.sh b/test/shell.d/hyprland-floating-workspaces-test.sh index bfaf58d933f8..d3e861ef668b 100755 --- a/test/shell.d/hyprland-floating-workspaces-test.sh +++ b/test/shell.d/hyprland-floating-workspaces-test.sh @@ -119,6 +119,18 @@ grep -qxF 'o.workspace_mode({ workspace = "2", mode = "dwindle" })' "$modes_dir/ grep -qxF 'o.workspace_mode({ workspace = "6", mode = "floating" })' "$modes_dir/6.lua" || fail "a workspace with a layout of its own keeps it" pass "a new default leaves workspaces with windows as they are" + +# A failed workspace query changes nothing, rather than taking every saved +# layout for an empty workspace's. +printf 'o.workspace_mode({ workspace = "2", mode = "dwindle" })\n' >"$modes_dir/2.lua" +cp "$modes_dir/default.lua" "$tmpdir/default.before" +printf 'not json\n' >"$fake/workspaces.json" +if run omarchy-hyprland-workspace-layout-default scrolling 2>/dev/null; then + fail "a new default is refused when the workspaces cannot be read" +fi +[[ -f $modes_dir/2.lua ]] || fail "a failed workspace query keeps the saved layouts" +cmp -s "$modes_dir/default.lua" "$tmpdir/default.before" || fail "a failed workspace query keeps the old default" +pass "a failed workspace query leaves the saved layouts alone" rm -f "$modes_dir"/*.lua printf '[{ "id": 2, "name": "2", "tiledLayout": "dwindle" }, { "id": 4, "name": "4", "tiledLayout": "scrolling" }]\n' >"$fake/workspaces.json"