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.
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
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)];