1
0
Fork 0
dotfiles/.local/libexec/dwm/brightness-notify

35 lines
963 B
Text
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() {
2024-02-03 18:34:14 +01: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
2024-02-03 18:34:14 +01:00
icon="gpm-brightness-lcd"
newpercent=100
newbrightness=255
elif [ "$newpercent" -gt "50" ]; then
2024-02-03 18:34:14 +01:00
icon="gpm-brightness-lcd"
elif [ "$newpercent" -gt "0" ]; then
2024-02-03 18:34:14 +01:00
icon="gpm-brightness-lcd-disabled"
2023-03-28 18:46:39 +02:00
else
2024-02-03 18:34:14 +01:00
icon="gpm-brightness-lcd-disabled"
newpercent=0
newbrightness=0
2023-03-28 18:46:39 +02:00
fi
2024-01-27 19:54:35 +01:00
# shellcheck disable=2086
2024-01-29 14:16:07 +01:00
round $newbrightness | sudo tee /sys/class/backlight/*/brightness
2023-03-28 18:46:39 +02:00
notify-send -a "changeBrightness" -i "$icon" -u low "Brightness: ${newpercent}%" \
2024-02-03 18:34:14 +01:00
-h "string:x-dunst-stack-tag:$msgTag" \
-h "int:value:$newpercent" \
-h "string:hlcolor:$highlight"