src/video/cocoa/SDL_cocoamouse.m
changeset 8953 dc80dc0bd22e
parent 8862 523abf9a4fb4
parent 8952 4bb098814ec4
child 8986 1c81316ac642
     1.1 --- a/src/video/cocoa/SDL_cocoamouse.m	Wed Jun 25 02:08:37 2014 -0700
     1.2 +++ b/src/video/cocoa/SDL_cocoamouse.m	Wed Jun 25 17:06:12 2014 -0400
     1.3 @@ -307,6 +307,39 @@
     1.4      return 0;
     1.5  }
     1.6  
     1.7 +static int
     1.8 +Cocoa_CaptureMouse(SDL_Window *window)
     1.9 +{
    1.10 +    /* our Cocoa event code already tracks the mouse outside the window,
    1.11 +        so all we have to do here is say "okay" and do what we always do. */
    1.12 +    return 0;
    1.13 +}
    1.14 +
    1.15 +static Uint32
    1.16 +Cocoa_GetGlobalMouseState(int *x, int *y)
    1.17 +{
    1.18 +    const NSUInteger cocoaButtons = [NSEvent pressedMouseButtons];
    1.19 +    const NSPoint cocoaLocation = [NSEvent mouseLocation];
    1.20 +    Uint32 retval = 0;
    1.21 +
    1.22 +    for (NSScreen *screen in [NSScreen screens]) {
    1.23 +        NSRect frame = [screen frame];
    1.24 +        if (NSPointInRect(cocoaLocation, frame)) {
    1.25 +            *x = (int) cocoaLocation.x;
    1.26 +            *y = (int) ((frame.origin.y + frame.size.height) - cocoaLocation.y);
    1.27 +            break;
    1.28 +        }
    1.29 +    }
    1.30 +
    1.31 +    retval |= (cocoaButtons & (1 << 0)) ? SDL_BUTTON_LMASK : 0;
    1.32 +    retval |= (cocoaButtons & (1 << 1)) ? SDL_BUTTON_RMASK : 0;
    1.33 +    retval |= (cocoaButtons & (1 << 2)) ? SDL_BUTTON_MMASK : 0;
    1.34 +    retval |= (cocoaButtons & (1 << 3)) ? SDL_BUTTON_X1MASK : 0;
    1.35 +    retval |= (cocoaButtons & (1 << 4)) ? SDL_BUTTON_X2MASK : 0;
    1.36 +
    1.37 +    return retval;
    1.38 +}
    1.39 +
    1.40  void
    1.41  Cocoa_InitMouse(_THIS)
    1.42  {
    1.43 @@ -321,6 +354,8 @@
    1.44      mouse->WarpMouse = Cocoa_WarpMouse;
    1.45      mouse->WarpMouseGlobal = Cocoa_WarpMouseGlobal;
    1.46      mouse->SetRelativeMouseMode = Cocoa_SetRelativeMouseMode;
    1.47 +    mouse->CaptureMouse = Cocoa_CaptureMouse;
    1.48 +    mouse->GetGlobalMouseState = Cocoa_GetGlobalMouseState;
    1.49  
    1.50      SDL_SetDefaultCursor(Cocoa_CreateDefaultCursor());
    1.51