Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: scripts - ddcutil script to handle brightness control for extern… #1771

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions Configs/.local/share/bin/extbrightnesscontrol.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env sh

ScrDir=`dirname "$(realpath "$0")"`
source $ScrDir/globalcontrol.sh

monitorInfo=$( ddcutil detect )
monitors=($( echo "$monitorInfo" | grep "I2C bus:" | awk -F ': ' '{print $2}' ))
model=$( echo "$monitorInfo" | grep "Model:" | awk -F ': ' '{print $2}' | head -n 1 | xargs )

print_error() {
cat << "EOF"
./brightnesscontrol.sh <action>
...valid actions are...
i -- <i>ncrease brightness [+5%]
d -- <d>ecrease brightness [-5%]
s -- <s>et VALUE brightness [VALUE%]
g -- <g>et brightness
EOF
}

get_brightness() {
ddcutil getvcp 10 | awk -F 'current value = ' '{print $2}' | grep -o '[0-9]\+' | head -n 1
}

send_notification() {
brightness=$(get_brightness)
angle=$(((($brightness + 2) / 5) * 5))
ico="$HOME/.config/dunst/icons/vol/vol-${angle}.svg"

notify-send -a "t2" -r 91190 -t 800 -i "${ico}" "Brightness ${brightness}" "${model}"
}

set_brightness() {
for v in "${monitors[@]}" ; do
bus=$( echo $v | awk -F '-' '{print $2}' )

case $1 in
i)
ddcutil setvcp 10 + $2 --bus=$bus
;;
d)
ddcutil setvcp 10 - $2 --bus=$bus
;;
*)
ddcutil setvcp 10 $2 --bus=$bus
;;
esac
done
}

case $1 in
i)
currentBrightness=$(get_brightness)
if [[ "$currentBrightness" -lt 10 ]] ; then
# increase the brightness by 1% if less than 10%
set_brightness i 1
else
# increase the brightness by 5% otherwise
set_brightness i 5
fi
send_notification ;;
d)
currentBrightness=$(get_brightness)
if [[ "$currentBrightness" -le 2 ]] ; then
# avoid 0% brightness
set_brightness s 2
elif [[ "$currentBrightness" -le 10 ]] ; then
# decrease the brightness by 1% if less than 10%
set_brightness d 1
else
# decrease the brightness by 5% otherwise
set_brightness d 5
fi
send_notification ;;
s)
if [[ $2 -le 2 ]] ; then
# avoid 0% brightness
set_brightness s 2
else
set_brightness s $2
fi
send_notification ;;
g)
send_notification ;;
*)
print_error ;;
esac