libinput Explained: Touchpads, Gestures and Keyboard Remapping
Input on Linux used to be a per-desktop problem, with X11 drivers, xinput commands and xorg.conf snippets. libinput replaced that with one library that Wayland compositors and the modern X11 driver both use, which is why the advice you find from 2015 mostly no longer applies.
Where it sits
kernel evdev → libinput → compositor → applications
The kernel exposes raw events through evdev. libinput reads them and applies the processing nobody wants to reimplement: pointer acceleration, tap-to-click, palm detection, gesture recognition, scroll handling.
The compositor then decides what to do with the result and holds the configuration.
That last point is the one that matters. libinput does not read a config file of its own. Settings come from whatever is driving it.
sudo apt install libinput-tools # Debian and Ubuntu
sudo dnf install libinput-utils # Fedora
# every device and what it can do
sudo libinput list-devices
# watch events live, which is the diagnostic tool
sudo libinput debug-events
# including the gesture recognition
sudo libinput debug-events --verbose
libinput list-devices output is worth reading once:
Device: SynPS/2 Synaptics TouchPad
Kernel: /dev/input/event7
Capabilities: pointer gesture
Tap-to-click: disabled
Natural scrolling: disabled
Disable-w-typing: enabled
Click methods: button-areas clickfinger
Scroll methods: two-finger edge
Those lines tell you what the hardware supports and what is currently set. A feature absent from Capabilities is not configurable, which saves time arguing with a settings panel.
xinput is mostly historical now
# on Wayland, this lists almost nothing useful
xinput list
echo "$XDG_SESSION_TYPE"
# wayland
xinput talks to the X server. On a Wayland session there is no X server owning your devices, so it has nothing to configure. At most it affects XWayland clients, inconsistently.
The same goes for xmodmap, setxkbmap and /etc/X11/xorg.conf.d/ snippets: X11 only. Our Wayland versus X11 guide covers why the architecture changed.
Configuring it, by session type
A full desktop
Use the desktop’s own settings. GNOME stores them in dconf, KDE in its config files, and the compositor reads those, so editing anything else is ignored.
# GNOME, from the command line
gsettings set org.gnome.desktop.peripherals.touchpad tap-to-click true
gsettings set org.gnome.desktop.peripherals.touchpad natural-scroll true
gsettings set org.gnome.desktop.peripherals.touchpad speed 0.3
gsettings set org.gnome.desktop.peripherals.touchpad click-method 'fingers'
# what is available
gsettings list-recursively org.gnome.desktop.peripherals.touchpad
gsettings list-recursively org.gnome.desktop.peripherals.mouse
# KDE
kcmshell6 kcm_touchpad
# or edit ~/.config/kcminputrc
Sway, Hyprland and other bare compositors
In the compositor config, since there is no desktop settings panel.
# sway, in ~/.config/sway/config
input "type:touchpad" {
tap enabled
natural_scroll enabled
dwt enabled
middle_emulation enabled
accel_profile adaptive
pointer_accel 0.3
scroll_method two_finger
click_method clickfinger
}
input "type:keyboard" {
xkb_layout "gb"
xkb_options "ctrl:nocaps"
repeat_delay 300
repeat_rate 40
}
# sway: find the identifier for a specific device
swaymsg -t get_inputs
# hyprland, in its Lua config since 0.57
# see our Hyprland coverage for the config format change
Our tiling compositors guide covers the compositors themselves.
X11, still
# /etc/X11/xorg.conf.d/40-touchpad.conf
Section "InputClass"
Identifier "touchpad"
Driver "libinput"
MatchIsTouchpad "on"
Option "Tapping" "on"
Option "NaturalScrolling" "true"
Option "DisableWhileTyping" "on"
Option "ClickMethod" "clickfinger"
EndSection
man libinput # the full option list
The settings worth knowing
click_method is the one most people want changed and do not know the name of.
button_areasdivides the bottom of the pad into left, middle and right zonesclickfingeruses the number of fingers: one for left, two for right, three for middle
clickfinger is what macOS does and what most people prefer once they try it, because it removes the need to aim.
dwt, disable while typing, suppresses the touchpad briefly after a keystroke. The fix for cursor jumps mid-sentence.
Palm detection needs hardware support. It works from pressure data or a known quirk for the specific model, and some inexpensive touchpads provide neither, in which case dwt is all you get.
accel_profile is adaptive or flat. Flat means one-to-one movement with no acceleration, which gamers and some precision work prefer.
# test acceleration changes immediately, before committing them
sudo libinput debug-events --set-profile=flat
Gestures
Three and four finger swipes are reported by libinput and acted on by the compositor. GNOME and KDE both use them natively.
# are gestures reaching the stack at all
sudo libinput debug-events | grep -i gesture
On a bare compositor, nothing consumes them by default. libinput-gestures fills the gap:
sudo apt install libinput-gestures
sudo gpasswd -a "$USER" input # log out and back in
# ~/.config/libinput-gestures.conf
gesture swipe up 3 wtype -M ctrl -M shift -k t
gesture swipe left 4 swaymsg workspace next
gesture swipe right 4 swaymsg workspace prev
gesture pinch in 2 wtype -M ctrl -k minus
libinput-gestures-setup start
libinput-gestures-setup autostart
Note the input group requirement. Reading /dev/input/event* directly needs it, which our /dev guide covers, and it is a meaningful privilege: group membership means the process can read every keystroke on the system.
Keyboard remapping that works everywhere
The right answer, and it is not xmodmap.
keyd remaps at the evdev level, before libinput sees the event. Which means it applies in every application, on X11 and Wayland, in a TTY, and in the display manager.
sudo pacman -S keyd # Arch
# or build from source on other distributions
# /etc/keyd/default.conf
[ids]
*
[main]
# caps lock as both escape and control, the classic
capslock = overload(control, esc)
# swap left alt and super
leftalt = leftmeta
leftmeta = leftalt
[control]
# control plus hjkl as arrows, everywhere
h = left
j = down
k = up
l = right
sudo systemctl enable --now keyd
sudo keyd monitor # watch what it is doing
overload(control, esc) is worth knowing: held it acts as Control, tapped it sends Escape. That single mapping is the most popular keyboard change on Linux and it is one line here.
xremap is the alternative, with per-application rules and a config in YAML. More capable, more moving parts.
Why remap at this level rather than in the desktop:
| Approach | Scope |
|---|---|
keyd / xremap | Everything, including TTY and login screen |
Compositor xkb_options | That compositor’s session |
| Desktop shortcut settings | That desktop |
xmodmap / setxkbmap | X11 only |
For simple layout changes, xkb_options in the compositor config is sufficient:
xkb_options "ctrl:nocaps" # caps becomes control
xkb_options "caps:escape" # caps becomes escape
xkb_options "compose:ralt" # right alt as compose key
# the full list, which is long and worth skimming once
man 7 xkeyboard-config
grep -A2 'ctrl:' /usr/share/X11/xkb/rules/base.lst | head -20
Diagnosing input problems
# is the kernel seeing the device
sudo libinput list-devices | grep -A5 -i touchpad
cat /proc/bus/input/devices | grep -A5 -i touchpad
sudo dmesg | grep -iE 'input|touchpad|i2c_hid' | tail -20
# is libinput getting events
sudo libinput debug-events --device /dev/input/event7
# what does the compositor think
swaymsg -t get_inputs # sway
gsettings list-recursively org.gnome.desktop.peripherals.touchpad
Causes in rough order:
- Configuring the wrong layer.
xinputon Wayland, or anxorg.conf.dfile on a Wayland session - Device not detected, which is a kernel and firmware problem rather than libinput. Check
dmesgand our firmware guide - A quirk missing for new hardware. libinput carries per-model quirk files, and a very new laptop may predate its entry
- Hardware that does not report what the feature needs, which
list-devicescapabilities will show
# quirks, for the fourth case
ls /usr/share/libinput/
sudo libinput quirks list /dev/input/event7
A missing quirk is a reportable bug with a straightforward fix upstream, and libinput record produces exactly the data the maintainers ask for:
sudo libinput record /dev/input/event7 > touchpad.yml
Frequently Asked Questions
What is libinput?
The library that handles input devices for Wayland compositors and the modern X11 driver. It reads events from the kernel through evdev and applies processing such as pointer acceleration, palm detection, tap-to-click and gesture recognition, so every desktop gets consistent behaviour from one implementation.
Why do xinput commands no longer change anything?
Because xinput talks to the X server, and on a Wayland session there is no X server managing your devices. The compositor owns input and applies its own configuration. Use your desktop settings or the compositor config file instead, since xinput at best affects XWayland clients.
Where do I configure touchpad settings?
On a full desktop, through its own settings, because the compositor reads those rather than any config file. On a bare compositor such as Sway or Hyprland, in the compositor configuration. The X11 config files under xorg.conf.d apply only to X11 sessions.
What is the difference between natural scrolling and reverse scrolling?
They are the same setting under different names. Natural scrolling means content follows your fingers, as on a phone, rather than the scrollbar following them. libinput calls the option natural scrolling and some desktops label it reverse, which inverts the sense of the toggle and causes confusion.
How do I remap a key so it works in every application?
Use keyd or a similar daemon that remaps at the evdev level before libinput sees the event, which means it applies in every application and on every session type. Approaches based on xmodmap or setxkbmap only affect X11, and desktop shortcut settings only affect that desktop.
Why does my touchpad register clicks when I am typing?
Palm detection and the disable-while-typing feature are either not working for your hardware or not enabled. Check the device capabilities with libinput list-devices, since palm detection needs either a touchpad that reports pressure or a known hardware quirk, and some cheap touchpads provide neither.