After switching to Linux, I’ve been missing the smooth three-finger drag experience from macOS. Given that recent Windows laptops have significantly improved touchpad size and responsiveness, I decided it was time to tackle touchpad gestures on Linux.
Research and Selection #
There are basically two approaches to implementation:
- Parsing
libinput debug-eventsoutput and using tools likexdotoolto send keystrokes or mouse clicks. - Calling the
libinputAPI directly, which offers the best performance.
Implementation #
I chose to fork and merge two Rust projects to create a unified solution. One project handles general gestures, and the other focuses on the three-finger drag effect at the API level.
Architecture #
graph TD
A[Touchpad Event] --> B{libinput}
B --> C[ferstar/gestures
Rust Engine]
C --> D{Display Server}
D -- X11 --> E[libxdo API]
D -- Wayland --> F[ydotool daemon]
E --> G[Smooth Drag / Key Stroke]
F --> G
style C fill:#f96,stroke:#333,stroke-width:2px
style G fill:#4ecdc4,stroke:#333,stroke-width:2px
The project is now at v0.8.1, with major improvements including:
- Dual Platform Support: Works on both X11 and Wayland (auto-detection).
- Performance Optimization:
- Direct
libxdoAPI calls for X11 (minimum latency). - Optimized
ydotoolintegration for Wayland with 60 FPS throttling. - Thread pooling to prevent PID exhaustion.
- Regex and config caching for speed.
- Direct
Performance Metrics #
-
Low CPU Usage
- Even under intense three-finger dragging, this implementation uses less than 1% CPU.
- Competing Python or Ruby implementations often exceed 20%.
-
Resource Efficiency
- Memory usage: < 5MB.
- Binary size: < 2MB.
- Zero unnecessary dependencies.
Installation & Usage #
Dependencies #
Ubuntu/Debian:
sudo apt install libudev-dev libinput-dev libxdo-dev xdotool
# For Wayland
sudo apt install ydotoolArch Linux:
sudo pacman -S libinput xdotool
# Wayland
yay -S ydotoolInstall Binary #
Option 1: Pre-compiled Binary (Recommended)
wget https://github.com/ferstar/gestures/releases/latest/download/gestures
chmod +x gestures
sudo mv gestures /usr/local/bin/Option 2: Install via Cargo
cargo install --git https://github.com/ferstar/gestures.gitConfiguration #
The config uses the KDL format. Example:
// Three-finger drag (X11 & Wayland)
gesture "drag" swipe any {
fingers 3
acceleration 1.0 // Drag speed
mouse_up_delay 500 // Delay after lifting fingers (ms)
}
// Four-finger swipe up to switch workspace
gesture "switch-workspace-up" swipe up {
fingers 4
exec "xdotool" "key" "super+Page_Up"
}Running the Program #
Systemd Service #
# Install service file
gestures install-service
# Enable and start
systemctl --user enable --now gesturesCommon Issues #
Permission Denied #
You need to add your user to the input group:
sudo usermod -aG input $USERLinks #
Enjoy!