sdl2-compat: updates from latest SDL2 branch,

From 28d11608e3c70898e68c6fce319c46c504055f96 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Fri, 22 Dec 2023 14:02:20 +0300
Subject: [PATCH] updates from latest SDL2 branch,

export new symbol SDL_GameControllerGetSteamHandle
---
 include/SDL2/SDL_config_os2.h     |  2 +-
 include/SDL2/SDL_events.h         |  4 +++-
 include/SDL2/SDL_gamecontroller.h | 14 ++++++++++++++
 src/SDL2.exports                  |  1 +
 src/sdl3_include_wrapper.h        |  5 +++++
 src/sdl3_syms.h                   |  1 +
 test/testautomation_stdlib.c      |  7 +++++++
 7 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/include/SDL2/SDL_config_os2.h b/include/SDL2/SDL_config_os2.h
index 2effe1a..c902bf9 100644
--- a/include/SDL2/SDL_config_os2.h
+++ b/include/SDL2/SDL_config_os2.h
@@ -47,7 +47,7 @@
 /* dynamically loaded libusb-1.0 dll: */
 #define SDL_LIBUSB_DYNAMIC "usb100.dll"
 #endif
-/*#undef SDL_JOYSTICK_VIRTUAL */
+#define SDL_JOYSTICK_VIRTUAL 1
 
 /* Enable OpenGL support */
 /* #undef SDL_VIDEO_OPENGL */
diff --git a/include/SDL2/SDL_events.h b/include/SDL2/SDL_events.h
index be27751..c2f9dc6 100644
--- a/include/SDL2/SDL_events.h
+++ b/include/SDL2/SDL_events.h
@@ -131,6 +131,8 @@ typedef enum
     SDL_CONTROLLERTOUCHPADMOTION,      /**< Game controller touchpad finger was moved */
     SDL_CONTROLLERTOUCHPADUP,          /**< Game controller touchpad finger was lifted */
     SDL_CONTROLLERSENSORUPDATE,        /**< Game controller sensor was updated */
+    SDL_CONTROLLERUPDATECOMPLETE_RESERVED_FOR_SDL3,
+    SDL_CONTROLLERSTEAMHANDLEUPDATED,  /**< Game controller Steam handle has changed */
 
     /* Touch events */
     SDL_FINGERDOWN      = 0x700,
@@ -446,7 +448,7 @@ typedef struct SDL_ControllerButtonEvent
  */
 typedef struct SDL_ControllerDeviceEvent
 {
-    Uint32 type;        /**< ::SDL_CONTROLLERDEVICEADDED, ::SDL_CONTROLLERDEVICEREMOVED, or ::SDL_CONTROLLERDEVICEREMAPPED */
+    Uint32 type;        /**< ::SDL_CONTROLLERDEVICEADDED, ::SDL_CONTROLLERDEVICEREMOVED, ::SDL_CONTROLLERDEVICEREMAPPED, or ::SDL_CONTROLLERSTEAMHANDLEUPDATED */
     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
     Sint32 which;       /**< The joystick device index for the ADDED event, instance id for the REMOVED or REMAPPED event */
 } SDL_ControllerDeviceEvent;
diff --git a/include/SDL2/SDL_gamecontroller.h b/include/SDL2/SDL_gamecontroller.h
index bee07c4..0b9cb44 100644
--- a/include/SDL2/SDL_gamecontroller.h
+++ b/include/SDL2/SDL_gamecontroller.h
@@ -524,6 +524,20 @@ extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetFirmwareVersion(SDL_GameCont
  */
 extern DECLSPEC const char * SDLCALL SDL_GameControllerGetSerial(SDL_GameController *gamecontroller);
 
+/**
+ * Get the Steam Input handle of an opened controller, if available.
+ *
+ * Returns an InputHandle_t for the controller that can be used with Steam Input API:
+ * https://partner.steamgames.com/doc/api/ISteamInput
+ *
+ * \param gamecontroller the game controller object to query.
+ * \returns the gamepad handle, or 0 if unavailable.
+ *
+ * \since This function is available since SDL 2.30.0.
+ */
+extern DECLSPEC Uint64 SDLCALL SDL_GameControllerGetSteamHandle(SDL_GameController *gamecontroller);
+
+
 /**
  * Check if a controller has been opened and is currently connected.
  *
diff --git a/src/SDL2.exports b/src/SDL2.exports
index 300dbc6..b7780a3 100644
--- a/src/SDL2.exports
+++ b/src/SDL2.exports
@@ -843,3 +843,4 @@
 ++'_SDL_strcasestr'.'SDL2.dll'.'SDL_strcasestr'.'SDL_strcasestr'
 ++'_SDL_HasWindowSurface'.'SDL2.dll'.'SDL_HasWindowSurface'.'SDL_HasWindowSurface'
 ++'_SDL_DestroyWindowSurface'.'SDL2.dll'.'SDL_DestroyWindowSurface'.'SDL_DestroyWindowSurface'
+++'_SDL_GameControllerGetSteamHandle'.'SDL2.dll'.'SDL_GameControllerGetSteamHandle'.'SDL_GameControllerGetSteamHandle'
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index 6c9f8fc..e449046 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -988,6 +988,7 @@
 #define SDL_strnstr IGNORE_THIS_VERSION_OF_SDL_strnstr
 #define SDL_wcsnstr IGNORE_THIS_VERSION_OF_SDL_wcsnstr
 #define SDL_SyncWindow IGNORE_THIS_VERSION_OF_SDL_SyncWindow
+#define SDL_GetGamepadSteamHandle IGNORE_THIS_VERSION_OF_SDL_GetGamepadSteamHandle
 
 
 #define SDL_FUNCTION_POINTER_IS_VOID_POINTER 1
@@ -4856,6 +4857,10 @@
 #undef SDL_SyncWindow
 #endif
 
+#ifdef SDL_GetGamepadSteamHandle
+#undef SDL_GetGamepadSteamHandle
+#endif
+
 /* undefine these macros, too: redefine as SDL3_xxx, if needed. */
 
 #ifdef SDL_enabled_assert
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 69f17bf..afe7b1f 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -866,6 +866,7 @@ SDL3_SYM(int,SetStringProperty,(SDL_PropertiesID a, const char *b, const char *c
 SDL3_SYM(void,DestroyProperties,(SDL_PropertiesID a),(a),)
 SDL3_SYM(SDL_Window*,CreateWindowWithProperties,(SDL_PropertiesID a),(a),return)
 SDL3_SYM(char **,GetGamepadMappings,(int *a),(a),return)
+SDL3_SYM_RENAMED(Uint64,GameControllerGetSteamHandle,GetGamepadSteamHandle,(SDL_GameController *a),(a),return)
 
 #undef SDL3_SYM
 #undef SDL3_SYM_PASSTHROUGH
diff --git a/test/testautomation_stdlib.c b/test/testautomation_stdlib.c
index 9228b17..66ddc5d 100644
--- a/test/testautomation_stdlib.c
+++ b/test/testautomation_stdlib.c
@@ -187,6 +187,13 @@ int stdlib_snprintf(void *arg)
     SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
     SDLTest_AssertCheck(result == SDL_strlen(expected), "Check result value, expected: %d, got: %d", (int)SDL_strlen(expected), result);
 
+    if (sizeof(void *) >= 8) {
+        result = SDL_snprintf(text, sizeof(text), "%p", (void *)0x1ba07bddf60L);
+        expected = "0x1ba07bddf60";
+        SDLTest_AssertPass("Call to SDL_snprintf(text, sizeof(text), \"%%p\", 0x1ba07bddf60)");
+        SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
+        SDLTest_AssertCheck(result == SDL_strlen(expected), "Check result value, expected: %d, got: %d", (int)SDL_strlen(expected), result);
+    }
     return TEST_COMPLETED;
 }