diff --git a/.local/bin/brightness-notify b/.local/bin/brightness-notify index aeca4edb0..3ce312f2b 100755 --- a/.local/bin/brightness-notify +++ b/.local/bin/brightness-notify @@ -1,32 +1,33 @@ #!/bin/sh - -calc() { - awk "BEGIN {print int($*)}" -} - msgTag="brightness" # Arbitrary but unique message tag -oldbrightness="$(cat /sys/class/backlight/*/brightness)" -newbrightness="$(calc "$oldbrightness + $1 * 2.55")" -percentage=$(calc "$newbrightness * .39215686274509803921") highlight="#7aa2f7" -if [ "$percentage" -gt "100" ]; then +round() { + awk "BEGIN {printf \"%.0f\", $*}" +} + +oldbrightness="$(cat /sys/class/backlight/*/brightness)" +oldpercent="$(round "$oldbrightness * (100/255)")" +newpercent="$(round "$oldpercent + $1")" +newbrightness="$(round "$newpercent * (255/100)")" + +if [ "$newpercent" -gt "100" ]; then icon="gpm-brightness-lcd" - percentage=100 - newbrightness=255 -elif [ "$percentage" -gt "50" ]; then + newpercent=100 + newbrightness=255 +elif [ "$newpercent" -gt "50" ]; then icon="gpm-brightness-lcd" -elif [ "$percentage" -gt "0" ]; then +elif [ "$newpercent" -gt "0" ]; then icon="gpm-brightness-lcd-disabled" else icon="gpm-brightness-lcd-disabled" - percentage=0 - newbrightness=0 + newpercent=0 + newbrightness=0 fi -echo $newbrightness | tee /sys/class/backlight/*/brightness +round $newbrightness | tee /sys/class/backlight/*/brightness -notify-send -a "changeBrightness" -i "$icon" -u low "Brightness: ${percentage}%" \ +notify-send -a "changeBrightness" -i "$icon" -u low "Brightness: ${newpercent}%" \ -h string:x-dunst-stack-tag:$msgTag \ - -h int:value:$percentage \ + -h int:value:$newpercent \ -h string:hlcolor:$highlight