Lenovo ThinkPad X1 Yoga OLED Brightness
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
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 ;-)
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