Added initial NSScreen integration.
This (tentatively) fixes the bug of full screen windows on OS X always
opening on the primary monitor.
diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h
index 9a0e47a..37502f2 100644
--- a/include/GL/glfw3.h
+++ b/include/GL/glfw3.h
@@ -1171,9 +1171,6 @@
*
* @note This function may only be called from the main thread.
*
- * @bug **Mac OS X:** The primary monitor is always used for full screen
- * windows, regardless of which monitor was specified.
- *
* @sa glfwDestroyWindow
*
* @ingroup window
diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m
index 028adfa..a8fa832 100644
--- a/src/cocoa_monitor.m
+++ b/src/cocoa_monitor.m
@@ -272,6 +272,35 @@
}
}
+ NSArray* screens = [NSScreen screens];
+
+ for (i = 0; i < monitorCount; i++)
+ {
+ int j;
+
+ for (j = 0; j < [screens count]; j++)
+ {
+ NSScreen* screen = [screens objectAtIndex:j];
+ NSDictionary* dictionary = [screen deviceDescription];
+ NSNumber* number = [dictionary objectForKey:@"NSScreenNumber"];
+
+ if (monitors[i]->ns.displayID == [number unsignedIntegerValue])
+ {
+ monitors[i]->ns.screen = screen;
+ break;
+ }
+ }
+
+ if (monitors[i]->ns.screen == nil)
+ {
+ _glfwDestroyMonitors(monitors, monitorCount);
+ _glfwInputError(GLFW_PLATFORM_ERROR,
+ "Cocoa: Failed to find NSScreen for CGDisplay %s",
+ monitors[i]->name);
+ return NULL;
+ }
+ }
+
*count = monitorCount;
return monitors;
}
diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h
index 9eec3c2..c1dde4d 100644
--- a/src/cocoa_platform.h
+++ b/src/cocoa_platform.h
@@ -119,8 +119,9 @@
//------------------------------------------------------------------------
typedef struct _GLFWmonitorNS
{
- CGDirectDisplayID displayID;
- CGDisplayModeRef previousMode;
+ CGDirectDisplayID displayID;
+ CGDisplayModeRef previousMode;
+ id screen;
} _GLFWmonitorNS;
diff --git a/src/cocoa_window.m b/src/cocoa_window.m
index 6e78172..f4b8e78 100644
--- a/src/cocoa_window.m
+++ b/src/cocoa_window.m
@@ -759,7 +759,7 @@
return GL_FALSE;
_glfwPlatformShowWindow(window);
- [[window->ns.object contentView] enterFullScreenMode:[NSScreen mainScreen]
+ [[window->ns.object contentView] enterFullScreenMode:wndconfig->monitor->ns.screen
withOptions:nil];
}
diff --git a/src/init.c b/src/init.c
index b810770..dbed3c5 100644
--- a/src/init.c
+++ b/src/init.c
@@ -164,7 +164,9 @@
_glfwPlatformSetGammaRamp(monitor, &monitor->originalRamp);
}
- _glfwDestroyMonitors();
+ _glfwDestroyMonitors(_glfw.monitors, _glfw.monitorCount);
+ _glfw.monitors = NULL;
+ _glfw.monitorCount = 0;
_glfwPlatformTerminate();
diff --git a/src/internal.h b/src/internal.h
index 7cebf01..61b6f64 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -706,6 +706,6 @@
/*! @ingroup utility
*/
-void _glfwDestroyMonitors(void);
+void _glfwDestroyMonitors(_GLFWmonitor** monitors, int count);
#endif // _internal_h_
diff --git a/src/monitor.c b/src/monitor.c
index effaf60..b98cb89 100644
--- a/src/monitor.c
+++ b/src/monitor.c
@@ -144,7 +144,7 @@
}
}
- _glfwDestroyMonitors();
+ _glfwDestroyMonitors(_glfw.monitors, _glfw.monitorCount);
_glfw.monitors = monitors;
_glfw.monitorCount = monitorCount;
@@ -175,16 +175,14 @@
free(monitor);
}
-void _glfwDestroyMonitors(void)
+void _glfwDestroyMonitors(_GLFWmonitor** monitors, int count)
{
int i;
- for (i = 0; i < _glfw.monitorCount; i++)
- _glfwDestroyMonitor(_glfw.monitors[i]);
+ for (i = 0; i < count; i++)
+ _glfwDestroyMonitor(monitors[i]);
- free(_glfw.monitors);
- _glfw.monitors = NULL;
- _glfw.monitorCount = 0;
+ free(monitors);
}
const GLFWvidmode* _glfwChooseVideoMode(_GLFWmonitor* monitor,