# HG changeset patch # User Robotic-Brain # Date 1407613010 -7200 # Node ID a7f19122777727563cad416024c9de1e4dde5d60 # Parent f061a86fbb08cdbb3cee1d75b232f66cc8c99980 Clean version of https://bugzilla.libsdl.org/attachment.cgi?id=1808 diff -r f061a86fbb08 -r a7f191227777 src/video/cocoa/SDL_cocoamouse.m --- a/src/video/cocoa/SDL_cocoamouse.m Sun Jul 13 09:04:55 2014 -0700 +++ b/src/video/cocoa/SDL_cocoamouse.m Sat Aug 09 21:36:50 2014 +0200 @@ -208,41 +208,18 @@ } static void -Cocoa_WarpMouse(SDL_Window * window, int x, int y) -{ - SDL_WindowData *data = (SDL_WindowData *) window->driverdata; - if ([data->listener isMoving]) { - DLog("Postponing warp, window being moved."); - [data->listener setPendingMoveX:x - Y:y]; - return; - } - - SDL_Mouse *mouse = SDL_GetMouse(); - CGPoint point = CGPointMake(x + (float)window->x, y + (float)window->y); - - Cocoa_HandleMouseWarp(point.x, point.y); - - /* According to the docs, this was deprecated in 10.6, but it's still - * around. The substitute requires a CGEventSource, but I'm not entirely - * sure how we'd procure the right one for this event. - */ - CGSetLocalEventsSuppressionInterval(0.0); - CGWarpMouseCursorPosition(point); - CGSetLocalEventsSuppressionInterval(0.25); - - if (!mouse->relative_mode) { - /* CGWarpMouseCursorPosition doesn't generate a window event, unlike our - * other implementations' APIs. - */ - SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 0, x, y); - } -} - -static void Cocoa_WarpMouseGlobal(int x, int y) { SDL_Mouse *mouse = SDL_GetMouse(); + if (mouse->focus) { + SDL_WindowData *data = (SDL_WindowData *) mouse->focus->driverdata; + if ([data->listener isMoving]) { + DLog("Postponing warp, window being moved."); + [data->listener setPendingMoveX:x + Y:y]; + return; + } + } CGPoint point = CGPointMake((float)x, (float)y); Cocoa_HandleMouseWarp(point.x, point.y); @@ -263,6 +240,12 @@ } } +static void +Cocoa_WarpMouse(SDL_Window * window, int x, int y) +{ + Cocoa_WarpMouseGlobal(x + window->x, y + window->y); +} + static int Cocoa_SetRelativeMouseMode(SDL_bool enabled) { diff -r f061a86fbb08 -r a7f191227777 src/video/cocoa/SDL_cocoawindow.m --- a/src/video/cocoa/SDL_cocoawindow.m Sun Jul 13 09:04:55 2014 -0700 +++ b/src/video/cocoa/SDL_cocoawindow.m Sat Aug 09 21:36:50 2014 +0200 @@ -103,8 +103,11 @@ static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r) { - NSRect visibleScreen = fullscreen ? [screen frame] : [screen visibleFrame]; - r->origin.y = (visibleScreen.origin.y + visibleScreen.size.height) - r->origin.y - r->size.height; + // This essentially reverts the mainline SDL change that redefines global coord + // space for windows on the main display to be relative to the bottom of the + // menubar instead of the top of the screen. That change breaks at least + // Cocoa_WarpMouse and probably other things as well. + r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height; } static void @@ -389,11 +392,11 @@ isMoving = NO; SDL_Mouse *mouse = SDL_GetMouse(); - if (pendingWindowWarpX >= 0 && pendingWindowWarpY >= 0) { - mouse->WarpMouse(_data->window, pendingWindowWarpX, pendingWindowWarpY); - pendingWindowWarpX = pendingWindowWarpY = -1; + if (pendingWindowWarpX != INT_MAX && pendingWindowWarpY != INT_MAX) { + mouse->WarpMouseGlobal(pendingWindowWarpX, pendingWindowWarpY); + pendingWindowWarpX = pendingWindowWarpY = INT_MAX; } - if (mouse->relative_mode && SDL_GetMouseFocus() == _data->window) { + if (mouse->relative_mode && !mouse->relative_mode_warp && mouse->focus == _data->window) { mouse->SetRelativeMouseMode(SDL_TRUE); } } @@ -413,7 +416,7 @@ - (void)windowWillMove:(NSNotification *)aNotification { if ([_data->nswindow isKindOfClass:[SDLWindow class]]) { - pendingWindowWarpX = pendingWindowWarpY = -1; + pendingWindowWarpX = pendingWindowWarpY = INT_MAX; isMoving = YES; } } @@ -500,7 +503,7 @@ { SDL_Window *window = _data->window; SDL_Mouse *mouse = SDL_GetMouse(); - if (mouse->relative_mode && ![self isMoving]) { + if (mouse->relative_mode && !mouse->relative_mode_warp && ![self isMoving]) { mouse->SetRelativeMouseMode(SDL_TRUE); } @@ -532,7 +535,7 @@ - (void)windowDidResignKey:(NSNotification *)aNotification { SDL_Mouse *mouse = SDL_GetMouse(); - if (mouse->relative_mode) { + if (mouse->relative_mode && !mouse->relative_mode_warp) { mouse->SetRelativeMouseMode(SDL_FALSE); }