Commit beff5cece6961fa47a8cd7f49607ea15d3cee301

J?rgen P. Tjern? 2014-04-19T13:15:53

Mac: SDL_SetWindowPosition is now relative to the menubar. It used to be that SDL_SetWindowPosition was relative to the top of the screen, which didn't make sense. In addition, borderless windows can be positioned *below* the menubar, so SDL_SetWindowPosition(win, 0, 0) on a borderless window would hide ~30ish pixels of the window below the menubar.

diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index 9e6edbb..f2b2dd6 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -89,9 +89,10 @@
 
 static Uint32 s_moveHack;
 
-static void ConvertNSRect(NSRect *r)
+static void ConvertNSRect(NSScreen *screen, NSRect *r)
 {
-    r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
+    NSRect visibleScreen = [screen visibleFrame];
+    r->origin.y = visibleScreen.size.height - r->origin.y - r->size.height;
 }
 
 static void
@@ -410,7 +411,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
     SDL_Window *window = _data->window;
     NSWindow *nswindow = _data->nswindow;
     NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
-    ConvertNSRect(&rect);
+    ConvertNSRect([nswindow screen], &rect);
 
     if (s_moveHack) {
         SDL_bool blockMove = ((SDL_GetTicks() - s_moveHack) < 500);
@@ -421,7 +422,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
             /* Cocoa is adjusting the window in response to a mode change */
             rect.origin.x = window->x;
             rect.origin.y = window->y;
-            ConvertNSRect(&rect);
+            ConvertNSRect([nswindow screen], &rect);
             [nswindow setFrameOrigin:rect.origin];
             return;
         }
@@ -446,7 +447,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
     NSWindow *nswindow = _data->nswindow;
     int x, y, w, h;
     NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
-    ConvertNSRect(&rect);
+    ConvertNSRect([nswindow screen], &rect);
     x = (int)rect.origin.x;
     y = (int)rect.origin.y;
     w = (int)rect.size.width;
@@ -931,7 +932,7 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
     /* Fill in the SDL window with the window data */
     {
         NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
-        ConvertNSRect(&rect);
+        ConvertNSRect([nswindow screen], &rect);
         window->x = (int)rect.origin.x;
         window->y = (int)rect.origin.y;
         window->w = (int)rect.size.width;
@@ -1007,7 +1008,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
     rect.origin.y = window->y;
     rect.size.width = window->w;
     rect.size.height = window->h;
-    ConvertNSRect(&rect);
+    ConvertNSRect([[NSScreen screens] objectAtIndex:0], &rect);
 
     style = GetWindowStyle(window);
 
@@ -1135,7 +1136,7 @@ Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
     rect.origin.y = window->y;
     rect.size.width = window->w;
     rect.size.height = window->h;
-    ConvertNSRect(&rect);
+    ConvertNSRect([nswindow screen], &rect);
 
     moveHack = s_moveHack;
     s_moveHack = 0;
@@ -1335,7 +1336,7 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
         rect.origin.y = bounds.y;
         rect.size.width = bounds.w;
         rect.size.height = bounds.h;
-        ConvertNSRect(&rect);
+        ConvertNSRect([nswindow screen], &rect);
 
         /* Hack to fix origin on Mac OS X 10.4 */
         NSRect screenRect = [[nswindow screen] frame];
@@ -1353,7 +1354,7 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
         rect.origin.y = window->windowed.y;
         rect.size.width = window->windowed.w;
         rect.size.height = window->windowed.h;
-        ConvertNSRect(&rect);
+        ConvertNSRect([nswindow screen], &rect);
 
         if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
             [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];