From e82e2b7570b1f4ffd3ad8117fb1b9db25e7488a7 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 Dec 2015 21:03:24 +0100 Subject: [PATCH] Fix full screen window position on OS X Fixes #653. --- README.md | 1 + src/cocoa_window.m | 36 ++++++++++++++++-------------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index e78bb897..b62ff742 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ used by the tests and examples and are not required to build the library. - Removed dependency on external OpenGL or OpenGL ES headers - [Win32] Added support for Windows 8.1 per-monitor DPI - [Cocoa] Removed support for OS X 10.6 + - [Cocoa] Bugfix: Full screen windows on secondary monitors were mispositioned - [X11] Bugfix: Monitor connection and disconnection events were not reported - [X11] Bugfix: Decoding of UTF-8 text from XIM could continue past the end - [POSIX] Bugfix: An unrelated TLS key could be deleted by `glfwTerminate` diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 15bc48e5..1d4ce2f8 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -64,22 +64,27 @@ static void centerCursor(_GLFWwindow *window) _glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0); } +// Transforms the specified y-coordinate between the CG display and NS screen +// coordinate systems +// +static float transformY(float y) +{ + const float height = CGDisplayBounds(CGMainDisplayID()).size.height; + return height - y; +} + // Enter full screen mode // static GLFWbool enterFullscreenMode(_GLFWwindow* window) { - GLFWvidmode mode; - GLFWbool status; - int xpos, ypos; - - status = _glfwSetVideoMode(window->monitor, &window->videoMode); - - _glfwPlatformGetVideoMode(window->monitor, &mode); - _glfwPlatformGetMonitorPos(window->monitor, &xpos, &ypos); - - [window->ns.object setFrame:NSMakeRect(xpos, ypos, mode.width, mode.height) - display:YES]; + const GLFWbool status = _glfwSetVideoMode(window->monitor, &window->videoMode); + const CGRect bounds = CGDisplayBounds(window->monitor->ns.displayID); + const NSRect frame = NSMakeRect(bounds.origin.x, + transformY(bounds.origin.y + bounds.size.height), + bounds.size.width, + bounds.size.height); + [window->ns.object setFrame:frame display:YES]; return status; } @@ -90,15 +95,6 @@ static void leaveFullscreenMode(_GLFWwindow* window) _glfwRestoreVideoMode(window->monitor); } -// Transforms the specified y-coordinate between the CG display and NS screen -// coordinate systems -// -static float transformY(float y) -{ - const float height = CGDisplayBounds(CGMainDisplayID()).size.height; - return height - y; -} - // Translates OS X key modifiers into GLFW ones // static int translateFlags(NSUInteger flags)