sdl2-compat: Updated for latest SDL3 changes as of ea11c9e0c75b09442c2d2387e866fed2b146ae22

From 3d7567cbe56ec9ca89d14ddd8b352966d3b7a809 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 24 Jun 2024 12:51:03 -0700
Subject: [PATCH] Updated for latest SDL3 changes as of
 ea11c9e0c75b09442c2d2387e866fed2b146ae22

---
 src/sdl2_compat.c          | 80 ++++++++++++++++++++++++++++++++-
 src/sdl3_include_wrapper.h | 90 +++++++++++++++++++++++++++++++++-----
 src/sdl3_syms.h            | 11 ++---
 3 files changed, 164 insertions(+), 17 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 709abb8..c80a329 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -6823,16 +6823,92 @@ SDL_JoystickSetPlayerIndex(SDL_Joystick *joystick, int player_index)
     SDL3_SetJoystickPlayerIndex(joystick, player_index);
 }
 
+SDL_DECLSPEC void SDLCALL
+SDL_StartTextInput(void)
+{
+    SDL_Window **windows = SDL3_GetWindows(NULL);
+    if (windows) {
+        int i;
+
+        for (i = 0; windows[i]; ++i) {
+            SDL3_StartTextInput(windows[i]);
+        }
+        SDL_free(windows);
+    }
+}
+
+SDL_DECLSPEC SDL_bool SDLCALL
+SDL_IsTextInputActive(void)
+{
+    SDL_bool result = SDL_FALSE;
+    SDL_Window **windows = SDL3_GetWindows(NULL);
+    if (windows) {
+        int i;
+
+        for (i = 0; windows[i]; ++i) {
+            if (SDL3_TextInputActive(windows[i])) {
+                result = SDL_TRUE;
+                break;
+            }
+        }
+        SDL_free(windows);
+    }
+    return result;
+}
+
+SDL_DECLSPEC void SDLCALL
+SDL_StopTextInput(void)
+{
+    SDL_Window **windows = SDL3_GetWindows(NULL);
+    if (windows) {
+        int i;
+
+        for (i = 0; windows[i]; ++i) {
+            SDL3_StopTextInput(windows[i]);
+        }
+        SDL_free(windows);
+    }
+}
+
+SDL_DECLSPEC void SDLCALL
+SDL_ClearComposition(void)
+{
+    SDL_Window **windows = SDL3_GetWindows(NULL);
+    if (windows) {
+        int i;
+
+        for (i = 0; windows[i]; ++i) {
+            SDL3_ClearComposition(windows[i]);
+        }
+        SDL_free(windows);
+    }
+}
+
 SDL_DECLSPEC SDL_bool SDLCALL
 SDL_IsTextInputShown()
 {
-    return SDL3_TextInputActive();
+    return SDL_IsTextInputActive();
 }
 
 SDL_DECLSPEC void SDLCALL
 SDL_SetTextInputRect(const SDL_Rect *rect)
 {
-    SDL3_SetTextInputRect(rect);
+    SDL_Window **windows;
+
+    if (!rect) {
+        SDL3_InvalidParamError("rect");
+        return;
+    }
+
+    windows = SDL3_GetWindows(NULL);
+    if (windows) {
+        int i;
+
+        for ( i = 0; windows[i]; ++i ) {
+            SDL3_SetTextInputRect(windows[i], rect);
+        }
+        SDL_free( windows );
+    }
 }
 
 SDL_DECLSPEC void SDLCALL
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index 40c7445..a755fa3 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -198,11 +198,11 @@
 #define SDL_GetAndroidSDKVersion IGNORE_THIS_VERSION_OF_SDL_GetAndroidSDKVersion
 #define SDL_GetAssertionHandler IGNORE_THIS_VERSION_OF_SDL_GetAssertionHandler
 #define SDL_GetAssertionReport IGNORE_THIS_VERSION_OF_SDL_GetAssertionReport
-#define SDL_GetAudioRecordingDevices IGNORE_THIS_VERSION_OF_SDL_GetAudioRecordingDevices
 #define SDL_GetAudioDeviceFormat IGNORE_THIS_VERSION_OF_SDL_GetAudioDeviceFormat
 #define SDL_GetAudioDeviceName IGNORE_THIS_VERSION_OF_SDL_GetAudioDeviceName
 #define SDL_GetAudioDriver IGNORE_THIS_VERSION_OF_SDL_GetAudioDriver
 #define SDL_GetAudioPlaybackDevices IGNORE_THIS_VERSION_OF_SDL_GetAudioPlaybackDevices
