x11: Don't panic when using dead keys #432
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #366
I was originally planning to fix this by rewriting keyboard handling to use XInput2+XKB+libxkbcommon, and I do indeed have a fully functional implementation of that. However, I never managed to figure out how to handle IME, and I could seldom find the motivation to try to conquer yet another dimension of X11 eroticism. That only got worse when I discovered older libxkbcommon versions, which are still in use, don't support compose sequences. As a result, this fairly important issue has gone unresolved for much longer than I ever intended.
This PR fixes the issue using a bold new solution: a single
if
that checks if the keycode is non-zero. AKeyPress
with a keycode of 0 is received at the end of compose sequences and pre-edit sequences, which has our desired UTF8 string associated with it. The panic was simply the result of trying to send aKeyboardInput
event for this input, which involved trying to calculate a scancode for this nonexistent key. So, now we just don't try to send aKeyboardInput
event in that case, and just like that, everything works.I should note that the behavior of the X11 backend isn't consistent with the expectations laid out in #343. While I was able to easily achieve that behavior using XInput2, vanilla X11 seems less cooperative. For individual keys pressed during a compose/pre-edit sequence, X11 only generates
KeyRelease
events, so the user receivesKeyboardInput
events for key releases with no corresponding press events. In the case of compose, theReceivedCharacter
is sent to the user before theKeyboardInput
for the release of the final key in the sequence. For pre-editing, aKeyboardInput
for the release of the return key is sent after theReceivedCharacter
.