SDL_SetTextInputRect() has been renamed to SDL_SetTextInputArea()

The new function includes the cursor position so IME UI elements can be placed relative to the cursor, as well as having the whole text area available so on-screen keyboards can avoid it.
This commit is contained in:
Sam Lantinga
2024-06-28 13:17:04 -07:00
parent e324c7d692
commit bdd531986b
35 changed files with 201 additions and 148 deletions

View File

@@ -211,7 +211,7 @@ static DBusHandlerResult DBus_MessageFilter(DBusConnection *conn, DBusMessage *m
SDL_SendEditingText("", 0, 0);
}
SDL_Fcitx_UpdateTextRect(SDL_GetKeyboardFocus());
SDL_Fcitx_UpdateTextInputArea(SDL_GetKeyboardFocus());
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -390,7 +390,7 @@ SDL_bool SDL_Fcitx_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
DBUS_TYPE_UINT32, &keysym, DBUS_TYPE_UINT32, &keycode, DBUS_TYPE_UINT32, &mod_state, DBUS_TYPE_BOOLEAN, &is_release, DBUS_TYPE_UINT32, &event_time, DBUS_TYPE_INVALID,
DBUS_TYPE_BOOLEAN, &handled, DBUS_TYPE_INVALID)) {
if (handled) {
SDL_Fcitx_UpdateTextRect(SDL_GetKeyboardFocus());
SDL_Fcitx_UpdateTextInputArea(SDL_GetKeyboardFocus());
return SDL_TRUE;
}
}
@@ -398,7 +398,7 @@ SDL_bool SDL_Fcitx_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
return SDL_FALSE;
}
void SDL_Fcitx_UpdateTextRect(SDL_Window *window)
void SDL_Fcitx_UpdateTextInputArea(SDL_Window *window)
{
int x = 0, y = 0;
SDL_Rect *cursor = &fcitx_client.cursor_rect;
@@ -407,7 +407,11 @@ void SDL_Fcitx_UpdateTextRect(SDL_Window *window)
return;
}
SDL_copyp(cursor, &window->text_input_rect);
// We'll use a square at the text input cursor location for the cursor_rect
cursor->x = window->text_input_rect.x + window->text_input_cursor;
cursor->y = window->text_input_rect.x;
cursor->w = window->text_input_rect.h;
cursor->h = window->text_input_rect.h;
SDL_GetWindowPosition(window, &x, &y);

View File

@@ -29,7 +29,7 @@ extern void SDL_Fcitx_Quit(void);
extern void SDL_Fcitx_SetFocus(SDL_bool focused);
extern void SDL_Fcitx_Reset(void);
extern SDL_bool SDL_Fcitx_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state);
extern void SDL_Fcitx_UpdateTextRect(SDL_Window *window);
extern void SDL_Fcitx_UpdateTextInputArea(SDL_Window *window);
extern void SDL_Fcitx_PumpEvents(void);
#endif /* SDL_fcitx_h_ */

View File

@@ -261,7 +261,7 @@ static DBusHandlerResult IBus_MessageHandler(DBusConnection *conn, DBusMessage *
}
}
SDL_IBus_UpdateTextRect(SDL_GetKeyboardFocus());
SDL_IBus_UpdateTextInputArea(SDL_GetKeyboardFocus());
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -483,7 +483,7 @@ static SDL_bool IBus_SetupConnection(SDL_DBusContext *dbus, const char *addr)
SDL_Window *window = SDL_GetKeyboardFocus();
if (SDL_TextInputActive(window)) {
SDL_IBus_SetFocus(SDL_TRUE);
SDL_IBus_UpdateTextRect(window);
SDL_IBus_UpdateTextInputArea(window);
} else {
SDL_IBus_SetFocus(SDL_FALSE);
}
@@ -674,12 +674,12 @@ SDL_bool SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
}
}
SDL_IBus_UpdateTextRect(SDL_GetKeyboardFocus());
SDL_IBus_UpdateTextInputArea(SDL_GetKeyboardFocus());
return (result != 0);
}
void SDL_IBus_UpdateTextRect(SDL_Window *window)
void SDL_IBus_UpdateTextInputArea(SDL_Window *window)
{
int x = 0, y = 0;
SDL_DBusContext *dbus;
@@ -688,7 +688,11 @@ void SDL_IBus_UpdateTextRect(SDL_Window *window)
return;
}
SDL_copyp(&ibus_cursor_rect, &window->text_input_rect);
// We'll use a square at the text input cursor location for the ibus_cursor
ibus_cursor_rect.x = window->text_input_rect.x + window->text_input_cursor;
ibus_cursor_rect.y = window->text_input_rect.x;
ibus_cursor_rect.w = window->text_input_rect.h;
ibus_cursor_rect.h = window->text_input_rect.h;
SDL_GetWindowPosition(window, &x, &y);

