- treat 'vid_adapter 0' as what Windows considers the primary monitor.

Courtesy of https://devblogs.microsoft.com/oldnewthing/20070809-00/?p=25643
This commit is contained in:
Christoph Oelckers 2021-09-12 10:02:30 +02:00
parent b550f57ce3
commit f783a94835

View file

@ -48,7 +48,7 @@
#include "win32basevideo.h" #include "win32basevideo.h"
#include "cmdlib.h" #include "cmdlib.h"
CVAR(Int, vid_adapter, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Int, vid_adapter, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
//========================================================================== //==========================================================================
// //
@ -69,6 +69,12 @@ Win32BaseVideo::Win32BaseVideo()
// //
//========================================================================== //==========================================================================
HMONITOR GetPrimaryMonitorHandle()
{
const POINT ptZero = { 0, 0 };
return MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY);
}
struct MonitorEnumState struct MonitorEnumState
{ {
int curIdx; int curIdx;
@ -116,9 +122,14 @@ void Win32BaseVideo::GetDisplayDeviceName()
mes.curIdx = 1; mes.curIdx = 1;
mes.hFoundMonitor = nullptr; mes.hFoundMonitor = nullptr;
// Could also use EnumDisplayDevices, I guess. That might work. if (vid_adapter == 0)
if (EnumDisplayMonitors(0, 0, &GetDisplayDeviceNameMonitorEnumProc, LPARAM(&mes)))
{ {
mes.hFoundMonitor = GetPrimaryMonitorHandle();
}
// Could also use EnumDisplayDevices, I guess. That might work.
else EnumDisplayMonitors(0, 0, &GetDisplayDeviceNameMonitorEnumProc, LPARAM(&mes));
if (mes.hFoundMonitor) if (mes.hFoundMonitor)
{ {
MONITORINFOEXA mi; MONITORINFOEXA mi;
@ -133,7 +144,7 @@ void Win32BaseVideo::GetDisplayDeviceName()
m_hMonitor = mes.hFoundMonitor; m_hMonitor = mes.hFoundMonitor;
} }
} }
}
} }
//========================================================================== //==========================================================================