Notes

Enable macOS like touchpad gestures on Ubuntu

Edit on GitHub

Linux
4 minutes

NOTE: i ended up finally learning how to properly use Workspaces in Ubuntu and no longer use the swipe gesture. They were wonky anyway, middle click was still pasting things in the end.. The touchpad on a Lenove Thinkpad is good, better than any HP or Acer i have ever used, but still doesn’t compare to one on a MacBook

FYI:

  • I’m using the touchpad of a Lenovo T450.
  • On my Mac, i use 3-finger swipe up for app Expose, and 3-finger left/right to switch between full-screen apps

Installation and setup

Add yourself to the input group.

1# must be a part of the 'input' group to have permission to read touchpad device
2sudo gpasswd -a $USER input

Logout completely to assign this group and log back in (or reboot). You can confirm that you were added to the group with groups

Loggin out/in didn’t work for me so went ahead and rebooted..

 1# install xdotool for keyboard input and wmctrl for Window Manager control
 2sudo apt install -y xdotool wmctrl
 3
 4# install libinput-tools
 5sudo apt install libinput-tools
 6
 7# install dependencies for Gestures GUI
 8sudo apt install -y python3 python3-setuptools python3-gi python-gobject
 9
10# install libinput-gestures from its repo
11cd /home/${USER}/Downloads/
12git clone https://github.com/bulletmark/libinput-gestures.git
13cd libinput-gestures
14# sudo make install 
15# OR
16sudo ./libinput-gestures-setup install
17
18# Install the Gestures GUI from it's git repo
19cd /home/${USER}/Downloads/
20git clone https://gitlab.com/cunidev/gestures
21cd gestures
22sudo python3 setup.py install
23
24# start and set it to start automatically on boot
25libinput-gestures-setup autostart
26libinput-gestures-setup start
27
28# cleanup
29cd /home/${USER}/Downloads/
30sudo rm -rf ibinput-gestures gestures
31sudo apt autoremove -y
  • We need xdotool to stimulate keyboard input
  • We need wmctrl to control Window Manager
  • We may need to install libinput-tools on Ubuntu
  • libinput supports both pinch and swipe gestures

3 finger swipe and middle click

If you want to use 3 finger gestures, and your touchpad also detects 3 finger tap as middle click, then you may wanna disable the middle click if you want to use 3 finger gestures.. synclient TapButton3=0

1# Disable middle click in order to use 3 finger gestures
2sudo apt install xserver-xorg-input-synaptics
3synclient TapButton3=0

If this doesn’t work, you can disable it in Gnome Tweaks: Tweaks > Keyboard & Mouse > Disable ‘Middle click Paste’

Commands for Gestures

At this point you are ready to start defining your gestures using the GUI

  • If you want the gesture to perform a keystroke, you’d use xdotool
xdotool key super
  • If you want to show a notification, you will use notify-send
notify-send "Swiped up"
GestureFunctionCommand
3 Finger swipe UPExpose (see all open apps)xdotool key super
3 Finger swipe DOWNExpose (see all open apps)xdotool key super
3 Finger swipe LEFTMove to prev workspacexdotool key super+Page_Up
3 Finger swipe RIGHTMove to next workspacexdotool key super+Page_Down

You can find a list of Keyboard shortcuts and the key combinations in Settings > Devices > Keyboard

Multiple monitor displays and Workspaces

I have a 3 monitor setup and by default, switching the Workspace only switches the active screen, not all monitor screens change.. You can disable this behaviour with Gnome Tweaks

1sudo apt install gnome-tweaks

Run Tweaks. Under settings for Workspaces, set Workspaces spans displays

Config files

  • System wide settings: /etc/libinput-gestures.conf
  • User settings: ~/.config/libinput-gestures.conf

The user file overrides the system defaults. The system config file is very nicely commented and you may wanna have a look if you want to understand what’s happening.. Here’s a sample of my config

1# ~/.config/libinput-gestures.conf
2
3# Gestures
4gesture swipe up 3 xdotool key super
5gesture swipe down 3 xdotool key super
6gesture swipe left 3 xdotool key super+Page_Up
7gesture swipe right 3 xdotool key super+Page_Down

What the Gestures GUI does is basically give you a user interface where you can add your gestures and commands for them. Underneath, it just writes to a user’s libinput-gestures.conf file