void x11_handle_key_event(XEvent *event, XIC ic, bool filter) { int i; unsigned state, key; uint16_t mod = 0; uint32_t chars[32] = {0}; bool down = event->type == KeyPress; int num = 0; KeySym keysym = 0; if (down && !filter) { char keybuf[32] = {0}; #ifdef X_HAVE_UTF8_STRING Status status = 0; /* XwcLookupString doesn't seem to work. */ num = Xutf8LookupString(ic, &event->xkey, keybuf, ARRAY_SIZE(keybuf), &keysym, &status); /* libc functions need UTF-8 locale to work properly, * which makes mbrtowc a bit impractical. * * Use custom UTF8 -> UTF-32 conversion. */ num = conv_utf8_utf32(chars, ARRAY_SIZE(chars), keybuf, num); #else (void)ic; num = XLookupString(&event->xkey, keybuf, sizeof(keybuf), &keysym, NULL); /* ASCII only. */ for (i = 0; i < num; i++) chars[i] = keybuf[i] & 0x7f; #endif } key = input_keymaps_translate_keysym_to_rk(keysym); state = event->xkey.state; if (state & ShiftMask) mod |= RETROKMOD_SHIFT; if (state & LockMask) mod |= RETROKMOD_CAPSLOCK; if (state & ControlMask) mod |= RETROKMOD_CTRL; if (state & Mod1Mask) mod |= RETROKMOD_ALT; if (state & Mod4Mask) mod |= RETROKMOD_META; if (IsKeypadKey(keysym)) mod |= RETROKMOD_NUMLOCK; input_keyboard_event(down, key, chars[0], mod, RETRO_DEVICE_KEYBOARD); for (i = 1; i < num; i++) input_keyboard_event(down, RETROK_UNKNOWN, chars[i], mod, RETRO_DEVICE_KEYBOARD); }
void x11_handle_key_event(XEvent *event, XIC ic, bool filter) { int i; char keybuf[32] = {0}; uint32_t chars[32] = {0}; bool down = event->type == KeyPress; unsigned key = input_translate_keysym_to_rk(XLookupKeysym(&event->xkey, 0)); int num = 0; if (down && !filter) { KeySym keysym = 0; #ifdef X_HAVE_UTF8_STRING Status status = 0; // XwcLookupString doesn't seem to work. num = Xutf8LookupString(ic, &event->xkey, keybuf, ARRAY_SIZE(keybuf), &keysym, &status); // libc functions need UTF-8 locale to work properly, which makes mbrtowc a bit impractical. // Use custom utf8 -> UTF-32 conversion. num = conv_utf8_utf32(chars, ARRAY_SIZE(chars), keybuf, num); #else (void)ic; num = XLookupString(&event->xkey, keybuf, sizeof(keybuf), &keysym, NULL); // ASCII only. for (i = 0; i < num; i++) chars[i] = keybuf[i] & 0x7f; #endif } unsigned state = event->xkey.state; uint16_t mod = 0; mod |= (state & ShiftMask) ? RETROKMOD_SHIFT : 0; mod |= (state & LockMask) ? RETROKMOD_CAPSLOCK : 0; mod |= (state & ControlMask) ? RETROKMOD_CTRL : 0; mod |= (state & Mod1Mask) ? RETROKMOD_ALT : 0; mod |= (state & Mod4Mask) ? RETROKMOD_META : 0; input_keyboard_event(down, key, chars[0], mod); for (i = 1; i < num; i++) input_keyboard_event(down, RETROK_UNKNOWN, chars[i], mod); }