SDL_cocoamouse.m: SetRelativeMouseMode even if out of focus Should fix #3087
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m
index 7713fb5..30cf84a 100644
--- a/src/video/cocoa/SDL_cocoamouse.m
+++ b/src/video/cocoa/SDL_cocoamouse.m
@@ -259,7 +259,16 @@ Cocoa_WarpMouse(SDL_Window * window, int x, int y)
static int
Cocoa_SetRelativeMouseMode(SDL_bool enabled)
{
- /* We will re-apply the relative mode when the window gets focus, if it
+ CGError result;
+ if (enabled) {
+ DLog("Turning on.");
+ result = CGAssociateMouseAndMouseCursorPosition(NO);
+ if (result != kCGErrorSuccess) {
+ return SDL_SetError("CGAssociateMouseAndMouseCursorPosition() failed");
+ }
+ }
+
+ /* We will re-apply the non-relative mode when the window gets focus, if it
* doesn't have focus right now.
*/
SDL_Window *window = SDL_GetKeyboardFocus();
@@ -267,7 +276,7 @@ Cocoa_SetRelativeMouseMode(SDL_bool enabled)
return 0;
}
- /* We will re-apply the relative mode when the window finishes being moved,
+ /* We will re-apply the non-relative mode when the window finishes being moved,
* if it is being moved right now.
*/
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
@@ -275,17 +284,14 @@ Cocoa_SetRelativeMouseMode(SDL_bool enabled)
return 0;
}
- CGError result;
- if (enabled) {
- DLog("Turning on.");
- result = CGAssociateMouseAndMouseCursorPosition(NO);
- } else {
+ if (!enabled) {
DLog("Turning off.");
result = CGAssociateMouseAndMouseCursorPosition(YES);
+ if (result != kCGErrorSuccess) {
+ return SDL_SetError("CGAssociateMouseAndMouseCursorPosition() failed");
+ }
}
- if (result != kCGErrorSuccess) {
- return SDL_SetError("CGAssociateMouseAndMouseCursorPosition() failed");
- }
+
/* The hide/unhide calls are redundant most of the time, but they fix
* https://bugzilla.libsdl.org/show_bug.cgi?id=2550