Xinput is a powerful command line tool for tweaking input device behavior in the Linux Xorg server. It grants low-level control over mice, touchpads, drawing tablets and other hardware. This 2600+ word insider‘s guide will teach you to leverage xinput for boosting productivity and comfort through customized scroll speeds, tap configurations and more.

How Linux Handles Input Devices

To understand xinput, we must first cover how Linux detects and interacts with input hardware like mice, keyboards and touchpads.

The X Window System (commonly X11 or Xorg) is the historic display server handling graphics and user input in Linux. More modern options like Wayland are slowly gaining adoption, but Xorg remains default in popular distros like Ubuntu.

A key responsibility of Xorg is managing input devices hotplugged via USB, Bluetooth and other connections. It handles enumeration, applies global settings, and routes input events to the correct applications.

Xorg Core Components

These are the main pieces of Xorg involved:

  • Xorg server – The core process started at login running on bare metal or in a VM
  • Device drivers – Kernel modules or userspace libraries powering device functionality
  • Input stack – Filters, modifies and processes input events before sending to clients
  • libinput – Generic input abstraction library for consistent event handling

When you attach a new keyboard or mouse, hotplugging rules kick in:

  1. The Linux kernel detects and enables the new hardware
  2. udev creates device nodes under /dev mapped to lower-level identifiers
  3. Xorg probes the nodes and loads any necessary drivers
  4. libinput reads capabilities and applies global settings
  5. Xinput makes the configured device available to Xorg clients

This seamless integration gives a plug-and-play experience. You can instantly use new hardware for scrolling webpages or entering passwords without reconfiguring anything.

Contrasting Xorg and Wayland

Modern Wayland compositors like GNOME are slowly replacing Xorg in specialty distros. The input handling architecture differs:

Xorg

  • Devices configured through Xserver via files like xorg.conf
  • Global settings with xinput plus per-client configurations
  • Broad hardware support with customizable drivers

Wayland

  • Input handling delegated to display server like GNOME Shell
  • Settings available via GUI tools or libinput configuration files
  • Generic kernel drivers fit most hardware thanks to libinput

Wayland pushes input processing into the display compositor. This suits devices like laptop touchpads. But for gaming mice, drawing tablets and niche hardware, Xorg remains favorable.

The Role of Libinput

Libinput is a shared library that uniformly handles input devices on both Xorg and Wayland. It‘s responsible for:

  • Processing raw input events from the kernel
  • Mapping events to global definitions like pointer motion
  • Filtering duplicate events or applying transformations
  • Adding multi-touch and gesture support
  • Exposing device capabilities for configurability

Libinput enables Xorg and Wayland compositors to support extremely varied hardware like 3D mice or courtroom sketchpads using standard APIs.

It plays a pivotal role letting xinput tweak configurations in Xorg. The settings changed with xinput directly adjust libinput behavior for that device.

Now that we‘ve covered the Linux input stack, let‘s see how to leverage xinput and libinput to customize mice, touchpads and more.

Customizing Input Devices with Xinput

Xinput allows applying per-device settings overriding the Xorg server and libinput defaults. This grants control over acceleration profiles, scroll speeds, button mappings and advanced functionality.

Let‘s walk through practical examples of improving Linux usability by tweaking input hardware behavior with xinput.

Listing Available Input Devices

The first step is enumerating which input devices are connected and managed through Xorg.

Run this simple command to print recognized mice, touchpads, tablets and other hardware:

xinput list

A sample output section may look like:

⎡ Virtual core pointer                      id=2   [master pointer]
⎜   ↳ Logitech MX5000                     id=10   [slave pointer]   
⎜   ↳ SynPS/2 Synaptics TouchPad               id=12   [slave pointer]
⎜   ↳ Wacom Intuos PT S Pen stylus            id=14   [slave pointer]
⎜   ↳ Wacom Intuos PT Pen eraser             id=15   [slave pointer]

This shows my USB mouse, internal laptop touchpad, and digital drawing tablet with stylus are all managed by Xorg.

Take note of the full name and ID of devices you wish to customize.

💡 Pro Tip: Refer to devices by name rather than ID, as IDs may change between reboots based on enumeration order.

Viewing Device Capabilities

Now that we know available hardware, we can check device capabilities exposed through libinput.

Run:

xinput list-props "Logitech MX5000"

And you will see TONS of options printed for configured mice, touchpads and tablets.

Here are some particularly useful settings:

Pointer Acceleration:

Device Accel Profile (276): 0
Device Accel Constant Deceleration (277): 1.000000
Device Accel Velocity Scaling (278): 1.000000

Scrolling Configuration:

Libinput Scroll Method Enabled (283): 1, 1
Libinput Scroll Button (284): 274
Libinput Button Scrolling Button (285): 274

Advanced Gestures:

Libinput Tapping Enabled (282): 1
Libinput Middle Emulation Enabled (286): 0
Libinput Disable While Typing Enabled (288): 1

And device-specific settings like noise cancellation for touchpads.

Using xinput list-props, you can probe the full gamut of customizations exposed by libinput for a particular piece of hardware.

Adjusting Pointer Acceleration

One common task is tuning pointer acceleration – the curve determining how rapidly mouse cursors accelerate when moving the device faster.

Users often want to flatten the acceleration profile for consistent cursor speeds during gaming and graphics work.

