rework brightness-notify to properly calculate using percentages
This commit is contained in:
parent
5c32b08875
commit
2355c80005
1 changed files with 19 additions and 18 deletions
|
@ -1,32 +1,33 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
calc() {
|
|
||||||
awk "BEGIN {print int($*)}"
|
|
||||||
}
|
|
||||||
|
|
||||||
msgTag="brightness" # Arbitrary but unique message tag
|
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"
|
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"
|
icon="gpm-brightness-lcd"
|
||||||
percentage=100
|
newpercent=100
|
||||||
newbrightness=255
|
newbrightness=255
|
||||||
elif [ "$percentage" -gt "50" ]; then
|
elif [ "$newpercent" -gt "50" ]; then
|
||||||
icon="gpm-brightness-lcd"
|
icon="gpm-brightness-lcd"
|
||||||
elif [ "$percentage" -gt "0" ]; then
|
elif [ "$newpercent" -gt "0" ]; then
|
||||||
icon="gpm-brightness-lcd-disabled"
|
icon="gpm-brightness-lcd-disabled"
|
||||||
else
|
else
|
||||||
icon="gpm-brightness-lcd-disabled"
|
icon="gpm-brightness-lcd-disabled"
|
||||||
percentage=0
|
newpercent=0
|
||||||
newbrightness=0
|
newbrightness=0
|
||||||
fi
|
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 string:x-dunst-stack-tag:$msgTag \
|
||||||
-h int:value:$percentage \
|
-h int:value:$newpercent \
|
||||||
-h string:hlcolor:$highlight
|
-h string:hlcolor:$highlight
|
||||||
|
|
Loading…
Add table
Reference in a new issue