43 lines
1.5 KiB
Bash
Executable File
43 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
COLUMN_WIDTH="${COLUMN_WIDTH:-0.5}" # match your hyprscrolling config
|
|
ICON="${ICON:-}" # nerd-font icon
|
|
|
|
# Focused monitor id (numeric) + its active workspace id (numeric)
|
|
read -r focused_mon_id focused_ws_id < <(
|
|
hyprctl -j monitors | jq -r '
|
|
.[] | select(.focused==true) | "\(.id) \(.activeWorkspace.id)"
|
|
'
|
|
)
|
|
|
|
# Fallback if something went wrong (shouldn't happen)
|
|
focused_mon_id="${focused_mon_id:-0}"
|
|
focused_ws_id="${focused_ws_id:-1}"
|
|
|
|
# Count mapped windows on the focused monitor + its active workspace.
|
|
win_count="$(
|
|
hyprctl -j clients | jq --argjson ws "$focused_ws_id" --argjson mid "$focused_mon_id" '
|
|
[ .[]
|
|
| select(.mapped == true)
|
|
| select(.workspace.id == $ws)
|
|
| select(.monitor == $mid)
|
|
] | length
|
|
'
|
|
)"
|
|
|
|
# floor(1 / COLUMN_WIDTH) using awk (portable)
|
|
max_visible="$(awk -v w="$COLUMN_WIDTH" 'BEGIN{ if (w<=0) {print 1} else {print int(1.0/w)} }')"
|
|
if [ "$max_visible" -lt 1 ]; then max_visible=1; fi
|
|
|
|
overflow=$(( win_count - max_visible ))
|
|
|
|
if [ "$overflow" -gt 0 ]; then
|
|
printf '{"text":"%s +%d","tooltip":"%d windows on this monitor/workspace, approx %d fit (column_width=%s)","class":"overflow"}\n' \
|
|
"$ICON" "$overflow" "$win_count" "$max_visible" "$COLUMN_WIDTH"
|
|
else
|
|
# keep hidden when OK (set text to something like "•" if you want it always visible)
|
|
printf '{"text":"","tooltip":"%d windows, approx %d fit","class":"ok"}\n' \
|
|
"$win_count" "$max_visible"
|
|
fi
|