I hate being made to feel like a fool, especially by a software bug. I wasted four hours over the past two days trying to get my new Lenovo Yoga's touchscreen to work. It was fine in desktop mode, but rotated (for tablet mode) or inverted (for media mode), and the touchscreen's geometry would freak out; the touchscreen pointer wouldn't track anymore, gestures stopped working, it was a pain.

I tried using the event driver (evdev) settings, both "Axes Swap" and "Axis Inversion". It didn't help. I got desperate, and tried to teach myself the Coordinate Transformation Matrix, but that link is one brutally nasty "If you can't do matrix math, I'm not stupid enough to help you" bit of writing. I am knowledgeable enough to do matrix math, but his explanation is as clear as landfill, and about as useful.

It turns out that none of my confusion was my fault. There's a bug xf86-input-evdev-2.7, the version that ships with Ubuntu 12 (Quantal). It doesn't handle rotation or inversion well on the ELAN Touchscreens that ship with the Yoga. It's somewhat understandable-- the Yoga is a very new piece of hardware-- but damn, it's annoying.

I downloaded, compiled and installed xf86-input-evdev-2.8, and now it works. I have only keyboard-issued orientation working, but it's a start. The keyboard program is simple:

#!/bin/bash
ARG=$1
CMD=${ARG:0:1}
case $CMD in
    r) 
        xrandr --screen 0 -o right
        xinput set-prop --type=int --format=8 "ELAN Touchscreen" "Evdev Axes Swap" 1
        xinput set-prop --type=int --format=8 "ELAN Touchscreen" "Evdev Axis Inversion" 0 1
        ;;
    l)
        xrandr --screen 0 -o left
        xinput set-prop --type=int --format=8 "ELAN Touchscreen" "Evdev Axes Swap" 1
        xinput set-prop --type=int --format=8 "ELAN Touchscreen" "Evdev Axis Inversion" 1 0
        ;;
    i)
        xrandr --screen 0 -o inverted
        xinput set-prop --type=int --format=8 "ELAN Touchscreen" "Evdev Axes Swap" 0
        xinput set-prop --type=int --format=8 "ELAN Touchscreen" "Evdev Axis Inversion" 1 1
        ;;
    *)
        xrandr --screen 0 -o normal 
        xinput set-prop --type=int --format=8 "ELAN Touchscreen" "Evdev Axes Swap" 0
        xinput set-prop --type=int --format=8 "ELAN Touchscreen" "Evdev Axis Inversion" 0 0
        ;;
esac

And now, yoga r rotates the screen to portrait mode "right", yoga l is portrait mode "left", yoga i for "inverted" (upside down, "media mode"), and anything else, even just plain yoga, will put everything back to laptop mode, keyboard and all.