Bug 399646 - Brightness control adjusts the wrong backlight control (multiple GPUs)
Summary: Brightness control adjusts the wrong backlight control (multiple GPUs)
Alias: None
Product: Powerdevil
Classification: Unclassified
Component: general (show other bugs)
Version: 5.14.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
Depends on:
Reported: 2018-10-11 08:12 UTC by Bastian Beischer
Modified: 2021-12-03 17:19 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.24


Note You need to log in before you can comment on or make changes to this bug.
Description Bastian Beischer 2018-10-11 08:12:16 UTC
When using my laptops (Lenovo W520) FN-keys to adjust the display brightness the OSD shows up and the sliders change, but the display brightness does not.

This laptop has two physical GPUs (Intel + NVIDIA), depending on the BIOS settings you can use either Intel, NVIDIA by themselves or both. I have a PRIME setup where I'm using both GPUs, the Intel GPU is the main one and the other one is normally asleep, unless I plug in an external monitor.

I have to providers for backlight in /sys/class:


Both have "type" = "raw".

Even when I don't have a secondary monitor connected (and the NVIDIA GPU isn't used at all) I can see that the nv_backlight/brightness value changes when using the brightness control, but that's the wrong one!

Now I have had a quick glance at the code of the brightness controls, which appears to either use a whitelist of backlight providers, or goes through all the providers and picks the first one (since they both have type raw).

Because there surely are users who have NVIDIA as a primary GPU and Intel as a secondary one, it is possible that a hardcoded list of preferences will never satisfy all parties. Maybe a setting in ~/.config could be used to specify the correct device?
Comment 1 Jason Tibbitts 2019-01-03 21:49:04 UTC
I can confirm with a Thinkpad W530.  My situation is exactly the same.  I'm running Fedora 29 which has powerdevil 5.14.4 currently.  I haven't previously tried to run Linux on one of these laptops so I have no idea if this worked at some point in the past.

Supposedly (from a quick chat with Matthew Garrett on IRC) the desktop environment needs to figure out which output port needs to be adjusted, follow that to the device (graphics card) and then look for the backlight in /sys/class/backlight which corresponds to the device.

I have to give this laptop to a user, but I think I have another on hand to test if there's a patch I can try.
Comment 2 Dan Robinson 2020-02-11 01:21:51 UTC
I'm also affected by this. I have a T530 with multiple GPUs.

Just for fun, I read the source of gnome-power-manager which is the only one that gets this right. They seem to be checking if *_backlight/device/enabled is actually reading "enabled" and using that one.

At one point, I found the equivalent code in Powerdevil and Solid and for some reason I can't find where that file is right now.

I'm almost certain that would fix it if someone that (a) knows where that file is and (b) knows enough Qt (I don't, unless I spend a lot of time studying up) wants to write a patch. Or if you can point me in the right direction I'm happy to take a stab at it but it might be a while.
Comment 3 Daniel Tang 2020-04-28 06:07:54 UTC
The relevant PowerDevil code is at https://cgit.kde.org/powerdevil.git/tree/daemon/backends/upower/backlighthelper.cpp?id=5602920aeb852b3703ba357394e43454820460f3#n80

The GNOME backlight code has been moved from gnome-power-manager to https://gitlab.gnome.org/GNOME/gnome-settings-daemon/-/blob/523ffa148ce16773c2d9f711edb2c0424411d7ac/plugins/power/gsd-backlight.c#L119

An alternative code solution would be to affect *all* of the backlights at once.
Comment 4 Rover Bugfinder 2021-04-09 11:37:20 UTC
Bug still present in KDE 5.78.0 / Powerdevil 5.20.5.
I have a laptop with just one video card, but with 2 "backends"/providers/drivers found by the system: /sys/class/backlight/dell_backlight and /sys/class/backlight/intel_backlight (yes, it's a Dell laptop with an Intel video card :) ).
As Bastian says, KDE picks whatever backend is returned first by scanning the /sys/class/backlight directory. For me, it always seems to be the wrong one :). I also found (although in some other place) the same piece of code that does this.
I partially agree that KDE should check which backend is enabled and use that one (as Dan says). Perhaps this will be enough. Unless there really are 2 graphic cards installed, both enabled, and the user would like to adjust the brightness on all screens at once. Or maybe just some of them (e.g. because it works on one, but breaks on the other).
That's why I agree more to a configurable setting - letting the user choose is, in my opinion, always best.
Should it be a single-select or multi-select setting, should it be in ~/.config and only there or also on the KDE's systemsettings GUI is another question.
I'd opt for a multi-select setting and a list of check-boxes in systemsettings with all the found backends (found by listing the directory, just like it's done now), letting the user select which ones to use and then make Powerdevil iterate through the selected ones when the brightness action is called (button press, power level change, whatever). If none selected, change none. Or just the default. Or maybe introduce another setting - "Use default". If selected (this would be the selected by default on fresh installations), use all the found and enabled backends. When deselected (meaning: on purpose), use just the ones the user selected (including "none"). Something like:

Choose the provider/backend/driver/graphic card for screen brightness:
(o) Use default (all enabled providers)
( ) Choose the provider:
    [ ] dell
    [x] intel

(2 radiobuttons, 2 check-boxes enabled only when the second radiobutton is selected).
My C++ knowledge is too poor to fix this myself, and my Qt knowledge is zero, not to mention making a decision which path to take, doing it and then compiling half of KDE to do testing :). So, I'm just "keeping this bug alive" to show that it's still relevant (and help make KDE better than Windows ;) where the keyboard buttons to change the brightness do actually work on the same laptop...).
Comment 5 Dan Robinson 2021-05-22 18:32:13 UTC
I'm not sure controlling all of them is the right answer either unless there's an option to disable that, on the off chance there's hardware where both works and it causes either 2 steps of change per press, or a conflict.

Having an option isn't a bad idea either, but that's way over my head on the coding stand point (although real life has taken over since reporting this so I haven't had time to look at a patch at all).
Comment 6 Bug Janitor Service 2021-11-21 19:53:08 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/powerdevil/-/merge_requests/69
Comment 7 Nate Graham 2021-12-03 17:19:48 UTC
Git commit e95924f499eb3f8ca916e617e4c9e70aefb8669c by Nate Graham, on behalf of Dan Robinson.
Committed on 03/12/2021 at 17:19.
Pushed by ngraham into branch 'master'.

Check if backlight device is enabled

Check the enabled property on each backlight device before using
it as a backlight device, so the correct device is used in multi
GPU setups
FIXED-IN: 5.24

M  +10   -0    daemon/backends/upower/backlighthelper.cpp