A Lua script for libinput that debounces mouse scroll wheel input to prevent reverse-scrolling because of broken scroll wheel encoders.
I have a Lamzu Atlantis OG V2 4k. Unfortunately after 2 years of use the scroll wheel is nearly unusable; scrolling causes it to scroll in the opposite direction randomly. I don't have a soldering iron ready and so I can't really replace the encoder, so for now I made this script to fix it in software.
This script will intercept libinput events, and ignore scroll events that are in the opposite direction of the last scroll event and happen between the debounce threshold (100ms seems to work well by default)
Edit the constants at the top of wheel-debounce.lua:
| Variable | Default | Description |
|---|---|---|
MOUSE_NAME |
"Compx LAMZU 4K Receiver" |
The evdev name of your mouse |
DEBOUNCE_TIME_MICROS |
100000 | Debounce window in microseconds (100 ms). Increase this if you still get occasional scrolls in the opposite direction |
To find your mouse's evdev name:
libinput list-devicesThe best place to put wheel-debounce is in /etc/libinput/plugins after substiting your mouse name, since most Wayland compositors should load from there.
To verify that you've correctly selected your mouse name and that the plugin is loaded:
$ journalctl --grep wheel-debounce
and you should see something like:
May 17 15:15:28 ryzen kwin_wayland[47397]: Libinput: Plugin:wheel-debounce.lua - wheel-debounce: Loaded for mouse Compx LAMZU 4K Receiver