Bug 99870 - Inconsistent behaviour of XGrabKey on mutiple simultaneous presses
Summary: Inconsistent behaviour of XGrabKey on mutiple simultaneous presses
Status: RESOLVED NOTABUG
Alias: None
Product: xorg
Classification: Unclassified
Component: Server/Input/Core (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium minor
Assignee: Xorg Project Team
QA Contact: Xorg Project Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-20 14:58 UTC by Alejandro Castelló
Modified: 2017-03-03 10:16 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Alejandro Castelló 2017-02-20 14:58:53 UTC
After performing several passive grabs, say grab the 1 and 2 keys, holding both keys down before releasing either of them has inconsistent event reports. KeyPress events are reported correctly but KeyRelease ones depend on the order in which you release the keys:

press 1: a KeyPress event is reported
press 2: a KeyPress event is reported
release 1: a KeyRelease event is reported 
release 2: no KeyRelease event is reported to the grabbing client: the key release falls through to whatever window has the focus (tested with xev)

now in this other order, it behaves differently (and seemingly the correct way):

press 1: a KeyPress event is reported
press 2: a KeyPress event is reported
release 2: a KeyRelease event is reported
release 1: a KeyRelease event is reported


there's a similar occurrence when grabbing a third key:

press 1: a KeyPress event is reported
press 2: a KeyPress event is reported
press 3: a KeyPress event is reported
release 1: a KeyRelease event is reported
release 2: no event is reported
release 3: no event is reported

press 1: a KeyPress is reported
press 2: idem
press 3: idem
release 2: a KeyRelease is reported
release 1: idem
release 3: no event is reported

press 1: a KeyPress is reported
press 2: idem
press 3: idem
release 2: a KeyRelease is reported
release 3: idem
release 1: idem


it seems like after releasing the first key that was pressed, the server stops checking for releases. the only way in which every single release is reported is that in which the first key to be pressed was the last to be released: any keys other than the first can be released in any order and it still works properly.

this has been tested on the i3 window manager and the tinywm, same results, it's also irrespective of whether it's the root window or any other window that is grabbed.
Comment 1 Alejandro Castelló 2017-03-01 08:20:24 UTC
I've been doing tests with a fresh compilation of xserver (and required modules). I've found out that what happens is that after `activateKeyboardGrab' is called (dix/events.c), every KeyPress/KeyRelease event, regardless of whether its keycode has been XKeyGrab'd, is reported to the grabbing client, and as soon as `deactivateKeyboardGrab' is called, any key pressed before the deactivation doesn't produce a KeyRelease.

I'll be joining the mailing list to discuss if these are intended behaviours:

- passive core key grabs turn into full keyboard grabs after activated (non XGrabKey'd keys get reported until the grabbed key is released)

- after releasing the originally grabbed key the keyboard grab is deactivated even if another XGrabKey'd key has been pressed

- after deactivating the grab, any pending keyrelease event is thrown out instead of sent to either the grabbing client or the focus window
Comment 2 Alejandro Castelló 2017-03-03 10:16:26 UTC
Marking this as solved, after reading Chapter 9.4 of the Xlib Programming Manual, I've seen that it is noted that passive grabs turn into active grabs until KeyRelease. The bad behaviour described in my previous posts can be circumvented with calls to GrabKeyboard and XSendEvent.


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.