scripts/waybar/waybar-backlight.sh

53 lines
1.6 KiB
Bash
Raw Normal View History

#!/bin/bash
LOCK=/tmp/brightness-lock
if [ -e $LOCK ]; then
exit
fi
touch $LOCK
if [ -z $1 ]; then
ACTION="info"
elif [ $1 == 'up' ]; then
ACTION="set +1%"
elif [ $1 == 'down' ]; then
ACTION="set 1%-"
else
echo "Invalid argument $1"
fi
if [ -e /tmp/brightness-notification ]; then
NOTIFY_ID=$(cat /tmp/brightness-notification)
if [ -z /tmp/brightness-notification ]; then
rm /tmp/brightness-notification
fi
fi
BRIGHTNESS=$(brightnessctl info | grep Current | sed -r 's/.*\((1?[0-9]?[0-9])%\).*/\1/')
if [[ $ACTION != 'set +1%' ]] && [[ $BRIGHTNESS -eq 1 ]]; then
ACTION="info"
else
BRIGHTNESS=$(brightnessctl $ACTION | grep Current | sed -r 's/.*\((1?[0-9]?[0-9])%\).*/\1/')
if [[ $BRIGHTNESS -le 20 ]]; then
ICON='-low'
elif [[ $BRIGHTNESS -le 40 ]]; then
ICON='-low'
elif [[ $BRIGHTNESS -le 60 ]]; then
ICON='-medium'
elif [[ $BRIGHTNESS -le 80 ]]; then
ICON='-high'
else
ICON='-full'
fi
fi
if [ -n $NOTIFY_ID ]; then
NOTIFY_ID=$(notify-send --category=backlight --urgency=low --hint=int:value:$BRIGHTNESS --icon=${HOME}/.icons/Gruvbox/48x48@2x/status/notification-display-brightness${ICON}.svg -p -t 1000 -r $NOTIFY_ID Backlight ${BRIGHTNESS}%)
else
NOTIFY_ID=$(notify-send --category=backlight --urgency=low --hint=int:value:$BRIGHTNESS --icon=${HOME}/.icons/Gruvbox/48x48@2x/devices/notification-display-brightness${ICON}.svg -p -t 1000 Backlight ${BRIGHTNESS}%)
fi
echo $NOTIFY_ID > /tmp/brightness-notification
echo $BRIGHTNESS > ${HOME}/.spool/last_brightness
rm $LOCK