OLED 'backlight' problem

I have a Dell xps 15 7590 with the OLED screen. I have been following some of the advice on the Archwiki (here) to improve my experience with it. By and large this has worked fantastically but I've encountered a small problem when following this advice:


Summary

Backlight

If using a desktop environment with an OLED screen, you may notice the backlight does not function. Since on some models the screen is OLED (which do not have physical backlights), you may need to shim the ACPI backlight functions to update Xrandr's "--backlight" option. This is done by monitoring the acpi_video0 levels, and updating the xrandr brightness levels accordingly.

For this to work, you must first install inotify-tools and bc. Then, create the following file:

$ nano /usr/local/bin/xbacklightmon

#!/bin/sh 
#use LC_NUMERIC if you are using an European LC, else printf will not work because it expects an comma instead of a decimal point 
LC_NUMERIC="en_US.UTF-8" 

#Exit with 1 if $DISPLAY env isn't set. Helps when using the start up script below 
[ -z "$DISPLAY" ] && exit 1; 

# modify this path to the location of your backlight class 
path=/sys/class/backlight/intel_backlight 

read -r max < "$path"/max_brightness 

luminance() {
read -r level < "$path"/actual_brightness 
factor=$((max)) 
new_brightness="$(bc -l <<< "scale = 2; $level / $factor")" 
printf '%f\n' $new_brightness 
} 

# support both intel and nvidia 
DEVICE=eDP-1 
if [ ! -z "$(xrandr -q --output $DEVICE 2>&1)" ]; then 
DEVICE=eDP-1-1 
fi 

xrandr --output $DEVICE --brightness "$(luminance)" 

inotifywait -me modify --format '' "$path"/actual_brightness | while read; do 
xrandr --output $DEVICE --brightness "$(luminance)" 
done

Then make this file executable and owned by root:

$ chown root:root /usr/local/bin/xbacklightmon 
$ chmod 755 /usr/local/bin/xbacklightmon

You may test this by running the file, and using the backlight keys to test if the brightness updates.

To run the script automatically on startup, create a xbacklightmon.service file containing the following:

$ mkdir -p $HOME/.config/systemd/user/ 
$ nano $HOME/.config/systemd/user/xbacklightmon.service
[Unit] 
Description=Ugly fix to be able to control the brightness of OLED screens via keyboard brightness
After=multi-user.target 

[Service] 
Type=simple 
ExecStart=/usr/local/bin/xbacklightmon 
Restart=on-failure 
RestartSec=1 
 
[Install] 
WantedBy=default.target

And to enable on startup

systemctl --user enable xbacklightmon.service

While this solution has greatly improved the quality and control I have over screen brightness compared to my previous solution (icc-brightness-gnome-git) it tends to 'forget' my screen brightness after sleep and require readjusting. Also it disables the Night Light feature when used which I would like to keep. Is this to be expected? Is there any way around this? Are there better solutions to OLED screen brightness that I should be using?

You may try this
https://wiki.archlinux.org/index.php/Lenovo_ThinkPad_X1_Extreme_(Gen_2)#Brightness_control

There is a bug with it on my thinkpad and I need to patch the kernel.
It seems Phil added some patch from Ubuntu since 5.4.18 or 5.4.17 but it still don't work flawlessly in my thinkpad

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

Forum kindly sponsored by