diff options
author | Ryan C. Gordon <icculus@icculus.org> | 2014-06-25 17:06:12 -0400 |
---|---|---|
committer | Ryan C. Gordon <icculus@icculus.org> | 2014-06-25 17:06:12 -0400 |
commit | dfd802ae0b3cebd8bc75b09fac9677a6f1fec0fd (patch) | |
tree | 65792e933265f26c33c39b9ec7d60a6d5b8afa49 /src/video/cocoa/SDL_cocoamouse.m | |
parent | 0746af0c63ee2a74901462335936968eeffcfefb (diff) | |
parent | a53f4799bd4e164497ff8d0e42491ae466538bf7 (diff) | |
download | sdl-dfd802ae0b3cebd8bc75b09fac9677a6f1fec0fd.tar.gz |
Merged Ryan's SDL-gui-backend branch.
Adds three APIs, and implements them on X11, Cocoa, and Windows:
- SDL_CaptureMouse()
- SDL_GetGlobalMouseState()
- SDL_SetWindowHitTest()
Diffstat (limited to 'src/video/cocoa/SDL_cocoamouse.m')
-rw-r--r-- | src/video/cocoa/SDL_cocoamouse.m | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m index dbd26aee8..287dcd719 100644 --- a/src/video/cocoa/SDL_cocoamouse.m +++ b/src/video/cocoa/SDL_cocoamouse.m @@ -241,6 +241,30 @@ Cocoa_WarpMouse(SDL_Window * window, int x, int y) } } +static void +Cocoa_WarpMouseGlobal(int x, int y) +{ + SDL_Mouse *mouse = SDL_GetMouse(); + CGPoint point = CGPointMake((float)x, (float)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 && mouse->focus) { + /* CGWarpMouseCursorPosition doesn't generate a window event, unlike our + * other implementations' APIs. + */ + SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 0, x - mouse->focus->x, y - mouse->focus->y); + } +} + static int Cocoa_SetRelativeMouseMode(SDL_bool enabled) { @@ -271,6 +295,15 @@ Cocoa_SetRelativeMouseMode(SDL_bool enabled) if (result != kCGErrorSuccess) { return SDL_SetError("CGAssociateMouseAndMouseCursorPosition() failed"); } + + /* The hide/unhide calls are redundant most of the time, but they fix + * https://bugzilla.libsdl.org/show_bug.cgi?id=2550 + */ + if (enabled) { + [NSCursor hide]; + } else { + [NSCursor unhide]; + } return 0; } @@ -319,6 +352,7 @@ Cocoa_InitMouse(_THIS) mouse->ShowCursor = Cocoa_ShowCursor; mouse->FreeCursor = Cocoa_FreeCursor; mouse->WarpMouse = Cocoa_WarpMouse; + mouse->WarpMouseGlobal = Cocoa_WarpMouseGlobal; mouse->SetRelativeMouseMode = Cocoa_SetRelativeMouseMode; mouse->CaptureMouse = Cocoa_CaptureMouse; mouse->GetGlobalMouseState = Cocoa_GetGlobalMouseState; @@ -350,8 +384,11 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event) } SDL_Mouse *mouse = SDL_GetMouse(); - SDL_MouseData *driverdata = (SDL_MouseData*)mouse->driverdata; + if (!driverdata) { + return; /* can happen when returning from fullscreen Space on shutdown */ + } + const SDL_bool seenWarp = driverdata->seenWarp; driverdata->seenWarp = NO; |