blob: 4ddff29328b444f198898e6301b8a4b7a995f1a5 (
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#!/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
bl_min=0
bl_max=100
# DDC/CI stuff
ddcutil="ddcutil --enable-sleep-less --noverify --sleep-multiplier $sleep_multiplier" # Make sure user is in group i2c
#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 $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; }
i2c_group() {
sudo=${SUDO:-sudo}
! $sudo -n true && echo "Please try again with root permissions!" && exit
grep '^i2c' /etc/groups && echo "i2c group already exists!" && exit
$sudo groupadd --system i2c && \
$sudo cp /usr/share/ddcutil/data/45-ddcutil-i2c.rules /etc/udev/rules.d && \
echo "i2c group successfully added! Now add your user to it"
}
if xrandr | grep -E '(eDP|LVDS-[0-9]) 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 -vE '^(eDP|LVDS)' | 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
|