From 53003aa707453c46d152bd8e623b07b5856e450c Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 6 Aug 2024 09:21:02 -0700
Subject: [PATCH] Updated for SDL3 relative mouse mode change
---
src/sdl2_compat.c | 30 ++++++++++++++++++++++++++++++
src/sdl3_include_wrapper.h | 20 ++++++++++----------
src/sdl3_syms.h | 4 ++--
3 files changed, 42 insertions(+), 12 deletions(-)
diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index e7e2b03..34e4cb4 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -767,6 +767,7 @@ static SDL2_EventFilter EventFilter2 = NULL;
static void *EventFilterUserData2 = NULL;
static SDL_mutex *EventWatchListMutex = NULL;
static EventFilterWrapperData *EventWatchers2 = NULL;
+static SDL_bool relative_mouse_mode = SDL_FALSE;
static SDL_JoystickID *joystick_list = NULL;
static int num_joysticks = 0;
static SDL_JoystickID *gamepad_button_swap_list = NULL;
@@ -1922,6 +1923,33 @@ SDL_WarpMouseGlobal(int x, int y)
return SDL3_WarpMouseGlobal((float)x, (float)y);
}
+SDL_DECLSPEC int SDLCALL
+SDL_SetRelativeMouseMode(SDL_bool enabled)
+{
+ int retval = 0;
+ SDL_Window **windows = SDL3_GetWindows(NULL);
+ if (windows) {
+ int i;
+
+ for (i = 0; windows[i]; ++i) {
+ if (SDL3_SetWindowRelativeMouseMode(windows[i], enabled) < 0) {
+ retval = -1;
+ }
+ }
+
+ SDL_free(windows);
+ }
+ if (retval == 0) {
+ relative_mouse_mode = enabled;
+ }
+ return retval;
+}
+
+SDL_DECLSPEC SDL_bool SDLCALL
+SDL_GetRelativeMouseMode(void)
+{
+ return relative_mouse_mode;
+}
SDL_DECLSPEC SDL2_RWops *SDLCALL
SDL_AllocRW(void)
@@ -4931,6 +4959,8 @@ SDL_InitSubSystem(Uint32 flags)
SDL_DECLSPEC void SDLCALL
SDL_Quit(void)
{
+ relative_mouse_mode = SDL_FALSE;
+
if (SDL3_WasInit(SDL_INIT_VIDEO)) {
GestureQuit();
}
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index 3b9a912..2492b67 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -418,7 +418,6 @@
#define SDL_GetRectIntersectionFloat IGNORE_THIS_VERSION_OF_SDL_GetRectIntersectionFloat
#define SDL_GetRectUnion IGNORE_THIS_VERSION_OF_SDL_GetRectUnion
#define SDL_GetRectUnionFloat IGNORE_THIS_VERSION_OF_SDL_GetRectUnionFloat
-#define SDL_GetRelativeMouseMode IGNORE_THIS_VERSION_OF_SDL_GetRelativeMouseMode
#define SDL_GetRelativeMouseState IGNORE_THIS_VERSION_OF_SDL_GetRelativeMouseState
#define SDL_GetRenderClipRect IGNORE_THIS_VERSION_OF_SDL_GetRenderClipRect
#define SDL_GetRenderColorScale IGNORE_THIS_VERSION_OF_SDL_GetRenderColorScale
@@ -517,6 +516,7 @@
#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_GetWindowRelativeMouseMode IGNORE_THIS_VERSION_OF_SDL_GetWindowRelativeMouseMode
#define SDL_GetWindowSafeArea IGNORE_THIS_VERSION_OF_SDL_GetWindowSafeArea
#define SDL_GetWindowSize IGNORE_THIS_VERSION_OF_SDL_GetWindowSize
#define SDL_GetWindowSizeInPixels IGNORE_THIS_VERSION_OF_SDL_GetWindowSizeInPixels
@@ -781,7 +781,6 @@
#define SDL_SetPointerProperty IGNORE_THIS_VERSION_OF_SDL_SetPointerProperty
#define SDL_SetPointerPropertyWithCleanup IGNORE_THIS_VERSION_OF_SDL_SetPointerPropertyWithCleanup
#define SDL_SetPrimarySelectionText IGNORE_THIS_VERSION_OF_SDL_SetPrimarySelectionText
-#define SDL_SetRelativeMouseMode IGNORE_THIS_VERSION_OF_SDL_SetRelativeMouseMode
#define SDL_SetRenderClipRect IGNORE_THIS_VERSION_OF_SDL_SetRenderClipRect
#define SDL_SetRenderColorScale IGNORE_THIS_VERSION_OF_SDL_SetRenderColorScale
#define SDL_SetRenderDrawBlendMode IGNORE_THIS_VERSION_OF_SDL_SetRenderDrawBlendMode
@@ -827,6 +826,7 @@
#define SDL_SetWindowMouseRect IGNORE_THIS_VERSION_OF_SDL_SetWindowMouseRect
#define SDL_SetWindowOpacity IGNORE_THIS_VERSION_OF_SDL_SetWindowOpacity
#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
#define SDL_SetWindowShape IGNORE_THIS_VERSION_OF_SDL_SetWindowShape
#define SDL_SetWindowSize IGNORE_THIS_VERSION_OF_SDL_SetWindowSize
@@ -2663,10 +2663,6 @@
#undef SDL_GetRectUnionFloat
#endif
-#ifdef SDL_GetRelativeMouseMode
-#undef SDL_GetRelativeMouseMode
-#endif
-
#ifdef SDL_GetRelativeMouseState
#undef SDL_GetRelativeMouseState
#endif
@@ -3059,6 +3055,10 @@
#undef SDL_GetWindowProperties
#endif
+#ifdef SDL_GetWindowRelativeMouseMode
+#undef SDL_GetWindowRelativeMouseMode
+#endif
+
#ifdef SDL_GetWindowSafeArea
#undef SDL_GetWindowSafeArea
#endif
@@ -4115,10 +4115,6 @@
#undef SDL_SetPrimarySelectionText
#endif
-#ifdef SDL_SetRelativeMouseMode
-#undef SDL_SetRelativeMouseMode
-#endif
-
#ifdef SDL_SetRenderClipRect
#undef SDL_SetRenderClipRect
#endif
@@ -4299,6 +4295,10 @@
#undef SDL_SetWindowPosition
#endif
+#ifdef SDL_SetWindowRelativeMouseMode
+#undef SDL_SetWindowRelativeMouseMode
+#endif
+
#ifdef SDL_SetWindowResizable
#undef SDL_SetWindowResizable
#endif
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 57e566d..69ba683 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -244,8 +244,8 @@ SDL3_SYM_PASSTHROUGH(SDL_Window*,GetMouseFocus,(void),(),return)
SDL3_SYM(Uint32,GetMouseState,(float *a, float *b),(a,b),return)
SDL3_SYM(Uint32,GetRelativeMouseState,(float *a, float *b),(a,b),return)
SDL3_SYM(void,WarpMouseInWindow,(SDL_Window *a, float b, float c),(a,b,c),)
-SDL3_SYM_PASSTHROUGH(int,SetRelativeMouseMode,(SDL_bool a),(a),return)
-SDL3_SYM_PASSTHROUGH(SDL_bool,GetRelativeMouseMode,(void),(),return)
+SDL3_SYM(int,SetWindowRelativeMouseMode,(SDL_Window *a, SDL_bool b),(a,b),return)
+SDL3_SYM(SDL_bool,GetWindowRelativeMouseMode,(SDL_Window *a),(a),return)
SDL3_SYM_PASSTHROUGH(SDL_Cursor*,CreateCursor,(const Uint8 *a, const Uint8 *b, int c, int d, int e, int f),(a,b,c,d,e,f),return)
SDL3_SYM(SDL_Cursor*,CreateColorCursor,(SDL_Surface *a, int b, int c),(a,b,c),return)
SDL3_SYM_PASSTHROUGH(SDL_Cursor*,CreateSystemCursor,(SDL_SystemCursor a),(a),return)