+#define SDL_GetAudioRecordingDevices IGNORE_THIS_VERSION_OF_SDL_GetAudioRecordingDevices
 #define SDL_GetAudioStreamAvailable IGNORE_THIS_VERSION_OF_SDL_GetAudioStreamAvailable
 #define SDL_GetAudioStreamData IGNORE_THIS_VERSION_OF_SDL_GetAudioStreamData
 #define SDL_GetAudioStreamDevice IGNORE_THIS_VERSION_OF_SDL_GetAudioStreamDevice
@@ -512,6 +512,7 @@
 #define SDL_GetWindowSurface IGNORE_THIS_VERSION_OF_SDL_GetWindowSurface
 #define SDL_GetWindowSurfaceVSync IGNORE_THIS_VERSION_OF_SDL_GetWindowSurfaceVSync
 #define SDL_GetWindowTitle IGNORE_THIS_VERSION_OF_SDL_GetWindowTitle
+#define SDL_GetWindows IGNORE_THIS_VERSION_OF_SDL_GetWindows
 #define SDL_GlobDirectory IGNORE_THIS_VERSION_OF_SDL_GlobDirectory
 #define SDL_GlobStorageDirectory IGNORE_THIS_VERSION_OF_SDL_GlobStorageDirectory
 #define SDL_HapticEffectSupported IGNORE_THIS_VERSION_OF_SDL_HapticEffectSupported
@@ -648,6 +649,7 @@
 #define SDL_ReadS32LE IGNORE_THIS_VERSION_OF_SDL_ReadS32LE
 #define SDL_ReadS64BE IGNORE_THIS_VERSION_OF_SDL_ReadS64BE
 #define SDL_ReadS64LE IGNORE_THIS_VERSION_OF_SDL_ReadS64LE
+#define SDL_ReadS8 IGNORE_THIS_VERSION_OF_SDL_ReadS8
 #define SDL_ReadStorageFile IGNORE_THIS_VERSION_OF_SDL_ReadStorageFile
 #define SDL_ReadSurfacePixel IGNORE_THIS_VERSION_OF_SDL_ReadSurfacePixel
 #define SDL_ReadU16BE IGNORE_THIS_VERSION_OF_SDL_ReadU16BE
@@ -764,8 +766,8 @@
 #define SDL_SetRenderTarget IGNORE_THIS_VERSION_OF_SDL_SetRenderTarget
 #define SDL_SetRenderVSync IGNORE_THIS_VERSION_OF_SDL_SetRenderVSync
 #define SDL_SetRenderViewport IGNORE_THIS_VERSION_OF_SDL_SetRenderViewport
-#define SDL_SetStringProperty IGNORE_THIS_VERSION_OF_SDL_SetStringProperty
 #define SDL_SetScancodeName IGNORE_THIS_VERSION_OF_SDL_SetScancodeName
+#define SDL_SetStringProperty IGNORE_THIS_VERSION_OF_SDL_SetStringProperty
 #define SDL_SetSurfaceAlphaMod IGNORE_THIS_VERSION_OF_SDL_SetSurfaceAlphaMod
 #define SDL_SetSurfaceBlendMode IGNORE_THIS_VERSION_OF_SDL_SetSurfaceBlendMode
 #define SDL_SetSurfaceClipRect IGNORE_THIS_VERSION_OF_SDL_SetSurfaceClipRect
@@ -883,6 +885,7 @@
 #define SDL_WriteS32LE IGNORE_THIS_VERSION_OF_SDL_WriteS32LE
 #define SDL_WriteS64BE IGNORE_THIS_VERSION_OF_SDL_WriteS64BE
 #define SDL_WriteS64LE IGNORE_THIS_VERSION_OF_SDL_WriteS64LE
+#define SDL_WriteS8 IGNORE_THIS_VERSION_OF_SDL_WriteS8
 #define SDL_WriteStorageFile IGNORE_THIS_VERSION_OF_SDL_WriteStorageFile
 #define SDL_WriteU16BE IGNORE_THIS_VERSION_OF_SDL_WriteU16BE
 #define SDL_WriteU16LE IGNORE_THIS_VERSION_OF_SDL_WriteU16LE
@@ -960,7 +963,11 @@
 #define SDL_iscntrl IGNORE_THIS_VERSION_OF_SDL_iscntrl
 #define SDL_isdigit IGNORE_THIS_VERSION_OF_SDL_isdigit
 #define SDL_isgraph IGNORE_THIS_VERSION_OF_SDL_isgraph
+#define SDL_isinf IGNORE_THIS_VERSION_OF_SDL_isinf
+#define SDL_isinff IGNORE_THIS_VERSION_OF_SDL_isinff
 #define SDL_islower IGNORE_THIS_VERSION_OF_SDL_islower
+#define SDL_isnan IGNORE_THIS_VERSION_OF_SDL_isnan
+#define SDL_isnanf IGNORE_THIS_VERSION_OF_SDL_isnanf
 #define SDL_isprint IGNORE_THIS_VERSION_OF_SDL_isprint
 #define SDL_ispunct IGNORE_THIS_VERSION_OF_SDL_ispunct
 #define SDL_isspace IGNORE_THIS_VERSION_OF_SDL_isspace
