mirror of
https://github.com/encounter/SDL.git
synced 2025-12-21 10:49:12 +00:00
Send key release event to input method. (#5281)
Co-authored-by: Ethan Lee <flibitijibibo@gmail.com>
This commit is contained in:
@@ -921,7 +921,7 @@ keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
keyboard_input_get_text(char text[8], const struct SDL_WaylandInput *input, uint32_t key, SDL_bool *handled_by_ime)
|
||||
keyboard_input_get_text(char text[8], const struct SDL_WaylandInput *input, uint32_t key, Uint8 state, SDL_bool *handled_by_ime)
|
||||
{
|
||||
SDL_WindowData *window = input->keyboard_focus;
|
||||
const xkb_keysym_t *syms;
|
||||
@@ -938,12 +938,16 @@ keyboard_input_get_text(char text[8], const struct SDL_WaylandInput *input, uint
|
||||
sym = syms[0];
|
||||
|
||||
#ifdef SDL_USE_IME
|
||||
if (SDL_IME_ProcessKeyEvent(sym, key + 8)) {
|
||||
if (SDL_IME_ProcessKeyEvent(sym, key + 8, state)) {
|
||||
*handled_by_ime = SDL_TRUE;
|
||||
return SDL_TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (state == SDL_RELEASED) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
if (input->xkb.compose_state && WAYLAND_xkb_compose_state_feed(input->xkb.compose_state, sym) == XKB_COMPOSE_FEED_ACCEPTED) {
|
||||
switch(WAYLAND_xkb_compose_state_get_status(input->xkb.compose_state)) {
|
||||
case XKB_COMPOSE_COMPOSING:
|
||||
@@ -977,7 +981,7 @@ keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
|
||||
SDL_bool handled_by_ime = SDL_FALSE;
|
||||
|
||||
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
||||
has_text = keyboard_input_get_text(text, input, key, &handled_by_ime);
|
||||
has_text = keyboard_input_get_text(text, input, key, SDL_PRESSED, &handled_by_ime);
|
||||
} else {
|
||||
if (keyboard_repeat_is_set(&input->keyboard_repeat)) {
|
||||
// Send any due key repeat events before stopping the repeat and generating the key up event
|
||||
@@ -987,6 +991,7 @@ keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
|
||||
keyboard_repeat_handle(&input->keyboard_repeat, time - input->keyboard_repeat.wl_press_time);
|
||||
keyboard_repeat_clear(&input->keyboard_repeat);
|
||||
}
|
||||
keyboard_input_get_text(text, input, key, SDL_RELEASED, &handled_by_ime);
|
||||
}
|
||||
|
||||
if (!handled_by_ime && key < SDL_arraysize(xfree86_scancode_table2)) {
|
||||
|
||||
@@ -996,8 +996,9 @@ X11_DispatchEvent(_THIS, XEvent *xevent)
|
||||
}
|
||||
break;
|
||||
|
||||
/* Key press? */
|
||||
case KeyPress:{
|
||||
/* Key press/release? */
|
||||
case KeyPress:
|
||||
case KeyRelease: {
|
||||
KeyCode keycode = xevent->xkey.keycode;
|
||||
KeySym keysym = NoSymbol;
|
||||
char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
|
||||
@@ -1005,7 +1006,7 @@ X11_DispatchEvent(_THIS, XEvent *xevent)
|
||||
SDL_bool handled_by_ime = SDL_FALSE;
|
||||
|
||||
#ifdef DEBUG_XEVENTS
|
||||
printf("window %p: KeyPress (X11 keycode = 0x%X)\n", data, xevent->xkey.keycode);
|
||||
printf("window %p: %s (X11 keycode = 0x%X)\n" data, (xevent->type == KeyPress ? "KeyPress" : "KeyRelease"), xevent->xkey.keycode);
|
||||
#endif
|
||||
#if 1
|
||||
if (videodata->key_layout[keycode] == SDL_SCANCODE_UNKNOWN && keycode) {
|
||||
@@ -1021,7 +1022,7 @@ X11_DispatchEvent(_THIS, XEvent *xevent)
|
||||
/* */
|
||||
SDL_zeroa(text);
|
||||
#ifdef X_HAVE_UTF8_STRING
|
||||
if (data->ic) {
|
||||
if (data->ic && xevent->type == KeyPress) {
|
||||
X11_Xutf8LookupString(data->ic, &xevent->xkey, text, sizeof(text),
|
||||
&keysym, &status);
|
||||
} else {
|
||||
@@ -1033,35 +1034,30 @@ X11_DispatchEvent(_THIS, XEvent *xevent)
|
||||
|
||||
#ifdef SDL_USE_IME
|
||||
if(SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE){
|
||||
handled_by_ime = SDL_IME_ProcessKeyEvent(keysym, keycode);
|
||||
handled_by_ime = SDL_IME_ProcessKeyEvent(keysym, keycode, (xevent->type == KeyPress ? SDL_PRESSED : SDL_RELEASED));
|
||||
}
|
||||
#endif
|
||||
if (!handled_by_ime) {
|
||||
/* Don't send the key if it looks like a duplicate of a filtered key sent by an IME */
|
||||
if (xevent->xkey.keycode != videodata->filter_code || xevent->xkey.time != videodata->filter_time) {
|
||||
SDL_SendKeyboardKey(SDL_PRESSED, videodata->key_layout[keycode]);
|
||||
}
|
||||
if(*text) {
|
||||
SDL_SendKeyboardText(text);
|
||||
if (xevent->type == KeyPress) {
|
||||
/* Don't send the key if it looks like a duplicate of a filtered key sent by an IME */
|
||||
if (xevent->xkey.keycode != videodata->filter_code || xevent->xkey.time != videodata->filter_time) {
|
||||
SDL_SendKeyboardKey(SDL_PRESSED, videodata->key_layout[keycode]);
|
||||
}
|
||||
if(*text) {
|
||||
SDL_SendKeyboardText(text);
|
||||
}
|
||||
} else {
|
||||
if (X11_KeyRepeat(display, xevent)) {
|
||||
/* We're about to get a repeated key down, ignore the key up */
|
||||
break;
|
||||
}
|
||||
SDL_SendKeyboardKey(SDL_RELEASED, videodata->key_layout[keycode]);
|
||||
}
|
||||
}
|
||||
|
||||
X11_UpdateUserTime(data, xevent->xkey.time);
|
||||
}
|
||||
break;
|
||||
|
||||
/* Key release? */
|
||||
case KeyRelease:{
|
||||
KeyCode keycode = xevent->xkey.keycode;
|
||||
|
||||
#ifdef DEBUG_XEVENTS
|
||||
printf("window %p: KeyRelease (X11 keycode = 0x%X)\n", data, xevent->xkey.keycode);
|
||||
#endif
|
||||
if (X11_KeyRepeat(display, xevent)) {
|
||||
/* We're about to get a repeated key down, ignore the key up */
|
||||
break;
|
||||
if (xevent->type == KeyPress) {
|
||||
X11_UpdateUserTime(data, xevent->xkey.time);
|
||||
}
|
||||
SDL_SendKeyboardKey(SDL_RELEASED, videodata->key_layout[keycode]);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user