--- src/video/cocoa/SDL_cocoawindow.h 2014-02-04 20:34:33.000000000 -0600 +++ src/video/cocoa/SDL_cocoawindow.h 2014-02-19 17:51:54.000000000 -0600 @@ -42,6 +42,9 @@ /* Window delegate functionality */ -(BOOL) windowShouldClose:(id) sender; -(void) windowDidExpose:(NSNotification *) aNotification; +#if ASL_SDL +-(void) windowWillMove:(NSNotification *) aNotification; +#endif // ASL_SDL -(void) windowDidMove:(NSNotification *) aNotification; -(void) windowDidResize:(NSNotification *) aNotification; -(void) windowDidMiniaturize:(NSNotification *) aNotification; --- src/video/cocoa/SDL_cocoawindow.m 2014-02-04 20:34:33.000000000 -0600 +++ src/video/cocoa/SDL_cocoawindow.m 2014-02-24 18:39:09.000000000 -0600 @@ -44,6 +44,10 @@ static Uint32 s_moveHack; +#if ASL_SDL +SDL_bool ASL_SDL_Cocoa_nonKeyWindowMoving; // User is moving a non-key window. +#endif // ASL_SDL + static void ConvertNSRect(NSRect *r) { r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height; @@ -203,6 +207,14 @@ SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0); } +#if ASL_SDL // Detect when the user begins moving a non-key window. +-(void) windowWillMove:(NSNotification *) aNotification +{ + if (SDL_GetKeyboardFocus() != _data->window) + ASL_SDL_Cocoa_nonKeyWindowMoving = SDL_TRUE; +} +#endif // ASL_SDL + - (void)windowDidMove:(NSNotification *)aNotification { int x, y; @@ -276,6 +288,16 @@ SDL_Window *window = _data->window; SDL_Mouse *mouse = SDL_GetMouse(); +#if ASL_SDL + // If user is moving a non-key window, delay updating key focus. + if (ASL_SDL_Cocoa_nonKeyWindowMoving) + return; + + // Reactivate relative mouse mode. + if (mouse->relative_mode) + mouse->SetRelativeMouseMode(SDL_TRUE); +#endif // ASL_SDL + /* We're going to get keyboard events, since we're key. */ SDL_SetKeyboardFocus(window); @@ -299,6 +321,17 @@ - (void)windowDidResignKey:(NSNotification *)aNotification { +#if ASL_SDL + SDL_Mouse *mouse = SDL_GetMouse(); + + // If window loses focus, it's no longer being moved. + ASL_SDL_Cocoa_nonKeyWindowMoving = SDL_FALSE; + + // Deactivate relative mouse mode so user can move window. + if (mouse->relative_mode) + mouse->SetRelativeMouseMode(SDL_FALSE); +#endif // ASL_SDL + /* Some other window will get mouse events, since we're not key. */ if (SDL_GetMouseFocus() == _data->window) { SDL_SetMouseFocus(NULL); @@ -415,6 +448,15 @@ NSPoint point; int x, y; +#if ASL_SDL + // If user is moving window, and we get a mouse moved event, we know the window move is done. + if (ASL_SDL_Cocoa_nonKeyWindowMoving) { + ASL_SDL_Cocoa_nonKeyWindowMoving = SDL_FALSE; + // Now update the focus. + [self windowDidBecomeKey:nil]; + } +#endif // ASL_SDL + if (mouse->relative_mode) { return; } @@ -461,6 +503,11 @@ - (void)mouseDragged:(NSEvent *)theEvent { +#if ASL_SDL + // Ignore mouse drags while a non-key window is being moved. + if (ASL_SDL_Cocoa_nonKeyWindowMoving) + return; +#endif // ASL_SDL [self mouseMoved:theEvent]; } --- src/video/cocoa/SDL_cocoamouse.m 2014-02-17 21:14:37.000000000 -0600 +++ src/video/cocoa/SDL_cocoamouse.m 2014-02-24 18:39:09.000000000 -0600 @@ -267,11 +267,21 @@ Cocoa_InitMouseEventTap(mouse->driverdata); } +#if ASL_SDL +extern SDL_bool ASL_SDL_Cocoa_nonKeyWindowMoving; +#endif // ASL_SDL + void Cocoa_HandleMouseEvent(_THIS, NSEvent *event) { SDL_Mouse *mouse = SDL_GetMouse(); +#if ASL_SDL + // Ignore mouse events while a non-key window is being moved. + if (ASL_SDL_Cocoa_nonKeyWindowMoving) + return; +#endif // ASL_SDL + if (mouse->relative_mode && ([event type] == NSMouseMoved || [event type] == NSLeftMouseDragged ||