From 4e38f31a86906315d3b598f2a66d5bbb15d5b8e6 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sat, 13 Aug 2016 17:49:20 +0200 Subject: [PATCH] Change GetClientWidth/GetClientHeight on macOS to grab size from view. Fix that GetClientWidth/Height returns 0 when queried before initial show. Allow window to be resizable on macOS. --- src/posix/cocoa/i_video.mm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index 242cb489b..8f8b7c135 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -169,7 +169,7 @@ namespace const NSInteger LEVEL_WINDOWED = NSNormalWindowLevel; const NSUInteger STYLE_MASK_FULLSCREEN = NSBorderlessWindowMask; - const NSUInteger STYLE_MASK_WINDOWED = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask; + const NSUInteger STYLE_MASK_WINDOWED = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask; } @@ -1207,12 +1207,18 @@ void SDLGLFB::ResetGammaTable() int SDLGLFB::GetClientWidth() { - return static_cast(rbOpts.width + 2.0f * rbOpts.shiftX); + NSView *view = [[NSOpenGLContext currentContext] view]; + NSRect backingBounds = [view convertRectToBacking: [view bounds]]; + int clientWidth = (int)backingBounds.size.width; + return clientWidth > 0 ? clientWidth : Width; } int SDLGLFB::GetClientHeight() { - return static_cast(rbOpts.height + 2.0f * rbOpts.shiftY); + NSView *view = [[NSOpenGLContext currentContext] view]; + NSRect backingBounds = [view convertRectToBacking: [view bounds]]; + int clientHeight = (int)backingBounds.size.height; + return clientHeight > 0 ? clientHeight : Height; }