Last active
September 11, 2020 18:27
-
-
Save InternetUnexplorer/61b7b010317c3485bc84d0dac6eb43bd to your computer and use it in GitHub Desktop.
A really simple daemon for adjusting monitor brightness using DDC/CI. Requires `ddcutil` to be installed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Simple Brightness Daemon | |
[Service] | |
ExecStart=/usr/bin/brightness-daemon.sh | |
Restart=on-failure | |
RestartSec=5 | |
[Install] | |
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
FIFO_NAME="/tmp/brightness-daemon-fifo" | |
DDCUTIL_FLAGS="--async --nousb" | |
NUM_DISPLAYS=2 | |
BRIGHTNESS_MIN=20 | |
BRIGHTNESS_MAX=100 | |
################################ | |
set -eEo pipefail | |
get_brightness() { | |
/usr/bin/ddcutil $DDCUTIL_FLAGS --brief getvcp 10 \ | |
| /usr/bin/sed -r 's/VCP 10 C ([0-9]*) 100/\1/g' | |
} | |
CURRENT_BRIGHTNESS=$(get_brightness) | |
echo Current brightness is $CURRENT_BRIGHTNESS%. | |
if [[ ! -p $FIFO_NAME ]]; then | |
/usr/bin/mkfifo $FIFO_NAME --mode 666 | |
fi | |
while true; do | |
read BRIGHTNESS_OFFSET < $FIFO_NAME | |
CURRENT_BRIGHTNESS=$((CURRENT_BRIGHTNESS + BRIGHTNESS_OFFSET)) | |
if ((CURRENT_BRIGHTNESS < BRIGHTNESS_MIN)); then | |
CURRENT_BRIGHTNESS=$BRIGHTNESS_MIN | |
fi | |
if ((CURRENT_BRIGHTNESS > BRIGHTNESS_MAX)); then | |
CURRENT_BRIGHTNESS=$BRIGHTNESS_MAX | |
fi | |
echo Setting brightness to $CURRENT_BRIGHTNESS%... | |
for i in $(seq 1 $NUM_DISPLAYS); do | |
/usr/bin/ddcutil ${DDCUTIL_FLAGS} --display $i setvcp 10 $CURRENT_BRIGHTNESS | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment