sdl2-compat: move SDL2 structures from sdl2_compat.c to sdl2_compat.h

From da9c9f6dc9a7170158255868bea0408a58037e0c Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Thu, 25 Jul 2024 18:11:04 +0300
Subject: [PATCH] move SDL2 structures from sdl2_compat.c to sdl2_compat.h

.. so that they can see SDL_begin_code.h. just in case..
---
 src/sdl2_compat.c | 546 +---------------------------------------------
 src/sdl2_compat.h | 529 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 537 insertions(+), 538 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 20ec601..e91a8aa 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -758,471 +758,6 @@ BOOL WINAPI _DllMainCRTStartup(HANDLE dllhandle, DWORD reason, LPVOID reserved)
     #error Please define an init procedure for your platform.
 #endif
 
-/* removed in SDL3 (no U16 audio formats supported) */
-#define SDL2_AUDIO_U16LSB 0x0010  /* Unsigned 16-bit samples */
-#define SDL2_AUDIO_U16MSB 0x1010  /* As above, but big-endian byte order */
-
-/* removed in SDL3 (which only uses SDL_WINDOW_HIDDEN now). */
-#define SDL2_WINDOW_SHOWN 0x000000004
-#define SDL2_WINDOW_FULLSCREEN_DESKTOP (0x00001000 | SDL_WINDOW_FULLSCREEN)
-#define SDL2_WINDOW_SKIP_TASKBAR 0x00010000
-
-/* removed in SDL3 (APIs like this were split into getter/setter functions). */
-#define SDL2_QUERY   -1
-#define SDL2_DISABLE  0
-#define SDL2_ENABLE   1
-
-/* changed values in SDL3 */
-#define SDL2_HAPTIC_CONSTANT   (1u<<0)
-#define SDL2_HAPTIC_SINE       (1u<<1)
-#define SDL2_HAPTIC_LEFTRIGHT     (1u<<2)
-#define SDL2_HAPTIC_TRIANGLE   (1u<<3)
-#define SDL2_HAPTIC_SAWTOOTHUP (1u<<4)
-#define SDL2_HAPTIC_SAWTOOTHDOWN (1u<<5)
-#define SDL2_HAPTIC_RAMP       (1u<<6)
-#define SDL2_HAPTIC_SPRING     (1u<<7)
-#define SDL2_HAPTIC_DAMPER     (1u<<8)
-#define SDL2_HAPTIC_INERTIA    (1u<<9)
-#define SDL2_HAPTIC_FRICTION   (1u<<10)
-#define SDL2_HAPTIC_CUSTOM     (1u<<11)
-#define SDL2_HAPTIC_GAIN       (1u<<12)
-#define SDL2_HAPTIC_AUTOCENTER (1u<<13)
-#define SDL2_HAPTIC_STATUS     (1u<<14)
-#define SDL2_HAPTIC_PAUSE      (1u<<15)
-
-#define SDL2_RENDERER_SOFTWARE      0x00000001
-#define SDL2_RENDERER_ACCELERATED   0x00000002
-#define SDL2_RENDERER_PRESENTVSYNC  0x00000004
-#define SDL2_RENDERER_TARGETTEXTURE 0x00000008
-
-/* Events changed in SDL3; notably, the `timestamp` field moved from
-   32 bit milliseconds to 64-bit nanoseconds, and the padding of the union
-   changed, so all the SDL2 structs have to be reproduced here. */
-
-/* Note that SDL_EventType _currently_ lines up; although some types have
-   come and gone in SDL3, so we don't manage an SDL2 copy here atm. */
-
-/* these were replaced in SDL3; all their subevents became top-level events. */
-/* These values are reserved in SDL3's SDL_EventType enum to help sdl2-compat. */
-#define SDL2_DISPLAYEVENT 0x150
-#define SDL2_WINDOWEVENT 0x200
-
-typedef struct SDL2_CommonEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-} SDL2_CommonEvent;
-
-/**
- *  \brief Display state change event data (event.display.*)
- */
-typedef struct SDL2_DisplayEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    Uint32 display;
-    Uint8 event;
-    Uint8 padding1;
-    Uint8 padding2;
-    Uint8 padding3;
-    Sint32 data1;
-} SDL2_DisplayEvent;
-
-typedef struct SDL2_WindowEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    Uint32 windowID;
-    Uint8 event;
-    Uint8 padding1;
-    Uint8 padding2;
-    Uint8 padding3;
-    Sint32 data1;
-    Sint32 data2;
-} SDL2_WindowEvent;
-
-typedef struct SDL2_KeyboardEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    Uint32 windowID;
-    Uint8 state;
-    Uint8 repeat;
-    Uint8 padding2;
-    Uint8 padding3;
-    SDL2_Keysym keysym;
-} SDL2_KeyboardEvent;
-
-#define SDL2_TEXTEDITINGEVENT_TEXT_SIZE (32)
-typedef struct SDL2_TextEditingEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    Uint32 windowID;
-    char text[SDL2_TEXTEDITINGEVENT_TEXT_SIZE];
-    Sint32 start;
-    Sint32 length;
-} SDL2_TextEditingEvent;
-
-#define SDL2_TEXTEDITING_EXT 0x305
-typedef struct SDL2_TextEditingExtEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    Uint32 windowID;
-    char* text;
-    Sint32 start;
-    Sint32 length;
-} SDL2_TextEditingExtEvent;
-
-#define SDL2_TEXTINPUTEVENT_TEXT_SIZE (32)
-typedef struct SDL2_TextInputEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    Uint32 windowID;
-    char text[SDL2_TEXTINPUTEVENT_TEXT_SIZE];
-} SDL2_TextInputEvent;
-
-typedef struct SDL2_MouseMotionEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    Uint32 windowID;
-    Uint32 which;
-    Uint32 state;
-    Sint32 x;
-    Sint32 y;
-    Sint32 xrel;
-    Sint32 yrel;
-} SDL2_MouseMotionEvent;
-
-typedef struct SDL2_MouseButtonEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    Uint32 windowID;
-    Uint32 which;
-    Uint8 button;
-    Uint8 state;
-    Uint8 clicks;
-    Uint8 padding1;
-    Sint32 x;
-    Sint32 y;
-} SDL2_MouseButtonEvent;
-
-typedef struct SDL2_MouseWheelEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    Uint32 windowID;
-    Uint32 which;
-    Sint32 x;
-    Sint32 y;
-    Uint32 direction;
-    float preciseX;
-    float preciseY;
-    Sint32 mouseX;
-    Sint32 mouseY;
-} SDL2_MouseWheelEvent;
-
-typedef struct SDL2_JoyAxisEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    SDL2_JoystickID which;
-    Uint8 axis;
-    Uint8 padding1;
-    Uint8 padding2;
-    Uint8 padding3;
-    Sint16 value;
-    Uint16 padding4;
-} SDL2_JoyAxisEvent;
-
-typedef struct SDL2_JoyBallEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    SDL2_JoystickID which;
-    Uint8 ball;
-    Uint8 padding1;
-    Uint8 padding2;
-    Uint8 padding3;
-    Sint16 xrel;
-    Sint16 yrel;
-} SDL2_JoyBallEvent;
-
-typedef struct SDL2_JoyHatEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    SDL2_JoystickID which;
-    Uint8 hat;
-    Uint8 value;
-    Uint8 padding1;
-    Uint8 padding2;
-} SDL2_JoyHatEvent;
-
-typedef struct SDL2_JoyButtonEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    SDL2_JoystickID which;
-    Uint8 button;
-    Uint8 state;
-    Uint8 padding1;
-    Uint8 padding2;
-} SDL2_JoyButtonEvent;
-
-typedef struct SDL2_JoyDeviceEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    Sint32 which;
-} SDL2_JoyDeviceEvent;
-
-typedef struct SDL2_JoyBatteryEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    SDL2_JoystickID which;
-    SDL_JoystickPowerLevel level;
-} SDL2_JoyBatteryEvent;
-
-typedef struct SDL2_ControllerAxisEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    SDL2_JoystickID which;
-    Uint8 axis;
-    Uint8 padding1;
-    Uint8 padding2;
-    Uint8 padding3;
-    Sint16 value;
-    Uint16 padding4;
-} SDL2_ControllerAxisEvent;
-
-typedef struct SDL2_ControllerButtonEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    SDL2_JoystickID which;
-    Uint8 button;
-    Uint8 state;
-    Uint8 padding1;
-    Uint8 padding2;
-} SDL2_ControllerButtonEvent;
-
-typedef struct SDL2_ControllerDeviceEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    Sint32 which;
-} SDL2_ControllerDeviceEvent;
-
-typedef struct SDL2_ControllerTouchpadEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    SDL2_JoystickID which;
-    Sint32 touchpad;
-    Sint32 finger;
-    float x;
-    float y;
-    float pressure;
-} SDL2_ControllerTouchpadEvent;
-
-typedef struct SDL2_ControllerSensorEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    SDL2_JoystickID which;
-    Sint32 sensor;
-    float data[3];
-    Uint64 timestamp_us;
-} SDL2_ControllerSensorEvent;
-
-typedef struct SDL2_AudioDeviceEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    Uint32 which;
-    Uint8 iscapture;
-    Uint8 padding1;
-    Uint8 padding2;
-    Uint8 padding3;
-} SDL2_AudioDeviceEvent;
-
-typedef struct SDL2_TouchFingerEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    SDL_TouchID touchId;
-    SDL_FingerID fingerId;
-    float x;
-    float y;
-    float dx;
-    float dy;
-    float pressure;
-    Uint32 windowID;
-} SDL2_TouchFingerEvent;
-
-#define SDL_DOLLARGESTURE 0x800
-#define SDL_DOLLARRECORD 0x801
-#define SDL_MULTIGESTURE 0x802
-
-typedef struct SDL2_MultiGestureEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    SDL_TouchID touchId;
-    float dTheta;
-    float dDist;
-    float x;
-    float y;
-    Uint16 numFingers;
-    Uint16 padding;
-} SDL2_MultiGestureEvent;
-
-typedef struct SDL2_DollarGestureEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    SDL_TouchID touchId;
-    SDL2_GestureID gestureId;
-    Uint32 numFingers;
-    float error;
-    float x;
-    float y;
-} SDL2_DollarGestureEvent;
-
-typedef struct SDL2_DropEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    char *file;
-    Uint32 windowID;
-} SDL2_DropEvent;
-
-typedef struct SDL2_SensorEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    Sint32 which;
-    float data[6];
-    Uint64 timestamp_us;
-} SDL2_SensorEvent;
-
-typedef struct SDL2_QuitEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-} SDL2_QuitEvent;
-
-typedef struct SDL2_OSEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-} SDL2_OSEvent;
-
-typedef struct SDL2_UserEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    Uint32 windowID;
-    Sint32 code;
-    void *data1;
-    void *data2;
-} SDL2_UserEvent;
-
-struct SDL2_SysWMmsg;
-typedef struct SDL2_SysWMmsg SDL2_SysWMmsg;
-
-typedef struct SDL2_SysWMEvent
-{
-    Uint32 type;
-    Uint32 timestamp;
-    SDL2_SysWMmsg *msg;
-} SDL2_SysWMEvent;
-
-union SDL2_Event
-{
-    Uint32 type;
-    SDL2_CommonEvent common;
-    SDL2_DisplayEvent display;
-    SDL2_WindowEvent window;
-    SDL2_KeyboardEvent key;
-    SDL2_TextEditingEvent edit;
-    SDL2_TextEditingExtEvent editExt;
-    SDL2_TextInputEvent text;
-    SDL2_MouseMotionEvent motion;
-    SDL2_MouseButtonEvent button;
-    SDL2_MouseWheelEvent wheel;
-    SDL2_JoyAxisEvent jaxis;
-    SDL2_JoyBallEvent jball;
-    SDL2_JoyHatEvent jhat;
-    SDL2_JoyButtonEvent jbutton;
-    SDL2_JoyDeviceEvent jdevice;
-    SDL2_JoyBatteryEvent jbattery;
-    SDL2_ControllerAxisEvent caxis;
-    SDL2_ControllerButtonEvent cbutton;
-    SDL2_ControllerDeviceEvent cdevice;
-    SDL2_ControllerTouchpadEvent ctouchpad;
-    SDL2_ControllerSensorEvent csensor;
-    SDL2_AudioDeviceEvent adevice;
-    SDL2_SensorEvent sensor;
-    SDL2_QuitEvent quit;
-    SDL2_UserEvent user;
-    SDL2_SysWMEvent syswm;
-    SDL2_TouchFingerEvent tfinger;
-    SDL2_MultiGestureEvent mgesture;
-    SDL2_DollarGestureEvent dgesture;
-    SDL2_DropEvent drop;
-    Uint8 padding[sizeof(void *) <= 8 ? 56 : sizeof(void *) == 16 ? 64 : 3 * sizeof(void *)];
-};
-
-/* Make sure we haven't broken binary compatibility */
-SDL_COMPILE_TIME_ASSERT(SDL2_Event, sizeof(SDL2_Event) == sizeof(((SDL2_Event *)NULL)->padding));
-
-typedef struct EventFilterWrapperData
-{
-    SDL2_EventFilter filter2;
-    void *userdata;
-    struct EventFilterWrapperData *next;
-} EventFilterWrapperData;
-
-
-/* SDL3 added a bus_type field we need to workaround. */
-struct SDL2_hid_device_info
-{
-    char *path;
-    unsigned short vendor_id;
-    unsigned short product_id;
-    wchar_t *serial_number;
-    unsigned short release_number;
-    wchar_t *manufacturer_string;
-    wchar_t *product_string;
-    unsigned short usage_page;
-    unsigned short usage;
-    int interface_number;
-    int interface_class;
-    int interface_subclass;
-    int interface_protocol;
-    struct SDL2_hid_device_info *next;
-};
-
-typedef struct AudioDeviceInfo
-{
-    SDL_AudioDeviceID devid;
-    char *name;
-} AudioDeviceInfo;
-
-typedef struct AudioDeviceList
-{
-    AudioDeviceInfo *devices;
-    int num_devices;
-} AudioDeviceList;
-
 
 /* Some SDL2 state we need to keep... */
 
