aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/script/dmenu-extbrightness
blob: a1865848b3b30f6aa361a72f04d629ed4116d8b2 (plain) (blame)
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
#!/bin/sh

if ! type ddcutil 1>/dev/null 2>&1; then
	notify-send "ddcutil is not installed" "Install it with your system package manager"
	exit 1
fi

# On Intel GPUs sometimes it won't recognise all monitors
available_monitors="$(ddcutil detect | grep Display | awk '{ print $2 }')"

selected_monitors="$(printf "All\n%s" "$available_monitors" | dmenu -i -p "Monitor")"
if [ "$selected_monitors" = "All" ]; then
	selected_monitors="$available_monitors"
elif [ "$selected_monitors" = "" ]; then
	exit
fi

brightness="$(dmenu -i -p "Brightness" </dev/null)"
[ -z "$brightness" ] && exit 1

for monitor in $selected_monitors; do
	ddcutil setvcp 10 "$brightness" --display "$monitor" &

	# Improves reliability on Intel GPUs as sometimes monitors don't get recognised and above command fails
	# sh -c "sleep 3 && ddcutil setvcp 10 $brightness --display $monitor &" &

	# Improves reliability on Intel iGPUs and prevents AMD GPUs from crashing
	sleep 1
done