Sunsetting XRandR Brightness

For a change, let’s talk about a topic other than notifications. More than five years ago (can’t believe how time has passed) I took over maintainership of PowerDevil, Plasma’s power management service. While I did a lot of cleanup and feature work in the beginning, there haven’t been many major changes for some time.

Bar-like popup informing of a screen brightness change
“Blast from the Past” – just casually sneaking in the more compact volume/brightness popup we’ll have in Plasma 5.20 to get your attention

One of the first features I added back then was smooth brightness changes. PowerDevil supports three ways of changing screen brightness: through XRandR configuration, through DDC (display data channel, for desktop monitors, experimental and not built by default), and by writing to sysfs (/sys/class/backlight or /sys/class/leds). Since the latter requires privileges and uses a helper binary through KDE’s KAuth framework, I only implemented the animation for the XRandR code path, which was executed in the same process.

Obviously, XRandR doesn’t work on Wayland, and it seems that modern graphics drivers don’t support changing brightness through it anymore either. I recently sat down and wrote a patch to have the helper binary execute a similar animation. KAuth works quite magically by exposing methods defined in an .actions file through DBus and then calling them as slots through Qt’s meta object. Unfortunately, the way it is designed doesn’t allow for delayed replies, which I wanted to use so the job only finished once the animation was completed in order to keep PowerDevil’s state consistent. I then found that KAuth randomly keeps its helper running for 10 seconds, more than enough for a 250ms animation.

I’m not too happy with the implementation and the brightness handling class itself has turned into quite a mess over the years, and having three (four, if you count keyboard brightness) completely separate brightness controls entangled within doesn’t help. To clean it up I want to get rid of XRandR brightness support. Since I don’t know if that’s actually still being used – I surely haven’t used it ever since I ditched the Intel driver – please do me a favor and check what brightness control your machine uses by running PowerDevil from command line (make sure to quit the running process first, and executable location will vary depending on your distribution):

QT_LOGGING_RULES='powerdevil=true' /usr/lib/x86_64-linux-gnu/libexec/org_kde_powerdevil

When using XRandR it will say “powerdevil: Using XRandR”, otherwise it’ll be “Xrandr not supported, trying ddc, helper”. (It’ll always say it tries the DDC helper even when it isn’t built with that.) If it actually uses XRandR please tell me and what GPU and driver you are using. That would help a lot in judging the impact of removing this! If it is indeed using XRandR, please see if you can still manually write into /sys/class/backlight/[whatever devices there may be]/brightness to alter screen brightness. It prefers XRandR but that doesn’t mean that sysfs couldn’t be working, too. Please also tell me the value of max_brightness in there. Feel free to chime in on the plasma-devel mailing list thread I started on the subject to share your thoughts. Now you can see why having some telemetry via KUserFeedback would be tremendously useful for improving code quality and, er, “user experience”.

Fullscreen video player of a KDE Akademy 2019 talk “Taking KDE to the Skies: Making the Drone Ground Control Kirogi” with a “Battery running low” notification in the top right
Casually watching one of my favorite Akademy 2019 talks when my battery ran out

Lastly, of course there can’t be a post on this blog without mentioning notifications: in the upcoming Plasma 5.19 the “low battery” notification is marked as critical which will make it show on top of full screen windows. Previously, while watching a video, playing a game, or giving a presentation, you likely didn’t see an advance warning. Only once battery reached critical levels would you get told to pick up a charger, running, tumbling down some stairs, frantically searching for it, before the 60 second timeout for sleep or standby expired. (Seriously, the reason why throughout the years I prolonged the timeout from the original 30 seconds and eventually added a “cancel” button was to stop fellow Plasma hackers injure themselves on sprints when running to their bags to fetch a charger.)

