get app icons for each workspace

This commit is contained in:
samantha42
2026-04-23 05:43:05 +02:00
parent 52fa42698f
commit f7d6f07e3a
9 changed files with 334 additions and 106 deletions

View File

@@ -7,30 +7,39 @@ else
IDS=(6 7 8 9 10)
fi
emit() {
local active urgent result
active=$(hyprctl activeworkspace -j 2>/dev/null | jq -r '.id')
urgent=$(hyprctl clients -j 2>/dev/null \
| jq -r '[.[] | select(.urgent==true) | .workspace.id] | unique | .[]')
result="["
for id in "${IDS[@]}"; do
local is_active="false"
local is_urgent="false"
[[ "$id" == "$active" ]] && is_active="true"
grep -qx "$id" <<< "$urgent" && is_urgent="true"
result+="{\"id\":$id,\"label\":\"$id\",\"active\":$is_active,\"urgent\":$is_urgent,\"output\":\"$OUTPUT\"},"
done
printf '%s\n' "${result%,}]"
# find the socket dynamically instead of relying on env var
get_socket() {
local runtime="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
local sig
sig=$(ls "$runtime/hypr/" 2>/dev/null | head -n1)
echo "$runtime/hypr/$sig/.socket2.sock"
}
emit() {
local active urgent_ids json
active=$(hyprctl activeworkspace -j 2>/dev/null | jq -r '.id')
urgent_ids=$(hyprctl clients -j 2>/dev/null \
| jq -r '[.[] | select(.urgent==true) | .workspace.id] | unique | .[]')
json=$(for id in "${IDS[@]}"; do
is_active=false
is_urgent=false
[[ "$id" == "$active" ]] && is_active=true
grep -qx "$id" <<< "$urgent_ids" && is_urgent=true
printf '{"id":%s,"label":"%s","active":%s,"urgent":%s,"output":"%s"}\n' \
"$id" "$id" "$is_active" "$is_urgent" "$OUTPUT"
done | jq -sc '.')
printf '%s\n' "$json"
}
# emit once on start
emit
# listen for events and re-emit
socat -u "UNIX-CONNECT:/tmp/hypr/${HYPRLAND_INSTANCE_SIGNATURE}/.socket2.sock" - \
SOCKET=$(get_socket)
echo "Using socket: $SOCKET" >&2
socat -u "UNIX-CONNECT:$SOCKET" - \
| stdbuf -oL grep -E "^(workspace|focusedmon|activewindow|urgent|createworkspace|destroyworkspace)>" \
| while IFS= read -r _; do
sleep 0.05