2024-02-01 04:20:58 +00:00
|
|
|
#!/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
|
|
|
|
|
2024-02-02 03:28:50 +00:00
|
|
|
if [ -z $NOTIFY_ID ]; then
|
2024-02-01 04:20:58 +00:00
|
|
|
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}%)
|
2024-02-02 03:28:50 +00:00
|
|
|
else
|
|
|
|
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}%)
|
2024-02-01 04:20:58 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo $NOTIFY_ID > /tmp/brightness-notification
|
|
|
|
echo $BRIGHTNESS > ${HOME}/.spool/last_brightness
|
|
|
|
rm $LOCK
|