From 88d9a8f45dd8c2685963b3fb54de8605c7f8d6ac Mon Sep 17 00:00:00 2001 From: Chris Cowan Date: Sat, 4 Mar 2023 22:56:40 -0800 Subject: [PATCH] Fix MacOS mouse grabbing issue Fixes https://github.com/sezero/quakespasm/issues/48 by centering the mouse on the window prior to grabbing it. --- Quake/in_sdl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Quake/in_sdl.c b/Quake/in_sdl.c index ed1ffd9e..530d2fb7 100644 --- a/Quake/in_sdl.c +++ b/Quake/in_sdl.c @@ -212,6 +212,15 @@ void IN_Activate (void) #endif #if defined(USE_SDL2) +#ifdef __APPLE__ + { + // Work around https://github.com/sezero/quakespasm/issues/48 + int width, height; + SDL_GetWindowSize((SDL_Window*) VID_GetWindow(), &width, &height); + SDL_WarpMouseInWindow((SDL_Window*) VID_GetWindow(), width / 2, height / 2); + } +#endif + if (SDL_SetRelativeMouseMode(SDL_TRUE) != 0) { Con_Printf("WARNING: SDL_SetRelativeMouseMode(SDL_TRUE) failed.\n");