Unintended behavior in apps due to missing rate limiting / deduplication of mouse click events
Context
Something I noticed with some of my Logitech mice, especially as they get older (or the users get older, leading to some imprecision in the force applied and movements), on the Wayland GNOME session in Fedora 39 (and earlier) is that I'm experiencing a lot of strange duplicated events going on.
I suspect this might just be that there is no rate limiting / deduplication going on, or that it is somehow not working correctly with some mice.
I'm observing this with libinput-1.24.0-1.fc39.x86_64 currently, but it happened in previous versions too.
Symptoms
In practice, this means that middle-clicking to open tabs in a web browser (such as Firefox) often leads to the same tab being opened multiple times in a row, or middle-clicking to close a tab might close multiple tabs at once. I think I have also seen the problem with left-clicking/right-clicking too, sometimes.
I don't recall this being a problem before with any of my devices, so I'm thinking maybe this is a libinput/Wayland-specific issue that was not present in the Xorg days.
Reproduction steps
The easiest way to reproduce this is by middle-clicking links in Firefox, or in Epiphany.
Particularly, to really stress-test this, you can middle-click and hold (i.e. not release the scroll wheel's click) over a link, maybe with some slight pressure variation, and you will quickly end up with half a dozen tabs opened within a fraction of a second.
Alternatively, in a similar way, you can reproduce this by middle-clicking (and holding) folders in Nautilus' ListView to open in a new tab, but you will have to make sure you have at least 2 tabs open first, because Nautilus will "shift" its listview UI downwards when opening the first new tab, making you lose your target under the mouse cursor.
Potential solution
There's a physical limit to how fast a human can intently click/unclick/reclick a mouse button (vs press-and-hold which would be a separate event), I doubt people typically click faster than, say, 50-100ms when doubleclicking is typically 300-500ms (I think?)...
Therefore, my guess is that libinput (or whatever handles mouse click events in Wayland) should rate-limit and de-duplicate physical click events that are too fast to be considered "intended by the user".
The mouse I am using with my laptop as I am typing this, where the problem easily occurs, is:
Bus 003 Device 012: ID 046d:c03d Logitech, Inc. M-BT96a Pilot Optical Mouse