Mac: SDL_SetWindowPosition is now relative to the menubar.
authorJørgen P. Tjernø <jorgen@valvesoftware.com>
Tue, 30 Jul 2013 16:58:16 -0700
changeset 87276b4f9d40414b
parent 7655 8f71b590aff6
child 8730 9b97d5eabe55
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.
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Sun Aug 18 11:15:30 2013 +0200
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Tue Jul 30 16:58:16 2013 -0700
     1.3 @@ -37,9 +37,10 @@
     1.4  
     1.5  static Uint32 s_moveHack;
     1.6  
     1.7 -static __inline__ void ConvertNSRect(NSRect *r)
     1.8 +static __inline__ void ConvertNSRect(NSScreen *screen, NSRect *r)
     1.9  {
    1.10 -    r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
    1.11 +    NSRect visibleScreen = [screen visibleFrame];
    1.12 +    r->origin.y = visibleScreen.size.height - r->origin.y - r->size.height;
    1.13  }
    1.14  
    1.15  static void ScheduleContextUpdates(SDL_WindowData *data)
    1.16 @@ -201,7 +202,7 @@
    1.17      SDL_Window *window = _data->window;
    1.18      NSWindow *nswindow = _data->nswindow;
    1.19      NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
    1.20 -    ConvertNSRect(&rect);
    1.21 +    ConvertNSRect([nswindow screen], &rect);
    1.22  
    1.23      if (s_moveHack) {
    1.24          SDL_bool blockMove = ((SDL_GetTicks() - s_moveHack) < 500);
    1.25 @@ -212,7 +213,7 @@
    1.26              /* Cocoa is adjusting the window in response to a mode change */
    1.27              rect.origin.x = window->x;
    1.28              rect.origin.y = window->y;
    1.29 -            ConvertNSRect(&rect);
    1.30 +            ConvertNSRect([nswindow screen], &rect);
    1.31              [nswindow setFrameOrigin:rect.origin];
    1.32              return;
    1.33          }
    1.34 @@ -229,8 +230,9 @@
    1.35  - (void)windowDidResize:(NSNotification *)aNotification
    1.36  {
    1.37      int x, y, w, h;
    1.38 -    NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]];
    1.39 -    ConvertNSRect(&rect);
    1.40 +    NSWindow *nswindow = _data->nswindow;
    1.41 +    NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
    1.42 +    ConvertNSRect([nswindow screen], &rect);
    1.43      x = (int)rect.origin.x;
    1.44      y = (int)rect.origin.y;
    1.45      w = (int)rect.size.width;
    1.46 @@ -625,7 +627,7 @@
    1.47      /* Fill in the SDL window with the window data */
    1.48      {
    1.49          NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
    1.50 -        ConvertNSRect(&rect);
    1.51 +        ConvertNSRect([nswindow screen], &rect);
    1.52          window->x = (int)rect.origin.x;
    1.53          window->y = (int)rect.origin.y;
    1.54          window->w = (int)rect.size.width;
    1.55 @@ -700,7 +702,7 @@
    1.56      rect.origin.y = window->y;
    1.57      rect.size.width = window->w;
    1.58      rect.size.height = window->h;
    1.59 -    ConvertNSRect(&rect);
    1.60 +    ConvertNSRect([[NSScreen screens] objectAtIndex:0], &rect);
    1.61  
    1.62      style = GetWindowStyle(window);
    1.63  
    1.64 @@ -803,7 +805,7 @@
    1.65      rect.origin.y = window->y;
    1.66      rect.size.width = window->w;
    1.67      rect.size.height = window->h;
    1.68 -    ConvertNSRect(&rect);
    1.69 +    ConvertNSRect([nswindow screen], &rect);
    1.70  
    1.71      moveHack = s_moveHack;
    1.72      s_moveHack = 0;
    1.73 @@ -998,7 +1000,7 @@
    1.74          rect.origin.y = bounds.y;
    1.75          rect.size.width = bounds.w;
    1.76          rect.size.height = bounds.h;
    1.77 -        ConvertNSRect(&rect);
    1.78 +        ConvertNSRect([nswindow screen], &rect);
    1.79  
    1.80          /* Hack to fix origin on Mac OS X 10.4 */
    1.81          NSRect screenRect = [[nswindow screen] frame];
    1.82 @@ -1016,7 +1018,7 @@
    1.83          rect.origin.y = window->windowed.y;
    1.84          rect.size.width = window->windowed.w;
    1.85          rect.size.height = window->windowed.h;
    1.86 -        ConvertNSRect(&rect);
    1.87 +        ConvertNSRect([nswindow screen], &rect);
    1.88  
    1.89          if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
    1.90              [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];