Improve backlight
This commit is contained in:
parent
9d1ed09dc6
commit
bc08bad7fa
1 changed files with 35 additions and 13 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue