Using xinput to Configure Linux X11 Touchscreens
This article provides an overview of how the Linux operating system
uses the xinput utility to control and calibrate
touchscreen hardware under the X11 display architecture. It covers the
underlying communication between the Linux kernel, the X server, and
input drivers, followed by the practical steps required to query, map,
calibrate, and persist touchscreen settings using
xinput.
The Architecture: Kernel to X11
The Linux operating system processes touchscreen inputs through a layered architecture:
- Kernel Level (
evdev): When you touch a physical digitizer, the hardware generates hardware interrupts handled by a kernel driver. The kernel exposes these interactions via the event device subsystem (/dev/input/event*). - X Server Driver (
xf86-input-libinputorevdev): The X.Org Server reads these raw kernel events through an input driver—most commonlylibinputon modern distributions. The driver normalizes raw multi-touch and absolute coordinate data into X11 core protocol events. - XInput Extension: The X server exposes these inputs via the X Input Extension (XInput), currently at version 2 (XI2).
- The
xinputTool: Thexinputcommand-line utility directly interfaces with the XInput extension, allowing users and scripts to dynamically query hardware states and modify driver properties at runtime without restarting the display server.
Identifying the Touchscreen
To manage a device, the X server must first identify it. Running the following command lists all recognized input devices, split into master and slave pointers/keyboards:
xinput listLook for the device name corresponding to your touchscreen digitizer
under the Virtual core pointer hierarchy. Note either
its full string name or its numerical id.
Inspecting Runtime Properties
Every driver exposes a set of configurable runtime parameters to the X server. To view the active properties of a specific touchscreen:
xinput list-props <device-id-or-name>Output properties typically include:
- Device Enabled: Toggles the device on
(
1) or off (0). - Coordinate Transformation Matrix: An affine transformation matrix controlling translation, scaling, and rotation.
- libinput Calibration Matrix: Internal hardware-to-display calibration values.
- libinput Send Events Modes: Toggles behaviors like disabling touch when an external mouse is attached.
Mapping and Rotating with the Transformation Matrix
The primary method Linux uses to align touch coordinates with display outputs is the Coordinate Transformation Matrix. This 3x3 matrix maps input coordinates \((x, y)\) to display coordinates \((x', y')\).
[ c0 c1 c2 ]
[ c3 c4 c5 ]
[ c6 c7 c8 ]
By default, the matrix is set to the identity matrix
(1 0 0 0 1 0 0 0 1). You can change this using
xinput set-prop:
xinput set-prop <device-id> "Coordinate Transformation Matrix" c0 c1 c2 c3 c4 c5 c6 c7 c8Common transformations include:
- Rotate 90 degrees clockwise:
xinput set-prop <device-id> "Coordinate Transformation Matrix" 0 1 0 -1 0 1 0 0 1 - Rotate 180 degrees:
xinput set-prop <device-id> "Coordinate Transformation Matrix" -1 0 1 0 -1 1 0 0 1 - Rotate 270 degrees clockwise:
xinput set-prop <device-id> "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1 - Map to a specific monitor in a multi-monitor
layout: X11 provides a helper utility,
xinput map-to-output, which automatically calculates and applies the necessary matrix:(Example:xinput map-to-output <device-id> <output-name>xinput map-to-output 11 eDP-1)
Real-Time Event Debugging
To verify that the X server receives input coordinates and button
clicks accurately, xinput can capture raw events in real
time:
xinput test <device-id>Touching the screen will output real-time absolute motion events
(motion a[0]=... a[1]=...) and button state
transitions.
Persisting xinput
Configurations
Changes made via the xinput command are stored in the X
server's memory and are lost when the display server restarts or when
the device is unplugged. To make configurations permanent across
reboots, Linux supports two primary approaches:
Xorg Configuration Files (Recommended for system-wide persistence):
Create anInputClassconfiguration file inside/etc/X11/xorg.conf.d/(e.g.,99-touchscreen.conf):Section "InputClass" Identifier "Touchscreen Calibration" MatchProduct "Your Touchscreen Name" MatchDevicePath "/dev/input/event*" Driver "libinput" Option "TransformationMatrix" "1 0 0 0 1 0 0 0 1" EndSectionSession Startup Scripts (User-level persistence):
Add the specificxinput set-proporxinput map-to-outputcommands to user session initialization files, such as~/.xprofile,~/.xinitrc, or the autostart utility of your desktop environment.