Touchscreen calibration with dual monitors (NVidia and xinput)
I've got a NVidia GTX260 card with one regular screen above one touchscreen using the eGalax driver.
I've tried to configure the touchscreen using xinput but I can't get it right. With the normal screen disconnected and fiddling with the "Evdev Axis Calibration" option it works fine, but when I hook up the normal screen again the tough mapping is shifted. If I touch the touchscreen the mouse moves to the corresponding position on the other screen.
Neither "Coordinate Transformation Matrix" nor "map-to-output" seems to work...
Any help is greatly appreciated!
/Henrik
I now (on 13.04) had a similar problem but xinput map-to-output
did help, if I do things in the right order.
xinput map-to-output
tweaks the "Coordinate Transformation Matrix".xinput_calibrator
sets "Evdev Axis Calibration" and is completely unaware of "Coordinate Transformation Matrix". It also always opens stretched to the full available output area.
This means that you must run xinput_calibrator
on a single screen.
xrandr --output <non-touch-output> --off
xinput map-to-output <touch input device> <touch-output>
(to reset "Coordinate Transformation Matrix" in case you've touched it before).Calibrate with
xinput_calibrator
.
You should now have well-calibrated touch on the single screen.
(My touchscreen was initially way off — X/Y swapped, Y inverted — so I had to run this twice, with--misclick 0
. I believe that's a property of my touchscreen, unrelated to the dual monitor situation.)Re-enable the second screen.
xrandr --output <non-touch-output> --on
Do
map-to-output
again.
While Beni's answer will probably work for some (if not most) people, in my case xinput_calibrator
was still getting confused despite the other displays being disabled. I also wasn't partial to installing closed-source drivers from the vendor.
Fortunately, using the information in this very QA and other sources (the EVDEV xorg documentation, and this answer), it turns out it's completely possible to set up everything manually as long as you're using EVDEV and Xorg (default for Kubuntu currently at least).
Single-session setup (via xinput)
- Find the device ID via
xinput --list
. This will be referred to as<DEVICE_ID>
. - Run
xinput --list-prop <DEVICE-ID>
and note down the default values just in case. - Set up the Coordinate Transformation Matrix property. The easiest way would be installing ptxconf from Hrobjartur's answer and using its configure option.
- You're now ready to set up axes. The first step is checking whether the X and Y coords are swapped with one another. To do this:
- press your finger/stylus on the top of your screen,
- and on the bottom.
If the mouse pointer appears on the left and right (or vice versa), run:
xinput --set-prop <DEVICE_ID> "Evdev Axes Swap" 1
. Otherwise, leave this property unchanged.
- Now, check whether the X and/or Y axes need to be inverted. This is controlled by the
Evdev Axis Inversion
property, with two values -X Y
, where 0 is normal and 1 is inverted. So:- check whether pressing on the far left of the screen places your cursor on the right. If so, you need to invert X.
- check whether pressing on the very top of the screen places your cursor at the bottom. If so, you need to invert Y.
- For example, inverting X and and leaving Y unchanged means running:
xinput --set-prop <DEVICE_ID> "Evdev Axis Inversion" 1 0
.
- Now we get to the fun stuff - calibration. The
Evdev Axis Calibration
property controls it, and it's theoretically vendor specific, but it's possible to figure it out with a bit of prodding (literally). Here's what you need to do:- check whether
Evdev Axis Calibration
was reset (it happened in my case after running ptxconf). If so, runxinput --set-prop <DEVICE_ID> "Evdev Axis Calibration" <DEFAULT_VALUES_FROM_POINT_1>
(take note that while the values are comma-separated in the output, they should be space-seperated in the input). - the values could be described, at least in my case, as
<FAR_RIGHT_OFFSET> <FAR_LEFT_OFFSET> <VERY_TOP_OFFSET> <VERY_BOTTOM_OFFSET>
. - take your stylus, and start poking at the far right offset. Adjust the first value until the pointer is under your stylus. Don't worry if the pointer is off-target on the other axis.
- do the same for the far left offset. Check if the offset on the right is still correct, if not, tweak the two values until you have a match.
- do the same with the other two offsets.
- check if the pointer is correctly placed on the far left middle, far right middle, top center, and bottom center of your screen. If so, you're good to go.
- check whether
- Run
xinput --list-props <DEVICE_ID>
and note down your final values. That's it!
Permament setup (via xorg conf)
As the xinput_calibration
output notes, to get the setting to stick you need to add a cofiguration file to your xorg conf's dir (it's /usr/share/X11/xorg.conf.d/
on Ubuntu, named with a sufficiently low priority - like
99-calibration.conf
in the example provided).
Prepare the xinput property values, and check the device name in xinput --list
. Now, all you have to do is create the file in the following way:
Section "InputClass"
Identifier "calibration"
MatchProduct "<DEVICE_NAME_FROM_XINPUT_LIST>"
Option "TransformationMatrix" "<VALUES_FROM(Coordinate Transformation Matrix)>"
Option "Calibration" "<VALUES_FROM(Evdev Axis Calibration)>"
Option "SwapAxes" "<VALUE_FROM(Evdev Axes Swap)>"
Option "InvertX" "<X_VALUE_FROM(Evdev Axis Inversion)>"
Option "InvertY" "<Y_VALUE_FROM(Evdev Axis Inversion)>"
EndSection
For example:
Section "InputClass"
Identifier "calibration"
MatchProduct "ACME USB Touch"
Option "TransformationMatrix" "0.5656 0.000000 0.676576 0.000000 0.765756 0.756233 0.000000 0.000000 1.000000"
Option "Calibration" "50 1366 25 2876"
Option "SwapAxes" "1"
Option "InvertY" "1"
EndSection
Check whether everything works after a reboot. And now you're all set!
for me with Ubuntu 12.04 LTS (64bit) it didn't wort until i saw in the xinput --help that the right command is
xinput map-to-crtc 'Name of input device' Name of output device
while Name of input device is shown by $xinput --list, name of output device is shown be $xrandr and could be LVDS1 oder VGA1 e.g.
If you want a graphical tool that sits in you system tray, then we just created one and would like to see if it is useful to anyone else: Just select your input pen device and which screen to map it to:
http://wenhsinjen.github.io/ptxconf/
We just started so its may have problem identifying your tablet or screens, so please let us know. We'll fix it straight away. Also we plan to have it retain its previous configuration after startup - maybe even remember which config was used for which screen configuration if some people keep adding and removing monitors.