@@ -1243,6 +778,18 @@ static int num_haptics = 0;
 static SDL_mutex *joystick_lock = NULL;
 static SDL_mutex *sensor_lock = NULL;
 
+typedef struct AudioDeviceInfo
+{
+    SDL_AudioDeviceID devid;
+    char *name;
+} AudioDeviceInfo;
+
+typedef struct AudioDeviceList
+{
+    AudioDeviceInfo *devices;
+    int num_devices;
+} AudioDeviceList;
+
 static SDL_Mutex *AudioDeviceLock = NULL;
 static SDL2_AudioStream *AudioOpenDevices[16];  /* SDL2 had a limit of 16 simultaneous devices opens (and the first slot was for the 1.2 legacy interface). We track these as _SDL2_ audio streams. */
 static AudioDeviceList AudioSDL3PlaybackDevices;
@@ -2346,66 +1893,6 @@ SDL_WarpMouseGlobal(int x, int y)
     return SDL3_WarpMouseGlobal((float)x, (float)y);
 }
 
-/* The SDL3 version of SDL_RWops (SDL_IOStream!) changed, so we need to convert when necessary. */
-
-#define SDL_RWOPS_UNKNOWN   0   /**< Unknown stream type */
-#define SDL_RWOPS_WINFILE   1   /**< Win32 file */
-#define SDL_RWOPS_STDFILE   2   /**< Stdio file */
-#define SDL_RWOPS_JNIFILE   3   /**< Android asset */
-#define SDL_RWOPS_MEMORY    4   /**< Memory stream */
-#define SDL_RWOPS_MEMORY_RO 5   /**< Read-Only memory stream */
-
-#if (defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)) && !defined(SDL_PLATFORM_WINRT)
-#define SDL_RWOPS_PLATFORM_FILE SDL_RWOPS_WINFILE
-#elif defined(SDL_PLATFORM_ANDROID)
-#define SDL_RWOPS_PLATFORM_FILE SDL_RWOPS_JNIFILE
-#else
-#define SDL_RWOPS_PLATFORM_FILE SDL_RWOPS_STDFILE
-#endif
-
-struct SDL2_RWops
-{
-    Sint64 (SDLCALL * size) (struct SDL2_RWops *ctx);
-    Sint64 (SDLCALL * seek) (struct SDL2_RWops *ctx, Sint64 offset, int whence);
-    size_t (SDLCALL * read) (struct SDL2_RWops *ctx, void *ptr, size_t size, size_t maxnum);
-    size_t (SDLCALL * write) (struct SDL2_RWops *ctx, const void *ptr, size_t size, size_t num);
-    int (SDLCALL * close) (struct SDL2_RWops *ctx);
-    Uint32 type;
-    union
-    {
-        struct {
-            SDL_bool autoclose;
-            void *fp;
-        } stdio;
-        struct
-        {
-            void *asset;
-        } androidio;
-        struct
-        {
-            SDL_bool append;
-            void *h;
-            struct
-            {
-                void *data;
-                size_t size;
-                size_t left;
-            } buffer;
-        } windowsio;
-        struct {
-            void *data1;
-            void *data2;
-        } unknown;
-        struct {
-            void *padding1;
-            void *padding2;
-            SDL_IOStream *iostrm;
-        } sdl3;
-        struct {
-            void *ptrs[3];  /* just so this matches SDL2's struct size. */
-        } match_sdl2;
-    } hidden;
-};
 
 SDL_DECLSPEC SDL2_RWops *SDLCALL
 SDL_AllocRW(void)
