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
12 changes: 12 additions & 0 deletions bin/omarchy-hyprland-window-minimize
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ fi
# Only floating workspaces have the dock to bring a window back from.
[[ $(omarchy-hyprland-workspace-layout-current "$WORKSPACE") == "floating" ]] || exit 0

remember_minimized_from() {
local address=$1 workspace=$2 clients tag
if clients=$(hyprctl clients -j); then
while read -r tag; do
[[ $tag =~ ^omarchy-minimized-from-[0-9]+$ && $tag != "omarchy-minimized-from-$workspace" ]] || continue
hyprctl dispatch "hl.dsp.window.tag({ tag = \"-$tag\", window = \"address:$address\" })" >/dev/null
done < <(jq -r --arg address "$address" '.[] | select(.address == $address) | (.tags // [])[]' <<<"$clients")
fi
hyprctl dispatch "hl.dsp.window.tag({ tag = \"+omarchy-minimized-from-$workspace\", window = \"address:$address\" })" >/dev/null
}

remember_minimized_from "$ADDRESS" "$WORKSPACE"
hyprctl dispatch "hl.dsp.window.move({ workspace = \"special:minimized\", follow = false, window = \"address:$ADDRESS\" })" >/dev/null

# Focus would otherwise stay with the minimized window, and the next window
Expand Down
28 changes: 25 additions & 3 deletions bin/omarchy-hyprland-workspace-layout-default
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,31 @@ mkdir -p "$MODES_DIR"
# default, including one given a layout of its own with Super + L.
# 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
busy_workspace_ids() {
local workspaces clients
workspaces=$(hyprctl workspaces -j) || return 1
clients=$(hyprctl clients -j) || return 1
# Both lists go through stdin, as a long client list outgrows one argument.
printf '%s\n%s\n' "$workspaces" "$clients" | jq -rs '
.[0] as $workspaces | .[1] as $clients |
if ($workspaces | type == "array") and ($clients | type == "array") then
(
[$workspaces[] | select(.id >= 1 and (.windows // 0) > 0) | .id] +
[$clients[]
| select(.workspace.name == "special:minimized")
| (.tags // [])[]
| select(test("^omarchy-minimized-from-[1-9][0-9]*$"))
| sub("^omarchy-minimized-from-"; "")
| tonumber]
) | unique | .[]
else
error("not a workspace list")
end
'
}

if ! busy=$(busy_workspace_ids); then
echo "omarchy-hyprland-workspace-layout-default: could not read the workspaces or the minimized windows, so nothing was changed" >&2
exit 1
fi

Expand Down
2 changes: 1 addition & 1 deletion manual/04-navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ A floating workspace works like a traditional desktop: windows overlap, and you

A floating workspace also shows a dock, with your pinned apps, everything that's running, and a grid of every app behind the apps button, which `Super + Alt + Space` and _Apps_ in the Omarchy menu open too. Right-click an app on the grid, or press `Delete`, to uninstall it. Click an app to open it, or to bring its window forward; click again to cycle through its windows. Middle-click opens a new window. Drag an icon along the dock to move it; dragging a running app in among the others keeps it there. Right-click to keep an app in the dock, take it out, or quit it. The dock gets out of the way of a fullscreen window. Right-click the apps button to move the dock to another edge or have it hide until the pointer reaches its edge. The position is also under _Trigger > Appearance > Dock > Dock Position_, and `omarchy dock position left` and `omarchy dock autohide on` set both from a terminal. Apps you keep in the dock are faded while they aren't running.

New workspaces, and any you haven't given a layout of their own with `Super + L`, use the default layout. Changing the default resets every workspace without windows to it, while one with windows on it keeps the layout it has. Pick it under _Trigger > Appearance > Workspace Layout_: Tiling, Scrolling, or Floating. `omarchy-hyprland-workspace-layout-default scrolling` sets it from a terminal.
New workspaces, and any you haven't given a layout of their own with `Super + L`, use the default layout. Changing the default resets every workspace without windows to it, while one with windows on it keeps the layout it has. A window minimized to the dock still counts as a window on the workspace it left. Pick it under _Trigger > Appearance > Workspace Layout_: Tiling, Scrolling, or Floating. `omarchy-hyprland-workspace-layout-default scrolling` sets it from a terminal.

### Grouping windows

Expand Down
20 changes: 19 additions & 1 deletion test/shell.d/dock-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,34 @@ chmod +x "$mock_bin/omarchy-hyprland-workspace-layout-current"
minimize() { PATH="$mock_bin:$ROOT/bin:$PATH" omarchy-hyprland-window-minimize "$@"; }

minimize 0xabc
grep -qxF 'hl.dsp.window.tag({ tag = "+omarchy-minimized-from-3", window = "address:0xabc" })' "$TMPDIR/hyprctl.log" ||
fail "minimize remembers the workspace the window left" "$(cat "$TMPDIR/hyprctl.log")"
grep -qxF 'hl.dsp.window.move({ workspace = "special:minimized", follow = false, window = "address:0xabc" })' "$TMPDIR/hyprctl.log" ||
fail "minimize moves the window to the dock's hidden workspace" "$(cat "$TMPDIR/hyprctl.log")"
[[ $(tail -1 "$TMPDIR/hyprctl.log") == 'hl.dsp.focus({ workspace = "3" })' ]] ||
fail "minimize focuses the workspace the window left" "$(cat "$TMPDIR/hyprctl.log")"
: >"$TMPDIR/hyprctl.log"
minimize
grep -qF 'address:0xdef' "$TMPDIR/hyprctl.log" && [[ $(tail -1 "$TMPDIR/hyprctl.log") == 'hl.dsp.focus({ workspace = "5" })' ]] ||
grep -qF 'hl.dsp.window.tag({ tag = "+omarchy-minimized-from-5", window = "address:0xdef" })' "$TMPDIR/hyprctl.log" &&
grep -qF 'address:0xdef' "$TMPDIR/hyprctl.log" && [[ $(tail -1 "$TMPDIR/hyprctl.log") == 'hl.dsp.focus({ workspace = "5" })' ]] ||
fail "minimize takes the active window when given none" "$(cat "$TMPDIR/hyprctl.log")"
pass "minimize sends a window to the dock and keeps focus on its workspace"

cat >"$mock_bin/hyprctl" <<STUB
#!/bin/bash
case "\$1" in
clients) printf '[{"address":"0xabc","workspace":{"id":7},"tags":["omarchy-minimized-from-3"]}]\n' ;;
dispatch) printf '%s\n' "\$2" >>"$TMPDIR/hyprctl.log" ;;
esac
STUB
: >"$TMPDIR/hyprctl.log"
minimize 0xabc
grep -qxF 'hl.dsp.window.tag({ tag = "-omarchy-minimized-from-3", window = "address:0xabc" })' "$TMPDIR/hyprctl.log" ||
fail "minimize forgets the previous workspace" "$(cat "$TMPDIR/hyprctl.log")"
grep -qxF 'hl.dsp.window.tag({ tag = "+omarchy-minimized-from-7", window = "address:0xabc" })' "$TMPDIR/hyprctl.log" ||
fail "minimize remembers the workspace it leaves this time" "$(cat "$TMPDIR/hyprctl.log")"
pass "minimize remembers only the workspace the window is leaving"

# A tiled workspace has no dock to bring a window back from, so nothing there
# is minimized.
cat >"$mock_bin/hyprctl" <<STUB
Expand Down
68 changes: 68 additions & 0 deletions test/shell.d/hyprland-floating-workspaces-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ cat >"$fake/monitors.json" <<'EOF'
EOF
printf '{ "id": 2, "name": "2", "tiledLayout": "dwindle" }\n' >"$fake/activeworkspace.json"
printf '[{ "id": 2, "name": "2", "tiledLayout": "dwindle" }, { "id": 4, "name": "4", "tiledLayout": "scrolling" }]\n' >"$fake/workspaces.json"
printf '[]\n' >"$fake/clients.json"
reset_logs

# --- Which layout a workspace is in -------------------------------------------
Expand Down Expand Up @@ -120,6 +121,73 @@ grep -qxF 'o.workspace_mode({ workspace = "6", mode = "floating" })' "$modes_dir
fail "a workspace with a layout of its own keeps it"
pass "a new default leaves workspaces with windows as they are"

rm -f "$modes_dir"/*.lua
printf 'o.workspace_mode({ default = "floating" })\n' >"$modes_dir/default.lua"
printf 'o.workspace_mode({ workspace = "4", mode = "floating" })\n' >"$modes_dir/4.lua"
printf 'o.workspace_mode({ workspace = "8", mode = "floating" })\n' >"$modes_dir/8.lua"
printf '[{ "id": 4, "name": "4", "windows": 0 }, { "id": 8, "name": "8", "windows": 0 }]\n' >"$fake/workspaces.json"
cat >"$fake/clients.json" <<'EOF'
[
{
"address": "0xabc",
"workspace": { "name": "special:minimized", "type": "special" },
"tags": ["omarchy-minimized-from-4"]
},
{
"address": "0xdef",
"workspace": { "name": "special:scratchpad", "type": "special" },
"tags": ["omarchy-minimized-from-8"]
}
]
EOF
run omarchy-hyprland-workspace-layout-default dwindle
grep -qxF 'o.workspace_mode({ workspace = "4", mode = "floating" })' "$modes_dir/4.lua" ||
fail "a workspace with a minimized window keeps its floating layout" "$(cat "$modes_dir/4.lua" 2>&1)"
[[ ! -e $modes_dir/8.lua ]] || fail "a scratchpad window does not keep another workspace's layout"
[[ $(run omarchy-hyprland-workspace-layout-current 4) == "floating" ]] ||
fail "the minimized window's workspace still reports floating"
[[ $(run omarchy-hyprland-workspace-layout-current 8) == "dwindle" ]] ||
fail "an empty workspace takes the new default"
pass "a minimized window keeps its workspace floating, and an empty one does not"

rm -f "$modes_dir"/*.lua
printf 'o.workspace_mode({ default = "floating" })\n' >"$modes_dir/default.lua"
printf '[{ "id": 2, "name": "2", "windows": 0 }]\n' >"$fake/workspaces.json"
printf '[{ "address": "0xabc", "workspace": { "name": "special:minimized" }, "tags": ["omarchy-minimized-from-2"] }]\n' >"$fake/clients.json"
run omarchy-hyprland-workspace-layout-default scrolling
grep -qxF 'o.workspace_mode({ workspace = "2", mode = "floating" })' "$modes_dir/2.lua" ||
fail "a minimized window's workspace keeps floating when the default changes" "$(ls "$modes_dir"; echo '---'; cat "$modes_dir"/*.lua)"
grep -qxF 'o.workspace_mode({ default = "scrolling" })' "$modes_dir/default.lua" ||
fail "the new default is still saved"
[[ $(run omarchy-hyprland-workspace-layout-current 2) == "floating" ]] ||
fail "the minimized window's workspace stays floating"
pass "a minimized window pins the floating layout the default used to give its workspace"

rm -f "$modes_dir"/*.lua
printf 'o.workspace_mode({ default = "floating" })\n' >"$modes_dir/default.lua"
printf '[{ "id": 2, "name": "2", "windows": 0 }]\n' >"$fake/workspaces.json"
jq -n '[range(200) | { address: "0x\(.)", workspace: { name: "3" }, title: ("x" * 1000) }] +
[{ address: "0xabc", workspace: { name: "special:minimized" }, tags: ["omarchy-minimized-from-2"] }]' >"$fake/clients.json"
run omarchy-hyprland-workspace-layout-default scrolling ||
fail "a new default is set however long the client list"
grep -qxF 'o.workspace_mode({ workspace = "2", mode = "floating" })' "$modes_dir/2.lua" ||
fail "a long client list still keeps a minimized window's workspace floating"
pass "a client list longer than one argument still sets the default"

rm -f "$modes_dir"/*.lua
printf 'o.workspace_mode({ default = "floating" })\n' >"$modes_dir/default.lua"
printf 'o.workspace_mode({ workspace = "2", mode = "floating" })\n' >"$modes_dir/2.lua"
cp "$modes_dir/default.lua" "$tmpdir/default.before"
printf '[{ "id": 2, "name": "2", "windows": 0 }]\n' >"$fake/workspaces.json"
printf 'not json\n' >"$fake/clients.json"
if run omarchy-hyprland-workspace-layout-default scrolling 2>/dev/null; then
fail "a new default is refused when minimized windows cannot be read"
fi
[[ -f $modes_dir/2.lua ]] || fail "an unreadable client list keeps the saved layouts"
cmp -s "$modes_dir/default.lua" "$tmpdir/default.before" || fail "an unreadable client list keeps the old default"
pass "an unreadable client list leaves the saved layouts alone"
printf '[]\n' >"$fake/clients.json"

# 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"
Expand Down