Bug 99280 - Missing KeyRelease event when releasing two grabbed keys
Summary: Missing KeyRelease event when releasing two grabbed keys
Status: RESOLVED NOTABUG
Alias: None
Product: xorg
Classification: Unclassified
Component: Server/General (show other bugs)
Version: 7.7 (2012.06)
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Xorg Project Team
QA Contact: Xorg Project Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-05 05:34 UTC by Jordan Torbiak
Modified: 2017-03-03 21:37 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
test program to reproduce the issue (2.08 KB, text/x-csrc)
2017-01-05 05:34 UTC, Jordan Torbiak
no flags Details

Description Jordan Torbiak 2017-01-05 05:34:02 UTC
Created attachment 128764 [details]
test program to reproduce the issue

Overview:

If two keys are grabbed using XGrabKey, then held down, then released in quick succession, only the first expected KeyRelease event shows up in the event queue.

If the whole keyboard is grabbed both KeyRelease events are received as expected.

Steps to Reproduce:

See attached program: grabtest.c

Build Date & Hardware:

xorg-server 1.18.4 on Arch Linux on a Macbook Air
xorg-server 1.16.4 on Debian on a desktop PC
Comment 1 Jordan Torbiak 2017-01-05 05:39:16 UTC
I've found one other description of this bug, in the GNOME mailing list archives: https://mail.gnome.org/archives/gnome-devel-list/2008-January/msg00009.html

See "minor glitch with XGrabKey".
Comment 2 Alejandro Castelló 2017-03-03 13:56:38 UTC
I had the same problem and made a detailed bug report as well: https://bugs.freedesktop.org/show_bug.cgi?id=99870

But after re-reading the Xlib Programming Manual https://www.niksula.hut.fi/~jkirma/books/xlib.pdf I found in Chapter 9.4: Grabbing the Keyboard and Pointer, that this is intended behaviour, when a passive grab is activated (XGrabKey'd key is pressed), an active grab takes place, and so every key will report to the grabbing client until the grabbing key is released. The way I found to work around this behaviour is to explicitly call XGrabKeyboard after the first KeyPress event is detected, and count up and down as KeyPresses and KeyReleases come, and thus ungrab the keyboard only after all pressed keys have been released. You might also want to send the unwanted key presses to the focused window.
Comment 3 Jordan Torbiak 2017-03-03 21:37:52 UTC
Thanks for the comment, Alejandro. I guess I didn't read Chapter 9 carefully enough. Your analysis of what's going from 99870 convinces me that the behaviour is reasonable:

- 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


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.