View File

@@ -44,7 +44,7 @@ extern SDL_bool SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 st
/* Update the position of IBus' candidate list. If rect is NULL then this will
just reposition it relative to the focused window's new position. */
extern void SDL_IBus_UpdateTextRect(SDL_Window *window);
extern void SDL_IBus_UpdateTextInputArea(SDL_Window *window);
/* Checks DBus for new IBus events, and calls SDL_SendKeyboardText /
SDL_SendEditingText for each event it finds */

View File

@@ -29,7 +29,7 @@ typedef void (*SDL_IME_Quit_t)(void);
typedef void (*SDL_IME_SetFocus_t)(SDL_bool);
typedef void (*SDL_IME_Reset_t)(void);
typedef SDL_bool (*SDL_IME_ProcessKeyEvent_t)(Uint32, Uint32, Uint8 state);
typedef void (*SDL_IME_UpdateTextRect_t)(SDL_Window *window);
typedef void (*SDL_IME_UpdateTextInputArea_t)(SDL_Window *window);
typedef void (*SDL_IME_PumpEvents_t)(void);
static SDL_IME_Init_t SDL_IME_Init_Real = NULL;
@@ -37,7 +37,7 @@ static SDL_IME_Quit_t SDL_IME_Quit_Real = NULL;
static SDL_IME_SetFocus_t SDL_IME_SetFocus_Real = NULL;
static SDL_IME_Reset_t SDL_IME_Reset_Real = NULL;
static SDL_IME_ProcessKeyEvent_t SDL_IME_ProcessKeyEvent_Real = NULL;
static SDL_IME_UpdateTextRect_t SDL_IME_UpdateTextRect_Real = NULL;
static SDL_IME_UpdateTextInputArea_t SDL_IME_UpdateTextInputArea_Real = NULL;
static SDL_IME_PumpEvents_t SDL_IME_PumpEvents_Real = NULL;
static void InitIME(void)
@@ -64,7 +64,7 @@ static void InitIME(void)
SDL_IME_SetFocus_Real = SDL_Fcitx_SetFocus;
SDL_IME_Reset_Real = SDL_Fcitx_Reset;
SDL_IME_ProcessKeyEvent_Real = SDL_Fcitx_ProcessKeyEvent;
SDL_IME_UpdateTextRect_Real = SDL_Fcitx_UpdateTextRect;
SDL_IME_UpdateTextInputArea_Real = SDL_Fcitx_UpdateTextInputArea;
SDL_IME_PumpEvents_Real = SDL_Fcitx_PumpEvents;
}
#endif /* HAVE_FCITX */
@@ -77,7 +77,7 @@ static void InitIME(void)
SDL_IME_SetFocus_Real = SDL_IBus_SetFocus;
SDL_IME_Reset_Real = SDL_IBus_Reset;
SDL_IME_ProcessKeyEvent_Real = SDL_IBus_ProcessKeyEvent;
SDL_IME_UpdateTextRect_Real = SDL_IBus_UpdateTextRect;
SDL_IME_UpdateTextInputArea_Real = SDL_IBus_UpdateTextInputArea;
SDL_IME_PumpEvents_Real = SDL_IBus_PumpEvents;
}
#endif /* HAVE_IBUS_IBUS_H */
@@ -98,7 +98,7 @@ SDL_bool SDL_IME_Init(void)
SDL_IME_SetFocus_Real = NULL;
SDL_IME_Reset_Real = NULL;
SDL_IME_ProcessKeyEvent_Real = NULL;
SDL_IME_UpdateTextRect_Real = NULL;
SDL_IME_UpdateTextInputArea_Real = NULL;
SDL_IME_PumpEvents_Real = NULL;
}
@@ -135,10 +135,10 @@ SDL_bool SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
return SDL_FALSE;
}
void SDL_IME_UpdateTextRect(SDL_Window *window)
void SDL_IME_UpdateTextInputArea(SDL_Window *window)
{
if (SDL_IME_UpdateTextRect_Real) {
SDL_IME_UpdateTextRect_Real(window);
if (SDL_IME_UpdateTextInputArea_Real) {
SDL_IME_UpdateTextInputArea_Real(window);
}
}

View File

@@ -29,7 +29,7 @@ extern void SDL_IME_Quit(void);
extern void SDL_IME_SetFocus(SDL_bool focused);
extern void SDL_IME_Reset(void);
extern SDL_bool SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state);
extern void SDL_IME_UpdateTextRect(SDL_Window *window);
extern void SDL_IME_UpdateTextInputArea(SDL_Window *window);
extern void SDL_IME_PumpEvents(void);
#endif /* SDL_ime_h_ */