Lots of new rules for hyprland

This commit is contained in:
2026-03-03 21:13:17 +01:00
parent 1bbf62fae2
commit 2776626e40
103 changed files with 490 additions and 5799 deletions
@@ -1,134 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
# Usage:
# Waybar exec: hyprscroll-overflow.sh
# Waybar on-click: hyprscroll-overflow.sh --pick
#
# Env:
# COLUMN_WIDTH=0.5
# ICON="󰓒"
# DMENU_CMD="walker --dmenu" (or: "wofi --dmenu", "rofi -dmenu", etc.)
COLUMN_WIDTH="${COLUMN_WIDTH:-0.5}"
ICON="${ICON:-󰓒}"
DMENU_CMD="${DMENU_CMD:-walker --dmenu}"
json_escape() {
# minimal JSON string escape (quotes, backslashes, newlines, tabs, CR)
local s="${1:-}"
s="${s//\\/\\\\}"
s="${s//\"/\\\"}"
s="${s//$'\n'/\\n}"
s="${s//$'\r'/\\r}"
s="${s//$'\t'/\\t}"
printf '%s' "$s"
}
fail_json() {
# NOTE: errors SHOULD still show (so you notice), hence JSON output here.
local msg="hyprscroll-overflow: ${1:-unknown error}"
printf '{"text":"%s !","tooltip":"%s","class":"error"}\n' \
"$(json_escape "$ICON")" "$(json_escape "$msg")"
exit 0
}
need() { command -v "$1" >/dev/null 2>&1 || fail_json "$1 not in PATH"; }
need hyprctl
need jq
need awk
read -r focused_mon_id focused_ws_id < <(
hyprctl -j monitors 2>/dev/null | jq -r '
.[] | select(.focused==true) | "\(.id) \(.activeWorkspace.id)"
'
) || fail_json "failed to read 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)
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)
# Include a stable selector: address (hex), plus class + title for humans.
tooltip_list="$(
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}
]
| to_entries
| map("\(.key+1). [\(.value.class)] \(.value.title) (\(.value.address))")
| .[]
' <<<"$clients_json"
)" || fail_json "failed to build tooltip list"
win_count="$(
jq -r --argjson ws "$focused_ws_id" --argjson mid "$focused_mon_id" '
[ .[]
| select(.mapped == true)
| select(.workspace.id == $ws)
| select(.monitor == $mid)
] | length
' <<<"$clients_json"
)" || fail_json "failed to count clients"
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 ))
# IMPORTANT: hide module by outputting NOTHING (no JSON) when not relevant
if (( overflow <= 0 )) || [[ "$layout" != "scrolling" ]]; then
exit 0
fi
text="$ICON +$overflow"
cls="overflow"
# IMPORTANT: use "$'\n' for newliners
tooltip="WS ${focused_ws_id}${win_count} window(s) "$'\n'
tooltip+="Approx ${max_visible} fit (column_width=${COLUMN_WIDTH}) "$'\n'
tooltip+="------------------------------"$'\n'
tooltip+="${tooltip_list:-"(no windows)"}"
printf '{"text":"%s","tooltip":"%s","class":"%s"}\n' \
"$(json_escape "$text")" \
"$(json_escape "$tooltip")" \
"$(json_escape "$cls")"
@@ -1,90 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
# hyprscrolling-per-monitor.sh
# Usage:
# ./hyprscrolling-per-monitor.sh <MONITOR_NAME>
#
# Example:
# ./hyprscrolling-per-monitor.sh DP-1
#
# This script reads the current resolution for the given monitor via hyprctl
# and sets hyprscrolling column width accordingly.
if [[ $# -lt 1 ]]; then
echo "Usage: $0 <MONITOR_NAME>"
exit 2
fi
MONITOR="$1"
# Map a resolution (WIDTHxHEIGHT) to a column width value for hyprscrolling.
# Tune these values to taste.
columnwidth_for_resolution() {
local res="$1"
case "$res" in
# --- Ultra-wide / super-wide ---
5120x1440) echo "0.22" ;; # 49" 32:9
3840x1080) echo "0.25" ;; # 49" 32:9 (your ultrawide)
3440x1440) echo "0.33" ;; # 34" 21:9
2560x1080) echo "0.40" ;; # 21:9 budget ultrawide
# --- QHD / high DPI ---
3840x2160) echo "0.40" ;; # 4K
3200x1800) echo "0.50" ;;
2880x1800) echo "0.50" ;;
2560x1600) echo "0.55" ;; # 16:10
2560x1440) echo "0.55" ;; # QHD
# --- FHD / laptop-ish ---
1920x1200) echo "0.55" ;; # 16:10
1920x1080) echo "0.50" ;; # FHD (your laptop request)
# --- HD / smaller ---
1680x1050) echo "0.65" ;;
1600x900) echo "0.70" ;;
1366x768) echo "0.80" ;;
1280x720) echo "0.85" ;;
# Unknown / fallback
*) echo "" ;;
esac
}
# Get resolution for a named monitor from hyprctl.
# Output format should be WIDTHxHEIGHT (e.g. 3840x1080).
get_monitor_resolution() {
local mon="$1"
local line
if ! line="$(hyprctl monitors 2>/dev/null | grep -A1 -E "^Monitor ${mon} " -m1 | tail -n1 || true)"; then
echo ""
return 0
fi
# Extract the resolution (e.g., 3840x1080) from the line
local token
token="$(echo "$line" | awk '{print $1}' | cut -d'@' -f1 || true)"
echo "$token"
}
resolution="$(get_monitor_resolution "$MONITOR")"
if [[ -z "$resolution" ]]; then
echo "Could not determine resolution for monitor '$MONITOR'."
echo "Tip: check available names with: hyprctl monitors"
exit 1
fi
colw="$(columnwidth_for_resolution "$resolution")"
if [[ -z "$colw" ]]; then
echo "No mapping for resolution '$resolution' on monitor '$MONITOR'."
echo "Add it to columnwidth_for_resolution() in this script."
exit 1
fi
# Apply to hyprscrolling.
# Using layoutmsg colresize (as in your snippet).
hyprctl dispatch layoutmsg colresize all "$colw"
echo "hyprscrolling: set column width to $colw for monitor '$MONITOR' ($resolution)"