The libinput input handling library that’s used by both X11 and Wayland based environments on the Linux desktop is preparing to introduce a Lua-based plug-in system. Via Lua scripts it will be possible to modify evdev input events / input device behavior to deal with quirky/broken input devices and better workaround other problems that aren’t currently easily addressable.
After deciding between Rust-based WASM or Lua, libinput developers decided to go with a Lua plug-in system since it’s very easy to sandbox the scripts for ensuring secure input handling. The Lua-based plugin system can modify events between the kernel and where the input is then seen by the libinput library.
Red Hat’s leading Linux input expert Peter Hutter explained in a blog post more about the motivation and need for this plugin system:
“The motivation for this are a few unfixable issues – issues we knew how to fix but we cannot actually implement and/or ship the fixes without breaking other devices. One example for this is the inverted Logitech MX Master 3S horizontal wheel. libinput ships quirks for the USB/Bluetooth connection but not for the Bolt receiver. Unlike the Unifying Receiver the Bolt receiver doesn’t give the kernel sufficient information to know which device is currently connected. Which means our quirks could only apply to the Bolt receiver (and thus any mouse connected to it) – that’s a rather bad idea though, we’d break every other mouse using the same receiver. Another example is an issue with worn out mouse buttons – on that device the behavior was predictable enough but any heuristics would catch a lot of legitimate buttons. That’s fine when you know your mouse is slightly broken and at least it works again. But it’s not something we can ship as a general solution. There are plenty more examples like that – custom pointer deceleration, different disable-while-typing, etc.
libinput has quirks but they are internal API and subject to change without notice at any time. They’re very definitely not for configuring a device and the local quirk file libinput parses is merely to bridge over the time until libinput ships the (hopefully upstreamed) quirk.
So the obvious solution is: let the users fix it themselves. And this is where the plugins come in. They are not full access into libinput, they are closer to a udev-hid-bpf in userspace. Logically they sit between the kernel event devices and libinput: input events are read from the kernel device, passed to the plugins, then passed to libinput. A plugin can look at and modify devices (add/remove buttons for example) and look at and modify the event stream as it comes from the kernel device.”
The pending libinput merge request for introducing the plug-in system includes a Lua script example for swapping the left and right mouse buttons:
The current thinking is that the new plug-in system should be merged for the upcoming libinput 1.29 release.