sdl2-compat: Adjust for new SDL_WINDOW_FULLSCREEN behavior (8ed8c)

From 8ed8c657ad631612897a9ecdaf1359fb7e4a6c48 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Tue, 31 Jan 2023 18:05:50 +0300
Subject: [PATCH] Adjust for new SDL_WINDOW_FULLSCREEN behavior

After https://github.com/libsdl-org/SDL/pull/7174.
---
 src/sdl2_compat.c | 23 +++++++++++++++++++++++
 src/sdl3_syms.h   |  4 ++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 4d148d9..ee36be2 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -3720,6 +3720,8 @@ SDL_FreeWAV(Uint8 *audio_buf)
     SDL3_free(audio_buf);
 }
 
+/* SDL3 changed SDL_WINDOW_FULLSCREEN and SDL_WINDOW_FULLSCREEN_DESKTOP
+ * to be two distict flags. */
 /* SDL3 removed SDL_WINDOW_SHOWN as redundant to SDL_WINDOW_HIDDEN. */
 DECLSPEC Uint32 SDLCALL
 SDL_GetWindowFlags(SDL_Window *window)
@@ -3728,9 +3730,30 @@ SDL_GetWindowFlags(SDL_Window *window)
     if ((flags & SDL_WINDOW_HIDDEN) == 0) {
         flags |= SDL2_WINDOW_SHOWN;
     }
+    if ((flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == 0) {
+        flags |= SDL_WINDOW_FULLSCREEN_EXCLUSIVE;
+    }
     return flags;
 }
 
+DECLSPEC SDL_Window * SDLCALL
+SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
+{
+    if (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) {
+        flags &= ~SDL_WINDOW_FULLSCREEN_EXCLUSIVE;
+    }
+    return SDL3_CreateWindow(title, x, y, w, h, flags);
+}
+
+DECLSPEC int SDLCALL
+SDL_SetWindowFullscreen(SDL_Window *window, Uint32 flags)
+{
+    if (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) {
+        flags &= ~SDL_WINDOW_FULLSCREEN_EXCLUSIVE;
+    }
+    return SDL3_SetWindowFullscreen(window, flags);
+}
+
 /* SDL3 added a return value. We just throw it away for SDL2. */
 DECLSPEC void SDLCALL
 SDL_GL_SwapWindow(SDL_Window *window)
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 2351d62..964b463 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -490,7 +490,7 @@ SDL3_SYM(SDL_DisplayMode*,GetClosestDisplayMode,(SDL_DisplayID a, const SDL_Disp
 SDL3_SYM(int,SetWindowDisplayMode,(SDL_Window *a, const SDL_DisplayMode *b),(a,b),return)
 SDL3_SYM(int,GetWindowDisplayMode,(SDL_Window *a, SDL_DisplayMode *b),(a,b),return)
 SDL3_SYM_PASSTHROUGH(Uint32,GetWindowPixelFormat,(SDL_Window *a),(a),return)
-SDL3_SYM_PASSTHROUGH(SDL_Window*,CreateWindow,(const char *a, int b, int c, int d, int e, Uint32 f),(a,b,c,d,e,f),return)
+SDL3_SYM(SDL_Window*,CreateWindow,(const char *a, int b, int c, int d, int e, Uint32 f),(a,b,c,d,e,f),return)
 SDL3_SYM_PASSTHROUGH(SDL_Window*,CreateWindowFrom,(const void *a),(a),return)
 SDL3_SYM_PASSTHROUGH(Uint32,GetWindowID,(SDL_Window *a),(a),return)
 SDL3_SYM_PASSTHROUGH(SDL_Window*,GetWindowFromID,(Uint32 a),(a),return)
@@ -515,7 +515,7 @@ SDL3_SYM_PASSTHROUGH(void,RaiseWindow,(SDL_Window *a),(a),)
 SDL3_SYM_PASSTHROUGH(void,MaximizeWindow,(SDL_Window *a),(a),)
 SDL3_SYM_PASSTHROUGH(void,MinimizeWindow,(SDL_Window *a),(a),)
 SDL3_SYM_PASSTHROUGH(void,RestoreWindow,(SDL_Window *a),(a),)
-SDL3_SYM_PASSTHROUGH(int,SetWindowFullscreen,(SDL_Window *a, Uint32 b),(a,b),return)
+SDL3_SYM(int,SetWindowFullscreen,(SDL_Window *a, Uint32 b),(a,b),return)
 SDL3_SYM_PASSTHROUGH(SDL_Surface*,GetWindowSurface,(SDL_Window *a),(a),return)
 SDL3_SYM_PASSTHROUGH(int,UpdateWindowSurface,(SDL_Window *a),(a),return)
 SDL3_SYM_PASSTHROUGH(int,UpdateWindowSurfaceRects,(SDL_Window *a, const SDL_Rect *b, int c),(a,b,c),return)