@@ -6336,15 +5823,6 @@ SDL_UnlockSensors(void)
 }
 
 
-struct SDL2_DisplayMode
-{
-    Uint32 format;              /**< pixel format */
-    int w;                      /**< width, in screen coordinates */
-    int h;                      /**< height, in screen coordinates */
-    int refresh_rate;           /**< refresh rate (or zero for unspecified) */
-    void *driverdata;           /**< driver-specific data, initialize to 0 */
-};
-
 static void
 DisplayMode_2to3(const SDL2_DisplayMode *in, SDL_DisplayMode *out) {
     if (in && out) {
diff --git a/src/sdl2_compat.h b/src/sdl2_compat.h
index bd4fe1e..b12cbed 100644
--- a/src/sdl2_compat.h
+++ b/src/sdl2_compat.h
@@ -32,6 +32,60 @@ typedef enum
 } SDL2_DUMMY_ENUM;
 SDL_COMPILE_TIME_ASSERT(SDL23bool, sizeof(SDL2_DUMMY_ENUM) == sizeof(SDL_bool));
 
+/* removed in SDL3 (which only uses SDL_WINDOW_HIDDEN now). */
+#define SDL2_WINDOW_SHOWN 0x000000004
+#define SDL2_WINDOW_FULLSCREEN_DESKTOP (0x00001000 | SDL_WINDOW_FULLSCREEN)
+#define SDL2_WINDOW_SKIP_TASKBAR 0x00010000
+
+/* removed in SDL3 (APIs like this were split into getter/setter functions). */
+#define SDL2_QUERY   -1
+#define SDL2_DISABLE  0
+#define SDL2_ENABLE   1
+
+/* changed values in SDL3 */
+#define SDL2_HAPTIC_CONSTANT   (1u<<0)
+#define SDL2_HAPTIC_SINE       (1u<<1)
+#define SDL2_HAPTIC_LEFTRIGHT     (1u<<2)
+#define SDL2_HAPTIC_TRIANGLE   (1u<<3)
+#define SDL2_HAPTIC_SAWTOOTHUP (1u<<4)
+#define SDL2_HAPTIC_SAWTOOTHDOWN (1u<<5)
+#define SDL2_HAPTIC_RAMP       (1u<<6)
+#define SDL2_HAPTIC_SPRING     (1u<<7)
+#define SDL2_HAPTIC_DAMPER     (1u<<8)
+#define SDL2_HAPTIC_INERTIA    (1u<<9)
+#define SDL2_HAPTIC_FRICTION   (1u<<10)
+#define SDL2_HAPTIC_CUSTOM     (1u<<11)
+#define SDL2_HAPTIC_GAIN       (1u<<12)
+#define SDL2_HAPTIC_AUTOCENTER (1u<<13)
+#define SDL2_HAPTIC_STATUS     (1u<<14)
+#define SDL2_HAPTIC_PAUSE      (1u<<15)
+
+#define SDL2_RENDERER_SOFTWARE      0x00000001
+#define SDL2_RENDERER_ACCELERATED   0x00000002
+#define SDL2_RENDERER_PRESENTVSYNC  0x00000004
+#define SDL2_RENDERER_TARGETTEXTURE 0x00000008
+
+
+/* SDL3 added a bus_type field, we need to workaround. */
+typedef struct SDL2_hid_device_info
+{
+    char *path;
+    unsigned short vendor_id;
+    unsigned short product_id;
+    wchar_t *serial_number;
+    unsigned short release_number;
+    wchar_t *manufacturer_string;
+    wchar_t *product_string;
+    unsigned short usage_page;
+    unsigned short usage;
+    int interface_number;
+    int interface_class;
+    int interface_subclass;
+    int interface_protocol;
+    struct SDL2_hid_device_info *next;
+} SDL2_hid_device_info;
+
+
 /* these types were removed from / renamed in SDL3. We need them for SDL2 APIs exported here. */
 
 typedef int SDL2_Keymod; /* actually this is an enum in real SDL2 */
@@ -107,11 +161,78 @@ typedef Sint32 SDL2_SensorID;  /* this became unsigned in SDL3, but we'll just h
 
 typedef Sint64 SDL2_GestureID;
 
-typedef struct SDL2_RWops SDL2_RWops;
-typedef struct SDL2_DisplayMode SDL2_DisplayMode;
+
+/* The SDL3 version of SDL_RWops (SDL_IOStream!) changed, so we need to convert when necessary. */
+
+#define SDL_RWOPS_UNKNOWN   0   /**< Unknown stream type */
+#define SDL_RWOPS_WINFILE   1   /**< Win32 file */
+#define SDL_RWOPS_STDFILE   2   /**< Stdio file */
+#define SDL_RWOPS_JNIFILE   3   /**< Android asset */
+#define SDL_RWOPS_MEMORY    4   /**< Memory stream */
+#define SDL_RWOPS_MEMORY_RO 5   /**< Read-Only memory stream */
+
+#if (defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)) && !defined(SDL_PLATFORM_WINRT)
+#define SDL_RWOPS_PLATFORM_FILE SDL_RWOPS_WINFILE
+#elif defined(SDL_PLATFORM_ANDROID)
+#define SDL_RWOPS_PLATFORM_FILE SDL_RWOPS_JNIFILE
+#else
+#define SDL_RWOPS_PLATFORM_FILE SDL_RWOPS_STDFILE
+#endif
+
+typedef struct SDL2_RWops
+{
+    Sint64 (SDLCALL * size) (struct SDL2_RWops *ctx);
+    Sint64 (SDLCALL * seek) (struct SDL2_RWops *ctx, Sint64 offset, int whence);
+    size_t (SDLCALL * read) (struct SDL2_RWops *ctx, void *ptr, size_t size, size_t maxnum);
+    size_t (SDLCALL * write) (struct SDL2_RWops *ctx, const void *ptr, size_t size, size_t num);
+    int (SDLCALL * close) (struct SDL2_RWops *ctx);
+    Uint32 type;
+    union
+    {
+        struct {
+            SDL_bool autoclose;
+            void *fp;
+        } stdio;
+        struct
+        {
+            void *asset;
+        } androidio;
+        struct
+        {
+            SDL_bool append;
+            void *h;
+            struct
+            {
+                void *data;
+                size_t size;
+                size_t left;
+            } buffer;
+        } windowsio;
+        struct {
+            void *data1;
+            void *data2;
+        } unknown;
+        struct {
+            void *padding1;
+            void *padding2;
+            SDL_IOStream *iostrm;
+        } sdl3;
+        struct {
+            void *ptrs[3];  /* just so this matches SDL2's struct size. */
+        } match_sdl2;
+    } hidden;
+} SDL2_RWops;
 
 
-typedef struct SDL2_hid_device_info SDL2_hid_device_info;
+typedef struct SDL2_DisplayMode
+{
+    Uint32 format;              /**< pixel format */
+    int w;                      /**< width, in screen coordinates */
+    int h;                      /**< height, in screen coordinates */
+    int refresh_rate;           /**< refresh rate (or zero for unspecified) */
+    void *driverdata;           /**< driver-specific data, initialize to 0 */
+} SDL2_DisplayMode;
+
 
 typedef enum SDL2_Scancode
 {
@@ -514,10 +635,410 @@ typedef struct SDL2_Keysym
     Uint16 raw;
 } SDL2_Keysym;
 
+
+/* Events changed in SDL3; notably, the `timestamp` field moved from
+   32 bit milliseconds to 64-bit nanoseconds, and the padding of the union
+   changed, so all the SDL2 structs have to be reproduced here. */
+
+/* Note that SDL_EventType _currently_ lines up; although some types have
+   come and gone in SDL3, so we don't manage an SDL2 copy here atm. */
+
+/* these were replaced in SDL3; all their subevents became top-level events. */
+/* These values are reserved in SDL3's SDL_EventType enum to help sdl2-compat. */
+#define SDL2_DISPLAYEVENT 0x150
+#define SDL2_WINDOWEVENT 0x200
+
+typedef struct SDL2_CommonEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+} SDL2_CommonEvent;
+
+/**
+ *  \brief Display state change event data (event.display.*)
+ */
+typedef struct SDL2_DisplayEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    Uint32 display;
+    Uint8 event;
+    Uint8 padding1;
+    Uint8 padding2;
+    Uint8 padding3;
+    Sint32 data1;
+} SDL2_DisplayEvent;
+
+typedef struct SDL2_WindowEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    Uint32 windowID;
+    Uint8 event;
+    Uint8 padding1;
+    Uint8 padding2;
+    Uint8 padding3;
+    Sint32 data1;
+    Sint32 data2;
+} SDL2_WindowEvent;
+
+typedef struct SDL2_KeyboardEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    Uint32 windowID;
+    Uint8 state;
+    Uint8 repeat;
+    Uint8 padding2;
+    Uint8 padding3;
+    SDL2_Keysym keysym;
+} SDL2_KeyboardEvent;
+
+#define SDL2_TEXTEDITINGEVENT_TEXT_SIZE (32)
+typedef struct SDL2_TextEditingEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    Uint32 windowID;
+    char text[SDL2_TEXTEDITINGEVENT_TEXT_SIZE];
+    Sint32 start;
+    Sint32 length;
+} SDL2_TextEditingEvent;
+
+#define SDL2_TEXTEDITING_EXT 0x305
+typedef struct SDL2_TextEditingExtEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    Uint32 windowID;
+    char* text;
+    Sint32 start;
+    Sint32 length;
+} SDL2_TextEditingExtEvent;
+
+#define SDL2_TEXTINPUTEVENT_TEXT_SIZE (32)
+typedef struct SDL2_TextInputEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    Uint32 windowID;
+    char text[SDL2_TEXTINPUTEVENT_TEXT_SIZE];
+} SDL2_TextInputEvent;
+
+typedef struct SDL2_MouseMotionEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    Uint32 windowID;
+    Uint32 which;
+    Uint32 state;
+    Sint32 x;
+    Sint32 y;
+    Sint32 xrel;
+    Sint32 yrel;
+} SDL2_MouseMotionEvent;
+
+typedef struct SDL2_MouseButtonEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    Uint32 windowID;
+    Uint32 which;
+    Uint8 button;
+    Uint8 state;
+    Uint8 clicks;
+    Uint8 padding1;
+    Sint32 x;
+    Sint32 y;
+} SDL2_MouseButtonEvent;
+
+typedef struct SDL2_MouseWheelEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    Uint32 windowID;
+    Uint32 which;
+    Sint32 x;
+    Sint32 y;
+    Uint32 direction;
+    float preciseX;
+    float preciseY;
+    Sint32 mouseX;
+    Sint32 mouseY;
+} SDL2_MouseWheelEvent;
+
+typedef struct SDL2_JoyAxisEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    SDL2_JoystickID which;
+    Uint8 axis;
+    Uint8 padding1;
+    Uint8 padding2;
+    Uint8 padding3;
+    Sint16 value;
+    Uint16 padding4;
+} SDL2_JoyAxisEvent;
+
+typedef struct SDL2_JoyBallEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    SDL2_JoystickID which;
+    Uint8 ball;
+    Uint8 padding1;
+    Uint8 padding2;
+    Uint8 padding3;
+    Sint16 xrel;
+    Sint16 yrel;
+} SDL2_JoyBallEvent;
+
+typedef struct SDL2_JoyHatEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    SDL2_JoystickID which;
+    Uint8 hat;
+    Uint8 value;
+    Uint8 padding1;
+    Uint8 padding2;
+} SDL2_JoyHatEvent;
+
+typedef struct SDL2_JoyButtonEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    SDL2_JoystickID which;
+    Uint8 button;
+    Uint8 state;
+    Uint8 padding1;
+    Uint8 padding2;
+} SDL2_JoyButtonEvent;
+
+typedef struct SDL2_JoyDeviceEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    Sint32 which;
+} SDL2_JoyDeviceEvent;
+
+typedef struct SDL2_JoyBatteryEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    SDL2_JoystickID which;
+    SDL_JoystickPowerLevel level;
+} SDL2_JoyBatteryEvent;
+
+typedef struct SDL2_ControllerAxisEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    SDL2_JoystickID which;
+    Uint8 axis;
+    Uint8 padding1;
+    Uint8 padding2;
+    Uint8 padding3;
+    Sint16 value;
+    Uint16 padding4;
+} SDL2_ControllerAxisEvent;
+
+typedef struct SDL2_ControllerButtonEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    SDL2_JoystickID which;
+    Uint8 button;
+    Uint8 state;
+    Uint8 padding1;
+    Uint8 padding2;
+} SDL2_ControllerButtonEvent;
+
+typedef struct SDL2_ControllerDeviceEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    Sint32 which;
+} SDL2_ControllerDeviceEvent;
+
+typedef struct SDL2_ControllerTouchpadEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    SDL2_JoystickID which;
+    Sint32 touchpad;
+    Sint32 finger;
+    float x;
+    float y;
+    float pressure;
+} SDL2_ControllerTouchpadEvent;
+
+typedef struct SDL2_ControllerSensorEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    SDL2_JoystickID which;
+    Sint32 sensor;
+    float data[3];
+    Uint64 timestamp_us;
+} SDL2_ControllerSensorEvent;
+
+typedef struct SDL2_AudioDeviceEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    Uint32 which;
+    Uint8 iscapture;
+    Uint8 padding1;
+    Uint8 padding2;
+    Uint8 padding3;
+} SDL2_AudioDeviceEvent;
+
+typedef struct SDL2_TouchFingerEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    SDL_TouchID touchId;
+    SDL_FingerID fingerId;
+    float x;
+    float y;
+    float dx;
+    float dy;
+    float pressure;
+    Uint32 windowID;
+} SDL2_TouchFingerEvent;
+
+#define SDL_DOLLARGESTURE 0x800
+#define SDL_DOLLARRECORD 0x801
+#define SDL_MULTIGESTURE 0x802
+
+typedef struct SDL2_MultiGestureEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    SDL_TouchID touchId;
+    float dTheta;
+    float dDist;
+    float x;
+    float y;
+    Uint16 numFingers;
+    Uint16 padding;
+} SDL2_MultiGestureEvent;
+
+typedef struct SDL2_DollarGestureEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    SDL_TouchID touchId;
+    SDL2_GestureID gestureId;
+    Uint32 numFingers;
+    float error;
+    float x;
+    float y;
+} SDL2_DollarGestureEvent;
+
+typedef struct SDL2_DropEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    char *file;
+    Uint32 windowID;
+} SDL2_DropEvent;
+
+typedef struct SDL2_SensorEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    Sint32 which;
+    float data[6];
+    Uint64 timestamp_us;
+} SDL2_SensorEvent;
+
+typedef struct SDL2_QuitEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+} SDL2_QuitEvent;
+
+typedef struct SDL2_OSEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+} SDL2_OSEvent;
+
+typedef struct SDL2_UserEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    Uint32 windowID;
+    Sint32 code;
+    void *data1;
+    void *data2;
+} SDL2_UserEvent;
+
+struct SDL2_SysWMmsg;
+typedef struct SDL2_SysWMmsg SDL2_SysWMmsg;
+
+typedef struct SDL2_SysWMEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+    SDL2_SysWMmsg *msg;
+} SDL2_SysWMEvent;
+
+typedef union SDL2_Event
+{
+    Uint32 type;
+    SDL2_CommonEvent common;
+    SDL2_DisplayEvent display;
+    SDL2_WindowEvent window;
+    SDL2_KeyboardEvent key;
+    SDL2_TextEditingEvent edit;
+    SDL2_TextEditingExtEvent editExt;
+    SDL2_TextInputEvent text;
+    SDL2_MouseMotionEvent motion;
+    SDL2_MouseButtonEvent button;
+    SDL2_MouseWheelEvent wheel;
+    SDL2_JoyAxisEvent jaxis;
+    SDL2_JoyBallEvent jball;
+    SDL2_JoyHatEvent jhat;
+    SDL2_JoyButtonEvent jbutton;
+    SDL2_JoyDeviceEvent jdevice;
+    SDL2_JoyBatteryEvent jbattery;
+    SDL2_ControllerAxisEvent caxis;
+    SDL2_ControllerButtonEvent cbutton;
+    SDL2_ControllerDeviceEvent cdevice;
+    SDL2_ControllerTouchpadEvent ctouchpad;
+    SDL2_ControllerSensorEvent csensor;
+    SDL2_AudioDeviceEvent adevice;
+    SDL2_SensorEvent sensor;
+    SDL2_QuitEvent quit;
+    SDL2_UserEvent user;
+    SDL2_SysWMEvent syswm;
+    SDL2_TouchFingerEvent tfinger;
+    SDL2_MultiGestureEvent mgesture;
+    SDL2_DollarGestureEvent dgesture;
+    SDL2_DropEvent drop;
+    Uint8 padding[sizeof(void *) <= 8 ? 56 : sizeof(void *) == 16 ? 64 : 3 * sizeof(void *)];
+} SDL2_Event;
+
+/* Make sure we haven't broken binary compatibility */
+SDL_COMPILE_TIME_ASSERT(SDL2_Event, sizeof(SDL2_Event) == sizeof(((SDL2_Event *)NULL)->padding));
+
 typedef SDL_EventAction SDL_eventaction;
-typedef union SDL2_Event SDL2_Event;
 typedef int (SDLCALL *SDL2_EventFilter) (void *userdata, SDL2_Event *event);
 
+typedef struct EventFilterWrapperData
+{
+    SDL2_EventFilter filter2;
+    void *userdata;
+    struct EventFilterWrapperData *next;
+} EventFilterWrapperData;
+
+/* removed in SDL3 (no U16 audio formats supported) */
+#define SDL2_AUDIO_U16LSB 0x0010  /* Unsigned 16-bit samples */
+#define SDL2_AUDIO_U16MSB 0x1010  /* As above, but big-endian byte order */
+
 typedef Uint16 SDL2_AudioFormat;
 
 struct SDL_AudioCVT;