wayland: Enforce text capitalization manually, for remapped keymods

main
Ethan Lee 2022-03-25 01:36:39 -04:00
parent a75c6150e0
commit 6d9ca92626
1 changed files with 20 additions and 0 deletions

View File

@ -910,6 +910,8 @@ keyboard_input_get_text(char text[8], const struct SDL_WaylandInput *input, uint
SDL_WindowData *window = input->keyboard_focus;
const xkb_keysym_t *syms;
xkb_keysym_t sym;
SDL_Keymod mod;
SDL_bool caps;
if (!window || window->keyboard_device != input || !input->xkb.state) {
return SDL_FALSE;
@ -921,6 +923,24 @@ keyboard_input_get_text(char text[8], const struct SDL_WaylandInput *input, uint
}
sym = syms[0];
/* Wayland is actually pretty cool and sends key codes based on presumed
* caps lock state, problem is that it isn't totally accurate if the key
* has been remapped, so we have to force caps for our purposes.
* -flibit
*/
mod = SDL_GetModState();
caps = (
/* Caps lock without shift... */
((mod & KMOD_CAPS) && !(mod & KMOD_SHIFT)) ||
/* No caps lock with shift... */
(!(mod & KMOD_CAPS) && (mod & KMOD_SHIFT))
);
if (caps) {
sym = toupper(sym);
} else {
sym = tolower(sym);
}
#ifdef SDL_USE_IME
if (SDL_IME_ProcessKeyEvent(sym, key + 8)) {
*handled_by_ime = SDL_TRUE;