Navigation Menu

Skip to content

Commit

Permalink
Mac: SDL_SetWindowPosition is now relative to the menubar.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jorgenpt committed Apr 19, 2014
1 parent defd90b commit beff5ce
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -89,9 +89,10 @@ - (void)sendEvent:(NSEvent *)event

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
Expand Down Expand Up @@ -410,7 +411,7 @@ - (void)windowDidMove:(NSNotification *)aNotification
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);
Expand All @@ -421,7 +422,7 @@ - (void)windowDidMove:(NSNotification *)aNotification
/* 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;
}
Expand All @@ -446,7 +447,7 @@ - (void)windowDidResize:(NSNotification *)aNotification
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;
Expand Down Expand Up @@ -931,7 +932,7 @@ - (void)resetCursorRects
/* 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;
Expand Down Expand Up @@ -1007,7 +1008,7 @@ - (void)resetCursorRects
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);

Expand Down Expand Up @@ -1135,7 +1136,7 @@ - (void)resetCursorRects
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;
Expand Down Expand Up @@ -1335,7 +1336,7 @@ - (void)resetCursorRects
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];
Expand All @@ -1353,7 +1354,7 @@ - (void)resetCursorRects
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)];
Expand Down

0 comments on commit beff5ce

Please sign in to comment.