From 3288fe40067a1a87fc2ff913ce4f1a5433d1c093 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sat, 4 Apr 2026 19:17:26 +0300 Subject: [PATCH] Fix mouse warping when controlling camera in Editor viewport on macOS --- Source/Engine/Platform/SDL/SDLInput.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Source/Engine/Platform/SDL/SDLInput.cpp b/Source/Engine/Platform/SDL/SDLInput.cpp index 76476f162..e799c6d2f 100644 --- a/Source/Engine/Platform/SDL/SDLInput.cpp +++ b/Source/Engine/Platform/SDL/SDLInput.cpp @@ -359,7 +359,6 @@ class SDLMouse : public Mouse private: Float2 _oldPosition = Float2::Zero; Window* _relativeModeWindow = nullptr; - const SDL_Rect* _oldScreenRect = nullptr; public: /// @@ -408,13 +407,14 @@ public: { _relativeModeWindow = window; SDL_GetMouseState(&_oldPosition.X, &_oldPosition.Y); +#if !PLATFORM_MAC if (!SDL_CursorVisible()) { - // Trap the cursor in current location + // Trap the cursor in current location to prevent accidental interactions with other UI elements or applications SDL_Rect clipRect = { (int)_oldPosition.X, (int)_oldPosition.Y, 1, 1 }; - _oldScreenRect = SDL_GetWindowMouseRect(windowHandle); SDL_SetWindowMouseRect(windowHandle, &clipRect); } +#endif } else { @@ -423,9 +423,8 @@ public: // FIXME: When floating game window is focused and editor viewport activated, the relative mode gets stuck return; } - SDL_SetWindowMouseRect(windowHandle, nullptr);//oldScreenRect); + SDL_SetWindowMouseRect(windowHandle, nullptr); SDL_WarpMouseInWindow(windowHandle, _oldPosition.X, _oldPosition.Y); - _oldScreenRect = nullptr; _relativeModeWindow = nullptr; } @@ -433,8 +432,8 @@ public: if (!SDL_SetWindowRelativeMouseMode(windowHandle, relativeMode)) LOG(Error, "Failed to set mouse relative mode: {0}", String(SDL_GetError())); -#if PLATFORM_MAC - // Warping right before entering relative mode seems to generate motion event for relative mode +#if PLATFORM_MAC && false + // Warping right before entering relative mode seems to generate motion event during relative mode SDL_PumpEvents(); SDL_FlushEvent(SDL_EVENT_MOUSE_MOTION); #endif