- 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 "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
{
int curIdx;
@ -116,24 +122,29 @@ void Win32BaseVideo::GetDisplayDeviceName()
mes.curIdx = 1;
mes.hFoundMonitor = nullptr;
// Could also use EnumDisplayDevices, I guess. That might work.
if (EnumDisplayMonitors(0, 0, &GetDisplayDeviceNameMonitorEnumProc, LPARAM(&mes)))
if (vid_adapter == 0)
{
if (mes.hFoundMonitor)
mes.hFoundMonitor = GetPrimaryMonitorHandle();
}
// Could also use EnumDisplayDevices, I guess. That might work.
else EnumDisplayMonitors(0, 0, &GetDisplayDeviceNameMonitorEnumProc, LPARAM(&mes));
if (mes.hFoundMonitor)
{
MONITORINFOEXA mi;
mi.cbSize = sizeof mi;
if (GetMonitorInfoA(mes.hFoundMonitor, &mi))
{
MONITORINFOEXA mi;
strcpy(m_DisplayDeviceBuffer, mi.szDevice);
m_DisplayDeviceName = m_DisplayDeviceBuffer;
mi.cbSize = sizeof mi;
if (GetMonitorInfoA(mes.hFoundMonitor, &mi))
{
strcpy(m_DisplayDeviceBuffer, mi.szDevice);
m_DisplayDeviceName = m_DisplayDeviceBuffer;
m_hMonitor = mes.hFoundMonitor;
}
m_hMonitor = mes.hFoundMonitor;
}
}
}
//==========================================================================