On Mon, Jan 13, 2020 at 11:58:11AM +0100, Klemens Nanni wrote:
> On Sun, Oct 13, 2019 at 09:28:26PM -0500, joshua stein wrote:
> > When responding to hardware keys to increment or decrement screen 
> > brightness, don't just adjust by 1 BCL level as there may be 100 
> > levels.  Find the next brightness level that is at least 5% up or 
> > down, and use that.
>       revision 1.14
>       date: 2019/10/21 16:32:51;  author: jcs;  state: Exp;  lines: +20 -33;
>       When incrementing or decrementing screen brightness, don't just
>       adjust by 1 BCL level as there may be 100 levels.  Find the next
>       brightness level that is at least 5% up or down and use that.
> 
>       ok kettenis
> 
> This diff broke backlight adjustment on my X230:  With 100% screen
> brightness, pressing the function keys to *de*crease it won't do
> anything.  Booting a kernel with ACPIVIDEO_DEBUG suggests that
> acpivout_find_brightness() is unable to find the next level below 100%
> that is at least 5% less than the full brightness, hence it returns
> something above 95% such that acpivout_brightness_step() gets stuck and
> will set brightness to 100% again.
> 
> `xbacklight -50' will properly decrease brightness to 50%, then the
> function keys also work and I can decrease to 44% as the immediate lower
> level, however increasing it again never works and is stuck at 44%.
> 
> In general, setting a lower brightness level with xbacklight(1) makes
> the function keys work but only ever in the range of [0, n) -- I can
> never reach a higher level than set with xbacklight.
> 
> `xbacklight +100' works and reverting avpivout.c revision 1.14 makes
> everything work again for me.
> 
> tobhe has the exact same issues on his T420.
> 
> Below is diff to show my X230 brightness levels, dmesg as well.

The problem is that the last two values are 67 and 100.  If you go
5% down, it's 95.  The nearest will still be 100.  The code then
realizes that it's the same level as before, and does nlevel--.
But nlevel-- is 99, and not 67, because nlevel is the value and
not the index of the bcl array.  So in essence the change needed
is to decrease the index, not the value, and then look up the value.

Patrick

Reply via email to