Skip to content

Commit f30859d

Browse files
committed
Merge pull request godotengine#110635 from WhalesState/x11-input
X11 input: prevent non-printable keys from producing empty strings
2 parents 3315dd3 + 1b697af commit f30859d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

platform/linuxbsd/x11/display_server_x11.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3837,12 +3837,21 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
38373837
XLookupString(xkeyevent, str, 255, &keysym_unicode, nullptr);
38383838
XLookupString(&xkeyevent_no_mod, nullptr, 0, &keysym_keycode, nullptr);
38393839

3840+
// Get a normalized keysym (ignoring modifiers like Shift/Ctrl).
38403841
String keysym;
38413842
#ifdef XKB_ENABLED
38423843
if (xkb_loaded_v08p) {
38433844
KeySym keysym_unicode_nm = 0; // keysym used to find unicode
38443845
XLookupString(&xkeyevent_no_mod, nullptr, 0, &keysym_unicode_nm, nullptr);
3845-
keysym = String::chr(xkb_keysym_to_utf32(xkb_keysym_to_upper(keysym_unicode_nm)));
3846+
3847+
// Unicode codepoint corresponding to the pressed key.
3848+
// Printable keys (letters, numbers, symbols) return a valid codepoint.
3849+
u_int32_t unicode_cp = xkb_keysym_to_utf32(xkb_keysym_to_upper(keysym_unicode_nm));
3850+
3851+
// Non-printable keys (Ctrl, Home, CapsLock, F1, etc.) return 0, so we skip them.
3852+
if (unicode_cp != 0) {
3853+
keysym = String::chr(unicode_cp);
3854+
}
38463855
}
38473856
#endif
38483857

0 commit comments

Comments
 (0)