no overflow if no overflow

This commit is contained in:
2026-02-27 22:31:20 +01:00
parent b38ee6a8a4
commit 8b19518697
@@ -26,6 +26,7 @@ json_escape() {
} }
fail_json() { fail_json() {
# NOTE: errors SHOULD still show (so you notice), hence JSON output here.
local msg="hyprscroll-overflow: ${1:-unknown error}" local msg="hyprscroll-overflow: ${1:-unknown error}"
printf '{"text":"%s !","tooltip":"%s","class":"error"}\n' \ printf '{"text":"%s !","tooltip":"%s","class":"error"}\n' \
"$(json_escape "$ICON")" "$(json_escape "$msg")" "$(json_escape "$ICON")" "$(json_escape "$msg")"
@@ -45,9 +46,42 @@ read -r focused_mon_id focused_ws_id < <(
[[ -n "${focused_mon_id:-}" && -n "${focused_ws_id:-}" ]] || fail_json "no focused monitor/workspace" [[ -n "${focused_mon_id:-}" && -n "${focused_ws_id:-}" ]] || fail_json "no focused monitor/workspace"
# Current layout (needed for both normal + --pick paths)
layout="$(hyprctl getoption general:layout 2>/dev/null | awk '/str:/ {print $2; exit}' || true)"
layout="${layout:-}"
# Collect windows (current ws + current monitor, mapped only) # Collect windows (current ws + current monitor, mapped only)
clients_json="$(hyprctl -j clients 2>/dev/null)" || fail_json "failed to read clients" clients_json="$(hyprctl -j clients 2>/dev/null)" || fail_json "failed to read clients"
# Click action: pick a window and focus it
if [[ "${1:-}" == "--pick" ]]; then
# Build menu lines: address at end so we can parse it back reliably.
menu="$(
jq -r --argjson ws "$focused_ws_id" --argjson mid "$focused_mon_id" '
[ .[]
| select(.mapped == true)
| select(.workspace.id == $ws)
| select(.monitor == $mid)
| {address, class, title}
]
| map("[\(.class)] \(.title) \(.address)")
| .[]
' <<<"$clients_json"
)" || exit 0
[[ -n "${menu:-}" ]] || exit 0
# shellcheck disable=SC2086
choice="$(printf '%s\n' "$menu" | eval "$DMENU_CMD" || true)"
[[ -n "${choice:-}" ]] || exit 0
addr="$(awk '{print $NF}' <<<"$choice")"
[[ "$addr" =~ ^0x[0-9a-fA-F]+$ ]] || exit 0
hyprctl dispatch focuswindow "address:${addr}" >/dev/null 2>&1 || exit 0
exit 0
fi
# Tooltip list (multiline) # Tooltip list (multiline)
# Include a stable selector: address (hex), plus class + title for humans. # Include a stable selector: address (hex), plus class + title for humans.
tooltip_list="$( tooltip_list="$(
@@ -80,41 +114,8 @@ max_visible="$(awk -v w="$COLUMN_WIDTH" 'BEGIN{ if (w<=0) {print 1} else {print
overflow=$(( win_count - max_visible )) overflow=$(( win_count - max_visible ))
layout="$(hyprctl getoption general:layout 2>/dev/null | awk '/str:/ {print $2; exit}' || true)" # IMPORTANT: hide module by outputting NOTHING (no JSON) when not relevant
layout="${layout:-}" if (( overflow <= 0 )) || [[ "$layout" != "scrolling" ]]; then
# Click action: pick a window and focus it
if [[ "${1:-}" == "--pick" ]]; then
# Build menu lines: address at end so we can parse it back reliably.
menu="$(
jq -r --argjson ws "$focused_ws_id" --argjson mid "$focused_mon_id" '
[ .[]
| select(.mapped == true)
| select(.workspace.id == $ws)
| select(.monitor == $mid)
| {address, class, title}
]
| map("[\(.class)] \(.title) \(.address)")
| .[]
' <<<"$clients_json"
)" || exit 0
[[ -n "${menu:-}" ]] || exit 0
# shellcheck disable=SC2086
choice="$(printf '%s\n' "$menu" | eval "$DMENU_CMD" || true)"
[[ -n "${choice:-}" ]] || exit 0
addr="$(awk '{print $NF}' <<<"$choice")"
[[ "$addr" =~ ^0x[0-9a-fA-F]+$ ]] || exit 0
# Focus brings it forward in normal tiling usage; for tricky stacking cases,
# you can also add: hyprctl dispatch bringactivetotop
hyprctl dispatch focuswindow "address:${addr}" >/dev/null 2>&1 || exit 0
exit 0
fi
if (( overflow == 0 )) || [[ "$layout" != "scrolling" ]]; then
exit 0 exit 0
fi fi