Tomasz Kramkowski


A basic logarithmic scale sysfs brightness adjuster.

My new laptop's backlight wasn't automatically working through some hardware shenanigans (like with my previous X220 and X230), I investigated some of the available options for doing it in software but they seemed to all involve convoluted setups with key bindings eventually calling suid executables.

It appears that the solution was relatively straightforward in the end. My laptop sends ACPI events whenever the brightness buttons are pressed. These can be handled via acpid:

action=/etc/acpi/brightness "%e"


case "$1" in
video/brightnessup*)   /usr/local/bin/brightness "$backlight" "+$pct" ;;
video/brightnessdown*) /usr/local/bin/brightness "$backlight" "-$pct" ;;

The initial draft simply read the backlight brightness and increased/decreased it by a fixed amount but it quickly became apparent that this was adjusting the raw brightness value and not a log-compensated abstraction.

brightness was written to solve this very specific problem of providing a basic command line interface for making log-scale adjustments to a backlight. It automatically handles clamping the value (as writing an out-of-range value is otherwise ignored and not clamped by the kernel).

For maximum precision brightness could store the log-scale setpoint and only ever convert to the raw value (and never back). But this would require storing additional state, and in reality I don't think I could notice the difference.