# Optimizing Touchpad Performance on Linux

## Bring touchpad experience from Windows™ to Linux

The serviceability of touchpad gestures on Windows™ is getting better and better since Windows 10 grows. The smoothness of gestures is greatly improved undoubtedly. In contrast, optimizing the experience of using touchpad on Linux with weak desktop environments is a problem that users who want to live as Linux users and also laptop users need to concern about 🤔.

The following is mainly about the libinput that following with Wayland but alternatives such as Synaptics. In addition, I have made some minor contributions to libinput(Simplified Chinese) in Archwiki, which can also be helpful.

The configuration files for Linux input devices are stored in /etc/X11/xorg.conf.d and 30-touchpad.conf, as the name suggests, is the configuration information for the touchpads. Copy it to /usr/share/X11/xorg.conf.d to do changes. At this moment, you can refer to the basic framework provided by 40-libinput.conf, following the configuration format below:

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


Option "Tapping" "on" turns on touch-to-tap option of the touchpad. There is going to be no need to press hard on the touchpad

Option "NaturalScrolling" "true" restores the more natural scrolling direction as same as Windows™, allowing you regain experience on Windows™

Option "ClickMethod" "clickfinger" turns on option double-finger-tap-to-right-click and three-finger-tap-to-click-on-the-middle.

In addition to this, libinput offers more options for tweaking click, scroll, touchpad pointer acceleration, etc. For other configuration options, see man page of libinput

There are friendly legends in the documents from freedesktop to help you understand various scrolling operations on libinput. At the same time, you can also see the configurations and supports for other input devices such as Trackpoint and Touch Screen, which is not within the scope of Touchpad in this article, so they are not discussed.

## Install xdotool

xdotool is a tool that can simulate keyboard strikes and mouse inputs. Cooperating with the libinput-gestures package mentioned below, you can bind trackpad gestures to the appropriate hotkeys or mouse opereations to add and optimize touchpad gestures.

In the Archlinux wiki, xdotool is described as ‘Very buggy’ in the recommendation list for analoging keyboard strikes and mouse activities in Xorg. However, I think that xdotool is very handy to use and there is nothing going wrong to me. The following is the basic operation of xdotool:

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


The grammar is very clear, so to speak. It is worth noting that for a few special keys, xdotool called them:

• 1 left mouse button
• 2 mouse middle button
• 3 right mouse button
• Left left arrow key
• Right right arrow key
• Super Super key
• plus plus key
• minus minus key

xdotool also supports search windows, focus to certain window and so on, which can fulfill the needs of most automation engaged with keyboard and mouse.

## Use 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/ to modify it. Start libinput-gestures-setup to initialize it

libinput-gestures-setup start


Gestures in libinput-gestures are cognized as: swipe and pinch, which respectively correspond to the swiping and pinching operation of the fingers on the touchpad. As we all know, these Ctrl + + and Ctrl + - hotkeys can basically enlarge and shrink views in most softwares. We are used to pinch-out-to-zoom-in and pinch-in-to-zoom out. So firstly add them to ~/.config/libinput-gestures.conf

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


With regard to pinch, you can specify in and out and the number of fingers involved in the activity. Similarly, for swipe, the number of fingers involved in the activity and the four directions of the swiping, which can be known as Left, Right, Up, and Down, can also be specified. The following is an example of swiping leftward and rightward to switch tabs in Chrome and most browsers.

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


Swipe to right with three fingers to the next tab and swipe to left with three fingers to go to the previous tab.

Although there is no animation feedback, it is still easy enough to get on hand.

By reading libinput-gestures related chapters about the introduction, we can know that the same number of fingers to swipe as to pinch may confuse the touchpad, so do not configure the two different actions with the same number of fingers, the experience will be worse, and there is greater probability to be misjudged. Especially when swiping with the same number of fingers but different directions, if you configure the double-finger swiping leftward and rightward to switch applications, it will be likely to conflict with the double-finger swiping upward and downward, that is, the scrolling.

## Few more Things

Of course, libinput-gestures and xdotool do not have to be used together. Supports for mouse and keyboard simulations can also be done by xte, xvkbd, and their usages are basically the same as xdotool.

The following is an example of xvkbd implementing left-click and Ctrl+Tab

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


xte operations on composite keys are implemented using keydown and keyup. The following is an example of xte implementing Ctrl+Tab

xte keydown Control_L
xte key Tab
xte keyup Control_L


Similarly, you can bind a gesture to launch an application directly via libinput-gestures, such as four-fingers swiping upward to open the application shortcut entry.

When the touchpad pointer acting strangely, or the gestures are misjudged, you can restart libinput-gestures with the following command to fix it:

libinput-gestures-setup restart