30 lines
1.1 KiB
Bash
30 lines
1.1 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
fallback='{"text":" ","class":"hidden"}'
|
|
# Get active workspace ID
|
|
active_ws=$(hyprctl activeworkspace -j | jq '.id') || { echo "$fallback"; exit 0; }
|
|
# Get all clients on this workspace
|
|
ws_clients=$(hyprctl clients -j | jq "[.[] | select(.workspace.id==$active_ws)]")
|
|
total_clients=$(echo "$ws_clients" | jq 'length')
|
|
(( total_clients == 0 )) && { echo "$fallback"; exit 0; }
|
|
# Get all monitors
|
|
monitors=$(hyprctl monitors -j)
|
|
# Count windows that are fully inside any monitor
|
|
visible_count=$(jq -n --argjson clients "$ws_clients" --argjson monitors "$monitors" '
|
|
[ $clients[] | select(
|
|
($monitors[] |
|
|
.x <= .at[0] and (.at[0] + .size[0]) <= (.x + .width) and
|
|
.y <= .at[1] and (.at[1] + .size[1]) <= (.y + .height)
|
|
)
|
|
) ] | length
|
|
')
|
|
# Show fallback if all windows fit
|
|
if (( total_clients <= visible_count )); then
|
|
echo "$fallback"
|
|
exit 0
|
|
fi
|
|
# Build tooltip
|
|
tooltip=$(echo "$ws_clients" | jq -r '.[].title' | sed ':a;N;$!ba;s/\n/\\n/g')
|
|
# Output JSON
|
|
echo "{\"text\":\"★ $total_clients\",\"tooltip\":\"$tooltip\",\"class\":\"overflow\"}"
|