Bug 264534 - Screen brightness does not change because powerdevil truncates the new value, which equals to the old value.
Summary: Screen brightness does not change because powerdevil truncates the new value,...
Status: RESOLVED FIXED
Alias: None
Product: solid
Classification: Frameworks and Libraries
Component: powermanagement (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: Dario Freddi
URL:
Keywords:
: 266005 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-01-27 21:45 UTC by Lamarque V. Souza
Modified: 2011-02-20 19:16 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Fixes the truncate problem in brightness value (1.00 KB, patch)
2011-01-27 21:45 UTC, Lamarque V. Souza
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lamarque V. Souza 2011-01-27 21:45:07 UTC
Created attachment 56535 [details]
Fixes the truncate problem in brightness value

Version:           unspecified (using KDE 4.6.0) 
OS:                Linux

After upgrading from 4.5.4 to 4.6.0 I noticed that when pressing the "increase brightness" key (Fn+F9 in my notebook) it does not increase the brigthness sometimes (only sometimes). My LCD has only 7 brightness levels, powerdevil calcules the brightness in percent. Powerdevil converts from percent to the 7 levels in powerdevil/daemon/backends/upower/xrandrbrightness.cpp:XRandrBrightness::setBrightness. The value is truncated when converted from double to long, which sometimes makes it equals the old value and consequently the brightness is not increased.

Reproducible: Always

Steps to Reproduce:
1. You need a LCD monitor with few brightness levels (7 in my case).
2. Set brigthness to the minimum using powerdevil applet's brightness slide.
3. Try increasing the brightness using shortcut key. It does not increase.
4. Set brigthness to ~60% using powerdevil applets's brightness slide.
5. Try increasing the brightness using shortcut key. It works in this case.

Actual Results:  
The increase brightness key only increases brightness when it is already above ~50%.

Expected Results:  
The increase brigthness key should always increase brigthness until it reaches the maximum.

The attached patch fixed the problem for me.

By the way, my notebook is a Sager NP7652.
Comment 1 Christoph Feck 2011-01-27 23:00:45 UTC
... or simply using qRound ?
Comment 2 Lamarque V. Souza 2011-01-27 23:35:02 UTC
Yeah, that also works. Adding 0.5 before the cast also works. There are several ways to do the same thing :-)
Comment 3 Lamarque V. Souza 2011-01-27 23:54:12 UTC
SVN commit 1217574 by lvsouza:

Rounds value instead of truncating it. This fix a problem with increasing brightness key not working sometimes.
CCBUG: 264534


 M  +1 -1      xrandrbrightness.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1217574
Comment 4 Lamarque V. Souza 2011-01-28 00:06:57 UTC
SVN commit 1217581 by lvsouza:

Backport r1217574 by lvsouza from trunk to the 4.6 branch:

Rounds value instead of truncating it. This fix a problem with increasing
brightness key not working sometimes.
CCBUG: 264534


 M  +1 -1      xrandrbrightness.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1217581
Comment 5 Lamarque V. Souza 2011-01-28 00:11:52 UTC
Comment on attachment 56535 [details]
Fixes the truncate problem in brightness value

Fixed in a different way. The file in question is pure C, so I used simple math to round the value instead of qRound.
Comment 6 Jonathan Challinger 2011-02-10 20:19:29 UTC
*** Bug 266005 has been marked as a duplicate of this bug. ***
Comment 7 Robin Bankhead 2011-02-19 13:35:18 UTC
Hi, I was directed here from bug 181444 and would like to ask whether my case might be caused by this bug.  I cannot increase brightness at all from the keyboard shortcut (and I have tried a variety of shortcuts), but dimming works perfectly from any initial value.  Also the slider and brightness changes caused by idle/idle-stop work as expected.

Could this be the same underlying cause? Hardware is a Samsung NC10 netbook with Intel 945GME graphics, kde 4.6.0 (no HAL) on Gentoo unstable.
Comment 8 Robin Bankhead 2011-02-19 14:19:30 UTC
Just to add that my screen has 8 different brightness levels (including 0 and 100%), each being a 14.3% increment. I established this using xbacklight, which also tells me (I think) that it's the "floor" of the percentage you feed it (i.e. the setting you get is always rounded down from the percentage you want). I don't know if this is driver-specific behaviour or what, but seems like it might be related.

For example, if I do

xbacklight + 14

nothing happens, but I can do

xbacklight - 1

and the brightness will drop to the next lower setting.
Comment 9 Lamarque V. Souza 2011-02-19 15:41:38 UTC
The symptoms you described match this bug's symptoms. Try 4.6.1 and it should work. The brightness slide increments brightness "continuously" with 1% value steps, in that case truncating and rouding results in the same value. On the other hand the brightness keys increment by big steps (~14% in your case), which makes it more likely to the truncated value differ from the rounded value.
Comment 10 Robin Bankhead 2011-02-20 14:00:11 UTC
Thanks, I'll have to wait until Gentoo release 4.6.1 but will post back if it doesn't work.

As you don't mention it above, is it the case that *decreasing* brightness by keys worked fine for you too (before the patch)?
Comment 11 Lamarque V. Souza 2011-02-20 15:45:52 UTC
The decrease brightness key works without this patch because truncating a float point number is the same thing as rounding it down.
Comment 12 Robin Bankhead 2011-02-20 19:16:43 UTC
I applied the fix to the sources for 4.6.0 and it does indeed work. Thanks again!