@@ -987,6 +994,12 @@
 #define SDL_powf IGNORE_THIS_VERSION_OF_SDL_powf
 #define SDL_qsort IGNORE_THIS_VERSION_OF_SDL_qsort
 #define SDL_qsort_r IGNORE_THIS_VERSION_OF_SDL_qsort_r
+#define SDL_rand IGNORE_THIS_VERSION_OF_SDL_rand
+#define SDL_rand_bits IGNORE_THIS_VERSION_OF_SDL_rand_bits
+#define SDL_rand_bits_r IGNORE_THIS_VERSION_OF_SDL_rand_bits_r
+#define SDL_rand_r IGNORE_THIS_VERSION_OF_SDL_rand_r
+#define SDL_randf IGNORE_THIS_VERSION_OF_SDL_randf
+#define SDL_randf_r IGNORE_THIS_VERSION_OF_SDL_randf_r
 #define SDL_realloc IGNORE_THIS_VERSION_OF_SDL_realloc
 #define SDL_round IGNORE_THIS_VERSION_OF_SDL_round
 #define SDL_roundf IGNORE_THIS_VERSION_OF_SDL_roundf
@@ -998,6 +1011,7 @@
 #define SDL_snprintf IGNORE_THIS_VERSION_OF_SDL_snprintf
 #define SDL_sqrt IGNORE_THIS_VERSION_OF_SDL_sqrt
 #define SDL_sqrtf IGNORE_THIS_VERSION_OF_SDL_sqrtf
+#define SDL_srand IGNORE_THIS_VERSION_OF_SDL_srand
 #define SDL_sscanf IGNORE_THIS_VERSION_OF_SDL_sscanf
 #define SDL_strcasecmp IGNORE_THIS_VERSION_OF_SDL_strcasecmp
 #define SDL_strcasestr IGNORE_THIS_VERSION_OF_SDL_strcasestr
@@ -1736,10 +1750,6 @@
 #undef SDL_GetAssertionReport
 #endif
 
-#ifdef SDL_GetAudioRecordingDevices
-#undef SDL_GetAudioRecordingDevices
-#endif
-
 #ifdef SDL_GetAudioDeviceFormat
 #undef SDL_GetAudioDeviceFormat
 #endif
@@ -1756,6 +1766,10 @@
 #undef SDL_GetAudioPlaybackDevices
 #endif
 
+#ifdef SDL_GetAudioRecordingDevices
+#undef SDL_GetAudioRecordingDevices
+#endif
+
 #ifdef SDL_GetAudioStreamAvailable
 #undef SDL_GetAudioStreamAvailable
 #endif
@@ -2992,6 +3006,10 @@
 #undef SDL_GetWindowTitle
 #endif
 
+#ifdef SDL_GetWindows
+#undef SDL_GetWindows
+#endif
+
 #ifdef SDL_GlobDirectory
 #undef SDL_GlobDirectory
 #endif
@@ -3536,6 +3554,10 @@
 #undef SDL_ReadS64LE
 #endif
 
+#ifdef SDL_ReadS8
+#undef SDL_ReadS8
+#endif
+
 #ifdef SDL_ReadStorageFile
 #undef SDL_ReadStorageFile
 #endif
@@ -4000,14 +4022,14 @@
 #undef SDL_SetRenderViewport
 #endif
 
-#ifdef SDL_SetStringProperty
-#undef SDL_SetStringProperty
-#endif
-
 #ifdef SDL_SetScancodeName
 #undef SDL_SetScancodeName
 #endif
 
+#ifdef SDL_SetStringProperty
+#undef SDL_SetStringProperty
+#endif
+
 #ifdef SDL_SetSurfaceAlphaMod
 #undef SDL_SetSurfaceAlphaMod
 #endif
@@ -4476,6 +4498,10 @@
 #undef SDL_WriteS64LE
 #endif
 
+#ifdef SDL_WriteS8
+#undef SDL_WriteS8
+#endif
+
 #ifdef SDL_WriteStorageFile
 #undef SDL_WriteStorageFile
 #endif
@@ -4784,10 +4810,26 @@
 #undef SDL_isgraph
 #endif
 
+#ifdef SDL_isinf
+#undef SDL_isinf
+#endif
+
+#ifdef SDL_isinff
+#undef SDL_isinff
+#endif
+
 #ifdef SDL_islower
 #undef SDL_islower
 #endif
 
+#ifdef SDL_isnan
+#undef SDL_isnan
+#endif
+
+#ifdef SDL_isnanf
+#undef SDL_isnanf
+#endif
+
 #ifdef SDL_isprint
 #undef SDL_isprint
 #endif
