Had to make some adjusttments
This commit is contained in:
@@ -4,46 +4,46 @@ set -euo pipefail
|
|||||||
COLUMN_WIDTH="${COLUMN_WIDTH:-0.5}"
|
COLUMN_WIDTH="${COLUMN_WIDTH:-0.5}"
|
||||||
ICON="${ICON:-}"
|
ICON="${ICON:-}"
|
||||||
|
|
||||||
# Always output valid JSON, even on error
|
|
||||||
fail_json() {
|
fail_json() {
|
||||||
printf '{"text":"%s !","tooltip":"hyprscroll-overflow: %s","class":"error"}\n' "$ICON" "${1//\"/\\\"}"
|
printf '{"text":"%s !","tooltip":"hyprscroll-overflow: %s","class":"error"}\n' \
|
||||||
|
"$ICON" "${1//\"/\\\"}"
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
command -v hyprctl >/dev/null 2>&1 || fail_json "hyprctl not in PATH"
|
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"
|
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 < <(
|
read -r focused_mon_id focused_ws_id < <(
|
||||||
hyprctl -j monitors 2>/dev/null | jq -r '
|
hyprctl -j monitors 2>/dev/null | jq -r '
|
||||||
.[] | select(.focused==true) | "\(.id) \(.activeWorkspace.id)"
|
.[] | select(.focused==true) | "\(.id) \(.activeWorkspace.id)"
|
||||||
' 2>/dev/null
|
'
|
||||||
) || fail_json "failed to read monitors"
|
) || fail_json "failed to read monitors"
|
||||||
|
|
||||||
[[ -n "${focused_mon_id:-}" && -n "${focused_ws_id:-}" ]] || fail_json "no focused monitor?"
|
[[ -n "${focused_mon_id:-}" && -n "${focused_ws_id:-}" ]] || fail_json "no focused monitor?"
|
||||||
|
|
||||||
# Count mapped windows on that monitor+workspace
|
|
||||||
win_count="$(
|
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" '
|
hyprctl -j clients 2>/dev/null | jq --argjson ws "$focused_ws_id" --argjson mid "$focused_mon_id" '
|
||||||
[ .[]
|
[ .[]
|
||||||
| select(.mapped == true)
|
| select(.mapped == true)
|
||||||
| select(.workspace.id == $ws)
|
| select(.workspace.id == $ws)
|
||||||
| select(.monitor == $mid)
|
| select(.monitor == $mid)
|
||||||
] | length
|
] | length
|
||||||
' 2>/dev/null
|
'
|
||||||
)" || fail_json "failed to count clients"
|
)" || 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)} }')" \
|
||||||
max_visible="$(awk -v w="$COLUMN_WIDTH" 'BEGIN{ if (w<=0) {print 1} else {print int(1.0/w)} }')" || fail_json "awk failed"
|
|| fail_json "awk failed"
|
||||||
(( max_visible < 1 )) && max_visible=1
|
(( max_visible < 1 )) && max_visible=1
|
||||||
|
|
||||||
overflow=$(( win_count - max_visible ))
|
overflow=$(( win_count - max_visible ))
|
||||||
|
|
||||||
layout="$(hyprctl getoption general:layout 2>/dev/null | awk '/str:/ {print $2; exit}')"
|
layout="$(hyprctl getoption general:layout 2>/dev/null | awk '/str:/ {print $2; exit}')"
|
||||||
|
[[ -n "${layout:-}" ]] || layout=""
|
||||||
|
|
||||||
if (( overflow > 0 )) && [[ "$layout" == "scrolling" ]]; then
|
if (( overflow > 0 )) && [[ "$layout" == "scrolling" ]]; then
|
||||||
printf '{"text":"%s +%d","tooltip":"%d windows; approx %d fit (column_width=%s)","class":"overflow"}\n' \
|
printf '{"text":"%s +%d","tooltip":"%d windows; approx %d fit (column_width=%s)","class":"overflow"}\n' \
|
||||||
"$ICON" "$overflow" "$win_count" "$max_visible" "$COLUMN_WIDTH"
|
"$ICON" "$overflow" "$win_count" "$max_visible" "$COLUMN_WIDTH"
|
||||||
else
|
else
|
||||||
printf '{"text":"","class":"hidden"}\n'
|
# truly empty (and tooltip empty) + class for CSS
|
||||||
fi
|
printf '{"text":"","tooltip":"","class":"hidden"}\n'
|
||||||
|
fi
|
||||||
|
|||||||
@@ -40,7 +40,8 @@
|
|||||||
"exec": "bash -lc 'COLUMN_WIDTH=0.5 \"$HOME/.config/hypr/scripts/hyprscroll-overflow.sh\"'",
|
"exec": "bash -lc 'COLUMN_WIDTH=0.5 \"$HOME/.config/hypr/scripts/hyprscroll-overflow.sh\"'",
|
||||||
"return-type": "json",
|
"return-type": "json",
|
||||||
"interval": 1,
|
"interval": 1,
|
||||||
"format": "{}",
|
"format": "{text}",
|
||||||
|
"tooltip": "{tooltip}",
|
||||||
},
|
},
|
||||||
|
|
||||||
"idle_inhibitor": {
|
"idle_inhibitor": {
|
||||||
|
|||||||
@@ -81,7 +81,8 @@ window#waybar {
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
border: none;
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user