Adapted overflow script
This commit is contained in:
@@ -1,30 +1,30 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# Estimate how many "columns" fit on the focused monitor:
|
COLUMN_WIDTH="${COLUMN_WIDTH:-0.5}" # match your hyprscrolling config
|
||||||
# max_visible_cols ≈ floor(1 / column_width)
|
ICON="${ICON:-}" # nerd-font icon
|
||||||
# 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
|
# Focused monitor id (numeric) + its active workspace id (numeric)
|
||||||
ICON="${ICON:-}" # pick any nerd-font icon you like
|
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')"
|
# Fallback if something went wrong (shouldn't happen)
|
||||||
focused_mon="$(hyprctl -j monitors | jq -r '.[] | select(.focused==true) | .name')"
|
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).
|
# Count mapped windows on the focused monitor + its active workspace.
|
||||||
# (Many people keep workspaces per-monitor; this keeps the widget “per your current screen”.)
|
win_count="$(
|
||||||
win_count="$(hyprctl -j clients \
|
hyprctl -j clients | jq --argjson ws "$focused_ws_id" --argjson mid "$focused_mon_id" '
|
||||||
| jq --argjson ws "$active_ws" --arg mon "$focused_mon" '
|
[ .[]
|
||||||
[ .[]
|
| select(.mapped == true)
|
||||||
| select(.workspace.id == $ws)
|
| select(.workspace.id == $ws)
|
||||||
| select(.monitor == $mon)
|
| select(.monitor == $mid)
|
||||||
| select(.mapped == true)
|
] | length
|
||||||
] | length
|
'
|
||||||
')"
|
)"
|
||||||
|
|
||||||
# floor(1 / COLUMN_WIDTH) using awk (portable)
|
# 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)} }')"
|
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 ))
|
overflow=$(( win_count - max_visible ))
|
||||||
|
|
||||||
if [ "$overflow" -gt 0 ]; then
|
if [ "$overflow" -gt 0 ]; then
|
||||||
# Waybar expects JSON for custom modules
|
printf '{"text":"%s +%d","tooltip":"%d windows on this monitor/workspace, approx %d fit (column_width=%s)","class":"overflow"}\n' \
|
||||||
printf '{"text":"%s +%d","tooltip":"%d windows on this workspace, approx %d fit on-screen (column_width=%s)","class":"overflow"}\n' \
|
|
||||||
"$ICON" "$overflow" "$win_count" "$max_visible" "$COLUMN_WIDTH"
|
"$ICON" "$overflow" "$win_count" "$max_visible" "$COLUMN_WIDTH"
|
||||||
else
|
else
|
||||||
# empty output hides it if you use "return-type: json" + "format": "{}"
|
# keep hidden when OK (set text to something like "•" if you want it always visible)
|
||||||
printf '{"text":"","tooltip":"%d windows, approx %d fit on-screen","class":"ok"}\n' \
|
printf '{"text":"","tooltip":"%d windows, approx %d fit","class":"ok"}\n' \
|
||||||
"$win_count" "$max_visible"
|
"$win_count" "$max_visible"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user