diff options
author | Raul Benencia <rul@kalgan.cc> | 2020-05-24 13:44:14 -0700 |
---|---|---|
committer | Raul Benencia <rul@kalgan.cc> | 2020-05-24 13:47:59 -0700 |
commit | 546a3a211a0d59f14edbd97c1990476e84a46247 (patch) | |
tree | c5709cc4a8f7b0f39e1cb023f0f6b03bf749272e /bin/dim-screen.sh | |
parent | 3589f3e66769e87831e9f31fb3493064dd3ce73e (diff) |
Add bin/ repo from home-bin/ repo
Diffstat (limited to 'bin/dim-screen.sh')
-rwxr-xr-x | bin/dim-screen.sh | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/bin/dim-screen.sh b/bin/dim-screen.sh new file mode 100755 index 0000000..949ed85 --- /dev/null +++ b/bin/dim-screen.sh @@ -0,0 +1,51 @@ +#!/bin/bash +# Debian package: xbacklight + +# Brightness will be lowered to this value. +min_brightness=0 + +# If your video driver works with xbacklight, set -time and -steps for fading +# to $min_brightness here. Setting steps to 1 disables fading. +fade_time=2000 +fade_steps=200 + +# Time to sleep (in seconds) between increments when using sysfs. If unset or +# empty, fading is disabled. +fade_step_time=0.05 + + +get_brightness() { + if [[ -z $sysfs_path ]]; then + xbacklight -get + else + cat $sysfs_path + fi +} + +set_brightness() { + if [[ -z $sysfs_path ]]; then + xbacklight -steps 1 -set $1 + else + echo $1 > $sysfs_path + fi +} + +fade_brightness() { + if [[ -z $sysfs_path ]]; then + xbacklight -time $fade_time -steps $fade_steps -set $1 + elif [[ -z $fade_step_time ]]; then + set_brightness $1 + else + local level + for level in $(eval echo {$(get_brightness)..$1}); do + set_brightness $level + sleep $fade_step_time + done + fi +} + +trap 'exit 0' TERM INT +trap "set_brightness $(get_brightness); kill %%" EXIT +fade_brightness $min_brightness +sleep 2147483647 & +wait |