From 6443c75edaa7dd3d3c152569b87defda44fe8115 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 25 Mar 2024 12:55:49 -0700 Subject: [PATCH] Removed SDL_TEXTINPUTEVENT_TEXT_SIZE --- docs/README-migration.md | 2 +- include/SDL3/SDL_events.h | 1 - src/core/haiku/SDL_BApp.h | 2 +- src/core/linux/SDL_fcitx.c | 12 +----------- src/core/linux/SDL_ibus.c | 12 +----------- src/events/SDL_keyboard.c | 8 ++++++++ src/video/wayland/SDL_waylandevents.c | 12 +----------- src/video/x11/SDL_x11events.c | 2 +- 8 files changed, 14 insertions(+), 37 deletions(-) diff --git a/docs/README-migration.md b/docs/README-migration.md index 05b8de7a7..68fd774c4 100644 --- a/docs/README-migration.md +++ b/docs/README-migration.md @@ -317,7 +317,7 @@ The timestamp_us member of the sensor events has been renamed sensor_timestamp a You should set the event.common.timestamp field before passing an event to SDL_PushEvent(). If the timestamp is 0 it will be filled in with SDL_GetTicksNS(). -Event memory is now managed by SDL, so you should not free the data in SDL_EVENT_DROP_FILE, and if you want to hold onto the text in SDL_EVENT_TEXT_EDITING and SDL_EVENT_TEXT_INPUT events, you should make a copy of it. +Event memory is now managed by SDL, so you should not free the data in SDL_EVENT_DROP_FILE, and if you want to hold onto the text in SDL_EVENT_TEXT_EDITING and SDL_EVENT_TEXT_INPUT events, you should make a copy of it. SDL_TEXTINPUTEVENT_TEXT_SIZE is no longer necessary and has been removed. Mouse events use floating point values for mouse coordinates and relative motion values. You can get sub-pixel motion depending on the platform and display scaling. diff --git a/include/SDL3/SDL_events.h b/include/SDL3/SDL_events.h index 619197361..4c96cbe15 100644 --- a/include/SDL3/SDL_events.h +++ b/include/SDL3/SDL_events.h @@ -320,7 +320,6 @@ typedef struct SDL_TextEditingEvent Sint32 length; /**< The length of selected editing text */ } SDL_TextEditingEvent; -#define SDL_TEXTINPUTEVENT_TEXT_SIZE 64 /** * Keyboard text input event structure (event.text.*) * diff --git a/src/core/haiku/SDL_BApp.h b/src/core/haiku/SDL_BApp.h index 66d88d1dd..8af12eec5 100644 --- a/src/core/haiku/SDL_BApp.h +++ b/src/core/haiku/SDL_BApp.h @@ -310,7 +310,7 @@ class SDL_BLooper : public BLooper const int8 *keyUtf8; ssize_t count; if (msg->FindData("key-utf8", B_INT8_TYPE, (const void **)&keyUtf8, &count) == B_OK) { - char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; + char text[64]; SDL_zeroa(text); SDL_memcpy(text, keyUtf8, count); SDL_SendKeyboardText(text); diff --git a/src/core/linux/SDL_fcitx.c b/src/core/linux/SDL_fcitx.c index 7fec89f1a..808054a05 100644 --- a/src/core/linux/SDL_fcitx.c +++ b/src/core/linux/SDL_fcitx.c @@ -191,17 +191,7 @@ static DBusHandlerResult DBus_MessageFilter(DBusConnection *conn, DBusMessage *m dbus->message_iter_init(msg, &iter); dbus->message_iter_get_basic(&iter, &text); - if (text && *text) { - char buf[SDL_TEXTINPUTEVENT_TEXT_SIZE]; - size_t text_bytes = SDL_strlen(text), i = 0; - - while (i < text_bytes) { - size_t sz = SDL_utf8strlcpy(buf, text + i, sizeof(buf)); - SDL_SendKeyboardText(buf); - - i += sz; - } - } + SDL_SendKeyboardText(text); return DBUS_HANDLER_RESULT_HANDLED; } diff --git a/src/core/linux/SDL_ibus.c b/src/core/linux/SDL_ibus.c index 17c905a67..9e514c302 100644 --- a/src/core/linux/SDL_ibus.c +++ b/src/core/linux/SDL_ibus.c @@ -228,17 +228,7 @@ static DBusHandlerResult IBus_MessageHandler(DBusConnection *conn, DBusMessage * dbus->message_iter_init(msg, &iter); text = IBus_GetVariantText(conn, &iter, dbus); - if (text && *text) { - char buf[SDL_TEXTINPUTEVENT_TEXT_SIZE]; - size_t text_bytes = SDL_strlen(text), i = 0; - - while (i < text_bytes) { - size_t sz = SDL_utf8strlcpy(buf, text + i, sizeof(buf)); - SDL_SendKeyboardText(buf); - - i += sz; - } - } + SDL_SendKeyboardText(text); return DBUS_HANDLER_RESULT_HANDLED; } diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c index 2f1ea4f1d..dd14e6c3d 100644 --- a/src/events/SDL_keyboard.c +++ b/src/events/SDL_keyboard.c @@ -1184,6 +1184,10 @@ int SDL_SendKeyboardText(const char *text) return 0; } + if (!text || !*text) { + return 0; + } + /* Don't post text events for unprintable characters */ if (SDL_iscntrl((unsigned char)*text)) { return 0; @@ -1218,6 +1222,10 @@ int SDL_SendEditingText(const char *text, int start, int length) return 0; } + if (!text) { + return 0; + } + /* Post the event, if desired */ posted = 0; if (SDL_EventEnabled(SDL_EVENT_TEXT_EDITING)) { diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c index c73197bd8..04a9c9b8c 100644 --- a/src/video/wayland/SDL_waylandevents.c +++ b/src/video/wayland/SDL_waylandevents.c @@ -2320,17 +2320,7 @@ static void text_input_commit_string(void *data, struct zwp_text_input_v3 *zwp_text_input_v3, const char *text) { - if (text && *text) { - char buf[SDL_TEXTINPUTEVENT_TEXT_SIZE]; - size_t text_bytes = SDL_strlen(text), i = 0; - - while (i < text_bytes) { - size_t sz = SDL_utf8strlcpy(buf, text + i, sizeof(buf)); - SDL_SendKeyboardText(buf); - - i += sz; - } - } + SDL_SendKeyboardText(text); } static void text_input_delete_surrounding_text(void *data, diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index 2d24a2d9e..9924c35b1 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -838,7 +838,7 @@ void X11_HandleKeyEvent(SDL_VideoDevice *_this, SDL_WindowData *windowdata, SDL_ Display *display = videodata->display; KeyCode keycode = xevent->xkey.keycode; KeySym keysym = NoSymbol; - char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; + char text[64]; Status status = 0; SDL_bool handled_by_ime = SDL_FALSE;