The usability of Windows touchpad gestures has increased with the rollout of Windows 10, with not only a greater variety of gestures, but also an undeniable improvement in smoothness. In contrast, optimizing the touchpad experience for Linux, which is lacking on the desktop, is a concern for both Linux users and laptop users.

The following article focuses on Wayland’s own libinput and does not discuss alternatives such as synaptics. In addition, I have made some minor contributions to libinput’s Archwiki Chinese entry, which can be helpful too.

The configuration files for Linux input devices are stored in /etc/X11/xorg.conf.d and 30-touchpad.conf, as the name implies, the configuration information for the touchpad. Copy them to /usr/share/X11/xorg.conf.d and modify it. At this point you can refer to the basic framework of 40-libinput.conf and follow the following configuration format

Section "InputClass"
    Identifier "touchpad"
    Driver "libinput"
    Option "Tapping" "on"
    Option "NaturalScrolling" "true"
    Option "ClickMethod" "clickfinger"

where Option "Tapping" "on" turns on the “touch tap” operation of the touchpad which eliminating the need to press the touchpad.

Option "NaturalScrolling" "true" restores a more natural scrolling orientation, allowing you to gain experience on Windows.

Option "ClickMethod" "clickfinger" turns on the option of “two-finger click” for right-click and “three-finger click” for middle-click.

In addition, libinput provides more options for “tap”, “scroll”, “touchpad pointer acceleration”, etc. Other configuration options can be found in libinput’s man page

For more information about libinput’s various point-and-click scrolling operations, there are friendly illustrations in its documentation to help understand them. Also, you can see the configuration and support for other input devices such as “red dots” and “touch screens”, which are outside the scope of this article on “touch panels”, so they are not discussed.

Installing xdotool

The xdotool is a tool that can simulate keyboard and mouse input. When used in conjunction with the libinput-gestures package mentioned below, you can add and optimize touchpad gestures by binding them to corresponding hotkeys or mouse actions.

In the ArchWiki’s Recommended for Xorg’s emulation of keystrokes, xdotool is described as “Very Buggy”. However, after using it briefly, I think xdotool is very simple and bug-free (maybe I’m only using the part that handles keyboard input 😂) Here is the basic operation of xdotool

xdotool click 1
xdotool key Ctrl+L
xdotool mousemove x y
xdotool type 'string'

This can be considered a very clear syntax. It is worth noting that xdotool calls several special keys: 1 left mouse button, 2 middle mouse button, 3 right mouse button, Left left array button, Right right array button, Super Windows logo key, plus plus sign, minus minus sign.

xdotool also supports window retrieval, getting window focus, etc., which can fulfill most of the keystroke automation needs.

Using libinput-gestures

Install libinput-gestures and add the current user to the input group, copy the configuration file template /etc/libinput-gestures.conf to ~/.config/ for modification. Start libinput-gestures-setup for initialization

libinput-gestures-setup start

where gestures are known by libinput-gestures as swipe and pinch, which correspond to finger swipe and pinch operations on the touchpad, respectively. As we all know, the Ctrl + + and Ctrl + - hotkeys can basically zoom in and out on most software views, and it is customary to open both fingers for zooming in and pinch them for zooming out, so add them to ~/.config/libinput-gestures.conf first.

gesture pinch in 2 xdotool key Ctrl+minus
gesture pinch out 2 xdotool key Ctrl+plus

For pinch, you can specify in and out and the number of fingers involved in the action. Similarly, for swipe, the number of fingers involved and the four directions of swiping (Left, Right, Up, Down) can be specified, and here is an example of swiping left and right to switch tabs in Chrome.

gesture swipe right 3 xdotool key Ctrl+Tab
gesture swipe left 3 xdotool key Ctrl+Alt+Tab

Three finger swipe right goes to the next tab, three finger swipe left goes to the previous tab. There is no corresponding animation feedback, but it works fine.

From reading libinput-gestures related chapter, I learned that the touchpad does not differentiate between swipe and pinch with the same number of fingers involved in the action. pinch is not completely accurate, so do not configure the same number of fingers of two different actions coexist. The later experience will be poor for the greater the probability of misjudgment. Especially when the same number of fingers swipe but in different directions, such as configuring two fingers left and right swipe to switch applications, it is likely to conflict with two fingers up and down swipe, that is, scrolling action.

More possibilities

Of course, libinput-gestures and xdotool do not have to be used together, but you can also use keystroke-enabled ones like xte, xvkbd, and their operation is roughly the same as xdotool.

The following are examples of xvkbd implementing left mouse click and Ctrl+Tab respectively

xvkbd -no-jump-pointer -xsendevent -text '\m1'
xvkbd -no-jump-pointer -xsendevent -text '\Ct'

xte operations on key combinations are implemented using keydown and keyup. Here is an example of xte’s implementation of Ctrl+Tab

xte keydown Control_L
xte key Tab
xte keyup Control_L

Similarly, you can also bind libinput-gestures to launch an application directly, such as a four-finger swipe up to call out the application shortcut portal.

When you encounter a jumping and flashing touchpad pointer, or a serious gesture miscalculation, try restarting libinput-gestures with the following command

libinput-gestures-setup restart

Thanks for reading 💗