sdl12-compat: Added a special API function to get access to the SDL 2.0 window

From e7cf61ec93f0968dc94ae48c42181b057e74eabf Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 8 Sep 2022 15:47:35 -0700
Subject: [PATCH] Added a special API function to get access to the SDL 2.0
 window

Fixes https://github.com/libsdl-org/sdl12-compat/issues/186
---
 include/SDL/SDL_syswm.h |  3 +++
 src/SDL12_compat.c      | 11 +++++++++++
 test/testwm.c           |  3 +++
 3 files changed, 17 insertions(+)

diff --git a/include/SDL/SDL_syswm.h b/include/SDL/SDL_syswm.h
index 4321a07a0..13ee52b1e 100644
--- a/include/SDL/SDL_syswm.h
+++ b/include/SDL/SDL_syswm.h
@@ -122,6 +122,9 @@ real SDL-1.2 available to you. */
 
 extern DECLSPEC int SDLCALL SDL_GetWMInfo(SDL_SysWMinfo *info);
 
+typedef struct SDL_Window SDL_Window;
+extern DECLSPEC SDL_Window * SDLCALL SDL12COMPAT_GetWindow(void);
+
 #include "close_code.h"
 
 #endif
diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index 2a379826f..2ce6eeb63 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -7057,6 +7057,12 @@ SDL_GetWMInfo(SDL12_SysWMinfo *info12)
     return 1;
 }
 
+DECLSPEC12 SDL_Window * SDLCALL
+SDL12COMPAT_GetWindow(void)
+{
+    return VideoWindow20;
+}
+
 DECLSPEC12 SDL12_Overlay * SDLCALL
 SDL_CreateYUVOverlay(int w, int h, Uint32 format12, SDL12_Surface *display12)
 {
@@ -7299,6 +7305,11 @@ SDL_GL_GetProcAddress(const char *sym)
     if ((SDL20_strcmp(sym, "glCopyTexSubImage3D") == 0)) {
         return (void *) glCopyTexSubImage3D_shim_for_scaling;
     }
+
+    /* this function is specific to the shim library */
+    if ((SDL20_strcmp(sym, "SDL12COMPAT_GetWindow") == 0)) {
+        return (void *) SDL12COMPAT_GetWindow;
+    }
     return SDL20_GL_GetProcAddress(sym);
 }
 
diff --git a/test/testwm.c b/test/testwm.c
index 04861562e..ced2981d8 100644
--- a/test/testwm.c
+++ b/test/testwm.c
@@ -458,6 +458,9 @@ int main(int argc, char *argv[])
 			printf("Generic syswm info: data=%X\n", syswm_info.data);
 			#endif
 		}
+#if SDL_COMPILEDVERSION >= SDL_VERSIONNUM(1, 2, 54)
+		printf("SDL 2.0 window: %p\n", SDL12COMPAT_GetWindow());
+#endif
 	}
 	SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
 #endif