Mapping ACPI events for brightness buttons on Lenovo Yoga X1 v2

Viewed 366

I installed Ubuntu Gnome 17.04 on my new Lenovo Yoga X1 (version 2) and the brightness buttons don't work out of the box. I've gone through the steps (below) I thought necessary to map these keys to xrandr calls, but nothing happens, even if I log the key mapping event being caught successfully. If I manually run the logged command brightness changes appropriately. What am I missing in the ACPI route?

First see what ACPI events the brightness buttons are sending

$ acpi_listen
video/brightnessdown BRTDN 00000087 00000000
video/brightnessup BRTUP 00000086 00000000

Then create the event definitions

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

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

Define the action script

$ cat /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
export XAUTHORITY=/home/jorvis/.Xauthority
export DISPLAY=:0

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

echo $VAL > "$BR_DIR/brightness"

Restart acpid

$ sudo /etc/init.d/acpid reload

Success should write to the brightness log

$ rm /tmp/yoga-brightness.log

[ hit brightness down button three times ]

$ sudo cat /tmp/yoga-brightness.log 
xrandr --output eDP-1 --brightness .76603773584905660377

Log is written correctly, as is the brightness value:

$ cat /sys/devices/pci0000:00/0000:00:02.0/drm/card0/card0-eDP-1/intel_backlight/brightness
759

Nothing happens on the actual display though. It DOES work though if I manually run the command which was logged to have run.

$ xrandr --output eDP-1 --brightness .76603773584905660377
1 Answers
Related