14 thoughts on “Sunsetting XRandR Brightness”

  1. Hello,
    Running the command on my DELL Latitude E7470 with intel graphics (Arch Linux) :

    powerdevil: Using XRandR

    1. Oh… okay. Can you manually adjust brightness by writing into /sys/class/backlight/[whatever devices there are]/brightness? It prefers XRandR (for the animation) but that doesn’t mean that sysfs couldn’t work, too.

  2. Manjaro with intel+nvidia configured for prime render offload.

    powerdevil: Xrandr not supported, trying ddc, helper

    System: Host: leela Kernel: 5.6.12-1-MANJARO x86_64 bits: 64 Desktop: KDE Plasma 5.18.5 Distro: Manjaro Linux
    Graphics: Device-1: Intel HD Graphics 630 driver: i915 v: kernel
    Device-2: NVIDIA GP107M [GeForce GTX 1050 Mobile] driver: nvidia v: 440.82
    Display: x11 server: X.Org 1.20.8 driver: modesetting,nvidia unloaded: intel tty: N/A
    OpenGL: renderer: Mesa Intel HD Graphics 630 (KBL GT2) v: 4.6 Mesa 20.0.6

  3. On NixOS on a recent Lenovo with iGPU, it says nothing. With external display attached and configured as only screen, it also says nothing.

  4. powerdevil: Xrandr not supported, trying ddc, helper

    Ubuntu 18.04 + KDE on laptop with Intel cpu and no additional gpu

  5. Hi Kai Uwe,

    powerdevil: Using XRandR

    GPU: Vanilla Intel on board.

    00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 620 (rev 07)


    Slackware64-current here, Dell Inspiron 5570

    KDE Plasma Version: 5.18.5
    KDE Frameworks Version: 5.70.0
    Qt Version: 5.13.2
    Kernel Version: 5.4.42
    OS Type: 64-bit
    Processors: 8 × Intel® Core™ i7-8550U CPU @ 1.80GHz
    Memory: 15,5 GiB of RAM

  6. Sorry, my comment got posted before I had time to finish it (I couldnt’t even supply a proper URL for my website).

    Just wanted to say that I saw your article on KDE Planet and that brought me here.

  7. powerdevil: Using XRandR

    00:02.0 VGA compatible controller: Intel Corporation HD Graphics 5300 (rev 08)
    Subsystem: ASUSTeK Computer Inc. HD Graphics 5300
    Kernel driver in use: i915
    Kernel modules: i915

    Operating System: Arch Linux
    KDE Plasma Version: 5.18.5
    KDE Frameworks Version: 5.70.0
    Qt Version: 5.14.2
    Kernel Version: 5.6.14-arch1-1
    OS Type: 64-bit
    Processors: 4 × Intel® Processor 5Y10 CPU @ 0.80GHz
    Memory: 3,8 Gio

  8. Using XRandR but /sys/class/backlight works manually. So I guess it’s fine for me.

    Intel integrated graphics (HD Graphics 5500) using i915 on my Dell inspiron 15 7000, Arch linux 5.6.13, kde framework 5.70, Qt 5.14.2

    It’s always frustrating when an upgrade breaks your ability to fully use your hardware, as even nowadays it’s not always easy to setup correctly on linux. Found your blog on planet, and wanted to thank you for this advance notice and taking the time to evaluate the impact of the change you envision.

  9. Alas, folks on OLED laptops often have no means to adjust brightness without XRandr, best I can tell. There’s no DDC (onboard monitor). The common sysfs backlight adjustments are there, but they don’t do anything.

    I have a Samsung Galaxy Book. I’ve heard similar for a number of Dell OLED laptops. I think it’s a fairly common state across most OLED displays. There’s no backlight to adjust: if you want a darker screen, you need the OS to output darker pixels.

  10. powerdevil: Backend loaded, loading core
    powerdevil: Core loaded, initializing backend
    powerdevil: No outputs have backlight property
    powerdevil: Xrandr not supported, trying ddc, helper
    powerdevil: [DDCutilBrightness] compiled without DDC/CI support
    powerdevil: Falling back to helper to get brightness
    powerdevil: current screen brightness value: 42
    powerdevil: Kbd backlight brightness value: 8
    powerdevil: current keyboard backlight brightness value: 8
    powerdevil: Backend ready, KDE Power Management system initialized
    powerdevil: Battery with UDI “/org/freedesktop/UPower/devices/battery_BAT1” was detected
    powerdevil: Session path: “/org/freedesktop/login1/session/_33”
    powerdevil: ACTIVE SESSION PATH: “/org/freedesktop/login1/session/_33”
    powerdevil: Current session is now active
    powerdevil: fd passing available: true
    powerdevil: systemd powersave events handling inhibited, descriptor: 20
    powerdevil: systemd support initialized
    powerdevil: Got a valid offer for “DPMSControl”
    powerdevil: Core is ready, registering various services on the bus…
    powerdevil: Can’t contact ck
    powerdevil: Currently using activity “ee0eaaab-a7c3-4e6d-bb29-925f3daa89d8”
    powerdevil: () ()
    powerdevil: () ()
    powerdevil: Loading profile for plugged AC
    powerdevil: Activity is not forcing a profile
    powerdevil: Loading timeouts with 300000
    powerdevil: Handle button events action could not check for screen configuration
    powerdevil: Can’t contact ck

    Operating System: KDE neon 5.18
    KDE Plasma Version: 5.18.5
    KDE Frameworks Version: 5.70.0
    Qt Version: 5.14.2
    Kernel Version: 5.3.0-53-generic
    OS Type: 64-bit
    Processors: 4 × Intel® Core™ i5-2467M CPU @ 1.60GHz

    Mobo: SAMSUNG model: 90X3A v: FAB1 serial: N/A UEFI [Legacy]: Phoenix v: 07HL date: 09/26/2011
    Graphics: Card: Intel 2nd Generation Core Processor Family Integrated Graphics Controller
    Display Server: x11 (X.Org 1.20.5 ) drivers: modesetting (unloaded: fbdev,vesa)
    OpenGL: renderer: Mesa DRI Intel Sandybridge Mobile version: 3.3 Mesa 19.2.8

  11. I have a Dell XPS 15 7590 with an OLED 4K 15″ display (very new design). The only way to adjust brightness on these is:

    xrandr –output eDP-1 –brightness 0.75

    They have backlight support present, but it does not actually do anything when you change the values. Right now I am in trouble because there is no good equivalent to that setting on Wayland, and you really need Wayland to get better scaling for HiDPI and palm detection support on the touchpad.

Leave a Reply

Your email address will not be published. Required fields are marked *