Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bin/omarchy-hyprland-workspace-layout-default
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +47 to +48

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Empty replies erase saved layouts

If hyprctl workspaces -j succeeds but returns empty or whitespace-only output, jq exits successfully without running the type check. That leaves busy empty, so the command deletes every saved workspace layout and overwrites default.lua, including layouts for workspaces with open windows.

Reject responses containing no JSON value before changing files, while still accepting []. Add an empty-output regression case alongside the malformed-JSON test.

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
Expand Down
12 changes: 12 additions & 0 deletions test/shell.d/hyprland-floating-workspaces-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down