23

xrandr can be used to change the display brightness using the command line. For example,

xrandr --output VGA-1 --brightness 0.4

Wayland does not support xrandr. Is there any similar tool in Wayland that can be used to control brightness and color temperature?

Note: This is NOT a duplicate of this question because that is about changing resolution, I want to control brightness on a desktop computer that does not support sys/class/backlight, so that frontends like Brightness Controller or Redshift can be made to work with Wayland.

9
  • Have you tried using kernel FS tree at /sys/class/backlight or using Gnome DBus interface dbus-send --type=method_call --dest=org.gnome.SettingsDaemon /org/gnome/SettingsDaemon/Power org.freedesktop.DBus.Properties.Set string:'org.gnome.SettingsDaemon.Power.Screen' string:'Brightness' variant:int32:30 source seems old you may find updated ones here in AskUbuntu.
    – user.dz
    Oct 24, 2020 at 9:55
  • /sys/class/backlight won't work on desktop. I am not sure what GNOME DBus interface does. It probably won't work outside GNOME. xrandr works on every major DE Oct 24, 2020 at 10:44
  • Are you sure about /sys/class/backlight as here askubuntu.com/a/785335/26246 because that the basic low level control if it is not there then probably have driver issue. doc: git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/… . For DBus, Yeah it is only for Gnome & Unity.
    – user.dz
    Oct 24, 2020 at 10:58
  • 1
    Check the edited question. I want to control brightness so that GUI frontends for controlling brightness (which come handy in desktops and systems with driver issues) can be made to work with Wayland Oct 24, 2020 at 11:08
  • 1
    @NicolasCordova did not find anything yet Jun 22, 2022 at 0:08

7 Answers 7

2

gammastep isn't the same as using xrandr -- it's more of a replacement for redshift. You can just manually set the brightness, but it's intended to be left running so as soon as you exit, your displays will reset to the default brightness. For example, you can set displays to 50% brightness:

gammastep -l 0:0 -o -b 0.5:0.5

The -l 0:0 sets lat/lon to 0, and -o tells it to perform just a one-shot operation (so you don't need correct lat/lon), and -b specifies the night:day brightness which are both the same here because we're just telling it to do a one-shot setting. You may decide that you want to take advantage of the continuous adjustment for day/night, in which case leave off the -o and give it your proper lat/lon.

brightnessctl is closer to the thing you're asking for, but when I ran it I couldn't set the brightness on my external displays -- only the builtin laptop screen:

brightnessctl -l # list displays
brightnessctl -l -c backlight # list displays of class 'backlight'
sudo brightnessctl -d intel_backlight s 25% # set display to 25%

light is similar to brightnessctl, including the fact that it doesn't detect (and thus can't control) my external displays.

All three of these packages are available in 22.04 jammy.

1

