diff --git a/src/dxgi/dxgi_adapter.cpp b/src/dxgi/dxgi_adapter.cpp index 24e4a18f..5bb73aea 100644 --- a/src/dxgi/dxgi_adapter.cpp +++ b/src/dxgi/dxgi_adapter.cpp @@ -81,14 +81,18 @@ namespace dxvk { if (ppOutput == nullptr) return DXGI_ERROR_INVALID_CALL; - if (Output > 0) { - *ppOutput = nullptr; - return DXGI_ERROR_NOT_FOUND; - } + MonitorEnumInfo info; + info.iMonitorId = Output; + info.oMonitor = nullptr; - // TODO support multiple monitors - HMONITOR monitor = ::MonitorFromPoint({ 0, 0 }, MONITOR_DEFAULTTOPRIMARY); - *ppOutput = ref(new DxgiOutput(this, monitor)); + ::EnumDisplayMonitors( + nullptr, nullptr, &MonitorEnumProc, + reinterpret_cast(&info)); + + if (info.oMonitor == nullptr) + return DXGI_ERROR_NOT_FOUND; + + *ppOutput = ref(new DxgiOutput(this, info.oMonitor)); return S_OK; } @@ -284,4 +288,19 @@ namespace dxvk { return S_OK; } + + BOOL DxgiAdapter::MonitorEnumProc( + HMONITOR hmon, + HDC hdc, + LPRECT rect, + LPARAM lp) { + auto data = reinterpret_cast(lp); + + if (data->iMonitorId--) + return TRUE; /* continue */ + + data->oMonitor = hmon; + return FALSE; /* stop */ + } + } diff --git a/src/dxgi/dxgi_adapter.h b/src/dxgi/dxgi_adapter.h index 674a502f..78d2a134 100644 --- a/src/dxgi/dxgi_adapter.h +++ b/src/dxgi/dxgi_adapter.h @@ -85,6 +85,17 @@ namespace dxvk { std::mutex m_outputMutex; OutputMap m_outputData; + struct MonitorEnumInfo { + UINT iMonitorId; + HMONITOR oMonitor; + }; + + static BOOL MonitorEnumProc( + HMONITOR hmon, + HDC hdc, + LPRECT rect, + LPARAM lp); + }; }