We can tweak the acceleration with:

xinput set-prop "Logitech MX5000" "Device Accel Constant Deceleration" 2.5

Higher values lead to a flatter acceleration curve and less velocity change when quickly swiping mice. Adjust until cursor movement precisely matches hand motion.

For touchpads, you may want higher acceleration to allow quickly traversing wider displays. Enable as needed with:

xinput set-prop "ELAN Touchpad" "Device Accel Velocity Scaling" 1.15

Inverting Scroll Direction

Another ergonomic setting is inverting the scroll direction to match between mice, touchpads, and OS expectations:

xinput set-prop "Logitech MX5000" "Libinput Natural Scrolling Enabled" 1

This makes the mouse wheel scroll up when moving fingers upward, and down when dragging down.

Some users strongly prefer "natural" inverted scrolling on touchpads but classical direction with mice. Xinput gives you freedom to standardize or mix things up.

Correcting Hardware Button Mappings

For specialty input devices, manufacturers sometimes incorrectly map buttons or axes in their kernel drivers:

xinput set-prop "Wacom Intuos PT Pen stylus" "Evdev Axes Swap" 1

Tweaks like axis swapping let you workaround quirky hardware handling – no proprietary configuration tools needed!

Disabling Touchpads While Typing

To avoid accidental touches when typing on laptops, you can automatically disable touchpads:

xinput set-prop "SynPS/2 Synaptics TouchPad" "Libinput Disable While Typing Enabled" 1

The touchpad will re-enable anytime the keyboard is idle. This prevents frustrating mid-sentence cursor jumps!

Expanding on Advanced Gestures

Beyond basic operation, many touchpads and drawing tablets support intricate finger combinations for shortcuts and efficiency boosts:

xinput set-prop "Wacom Intuos PT Pen stylus" "Wacom Enable Gesture" 1

Now specialized gestures like pinch or rotate get recognized in graphics apps.

Use xinput list-props to uncover device-specific taps, swipes, squeezes and more for streamlining workflows.

Matching Sensitivity Across Devices

If you use multiple input devices interchangeably, tuning the sensitivity can help coordinate muscle memory:

xinput set-prop "ELAN Touchpad" "Libinput Calibration Matrix" 1 0 0 0 1 0 0 0 1
xinput set-prop "Logitech MX5000" "Device Accel Velocity Scaling" 0.9

Now cursor movement precisely matches between mouse and touchpad.

Persisting Custom Configurations

A catch when tweaking xinput settings is they reset whenever Xorg restarts – like on system bootup or login.

Let‘s examine automatic techniques to load device customizations every session.

Startup Applications (GUI Method)

Most Linux desktops include startup applications or auto-start programs. These launch user commands when logging in.

We can leverage this feature to execute xinput every time X starts:

  1. Search for "Startup Applications" and open the tool
  2. Click add, then provide a name like "Custom Input Devices"
  3. In the command field, paste the xinput invocation
  4. Ensure the new entry is enabled and will run on login

For example, my Logitech mouse entry looks like:

xinput set-prop "Logitech MX5000" "Libinput Natural Scrolling Enabled" 1

Now natural scrolling gets set automatically whenever I start my desktop!

Xorg Configuration Files (Expert Method)

For power users wanting fine control over input devices, custom Xorg configurations work wonders. These *.conf files get parsed whenever starting the X server.

First, create a file like /etc/X11/xorg.conf.d/50-custom-inputs.conf with sudo permissions.

Then add device specific sections:

Section "InputClass"
    Identifier "Logitech Mouse"
    MatchProduct "Logitech MX5000"    
    Option "NaturalScrolling" "on"
EndSection

Section "InputClass"     
    Identifier "Wacom Tablet"
    MatchProduct "Wacom Intuos PT Pen stylus" 
    Option "EnableGesture" "on"
EndSection 

The crucial parts are:

  • Identifier – A friendly name for humans
  • MatchProduct – Must precisely match xinput list names
  • Options – InputClass properties like toggles and constants

With this file in place, Xorg parses it on launch and overrides device defaults!

Note the benefits over startups apps:

  • No need for separate GUI entries when changing multiple options
  • Can share file between systems for easy sharing of configuration
  • Handle more advanced settings than xinput alone allows

For supercharged customization leveraging other tools like xbindkeys, xorg files excel.

Optimizing Linux Productivity via Xinput

In this guide, we covered the anatomy of Linux input stacking from kernel to Xorg to applications. We detailed how hotplugging automounts devices, libinput interprets capabilities, and xinput exposes settings for tweaking.

Practical examples demonstrated using xinput to:

  • List connected mice, keyboards, tablets and touchpads
  • Inspect advanced device settings for acceleration, scrolling, typing and gestures
  • Tune configurations for matching sensitivity across hardware
  • Fix quirky button layouts or inconsistent scroll directions
  • Persist changes across reboots by scripting xinput commands

The benefit of learning xinput is unlocking customization options hidden within desktop environments. You can precisely tune niche parameters for boosting FPS skills or graphics tablet ergonomics. This delivers a tailored experience no GUI toolbox can match.

While requiring some comfort with the Linux terminal, don‘t let that scare you off. xinput remains far simpler than the labyrinthine Windows Registry! Just follow this guide, tweak to your needs, and transform productivity with fine-tuned input devices.

Similar Posts