Lenovo ThinkPad X1 Yoga OLED Brightness

7,830

Solution 1

There is no backlight with an OLED screen. So the normal methods do not work. Adjust screen brightness by way of:

xrandr --output eDP1 --brightness .5  # dim to half 

xrandr --output eDP1 --brightness 1  # no dimming

the number can be anything between 0 and 1

Solution 2

I've been looking for a way to run the xrandr command when pressing the brightness buttons. I created custom acpi events for that (more info on that here: https://help.ubuntu.com/community/LaptopSpecialKeys ). This is still a hack and no proper solution, but it works for me:

I created three files, /etc/acpi/events/yoga-brightness-up:

event=video/brightnessup BRTUP 00000086
action=/etc/acpi/yoga-brightness.sh up

and /etc/acpi/events/yoga-brightness-down:

event=video/brightnessdown BRTDN 00000087
action=/etc/acpi/yoga-brightness.sh down

and finally /etc/acpi/yoga-brightness.sh:

#!/bin/sh

# Where the backlight brightness is stored
BR_DIR="/sys/devices/pci0000:00/0000:00:02.0/drm/card0/card0-eDP-1/intel_backlight/"


test -d "$BR_DIR" || exit 0

MIN=0
MAX=$(cat "$BR_DIR/max_brightness")
VAL=$(cat "$BR_DIR/brightness")

if [ "$1" = down ]; then
    VAL=$((VAL-71))
else
    VAL=$((VAL+71))
fi

if [ "$VAL" -lt $MIN ]; then
    VAL=$MIN
elif [ "$VAL" -gt $MAX ]; then
    VAL=$MAX
fi

PERCENT=`echo "$VAL / $MAX" | bc -l`

export XAUTHORITY=/home/ivo/.Xauthority  # CHANGE "ivo" TO YOUR USER
export DISPLAY=:0.0

echo "xrandr --output eDP-1 --brightness $PERCENT" > /tmp/yoga-brightness.log
xrandr --output eDP-1 --brightness $PERCENT

echo $VAL > "$BR_DIR/brightness"

which is heavily inspired by the file asus-keyboard-backlight.sh and the information on https://bugs.launchpad.net/ubuntu/+source/xserver-xorg-video-intel/+bug/660901 for the xrandr root-access problem.

Don't forget to restart acpi by typing

sudo service acpid reload

I hope, this helps ;-)

Solution 3

Smooth Brightness Control

(Update: I've uploaded the provision script to automate this to Github.)

This script is based on the workaround by Ivo Blöchliger. I'd hate for my expensive laptop to look cheap, so I need a smooth transition between brightness values to compete with my non-linux colleagues.

This is created for and tested on Linux Mint 18.3 and Ubuntu 16.04.3 on a Lenovo ThinkPad X1 Yoga (2nd Gen) with OLED panel.

/etc/acpi/events/oled-brightness-up (644):

event=video/brightnessup BRTUP 00000086
action=/etc/acpi/oled-brightness.sh up

/etc/acpi/events/oled-brightness-down (644):

event=video/brightnessdown BRTDN 00000087
action=/etc/acpi/oled-brightness.sh down

/etc/acpi/oled-brightness.sh (755):

#!/bin/bash
# Smooth brightness control
# Change "redsandro" in the line below to your username
export XAUTHORITY=/home/redsandro/.Xauthority
export DISPLAY=:0.0

OLED_BR=`xrandr --verbose | grep -i brightness | cut -f2 -d ' '`
CURR=`LC_ALL=C /usr/bin/printf "%.*f" 1 $OLED_BR`

MIN=0
MAX=1.2

if [ "$1" == "up" ]; then
    VAL=`echo "scale=1; $CURR+0.1" | bc`
else
    VAL=`echo "scale=1; $CURR-0.1" | bc`
fi

if (( `echo "$VAL < $MIN" | bc -l` )); then
    VAL=$MIN
elif (( `echo "$VAL > $MAX" | bc -l` )); then
    VAL=$MAX
else
    if [ "$1" == "up" ]; then
        for I in {1..10..1}; do xrandr --output eDP1 --brightness `echo "scale=2; $I/100+$CURR" | bc` 2>&1 >/dev/null | logger -t oled-brightness; done
    else
        for I in {1..10..1}; do xrandr --output eDP1 --brightness `echo "scale=2; $CURR-$I/100" | bc` 2>&1 >/dev/null | logger -t oled-brightness; done
    fi
fi

# Set Intel backlight to fake value
# to sync OSD brightness indicator to actual brightness
INTEL_PANEL="/sys/devices/pci0000:00/0000:00:02.0/drm/card0/card0-eDP-1/intel_backlight/"
if [ -d "$INTEL_PANEL" ]; then
    PERCENT=`echo "scale=4; $VAL/$MAX" | bc -l`
    INTEL_MAX=$(cat "$INTEL_PANEL/max_brightness")
    INTEL_BRIGHTNESS=`echo "scale=4; $PERCENT*$INTEL_MAX" | bc -l`
    INTEL_BRIGHTNESS=`LC_ALL=C /usr/bin/printf "%.*f" 0 $INTEL_BRIGHTNESS`
    echo $INTEL_BRIGHTNESS > "$INTEL_PANEL/brightness"
fi

Remove any previous brightness handlers, and finally, do sudo service acpid reload

Solution 4

UPDATE -- 12 July 2019 --

There's now a nice script for Wayland, and I can use my brightness keys.

https://github.com/udifuchs/icc-brightness and ./icc-brightness watch.

The script hack below also would ramp the screen to full brightness when switch landscape to portrait mode (or vice versa) and not respond to the touchscreen-GUI brightness control. So really happy with the Wayland solution.

Old

I needed a few tweaks to make @Redsandro solution work on my ubuntu 18.10 install.

Specifically, the Xauth root workaround doesn't work (thanks for mentioning that @Ivo B!) as the .Xauthority file no longer exists. To find the new file location:

$ xauth info
Authority file:       /run/user/1000/gdm/Xauthority

Therefore we change the relevant line:

-OLD: export XAUTHORITY=/home/redsandro/.Xauthority
+NEW: export XAUTHORITY=/run/user/1000/gdm/Xauthority

Additionally, I also had to change eDP1 to eDP-1.

In total this led to changes on three lines.


Additional notes

In order to debug, I used

rui@chaiX1YG2:/var/log$ $ tail -f /var/log/syslog | grep oled-br

e.g. for the two respective errors I found (Xauthority & eDP)

Jan 16 13:03:01 chaiX1YG2 oled-brightness: Can't open display :0.0
Jan 16 13:03:01 chaiX1YG2 oled-brightness: No protocol specified
Jan 16 13:23:46 chaiX1YG2 oled-brightness: warning: output eDP1 not found; ignoring
Jan 16 13:23:46 chaiX1YG2 oled-brightness: xrandr: Need crtc to set gamma on.

NOTE also, this solution does not work in wayland! As xrandr does not work on wayland. So make sure when you log in, you choose xorg, not wayland),

