Files
illogical-impulse/tetrio/.config/eww/scripts/brightness
T
2024-02-22 15:35:06 +07:00

64 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
icons=("" "" "")
XDG_CACHE_HOME="$HOME/.cache"
date="$XDG_CACHE_HOME/eww/osd_brightness.date"
lock=0
showhide() {
# get dates
rundate=$(cat "$date")
currentdate=$(date +%s)
# handle showing
if [ "$rundate" = "$currentdate" ] && [ "$lock" -eq 0 ]; then
eww open osd
eww update osd_bright=true
lock=1
elif [ "$((currentdate - rundate))" = "2" ] && [ "$lock" -eq 1 ]; then
eww update osd_bright=false
if [ "$(eww get osd_vol)" = "false" ] && [ "$(eww get osd_bright)" = "false" ]; then
dummy=$(eww close osd)
fi
lock=0
fi
}
osd() {
if [ ! -f "$date" ]; then
mkdir -p "$XDG_CACHE_HOME/eww"
fi
date +%s > "$date"
# showhide
}
osd_handler() {
lock=0
rundate=0
if [ ! -f "$date" ]; then
mkdir -p "$XDG_CACHE_HOME/eww"
echo 0 > "$date"
fi
while true; do
showhide
sleep 0.1
done
dummy=$(eww close osd)
}
if [ "$1" = "osd" ]; then
osd
else
# initial
icon=${icons[$(awk -v n="$(light)" 'BEGIN{print int(n/34)}')]}
echo '{ "level": '"$(light)"', "icon": "'"$icon"'" }'
osd_handler &
udevadm monitor | rg --line-buffered "backlight" | while read -r _; do
icon="${icons[$(awk -v n="$(light)" 'BEGIN{print int(n/34)}')]}"
echo '{ "level": '"$(light)"', "icon": "'"$icon"'" }'
done
fi