From 4e1afcb4f709d8e41895613e919b7eb0a8741874 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 12 Oct 2023 07:01:05 -0700
Subject: [PATCH] Updated after SDL properties API changes
---
src/sdl2_compat.c | 58 ++++++++++++++++++++++++++++++++++----
src/sdl3_include_wrapper.h | 40 +++++++++++++-------------
src/sdl3_syms.h | 8 +++---
3 files changed, 77 insertions(+), 29 deletions(-)
diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 42eff92..7e32949 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -5269,6 +5269,54 @@ SDL_GetWindowFlags(SDL_Window *window)
#define POPUP_PARENT_PROP_STR "__SDL3_parentWnd"
+DECLSPEC void* SDLCALL
+SDL_GetWindowData(SDL_Window * window, const char *name)
+{
+ if (!window) {
+ SDL_SetError("Invalid window");
+ return NULL;
+ }
+
+ if (name == NULL || name[0] == '\0') {
+ SDL3_InvalidParamError("name");
+ return NULL;
+ }
+
+ return SDL3_GetProperty(SDL3_GetWindowProperties(window), name);
+}
+
+DECLSPEC void* SDLCALL
+SDL_SetWindowData(SDL_Window * window, const char *name, void *userdata)
+{
+ void *prev;
+
+ if (!window) {
+ SDL_SetError("Invalid window");
+ return NULL;
+ }
+
+ if (name == NULL || name[0] == '\0') {
+ SDL3_InvalidParamError("name");
+ return NULL;
+ }
+
+ prev = SDL_GetWindowData(window, name);
+ SDL3_SetProperty(SDL3_GetWindowProperties(window), name, userdata, NULL, NULL);
+ return prev;
+}
+
+DECLSPEC int SDLCALL
+SDL_SetTextureUserData(SDL_Texture * texture, void *userdata)
+{
+ return SDL3_SetProperty(SDL3_GetTextureProperties(texture), "userdata", userdata, NULL, NULL);
+}
+
+DECLSPEC void * SDLCALL
+SDL_GetTextureUserData(SDL_Texture * texture)
+{
+ return SDL3_GetProperty(SDL3_GetTextureProperties(texture), "userdata");
+}
+
DECLSPEC SDL_Window * SDLCALL
SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
{
@@ -5297,7 +5345,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
if (parent) {
window = SDL3_CreatePopupWindow(parent, x, y, w, h, flags);
- SDL3_SetWindowData(window, POPUP_PARENT_PROP_STR, parent);
+ SDL_SetWindowData(window, POPUP_PARENT_PROP_STR, parent);
}
}
if (window) {
@@ -5476,7 +5524,7 @@ SDL_SetWindowPosition(SDL_Window *window, int x, int y)
{
/* Popup windows need to be transformed from global to relative coordinates. */
if (SDL3_GetWindowFlags(window) & (SDL_WINDOW_TOOLTIP | SDL_WINDOW_POPUP_MENU)) {
- SDL_Window *parent = (SDL_Window *) SDL3_GetWindowData(window, POPUP_PARENT_PROP_STR);
+ SDL_Window *parent = (SDL_Window *) SDL_GetWindowData(window, POPUP_PARENT_PROP_STR);
while (parent) {
int x_off, y_off;
@@ -5485,7 +5533,7 @@ SDL_SetWindowPosition(SDL_Window *window, int x, int y)
x -= x_off;
y -= y_off;
- parent = (SDL_Window *) SDL3_GetWindowData(parent, POPUP_PARENT_PROP_STR);
+ parent = (SDL_Window *) SDL_GetWindowData(parent, POPUP_PARENT_PROP_STR);
}
} else {
if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISCENTERED(x)) {
@@ -5512,7 +5560,7 @@ SDL_GetWindowPosition(SDL_Window *window, int *x, int *y)
/* Popup windows need to be transformed from relative to global coordinates. */
if (SDL3_GetWindowFlags(window) & (SDL_WINDOW_TOOLTIP | SDL_WINDOW_POPUP_MENU)) {
- SDL_Window *parent = (SDL_Window *) SDL3_GetWindowData(window, POPUP_PARENT_PROP_STR);
+ SDL_Window *parent = (SDL_Window *) SDL_GetWindowData(window, POPUP_PARENT_PROP_STR);
while (parent) {
int x_off, y_off;
@@ -5521,7 +5569,7 @@ SDL_GetWindowPosition(SDL_Window *window, int *x, int *y)
*x += x_off;
*y += y_off;
- parent = (SDL_Window *) SDL3_GetWindowData(parent, POPUP_PARENT_PROP_STR);
+ parent = (SDL_Window *) SDL_GetWindowData(parent, POPUP_PARENT_PROP_STR);
}
}
}
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index ef62c04..4d677c4 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -299,6 +299,7 @@
#define SDL_GetPreferredLocales IGNORE_THIS_VERSION_OF_SDL_GetPreferredLocales
#define SDL_GetPrimaryDisplay IGNORE_THIS_VERSION_OF_SDL_GetPrimaryDisplay
#define SDL_GetPrimarySelectionText IGNORE_THIS_VERSION_OF_SDL_GetPrimarySelectionText
+#define SDL_GetProperty IGNORE_THIS_VERSION_OF_SDL_GetProperty
#define SDL_GetRGB IGNORE_THIS_VERSION_OF_SDL_GetRGB
#define SDL_GetRGBA IGNORE_THIS_VERSION_OF_SDL_GetRGBA
#define SDL_GetRectAndLineIntersection IGNORE_THIS_VERSION_OF_SDL_GetRectAndLineIntersection
@@ -355,8 +356,8 @@
#define SDL_GetTextureAlphaMod IGNORE_THIS_VERSION_OF_SDL_GetTextureAlphaMod
#define SDL_GetTextureBlendMode IGNORE_THIS_VERSION_OF_SDL_GetTextureBlendMode
#define SDL_GetTextureColorMod IGNORE_THIS_VERSION_OF_SDL_GetTextureColorMod
+#define SDL_GetTextureProperties IGNORE_THIS_VERSION_OF_SDL_GetProperties
#define SDL_GetTextureScaleMode IGNORE_THIS_VERSION_OF_SDL_GetTextureScaleMode
-#define SDL_GetTextureUserData IGNORE_THIS_VERSION_OF_SDL_GetTextureUserData
#define SDL_GetThreadID IGNORE_THIS_VERSION_OF_SDL_GetThreadID
#define SDL_GetThreadName IGNORE_THIS_VERSION_OF_SDL_GetThreadName
#define SDL_GetTicks IGNORE_THIS_VERSION_OF_SDL_GetTicks
@@ -368,7 +369,6 @@
#define SDL_GetVersion IGNORE_THIS_VERSION_OF_SDL_GetVersion
#define SDL_GetVideoDriver IGNORE_THIS_VERSION_OF_SDL_GetVideoDriver
#define SDL_GetWindowBordersSize IGNORE_THIS_VERSION_OF_SDL_GetWindowBordersSize
-#define SDL_GetWindowData IGNORE_THIS_VERSION_OF_SDL_GetWindowData
#define SDL_GetWindowDisplayScale IGNORE_THIS_VERSION_OF_SDL_GetWindowDisplayScale
#define SDL_GetWindowFlags IGNORE_THIS_VERSION_OF_SDL_GetWindowFlags
#define SDL_GetWindowFromID IGNORE_THIS_VERSION_OF_SDL_GetWindowFromID
@@ -386,6 +386,7 @@
#define SDL_GetWindowPixelDensity IGNORE_THIS_VERSION_OF_SDL_GetWindowPixelDensity
#define SDL_GetWindowPixelFormat IGNORE_THIS_VERSION_OF_SDL_GetWindowPixelFormat
#define SDL_GetWindowPosition IGNORE_THIS_VERSION_OF_SDL_GetWindowPosition
+#define SDL_GetWindowProperties IGNORE_THIS_VERSION_OF_SDL_GetWindowProperties
#define SDL_GetWindowSize IGNORE_THIS_VERSION_OF_SDL_GetWindowSize
#define SDL_GetWindowSizeInPixels IGNORE_THIS_VERSION_OF_SDL_GetWindowSizeInPixels
#define SDL_GetWindowSurface IGNORE_THIS_VERSION_OF_SDL_GetWindowSurface
@@ -604,6 +605,7 @@
#define SDL_SetPaletteColors IGNORE_THIS_VERSION_OF_SDL_SetPaletteColors
#define SDL_SetPixelFormatPalette IGNORE_THIS_VERSION_OF_SDL_SetPixelFormatPalette
#define SDL_SetPrimarySelectionText IGNORE_THIS_VERSION_OF_SDL_SetPrimarySelectionText
+#define SDL_SetProperty IGNORE_THIS_VERSION_OF_SDL_SetProperty
#define SDL_SetRelativeMouseMode IGNORE_THIS_VERSION_OF_SDL_SetRelativeMouseMode
#define SDL_SetRenderClipRect IGNORE_THIS_VERSION_OF_SDL_SetRenderClipRect
#define SDL_SetRenderDrawBlendMode IGNORE_THIS_VERSION_OF_SDL_SetRenderDrawBlendMode
@@ -626,11 +628,9 @@
#define SDL_SetTextureBlendMode IGNORE_THIS_VERSION_OF_SDL_SetTextureBlendMode
#define SDL_SetTextureColorMod IGNORE_THIS_VERSION_OF_SDL_SetTextureColorMod
#define SDL_SetTextureScaleMode IGNORE_THIS_VERSION_OF_SDL_SetTextureScaleMode
-#define SDL_SetTextureUserData IGNORE_THIS_VERSION_OF_SDL_SetTextureUserData
#define SDL_SetThreadPriority IGNORE_THIS_VERSION_OF_SDL_SetThreadPriority
#define SDL_SetWindowAlwaysOnTop IGNORE_THIS_VERSION_OF_SDL_SetWindowAlwaysOnTop
#define SDL_SetWindowBordered IGNORE_THIS_VERSION_OF_SDL_SetWindowBordered
-#define SDL_SetWindowData IGNORE_THIS_VERSION_OF_SDL_SetWindowData
#define SDL_SetWindowFullscreen IGNORE_THIS_VERSION_OF_SDL_SetWindowFullscreen
#define SDL_SetWindowFullscreenMode IGNORE_THIS_VERSION_OF_SDL_SetWindowFullscreenMode
#define SDL_SetWindowGrab IGNORE_THIS_VERSION_OF_SDL_SetWindowGrab
@@ -2046,6 +2046,10 @@
#undef SDL_GetPrimarySelectionText
#endif
+#ifdef SDL_GetProperty
+#undef SDL_GetProperty
+#endif
+
#ifdef SDL_GetRGB
#undef SDL_GetRGB
#endif
@@ -2270,12 +2274,12 @@
#undef SDL_GetTextureColorMod
#endif
-#ifdef SDL_GetTextureScaleMode
-#undef SDL_GetTextureScaleMode
+#ifdef SDL_GetTextureProperties
+#undef SDL_GetTextureProperties
#endif
-#ifdef SDL_GetTextureUserData
-#undef SDL_GetTextureUserData
+#ifdef SDL_GetTextureScaleMode
+#undef SDL_GetTextureScaleMode
#endif
#ifdef SDL_GetThreadID
@@ -2322,10 +2326,6 @@
#undef SDL_GetWindowBordersSize
#endif
-#ifdef SDL_GetWindowData
-#undef SDL_GetWindowData
-#endif
-
#ifdef SDL_GetWindowDisplayScale
#undef SDL_GetWindowDisplayScale
#endif
@@ -2394,6 +2394,10 @@
#undef SDL_GetWindowPosition
#endif
+#ifdef SDL_GetWindowProperties
+#undef SDL_GetWindowProperties
+#endif
+
#ifdef SDL_GetWindowSize
#undef SDL_GetWindowSize
#endif
@@ -3266,6 +3270,10 @@
#undef SDL_SetPrimarySelectionText
#endif
+#ifdef SDL_SetProperty
+#undef SDL_SetProperty
+#endif
+
#ifdef SDL_SetRelativeMouseMode
#undef SDL_SetRelativeMouseMode
#endif
@@ -3354,10 +3362,6 @@
#undef SDL_SetTextureScaleMode
#endif
-#ifdef SDL_SetTextureUserData
-#undef SDL_SetTextureUserData
-#endif
-
#ifdef SDL_SetThreadPriority
#undef SDL_SetThreadPriority
#endif
@@ -3370,10 +3374,6 @@
#undef SDL_SetWindowBordered
#endif
-#ifdef SDL_SetWindowData
-#undef SDL_SetWindowData
-#endif
-
#ifdef SDL_SetWindowFullscreen
#undef SDL_SetWindowFullscreen
#endif
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index b2375b0..473f448 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -463,8 +463,6 @@ SDL3_SYM(Uint32,GetWindowFlags,(SDL_Window *a),(a),return)
SDL3_SYM_PASSTHROUGH(const char*,GetWindowTitle,(SDL_Window *a),(a),return)
SDL3_SYM(int,SetWindowTitle,(SDL_Window *a, const char *b),(a,b),return)
SDL3_SYM(int,SetWindowIcon,(SDL_Window *a, SDL_Surface *b),(a,b),return)
-SDL3_SYM_PASSTHROUGH(void*,SetWindowData,(SDL_Window *a, const char *b, void *c),(a,b,c),return)
-SDL3_SYM_PASSTHROUGH(void*,GetWindowData,(SDL_Window *a, const char *b),(a,b),return)
SDL3_SYM(int,SetWindowPosition,(SDL_Window *a, int b, int c),(a,b,c),return)
SDL3_SYM(int,GetWindowPosition,(SDL_Window *a, int *b, int *c),(a,b,c),return)
SDL3_SYM(int,GetWindowSize,(SDL_Window *a, int *b, int *c),(a,b,c),return)
@@ -745,8 +743,6 @@ SDL3_SYM_PASSTHROUGH(int,FlashWindow,(SDL_Window *a, SDL_FlashOperation b),(a,b)
SDL3_SYM_RENAMED(int,GameControllerSendEffect,SendGamepadEffect,(SDL_GameController *a, const void *b, int c),(a,b,c),return)
SDL3_SYM_RENAMED(int,JoystickSendEffect,SendJoystickEffect,(SDL_Joystick *a, const void *b, int c),(a,b,c),return)
SDL3_SYM_RENAMED(float,GameControllerGetSensorDataRate,GetGamepadSensorDataRate,(SDL_GameController *a, SDL_SensorType b),(a,b),return)
-SDL3_SYM_PASSTHROUGH(int,SetTextureUserData,(SDL_Texture *a, void *b),(a,b),return)
-SDL3_SYM_PASSTHROUGH(void*,GetTextureUserData,(SDL_Texture *a),(a),return)
SDL3_SYM_PASSTHROUGH(int,RenderGeometry,(SDL_Renderer *a, SDL_Texture *b, const SDL_Vertex *c, int d, const int *e, int f),(a,b,c,d,e,f),return)
SDL3_SYM_PASSTHROUGH(int,RenderGeometryRaw,(SDL_Renderer *a, SDL_Texture *b, const float *c, int d, const SDL_Color *e, int f, const float *g, int h, int i, const void *j, int k, int l),(a,b,c,d,e,f,g,h,i,j,k,l),return)
SDL3_SYM_RENAMED(int,RenderSetVSync,SetRenderVSync,(SDL_Renderer *a, int b),(a,b),return)
@@ -905,6 +901,10 @@ SDL3_SYM(SDL_GamepadBinding **,GetGamepadBindings,(SDL_Gamepad *a, int *b),(a,b)
#ifdef __GDK__
SDL3_SYM_PASSTHROUGH(int,GDKGetDefaultUser,(XUserHandle *a),(a),return)
#endif
+SDL3_SYM(int,SetProperty,(SDL_PropertiesID a, const char *b, void *c, void (SDLCALL *d)(void *userdata, void *value), void *e),(a,b,c,d,e),return)
+SDL3_SYM(void*,GetProperty,(SDL_PropertiesID a, const char *b),(a,b),return)
+SDL3_SYM(SDL_PropertiesID,GetWindowProperties,(SDL_Window *a),(a),return)
+SDL3_SYM(SDL_PropertiesID,GetTextureProperties,(SDL_Texture *a),(a),return)
#undef SDL3_SYM
#undef SDL3_SYM_PASSTHROUGH