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

37 lines
1,019 B
Bash
Executable file

#!/bin/sh
msgTag="brightness" # Arbitrary but unique message tag
highlight="#7aa2f7"
round() {
awk "BEGIN {printf \"%.0f\", $*}"
}
oldbrightness="$(cat /sys/class/backlight/*/brightness)"
oldpercent="$(round "$oldbrightness * (100/255)")"
case $1 in
-* | +*) newpercent="$(round "$oldpercent + $1")" ;;
*) newpercent=$1 ;;
esac
newbrightness="$(round "$newpercent * (255/100)")"
if [ "$newpercent" -gt "100" ]; then
icon="gpm-brightness-lcd"
newpercent=100
newbrightness=255
elif [ "$newpercent" -gt "50" ]; then
icon="gpm-brightness-lcd"
elif [ "$newpercent" -gt "0" ]; then
icon="gpm-brightness-lcd-disabled"
else
icon="gpm-brightness-lcd-disabled"
newpercent=0
newbrightness=0
fi
# shellcheck disable=2086
round $newbrightness | sudo tee /sys/class/backlight/*/brightness
notify-send -a "changeBrightness" -i "$icon" -u low "Brightness: ${newpercent}%" \
-h "string:x-dunst-stack-tag:$msgTag" \
-h "int:value:$newpercent" \
-h "string:hlcolor:$highlight"