Bug 101796 - Keys can get stuck permanently when grabbing keyboard with evdev
Summary: Keys can get stuck permanently when grabbing keyboard with evdev
Status: RESOLVED FIXED
Alias: None
Product: Wayland
Classification: Unclassified
Component: libinput (show other bugs)
Version: unspecified
Hardware: All Linux (All)
: medium normal
Assignee: Wayland bug list
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-15 20:03 UTC by noah.bergbauer
Modified: 2017-07-24 23:50 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Description noah.bergbauer 2017-07-15 20:03:13 UTC
The logic in evdev.c (https://github.com/wayland-project/libinput/blob/688142c8a22c00cfe7b9dec6a71e935b899d8b65/src/evdev.c#L167-L169) remembers how many times a key is pressed simultaneously and only emits KEY_UP events when this counter is incremented to 1 and KEY_DOWN when it is decremented to 0.

This is problematic as key release events might get dropped, for example if the keyboard is exclusively grabbed by evdev's EVIOCGRAB while a key is pressed.

This issue is easily reproducible by launching one instance of libinput-debug-events (or any libinput-based application that reads keyboard input) and then running this in another terminal:
libinput-debug-events --device /path/to/keyboard --grab & (sleep 1 ; killall libinput-debug-events)

Because you submit the command by pressing the Enter key and libinput-debug-events launches fast enough, the release event for your Enter key happens after the device is grabbed, so the first instance of libinput-debug-events will not receive it. Because of this bug, the Enter key is now permanently stuck there as it is always pressed either 1 or 2 times, so libinput will never send any key events for it again.

(Please note that running this test inside any libinput-based desktop environment (xf86-input-libinput or Wayland) obviously triggers the same bug and may force you to restart your window manager.)



In other implementations (xf86-input-evdev, Microsoft Windows), missing release events are handled gracefully: As pressing an already held key indicates a missing release event, they just ignore this, so a subsequent key release event actually releases the key.
Comment 2 Peter Hutterer 2017-07-24 23:49:34 UTC
commit d950a73077c38efce28671548a1610270790b2a4
Author: Peter Hutterer <peter.hutterer@who-t.net>
Date:   Tue Jul 25 09:38:46 2017 +1000

    lid: disable all types but EV_SYN and EV_SW
Comment 3 Peter Hutterer 2017-07-24 23:50:10 UTC
sorry, that was the wrong copy-paste. Commit that fixed it is:

commit 399c50dbeb9dd96ee959dc270bcb9f4be7ab6710
Author: Peter Hutterer <peter.hutterer@who-t.net>
Date:   Tue Jul 18 16:12:27 2017 +1000

    evdev: recover from a lost button count


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.