src/video/cocoa/SDL_cocoamouse.m
changeset 5406 1517da4ab6b1
parent 5405 64fa8526e1ce
child 5419 210b0abe9e44
     1.1 --- a/src/video/cocoa/SDL_cocoamouse.m	Sun Feb 27 21:36:23 2011 -0800
     1.2 +++ b/src/video/cocoa/SDL_cocoamouse.m	Sun Feb 27 22:06:46 2011 -0800
     1.3 @@ -116,6 +116,23 @@
     1.4      CGWarpMouseCursorPosition(point);
     1.5  }
     1.6  
     1.7 +static int
     1.8 +Cocoa_SetRelativeMouseMode(SDL_bool enabled)
     1.9 +{
    1.10 +    CGError result;
    1.11 +
    1.12 +    if (enabled) {
    1.13 +        result = CGAssociateMouseAndMouseCursorPosition(NO);
    1.14 +    } else {
    1.15 +        result = CGAssociateMouseAndMouseCursorPosition(YES);
    1.16 +    }
    1.17 +    if (result != kCGErrorSuccess) {
    1.18 +        SDL_SetError("CGAssociateMouseAndMouseCursorPosition() failed");
    1.19 +        return -1;
    1.20 +    }
    1.21 +    return 0;
    1.22 +}
    1.23 +
    1.24  void
    1.25  Cocoa_InitMouse(_THIS)
    1.26  {
    1.27 @@ -123,8 +140,9 @@
    1.28  
    1.29      mouse->CreateCursor = Cocoa_CreateCursor;
    1.30      mouse->ShowCursor = Cocoa_ShowCursor;
    1.31 +    mouse->FreeCursor = Cocoa_FreeCursor;
    1.32      mouse->WarpMouse = Cocoa_WarpMouse;
    1.33 -    mouse->FreeCursor = Cocoa_FreeCursor;
    1.34 +    mouse->SetRelativeMouseMode = Cocoa_SetRelativeMouseMode;
    1.35  
    1.36      SDL_SetDefaultCursor(Cocoa_CreateDefaultCursor());
    1.37  }
    1.38 @@ -147,7 +165,13 @@
    1.39  void
    1.40  Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
    1.41  {
    1.42 -    /* We're correctly using views even in fullscreen mode now */
    1.43 +    SDL_Mouse *mouse = SDL_GetMouse();
    1.44 +
    1.45 +    if (mouse->relative_mode && [event type] == NSMouseMoved) {
    1.46 +        float x = [event deltaX];
    1.47 +        float y = [event deltaY];
    1.48 +        SDL_SendMouseMotion(mouse->focus, 1, (int)x, (int)y);
    1.49 +    }
    1.50  }
    1.51  
    1.52  void