src/video/cocoa/SDL_cocoamouse.m
changeset 8815 c6d0a457f3b2
parent 8800 0d406d07509b
child 8816 7e2f5d693149
     1.1 --- a/src/video/cocoa/SDL_cocoamouse.m	Wed Jun 04 10:52:34 2014 -0700
     1.2 +++ b/src/video/cocoa/SDL_cocoamouse.m	Wed Jun 04 10:55:26 2014 -0700
     1.3 @@ -241,6 +241,30 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +static void
     1.8 +Cocoa_WarpMouseGlobal(int x, int y)
     1.9 +{
    1.10 +    SDL_Mouse *mouse = SDL_GetMouse();
    1.11 +    CGPoint point = CGPointMake((float)x, (float)y);
    1.12 +
    1.13 +    Cocoa_HandleMouseWarp(point.x, point.y);
    1.14 +
    1.15 +    /* According to the docs, this was deprecated in 10.6, but it's still
    1.16 +     * around. The substitute requires a CGEventSource, but I'm not entirely
    1.17 +     * sure how we'd procure the right one for this event.
    1.18 +     */
    1.19 +    CGSetLocalEventsSuppressionInterval(0.0);
    1.20 +    CGWarpMouseCursorPosition(point);
    1.21 +    CGSetLocalEventsSuppressionInterval(0.25);
    1.22 +
    1.23 +    if (!mouse->relative_mode && mouse->focus) {
    1.24 +        /* CGWarpMouseCursorPosition doesn't generate a window event, unlike our
    1.25 +         * other implementations' APIs.
    1.26 +         */
    1.27 +        SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 0, x - mouse->focus.x, y - mouse->focus.y);
    1.28 +    }
    1.29 +}
    1.30 +
    1.31  static int
    1.32  Cocoa_SetRelativeMouseMode(SDL_bool enabled)
    1.33  {
    1.34 @@ -295,6 +319,7 @@
    1.35      mouse->ShowCursor = Cocoa_ShowCursor;
    1.36      mouse->FreeCursor = Cocoa_FreeCursor;
    1.37      mouse->WarpMouse = Cocoa_WarpMouse;
    1.38 +    mouse->WarpMouseGlobal = Cocoa_WarpMouseGlobal;
    1.39      mouse->SetRelativeMouseMode = Cocoa_SetRelativeMouseMode;
    1.40  
    1.41      SDL_SetDefaultCursor(Cocoa_CreateDefaultCursor());