Saturday, January 30, 2016

Coordinate Transformation Matrix for Touchscreen in multi-screen setup in X11

Currently I have a twin screen setup in Arch Linux, like this:

On the left, DELL 1901FP is turned 90 degree counter-clockwise in its portrait mode. On the right, DELL P2314T, a touch screen, is in its regular landscape orientation, with its bottom line aligning with the bottom of the rotated screen on the left.

Here's my xorg.conf for that. (Although one can also setup screen arrangement in KDE/Plasma/Gnome/etc., for KDM/SDDM/GDM/etc. to recognize it in the login screen, it's important to put this in xorg.conf)

X11 sees a (1024+1920) wide * 1280 high DISPLAY, with an upper-right corner being invisible.

Since the touchscreen is just a regular pointer device (through its driver), when I put my finger on the left border of the touchscreen on the right, the cursor goes all the way to the very left of the DISPLAY. Touchscreen is only useful if the cursor follows my finger. Therefore, we need to do some Input Coordinate Transformation.

Coordinate Transformation Matrix is precisely the needed configuration.

From the documentation above, our goal is to map the following coordinates on the left (X11's default behavior) to the ones on the right:

So that means we are solving the following system:

Here's the solution:

Convert it to float numbers:

Now we can put these numbers into the configuration, as the document instructed.

However, it doesn't work. The cursor stays on the lower right. After some debugging, I found the offsets 1024 and 200 were the culprit. They need to be a percentage, i.e. relative to the full width and height.

So 1024.0/(1024+1929) = .3476766, 200.0/1280 = .15625

I put it in /usr/share/sddm/scripts/Xsetup (or /usr/share/config/kdm/Xsetup if you haven't upgraded to plasma) as well as ~/.xprofile so it automatically runs every time.

Edit 2016-02-22: I ended up having 3 screens with two in the portrait orientation. SDDM correctly uses metamodes setting in xorg.conf, regardless of the screen power. However, KDE is more sensitive to that so sometimes the layout is messed up. Here's a script to quickly correct that.

No comments:

Post a Comment