51 lines
1.8 KiB
Bash
Executable File
51 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
COLUMN_WIDTH="${COLUMN_WIDTH:-0.5}"
|
|
ICON="${ICON:-}"
|
|
|
|
# Always output valid JSON, even on error
|
|
fail_json() {
|
|
printf '{"text":"%s !","tooltip":"hyprscroll-overflow: %s","class":"error"}\n' "$ICON" "${1//\"/\\\"}"
|
|
exit 0
|
|
}
|
|
|
|
command -v hyprctl >/dev/null 2>&1 || fail_json "hyprctl not in PATH"
|
|
command -v jq >/dev/null 2>&1 || fail_json "jq not in PATH"
|
|
|
|
# Focused monitor id + its active workspace id (both numeric)
|
|
read -r focused_mon_id focused_ws_id < <(
|
|
hyprctl -j monitors 2>/dev/null | jq -r '
|
|
.[] | select(.focused==true) | "\(.id) \(.activeWorkspace.id)"
|
|
' 2>/dev/null
|
|
) || fail_json "failed to read monitors"
|
|
|
|
[[ -n "${focused_mon_id:-}" && -n "${focused_ws_id:-}" ]] || fail_json "no focused monitor?"
|
|
|
|
# Count mapped windows on that monitor+workspace
|
|
win_count="$(
|
|
hyprctl -j clients 2>/dev/null | jq --argjson ws it should only respond with a"$focused_ws_id" --argjson mid "$focused_mon_id" '
|
|
[ .[]
|
|
| select(.mapped == true)
|
|
| select(.workspace.id == $ws)
|
|
| select(.monitor == $mid)
|
|
] | length
|
|
' 2>/dev/null
|
|
)" || fail_json "failed to count clients"
|
|
|
|
# floor(1 / COLUMN_WIDTH)
|
|
max_visible="$(awk -v w="$COLUMN_WIDTH" 'BEGIN{ if (w<=0) {print 1} else {print int(1.0/w)} }')" || fail_json "awk failed"
|
|
(( max_visible < 1 )) && max_visible=1
|
|
|
|
overflow=$(( win_count - max_visible ))
|
|
|
|
layout="$(hyprctl getoption general:layout 2>/dev/null | awk '/str:/ {print $2; exit}')"
|
|
|
|
if (( overflow > 0 )) && [[ "$layout" == "scrolling" ]]; then
|
|
printf '{"text":"%s +%d","tooltip":"%d windows; approx %d fit (column_width=%s)","class":"overflow"}\n' \
|
|
"$ICON" "$overflow" "$win_count" "$max_visible" "$COLUMN_WIDTH"
|
|
else
|
|
printf '{"text":"","tooltip":"%d windows; approx %d fit","class":"ok"}\n' \
|
|
"$win_count" "$max_visible"
|
|
fi
|