diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index b11626c7..1760d2ab 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -244,6 +244,17 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) free(displays); + for (i = 0; i < monitorCount; i++) + { + if (CGDisplayIsMain(monitors[i]->ns.displayID)) + { + _GLFWmonitor* temp = monitors[0]; + monitors[0] = monitors[i]; + monitors[i] = temp; + break; + } + } + *count = monitorCount; return monitors; } diff --git a/src/internal.h b/src/internal.h index fed23dd1..71c7c330 100644 --- a/src/internal.h +++ b/src/internal.h @@ -257,8 +257,6 @@ struct _GLFWmonitor { char* name; - GLboolean primary; - // Physical dimensions in millimeters. int widthMM, heightMM; // Logical orientation of the screen on the desktop @@ -686,7 +684,6 @@ GLboolean _glfwIsValidContext(_GLFWwndconfig* wndconfig); /*! @ingroup utility */ _GLFWmonitor* _glfwCreateMonitor(const char* name, - GLboolean primary, int widthMM, int heightMM, int x, int y); diff --git a/src/monitor.c b/src/monitor.c index 4ec7ddde..f7dcfe5f 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -156,7 +156,6 @@ void _glfwInputMonitorChange(void) ////////////////////////////////////////////////////////////////////////// _GLFWmonitor* _glfwCreateMonitor(const char* name, - GLboolean primary, int widthMM, int heightMM, int x, int y) { @@ -168,7 +167,6 @@ _GLFWmonitor* _glfwCreateMonitor(const char* name, } monitor->name = strdup(name); - monitor->primary = primary; monitor->widthMM = widthMM; monitor->heightMM = heightMM; monitor->positionX = x; @@ -280,31 +278,13 @@ GLFWAPI GLFWmonitor** glfwGetMonitors(int* count) GLFWAPI GLFWmonitor* glfwGetPrimaryMonitor(void) { - int i; - _GLFWmonitor* primary = NULL; - if (!_glfwInitialized) { _glfwInputError(GLFW_NOT_INITIALIZED, NULL); return NULL; } - for (i = 0; i < _glfw.monitorCount; i++) - { - if (_glfw.monitors[i]->primary) - { - primary = _glfw.monitors[i]; - break; - } - } - - if (!primary) - { - _glfwInputError(GLFW_PLATFORM_ERROR, NULL); - return NULL; - } - - return (GLFWmonitor*) primary; + return (GLFWmonitor*) _glfw.monitors[0]; } GLFWAPI void glfwGetMonitorPos(GLFWmonitor* handle, int* xpos, int* ypos) diff --git a/src/win32_monitor.c b/src/win32_monitor.c index f49af247..bf59df07 100644 --- a/src/win32_monitor.c +++ b/src/win32_monitor.c @@ -102,6 +102,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) int size = 0, found = 0; _GLFWmonitor** monitors = NULL; DWORD adapterIndex = 0; + int primaryIndex = 0; for (;;) { @@ -111,7 +112,6 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) DEVMODE settings; char* name; HDC dc; - GLboolean primary; ZeroMemory(&adapter, sizeof(DISPLAY_DEVICE)); adapter.cb = sizeof(DISPLAY_DEVICE); @@ -156,7 +156,8 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) EnumDisplayDevices(adapter.DeviceName, 0, &display, 0); dc = CreateDC(L"DISPLAY", display.DeviceString, NULL, NULL); - primary = adapter.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE; + if (adapter.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) + primaryIndex = found; name = _glfwCreateUTF8FromWideString(display.DeviceString); if (!name) @@ -165,7 +166,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) return NULL; } - monitors[found] = _glfwCreateMonitor(name, primary, + monitors[found] = _glfwCreateMonitor(name, GetDeviceCaps(dc, HORZSIZE), GetDeviceCaps(dc, VERTSIZE), settings.dmPosition.x, @@ -184,6 +185,13 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) found++; } + if (primaryIndex > 0) + { + _GLFWmonitor* temp = monitors[0]; + monitors[0] = monitors[primaryIndex]; + monitors[primaryIndex] = temp; + } + *count = found; return monitors; } diff --git a/src/x11_monitor.c b/src/x11_monitor.c index fefd2c5a..c9bf05c5 100644 --- a/src/x11_monitor.c +++ b/src/x11_monitor.c @@ -193,7 +193,6 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* found) } monitors[*found] = _glfwCreateMonitor(oi->name, - output == primary, oi->mm_width, oi->mm_height, ci->x, ci->y); @@ -207,6 +206,17 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* found) } XRRFreeScreenResources(sr); + + for (i = 0; i < *found; i++) + { + if (monitors[i]->x11.output == primary) + { + _GLFWmonitor* temp = monitors[0]; + monitors[0] = monitors[i]; + monitors[i] = temp; + break; + } + } } else { @@ -222,11 +232,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* found) widthMM = DisplayWidthMM(_glfw.x11.display, _glfw.x11.screen); heightMM = DisplayHeightMM(_glfw.x11.display, _glfw.x11.screen); - monitors[0] = _glfwCreateMonitor("Display", - GL_TRUE, - widthMM, heightMM, - 0, 0); - + monitors[0] = _glfwCreateMonitor("Display", widthMM, heightMM, 0, 0); *found = 1; }