diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index 076bc39f..46fa11e2 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -263,9 +263,9 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) { const CGSize size = CGDisplayScreenSize(displays[i]); const CGRect bounds = CGDisplayBounds(displays[i]); - const char* name = getDisplayName(displays[i]); - monitors[found] = _glfwCreateMonitor(name, + monitors[found] = _glfwCreateMonitor(getDisplayName(displays[i]), + CGDisplayIsMain(displays[i]), size.width, size.height, bounds.origin.x, bounds.origin.y); diff --git a/src/internal.h b/src/internal.h index 4acebe95..5a353b22 100755 --- a/src/internal.h +++ b/src/internal.h @@ -209,6 +209,9 @@ struct _GLFWmonitor void* userPointer; char* name; + + GLboolean primary; + // physical dimensions in millimeters. int physicalWidth; int physicalHeight; @@ -393,6 +396,7 @@ GLboolean _glfwIsValidContext(_GLFWwndconfig* wndconfig); // Monitor management (monitor.c) _GLFWmonitor* _glfwCreateMonitor(const char* name, + GLboolean primary, int physicalWidth, int physicalHeight, int screenX, int screenY); void _glfwDestroyMonitor(_GLFWmonitor* monitor); diff --git a/src/monitor.c b/src/monitor.c index 269bef8a..990e375f 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -78,6 +78,7 @@ static int compareVideoModes(const void* firstPtr, const void* secondPtr) //======================================================================== _GLFWmonitor* _glfwCreateMonitor(const char* name, + GLboolean primary, int physicalWidth, int physicalHeight, int screenX, int screenY) { @@ -89,6 +90,7 @@ _GLFWmonitor* _glfwCreateMonitor(const char* name, } monitor->name = strdup(name); + monitor->primary = primary; monitor->physicalWidth = physicalWidth; monitor->physicalHeight = physicalHeight; monitor->screenX = screenX; @@ -253,13 +255,31 @@ GLFWAPI GLFWmonitor* glfwGetMonitors(int* count) GLFWAPI GLFWmonitor glfwGetPrimaryMonitor(void) { + int i; + GLFWmonitor handle = NULL; + if (!_glfwInitialized) { _glfwSetError(GLFW_NOT_INITIALIZED, NULL); return NULL; } - return _glfwLibrary.monitors[0]; + for (i = 0; i < _glfwLibrary.monitorCount; i++) + { + if (_glfwLibrary.monitors[i]->primary) + { + handle = _glfwLibrary.monitors[i]; + break; + } + } + + if (!handle) + { + _glfwSetError(GLFW_PLATFORM_ERROR, NULL); + return NULL; + } + + return handle; } diff --git a/src/win32_monitor.c b/src/win32_monitor.c index a7d8bd24..34734c42 100644 --- a/src/win32_monitor.c +++ b/src/win32_monitor.c @@ -257,7 +257,9 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) EnumDisplayDevices(adapter.DeviceName, 0, &monitor, 0); dc = CreateDC(L"DISPLAY", monitor.DeviceString, NULL, NULL); - monitors[found] = _glfwCreateMonitor(name, + const GLboolean primary = adapter.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE; + + monitors[found] = _glfwCreateMonitor(name, primary, GetDeviceCaps(dc, HORZSIZE), GetDeviceCaps(dc, VERTSIZE), settings.dmPosition.x, diff --git a/src/x11_monitor.c b/src/x11_monitor.c index 39a7be82..60e498f1 100644 --- a/src/x11_monitor.c +++ b/src/x11_monitor.c @@ -465,6 +465,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) ci = XRRGetCrtcInfo(_glfwLibrary.X11.display, sr, oi->crtc); monitors[found] = _glfwCreateMonitor(oi->name, + i == 0, oi->mm_width, oi->mm_height, ci->x, ci->y);