Comment

Comment by ComputerGuru

I've never been a fan of Linux on laptops as I feel its DE is just not there yet and prefer to stick to the terminal or the desktop, but I switched my laptop to Linux about six months ago to re-assess and ran into a number of big issues, the most unexpected of which was the poor state of basic touchpad support, not to mention multitouch input support - I genuinely thought it would be a solved problem by now, but I can't blame anyone but myself given that it's open source and anyone is free to contribute a fix (read on).

IMHO the most egregious offender is libinput because everyone and their pet fish seem to be in a massive hurry to drop the proprietary synaptics driver and replace it with libinput; you're not allowed to ask for synaptics support because all distro and project maintainers will lecture you about "upgrading" to libinput which has "superior" touch and multitouch support... except libinput absolutely does not, even if it is theoretically architectured in a way that would enable superior touch/multitouch support someday.

The biggest problem is that the acceleration curves libinput uses are vastly inferior to those that ship out-of-the-box with other operating systems or the proprietary solutions from the manufacturers. When you read about the TrackPoint and the research that went into developing acceleration curves/profiles for input devices [0], it is hubris to think you can throw it all away and expect to still have a superior product.

Anyway, long story short, if you're using a synaptics or synaptics-compatible trackpad, the old synaptics drivers have the best (by far) acceleration profiles and feel the most natural to use, but they are not supported by multitouch plugins for the desktop environments. That's not to say the drivers don't have multitouch support: they do, and they accurately report all motions, but only as raw events.

I wrote this simple program to read the raw input from the synaptics driver and recognize two-, three-, four-, and five-finger tap and swipe gestures from the raw event stream generated by the synaptics driver per the kernel multi-touch protocol [1]. I initially wrote it in an evening after studying the protocol to get just simple back/forward swipe navigations working with the only actually good touchpad drivers for Linux I could find (the synaptics one), and intended to clean it up before throwing it on GitHub for anyone else that might find it interesting but realized I wasn't sufficiently motivated to clean it up anytime soon so decided to just upload it as-is.

sygesture [2] is written in rust and processes the raw MT protocol events generated by the trackpad in real-time to recognize multitouch gestures. Currently it spawns an `evtest` instance rather than opening the input device directly, that was a hack to not have to deal with translating the binary protocol but adds a dependency on the `evtest` utility (should be in your package manager). The path to device is also hard-coded in `main.rs` (and currently it only supports a single input device), but all that is separated from the actual parsing logic because I planned on making that modular from the start, but never got around to it. The mapping of gesture to action is also hard-coded in `main.rs` and isn't currently configurable. (It's all very easy to change even if you don't know rust, as all it does is spawn a program with certain arguments in response to each motion.) I'll throw an MIT license in the repo as soon as I get a chance.

The utility is pretty bulletproof, even though the heuristic is fairly simple (the rationale behind the consensus algorithm is documented in the comments). It's extremely fast (don't have a reliable way to measure lag, but I'm extremely sensitive to it and don't detect any) and has low memory usage (CPU usage is basically zero except for the duration of a gesture, if you're polling at a high-enough frequency to pick up on that).

Something not accounted for at all in the code is support for non-swipe gestures such as pinch-to-zoom and (has anyone ever used it?) "circle gesture" that can be apparently be used for weird things.

[0]: https://www.microsoft.com/buxtoncollection/detail.aspx?id=60

[1]: https://www.kernel.org/doc/html/v4.18/input/multi-touch-prot...

[2]: https://github.com/mqudsi/syngesture

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton