From 550e04c57976c6cedf8cd52ea38907bd59981a7c Mon Sep 17 00:00:00 2001 From: Paul Gofman Date: Tue, 16 May 2023 10:21:47 -0600 Subject: [PATCH] [dxgi] Preserve system monitor sort order in enumMonitors() --- src/wsi/win32/wsi_monitor_win32.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/wsi/win32/wsi_monitor_win32.cpp b/src/wsi/win32/wsi_monitor_win32.cpp index c9c2bef9b..ae4a0ff35 100644 --- a/src/wsi/win32/wsi_monitor_win32.cpp +++ b/src/wsi/win32/wsi_monitor_win32.cpp @@ -18,7 +18,7 @@ namespace dxvk::wsi { } struct MonitorEnumInfo { - const WCHAR *gdiDeviceName; + std::set *gdiDeviceNames; UINT iMonitorId; HMONITOR oMonitor; }; @@ -30,13 +30,13 @@ namespace dxvk::wsi { LPARAM lp) { auto data = reinterpret_cast(lp); - if (data->gdiDeviceName) + if (data->gdiDeviceNames) { MONITORINFOEXW monitorInfo; monitorInfo.cbSize = sizeof(monitorInfo); GetMonitorInfoW(hmon, (MONITORINFO *)&monitorInfo); - if (wcscmp(data->gdiDeviceName, monitorInfo.szDevice)) + if (data->gdiDeviceNames->find(monitorInfo.szDevice) == data->gdiDeviceNames->end()) return TRUE; } if (data->iMonitorId--) @@ -49,7 +49,7 @@ namespace dxvk::wsi { MonitorEnumInfo info; info.iMonitorId = index; info.oMonitor = nullptr; - info.gdiDeviceName = nullptr; + info.gdiDeviceNames = nullptr; ::EnumDisplayMonitors( nullptr, nullptr, &MonitorEnumProc, @@ -65,6 +65,7 @@ namespace dxvk::wsi { std::vector paths; std::vector modes; std::set> sources; + std::set gdiDeviceNames; UINT32 pathCount = 0; UINT32 modeCount = 0; LONG result; @@ -93,6 +94,7 @@ namespace dxvk::wsi { MonitorEnumInfo info; info.iMonitorId = index; info.oMonitor = nullptr; + info.gdiDeviceNames = &gdiDeviceNames; for (const auto &path : paths) { uint32_t i; @@ -121,16 +123,12 @@ namespace dxvk::wsi { return enumMonitors(index); } - info.gdiDeviceName = deviceName.viewGdiDeviceName; - - ::EnumDisplayMonitors( - nullptr, nullptr, &MonitorEnumProc, - reinterpret_cast(&info)); - - if (info.oMonitor != nullptr) - return info.oMonitor; + gdiDeviceNames.insert(deviceName.viewGdiDeviceName); } - return nullptr; + ::EnumDisplayMonitors( + nullptr, nullptr, &MonitorEnumProc, + reinterpret_cast(&info)); + return info.oMonitor; }