@@ -4892,6 +4934,30 @@
 #undef SDL_qsort_r
 #endif
 
+#ifdef SDL_rand
+#undef SDL_rand
+#endif
+
+#ifdef SDL_rand_bits
+#undef SDL_rand_bits
+#endif
+
+#ifdef SDL_rand_bits_r
+#undef SDL_rand_bits_r
+#endif
+
+#ifdef SDL_rand_r
+#undef SDL_rand_r
+#endif
+
+#ifdef SDL_randf
+#undef SDL_randf
+#endif
+
+#ifdef SDL_randf_r
+#undef SDL_randf_r
+#endif
+
 #ifdef SDL_realloc
 #undef SDL_realloc
 #endif
@@ -4936,6 +5002,10 @@
 #undef SDL_sqrtf
 #endif
 
+#ifdef SDL_srand
+#undef SDL_srand
+#endif
+
 #ifdef SDL_sscanf
 #undef SDL_sscanf
 #endif
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index bea848f..e96dff4 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -223,10 +223,10 @@ SDL3_SYM(const char*,GetScancodeName,(SDL_Scancode a),(a),return)
 SDL3_SYM(SDL_Scancode,GetScancodeFromName,(const char *a),(a),return)
 SDL3_SYM(const char*,GetKeyName,(SDL_Keycode a),(a),return)
 SDL3_SYM(SDL_Keycode,GetKeyFromName,(const char *a),(a),return)
-SDL3_SYM_PASSTHROUGH(void,StartTextInput,(void),(),)
-SDL3_SYM_RENAMED(SDL_bool,IsTextInputActive,TextInputActive,(void),(),return)
-SDL3_SYM_PASSTHROUGH(void,StopTextInput,(void),(),)
-SDL3_SYM(int,SetTextInputRect,(const SDL_Rect *a),(a),return)
+SDL3_SYM(int,StartTextInput,(SDL_Window *a),(a),return)
+SDL3_SYM(SDL_bool,TextInputActive,(SDL_Window *a),(a),return)
+SDL3_SYM(int,StopTextInput,(SDL_Window *a),(a),return)
+SDL3_SYM(int,SetTextInputRect,(SDL_Window *a, const SDL_Rect *b),(a,b),return)
 SDL3_SYM_PASSTHROUGH(SDL_bool,HasScreenKeyboardSupport,(void),(),return)
 SDL3_SYM_RENAMED(SDL_bool,IsScreenKeyboardShown,ScreenKeyboardShown,(SDL_Window *a),(a),return)
 SDL3_SYM_PASSTHROUGH(void*,LoadObject,(const char *a),(a),return)
@@ -720,7 +720,7 @@ SDL3_SYM(int,RenderCoordinatesToWindow,(SDL_Renderer *a, float b, float c, float
 SDL3_SYM_PASSTHROUGH(void,hid_ble_scan,(SDL_bool a),(a),)
 SDL3_SYM(int,PremultiplyAlpha,(int a, int b, SDL_PixelFormatEnum c, const void *d, int e, SDL_PixelFormatEnum f, void *g, int h),(a,b,c,d,e,f,g,h),return)
 SDL3_SYM(const char*,GetTouchDeviceName,(SDL_TouchID a),(a),return)
-SDL3_SYM_PASSTHROUGH(void,ClearComposition,(void),(),)
+SDL3_SYM(int,ClearComposition,(SDL_Window *a),(a),return)
 SDL3_SYM_RENAMED(SDL_bool,HasIntersectionF,HasRectIntersectionFloat,(const SDL_FRect *a, const SDL_FRect *b),(a,b),return)
 SDL3_SYM_RENAMED(SDL_bool,IntersectFRect,GetRectIntersectionFloat,(const SDL_FRect *a, const SDL_FRect *b, SDL_FRect *c),(a,b,c),return)
 SDL3_SYM(int,GetRectUnionFloat,(const SDL_FRect *a, const SDL_FRect *b, SDL_FRect *c),(a,b,c),return)
@@ -849,6 +849,7 @@ SDL3_SYM(int,GetSurfaceColorspace,(SDL_Surface *a, SDL_Colorspace *b),(a,b),retu
 SDL3_SYM(int,SetWindowShape,(SDL_Window *a, SDL_Surface *b),(a,b),return)
 SDL3_SYM(SDL_PropertiesID,GetSurfaceProperties,(SDL_Surface *a),(a),return)
 SDL3_SYM(int,ClearProperty,(SDL_PropertiesID a, const char *b),(a,b),return)
+SDL3_SYM(SDL_Window **,GetWindows,(int *a),(a),return)
 
 #undef SDL3_SYM
 #undef SDL3_SYM_PASSTHROUGH