How to set up trackpad gestures on ElementaryOS and Ubuntu
If you by any chance had an opportunity to use a trackpad on MacBook or even better a Magic Trackpad I highly doubt you weren't amazed. I know I was. It's definitly one of few things I missed the most when switched from MacBook Pro to ThinkPad T490. Eventhough ThinkPad's keyboard is by far superior to Mac's, the trackpad is... meh. Nontheless, it is a multitouch device and that means I can use it with swipe and pinch gestures to supercharge my workflow.
Sadly, I don't know about any Linux distro that comes with a usable gesture support. No worries, that's why this tutorial exists.
libinput
is a library that adds various gestures support to the OS.
In order to be allowed to use gestures, your user must be added to the input
group
In terminal, type the following command and enter your password
sudo gpasswd -a $USER input
After that, you will have to logout, and log back in order for the changes to take effect.
Install packages needed to install and use app for creating and mapping gestures.
sudo apt-get install wmctrl python3 python3-setuptools xdotool python3-gi libinput-tools python-gobject
After that, clone the libinput-gestures
to your Downloads directory:
cd ~/Downloads
git clone https://github.com/bulletmark/libinput-gestures.git
cd libinput-gestures
sudo make install
To be sure that this utility is started whenever your computer is turned on, we need to run the following commands:
libinput-gestures-setup autostart
libinput-gestures-setup start
At this point, you can create a config file to map gestures to actions which I'll cover in another tutorial. For the sake of simplicity, we'll stick with a GUI app for this one.
To install Gestures GUI app, run following commands:
cd ~/Downloads
git clone https://gitlab.com/cunidev/gestures.git
cd gestures
sudo python3 setup.py install
Mapping gestures to actions
Run Gestures app from the Applications menu.
Start by adding new gesture. Simply click + icon in the upper-left corner.
In the pop-up choose which type of gesture you wish to add - Swipe or Pinch. Next, choose a direction: Up, Down, Left, Right for the Swipe type of gesture and In, Out, Clockwise, Anticlockwise for the Pinch. After that, select how many fingers the gesture is consisted of. In the Command field you should enter a command which will be executed when geture occures. For this, we will use xdotool which we installed at the beginning. It is a simple utility that programatically "fakes" keyboard and mouse events. Will use it to trick our OS to think we pressed a keyboard shortcut.
The way I use setup my gestures is:
4-finger swipe left perform xdotool key super+Right
(Switch to workspace right)
4-finger swipe right perform xdotool key super+Left
(Switch to workspace left)
4-finger swipe up perform xdotool key super+Up
(
Toggle maximized)
4-finger swipe down perform xdotool key super+Down
(
Multitasking view, same as super+S)
3-finger swipe left perform xdotool key alt+Left
(
Browser back)
3-finger swipe right perform xdotool key alt+Right
(
Browser forward)
Add getures one by one and click confirm.
For the swipe action, Two fingers option might be disabled because it's already provided by the touchpad itself for scrolling.
As a last step, we can clean up by safely removing cloned repositories
rm -rf ~/Downloads/libinput-gestures
rm -rf ~/Downloads/gestures
I hope this helps you in your everyday work, I sure know it helped me :)
Here are some links and references related to the libraries mentioned in this article