Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different Tim McDaniel On OSX, with revision 8729, the coordinate space for window position and the coordinate space for global mouse position don't match. For a non-fullscreen window, the window position is global relative to the bottom of the menubar. The global mouse position is relative to the top of the screen. This affects Cocoa_WarpMouse and potentially other things as well. Further, the coordinate system for window position is now affected by what screen it is on. For example, if I have two equal size screens oriented side by side such that the tops of the screens are equal in global space, with the menubar on one screen, and a window straddles the two screens, the window's y position makes no sense. The window's y position depends on what screen "most" of the window is on. So if I move the window horizontally just a bit, the y position of my window is now different by the size of the menubar, even though the window was not moved vertically. I'd like to reiterate that this was a fairly fundamental change (and a breaking change for us). If SDL OSX is to really support multi-display configurations, this is especially problematic. If the real concern is preventing windows from going under the menubar, then perhaps a solution involving something like overriding [NSWindow constrainFrameRect] would be less problematic than redefining the global window coord space for the main display.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m
index 4ea420d..f048060 100644
--- a/src/video/cocoa/SDL_cocoamouse.m
+++ b/src/video/cocoa/SDL_cocoamouse.m
@@ -208,41 +208,17 @@ Cocoa_ShowCursor(SDL_Cursor * cursor)
}
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 +239,12 @@ Cocoa_WarpMouseGlobal(int x, int y)
}
}
+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 --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index 63d6f21..29bba45 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -103,8 +103,7 @@ static Uint32 s_moveHack;
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;
+ r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
}
static void
@@ -389,11 +388,11 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
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 +412,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
- (void)windowWillMove:(NSNotification *)aNotification
{
if ([_data->nswindow isKindOfClass:[SDLWindow class]]) {
- pendingWindowWarpX = pendingWindowWarpY = -1;
+ pendingWindowWarpX = pendingWindowWarpY = INT_MAX;
isMoving = YES;
}
}
@@ -500,7 +499,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
{
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 +531,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
- (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);
}