As this is wayland (it's just a protocol), this will depend on your compositor (e.g. Kwin for KDE, Mutter for GNOME), but it does not seem like there is anything equivalent as of right now (February 2023).

I dug into the code to learn how xrandr actually does this, and the relevant code is right here: https://gitlab.freedesktop.org/xorg/app/xrandr/-/blob/6f714830da6c8d74f024be6b0bb32c1ea39c1217/xrandr.c#L1469-1494

Here's the relevant snippet:

    if (output->gamma.red == 0.0)
        output->gamma.red = 1.0;
    if (output->gamma.green == 0.0)
        output->gamma.green = 1.0;
    if (output->gamma.blue == 0.0)
        output->gamma.blue = 1.0;

    gammaRed = 1.0 / output->gamma.red;
    gammaGreen = 1.0 / output->gamma.green;
    gammaBlue = 1.0 / output->gamma.blue;

    for (i = 0; i < size; i++) {
        if (gammaRed == 1.0 && output->brightness == 1.0)
        crtc_gamma->red[i] = (double)i / (double)(size - 1) * 65535.0;
        else
        crtc_gamma->red[i] = dmin(pow((double)i/(double)(size - 1),
                          gammaRed) * output->brightness,
                      1.0) * 65535.0;

        if (gammaGreen == 1.0 && output->brightness == 1.0)
        crtc_gamma->green[i] = (double)i / (double)(size - 1) * 65535.0;
        else
        crtc_gamma->green[i] = dmin(pow((double)i/(double)(size - 1),
                        gammaGreen) * output->brightness,
                        1.0) * 65535.0;

        if (gammaBlue == 1.0 && output->brightness == 1.0)
        crtc_gamma->blue[i] = (double)i / (double)(size - 1) * 65535.0;
        else
        crtc_gamma->blue[i] = dmin(pow((double)i/(double)(size - 1),
                           gammaBlue) * output->brightness,
                       1.0) * 65535.0;
    }

    XRRSetCrtcGamma(dpy, crtc->crtc.xid, crtc_gamma);

What xrandr does to reduce the brightness is actually change the gamma function to ramp up slower up to a max value, by applying a gamma curve to the RGB channels, and applying it using XRRSetCrtcGamma -- short for XRANDR Set CRTC Gamma, where XRANDR is X.org Resize and Rotate, and CRTC is a CRT (cathode ray tube) controller, which despite the old name, is just a term for the video controller in general.

As this behaviour is specific to xrandr, compositors themselves (e.g Kwin or Sway) will have to implement it, but before even that, I believe wayland needs to implement the protocol.

So it will require

  1. The wayland protocol to be agreed upon and merged (there's a PR here that I can see: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/14)
  2. Your compositor (kwin, mutter, sway, weston, etc) to implement this protocol
  3. Your compositor to expose the gamma changing settings in an API
  4. Someone to write a tool, like xrandr, that adjusts the brightness using a gamma curve, using this new API. This could also, in theory, be done by your compositor, which can expose a CLI or a graphical interface to adjust this.

xrandr itself has been replaced by compositor-specific tools like kscreen-doctor and the GUI system settings for your desktop environment, so it will be up to your desktop environment to provide tools to do exactly what xrandr --brightness has done in the past.

EDIT: further looking into the kwin code, it appears that if your compositor supports night color (aka redshift) of some sort, it should in theory be possible to support this.

Kwin actually has support for brightness in the code, but it doesn't appear to be exposed by any of the built-in plugins, but it seems like it's possible to write a plugin that changes the brightness.

1

ddcutil, it worked for me with wayland

Just change the value of the brightness and the display ID in the example bellow:

sudo ddcutil setvcp 10 50 --display 1
0

Yes, Wayland has an equivalent to xrandr. The package is called wlr-randr and is in the universe repository of Ubuntu 21.04 and later.

You can find the project's webpage here: https://sr.ht/~emersion/wlr-randr/

2
  • 1
    wlr-randr is for wlroots-based compositors only.
    – Tooniis
    Mar 3, 2022 at 11:06
  • 1
    From what I see, it's not possible to change the brightness of the screen with this.
    – iGEL
    Jul 18, 2022 at 12:56
0

After having this issue for a long time, the best solution I found is this project gnome-randr-rust.

It only has the adjust brightness functionality, but you need to use an experimental branch and install it locally for it to work.

For more information on the experimental branch see this issue.

0

A realistic and honest answer is that currently in the middle of 2023 there is no official project or software that can guarantee that you can change the brightness of your monitor using wayland since wayland is based on xbacklight and xrand is based on contrast opacity, so which xorg does not depend on the type of monitor but wayland does.

Perhaps the developers believed that no one would need it and that is why there is no official library or tool to do this, for this reason in any distribution that uses wayland by default it is possible to change the brightness of some monitors like ubuntu or fedora.

You have to wait maybe another four or five years before we can change the brightness of the monitor, meanwhile you can use some xorg based distribution or system like debian, arch or osx.

0

On Ubuntu 22.04.4 LTS works fine using ddcutil on default wayland session:

Install app:

sudo apt -y install ddcutil;

Change the brightness:

sudo ddcutil setvcp 10 50 --display 1;

Where 50 is the % pof the value for brightness and --display 1 is the number of display.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .