Improve backlight

This commit is contained in:
Midgard 2020-10-21 20:04:02 +02:00
parent 9d1ed09dc6
commit bc08bad7fa
Signed by untrusted user who does not match committer: midgard
GPG key ID: 511C112F1331BBB4

View file

@ -1,5 +1,7 @@
#!/bin/bash
set -euo pipefail
# Control screen brightness in a logarithmic fashion. Linear backlight control
# just annoys me: I want fine-grained control over low brightnesses and quickly
# change the value at high brightnesses.
@ -22,20 +24,40 @@ pgrep -u $UID -x xbacklight >/dev/null && exit
# Calculate new target brightness
current_brightness=$(xbacklight -get)
case $1 in
up)
target=$((current_brightness * $change_percent / 100))
[ $target -ne $current_brightness ] || target=$((target + 1))
;;
down)
target=$((current_brightness * 100 / $change_percent))
[ $target -ne $current_brightness ] || target=$((target - 1))
;;
esac
# Boundaries: can't go higher than 100% or lower than 1%
[ $target -le 1 ] && target=1
[ $target -ge 100 ] && target=100
new_target() {
echo $current_brightness >&2
case $1 in
up)
if [ $current_brightness = 0 ]; then
echo 1
return
fi
target=$((current_brightness * $change_percent / 100))
[ $target -ne $current_brightness ] || target=$((target + 1))
;;
down)
if [ $current_brightness = 0 ]; then
echo 0.1
return
fi
target=$((current_brightness * 100 / $change_percent))
[ $target -ne $current_brightness ] || target=$((target - 1))
;;
esac
# Boundaries
if [ $target -le 1 ]; then echo 0.1; return; fi
if [ $target -ge 100 ]; then echo 100; return; fi
echo $target
}
target=$(new_target "$1")
echo $target
# Smoothly set the new brightness
xbacklight -time 100 -fps 60 -set $target