Created
July 28, 2018 09:15
-
-
Save Susensio/bf01c69e064b912c17416b0e3dc104a7 to your computer and use it in GitHub Desktop.
Syncs laptop backligh to LG HDMI monitor
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/env bash | |
# Listen for changes in backlight and applies to external screen | |
MAX_BACKLIGHT=$(</sys/class/backlight/intel_backlight/max_brightness) | |
last_backlight=$(</sys/class/backlight/intel_backlight/brightness) | |
acpi_listen | while IFS='/' read -ra line; do | |
if [ "$line" = "video" ]; then | |
# Read laptop backlight | |
sleep 0.2 | |
backlight=$(</sys/class/backlight/intel_backlight/brightness) | |
if [ $last_backlight != $backlight ]; then | |
# Only when values are different to not overload ddcutil (works on i2c and is slow) | |
brightness=$(( 120 * backlight / MAX_BACKLIGHT )) | |
brightness=$(( brightness > 100 ? 100 : brightness )) | |
contrast=$(( 150 * backlight / MAX_BACKLIGHT )) | |
contrast=$(( contrast > 60 ? 60 : contrast )) | |
echo -e "B:$brightness\tC:$contrast" | |
ddcutil setvcp 10 $brightness | |
ddcutil setvcp 12 $contrast | |
last_backlight=$backlight | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment