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

From 8aa87e8cecec7b11b5ef76738e7bcdf392c54305 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Sat, 2 Nov 2024 17:11:20 +0300
Subject: [PATCH] sync with latest SDL2 and SDL3

---
 include/SDL2/SDL_events.h         | 18 ++++++++++++------
 include/SDL2/SDL_gamecontroller.h | 10 ++++++++++
 include/SDL2/SDL_stdinc.h         | 17 +++++++++--------
 include/SDL2/SDL_vulkan.h         |  4 ++++
 src/sdl3_include_wrapper.h        |  5 +++++
 5 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/include/SDL2/SDL_events.h b/include/SDL2/SDL_events.h
index 33d6da4..82588aa 100644
--- a/include/SDL2/SDL_events.h
+++ b/include/SDL2/SDL_events.h
@@ -412,6 +412,11 @@ typedef struct SDL_JoyButtonEvent
 
 /**
  * Joystick device event structure (event.jdevice.*)
+ *
+ * SDL will send JOYSTICK_ADDED events for devices that are already plugged in
+ * during SDL_Init.
+ *
+ * \sa SDL_ControllerDeviceEvent
  */
 typedef struct SDL_JoyDeviceEvent
 {
@@ -465,6 +470,12 @@ typedef struct SDL_ControllerButtonEvent
 
 /**
  * Controller device event structure (event.cdevice.*)
+ *
+ * Joysticks that are supported game controllers receive both an
+ * SDL_JoyDeviceEvent and an SDL_ControllerDeviceEvent.
+ *
+ * SDL will send CONTROLLERDEVICEADDED events for joysticks that are already
+ * plugged in during SDL_Init() and are recognized as game controllers.
  */
 typedef struct SDL_ControllerDeviceEvent
 {
@@ -639,12 +650,7 @@ typedef struct SDL_SysWMEvent
  * General event structure
  *
  * The SDL_Event structure is the core of all event handling in SDL. SDL_Event
- * is a union of all event structures used in SDL. Using it is a simple matter
- * of knowing which event type corresponds to which union member. The table
- * below lists these relationships.
- *
- * The SDL_Event structure has two uses: * Reading events from the event queue
- * * Placing events on the event queue
+ * is a union of all event structures used in SDL.
  */
 typedef union SDL_Event
 {
diff --git a/include/SDL2/SDL_gamecontroller.h b/include/SDL2/SDL_gamecontroller.h
index 030e0f0..f4a1e6d 100644
--- a/include/SDL2/SDL_gamecontroller.h
+++ b/include/SDL2/SDL_gamecontroller.h
@@ -146,6 +146,10 @@ typedef struct SDL_GameControllerButtonBind
  * If a new mapping is loaded for an already known controller GUID, the later
  * version will overwrite the one currently loaded.
  *
+ * If this function is called before SDL_Init, SDL will generate an
+ * SDL_CONTROLLERDEVICEADDED event for matching controllers that are plugged
+ * in at the time that SDL_Init is called.
+ *
  * Mappings not belonging to the current platform or with no platform field
  * specified will be ignored (i.e. mappings for Linux will be ignored in
  * Windows, etc).
@@ -164,6 +168,7 @@ typedef struct SDL_GameControllerButtonBind
  * \sa SDL_GameControllerAddMapping
  * \sa SDL_GameControllerAddMappingsFromFile
  * \sa SDL_GameControllerMappingForGUID
+ * \sa SDL_CONTROLLERDEVICEADDED
  */
 extern DECLSPEC int SDLCALL SDL_GameControllerAddMappingsFromRW(SDL_RWops * rw, int freerw);
 
@@ -193,6 +198,10 @@ extern DECLSPEC int SDLCALL SDL_GameControllerAddMappingsFromRW(SDL_RWops * rw,
  * "341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7"
  * ```
  *
+ * If this function is called before SDL_Init, SDL will generate an
+ * SDL_CONTROLLERDEVICEADDED event for matching controllers that are plugged
+ * in at the time that SDL_Init is called.
+ *
  * \param mappingString the mapping string.
  * \returns 1 if a new mapping is added, 0 if an existing mapping is updated,
  *          -1 on error; call SDL_GetError() for more information.
@@ -201,6 +210,7 @@ extern DECLSPEC int SDLCALL SDL_GameControllerAddMappingsFromRW(SDL_RWops * rw,
  *
  * \sa SDL_GameControllerMapping
  * \sa SDL_GameControllerMappingForGUID
+ * \sa SDL_CONTROLLERDEVICEADDED
  */
 extern DECLSPEC int SDLCALL SDL_GameControllerAddMapping(const char* mappingString);
 
diff --git a/include/SDL2/SDL_stdinc.h b/include/SDL2/SDL_stdinc.h
index 9fa3488..e77a248 100644
--- a/include/SDL2/SDL_stdinc.h
+++ b/include/SDL2/SDL_stdinc.h
@@ -193,58 +193,59 @@ typedef enum
 /**
  * A signed 8-bit integer type.
  */
+typedef int8_t Sint8;
 #define SDL_MAX_SINT8   ((Sint8)0x7F)           /* 127 */
 #define SDL_MIN_SINT8   ((Sint8)(~0x7F))        /* -128 */
-typedef int8_t Sint8;
 
 /**
  * An unsigned 8-bit integer type.
  */
+typedef uint8_t Uint8;
 #define SDL_MAX_UINT8   ((Uint8)0xFF)           /* 255 */
 #define SDL_MIN_UINT8   ((Uint8)0x00)           /* 0 */
-typedef uint8_t Uint8;
 
 /**
  * A signed 16-bit integer type.
  */
+typedef int16_t Sint16;
 #define SDL_MAX_SINT16  ((Sint16)0x7FFF)        /* 32767 */
 #define SDL_MIN_SINT16  ((Sint16)(~0x7FFF))     /* -32768 */
-typedef int16_t Sint16;
 
 /**
  * An unsigned 16-bit integer type.
  */
+typedef uint16_t Uint16;
 #define SDL_MAX_UINT16  ((Uint16)0xFFFF)        /* 65535 */
 #define SDL_MIN_UINT16  ((Uint16)0x0000)        /* 0 */
-typedef uint16_t Uint16;
 
 /**
  * A signed 32-bit integer type.
  */
+typedef int32_t Sint32;
 #define SDL_MAX_SINT32  ((Sint32)0x7FFFFFFF)    /* 2147483647 */
 #define SDL_MIN_SINT32  ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
-typedef int32_t Sint32;
 
 /**
  * An unsigned 32-bit integer type.
  */
+typedef uint32_t Uint32;
 #define SDL_MAX_UINT32  ((Uint32)0xFFFFFFFFu)   /* 4294967295 */
 #define SDL_MIN_UINT32  ((Uint32)0x00000000)    /* 0 */
-typedef uint32_t Uint32;
 
 /**
  * A signed 64-bit integer type.
  */
+typedef int64_t Sint64;
 #define SDL_MAX_SINT64  ((Sint64)0x7FFFFFFFFFFFFFFFll)      /* 9223372036854775807 */
 #define SDL_MIN_SINT64  ((Sint64)(~0x7FFFFFFFFFFFFFFFll))   /* -9223372036854775808 */
-typedef int64_t Sint64;
 
 /**
  * An unsigned 64-bit integer type.
  */
+typedef uint64_t Uint64;
 #define SDL_MAX_UINT64  ((Uint64)0xFFFFFFFFFFFFFFFFull)     /* 18446744073709551615 */
 #define SDL_MIN_UINT64  ((Uint64)(0x0000000000000000ull))   /* 0 */
-typedef uint64_t Uint64;
+
 
 /* @} *//* Basic data types */
 
diff --git a/include/SDL2/SDL_vulkan.h b/include/SDL2/SDL_vulkan.h
index 06d8135..e005ed3 100644
--- a/include/SDL2/SDL_vulkan.h
+++ b/include/SDL2/SDL_vulkan.h
@@ -52,6 +52,10 @@ extern "C" {
 VK_DEFINE_HANDLE(VkInstance)
 VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSurfaceKHR)
 
+/* Make sure to undef to avoid issues in case of later vulkan include */
+#undef VK_DEFINE_HANDLE
+#undef VK_DEFINE_NON_DISPATCHABLE_HANDLE
+
 #endif /* !NO_SDL_VULKAN_TYPEDEFS */
 
 typedef VkInstance SDL_vulkanInstance;
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index a30d8ce..e82dc6a 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -1215,6 +1215,7 @@
 #define SDL_GetDefaultLogOutputFunction IGNORE_THIS_VERSION_OF_SDL_GetDefaultLogOutputFunction
 #define SDL_RenderDebugText IGNORE_THIS_VERSION_OF_SDL_RenderDebugText
 #define SDL_GetSandbox IGNORE_THIS_VERSION_OF_SDL_GetSandbox
+#define SDL_CancelGPUCommandBuffer IGNORE_THIS_VERSION_OF_SDL_CancelGPUCommandBuffer
 
 
 #define SDL_FUNCTION_POINTER_IS_VOID_POINTER 1
@@ -5967,6 +5968,10 @@
 #undef SDL_GetSandbox
 #endif
 
+#ifdef SDL_CancelGPUCommandBuffer
+#undef SDL_CancelGPUCommandBuffer
+#endif
+
 #undef SDL_ThreadID /* see at top. */
 
 /* dump the macro CreateThread versions, too. */