Implement dynamic retrieval of more accurate monitor name if possible for Windows 7 and above

This commit is contained in:
Scr3amer 2023-03-31 16:50:21 -04:00 committed by GitHub
parent af9381a513
commit 1917698c4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
//======================================================================== //========================================================================
// GLFW 3.4 Win32 - www.glfw.org // GLFW 3.3 Win32 - www.glfw.org
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard // Copyright (c) 2002-2006 Marcus Geelnard
// Copyright (c) 2006-2019 Camilla Löwy <elmindreda@glfw.org> // Copyright (c) 2006-2019 Camilla Löwy <elmindreda@glfw.org>
@ -29,17 +29,311 @@
#include "internal.h" #include "internal.h"
#if defined(_GLFW_WIN32)
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <limits.h> #include <limits.h>
#include <malloc.h>
#include <wchar.h> #include <wchar.h>
#if WINVER < 0x0601 // For windows 7 and above
typedef struct DISPLAYCONFIG_PATH_SOURCE_INFO
{
LUID adapterId;
UINT32 id;
union
{
UINT32 modeInfoIdx;
struct
{
UINT32 cloneGroupId : 16;
UINT32 sourceModeInfoIdx : 16;
} DUMMYSTRUCTNAME;
} DUMMYUNIONNAME;
UINT32 statusFlags;
} DISPLAYCONFIG_PATH_SOURCE_INFO;
typedef enum
{
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_OTHER = -1,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HD15 = 0,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SVIDEO = 1,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPOSITE_VIDEO = 2,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPONENT_VIDEO = 3,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DVI = 4,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HDMI = 5,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_LVDS = 6,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_D_JPN = 8,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDI = 9,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EXTERNAL = 10,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED = 11,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EXTERNAL = 12,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EMBEDDED = 13,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDTVDONGLE = 14,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_MIRACAST = 15,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INDIRECT_WIRED = 16,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INDIRECT_VIRTUAL = 17,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_USB_TUNNEL,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL = 0x80000000,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_FORCE_UINT32 = 0xFFFFFFFF
} DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY;
typedef enum
{
DISPLAYCONFIG_ROTATION_IDENTITY = 1,
DISPLAYCONFIG_ROTATION_ROTATE90 = 2,
DISPLAYCONFIG_ROTATION_ROTATE180 = 3,
DISPLAYCONFIG_ROTATION_ROTATE270 = 4,
DISPLAYCONFIG_ROTATION_FORCE_UINT32 = 0xFFFFFFFF
} DISPLAYCONFIG_ROTATION;
typedef enum
{
DISPLAYCONFIG_SCALING_IDENTITY = 1,
DISPLAYCONFIG_SCALING_CENTERED = 2,
DISPLAYCONFIG_SCALING_STRETCHED = 3,
DISPLAYCONFIG_SCALING_ASPECTRATIOCENTEREDMAX = 4,
DISPLAYCONFIG_SCALING_CUSTOM = 5,
DISPLAYCONFIG_SCALING_PREFERRED = 128,
DISPLAYCONFIG_SCALING_FORCE_UINT32 = 0xFFFFFFFF
} DISPLAYCONFIG_SCALING;
typedef struct DISPLAYCONFIG_RATIONAL
{
UINT32 Numerator;
UINT32 Denominator;
} DISPLAYCONFIG_RATIONAL;
typedef enum
{
DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED = 0,
DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE = 1,
DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED = 2,
DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_UPPERFIELDFIRST,
DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_LOWERFIELDFIRST = 3,
DISPLAYCONFIG_SCANLINE_ORDERING_FORCE_UINT32 = 0xFFFFFFFF
} DISPLAYCONFIG_SCANLINE_ORDERING;
typedef struct DISPLAYCONFIG_PATH_TARGET_INFO
{
LUID adapterId;
UINT32 id;
union
{
UINT32 modeInfoIdx;
struct
{
UINT32 desktopModeInfoIdx : 16;
UINT32 targetModeInfoIdx : 16;
} DUMMYSTRUCTNAME;
} DUMMYUNIONNAME;
DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY outputTechnology;
DISPLAYCONFIG_ROTATION rotation;
DISPLAYCONFIG_SCALING scaling;
DISPLAYCONFIG_RATIONAL refreshRate;
DISPLAYCONFIG_SCANLINE_ORDERING scanLineOrdering;
BOOL targetAvailable;
UINT32 statusFlags;
} DISPLAYCONFIG_PATH_TARGET_INFO;
typedef struct DISPLAYCONFIG_PATH_INFO
{
DISPLAYCONFIG_PATH_SOURCE_INFO sourceInfo;
DISPLAYCONFIG_PATH_TARGET_INFO targetInfo;
UINT32 flags;
} DISPLAYCONFIG_PATH_INFO;
typedef enum
{
DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE = 1,
DISPLAYCONFIG_MODE_INFO_TYPE_TARGET = 2,
DISPLAYCONFIG_MODE_INFO_TYPE_DESKTOP_IMAGE = 3,
DISPLAYCONFIG_MODE_INFO_TYPE_FORCE_UINT32 = 0xFFFFFFFF
} DISPLAYCONFIG_MODE_INFO_TYPE;
typedef struct DISPLAYCONFIG_2DREGION
{
UINT32 cx;
UINT32 cy;
} DISPLAYCONFIG_2DREGION;
typedef struct DISPLAYCONFIG_VIDEO_SIGNAL_INFO
{
UINT64 pixelRate;
DISPLAYCONFIG_RATIONAL hSyncFreq;
DISPLAYCONFIG_RATIONAL vSyncFreq;
DISPLAYCONFIG_2DREGION activeSize;
DISPLAYCONFIG_2DREGION totalSize;
union
{
struct
{
UINT32 videoStandard : 16;
UINT32 vSyncFreqDivider : 6;
UINT32 reserved : 10;
} AdditionalSignalInfo;
UINT32 videoStandard;
} DUMMYUNIONNAME;
DISPLAYCONFIG_SCANLINE_ORDERING scanLineOrdering;
} DISPLAYCONFIG_VIDEO_SIGNAL_INFO;
typedef struct DISPLAYCONFIG_TARGET_MODE
{
DISPLAYCONFIG_VIDEO_SIGNAL_INFO targetVideoSignalInfo;
} DISPLAYCONFIG_TARGET_MODE;
typedef enum
{
DISPLAYCONFIG_PIXELFORMAT_8BPP = 1,
DISPLAYCONFIG_PIXELFORMAT_16BPP = 2,
DISPLAYCONFIG_PIXELFORMAT_24BPP = 3,
DISPLAYCONFIG_PIXELFORMAT_32BPP = 4,
DISPLAYCONFIG_PIXELFORMAT_NONGDI = 5,
DISPLAYCONFIG_PIXELFORMAT_FORCE_UINT32 = 0xffffffff
} DISPLAYCONFIG_PIXELFORMAT;
typedef struct DISPLAYCONFIG_SOURCE_MODE
{
UINT32 width;
UINT32 height;
DISPLAYCONFIG_PIXELFORMAT pixelFormat;
POINTL position;
} DISPLAYCONFIG_SOURCE_MODE;
typedef struct DISPLAYCONFIG_DESKTOP_IMAGE_INFO
{
POINTL PathSourceSize;
RECTL DesktopImageRegion;
RECTL DesktopImageClip;
} DISPLAYCONFIG_DESKTOP_IMAGE_INFO;
typedef struct DISPLAYCONFIG_MODE_INFO
{
DISPLAYCONFIG_MODE_INFO_TYPE infoType;
UINT32 id;
LUID adapterId;
union
{
DISPLAYCONFIG_TARGET_MODE targetMode;
DISPLAYCONFIG_SOURCE_MODE sourceMode;
DISPLAYCONFIG_DESKTOP_IMAGE_INFO desktopImageInfo;
} DUMMYUNIONNAME;
} DISPLAYCONFIG_MODE_INFO;
const UINT32 QDC_ONLY_ACTIVE_PATHS = 0x00000002;
typedef enum
{
DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME = 1,
DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME = 2,
DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_PREFERRED_MODE = 3,
DISPLAYCONFIG_DEVICE_INFO_GET_ADAPTER_NAME = 4,
DISPLAYCONFIG_DEVICE_INFO_SET_TARGET_PERSISTENCE = 5,
DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_BASE_TYPE = 6,
DISPLAYCONFIG_DEVICE_INFO_GET_SUPPORT_VIRTUAL_RESOLUTION = 7,
DISPLAYCONFIG_DEVICE_INFO_SET_SUPPORT_VIRTUAL_RESOLUTION = 8,
DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO = 9,
DISPLAYCONFIG_DEVICE_INFO_SET_ADVANCED_COLOR_STATE = 10,
DISPLAYCONFIG_DEVICE_INFO_GET_SDR_WHITE_LEVEL = 11,
DISPLAYCONFIG_DEVICE_INFO_GET_MONITOR_SPECIALIZATION,
DISPLAYCONFIG_DEVICE_INFO_SET_MONITOR_SPECIALIZATION,
DISPLAYCONFIG_DEVICE_INFO_FORCE_UINT32 = 0xFFFFFFFF
} DISPLAYCONFIG_DEVICE_INFO_TYPE;
typedef struct DISPLAYCONFIG_DEVICE_INFO_HEADER {
DISPLAYCONFIG_DEVICE_INFO_TYPE type;
UINT32 size;
LUID adapterId;
UINT32 id;
} DISPLAYCONFIG_DEVICE_INFO_HEADER;
typedef struct DISPLAYCONFIG_SOURCE_DEVICE_NAME
{
DISPLAYCONFIG_DEVICE_INFO_HEADER header;
WCHAR viewGdiDeviceName[CCHDEVICENAME];
} DISPLAYCONFIG_SOURCE_DEVICE_NAME;
typedef struct DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS
{
union
{
struct
{
UINT32 friendlyNameFromEdid : 1;
UINT32 friendlyNameForced : 1;
UINT32 edidIdsValid : 1;
UINT32 reserved : 29;
} DUMMYSTRUCTNAME;
UINT32 value;
} DUMMYUNIONNAME;
} DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS;
typedef struct DISPLAYCONFIG_TARGET_DEVICE_NAME
{
DISPLAYCONFIG_DEVICE_INFO_HEADER header;
DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS flags;
DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY outputTechnology;
UINT16 edidManufactureId;
UINT16 edidProductCodeId;
UINT32 connectorInstance;
WCHAR monitorFriendlyDeviceName[64];
WCHAR monitorDevicePath[128];
} DISPLAYCONFIG_TARGET_DEVICE_NAME;
typedef enum DISPLAYCONFIG_TOPOLOGY_ID
{
DISPLAYCONFIG_TOPOLOGY_INTERNAL = 0x00000001,
DISPLAYCONFIG_TOPOLOGY_CLONE = 0x00000002,
DISPLAYCONFIG_TOPOLOGY_EXTEND = 0x00000004,
DISPLAYCONFIG_TOPOLOGY_EXTERNAL = 0x00000008,
DISPLAYCONFIG_TOPOLOGY_FORCE_UINT32 = 0xFFFFFFFF
} DISPLAYCONFIG_TOPOLOGY_ID;
#endif //#if WINVER < 0x0601
typedef LONG (*pGetDisplayConfigBufferSizes)(UINT32 flags, UINT32 *numPathArrayElements, UINT32 *numModeInfoArrayElements);
typedef LONG (*pQueryDisplayConfig)(UINT32 flags, UINT32 *numPathArrayElements, DISPLAYCONFIG_PATH_INFO *pathArray, UINT32 *numModeInfoArrayElements, DISPLAYCONFIG_MODE_INFO *modeInfoArray, DISPLAYCONFIG_TOPOLOGY_ID *currentTopologyId);
typedef LONG (*pDisplayConfigGetDeviceInfo)(DISPLAYCONFIG_DEVICE_INFO_HEADER* requestPacket);
typedef struct AccurateNameRequiredData
{
HMODULE m_dll;
pGetDisplayConfigBufferSizes m_GetDisplayConfigBufferSizes;
pQueryDisplayConfig m_QueryDisplayConfig;
pDisplayConfigGetDeviceInfo m_DisplayConfigGetDeviceInfo;
} AccurateNameRequiredData;
BOOL loadWin7MonitorPointers(AccurateNameRequiredData *io_ptrs)
{
if(!IsWindows7OrGreater())
return 0;
io_ptrs->m_dll = LoadLibrary(L"User32.dll");
if (io_ptrs == NULL)
return 0;
io_ptrs->m_GetDisplayConfigBufferSizes = (pGetDisplayConfigBufferSizes)GetProcAddress(io_ptrs->m_dll, "GetDisplayConfigBufferSizes");
if(io_ptrs->m_GetDisplayConfigBufferSizes == NULL)
return 0;
io_ptrs->m_QueryDisplayConfig = (pQueryDisplayConfig)GetProcAddress(io_ptrs->m_dll, "QueryDisplayConfig");
if(io_ptrs->m_QueryDisplayConfig == NULL)
return 0;
io_ptrs->m_DisplayConfigGetDeviceInfo = (pDisplayConfigGetDeviceInfo)GetProcAddress(io_ptrs->m_dll, "DisplayConfigGetDeviceInfo");
if(io_ptrs->m_DisplayConfigGetDeviceInfo == NULL)
return 0;
return 1;
}
// If the returned pointer is valid (not NULL) the caller of this function is in charge of freeing the memory when he is done. // If the returned pointer is valid (not NULL) the caller of this function is in charge of freeing the memory when he is done.
static char * tryGetMoreAccurateDisplayName(const WCHAR *deviceName) static char * GetAccurateMonitorName(const WCHAR *deviceName)
{ {
AccurateNameRequiredData dllPointers;
if(loadWin7MonitorPointers(&dllPointers) == 0)
return NULL;
DISPLAYCONFIG_PATH_INFO *paths = NULL; DISPLAYCONFIG_PATH_INFO *paths = NULL;
DISPLAYCONFIG_MODE_INFO *modes = NULL; DISPLAYCONFIG_MODE_INFO *modes = NULL;
char *retval = NULL; char *retval = NULL;
@ -49,9 +343,9 @@ static char * tryGetMoreAccurateDisplayName(const WCHAR *deviceName)
LONG rc; LONG rc;
do { do {
rc = GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &pathCount, &modeCount); rc = dllPointers.m_GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &pathCount, &modeCount);
if (rc != ERROR_SUCCESS) { if (rc != ERROR_SUCCESS) {
goto WHEN_FAILURE; goto GET_ACCURATE_MONITOR_NAME_FAILURE;
} }
free(paths); free(paths);
@ -60,10 +354,10 @@ static char * tryGetMoreAccurateDisplayName(const WCHAR *deviceName)
paths = (DISPLAYCONFIG_PATH_INFO *) malloc(sizeof (DISPLAYCONFIG_PATH_INFO) * pathCount); paths = (DISPLAYCONFIG_PATH_INFO *) malloc(sizeof (DISPLAYCONFIG_PATH_INFO) * pathCount);
modes = (DISPLAYCONFIG_MODE_INFO *) malloc(sizeof (DISPLAYCONFIG_MODE_INFO) * modeCount); modes = (DISPLAYCONFIG_MODE_INFO *) malloc(sizeof (DISPLAYCONFIG_MODE_INFO) * modeCount);
if ((paths == NULL) || (modes == NULL)) { if ((paths == NULL) || (modes == NULL)) {
goto WHEN_FAILURE; goto GET_ACCURATE_MONITOR_NAME_FAILURE;
} }
rc = QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &pathCount, paths, &modeCount, modes, 0); rc = dllPointers.m_QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &pathCount, paths, &modeCount, modes, 0);
} while (rc == ERROR_INSUFFICIENT_BUFFER); } while (rc == ERROR_INSUFFICIENT_BUFFER);
if (rc == ERROR_SUCCESS) { if (rc == ERROR_SUCCESS) {
@ -76,7 +370,7 @@ static char * tryGetMoreAccurateDisplayName(const WCHAR *deviceName)
sourceName.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME; sourceName.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME;
sourceName.header.size = sizeof (sourceName); sourceName.header.size = sizeof (sourceName);
sourceName.header.id = paths[i].sourceInfo.id; sourceName.header.id = paths[i].sourceInfo.id;
rc = DisplayConfigGetDeviceInfo(&sourceName.header); rc = dllPointers.m_DisplayConfigGetDeviceInfo(&sourceName.header);
if (rc != ERROR_SUCCESS) { if (rc != ERROR_SUCCESS) {
break; break;
} else if (wcscmp(deviceName, sourceName.viewGdiDeviceName) != 0) { } else if (wcscmp(deviceName, sourceName.viewGdiDeviceName) != 0) {
@ -88,7 +382,7 @@ static char * tryGetMoreAccurateDisplayName(const WCHAR *deviceName)
targetName.header.id = paths[i].targetInfo.id; targetName.header.id = paths[i].targetInfo.id;
targetName.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME; targetName.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME;
targetName.header.size = sizeof (targetName); targetName.header.size = sizeof (targetName);
rc = DisplayConfigGetDeviceInfo(&targetName.header); rc = dllPointers.m_DisplayConfigGetDeviceInfo(&targetName.header);
if (rc == ERROR_SUCCESS) { if (rc == ERROR_SUCCESS) {
retval = _glfwCreateUTF8FromWideStringWin32(targetName.monitorFriendlyDeviceName); retval = _glfwCreateUTF8FromWideStringWin32(targetName.monitorFriendlyDeviceName);
/* if we got an empty string, treat it as failure so we'll fallback /* if we got an empty string, treat it as failure so we'll fallback
@ -102,18 +396,19 @@ static char * tryGetMoreAccurateDisplayName(const WCHAR *deviceName)
} }
} }
FreeLibrary(dllPointers.m_dll);
free(paths); free(paths);
free(modes); free(modes);
return retval; return retval;
WHEN_FAILURE: GET_ACCURATE_MONITOR_NAME_FAILURE:
FreeLibrary(dllPointers.m_dll);
free(retval); free(retval);
free(paths); free(paths);
free(modes); free(modes);
return NULL; return NULL;
} }
// Callback for EnumDisplayMonitors in createMonitor // Callback for EnumDisplayMonitors in createMonitor
// //
static BOOL CALLBACK monitorCallback(HMONITOR handle, static BOOL CALLBACK monitorCallback(HMONITOR handle,
@ -131,7 +426,7 @@ static BOOL CALLBACK monitorCallback(HMONITOR handle,
if (wcscmp(mi.szDevice, monitor->win32.adapterName) == 0) if (wcscmp(mi.szDevice, monitor->win32.adapterName) == 0)
{ {
monitor->win32.handle = handle; monitor->win32.handle = handle;
char *possibleBetterDisplayName = tryGetMoreAccurateDisplayName(mi.szDevice); char *possibleBetterDisplayName = GetAccurateMonitorName(mi.szDevice);
if(possibleBetterDisplayName != NULL) if(possibleBetterDisplayName != NULL)
{ {
strncpy(monitor->name, possibleBetterDisplayName, sizeof(monitor->name) - 1); strncpy(monitor->name, possibleBetterDisplayName, sizeof(monitor->name) - 1);
@ -144,7 +439,6 @@ static BOOL CALLBACK monitorCallback(HMONITOR handle,
return TRUE; return TRUE;
} }
// Create monitor from an adapter and (optionally) a display // Create monitor from an adapter and (optionally) a display
// //
static _GLFWmonitor* createMonitor(DISPLAY_DEVICEW* adapter, static _GLFWmonitor* createMonitor(DISPLAY_DEVICEW* adapter,
@ -184,7 +478,7 @@ static _GLFWmonitor* createMonitor(DISPLAY_DEVICEW* adapter,
DeleteDC(dc); DeleteDC(dc);
monitor = _glfwAllocMonitor(name, widthMM, heightMM); monitor = _glfwAllocMonitor(name, widthMM, heightMM);
_glfw_free(name); free(name);
if (adapter->StateFlags & DISPLAY_DEVICE_MODESPRUNED) if (adapter->StateFlags & DISPLAY_DEVICE_MODESPRUNED)
monitor->win32.modesPruned = GLFW_TRUE; monitor->win32.modesPruned = GLFW_TRUE;
@ -233,7 +527,7 @@ void _glfwPollMonitorsWin32(void)
disconnectedCount = _glfw.monitorCount; disconnectedCount = _glfw.monitorCount;
if (disconnectedCount) if (disconnectedCount)
{ {
disconnected = _glfw_calloc(_glfw.monitorCount, sizeof(_GLFWmonitor*)); disconnected = calloc(_glfw.monitorCount, sizeof(_GLFWmonitor*));
memcpy(disconnected, memcpy(disconnected,
_glfw.monitors, _glfw.monitors,
_glfw.monitorCount * sizeof(_GLFWmonitor*)); _glfw.monitorCount * sizeof(_GLFWmonitor*));
@ -285,7 +579,7 @@ void _glfwPollMonitorsWin32(void)
monitor = createMonitor(&adapter, &display); monitor = createMonitor(&adapter, &display);
if (!monitor) if (!monitor)
{ {
_glfw_free(disconnected); free(disconnected);
return; return;
} }
@ -315,7 +609,7 @@ void _glfwPollMonitorsWin32(void)
monitor = createMonitor(&adapter, NULL); monitor = createMonitor(&adapter, NULL);
if (!monitor) if (!monitor)
{ {
_glfw_free(disconnected); free(disconnected);
return; return;
} }
@ -329,7 +623,7 @@ void _glfwPollMonitorsWin32(void)
_glfwInputMonitor(disconnected[i], GLFW_DISCONNECTED, 0); _glfwInputMonitor(disconnected[i], GLFW_DISCONNECTED, 0);
} }
_glfw_free(disconnected); free(disconnected);
} }
// Change the current video mode // Change the current video mode
@ -342,7 +636,7 @@ void _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desired)
LONG result; LONG result;
best = _glfwChooseVideoMode(monitor, desired); best = _glfwChooseVideoMode(monitor, desired);
_glfwGetVideoModeWin32(monitor, &current); _glfwPlatformGetVideoMode(monitor, &current);
if (_glfwCompareVideoModes(&current, best) == 0) if (_glfwCompareVideoModes(&current, best) == 0)
return; return;
@ -402,7 +696,7 @@ void _glfwRestoreVideoModeWin32(_GLFWmonitor* monitor)
} }
} }
void _glfwGetHMONITORContentScaleWin32(HMONITOR handle, float* xscale, float* yscale) void _glfwGetMonitorContentScaleWin32(HMONITOR handle, float* xscale, float* yscale)
{ {
UINT xdpi, ydpi; UINT xdpi, ydpi;
@ -438,11 +732,11 @@ void _glfwGetHMONITORContentScaleWin32(HMONITOR handle, float* xscale, float* ys
////// GLFW platform API ////// ////// GLFW platform API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void _glfwFreeMonitorWin32(_GLFWmonitor* monitor) void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor)
{ {
} }
void _glfwGetMonitorPosWin32(_GLFWmonitor* monitor, int* xpos, int* ypos) void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
{ {
DEVMODEW dm; DEVMODEW dm;
ZeroMemory(&dm, sizeof(dm)); ZeroMemory(&dm, sizeof(dm));
@ -459,13 +753,13 @@ void _glfwGetMonitorPosWin32(_GLFWmonitor* monitor, int* xpos, int* ypos)
*ypos = dm.dmPosition.y; *ypos = dm.dmPosition.y;
} }
void _glfwGetMonitorContentScaleWin32(_GLFWmonitor* monitor, void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor,
float* xscale, float* yscale) float* xscale, float* yscale)
{ {
_glfwGetHMONITORContentScaleWin32(monitor->win32.handle, xscale, yscale); _glfwGetMonitorContentScaleWin32(monitor->win32.handle, xscale, yscale);
} }
void _glfwGetMonitorWorkareaWin32(_GLFWmonitor* monitor, void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor,
int* xpos, int* ypos, int* xpos, int* ypos,
int* width, int* height) int* width, int* height)
{ {
@ -482,7 +776,7 @@ void _glfwGetMonitorWorkareaWin32(_GLFWmonitor* monitor,
*height = mi.rcWork.bottom - mi.rcWork.top; *height = mi.rcWork.bottom - mi.rcWork.top;
} }
GLFWvidmode* _glfwGetVideoModesWin32(_GLFWmonitor* monitor, int* count) GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
{ {
int modeIndex = 0, size = 0; int modeIndex = 0, size = 0;
GLFWvidmode* result = NULL; GLFWvidmode* result = NULL;
@ -541,7 +835,7 @@ GLFWvidmode* _glfwGetVideoModesWin32(_GLFWmonitor* monitor, int* count)
if (*count == size) if (*count == size)
{ {
size += 128; size += 128;
result = (GLFWvidmode*) _glfw_realloc(result, size * sizeof(GLFWvidmode)); result = (GLFWvidmode*) realloc(result, size * sizeof(GLFWvidmode));
} }
(*count)++; (*count)++;
@ -551,15 +845,15 @@ GLFWvidmode* _glfwGetVideoModesWin32(_GLFWmonitor* monitor, int* count)
if (!*count) if (!*count)
{ {
// HACK: Report the current mode if no valid modes were found // HACK: Report the current mode if no valid modes were found
result = _glfw_calloc(1, sizeof(GLFWvidmode)); result = calloc(1, sizeof(GLFWvidmode));
_glfwGetVideoModeWin32(monitor, result); _glfwPlatformGetVideoMode(monitor, result);
*count = 1; *count = 1;
} }
return result; return result;
} }
void _glfwGetVideoModeWin32(_GLFWmonitor* monitor, GLFWvidmode* mode) void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
{ {
DEVMODEW dm; DEVMODEW dm;
ZeroMemory(&dm, sizeof(dm)); ZeroMemory(&dm, sizeof(dm));
@ -576,7 +870,7 @@ void _glfwGetVideoModeWin32(_GLFWmonitor* monitor, GLFWvidmode* mode)
&mode->blueBits); &mode->blueBits);
} }
GLFWbool _glfwGetGammaRampWin32(_GLFWmonitor* monitor, GLFWgammaramp* ramp) GLFWbool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
{ {
HDC dc; HDC dc;
WORD values[3][256]; WORD values[3][256];
@ -594,7 +888,7 @@ GLFWbool _glfwGetGammaRampWin32(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
return GLFW_TRUE; return GLFW_TRUE;
} }
void _glfwSetGammaRampWin32(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
{ {
HDC dc; HDC dc;
WORD values[3][256]; WORD values[3][256];
@ -633,6 +927,3 @@ GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* handle)
_GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return monitor->win32.publicDisplayName; return monitor->win32.publicDisplayName;
} }
#endif // _GLFW_WIN32