The text input state has been changed to be window-specific.

SDL_StartTextInput(), SDL_StopTextInput(), SDL_TextInputActive(), SDL_ClearComposition(), and SDL_SetTextInputRect() all now take a window parameter.

This change also fixes IME candidate positioning when SDL_SetTextInputRect() is called before SDL_StartTextInput(), as is recommended in the documentation.
This commit is contained in:
Sam Lantinga
2024-06-22 06:16:19 -07:00
parent 258ee05655
commit 76631a0978
48 changed files with 361 additions and 339 deletions

View File

@@ -261,7 +261,7 @@ static DBusHandlerResult IBus_MessageHandler(DBusConnection *conn, DBusMessage *
}
}
SDL_IBus_UpdateTextRect(NULL);
SDL_IBus_UpdateTextRect(SDL_GetKeyboardFocus());
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -480,9 +480,13 @@ static SDL_bool IBus_SetupConnection(SDL_DBusContext *dbus, const char *addr)
dbus->connection_flush(ibus_conn);
}
SDL_IBus_SetFocus(SDL_GetKeyboardFocus() != NULL);
SDL_IBus_UpdateTextRect(NULL);
SDL_Window *window = SDL_GetKeyboardFocus();
if (SDL_TextInputActive(window)) {
SDL_IBus_SetFocus(SDL_TRUE);
SDL_IBus_UpdateTextRect(window);
} else {
SDL_IBus_SetFocus(SDL_FALSE);
}
return result;
}
@@ -670,31 +674,27 @@ SDL_bool SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
}
}
SDL_IBus_UpdateTextRect(NULL);
SDL_IBus_UpdateTextRect(SDL_GetKeyboardFocus());
return (result != 0);
}
void SDL_IBus_UpdateTextRect(const SDL_Rect *rect)
void SDL_IBus_UpdateTextRect(SDL_Window *window)
{
SDL_Window *focused_win;
int x = 0, y = 0;
SDL_DBusContext *dbus;
if (rect) {
SDL_memcpy(&ibus_cursor_rect, rect, sizeof(ibus_cursor_rect));
}
focused_win = SDL_GetKeyboardFocus();
if (!focused_win) {
if (!window) {
return;
}
SDL_GetWindowPosition(focused_win, &x, &y);
SDL_copyp(&ibus_cursor_rect, &window->text_input_rect);
SDL_GetWindowPosition(window, &x, &y);
#ifdef SDL_VIDEO_DRIVER_X11
{
SDL_PropertiesID props = SDL_GetWindowProperties(focused_win);
SDL_PropertiesID props = SDL_GetWindowProperties(window);
Display *x_disp = (Display *)SDL_GetProperty(props, SDL_PROP_WINDOW_X11_DISPLAY_POINTER, NULL);
int x_screen = SDL_GetNumberProperty(props, SDL_PROP_WINDOW_X11_SCREEN_NUMBER, 0);
Window x_win = SDL_GetNumberProperty(props, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0);