sdl2-compat: Updated for latest SDL3 changes

From a7bd9760b7e0b3e693a5d51f787aaa7d98d50577 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 12 Nov 2023 12:33:50 -0800
Subject: [PATCH] Updated for latest SDL3 changes

---
 src/sdl2_compat.c          |  54 ++++++++--------
 src/sdl3_include_wrapper.h | 125 +++++++++++++++++++++++++++++++++++--
 src/sdl3_syms.h            |  18 +++++-
 3 files changed, 164 insertions(+), 33 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index a55fe6e..f595139 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -2591,26 +2591,26 @@ DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo(SDL_Window *window, SDL_SysWMinfo
 
     if (SDL_strcmp(driver, "Android") == 0) {
         info->subsystem = SDL2_SYSWM_ANDROID;
-        info->info.android.window = SDL3_GetProperty(props, "SDL.window.android.window");
-        info->info.android.surface = SDL3_GetProperty(props, "SDL.window.android.surface");
+        info->info.android.window = SDL3_GetProperty(props, "SDL.window.android.window", NULL);
+        info->info.android.surface = SDL3_GetProperty(props, "SDL.window.android.surface", NULL);
     } else if (SDL_strcmp(driver, "cocoa") == 0) {
         info->subsystem = SDL2_SYSWM_COCOA;
-        info->info.cocoa.window = (NSWindow *)SDL3_GetProperty(props, "SDL.window.cocoa.window");
+        info->info.cocoa.window = (NSWindow *)SDL3_GetProperty(props, "SDL.window.cocoa.window", NULL);
     } else if (SDL_strcmp(driver, "kmsdrm") == 0) {
         info->subsystem = SDL2_SYSWM_KMSDRM;
-        info->info.kmsdrm.dev_index = (int)(intptr_t)SDL3_GetProperty(props, "SDL.window.kmsdrm.dev_index");
-        info->info.kmsdrm.drm_fd = (int)(intptr_t)SDL3_GetProperty(props, "SDL.window.kmsdrm.drm_fd");
-        info->info.kmsdrm.gbm_dev = SDL3_GetProperty(props, "SDL.window.kmsdrm.gbm_dev");
+        info->info.kmsdrm.dev_index = (int)SDL3_GetNumberProperty(props, "SDL.window.kmsdrm.dev_index", 0);
+        info->info.kmsdrm.drm_fd = (int)SDL3_GetNumberProperty(props, "SDL.window.kmsdrm.drm_fd", -1);
+        info->info.kmsdrm.gbm_dev = SDL3_GetProperty(props, "SDL.window.kmsdrm.gbm_dev", NULL);
     } else if (SDL_strcmp(driver, "uikit") == 0) {
         info->subsystem = SDL2_SYSWM_UIKIT;
-        info->info.uikit.window = (UIWindow *)SDL3_GetProperty(props, "SDL.window.uikit.window");
+        info->info.uikit.window = (UIWindow *)SDL3_GetProperty(props, "SDL.window.uikit.window", NULL);
         info->info.uikit.colorbuffer = 0;
         info->info.uikit.framebuffer = 0;
         info->info.uikit.resolveFramebuffer = 0;
     } else if (SDL_strcmp(driver, "vivante") == 0) {
         info->subsystem = SDL2_SYSWM_VIVANTE;
-        info->info.vivante.display = SDL3_GetProperty(props, "SDL.window.vivante.display");
-        info->info.vivante.window = SDL3_GetProperty(props, "SDL.window.vivante.window");
+        info->info.vivante.display = SDL3_GetProperty(props, "SDL.window.vivante.display", NULL);
+        info->info.vivante.window = SDL3_GetProperty(props, "SDL.window.vivante.window", NULL);
     } else if (SDL_strcmp(driver, "wayland") == 0) {
         Uint32 version2 = SDL_VERSIONNUM((Uint32)info->version.major,
                                          (Uint32)info->version.minor,
@@ -2634,33 +2634,33 @@ DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo(SDL_Window *window, SDL_SysWMinfo
         }
 
         info->subsystem = SDL2_SYSWM_WAYLAND;
-        info->info.wl.display = SDL3_GetProperty(props, "SDL.window.wayland.display");
-        info->info.wl.surface = SDL3_GetProperty(props, "SDL.window.wayland.surface");
+        info->info.wl.display = SDL3_GetProperty(props, "SDL.window.wayland.display", NULL);
+        info->info.wl.surface = SDL3_GetProperty(props, "SDL.window.wayland.surface", NULL);
         info->info.wl.shell_surface = NULL; /* Deprecated */
 
         if (version2 >= SDL_VERSIONNUM(2, 0, 15)) {
-            info->info.wl.egl_window = SDL3_GetProperty(props, "SDL.window.wayland.egl_window");
-            info->info.wl.xdg_surface = SDL3_GetProperty(props, "SDL.window.wayland.xdg_surface");
+            info->info.wl.egl_window = SDL3_GetProperty(props, "SDL.window.wayland.egl_window", NULL);
+            info->info.wl.xdg_surface = SDL3_GetProperty(props, "SDL.window.wayland.xdg_surface", NULL);
             if (version2 >= SDL_VERSIONNUM(2, 0, 17)) {
-                info->info.wl.xdg_toplevel = SDL3_GetProperty(props, "SDL.window.wayland.xdg_toplevel");
+                info->info.wl.xdg_toplevel = SDL3_GetProperty(props, "SDL.window.wayland.xdg_toplevel", NULL);
                 if (version2 >= SDL_VERSIONNUM(2, 0, 22)) {
-                    info->info.wl.xdg_popup = SDL3_GetProperty(props, "SDL.window.wayland.xdg_popup");
-                    info->info.wl.xdg_positioner = SDL3_GetProperty(props, "SDL.window.wayland.xdg_positioner");
+                    info->info.wl.xdg_popup = SDL3_GetProperty(props, "SDL.window.wayland.xdg_popup", NULL);
+                    info->info.wl.xdg_positioner = SDL3_GetProperty(props, "SDL.window.wayland.xdg_positioner", NULL);
                 }
             }
         }
     } else if (SDL_strcmp(driver, "windows") == 0) {
         info->subsystem = SDL2_SYSWM_WINDOWS;
-        info->info.win.window = SDL3_GetProperty(props, "SDL.window.win32.hwnd");
-        info->info.win.hdc = SDL3_GetProperty(props, "SDL.window.win32.hdc");
-        info->info.win.hinstance = SDL3_GetProperty(props, "SDL.window.win32.hinstance");
+        info->info.win.window = SDL3_GetProperty(props, "SDL.window.win32.hwnd", NULL);
+        info->info.win.hdc = SDL3_GetProperty(props, "SDL.window.win32.hdc", NULL);
+        info->info.win.hinstance = SDL3_GetProperty(props, "SDL.window.win32.hinstance", NULL);
     } else if (SDL_strcmp(driver, "winrt") == 0) {
         info->subsystem = SDL2_SYSWM_WINRT;
-        info->info.winrt.window = SDL3_GetProperty(props, "SDL.window.winrt.window");
+        info->info.winrt.window = SDL3_GetProperty(props, "SDL.window.winrt.window", NULL);
     } else if (SDL_strcmp(driver, "x11") == 0) {
         info->subsystem = SDL2_SYSWM_X11;
-        info->info.x11.display = SDL3_GetProperty(props, "SDL.window.x11.display");
-        info->info.x11.window = (unsigned long)(uintptr_t)SDL3_GetProperty(props, "SDL.window.x11.window");
+        info->info.x11.display = SDL3_GetProperty(props, "SDL.window.x11.display", NULL);
+        info->info.x11.window = (unsigned long)SDL3_GetNumberProperty(props, "SDL.window.x11.window", 0);
     } else {
         SDL3_SetError("Video driver '%s' has no mapping to SDL_SysWMinfo", driver);
         info->subsystem = SDL2_SYSWM_UNKNOWN;
@@ -5449,7 +5449,7 @@ SDL_GetWindowData(SDL_Window * window, const char *name)
         return NULL;
     }
 
-    return SDL3_GetProperty(SDL3_GetWindowProperties(window), name);
+    return SDL3_GetProperty(SDL3_GetWindowProperties(window), name, NULL);
 }
 
 DECLSPEC void* SDLCALL
@@ -5481,7 +5481,7 @@ SDL_SetTextureUserData(SDL_Texture * texture, void *userdata)
 DECLSPEC void * SDLCALL
 SDL_GetTextureUserData(SDL_Texture * texture)
 {
-    return SDL3_GetProperty(SDL3_GetTextureProperties(texture), "userdata");
+    return SDL3_GetProperty(SDL3_GetTextureProperties(texture), "userdata", NULL);
 }
 
 DECLSPEC SDL_Window * SDLCALL
@@ -6773,19 +6773,19 @@ SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex)
 DECLSPEC IDirect3DDevice9* SDLCALL SDL_RenderGetD3D9Device(SDL_Renderer *renderer)
 {
     return (IDirect3DDevice9 *)SDL3_GetProperty(SDL3_GetRendererProperties(renderer),
-                                                "SDL.renderer.d3d9.device");
+                                                "SDL.renderer.d3d9.device", NULL);
 }
 
 DECLSPEC ID3D11Device* SDLCALL SDL_RenderGetD3D11Device(SDL_Renderer *renderer)
 {
     return (ID3D11Device *)SDL3_GetProperty(SDL3_GetRendererProperties(renderer),
-                                            "SDL.renderer.d3d11.device");
+                                            "SDL.renderer.d3d11.device", NULL);
 }
 
 DECLSPEC ID3D12Device* SDLCALL SDL_RenderGetD3D12Device(SDL_Renderer *renderer)
 {
     return (ID3D12Device *)SDL3_GetProperty(SDL3_GetRendererProperties(renderer),
-                                            "SDL.renderer.d3d12.device");
+                                            "SDL.renderer.d3d12.device", NULL);
 }
 #endif
 
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index bb7a8fc..7937ec0 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -923,7 +923,6 @@
 #define SDL_SetAudioStreamFrequencyRatio IGNORE_THIS_VERSION_OF_SDL_SetAudioStreamFrequencyRatio
 #define SDL_SetAudioPostmixCallback IGNORE_THIS_VERSION_OF_SDL_SetAudioPostmixCallback
 #define SDL_GetAudioStreamQueued IGNORE_THIS_VERSION_OF_SDL_GetAudioStreamQueued
-#define SDL_GetTextureDXGIResource IGNORE_THIS_VERSION_OF_SDL_GetTextureDXGIResource
 #define SDL_CreateProperties IGNORE_THIS_VERSION_OF_SDL_CreateProperties
 #define SDL_LockProperties IGNORE_THIS_VERSION_OF_SDL_LockProperties
 #define SDL_UnlockProperties IGNORE_THIS_VERSION_OF_SDL_UnlockProperties
@@ -966,6 +965,30 @@
 #define SDL_GetVideoCaptureDevices IGNORE_THIS_VERSION_OF_SDL_GetVideoCaptureDevices
 #define SDL_GetGamepadButtonLabelForType IGNORE_THIS_VERSION_OF_SDL_GetGamepadButtonLabelForType
 #define SDL_GetGamepadButtonLabel IGNORE_THIS_VERSION_OF_SDL_GetGamepadButtonLabel
+#define SDL_GetPens IGNORE_THIS_VERSION_OF_SDL_GetPens
+#define SDL_GetPenStatus IGNORE_THIS_VERSION_OF_SDL_GetPenStatus
+#define SDL_GetPenFromGUID IGNORE_THIS_VERSION_OF_SDL_GetPenFromGUID
+#define SDL_GetPenGUID IGNORE_THIS_VERSION_OF_SDL_GetPenGUID
+#define SDL_PenConnected IGNORE_THIS_VERSION_OF_SDL_PenConnected
+#define SDL_GetPenName IGNORE_THIS_VERSION_OF_SDL_GetPenName
+#define SDL_GetPenCapabilities IGNORE_THIS_VERSION_OF_SDL_GetPenCapabilities
+#define SDL_GetPenType IGNORE_THIS_VERSION_OF_SDL_GetPenType
+#define SDL_GetPens IGNORE_THIS_VERSION_OF_SDL_GetPens
+#define SDL_GetPenStatus IGNORE_THIS_VERSION_OF_SDL_GetPenStatus
+#define SDL_GetPenFromGUID IGNORE_THIS_VERSION_OF_SDL_GetPenFromGUID
+#define SDL_GetPenGUID IGNORE_THIS_VERSION_OF_SDL_GetPenGUID
+#define SDL_PenConnected IGNORE_THIS_VERSION_OF_SDL_PenConnected
+#define SDL_GetPenName IGNORE_THIS_VERSION_OF_SDL_GetPenName
+#define SDL_GetPenCapabilities IGNORE_THIS_VERSION_OF_SDL_GetPenCapabilities
+#define SDL_GetPenType IGNORE_THIS_VERSION_OF_SDL_GetPenType
+#define SDL_SetStringProperty IGNORE_THIS_VERSION_OF_SDL_SetStringProperty
+#define SDL_SetNumberProperty IGNORE_THIS_VERSION_OF_SDL_SetNumberProperty
+#define SDL_SetFloatProperty IGNORE_THIS_VERSION_OF_SDL_SetFloatProperty
+#define SDL_GetPropertyType IGNORE_THIS_VERSION_OF_SDL_GetPropertyType
+#define SDL_GetStringProperty IGNORE_THIS_VERSION_OF_SDL_GetStringProperty
+#define SDL_GetNumberProperty IGNORE_THIS_VERSION_OF_SDL_GetNumberProperty
+#define SDL_GetFloatProperty IGNORE_THIS_VERSION_OF_SDL_GetFloatProperty
+#define SDL_EnumerateProperties IGNORE_THIS_VERSION_OF_SDL_EnumerateProperties
 
 
 #define SDL_FUNCTION_POINTER_IS_VOID_POINTER 1
