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
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".
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.
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.