Bug 269403 - kglobalaccel_x11 ungrabs wrong X11 keycodes leading to non-functional delete key
Summary: kglobalaccel_x11 ungrabs wrong X11 keycodes leading to non-functional delete key
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kglobalaccel
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Debian stable Linux
: NOR normal
Target Milestone: ---
Assignee: Martin Flöser
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-25 18:27 UTC by Edgar Fuß
Modified: 2018-11-03 12:14 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Remember X11 keycodes/modifiers grabbed for Qt keycodes so as to ungrab the same values (2.60 KB, patch)
2011-03-25 18:27 UTC, Edgar Fuß
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Edgar Fuß 2011-03-25 18:27:32 UTC
Created attachment 58335 [details]
Remember X11 keycodes/modifiers grabbed for Qt keycodes so as to ungrab the same values

Version:           unspecified (using KDE 4.4.5) 
OS:                Linux

This is rather a bug in kdebase-runtime/kglobalaccel, but there's no bugzilla category for that.

It goes like this:
Kglobalaccel wants to register the Print key.
The X11 implementation (kglobalaccel_x11) looks up the X11 keycode for that Qt key, result is 107. It XGrabKey()s 107.
Later, the mapping changes. Kglobalaccel now unregisters all keys in order re-register them later.
Kglobalaccel unregisters the Print Key.
The X11 implementation looks up the X11 keycode, now being 111. It XUngrabKey()s 111.
This leaves 107 (which now is the Delete/,,Entfernen'' Key) still grabbed and thus non-functional.

Since this is a race condition between shortcut registration and keyboard mapping, it seems to appear randomly.

The obvious fix is making kglobalaccel_x11 remember the X11 keycodes/modifiers it grabbed according to Qt kecodes.
This is my first encounter with QLists plus I'm not familiar with C++, but surprisingly, my fix works.

Reproducible: Sometimes

Steps to Reproduce:
In xorg.conf, select a german keyboard model and layout (i.e. pc105, de).
Start xev.
Press ,,Entfernen''.

Actual Results:  
keymapstate event

Expected Results:  
keypressed event

This is the infamous ,,Entfernen-Taste funktionierrt nicht/Delete Key doesn't work'' bug.
Comment 1 Thomas Lübking 2015-10-10 22:37:46 UTC
kglobalaccel needs to catch keyboard mapping events.
Sorry for the extreme late reply but khotkeys bug seem to go completely unnoticed.
Comment 2 Thomas Lübking 2015-10-25 11:22:05 UTC
Possible fix (+ workaround without that the original problem isn't even reached atm.)
https://git.reviewboard.kde.org/r/125786/
Comment 3 Fabian Vogt 2018-11-03 12:14:47 UTC
Git commit 4d28bd4183d20a9bff4f50e88cbb47ffef0ede43 by Fabian Vogt.
Committed on 03/11/2018 at 12:14.
Pushed by fvogt into branch 'master'.

Fix keyboard layout change notifications

Summary:
This rework fixes several issues:
- Qt wasn't informed about XCB_MAPPING_NOTIFY anymore
- With XKB enabled in Qt, X won't send XCB_MAPPING_NOTIFY anymore.
  So listen for XKB events as well.
- Install the event filter before fetching the keysym mapping to
  close a race window
- Use the old mapping for ungrabbing
Related: bug 350816

Test Plan:
Ctrl-Alt-Y global shortcut works even when doing
"setxkbmap us; kglobalaccel5 & sleep 1; setxkbmap de;" while it did not
before. On some systems, this race happened on every login, now it works
reliably.

Reviewers: #frameworks, #plasma, romangg

Reviewed By: #plasma, romangg

Subscribers: romangg, ngraham, anthonyfieroni, kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D16434

M  +1    -1    CMakeLists.txt
M  +1    -1    src/runtime/plugins/CMakeLists.txt
M  +1    -0    src/runtime/plugins/xcb/CMakeLists.txt
M  +55   -21   src/runtime/plugins/xcb/kglobalaccel_x11.cpp
M  +1    -0    src/runtime/plugins/xcb/kglobalaccel_x11.h

https://commits.kde.org/kglobalaccel/4d28bd4183d20a9bff4f50e88cbb47ffef0ede43