summaryrefslogtreecommitdiff
path: root/keyboard/bl
blob: 34ea0b0c57cce799bc9bf5a78b01c6061ab82d1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh
# 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
bl_min=0
bl_max=100

# DDC/CI stuff
ddcutil="ddcutil --sleep-less --noverify --enable-capabilities-cache --sleep-multiplier $sleep_multiplier" # Make sure user is in group i2c

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_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; }

case $1 in
	set) forall ddc_set $2 ;;
	get) forall ddc_get && echo '%' ;;
	inc) forall ddc_inc $2 ;;
	dec) forall ddc_dec $2 ;;
esac