feat(waybar): add autohide dock
This commit is contained in:
130
waybar/scripts/dock-autohide.sh
Executable file
130
waybar/scripts/dock-autohide.sh
Executable file
@@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
TOGGLE="$HOME/.config/waybar/scripts/dock-toggle.sh"
|
||||
|
||||
SHOW_EDGE_SIZE=12
|
||||
DOCK_HEIGHT=72
|
||||
HIDE_DELAY=0.35
|
||||
POLL_INTERVAL=0.08
|
||||
|
||||
LOG_FILE="/tmp/waybar-dock.log"
|
||||
DEBUG=1
|
||||
|
||||
last_inside_dock_time=0
|
||||
|
||||
log() {
|
||||
if [[ "$DEBUG" -eq 1 ]]; then
|
||||
echo "[$(date '+%H:%M:%S.%3N')] $*" >>"$LOG_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
get_cursor() {
|
||||
hyprctl -j cursorpos
|
||||
}
|
||||
|
||||
get_monitors() {
|
||||
hyprctl -j monitors
|
||||
}
|
||||
|
||||
get_monitor_for_cursor() {
|
||||
local cursor_json monitors_json
|
||||
cursor_json="$(get_cursor)"
|
||||
monitors_json="$(get_monitors)"
|
||||
|
||||
local cx cy
|
||||
cx="$(jq -r '.x' <<<"$cursor_json")"
|
||||
cy="$(jq -r '.y' <<<"$cursor_json")"
|
||||
|
||||
jq -c --argjson cx "$cx" --argjson cy "$cy" '
|
||||
map(
|
||||
. as $m
|
||||
| ($m.width / $m.scale) as $lw
|
||||
| ($m.height / $m.scale) as $lh
|
||||
| select(
|
||||
($cx >= $m.x) and
|
||||
($cx < ($m.x + $lw)) and
|
||||
($cy >= $m.y) and
|
||||
($cy < ($m.y + $lh))
|
||||
)
|
||||
) | first
|
||||
' <<<"$monitors_json"
|
||||
}
|
||||
|
||||
dock_visible() {
|
||||
[[ "$("$TOGGLE" status)" == "visible" ]]
|
||||
}
|
||||
|
||||
show_dock() {
|
||||
"$TOGGLE" show
|
||||
}
|
||||
|
||||
hide_dock() {
|
||||
"$TOGGLE" hide
|
||||
}
|
||||
|
||||
log "Started dock autohide"
|
||||
|
||||
while true; do
|
||||
cursor_json="$(get_cursor)"
|
||||
monitor_json="$(get_monitor_for_cursor)"
|
||||
now="$(date +%s.%N)"
|
||||
|
||||
cx="$(jq -r '.x' <<<"$cursor_json")"
|
||||
cy="$(jq -r '.y' <<<"$cursor_json")"
|
||||
|
||||
if [[ "$monitor_json" == "null" || -z "$monitor_json" ]]; then
|
||||
log "No monitor found for cursor x=$cx y=$cy"
|
||||
sleep "$POLL_INTERVAL"
|
||||
continue
|
||||
fi
|
||||
|
||||
mon_name="$(jq -r '.name // .id // "unknown"' <<<"$monitor_json")"
|
||||
mon_x="$(jq -r '.x' <<<"$monitor_json")"
|
||||
mon_y="$(jq -r '.y' <<<"$monitor_json")"
|
||||
mon_w="$(jq -r '.width' <<<"$monitor_json")"
|
||||
mon_h="$(jq -r '.height' <<<"$monitor_json")"
|
||||
mon_scale="$(jq -r '.scale' <<<"$monitor_json")"
|
||||
|
||||
layout_w="$(awk "BEGIN {print $mon_w / $mon_scale}")"
|
||||
layout_h="$(awk "BEGIN {print $mon_h / $mon_scale}")"
|
||||
|
||||
layout_bottom="$(awk "BEGIN {print $mon_y + $layout_h}")"
|
||||
|
||||
show_threshold="$(awk "BEGIN {print $layout_bottom - $SHOW_EDGE_SIZE}")"
|
||||
keep_visible_threshold="$(awk "BEGIN {print $layout_bottom - $DOCK_HEIGHT}")"
|
||||
|
||||
log "cursor=($cx,$cy) monitor=$mon_name raw=${mon_w}x${mon_h} scale=$mon_scale layout=${layout_w}x${layout_h} bottom=$layout_bottom show_threshold=$show_threshold keep_visible_threshold=$keep_visible_threshold"
|
||||
|
||||
# 1) Cursor ganz unten -> Dock zeigen
|
||||
if awk "BEGIN {exit !($cy >= $show_threshold)}"; then
|
||||
log "ENTER SHOW EDGE on $mon_name"
|
||||
show_dock
|
||||
last_inside_dock_time="$now"
|
||||
|
||||
# 2) Cursor ist auf dem Dock-Bereich -> sichtbar lassen
|
||||
elif awk "BEGIN {exit !($cy >= $keep_visible_threshold)}"; then
|
||||
log "INSIDE DOCK AREA on $mon_name"
|
||||
last_inside_dock_time="$now"
|
||||
|
||||
if ! dock_visible; then
|
||||
log "SHOW DOCK because cursor is inside dock area"
|
||||
show_dock
|
||||
fi
|
||||
|
||||
# 3) Cursor ist oberhalb des Dock-Bereichs -> ggf. verstecken
|
||||
else
|
||||
if dock_visible; then
|
||||
delta="$(awk "BEGIN {print $now - $last_inside_dock_time}")"
|
||||
log "ABOVE DOCK AREA delta=$delta"
|
||||
|
||||
if awk "BEGIN {exit !($delta >= $HIDE_DELAY)}"; then
|
||||
log "HIDE DOCK"
|
||||
hide_dock
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
sleep "$POLL_INTERVAL"
|
||||
done
|
||||
Reference in New Issue
Block a user