diff options
Diffstat (limited to 'keyboard/bl')
-rwxr-xr-x | keyboard/bl | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/keyboard/bl b/keyboard/bl index 75a0b4b..84694e9 100755 --- a/keyboard/bl +++ b/keyboard/bl @@ -1,4 +1,5 @@ #!/bin/sh +# Depends on ddcutil, light # Config sleep_multiplier=.1 # Set this as low as you can get away with bl_vcp=0x10 # 0x10 is the standard VCP for controlling the backlight @@ -12,12 +13,10 @@ ddcutil="ddcutil --sleep-less --noverify --sleep-multiplier $sleep_multiplier" # max() { [ $1 -gt $2 ] && echo $1 || echo $2; } min() { [ $1 -lt $2 ] && echo $1 || echo $2; } ddc_set() { $ddcutil --display $2 setvcp $bl_vcp $1; } -ddc_get() { $ddcutil --display $2 getvcp $bl_vcp | grep -o "current value =\s*[0-9]*" | tr -cd '[0-9]'; } +ddc_get() { $ddcutil --display $1 getvcp $bl_vcp | grep -o "current value =\s*[0-9]*" | tr -cd '[0-9]'; } ddc_inc() { ddc_set $(min $(( `ddc_get` + $1 )) $bl_max) $2; } ddc_dec() { ddc_set $(max $(( `ddc_get` - $1 )) $bl_min) $2; } -forall() { for d in $(seq `xrandr | grep ' connected' | wc -l`); do ($1 $2 $d); done; } - i2c_group() { sudo=${SUDO:-sudo} ! $sudo -n true && echo "Please try again with root permissions!" && exit @@ -27,10 +26,22 @@ i2c_group() { echo "i2c group successfully added! Now add your user to it" } -case $1 in - set) forall ddc_set $2 ;; - get) forall ddc_get && echo '%' ;; - inc) forall ddc_inc $2 ;; - dec) forall ddc_dec $2 ;; - i2c-groupadd) i2c_group ;; -esac +if xrandr | grep 'eDP connected' > /dev/null; then + case $1 in + set) light -S $2 ;; + inc|+) light -A $2 ;; + dec|-) light -U $2 ;; + get|*) printf "eDP: " && light | tr -d '\n' && echo '%' ;; + esac +fi + +dn=1 +for d in $(xrandr | grep ' connected' | grep -v '^eDP' | cut -d' ' -f1); do + case $1 in + set) ddc_set $2 $dn ;; + inc|+) ddc_inc $2 $dn ;; + dec|-) ddc_dec $2 $dn ;; + get|*) printf "$d: " && ddc_get $dn && echo '%' ;; + esac + dn=$(( $dn + 1 )) +done |