#!/usr/bin/env bash OUTPUT="${1:-DP-2}" if [[ "$OUTPUT" == "DP-2" ]]; then IDS=(1 2 3 4 5) else IDS=(6 7 8 9 10) fi # 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 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 emit done