Mac: Fixed SDL_SetWindowSize to set the size of the content area of the window, rather than the total size including decorations.
authorAlex Szpakowski <slime73@gmail.com>
Wed, 09 Sep 2015 13:55:11 -0300
changeset 9860 858a9b80e18a
parent 9859 2ec928ff921c
child 9861 2117766ff8d2
Mac: Fixed SDL_SetWindowSize to set the size of the content area of the window, rather than the total size including decorations.
src/video/cocoa/SDL_cocoawindow.m
--- a/src/video/cocoa/SDL_cocoawindow.m	Mon Sep 07 13:25:36 2015 -0400
+++ b/src/video/cocoa/SDL_cocoawindow.m	Wed Sep 09 13:55:11 2015 -0300
@@ -1288,13 +1288,23 @@
 {
     SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
     NSWindow *nswindow = windata->nswindow;
+    NSRect rect;
+    Uint32 moveHack;
 
-    NSRect frame = [nswindow frame];
-    frame.origin.y = (frame.origin.y + frame.size.height) - ((float) window->h);
-    frame.size.width = window->w;
-    frame.size.height = window->h;
+    /* Cocoa will resize the window from the bottom-left rather than the
+     * top-left when -[nswindow setContentSize:] is used, so we must set the
+     * entire frame based on the new size, in order to preserve the position.
+     */
+    rect.origin.x = window->x;
+    rect.origin.y = window->y;
+    rect.size.width = window->w;
+    rect.size.height = window->h;
+    ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
 
-    [nswindow setFrame:frame display:YES];
+    moveHack = s_moveHack;
+    s_moveHack = 0;
+    [nswindow setFrame:[nswindow frameRectForContentRect:rect] display:YES];
+    s_moveHack = moveHack;
 
     ScheduleContextUpdates(windata);
 }}