1
0
Fork 0

rework brightness-notify to properly calculate using percentages

This commit is contained in:
Luca Bilke 2023-04-12 11:29:00 +02:00 committed by Luca Bilke
parent 6304e72625
commit 1ba0762bca
1 changed files with 19 additions and 18 deletions

View File

@ -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