diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 9a0e47a9..37502f2c 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -1171,9 +1171,6 @@ GLFWAPI void glfwWindowHint(int target, int hint); * * @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 028adfac..a8fa832b 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -272,6 +272,35 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) } } + 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 9eec3c28..c1dde4d3 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -119,8 +119,9 @@ typedef struct _GLFWlibraryNS //------------------------------------------------------------------------ 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 6e781723..f4b8e782 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -759,7 +759,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, 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 b8107704..dbed3c5a 100644 --- a/src/init.c +++ b/src/init.c @@ -164,7 +164,9 @@ GLFWAPI void glfwTerminate(void) _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 7cebf016..61b6f64e 100644 --- a/src/internal.h +++ b/src/internal.h @@ -706,6 +706,6 @@ void _glfwDestroyMonitor(_GLFWmonitor* monitor); /*! @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 effaf609..b98cb89e 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -144,7 +144,7 @@ void _glfwInputMonitorChange(void) } } - _glfwDestroyMonitors(); + _glfwDestroyMonitors(_glfw.monitors, _glfw.monitorCount); _glfw.monitors = monitors; _glfw.monitorCount = monitorCount; @@ -175,16 +175,14 @@ void _glfwDestroyMonitor(_GLFWmonitor* monitor) 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,