From 0df9cc2fc516220eff62ddd838352f92e9c24aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 14 Mar 2017 18:40:41 +0100 Subject: [PATCH] Win32: Improve monitor enumeration This changes enumeration to add as a GLFW monitor any active adapter without displays, even if other active adapters do have displays. Related to #441. Fixes #960. --- README.md | 1 + src/win32_monitor.c | 78 ++++++++++++++++----------------------------- 2 files changed, 29 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index a979061e..ad87fa02 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,7 @@ information on what to include when reporting a bug. - [Win32] Bugfix: Mouse capture logic lost secondary release messages (#954) - [Win32] Bugfix: The 32-bit Vulkan loader library static was not searched for - [Win32] Bugfix: Vulkan libraries have a new path as of SDK 1.0.42.0 (#956) +- [Win32] Bugfix: Monitors with no display devices were not enumerated (#960) - [X11] Replaced `_GLFW_HAS_XF86VM` compile-time option with dynamic loading - [X11] Bugfix: `glfwGetVideoMode` would segfault on Cygwin/X - [X11] Bugfix: Dynamic X11 library loading did not use full sonames (#941) diff --git a/src/win32_monitor.c b/src/win32_monitor.c index cc5e24f8..d91a02f8 100644 --- a/src/win32_monitor.c +++ b/src/win32_monitor.c @@ -94,7 +94,6 @@ void _glfwPollMonitorsWin32(void) _GLFWmonitor** disconnected = NULL; DWORD adapterIndex, displayIndex; DISPLAY_DEVICEW adapter, display; - GLFWbool hasDisplays = GLFW_FALSE; disconnectedCount = _glfw.monitorCount; if (disconnectedCount) @@ -105,30 +104,6 @@ void _glfwPollMonitorsWin32(void) _glfw.monitorCount * sizeof(_GLFWmonitor*)); } - // HACK: Check if any active adapters have connected displays - // If not, this is a headless system or a VMware guest - - for (adapterIndex = 0; ; adapterIndex++) - { - ZeroMemory(&adapter, sizeof(DISPLAY_DEVICEW)); - adapter.cb = sizeof(DISPLAY_DEVICEW); - - if (!EnumDisplayDevicesW(NULL, adapterIndex, &adapter, 0)) - break; - - if (!(adapter.StateFlags & DISPLAY_DEVICE_ACTIVE)) - continue; - - ZeroMemory(&display, sizeof(DISPLAY_DEVICEW)); - display.cb = sizeof(DISPLAY_DEVICEW); - - if (EnumDisplayDevicesW(adapter.DeviceName, 0, &display, 0)) - { - hasDisplays = GLFW_TRUE; - break; - } - } - for (adapterIndex = 0; ; adapterIndex++) { int type = _GLFW_INSERT_LAST; @@ -145,37 +120,40 @@ void _glfwPollMonitorsWin32(void) if (adapter.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) type = _GLFW_INSERT_FIRST; - if (hasDisplays) + for (displayIndex = 0; ; displayIndex++) { - for (displayIndex = 0; ; displayIndex++) + ZeroMemory(&display, sizeof(DISPLAY_DEVICEW)); + display.cb = sizeof(DISPLAY_DEVICEW); + + if (!EnumDisplayDevicesW(adapter.DeviceName, displayIndex, &display, 0)) + break; + + if (!(display.StateFlags & DISPLAY_DEVICE_ACTIVE)) + continue; + + for (i = 0; i < disconnectedCount; i++) { - ZeroMemory(&display, sizeof(DISPLAY_DEVICEW)); - display.cb = sizeof(DISPLAY_DEVICEW); - - if (!EnumDisplayDevicesW(adapter.DeviceName, displayIndex, &display, 0)) - break; - - for (i = 0; i < disconnectedCount; i++) + if (disconnected[i] && + wcscmp(disconnected[i]->win32.displayName, + display.DeviceName) == 0) { - if (disconnected[i] && - wcscmp(disconnected[i]->win32.displayName, - display.DeviceName) == 0) - { - disconnected[i] = NULL; - break; - } + disconnected[i] = NULL; + break; } - - if (i < disconnectedCount) - continue; - - _glfwInputMonitor(createMonitor(&adapter, &display), - GLFW_CONNECTED, type); - - type = _GLFW_INSERT_LAST; } + + if (i < disconnectedCount) + continue; + + _glfwInputMonitor(createMonitor(&adapter, &display), + GLFW_CONNECTED, type); + + type = _GLFW_INSERT_LAST; } - else + + // HACK: If an active adapter does not have any display devices + // (as sometimes happens), add it directly as a monitor + if (displayIndex == 0) { for (i = 0; i < disconnectedCount; i++) {