We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2071

Summary: Dead Keys don't generate events on X11
Product: SDL Reporter: Daniel Gibson <metalcaedes>
Component: eventsAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: drewb, icculus, metalcaedes
Version: HG 2.0Keywords: target-2.0.4
Hardware: x86_64   
OS: Linux   
Attachments: Patch to generate SDL_KEYDOWN/UP events for dead keys
Small test-program that prints key events

Description Daniel Gibson 2013-08-28 21:37:03 UTC
Created attachment 1310 [details]
Patch to generate SDL_KEYDOWN/UP events for dead keys

Pressing dead keys (e.g. ^ or `) on Linux/X11 doesn't generate SDL_KEYDOWN events, pressing another key afterwards (like for composition) just generates a "The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> X11 KeyCode 0 (-8), X11 KeySym 0x0 ((null))." message.

This is because XFilterEvent() (at the beginning of X11_DispatchEvent() in SDL_x11events.c) returns True for dead keys, so those events are discarded. 
I also found out that XFilterEvents actually changes the events.
(Some more information can be found at http://forums.libsdl.org/viewtopic.php?p=38900#38900 - note that for some reason the forum transformed "â" to "â")


I wrote a patch that in case of KeyPress/KeyRelease events saves the type and the KeyCode and, if XFilterEvent() decides to filter the event, calls SDL_SendKeyboardKey() accordingly.

This yields a similar behavior like SDL2 on Windows: There is a SDL_TEXTINPUT event with the composed char, but there are also two SDL_KEYDOWN events for the keys.

One small issue is that is that the SDL Keycode isn't the same as with the corresponding nodeadkey layout, but seems to be a direct translation of the Scancode.
E.g. on my (german) layout, The ^ key (below Esc) generates a SDL_SCANCODE_GRAVE (`), but a ^ Keycode without dead keys. With dead keys enabled it generates the same Scancode, but a ` Keycode. 
Probably X11 doesn't provide a proper mapping for that key because it's dead anyway, so the default is used.
I think that this is acceptable though and better than no key event at all (like it's the case right now).
Comment 1 Daniel Gibson 2013-08-28 21:38:31 UTC
Created attachment 1311 [details]
Small test-program that prints key events
Comment 2 Daniel Gibson 2014-01-15 20:15:11 UTC
A variant of this patch has been merged in the meantime: https://hg.libsdl.org/SDL/rev/713c6a333c33
So this can be closed.
Comment 3 Daniel Gibson 2015-02-09 02:53:16 UTC
This bug happens again in latest hg, because the fix was reverted as it caused https://bugzilla.libsdl.org/show_bug.cgi?id=2526
Comment 4 Ryan C. Gordon 2015-12-31 05:01:21 UTC
*** Bug 3076 has been marked as a duplicate of this bug. ***
Comment 5 Sam Lantinga 2016-10-01 21:11:44 UTC
Fixed by Alex's patch in bug 3136
https://hg.libsdl.org/SDL/rev/2f18ea79bc03
Comment 6 Sam Lantinga 2016-10-01 21:11:53 UTC
Fixed!