sdl2-compat: move shared SDL2 types to sdl2_compat.h

From 5f8ae97b2d773837d2ee5558a811ac5272e8f5e9 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Thu, 12 Jan 2023 10:01:02 +0300
Subject: [PATCH] move shared SDL2 types to sdl2_compat.h

---
 src/dynapi/SDL_dynapi.c       | 10 +--------
 src/dynapi/SDL_dynapi_procs.h |  2 +-
 src/sdl2_compat.c             | 13 +-----------
 src/sdl2_compat.h             | 38 +++++++++++++++++++++++++++++++++++
 4 files changed, 41 insertions(+), 22 deletions(-)
 create mode 100644 src/sdl2_compat.h

diff --git a/src/dynapi/SDL_dynapi.c b/src/dynapi/SDL_dynapi.c
index 3bcd8b0..3efce01 100644
--- a/src/dynapi/SDL_dynapi.c
+++ b/src/dynapi/SDL_dynapi.c
@@ -20,6 +20,7 @@
 */
 
 #include "../sdl3_include_wrapper.h"
+#include "../sdl2_compat.h"
 
 #include "SDL_dynapi.h"
 
@@ -27,15 +28,6 @@
 
 #define SDL_DYNAMIC_API_ENVVAR "SDL_DYNAMIC_API"
 
-/* sdl2-compat: these types were removed from SDL3, but we need them for SDL2 APIs exported here. */
-typedef Sint64 SDL_GestureID;
-typedef SDL_Gamepad SDL_GameController;  /* since they're opaque types, for simplicity we just typedef it here and use the old types in sdl3_syms.h */
-typedef SDL_GamepadAxis SDL_GameControllerAxis;
-typedef SDL_GamepadBinding SDL_GameControllerButtonBind;
-typedef SDL_GamepadButton SDL_GameControllerButton;
-typedef SDL_GamepadType SDL_GameControllerType;
-
-
 #if defined(__OS2__)
 #define INCL_DOS
 #define INCL_DOSERRORS
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 5469300..b4b8234 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -188,7 +188,7 @@ SDL_DYNAPI_PROC(Uint8,SDL_GameControllerGetButton,(SDL_GameController *a, SDL_Ga
 SDL_DYNAPI_PROC(void,SDL_GameControllerClose,(SDL_GameController *a),(a),)
 SDL_DYNAPI_PROC(int,SDL_RecordGesture,(SDL_TouchID a),(a),return)
 SDL_DYNAPI_PROC(int,SDL_SaveAllDollarTemplates,(SDL_RWops *a),(a),return)
-SDL_DYNAPI_PROC(int,SDL_SaveDollarTemplate,(SDL_GestureID a, SDL_RWops *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_SaveDollarTemplate,(SDL2_GestureID a, SDL_RWops *b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_LoadDollarTemplates,(SDL_TouchID a, SDL_RWops *b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_NumHaptics,(void),(),return)
 SDL_DYNAPI_PROC(const char*,SDL_HapticName,(int a),(a),return)
diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 60509af..ca28208 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -22,7 +22,7 @@
 /* This file contains functions for backwards compatibility with SDL2 */
 
 #include "sdl3_include_wrapper.h"
-
+#include "sdl2_compat.h"
 #include "dynapi/SDL_dynapi.h"
 
 
@@ -105,17 +105,6 @@ This breaks the build when creating SDL_ ## DisableScreenSaver
 extern "C" {
 #endif
 
-typedef SDL_Gamepad SDL_GameController;  /* since they're opaque types, for simplicity we just typedef it here and use the old types in sdl3_syms.h */
-typedef SDL_GamepadAxis SDL_GameControllerAxis;
-typedef SDL_GamepadBinding SDL_GameControllerButtonBind;
-typedef SDL_GamepadButton SDL_GameControllerButton;
-typedef SDL_GamepadType SDL_GameControllerType;
-
-typedef Sint32 SDL2_JoystickID;  /* this became unsigned in SDL3, but we'll just hope we don't overflow. */
-typedef Sint32 SDL2_SensorID;  /* this became unsigned in SDL3, but we'll just hope we don't overflow. */
-
-typedef Sint64 SDL2_GestureID;
-
 #define SDL3_SYM(rc,fn,params,args,ret) \
     typedef rc (SDLCALL *SDL3_##fn##_t) params; \
     static SDL3_##fn##_t SDL3_##fn = NULL;
diff --git a/src/sdl2_compat.h b/src/sdl2_compat.h
new file mode 100644
index 0000000..6097e7c
--- /dev/null
+++ b/src/sdl2_compat.h
@@ -0,0 +1,38 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef sdl2_compat_h
+#define sdl2_compat_h
+
+/* these types were removed from SDL3, but we need them for SDL2 APIs exported here. */
+
+typedef SDL_Gamepad SDL_GameController;  /* since they're opaque types, for simplicity we just typedef it here and use the old types in sdl3_syms.h */
+typedef SDL_GamepadAxis SDL_GameControllerAxis;
+typedef SDL_GamepadBinding SDL_GameControllerButtonBind;
+typedef SDL_GamepadButton SDL_GameControllerButton;
+typedef SDL_GamepadType SDL_GameControllerType;
+
+typedef Sint32 SDL2_JoystickID;  /* this became unsigned in SDL3, but we'll just hope we don't overflow. */
+typedef Sint32 SDL2_SensorID;  /* this became unsigned in SDL3, but we'll just hope we don't overflow. */
+
+typedef Sint64 SDL2_GestureID;
+
+#endif /* sdl2_compat_h */