#!/usr/bin/env bash # shellcheck source=/dev/null source "$(dirname "$0")"/utils icons=("" "" "") date="$XDG_CACHE_HOME/eww/osd_brightness.date" gen_output() { percent="$(brillo)" icon="${icons[$(awk -v n="$percent" 'BEGIN{print int(n/34)}')]}" echo '{"percent": "'"$percent"'", "icon": "'"$icon"'"}' } if [ "$1" = "osd" ]; then osd "$date" else # initial last_time=$(get_time_ms) gen_output osd_handler "osd-brightness" & udevadm monitor | rg --line-buffered "backlight" | while read -r _; do current_time=$(get_time_ms) delta=$((current_time - last_time)) if [[ $delta -gt 50 ]]; then gen_output # reset debounce timer last_time=$(get_time_ms) fi done fi