2011-10-01 13:42:59 -04:00
|
|
|
//========================================================================
|
2019-04-16 08:43:29 -04:00
|
|
|
// GLFW 3.4 Win32 - www.glfw.org
|
2011-10-01 13:42:59 -04:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Copyright (c) 2002-2006 Marcus Geelnard
|
2019-04-15 14:50:00 -04:00
|
|
|
// Copyright (c) 2006-2019 Camilla Löwy <elmindreda@glfw.org>
|
2011-10-01 13:42:59 -04:00
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
|
|
// arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it
|
|
|
|
// freely, subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
// claim that you wrote the original software. If you use this software
|
|
|
|
// in a product, an acknowledgment in the product documentation would
|
|
|
|
// be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such, and must not
|
|
|
|
// be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source
|
|
|
|
// distribution.
|
|
|
|
//
|
|
|
|
//========================================================================
|
2019-05-20 09:24:14 -04:00
|
|
|
// Please use C89 style variable declarations in this file because VS 2010
|
|
|
|
//========================================================================
|
2011-10-01 13:42:59 -04:00
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-09-12 15:04:24 -04:00
|
|
|
#include <limits.h>
|
2019-12-15 11:36:55 -05:00
|
|
|
#include <wchar.h>
|
2011-10-01 13:42:59 -04:00
|
|
|
|
|
|
|
|
2017-08-27 16:42:23 -04:00
|
|
|
// Callback for EnumDisplayMonitors in createMonitor
|
|
|
|
//
|
|
|
|
static BOOL CALLBACK monitorCallback(HMONITOR handle,
|
|
|
|
HDC dc,
|
|
|
|
RECT* rect,
|
|
|
|
LPARAM data)
|
|
|
|
{
|
|
|
|
MONITORINFOEXW mi;
|
|
|
|
ZeroMemory(&mi, sizeof(mi));
|
|
|
|
mi.cbSize = sizeof(mi);
|
|
|
|
|
|
|
|
if (GetMonitorInfoW(handle, (MONITORINFO*) &mi))
|
|
|
|
{
|
|
|
|
_GLFWmonitor* monitor = (_GLFWmonitor*) data;
|
|
|
|
if (wcscmp(mi.szDevice, monitor->win32.adapterName) == 0)
|
|
|
|
monitor->win32.handle = handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-10-18 18:46:26 -04:00
|
|
|
// Create monitor from an adapter and (optionally) a display
|
|
|
|
//
|
|
|
|
static _GLFWmonitor* createMonitor(DISPLAY_DEVICEW* adapter,
|
|
|
|
DISPLAY_DEVICEW* display)
|
|
|
|
{
|
|
|
|
_GLFWmonitor* monitor;
|
2017-08-29 13:19:00 -04:00
|
|
|
int widthMM, heightMM;
|
2015-10-18 18:46:26 -04:00
|
|
|
char* name;
|
|
|
|
HDC dc;
|
2017-08-27 16:42:23 -04:00
|
|
|
DEVMODEW dm;
|
|
|
|
RECT rect;
|
2015-10-18 18:46:26 -04:00
|
|
|
|
|
|
|
if (display)
|
|
|
|
name = _glfwCreateUTF8FromWideStringWin32(display->DeviceString);
|
|
|
|
else
|
|
|
|
name = _glfwCreateUTF8FromWideStringWin32(adapter->DeviceString);
|
|
|
|
if (!name)
|
|
|
|
return NULL;
|
|
|
|
|
2017-08-29 13:19:00 -04:00
|
|
|
ZeroMemory(&dm, sizeof(dm));
|
|
|
|
dm.dmSize = sizeof(dm);
|
|
|
|
EnumDisplaySettingsW(adapter->DeviceName, ENUM_CURRENT_SETTINGS, &dm);
|
|
|
|
|
2015-10-18 18:46:26 -04:00
|
|
|
dc = CreateDCW(L"DISPLAY", adapter->DeviceName, NULL, NULL);
|
|
|
|
|
2017-08-29 13:19:00 -04:00
|
|
|
if (IsWindows8Point1OrGreater())
|
|
|
|
{
|
|
|
|
widthMM = GetDeviceCaps(dc, HORZSIZE);
|
|
|
|
heightMM = GetDeviceCaps(dc, VERTSIZE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
widthMM = (int) (dm.dmPelsWidth * 25.4f / GetDeviceCaps(dc, LOGPIXELSX));
|
|
|
|
heightMM = (int) (dm.dmPelsHeight * 25.4f / GetDeviceCaps(dc, LOGPIXELSY));
|
|
|
|
}
|
2015-10-18 18:46:26 -04:00
|
|
|
|
|
|
|
DeleteDC(dc);
|
2017-08-29 13:19:00 -04:00
|
|
|
|
|
|
|
monitor = _glfwAllocMonitor(name, widthMM, heightMM);
|
2021-08-03 14:53:48 -04:00
|
|
|
_glfw_free(name);
|
2015-10-18 18:46:26 -04:00
|
|
|
|
|
|
|
if (adapter->StateFlags & DISPLAY_DEVICE_MODESPRUNED)
|
|
|
|
monitor->win32.modesPruned = GLFW_TRUE;
|
|
|
|
|
|
|
|
wcscpy(monitor->win32.adapterName, adapter->DeviceName);
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0,
|
|
|
|
adapter->DeviceName, -1,
|
|
|
|
monitor->win32.publicAdapterName,
|
|
|
|
sizeof(monitor->win32.publicAdapterName),
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
if (display)
|
|
|
|
{
|
|
|
|
wcscpy(monitor->win32.displayName, display->DeviceName);
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0,
|
|
|
|
display->DeviceName, -1,
|
|
|
|
monitor->win32.publicDisplayName,
|
|
|
|
sizeof(monitor->win32.publicDisplayName),
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2017-08-27 16:42:23 -04:00
|
|
|
rect.left = dm.dmPosition.x;
|
|
|
|
rect.top = dm.dmPosition.y;
|
|
|
|
rect.right = dm.dmPosition.x + dm.dmPelsWidth;
|
|
|
|
rect.bottom = dm.dmPosition.y + dm.dmPelsHeight;
|
|
|
|
|
|
|
|
EnumDisplayMonitors(NULL, &rect, monitorCallback, (LPARAM) monitor);
|
2015-10-18 18:46:26 -04:00
|
|
|
return monitor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-12 15:04:24 -04:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-12-04 19:19:48 -05:00
|
|
|
// Poll for changes in the set of connected monitors
|
2013-02-04 07:22:10 -05:00
|
|
|
//
|
2016-12-04 19:19:48 -05:00
|
|
|
void _glfwPollMonitorsWin32(void)
|
2011-10-01 13:42:59 -04:00
|
|
|
{
|
2016-12-04 19:19:48 -05:00
|
|
|
int i, disconnectedCount;
|
2017-02-15 23:23:10 -05:00
|
|
|
_GLFWmonitor** disconnected = NULL;
|
2016-12-04 19:19:48 -05:00
|
|
|
DWORD adapterIndex, displayIndex;
|
2015-10-18 18:46:26 -04:00
|
|
|
DISPLAY_DEVICEW adapter, display;
|
2017-03-19 17:21:46 -04:00
|
|
|
_GLFWmonitor* monitor;
|
2011-10-01 13:42:59 -04:00
|
|
|
|
2016-12-04 19:19:48 -05:00
|
|
|
disconnectedCount = _glfw.monitorCount;
|
2017-02-15 23:23:10 -05:00
|
|
|
if (disconnectedCount)
|
|
|
|
{
|
2021-08-03 14:53:48 -04:00
|
|
|
disconnected = _glfw_calloc(_glfw.monitorCount, sizeof(_GLFWmonitor*));
|
2017-02-15 23:23:10 -05:00
|
|
|
memcpy(disconnected,
|
|
|
|
_glfw.monitors,
|
|
|
|
_glfw.monitorCount * sizeof(_GLFWmonitor*));
|
|
|
|
}
|
2013-06-09 07:07:23 -04:00
|
|
|
|
2015-10-18 18:46:26 -04:00
|
|
|
for (adapterIndex = 0; ; adapterIndex++)
|
|
|
|
{
|
2016-12-04 19:19:48 -05:00
|
|
|
int type = _GLFW_INSERT_LAST;
|
|
|
|
|
2017-08-27 17:09:08 -04:00
|
|
|
ZeroMemory(&adapter, sizeof(adapter));
|
|
|
|
adapter.cb = sizeof(adapter);
|
2012-09-13 11:46:40 -04:00
|
|
|
|
2015-10-18 18:46:26 -04:00
|
|
|
if (!EnumDisplayDevicesW(NULL, adapterIndex, &adapter, 0))
|
|
|
|
break;
|
2012-09-12 13:35:52 -04:00
|
|
|
|
2015-10-18 18:46:26 -04:00
|
|
|
if (!(adapter.StateFlags & DISPLAY_DEVICE_ACTIVE))
|
|
|
|
continue;
|
2015-09-20 10:25:00 -04:00
|
|
|
|
2015-10-18 18:46:26 -04:00
|
|
|
if (adapter.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
|
2016-12-04 19:19:48 -05:00
|
|
|
type = _GLFW_INSERT_FIRST;
|
2012-09-12 13:35:52 -04:00
|
|
|
|
2017-03-14 13:40:41 -04:00
|
|
|
for (displayIndex = 0; ; displayIndex++)
|
2015-10-18 18:46:26 -04:00
|
|
|
{
|
2017-08-27 17:09:08 -04:00
|
|
|
ZeroMemory(&display, sizeof(display));
|
|
|
|
display.cb = sizeof(display);
|
2014-10-28 10:35:03 -04:00
|
|
|
|
2017-03-14 13:40:41 -04:00
|
|
|
if (!EnumDisplayDevicesW(adapter.DeviceName, displayIndex, &display, 0))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!(display.StateFlags & DISPLAY_DEVICE_ACTIVE))
|
|
|
|
continue;
|
2014-09-12 11:03:44 -04:00
|
|
|
|
2017-03-14 13:40:41 -04:00
|
|
|
for (i = 0; i < disconnectedCount; i++)
|
|
|
|
{
|
|
|
|
if (disconnected[i] &&
|
|
|
|
wcscmp(disconnected[i]->win32.displayName,
|
|
|
|
display.DeviceName) == 0)
|
2016-12-04 19:19:48 -05:00
|
|
|
{
|
2017-03-14 13:40:41 -04:00
|
|
|
disconnected[i] = NULL;
|
2020-09-04 11:59:08 -04:00
|
|
|
// handle may have changed, update
|
|
|
|
EnumDisplayMonitors(NULL, NULL, monitorCallback, (LPARAM) _glfw.monitors[i]);
|
2017-03-14 13:40:41 -04:00
|
|
|
break;
|
2016-12-04 19:19:48 -05:00
|
|
|
}
|
2017-03-14 13:40:41 -04:00
|
|
|
}
|
2016-12-04 19:19:48 -05:00
|
|
|
|
2017-03-14 13:40:41 -04:00
|
|
|
if (i < disconnectedCount)
|
|
|
|
continue;
|
2016-12-04 19:19:48 -05:00
|
|
|
|
2017-03-19 17:21:46 -04:00
|
|
|
monitor = createMonitor(&adapter, &display);
|
|
|
|
if (!monitor)
|
|
|
|
{
|
2021-08-03 14:53:48 -04:00
|
|
|
_glfw_free(disconnected);
|
2017-03-19 17:21:46 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_glfwInputMonitor(monitor, GLFW_CONNECTED, type);
|
2016-12-04 19:19:48 -05:00
|
|
|
|
2017-03-14 13:40:41 -04:00
|
|
|
type = _GLFW_INSERT_LAST;
|
2015-10-18 18:46:26 -04:00
|
|
|
}
|
2017-03-14 13:40:41 -04:00
|
|
|
|
|
|
|
// HACK: If an active adapter does not have any display devices
|
|
|
|
// (as sometimes happens), add it directly as a monitor
|
|
|
|
if (displayIndex == 0)
|
2015-10-18 18:46:26 -04:00
|
|
|
{
|
2016-12-04 19:19:48 -05:00
|
|
|
for (i = 0; i < disconnectedCount; i++)
|
|
|
|
{
|
|
|
|
if (disconnected[i] &&
|
|
|
|
wcscmp(disconnected[i]->win32.adapterName,
|
|
|
|
adapter.DeviceName) == 0)
|
|
|
|
{
|
|
|
|
disconnected[i] = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < disconnectedCount)
|
|
|
|
continue;
|
|
|
|
|
2017-03-19 17:21:46 -04:00
|
|
|
monitor = createMonitor(&adapter, NULL);
|
|
|
|
if (!monitor)
|
|
|
|
{
|
2021-08-03 14:53:48 -04:00
|
|
|
_glfw_free(disconnected);
|
2017-03-19 17:21:46 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_glfwInputMonitor(monitor, GLFW_CONNECTED, type);
|
2014-09-12 11:00:05 -04:00
|
|
|
}
|
2013-02-17 13:09:22 -05:00
|
|
|
}
|
|
|
|
|
2016-12-04 19:19:48 -05:00
|
|
|
for (i = 0; i < disconnectedCount; i++)
|
|
|
|
{
|
|
|
|
if (disconnected[i])
|
|
|
|
_glfwInputMonitor(disconnected[i], GLFW_DISCONNECTED, 0);
|
|
|
|
}
|
2015-10-18 18:46:26 -04:00
|
|
|
|
2021-08-03 14:53:48 -04:00
|
|
|
_glfw_free(disconnected);
|
2011-10-01 13:42:59 -04:00
|
|
|
}
|
2013-02-20 10:00:53 -05:00
|
|
|
|
2016-12-04 19:19:48 -05:00
|
|
|
// Change the current video mode
|
|
|
|
//
|
2018-02-05 11:11:04 -05:00
|
|
|
void _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desired)
|
2013-04-22 08:43:13 -04:00
|
|
|
{
|
2016-12-04 19:19:48 -05:00
|
|
|
GLFWvidmode current;
|
|
|
|
const GLFWvidmode* best;
|
|
|
|
DEVMODEW dm;
|
2017-01-19 14:29:27 -05:00
|
|
|
LONG result;
|
2016-12-04 19:19:48 -05:00
|
|
|
|
|
|
|
best = _glfwChooseVideoMode(monitor, desired);
|
|
|
|
_glfwPlatformGetVideoMode(monitor, ¤t);
|
|
|
|
if (_glfwCompareVideoModes(¤t, best) == 0)
|
2018-02-05 11:11:04 -05:00
|
|
|
return;
|
2016-12-04 19:19:48 -05:00
|
|
|
|
|
|
|
ZeroMemory(&dm, sizeof(dm));
|
2017-08-27 17:09:08 -04:00
|
|
|
dm.dmSize = sizeof(dm);
|
2016-12-04 19:19:48 -05:00
|
|
|
dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL |
|
|
|
|
DM_DISPLAYFREQUENCY;
|
|
|
|
dm.dmPelsWidth = best->width;
|
|
|
|
dm.dmPelsHeight = best->height;
|
|
|
|
dm.dmBitsPerPel = best->redBits + best->greenBits + best->blueBits;
|
|
|
|
dm.dmDisplayFrequency = best->refreshRate;
|
|
|
|
|
|
|
|
if (dm.dmBitsPerPel < 15 || dm.dmBitsPerPel >= 24)
|
|
|
|
dm.dmBitsPerPel = 32;
|
|
|
|
|
2017-01-19 14:29:27 -05:00
|
|
|
result = ChangeDisplaySettingsExW(monitor->win32.adapterName,
|
|
|
|
&dm,
|
|
|
|
NULL,
|
|
|
|
CDS_FULLSCREEN,
|
|
|
|
NULL);
|
2018-02-05 11:11:04 -05:00
|
|
|
if (result == DISP_CHANGE_SUCCESSFUL)
|
|
|
|
monitor->win32.modeChanged = GLFW_TRUE;
|
|
|
|
else
|
2016-12-04 19:19:48 -05:00
|
|
|
{
|
2017-01-19 14:29:27 -05:00
|
|
|
const char* description = "Unknown error";
|
|
|
|
|
|
|
|
if (result == DISP_CHANGE_BADDUALVIEW)
|
|
|
|
description = "The system uses DualView";
|
|
|
|
else if (result == DISP_CHANGE_BADFLAGS)
|
|
|
|
description = "Invalid flags";
|
|
|
|
else if (result == DISP_CHANGE_BADMODE)
|
|
|
|
description = "Graphics mode not supported";
|
|
|
|
else if (result == DISP_CHANGE_BADPARAM)
|
|
|
|
description = "Invalid parameter";
|
|
|
|
else if (result == DISP_CHANGE_FAILED)
|
|
|
|
description = "Graphics mode failed";
|
|
|
|
else if (result == DISP_CHANGE_NOTUPDATED)
|
|
|
|
description = "Failed to write to registry";
|
|
|
|
else if (result == DISP_CHANGE_RESTART)
|
|
|
|
description = "Computer restart required";
|
|
|
|
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to set video mode: %s",
|
|
|
|
description);
|
2016-12-04 19:19:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore the previously saved (original) video mode
|
|
|
|
//
|
|
|
|
void _glfwRestoreVideoModeWin32(_GLFWmonitor* monitor)
|
|
|
|
{
|
|
|
|
if (monitor->win32.modeChanged)
|
|
|
|
{
|
|
|
|
ChangeDisplaySettingsExW(monitor->win32.adapterName,
|
|
|
|
NULL, NULL, CDS_FULLSCREEN, NULL);
|
|
|
|
monitor->win32.modeChanged = GLFW_FALSE;
|
|
|
|
}
|
2013-04-22 08:43:13 -04:00
|
|
|
}
|
|
|
|
|
2017-08-29 13:19:00 -04:00
|
|
|
void _glfwGetMonitorContentScaleWin32(HMONITOR handle, float* xscale, float* yscale)
|
|
|
|
{
|
|
|
|
UINT xdpi, ydpi;
|
|
|
|
|
|
|
|
if (IsWindows8Point1OrGreater())
|
|
|
|
GetDpiForMonitor(handle, MDT_EFFECTIVE_DPI, &xdpi, &ydpi);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const HDC dc = GetDC(NULL);
|
|
|
|
xdpi = GetDeviceCaps(dc, LOGPIXELSX);
|
|
|
|
ydpi = GetDeviceCaps(dc, LOGPIXELSY);
|
|
|
|
ReleaseDC(NULL, dc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xscale)
|
2018-06-07 13:01:07 -04:00
|
|
|
*xscale = xdpi / (float) USER_DEFAULT_SCREEN_DPI;
|
2017-08-29 13:19:00 -04:00
|
|
|
if (yscale)
|
2018-06-07 13:01:07 -04:00
|
|
|
*yscale = ydpi / (float) USER_DEFAULT_SCREEN_DPI;
|
2017-08-29 13:19:00 -04:00
|
|
|
}
|
|
|
|
|
2016-12-04 19:19:48 -05:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-02-24 15:53:39 -05:00
|
|
|
void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-20 10:00:53 -05:00
|
|
|
void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
|
|
|
|
{
|
2017-08-27 17:09:08 -04:00
|
|
|
DEVMODEW dm;
|
|
|
|
ZeroMemory(&dm, sizeof(dm));
|
|
|
|
dm.dmSize = sizeof(dm);
|
2013-02-20 10:00:53 -05:00
|
|
|
|
2014-09-12 11:00:05 -04:00
|
|
|
EnumDisplaySettingsExW(monitor->win32.adapterName,
|
2014-03-06 12:30:14 -05:00
|
|
|
ENUM_CURRENT_SETTINGS,
|
2017-08-27 17:09:08 -04:00
|
|
|
&dm,
|
2014-03-06 12:30:14 -05:00
|
|
|
EDS_ROTATEDMODE);
|
2013-02-20 10:00:53 -05:00
|
|
|
|
|
|
|
if (xpos)
|
2017-08-27 17:09:08 -04:00
|
|
|
*xpos = dm.dmPosition.x;
|
2013-02-20 10:00:53 -05:00
|
|
|
if (ypos)
|
2017-08-27 17:09:08 -04:00
|
|
|
*ypos = dm.dmPosition.y;
|
2013-02-20 10:00:53 -05:00
|
|
|
}
|
2011-10-01 13:42:59 -04:00
|
|
|
|
2017-08-29 13:19:00 -04:00
|
|
|
void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor,
|
|
|
|
float* xscale, float* yscale)
|
|
|
|
{
|
|
|
|
_glfwGetMonitorContentScaleWin32(monitor->win32.handle, xscale, yscale);
|
|
|
|
}
|
|
|
|
|
2019-02-25 08:01:08 -05:00
|
|
|
void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor,
|
|
|
|
int* xpos, int* ypos,
|
|
|
|
int* width, int* height)
|
2017-04-06 15:48:08 -04:00
|
|
|
{
|
2019-02-25 08:09:34 -05:00
|
|
|
MONITORINFO mi = { sizeof(mi) };
|
|
|
|
GetMonitorInfo(monitor->win32.handle, &mi);
|
2017-04-06 15:48:08 -04:00
|
|
|
|
2018-09-08 11:14:57 -04:00
|
|
|
if (xpos)
|
2019-02-25 08:09:34 -05:00
|
|
|
*xpos = mi.rcWork.left;
|
2018-09-08 11:14:57 -04:00
|
|
|
if (ypos)
|
2019-02-25 08:09:34 -05:00
|
|
|
*ypos = mi.rcWork.top;
|
2018-09-08 11:14:57 -04:00
|
|
|
if (width)
|
2019-02-25 08:09:34 -05:00
|
|
|
*width = mi.rcWork.right - mi.rcWork.left;
|
2018-09-08 11:14:57 -04:00
|
|
|
if (height)
|
2019-02-25 08:09:34 -05:00
|
|
|
*height = mi.rcWork.bottom - mi.rcWork.top;
|
2017-04-06 15:48:08 -04:00
|
|
|
}
|
|
|
|
|
2015-03-22 19:08:28 -04:00
|
|
|
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
|
2012-09-12 15:04:24 -04:00
|
|
|
{
|
2015-03-22 19:08:28 -04:00
|
|
|
int modeIndex = 0, size = 0;
|
2012-09-12 15:04:24 -04:00
|
|
|
GLFWvidmode* result = NULL;
|
|
|
|
|
2015-03-22 19:08:28 -04:00
|
|
|
*count = 0;
|
2012-09-12 15:04:24 -04:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
GLFWvidmode mode;
|
2014-03-06 12:30:14 -05:00
|
|
|
DEVMODEW dm;
|
2012-09-12 15:04:24 -04:00
|
|
|
|
2017-08-27 17:09:08 -04:00
|
|
|
ZeroMemory(&dm, sizeof(dm));
|
|
|
|
dm.dmSize = sizeof(dm);
|
2012-09-12 15:04:24 -04:00
|
|
|
|
2014-09-12 11:00:05 -04:00
|
|
|
if (!EnumDisplaySettingsW(monitor->win32.adapterName, modeIndex, &dm))
|
2012-09-12 15:04:24 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
modeIndex++;
|
|
|
|
|
2015-03-22 19:08:28 -04:00
|
|
|
// Skip modes with less than 15 BPP
|
2012-09-12 15:04:24 -04:00
|
|
|
if (dm.dmBitsPerPel < 15)
|
|
|
|
continue;
|
|
|
|
|
2013-05-30 09:52:42 -04:00
|
|
|
mode.width = dm.dmPelsWidth;
|
2012-09-12 15:04:24 -04:00
|
|
|
mode.height = dm.dmPelsHeight;
|
2013-05-30 09:52:42 -04:00
|
|
|
mode.refreshRate = dm.dmDisplayFrequency;
|
2012-09-12 15:04:24 -04:00
|
|
|
_glfwSplitBPP(dm.dmBitsPerPel,
|
2012-09-12 17:03:15 -04:00
|
|
|
&mode.redBits,
|
|
|
|
&mode.greenBits,
|
|
|
|
&mode.blueBits);
|
2012-09-12 15:04:24 -04:00
|
|
|
|
2015-03-22 19:08:28 -04:00
|
|
|
for (i = 0; i < *count; i++)
|
2012-09-12 15:04:24 -04:00
|
|
|
{
|
|
|
|
if (_glfwCompareVideoModes(result + i, &mode) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-03-22 19:08:28 -04:00
|
|
|
// Skip duplicate modes
|
|
|
|
if (i < *count)
|
2012-09-12 15:04:24 -04:00
|
|
|
continue;
|
|
|
|
|
2015-09-20 10:25:00 -04:00
|
|
|
if (monitor->win32.modesPruned)
|
|
|
|
{
|
|
|
|
// Skip modes not supported by the connected displays
|
|
|
|
if (ChangeDisplaySettingsExW(monitor->win32.adapterName,
|
|
|
|
&dm,
|
|
|
|
NULL,
|
|
|
|
CDS_TEST,
|
|
|
|
NULL) != DISP_CHANGE_SUCCESSFUL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-22 19:08:28 -04:00
|
|
|
if (*count == size)
|
2012-09-12 15:04:24 -04:00
|
|
|
{
|
2015-12-06 09:08:23 -05:00
|
|
|
size += 128;
|
2021-08-03 14:53:48 -04:00
|
|
|
result = (GLFWvidmode*) _glfw_realloc(result, size * sizeof(GLFWvidmode));
|
2012-09-12 15:04:24 -04:00
|
|
|
}
|
|
|
|
|
2015-03-22 19:08:28 -04:00
|
|
|
(*count)++;
|
|
|
|
result[*count - 1] = mode;
|
2012-09-12 15:04:24 -04:00
|
|
|
}
|
|
|
|
|
2015-12-06 08:55:57 -05:00
|
|
|
if (!*count)
|
|
|
|
{
|
|
|
|
// HACK: Report the current mode if no valid modes were found
|
2021-08-03 14:53:48 -04:00
|
|
|
result = _glfw_calloc(1, sizeof(GLFWvidmode));
|
2015-12-10 06:16:13 -05:00
|
|
|
_glfwPlatformGetVideoMode(monitor, result);
|
2015-12-06 08:55:57 -05:00
|
|
|
*count = 1;
|
|
|
|
}
|
|
|
|
|
2012-09-12 15:04:24 -04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
|
|
|
|
{
|
2014-03-06 12:30:14 -05:00
|
|
|
DEVMODEW dm;
|
2017-08-27 17:09:08 -04:00
|
|
|
ZeroMemory(&dm, sizeof(dm));
|
|
|
|
dm.dmSize = sizeof(dm);
|
2012-09-12 15:04:24 -04:00
|
|
|
|
2014-09-12 11:00:05 -04:00
|
|
|
EnumDisplaySettingsW(monitor->win32.adapterName, ENUM_CURRENT_SETTINGS, &dm);
|
2012-09-12 15:04:24 -04:00
|
|
|
|
|
|
|
mode->width = dm.dmPelsWidth;
|
|
|
|
mode->height = dm.dmPelsHeight;
|
2013-05-30 09:52:42 -04:00
|
|
|
mode->refreshRate = dm.dmDisplayFrequency;
|
2012-09-12 15:04:24 -04:00
|
|
|
_glfwSplitBPP(dm.dmBitsPerPel,
|
|
|
|
&mode->redBits,
|
|
|
|
&mode->greenBits,
|
|
|
|
&mode->blueBits);
|
|
|
|
}
|
|
|
|
|
2018-12-19 08:53:01 -05:00
|
|
|
GLFWbool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
|
2014-08-18 06:31:48 -04:00
|
|
|
{
|
|
|
|
HDC dc;
|
2019-08-22 17:39:47 -04:00
|
|
|
WORD values[3][256];
|
2014-08-18 06:31:48 -04:00
|
|
|
|
2014-09-12 11:00:05 -04:00
|
|
|
dc = CreateDCW(L"DISPLAY", monitor->win32.adapterName, NULL, NULL);
|
2014-08-18 06:31:48 -04:00
|
|
|
GetDeviceGammaRamp(dc, values);
|
|
|
|
DeleteDC(dc);
|
|
|
|
|
|
|
|
_glfwAllocGammaArrays(ramp, 256);
|
|
|
|
|
2019-08-22 17:39:47 -04:00
|
|
|
memcpy(ramp->red, values[0], sizeof(values[0]));
|
|
|
|
memcpy(ramp->green, values[1], sizeof(values[1]));
|
|
|
|
memcpy(ramp->blue, values[2], sizeof(values[2]));
|
2018-12-19 08:53:01 -05:00
|
|
|
|
|
|
|
return GLFW_TRUE;
|
2014-08-18 06:31:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
|
|
|
|
{
|
|
|
|
HDC dc;
|
2019-08-22 17:39:47 -04:00
|
|
|
WORD values[3][256];
|
2014-08-18 06:31:48 -04:00
|
|
|
|
|
|
|
if (ramp->size != 256)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Gamma ramp size must be 256");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-22 17:39:47 -04:00
|
|
|
memcpy(values[0], ramp->red, sizeof(values[0]));
|
|
|
|
memcpy(values[1], ramp->green, sizeof(values[1]));
|
|
|
|
memcpy(values[2], ramp->blue, sizeof(values[2]));
|
2014-08-18 06:31:48 -04:00
|
|
|
|
2014-09-12 11:00:05 -04:00
|
|
|
dc = CreateDCW(L"DISPLAY", monitor->win32.adapterName, NULL, NULL);
|
2014-08-18 06:31:48 -04:00
|
|
|
SetDeviceGammaRamp(dc, values);
|
|
|
|
DeleteDC(dc);
|
|
|
|
}
|
|
|
|
|
2014-01-13 14:02:43 -05:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW native API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-10-28 10:35:03 -04:00
|
|
|
GLFWAPI const char* glfwGetWin32Adapter(GLFWmonitor* handle)
|
|
|
|
{
|
|
|
|
_GLFWmonitor* monitor = (_GLFWmonitor*) handle;
|
|
|
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
|
|
|
return monitor->win32.publicAdapterName;
|
|
|
|
}
|
|
|
|
|
2014-09-12 11:03:44 -04:00
|
|
|
GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* handle)
|
2014-01-13 14:02:43 -05:00
|
|
|
{
|
|
|
|
_GLFWmonitor* monitor = (_GLFWmonitor*) handle;
|
|
|
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
2014-10-28 10:35:03 -04:00
|
|
|
return monitor->win32.publicDisplayName;
|
2014-01-13 14:02:43 -05:00
|
|
|
}
|
|
|
|
|