sdl2-compat: Update for SDL3 modal and toplevel parent changes

From 66b5862fbe809db8700f1b60da7ce014dd895b40 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Thu, 5 Sep 2024 15:12:45 -0400
Subject: [PATCH] Update for SDL3 modal and toplevel parent changes

---
 src/sdl2_compat.c          | 21 +++++++++++++++++++++
 src/sdl3_include_wrapper.h | 11 ++++++++---
 src/sdl3_syms.h            |  3 ++-
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index f7cae27..e7f1098 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -6913,6 +6913,27 @@ SDL_SetWindowMaximumSize(SDL_Window *window, int max_w, int max_h)
     SDL3_SetWindowMaximumSize(window, max_w, max_h);
 }
 
+SDL_DECLSPEC int SDLCALL
+SDL_SetWindowModalFor(SDL_Window *modal_window, SDL_Window *parent_window)
+{
+    if (!modal_window) {
+        SDL3_SetError("Invalid window");
+        return -1;
+    }
+    if (SDL3_GetWindowFlags(modal_window) & SDL_WINDOW_MODAL) {
+        SDL3_SetWindowModal(modal_window, SDL_FALSE);
+    }
+    if (SDL3_SetWindowParent(modal_window, parent_window)) {
+        int ret = 0;
+        if (parent_window) {
+            ret = SDL3_SetWindowModal(modal_window, SDL_TRUE) ? 0 : -1;
+        }
+        return ret;
+    }
+
+    return -1;
+}
+
 SDL_DECLSPEC void SDLCALL
 SDL_JoystickSetPlayerIndex(SDL_Joystick *joystick, int player_index)
 {
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index 1237c83..0dced61 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -886,10 +886,11 @@
 #define SDL_SetWindowKeyboardGrab IGNORE_THIS_VERSION_OF_SDL_SetWindowKeyboardGrab
 #define SDL_SetWindowMaximumSize IGNORE_THIS_VERSION_OF_SDL_SetWindowMaximumSize
 #define SDL_SetWindowMinimumSize IGNORE_THIS_VERSION_OF_SDL_SetWindowMinimumSize
-#define SDL_SetWindowModalFor IGNORE_THIS_VERSION_OF_SDL_SetWindowModalFor
+#define SDL_SetWindowModal IGNORE_THIS_VERSION_OF_SDL_SetWindowModal
 #define SDL_SetWindowMouseGrab IGNORE_THIS_VERSION_OF_SDL_SetWindowMouseGrab
 #define SDL_SetWindowMouseRect IGNORE_THIS_VERSION_OF_SDL_SetWindowMouseRect
 #define SDL_SetWindowOpacity IGNORE_THIS_VERSION_OF_SDL_SetWindowOpacity
+#define SDL_SetWindowParent IGNORE_THIS_VERSION_OF_SDL_SetWindowParent
 #define SDL_SetWindowPosition IGNORE_THIS_VERSION_OF_SDL_SetWindowPosition
 #define SDL_SetWindowRelativeMouseMode IGNORE_THIS_VERSION_OF_SDL_SetWindowRelativeMouseMode
 #define SDL_SetWindowResizable IGNORE_THIS_VERSION_OF_SDL_SetWindowResizable
@@ -4609,8 +4610,8 @@
 #undef SDL_SetWindowMinimumSize
 #endif
 
-#ifdef SDL_SetWindowModalFor
-#undef SDL_SetWindowModalFor
+#ifdef SDL_SetWindowModal
+#undef SDL_SetWindowModal
 #endif
 
 #ifdef SDL_SetWindowMouseGrab
@@ -4625,6 +4626,10 @@
 #undef SDL_SetWindowOpacity
 #endif
 
+#ifdef SDL_SetWindowParent
+#undef SDL_SetWindowParent
+#endif
+
 #ifdef SDL_SetWindowPosition
 #undef SDL_SetWindowPosition
 #endif
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 4fd44c5..3b7873d 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -658,10 +658,11 @@ SDL3_SYM(SDL_bool,SetWindowIcon,(SDL_Window *a, SDL_Surface *b),(a,b),return)
 SDL3_SYM(SDL_bool,SetWindowKeyboardGrab,(SDL_Window *a, SDL_bool b),(a,b),return)
 SDL3_SYM(SDL_bool,SetWindowMaximumSize,(SDL_Window *a, int b, int c),(a,b,c),return)
 SDL3_SYM(SDL_bool,SetWindowMinimumSize,(SDL_Window *a, int b, int c),(a,b,c),return)
-SDL3_SYM_PASSTHROUGH_RETCODE(SDL_bool,SetWindowModalFor,(SDL_Window *a, SDL_Window *b),(a,b),return)
+SDL3_SYM(SDL_bool,SetWindowModal,(SDL_Window *a, SDL_bool b),(a,b),return)
 SDL3_SYM(SDL_bool,SetWindowMouseGrab,(SDL_Window *a, SDL_bool b),(a,b),return)
 SDL3_SYM_PASSTHROUGH_RETCODE(SDL_bool,SetWindowMouseRect,(SDL_Window *a, const SDL_Rect *b),(a,b),return)
 SDL3_SYM_PASSTHROUGH_RETCODE(SDL_bool,SetWindowOpacity,(SDL_Window *a, float b),(a,b),return)
+SDL3_SYM(SDL_bool,SetWindowParent,(SDL_Window *a, SDL_Window *b),(a,b),return)
 SDL3_SYM(SDL_bool,SetWindowPosition,(SDL_Window *a, int b, int c),(a,b,c),return)
 SDL3_SYM(SDL_bool,SetWindowRelativeMouseMode,(SDL_Window *a, SDL_bool b),(a,b),return)
 SDL3_SYM(SDL_bool,SetWindowResizable,(SDL_Window *a, SDL_bool b),(a,b),return)