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