Skip to content

Draft: backends/libinput: Ignore redundant events for pointer buttons when pressed/released on multiple devices

Bruno Filipe requested to merge bfilipekde/kwin:kwin_libinput_button_fix into master

Currently, KWin's libinput backend doesn't follow the following behavior, taken from https://wayland.freedesktop.org/libinput/doc/latest/seats.html:

  • if the same button is pressed on different devices, the button should only be considered logically pressed once.
  • if the same button is released on one device, the button should be considered logically down if still down on another device.

libinput provides a function to aid with the above: libinput_event_pointer_get_seat_button_count(), and this small patch uses that to check for those two conditions and then drop the event if it violates them.

Other compositors using libinput do similar checks, and that's also the behavior on KWin X11, but not in KWin Wayland.

This attempts to fix https://bugs.kde.org/show_bug.cgi?id=486034, which I reported week ago.

About the code, sorry if I miss something, not a KDE or C/C++ programmer. Regarding the patch, it works fine but for now it only implements the logic for mouse clicks, although it might be worth looking if it makes sense to do it for keyboard presses also.

I'm not 100% sure the Connection Adaptor event loop is the best place to drop the event, or if it makes more sense to handle it later in the pipeline. I decided to do it earlier, because it didnt make much sense to emit "pointerButtonChanged(...)" only to drop it later. The only "downside" to dropping it earlier is that we will sometimes end up calling libinput_event_pointer_get_button_state() twice. Once here, and once in https://invent.kde.org/plasma/kwin/-/blob/master/src/backends/libinput/events.cpp?ref_type=heads#L179

I'm open to suggestions and feedback, this is my first contribution to KDE.

References:

Merge request reports