sdl2-compat: sync with latest SDL2 and SDL3 (a7d82)

From a7d8218e64f3dc38df42dc83b2465d4a7830e3b3 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Fri, 7 Mar 2025 22:47:00 +0300
Subject: [PATCH] sync with latest SDL2 and SDL3

---
 include/SDL2/SDL_hints.h     | 21 +++++++++++++++
 include/SDL2/SDL_keyboard.h  |  2 +-
 include/SDL2/SDL_render.h    |  2 +-
 src/sdl3_include_wrapper.h   | 20 +++++++++++++++
 test/testautomation_stdlib.c | 50 +++++++++++++++++++++---------------
 5 files changed, 73 insertions(+), 22 deletions(-)

diff --git a/include/SDL2/SDL_hints.h b/include/SDL2/SDL_hints.h
index 4665107f..6713d01f 100644
--- a/include/SDL2/SDL_hints.h
+++ b/include/SDL2/SDL_hints.h
@@ -1423,6 +1423,27 @@ extern "C" {
  */
 #define SDL_HINT_JOYSTICK_DEVICE "SDL_JOYSTICK_DEVICE"
 
+
+/**
+ * A variable containing a list of devices and their desired number of haptic
+ * (force feedback) enabled axis.
+ *
+ * The format of the string is a comma separated list of USB VID/PID pairs in
+ * hexadecimal form plus the number of desired axes, e.g.
+ *
+ * `0xAAAA/0xBBBB/1,0xCCCC/0xDDDD/3`
+ *
+ * This hint supports a "wildcard" device that will set the number of haptic
+ * axes on all initialized haptic devices which were not defined explicitly in
+ * this hint.
+ *
+ * `0xFFFF/0xFFFF/1`
+ *
+ * This hint should be set before a controller is opened. The number of haptic
+ * axes won't exceed the number of real axes found on the device.
+ */
+#define SDL_HINT_JOYSTICK_HAPTIC_AXES "SDL_JOYSTICK_HAPTIC_AXES"
+
 /**
  * A variable controlling whether joysticks on Linux will always treat 'hat'
  * axis inputs (ABS_HAT0X - ABS_HAT3Y) as 8-way digital hats without checking
diff --git a/include/SDL2/SDL_keyboard.h b/include/SDL2/SDL_keyboard.h
index 8c4efdd0..62ac9f22 100644
--- a/include/SDL2/SDL_keyboard.h
+++ b/include/SDL2/SDL_keyboard.h
@@ -255,7 +255,7 @@ extern DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromName(const char *name);
  * On some platforms using this function activates the screen keyboard.
  *
  * On desktop platforms, SDL_StartTextInput() is implicitly called on SDL
- * window creation which will cause events SDL_TextInputEvent and
+ * video subsystem initialization which will cause SDL_TextInputEvent and
  * SDL_TextEditingEvent to begin emitting.
  *
  * \since This function is available since SDL 2.0.0.
diff --git a/include/SDL2/SDL_render.h b/include/SDL2/SDL_render.h
index 2118ed99..b5a70f35 100644
--- a/include/SDL2/SDL_render.h
+++ b/include/SDL2/SDL_render.h
@@ -787,7 +787,7 @@ extern DECLSPEC int SDLCALL SDL_SetRenderTarget(SDL_Renderer *renderer,
  * Get the current render target.
  *
  * The default render target is the window for which the renderer was created,
- * and is reported a NULL here.
+ * and is reported as NULL here.
  *
  * \param renderer the rendering context.
  * \returns the current render target or NULL for the default render target.
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index 25649cad..62f679dd 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -1266,6 +1266,10 @@
 #define SDL_ClickTrayEntry IGNORE_THIS_VERSION_OF_SDL_ClickTrayEntry
 #define SDL_UpdateTrays IGNORE_THIS_VERSION_OF_SDL_UpdateTrays
 #define SDL_StretchSurface IGNORE_THIS_VERSION_OF_SDL_StretchSurface
+#define SDL_SetRelativeMouseTransform IGNORE_THIS_VERSION_OF_SDL_SetRelativeMouseTransform
+#define SDL_RenderTexture9GridTiled IGNORE_THIS_VERSION_OF_SDL_RenderTexture9GridTiled
+#define SDL_SetDefaultTextureScaleMode IGNORE_THIS_VERSION_OF_SDL_SetDefaultTextureScaleMode
+#define SDL_GetDefaultTextureScaleMode IGNORE_THIS_VERSION_OF_SDL_GetDefaultTextureScaleMode
 
 
 #define SDL_FUNCTION_POINTER_IS_VOID_POINTER 1
@@ -6224,6 +6228,22 @@
 #undef SDL_StretchSurface
 #endif
 
+#ifdef SDL_SetRelativeMouseTransform
+#undef SDL_SetRelativeMouseTransform
+#endif
+
+#ifdef SDL_RenderTexture9GridTiled
+#undef SDL_RenderTexture9GridTiled
+#endif
+
+#ifdef SDL_SetDefaultTextureScaleMode
+#undef SDL_SetDefaultTextureScaleMode
+#endif
+
+#ifdef SDL_GetDefaultTextureScaleMode
+#undef SDL_GetDefaultTextureScaleMode
+#endif
+
 #undef SDL_ThreadID /* see at top. */
 
 /* dump the macro CreateThread versions, too. */
diff --git a/test/testautomation_stdlib.c b/test/testautomation_stdlib.c
index 1d10d805..b4979b0d 100644
--- a/test/testautomation_stdlib.c
+++ b/test/testautomation_stdlib.c
@@ -397,6 +397,7 @@ int stdlib_getsetenv(void *arg)
 #endif
 
 #define FMT_PRILLd "%lld"
+#define FMT_PRILLdn "%lld%lln"
 #define FMT_PRILLu "%llu"
 
 /**
@@ -407,11 +408,12 @@ int stdlib_sscanf(void *arg)
 {
     int output;
     int result;
+    int length;
     int expected_output;
     int expected_result;
-    short short_output, expected_short_output;
-    long long_output, expected_long_output;
-    long long long_long_output, expected_long_long_output;
+    short short_output, expected_short_output, short_length;
+    long long_output, expected_long_output, long_length;
+    long long long_long_output, expected_long_long_output, long_long_length;
     size_t size_output, expected_size_output;
     char text[128], text2[128];
 
@@ -430,43 +432,51 @@ int stdlib_sscanf(void *arg)
     SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
 
     output = 123;
+    length = 0;
     expected_output = 2;
     expected_result = 1;
-    result = SDL_sscanf("2", "%i", &output);
-    SDLTest_AssertPass("Call to SDL_sscanf(\"2\", \"%%i\", &output)");
+    result = SDL_sscanf("2", "%i%n", &output, &length);
+    SDLTest_AssertPass("Call to SDL_sscanf(\"2\", \"%%i%%n\", &output, &length)");
     SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
     SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
+    SDLTest_AssertCheck(length == 1, "Check length, expected: 1, got: %i", length);
 
     output = 123;
+    length = 0;
     expected_output = 0xa;
     expected_result = 1;
-    result = SDL_sscanf("aa", "%1x", &output);
-    SDLTest_AssertPass("Call to SDL_sscanf(\"aa\", \"%%1x\", &output)");
+    result = SDL_sscanf("aa", "%1x%n", &output, &length);
+    SDLTest_AssertPass("Call to SDL_sscanf(\"aa\", \"%%1x%%n\", &output, &length)");
     SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
     SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
+    SDLTest_AssertCheck(length == 1, "Check length, expected: 1, got: %i", length);
 
-#define SIZED_TEST_CASE(type, var, format_specifier)                                                                                                                             \
+#define SIZED_TEST_CASE(type, var, printf_specifier, scanf_specifier)                                                                                                            \
     var##_output = 123;                                                                                                                                                          \
+    var##_length = 0;                                                                                                                                                            \
     expected_##var##_output = (type)(((unsigned type)(~0)) >> 1);                                                                                                                \
     expected_result = 1;                                                                                                                                                         \
-    result = SDL_snprintf(text, sizeof(text), format_specifier, expected_##var##_output);                                                                                        \
-    result = SDL_sscanf(text, format_specifier, &var##_output);                                                                                                                  \
-    SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", \"%s\", &output)", text, #format_specifier);                                                                                  \
-    SDLTest_AssertCheck(expected_##var##_output == var##_output, "Check output, expected: " format_specifier ", got: " format_specifier, expected_##var##_output, var##_output); \
+    result = SDL_snprintf(text, sizeof(text), printf_specifier, expected_##var##_output);                                                                                        \
+    result = SDL_sscanf(text, scanf_specifier, &var##_output, &var##_length);                                                                                                    \
+    SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", %s, &output, &length)", text, #scanf_specifier);                                                                              \
+    SDLTest_AssertCheck(expected_##var##_output == var##_output, "Check output, expected: " printf_specifier ", got: " printf_specifier, expected_##var##_output, var##_output); \
     SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);                                                        \
+    SDLTest_AssertCheck(var##_length == (type)SDL_strlen(text), "Check length, expected: %i, got: %i", (int)SDL_strlen(text), (int)var##_length);                                \
                                                                                                                                                                                  \
     var##_output = 123;                                                                                                                                                          \
+    var##_length = 0;                                                                                                                                                            \
     expected_##var##_output = ~(type)(((unsigned type)(~0)) >> 1);                                                                                                               \
     expected_result = 1;                                                                                                                                                         \
-    result = SDL_snprintf(text, sizeof(text), format_specifier, expected_##var##_output);                                                                                        \
-    result = SDL_sscanf(text, format_specifier, &var##_output);                                                                                                                  \
-    SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", \"%s\", &output)", text, #format_specifier);                                                                                  \
-    SDLTest_AssertCheck(expected_##var##_output == var##_output, "Check output, expected: " format_specifier ", got: " format_specifier, expected_##var##_output, var##_output); \
-    SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
+    result = SDL_snprintf(text, sizeof(text), printf_specifier, expected_##var##_output);                                                                                        \
+    result = SDL_sscanf(text, scanf_specifier, &var##_output, &var##_length);                                                                                                    \
+    SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", %s, &output, &length)", text, #scanf_specifier);                                                                              \
+    SDLTest_AssertCheck(expected_##var##_output == var##_output, "Check output, expected: " printf_specifier ", got: " printf_specifier, expected_##var##_output, var##_output); \
+    SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);                                                        \
+    SDLTest_AssertCheck(var##_length == (type)SDL_strlen(text), "Check length, expected: %i, got: %i", (int)SDL_strlen(text), (int)var##_length);                                \
 
-    SIZED_TEST_CASE(short, short, "%hd")
-    SIZED_TEST_CASE(long, long, "%ld")
-    SIZED_TEST_CASE(long long, long_long, "%lld")
+    SIZED_TEST_CASE(short, short, "%hd", "%hd%hn")
+    SIZED_TEST_CASE(long, long, "%ld", "%ld%ln")
+    SIZED_TEST_CASE(long long, long_long, FMT_PRILLd, FMT_PRILLdn)
 
     size_output = 123;
     expected_size_output = ~((size_t)0);