/
set_brightness.sh
executable file
·51 lines (40 loc) · 1.09 KB
/
set_brightness.sh
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
48
49
50
51
#!/bin/bash
function brightness_target() {
res=eDP
r="([0-9]+)x([0-9]+)\+([0-9]+)\+([0-9]+)"
cursor_x=$(xdotool getmouselocation --shell | grep 'X=' | awk -F 'X=' '{print $2}')
cursor_y=$(xdotool getmouselocation --shell | grep 'Y=' | awk -F 'Y=' '{print $2}')
screen_infos=$(xrandr | grep -E "$r")
while read -r line; do
screen_name=$(echo "$line" | cut -d ' ' -f1)
if [[ $line =~ $r ]]; then
width="${BASH_REMATCH[1]}"
height="${BASH_REMATCH[2]}"
x_offset="${BASH_REMATCH[3]}"
y_offset="${BASH_REMATCH[4]}"
if [[ $cursor_x -ge $x_offset && $cursor_x -le $(($x_offset + $width)) && $cursor_y -ge $y_offset && $cursor_y -le $(($y_offset + $height)) ]]; then
res="$screen_name"
fi
fi
done <<< $screen_infos
echo $res
}
t=$(brightness_target)
if [[ 'eDP' == $t ]]; then
brightnessctl s $1
else
if [[ "$1" =~ ^\+ ]]; then
sign=+
value=${1:1:2}
else
sign=-
value=${1:0:2}
fi
# 4 HDMI
# 12 DP1
# 13 DP2
for i in 4 12 13; do
ddcutil setvcp 10 $sign $value --bus $i --sleep-multiplier .1 &
done
wait
fi