(A bit unfortunate as for me, firefox touch events only works in Wayland, so I have to choose between the brightness vs firefox touchscroll. Not sure why that is yet).

(This answer would have been a comment but I lack credits.)

Solution 5

I did a similar thing to the above in Ubuntu MATE 17.04:

  1. cat $MYDIR/scrbr.property = 0.5 (scrbr = screen-brightness)
  2. Created a script scrbr.sh:

```

#!/bin/bash

ACTION=$1

PROP_FILE=$MYDIR/scrbr.property
BRIGHT=$(cat $PROP_FILE)

if [[ "$ACTION" == "--up" ]]; then
        SYM="+"
elif [[ "$ACTION" == "--down" ]]; then
        SYM="-"
fi

BRIGHT=$(echo "$BRIGHT $SYM 0.1" | bc)

# Not less than 0
[[ $BRIGHT == -* ]] && BRIGHT=0

echo $BRIGHT > $PROP_FILE

xrandr --output eDP-1 --brightness $BRIGHT
  1. Remap keys WinKey + Up to scrbr.sh --up, and same for --down.

  2. Profit.

Share:
7,830

Related videos on Youtube

joar
Author by

joar

Updated on September 18, 2022

Comments

  • joar
    joar over 1 year

    I'm running 16.04 on my X1 Yoga OLED.

    I can't change the brightness of the screen at all, it seems to be on maximum brightness all the time. I've tried:

    • Fn+F5/F6
    • xbacklight -set 50(and 100, and 0, and 20, ...)/xbacklight -dec 10

    I'm using GNOME Shell in Xorg.

    Hopefully useful list of software and versions, tell me in the comments if you need more.

    gnome-shell 3.18.5-0ubuntu0.1
    tlp         0.9-1~xenial
    tp-smapi    0.41-1
    
  • joar
    joar over 7 years
    This is correct. I wonder if GNOME/driver maintainers have tackled the user interface issue of "I expect my screen to dim when I press the SUN_ICON MINUS_SIGN key." yet, and if and when it'll arrive in 16.04.
  • user240891
    user240891 about 7 years
    I have the same laptop and the same problem, tried this method but I get: xrandr --output eDP1 --brightness .5 warning: output eDP1 not found; ignoring xrandr: Need crtc to set gamma on.
  • user240891
    user240891 about 7 years
    I have the same laptop and the same problem, tried this method but I get: xrandr --output eDP1 --brightness .5 warning: output eDP1 not found; ignoring xrandr: Need crtc to set gamma on.
  • Dan Christensen
    Dan Christensen almost 7 years
    I got this to work, but had to specify "eDP1" instead of "eDP-1". Also, it's worth mentioning that you need to do "chmod a+rx /etc/acpi/yoga-brightness.sh". Thanks!
  • P.Meyer
    P.Meyer over 6 years
    I just installed a new Linux Distribution and had to look up my own answer, so I found your comment. If your device is called differently, then just enter xrandr by itself. It will, among other things, output the device-name. Mine is called now: eDP-1 for example.
  • user9221
    user9221 about 6 years
    I updated the script above to be a multi user capable and handle GDM xauthority location gist.github.com/jackinloadup/c98682416f0363b9a6c6d4daf13c6c3‌​2