Mac: Don't disassociate cursor if window is moving / doesn't have focus.
authorJørgen P. Tjernø <jorgen@valvesoftware.com>
Wed, 26 Feb 2014 16:10:52 -0800
changeset 8262 acc0dcf38b3d
parent 8261 841b66e4397a
child 8263 e22c4959e385
Mac: Don't disassociate cursor if window is moving / doesn't have focus. Bug: https://bugzilla.libsdl.org/show_bug.cgi?id=2396
src/video/cocoa/SDL_cocoamouse.m
--- a/src/video/cocoa/SDL_cocoamouse.m	Wed Feb 26 11:35:02 2014 -0800
+++ b/src/video/cocoa/SDL_cocoamouse.m	Wed Feb 26 16:10:52 2014 -0800
@@ -244,8 +244,23 @@
 static int
 Cocoa_SetRelativeMouseMode(SDL_bool enabled)
 {
+    /* We will re-apply the relative mode when the window gets focus, if it
+     * doesn't have focus right now.
+     */
+    SDL_Window *window = SDL_GetMouseFocus();
+    if (!window) {
+      return 0;
+    }
+
+    /* We will re-apply the relative mode when the window finishes being moved,
+     * if it is being moved right now.
+     */
+    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+    if ([data->listener isMoving]) {
+        return;
+    }
+
     CGError result;
-
     if (enabled) {
         DLog("Turning on.");
         result = CGAssociateMouseAndMouseCursorPosition(NO);