Browse Source

Removed SDL_TEXTINPUTEVENT_TEXT_SIZE

Sam Lantinga 1 year ago
parent
commit
6443c75eda

+ 1 - 1
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.
 

+ 0 - 1
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.*)
  *

+ 1 - 1
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);

+ 1 - 11
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;
     }

+ 1 - 11
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;
     }

+ 8 - 0
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)) {

+ 1 - 11
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,

+ 1 - 1
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;