diff --git a/bin/laptop-screen-brightness b/bin/laptop-screen-brightness new file mode 100755 index 0000000..7709f63 --- /dev/null +++ b/bin/laptop-screen-brightness @@ -0,0 +1,40 @@ +#!/bin/bash + +# Keys: XF86MonBrightnessUp, XF86MonBrightnessDown + +class=intel_backlight +dir=/sys/class/backlight/$class +cur=$(cat $dir/brightness) +max=$(cat $dir/max_brightness) + +step=$(("$2" + 0)) +cur_pct=$((100 * $cur / $max)) + +case "$1" in + "up") + echo "up $2%" + target_pct=$(($cur_pct + $2)) + ;; + "down") + echo "down $2%" + target_pct=$(($cur_pct - $2)) + ;; + *) + echo "Backlight at $cur/$max ($cur_pct%)" + exit 0 +esac + +if [ "$target_pct" -lt "0" ]; then + target_pct=0 +fi +if [ "$target_pct" -gt "100" ]; then + target_pct=100 +fi + +target_val=$(($max * $target_pct / 100)) + +echo "Backlight at $cur/$max ($cur_pct%)" +echo "Target $target_val ($target_pct%)" +echo "Dest $dir/brightness" +echo $target_val > $dir/brightness +