blob: 6e6961496df1cc1a4096271f861f4fd18af43103 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#!/bin/sh
xrandr_verbose=$(xrandr --verbose)
monitors=$(echo "$xrandr_verbose" | grep -i '\sconnected' | grep '[0-9]x[0-9]' | cut -d ' ' -f1)
for monitor in $monitors; do
case "$monitor" in
*DP* | *DisplayPort* | *HDMI*)
current_brightness=$(echo "$xrandr_verbose" | grep -i "^$monitor connected" -A5 | grep -i "Brightness:" | cut -d ' ' -f2)
[ -z "$current_brightness" ] && continue
if [ "$#" -eq 2 ]; then
scale_change=$(echo "$2 / 100" | bc -l)
case "$1" in
"-inc") new_brightness=$(echo "$current_brightness + $scale_change" | bc -l) ;;
"-dec") new_brightness=$(echo "$current_brightness - $scale_change" | bc -l) ;;
*) echo "Invalid argument $1. Use -inc or -dec." && exit 1 ;;
esac
new_brightness=$(echo "if ($new_brightness > 1) 1 else if ($new_brightness < 0) 0 else $new_brightness" | bc -l)
xrandr --output "$monitor" --brightness "$new_brightness"
fi
;;
esac
done
|