@@ -4574,10 +4597,6 @@
 #undef SDL_GetAudioStreamQueued
 #endif
 
-#ifdef SDL_GetTextureDXGIResource
-#undef SDL_GetTextureDXGIResource
-#endif
-
 #ifdef SDL_CreateProperties
 #undef SDL_CreateProperties
 #endif
@@ -4746,6 +4765,102 @@
 #undef SDL_GetGamepadButtonLabel
 #endif
 
+#ifdef SDL_GetPens
+#undef SDL_GetPens
+#endif
+
+#ifdef SDL_GetPenStatus
+#undef SDL_GetPenStatus
+#endif
+
+#ifdef SDL_GetPenFromGUID
+#undef SDL_GetPenFromGUID
+#endif
+
+#ifdef SDL_GetPenGUID
+#undef SDL_GetPenGUID
+#endif
+
+#ifdef SDL_PenConnected
+#undef SDL_PenConnected
+#endif
+
+#ifdef SDL_GetPenName
+#undef SDL_GetPenName
+#endif
+
+#ifdef SDL_GetPenCapabilities
+#undef SDL_GetPenCapabilities
+#endif
+
+#ifdef SDL_GetPenType
+#undef SDL_GetPenType
+#endif
+
+#ifdef SDL_GetPens
+#undef SDL_GetPens
+#endif
+
+#ifdef SDL_GetPenStatus
+#undef SDL_GetPenStatus
+#endif
+
+#ifdef SDL_GetPenFromGUID
+#undef SDL_GetPenFromGUID
+#endif
+
+#ifdef SDL_GetPenGUID
+#undef SDL_GetPenGUID
+#endif
+
+#ifdef SDL_PenConnected
+#undef SDL_PenConnected
+#endif
+
+#ifdef SDL_GetPenName
+#undef SDL_GetPenName
+#endif
+
+#ifdef SDL_GetPenCapabilities
+#undef SDL_GetPenCapabilities
+#endif
+
+#ifdef SDL_GetPenType
+#undef SDL_GetPenType
+#endif
+
+#ifdef SDL_SetStringProperty
+#undef SDL_SetStringProperty
+#endif
+
+#ifdef SDL_SetNumberProperty
+#undef SDL_SetNumberProperty
+#endif
+
+#ifdef SDL_SetFloatProperty
+#undef SDL_SetFloatProperty
+#endif
+
+#ifdef SDL_GetPropertyType
+#undef SDL_GetPropertyType
+#endif
+
+#ifdef SDL_GetStringProperty
+#undef SDL_GetStringProperty
+#endif
+
+#ifdef SDL_GetNumberProperty
+#undef SDL_GetNumberProperty
+#endif
+
+#ifdef SDL_GetFloatProperty
+#undef SDL_GetFloatProperty
+#endif
+
+#ifdef SDL_EnumerateProperties
+#undef SDL_EnumerateProperties
+#endif
+
 /* undefine these macros too: */
 /* redefine as SDL3_xxx, if needed. */
 
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 588393b..8b5b9d9 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -890,12 +890,28 @@ SDL3_SYM(SDL_GamepadBinding **,GetGamepadBindings,(SDL_Gamepad *a, int *b),(a,b)
 SDL3_SYM_PASSTHROUGH(int,GDKGetDefaultUser,(XUserHandle *a),(a),return)
 #endif
 SDL3_SYM(int,SetProperty,(SDL_PropertiesID a, const char *b, void *c),(a,b,c),return)
-SDL3_SYM(void*,GetProperty,(SDL_PropertiesID a, const char *b),(a,b),return)
+SDL3_SYM(void*,GetProperty,(SDL_PropertiesID a, const char *b, void *c),(a,b,c),return)
 SDL3_SYM(SDL_PropertiesID,GetWindowProperties,(SDL_Window *a),(a),return)
 SDL3_SYM(SDL_PropertiesID,GetTextureProperties,(SDL_Texture *a),(a),return)
 SDL3_SYM(SDL_PropertiesID,GetRendererProperties,(SDL_Renderer *a),(a),return)
 SDL3_SYM(SDL_GamepadButtonLabel,GetGamepadButtonLabelForType,(SDL_GamepadType a, SDL_GamepadButton b),(a,b),return)
 SDL3_SYM(SDL_GamepadButtonLabel,GetGamepadButtonLabel,(SDL_Gamepad *a, SDL_GamepadButton b),(a,b),return)
+SDL3_SYM(SDL_PenID*,GetPens,(int *a),(a),return)
+SDL3_SYM(Uint32,GetPenStatus,(SDL_PenID a, float *b, float *c, float *d, size_t e),(a,b,c,d,e),return)
+SDL3_SYM(SDL_PenID,GetPenFromGUID,(SDL_GUID a),(a),return)
+SDL3_SYM(SDL_GUID,GetPenGUID,(SDL_PenID a),(a),return)
+SDL3_SYM(SDL_bool,PenConnected,(SDL_PenID a),(a),return)
+SDL3_SYM(const char*,GetPenName,(SDL_PenID a),(a),return)
+SDL3_SYM(Uint32,GetPenCapabilities,(SDL_PenID a, SDL_PenCapabilityInfo *b),(a,b),return)
+SDL3_SYM(SDL_PenSubtype,GetPenType,(SDL_PenID a),(a),return)
+SDL3_SYM(int,SetStringProperty,(SDL_PropertiesID a, const char *b, const char *c),(a,b,c),return)
+SDL3_SYM(int,SetNumberProperty,(SDL_PropertiesID a, const char *b, Sint64 c),(a,b,c),return)
+SDL3_SYM(int,SetFloatProperty,(SDL_PropertiesID a, const char *b, float c),(a,b,c),return)
+SDL3_SYM(SDL_PropertyType,GetPropertyType,(SDL_PropertiesID a, const char *b),(a,b),return)
+SDL3_SYM(const char*,GetStringProperty,(SDL_PropertiesID a, const char *b, const char *c),(a,b,c),return)
+SDL3_SYM(Sint64,GetNumberProperty,(SDL_PropertiesID a, const char *b, Sint64 c),(a,b,c),return)
+SDL3_SYM(float,GetFloatProperty,(SDL_PropertiesID a, const char *b, float c),(a,b,c),return)
+SDL3_SYM(int,EnumerateProperties,(SDL_PropertiesID a, SDL_EnumeratePropertiesCallback b, void *c),(a,b,c),return)
 
 #undef SDL3_SYM
 #undef SDL3_SYM_PASSTHROUGH