1
0
Fork 0
dotfiles/.local/bin/brightness-notify

34 lines
926 B
Plaintext
Raw Normal View History

2023-03-28 18:46:39 +02:00
#!/bin/sh
msgTag="brightness" # Arbitrary but unique message tag
highlight="#7aa2f7"
2023-03-28 18:46:39 +02:00
round() {
2023-04-12 11:37:10 +02:00
awk "BEGIN {printf \"%.0f\", $*}"
2023-03-28 18:46:39 +02:00
}
oldbrightness="$(cat /sys/class/backlight/*/brightness)"
oldpercent="$(round "$oldbrightness * (100/255)")"
newpercent="$(round "$oldpercent + $1")"
newbrightness="$(round "$newpercent * (255/100)")"
2023-03-28 18:46:39 +02:00
if [ "$newpercent" -gt "100" ]; then
2023-04-12 11:37:10 +02:00
icon="gpm-brightness-lcd"
newpercent=100
newbrightness=255
elif [ "$newpercent" -gt "50" ]; then
2023-04-12 11:37:10 +02:00
icon="gpm-brightness-lcd"
elif [ "$newpercent" -gt "0" ]; then
2023-04-12 11:37:10 +02:00
icon="gpm-brightness-lcd-disabled"
2023-03-28 18:46:39 +02:00
else
2023-04-12 11:37:10 +02:00
icon="gpm-brightness-lcd-disabled"
newpercent=0
newbrightness=0
2023-03-28 18:46:39 +02:00
fi
round $newbrightness | tee /sys/class/backlight/*/brightness
2023-03-28 18:46:39 +02:00
notify-send -a "changeBrightness" -i "$icon" -u low "Brightness: ${newpercent}%" \
2023-04-12 11:37:10 +02:00
-h string:x-dunst-stack-tag:$msgTag \
-h int:value:$newpercent \
-h string:hlcolor:$highlight