Browse Source

Fix full screen window position on OS X

Fixes #653.
Camilla Berglund 9 years ago
parent
commit
e82e2b7570
2 changed files with 17 additions and 20 deletions
  1. 1 0
      README.md
  2. 16 20
      src/cocoa_window.m

+ 1 - 0
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`

+ 16 - 20
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)