Cocoa : fix mouse cursor hang when RMB-dragging in a not frontmost window
authorDamien Plisson <damien.plisson@yahoo.fr>
Mon, 1 Feb 2010 11:20:01 +0000 (11:20 +0000)
committerDamien Plisson <damien.plisson@yahoo.fr>
Mon, 1 Feb 2010 11:20:01 +0000 (11:20 +0000)
With continuous grab on, in 2+ window setup, when RMB-dragging an object in a 3D view of a not active (not frontmost) window, mouse cursor was stuck, with no escape.
Cursor grab must be done by the window that is key (able to receive mouse move events).

intern/ghost/intern/GHOST_WindowCocoa.mm

index 5dcc949ed4590ab85499116854dda757247e2f3e..1223f866a9bb041553a78c63883670abaa8a0455 100644 (file)
@@ -1100,6 +1100,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorGrab(GHOST_TGrabCursorMode mode
                //No need to perform grab without warp as it is always on in OS X
                if(mode != GHOST_kGrabNormal) {
                        GHOST_TInt32 x_old,y_old;
+                       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
                        m_systemCocoa->getCursorPosition(x_old,y_old);
                        screenToClient(x_old, y_old, m_cursorGrabInitPos[0], m_cursorGrabInitPos[1]);
@@ -1110,8 +1111,13 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorGrab(GHOST_TGrabCursorMode mode
                                setWindowCursorVisibility(false);
                        }
                        
+                       //Make window key if it wasn't to get the mouse move events
+                       [m_window makeKeyWindow];
+                       
                        //Dissociate cursor position even for warp mode, to allow mouse acceleration to work even when warping the cursor
                        err = CGAssociateMouseAndMouseCursorPosition(false) == kCGErrorSuccess ? GHOST_kSuccess : GHOST_kFailure;
+                       
+                       [pool drain];
                }
        }
        else {