sdl2-compat: updated after SDL3 version api changes.

From 4b1ddfd3f6d40fa172d3757157fec97b06c99845 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Wed, 15 May 2024 21:25:04 +0300
Subject: [PATCH] updated after SDL3 version api changes.

---
 src/dynapi/SDL_dynapi_procs.h |  2 +-
 src/sdl2_compat.c             | 25 ++++++++++++++-----------
 src/sdl2_compat.h             |  9 ++++++++-
 src/sdl2_protos.h             |  2 +-
 src/sdl3_syms.h               |  2 +-
 5 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 18e4600..23350e1 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -521,7 +521,7 @@ SDL_DYNAPI_PROC(int,SDL_GetNumTouchDevices,(void),(),return)
 SDL_DYNAPI_PROC(SDL_TouchID,SDL_GetTouchDevice,(int a),(a),return)
 SDL_DYNAPI_PROC(int,SDL_GetNumTouchFingers,(SDL_TouchID a),(a),return)
 SDL_DYNAPI_PROC(SDL_Finger*,SDL_GetTouchFinger,(SDL_TouchID a, int b),(a,b),return)
-SDL_DYNAPI_PROC(void,SDL_GetVersion,(SDL_Version *a),(a),)
+SDL_DYNAPI_PROC(void,SDL_GetVersion,(SDL2_version *a),(a),)
 SDL_DYNAPI_PROC(const char*,SDL_GetRevision,(void),(),return)
 SDL_DYNAPI_PROC(int,SDL_GetRevisionNumber,(void),(),return)
 SDL_DYNAPI_PROC(int,SDL_GetNumVideoDrivers,(void),(),return)
diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index b43956f..b38d974 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -199,7 +199,6 @@ do { \
 #include <SDL3/SDL_opengl_glext.h>
 
 static SDL_bool WantDebugLogging = SDL_FALSE;
-static Uint32 LinkedSDL3VersionInt = 0;
 
 
 static char *
@@ -598,19 +597,21 @@ LoadSDL3(void)
             #define SDL3_SYM(rc,fn,params,args,ret) SDL3_##fn = (SDL3_##fn##_t) LoadSDL3Symbol("SDL_" #fn, &okay);
             #include "sdl3_syms.h"
             if (okay) {
-                SDL_Version v;
-                SDL3_GetVersion(&v);
-                LinkedSDL3VersionInt = SDL_VERSIONNUM(v.major, v.minor, v.patch);
-                okay = (LinkedSDL3VersionInt >= SDL3_REQUIRED_VER);
+                const int sdl3version = SDL3_GetVersion();
+                const int sdl3major = SDL_VERSIONNUM_MAJOR(sdl3version);
+                const int sdl3minor = SDL_VERSIONNUM_MINOR(sdl3version);
+                const int sdl3micro = SDL_VERSIONNUM_MICRO(sdl3version);
+
+                okay = (sdl3version >= SDL3_REQUIRED_VER);
                 if (!okay) {
                     char value[12];
                     char *p = SDL2COMPAT_stpcpy(loaderror, "SDL3 ");
 
-                    SDL2COMPAT_itoa(value, v.major);
+                    SDL2COMPAT_itoa(value, sdl3major);
                     p = SDL2COMPAT_stpcpy(p, value); *p++ = '.';
-                    SDL2COMPAT_itoa(value, v.minor);
+                    SDL2COMPAT_itoa(value, sdl3minor);
                     p = SDL2COMPAT_stpcpy(p, value); *p++ = '.';
-                    SDL2COMPAT_itoa(value, v.patch);
+                    SDL2COMPAT_itoa(value, sdl3micro);
                     p = SDL2COMPAT_stpcpy(p, value);
 
                     SDL2COMPAT_stpcpy(p, " library is too old.");
@@ -618,9 +619,11 @@ LoadSDL3(void)
                     WantDebugLogging = SDL2Compat_GetHintBoolean("SDL2COMPAT_DEBUG_LOGGING", SDL_FALSE);
                     if (WantDebugLogging) {
                         #if defined(__DATE__) && defined(__TIME__)
-                        SDL3_Log("sdl2-compat 2.%d.%d, built on " __DATE__ " at " __TIME__ ", talking to SDL3 %d.%d.%d", SDL2_COMPAT_VERSION_MINOR, SDL2_COMPAT_VERSION_PATCH, v.major, v.minor, v.patch);
+                        SDL3_Log("sdl2-compat 2.%d.%d, built on " __DATE__ " at " __TIME__ ", talking to SDL3 %d.%d.%d",
+                                 SDL2_COMPAT_VERSION_MINOR, SDL2_COMPAT_VERSION_PATCH, sdl3major, sdl3minor, sdl3micro);
                         #else
-                        SDL3_Log("sdl2-compat 2.%d.%d, talking to SDL3 %d.%d.%d", SDL2_COMPAT_VERSION_MINOR, SDL2_COMPAT_VERSION_PATCH, v.major, v.minor, v.patch);
+                        SDL3_Log("sdl2-compat 2.%d.%d, talking to SDL3 %d.%d.%d",
+                                 SDL2_COMPAT_VERSION_MINOR, SDL2_COMPAT_VERSION_PATCH, sdl3major, sdl3minor, sdl3micro);
                         #endif
                     }
                     SDL2Compat_ApplyQuirks(force_x11);  /* Apply and maybe print a list of any enabled quirks. */
@@ -1308,7 +1311,7 @@ SDL2Compat_InitOnStartup(void)
 
 /* obviously we have to override this so we don't report ourselves as SDL3. */
 DECLSPEC void SDLCALL
-SDL_GetVersion(SDL_Version *ver)
+SDL_GetVersion(SDL2_version *ver)
 {
     if (ver) {
         ver->major = 2;
diff --git a/src/sdl2_compat.h b/src/sdl2_compat.h
index f50c12b..5b68684 100644
--- a/src/sdl2_compat.h
+++ b/src/sdl2_compat.h
@@ -217,6 +217,13 @@ typedef struct ID3D12Device ID3D12Device;
 typedef void (SDLCALL * SDL2_WindowsMessageHook)(void *userdata, void *hWnd, unsigned int message, Uint64 wParam, Sint64 lParam);
 #endif
 
+typedef struct SDL2_version
+{
+    Uint8 major;
+    Uint8 minor;
+    Uint8 patch;
+} SDL2_version;
+
 /* SDL2 SysWM mapping */
 typedef enum
 {
@@ -247,7 +254,7 @@ typedef struct _UIWindow UIWindow;
 
 struct SDL_SysWMinfo
 {
-    SDL_Version version;
+    SDL2_version version;
     SDL2_SYSWM_TYPE subsystem;
     union
     {
diff --git a/src/sdl2_protos.h b/src/sdl2_protos.h
index e912d7a..bbff88e 100644
--- a/src/sdl2_protos.h
+++ b/src/sdl2_protos.h
@@ -511,7 +511,7 @@ SDL2_PROTO(int,GetNumTouchDevices,(void))
 SDL2_PROTO(SDL_TouchID,GetTouchDevice,(int a))
 SDL2_PROTO(int,GetNumTouchFingers,(SDL_TouchID a))
 SDL2_PROTO(SDL_Finger*,GetTouchFinger,(SDL_TouchID a, int b))
-SDL2_PROTO(void,GetVersion,(SDL_Version *a))
+SDL2_PROTO(void,GetVersion,(SDL2_version *a))
 SDL2_PROTO(const char*,GetRevision,(void))
 SDL2_PROTO(int,GetRevisionNumber,(void))
 SDL2_PROTO(int,GetNumVideoDrivers,(void))
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 47be816..2cd718a 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -457,7 +457,7 @@ SDL3_SYM_PASSTHROUGH(SDL_TimerID,AddTimer,(Uint32 a, SDL_TimerCallback b, void *
 SDL3_SYM_PASSTHROUGH(SDL_bool,RemoveTimer,(SDL_TimerID a),(a),return)
 SDL3_SYM(SDL_TouchID*,GetTouchDevices,(int *a),(a),return)
 SDL3_SYM(SDL_Finger**,GetTouchFingers,(SDL_TouchID a, int *b),(a,b),return)
-SDL3_SYM(int,GetVersion,(SDL_Version *a),(a),return)
+SDL3_SYM(int,GetVersion,(void),(),return)
 SDL3_SYM_PASSTHROUGH(int,GetNumVideoDrivers,(void),(),return)
 SDL3_SYM(const char*,GetVideoDriver,(int a),(a),return)
 SDL3_SYM(const char*,GetCurrentVideoDriver,(void),(),return)