Adapted overflow script

This commit is contained in:
2026-02-26 15:05:14 +01:00
parent 7aa2c51438
commit 7b09e630fb
2 changed files with 25 additions and 26 deletions
@@ -1,30 +1,30 @@
#!/usr/bin/env bash
set -euo pipefail
# Estimate how many "columns" fit on the focused monitor:
# max_visible_cols ≈ floor(1 / column_width)
# Then compare with number of windows in the active workspace on that monitor.
#
# Notes:
# - This is an approximation (hyprscrolling can have edge cases), but works well in practice.
# - If you use different column_width per monitor, you can extend this by detecting monitor + mapping widths.
COLUMN_WIDTH="${COLUMN_WIDTH:-0.5}" # match your hyprscrolling config
ICON="${ICON:-󰓒}" # nerd-font icon
COLUMN_WIDTH="${COLUMN_WIDTH:-0.5}" # match your hyprscrolling config
ICON="${ICON:-󰓒}" # pick any nerd-font icon you like
# 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)"
'
)
active_ws="$(hyprctl -j activeworkspace | jq -r '.id')"
focused_mon="$(hyprctl -j monitors | jq -r '.[] | select(.focused==true) | .name')"
# Fallback if something went wrong (shouldn't happen)
focused_mon_id="${focused_mon_id:-0}"
focused_ws_id="${focused_ws_id:-1}"
# Count windows on the active workspace (and on the focused monitor).
# (Many people keep workspaces per-monitor; this keeps the widget “per your current screen”.)
win_count="$(hyprctl -j clients \
| jq --argjson ws "$active_ws" --arg mon "$focused_mon" '
[ .[]
| select(.workspace.id == $ws)
| select(.monitor == $mon)
| select(.mapped == true)
] | length
')"
# 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)} }')"
@@ -33,11 +33,10 @@ if [ "$max_visible" -lt 1 ]; then max_visible=1; fi
overflow=$(( win_count - max_visible ))
if [ "$overflow" -gt 0 ]; then
# Waybar expects JSON for custom modules
printf '{"text":"%s +%d","tooltip":"%d windows on this workspace, approx %d fit on-screen (column_width=%s)","class":"overflow"}\n' \
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
# empty output hides it if you use "return-type: json" + "format": "{}"
printf '{"text":"","tooltip":"%d windows, approx %d fit on-screen","class":"ok"}\n' \
# 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
fi