Implement backlight brightness curve
This MR is based on a previous MR by Diego Escalante Urrelo.
gsd-power controls how the desktop changes brightness on key events, or when adjusting gnome-shell or gnome-control-center brightness sliders.
Its API takes a value from 0-100, currently representing a 1:1 relation to the backlight's brightness level. This range is divided by default into 20 steps, meaning that you have 20 equally spaced brightness levels to choose from.
However, this presents a usability problem, as humans do not perceive brightness linearly. Steps in the lower range appear far too large, while those the upper range they appear exceedingly small.
This commit fixes that issue by mapping the 0-100 brightness levels of gnome to a brightness curve. The brightness curve is created using a Bezier curve function whose parameters can be tuned (though they are hardcoded) to achieve the best results across a wide range of devices. Additionally, the commit reworks existing tests for brightness controls to be compatible with the brightness curve, and adds a new test in order to cover the old functionality which is used with non-linear backlights.
Curve Comparison:
The default linear scaling is in orange and labeled Column C, while the new scaling is in blue and labeled Column B.
The brightness curve is applied based on the linearity of the backlight, which is determined using the "scale" sysfs attribute of the backlight. User override is possible by creating a custom property named "GSD_BACKLIGHT_SCALE" for the backlight. The curve is applied under the following conditions, where "GSD_BACKLIGHT_SCALE" is given priority to allow user configuration:
+----------------------+--------------------------+
| backlight scale type | brightness curve applied |
+----------------------+--------------------------+
| linear | yes |
| non-linear | no |
| unknown | yes |
+----------------------+--------------------------+
Since scale
is unknown
for most backlights when it should be linear
, the brightness curve is applied when the scale
is unknown
. Note that it is not applied if the number of steps for the backlight is less than 99, which is the condition already used to exclude backlights with ACPI interfaces.
Closes #719