41static BOOL CALLBACK monitorCallback(HMONITOR handle,
47 ZeroMemory(&mi,
sizeof(mi));
48 mi.cbSize =
sizeof(mi);
50 if (GetMonitorInfoW(handle, (MONITORINFO*) &mi))
53 if (wcscmp(mi.szDevice, monitor->win32.adapterName) == 0)
54 monitor->win32.handle = handle;
62static _GLFWmonitor* createMonitor(DISPLAY_DEVICEW* adapter,
63 DISPLAY_DEVICEW* display)
66 int widthMM, heightMM;
79 ZeroMemory(&dm,
sizeof(dm));
80 dm.dmSize =
sizeof(dm);
81 EnumDisplaySettingsW(adapter->DeviceName, ENUM_CURRENT_SETTINGS, &dm);
83 dc = CreateDCW(L
"DISPLAY", adapter->DeviceName,
NULL,
NULL);
87 widthMM = GetDeviceCaps(dc, HORZSIZE);
88 heightMM = GetDeviceCaps(dc, VERTSIZE);
92 widthMM = (int) (dm.dmPelsWidth * 25.4f / GetDeviceCaps(dc, LOGPIXELSX));
93 heightMM = (int) (dm.dmPelsHeight * 25.4f / GetDeviceCaps(dc, LOGPIXELSY));
101 if (adapter->StateFlags & DISPLAY_DEVICE_MODESPRUNED)
104 wcscpy(monitor->win32.adapterName, adapter->DeviceName);
105 WideCharToMultiByte(CP_UTF8, 0,
106 adapter->DeviceName, -1,
107 monitor->win32.publicAdapterName,
108 sizeof(monitor->win32.publicAdapterName),
113 wcscpy(monitor->win32.displayName, display->DeviceName);
114 WideCharToMultiByte(CP_UTF8, 0,
115 display->DeviceName, -1,
116 monitor->win32.publicDisplayName,
117 sizeof(monitor->win32.publicDisplayName),
121 rect.left = dm.dmPosition.x;
122 rect.top = dm.dmPosition.y;
123 rect.right = dm.dmPosition.x + dm.dmPelsWidth;
124 rect.bottom = dm.dmPosition.y + dm.dmPelsHeight;
126 EnumDisplayMonitors(
NULL, &rect, monitorCallback, (LPARAM) monitor);
139 int i, disconnectedCount;
141 DWORD adapterIndex, displayIndex;
142 DISPLAY_DEVICEW adapter, display;
146 if (disconnectedCount)
154 for (adapterIndex = 0; ; adapterIndex++)
158 ZeroMemory(&adapter,
sizeof(adapter));
159 adapter.cb =
sizeof(adapter);
161 if (!EnumDisplayDevicesW(
NULL, adapterIndex, &adapter, 0))
167 if (adapter.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
170 for (displayIndex = 0; ; displayIndex++)
172 ZeroMemory(&display,
sizeof(display));
173 display.cb =
sizeof(display);
175 if (!EnumDisplayDevicesW(adapter.DeviceName, displayIndex, &display, 0))
181 for (i = 0; i < disconnectedCount; i++)
183 if (disconnected[i] &&
184 wcscmp(disconnected[i]->win32.displayName,
185 display.DeviceName) == 0)
187 disconnected[i] =
NULL;
194 if (i < disconnectedCount)
197 monitor = createMonitor(&adapter, &display);
211 if (displayIndex == 0)
213 for (i = 0; i < disconnectedCount; i++)
215 if (disconnected[i] &&
216 wcscmp(disconnected[i]->win32.adapterName,
217 adapter.DeviceName) == 0)
219 disconnected[i] =
NULL;
224 if (i < disconnectedCount)
227 monitor = createMonitor(&adapter,
NULL);
238 for (i = 0; i < disconnectedCount; i++)
261 ZeroMemory(&dm,
sizeof(dm));
262 dm.dmSize =
sizeof(dm);
263 dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL |
265 dm.dmPelsWidth = best->
width;
266 dm.dmPelsHeight = best->
height;
270 if (dm.dmBitsPerPel < 15 || dm.dmBitsPerPel >= 24)
271 dm.dmBitsPerPel = 32;
273 result = ChangeDisplaySettingsExW(monitor->win32.adapterName,
278 if (result == DISP_CHANGE_SUCCESSFUL)
282 const char* description =
"Unknown error";
284 if (result == DISP_CHANGE_BADDUALVIEW)
285 description =
"The system uses DualView";
286 else if (result == DISP_CHANGE_BADFLAGS)
287 description =
"Invalid flags";
288 else if (result == DISP_CHANGE_BADMODE)
289 description =
"Graphics mode not supported";
290 else if (result == DISP_CHANGE_BADPARAM)
291 description =
"Invalid parameter";
292 else if (result == DISP_CHANGE_FAILED)
293 description =
"Graphics mode failed";
294 else if (result == DISP_CHANGE_NOTUPDATED)
295 description =
"Failed to write to registry";
296 else if (result == DISP_CHANGE_RESTART)
297 description =
"Computer restart required";
300 "Win32: Failed to set video mode: %s",
309 if (monitor->win32.modeChanged)
311 ChangeDisplaySettingsExW(monitor->win32.adapterName,
325 const HDC dc = GetDC(
NULL);
326 xdpi = GetDeviceCaps(dc, LOGPIXELSX);
327 ydpi = GetDeviceCaps(dc, LOGPIXELSY);
349 ZeroMemory(&dm,
sizeof(dm));
350 dm.dmSize =
sizeof(dm);
352 EnumDisplaySettingsExW(monitor->win32.adapterName,
353 ENUM_CURRENT_SETTINGS,
358 *xpos = dm.dmPosition.x;
360 *ypos = dm.dmPosition.y;
364 float* xscale,
float* yscale)
370 int* xpos,
int* ypos,
371 int* width,
int* height)
373 MONITORINFO mi = {
sizeof(mi) };
374 GetMonitorInfo(monitor->win32.handle, &mi);
377 *xpos = mi.rcWork.left;
379 *ypos = mi.rcWork.top;
381 *width = mi.rcWork.right - mi.rcWork.left;
383 *height = mi.rcWork.bottom - mi.rcWork.top;
388 int modeIndex = 0, size = 0;
399 ZeroMemory(&dm,
sizeof(dm));
400 dm.dmSize =
sizeof(dm);
402 if (!EnumDisplaySettingsW(monitor->win32.adapterName, modeIndex, &dm))
408 if (dm.dmBitsPerPel < 15)
411 mode.
width = dm.dmPelsWidth;
412 mode.
height = dm.dmPelsHeight;
419 for (i = 0; i < *count; i++)
429 if (monitor->win32.modesPruned)
432 if (ChangeDisplaySettingsExW(monitor->win32.adapterName,
436 NULL) != DISP_CHANGE_SUCCESSFUL)
449 result[*count - 1] = mode;
466 ZeroMemory(&dm,
sizeof(dm));
467 dm.dmSize =
sizeof(dm);
469 EnumDisplaySettingsW(monitor->win32.adapterName, ENUM_CURRENT_SETTINGS, &dm);
471 mode->
width = dm.dmPelsWidth;
472 mode->
height = dm.dmPelsHeight;
485 dc = CreateDCW(L
"DISPLAY", monitor->win32.adapterName,
NULL,
NULL);
486 GetDeviceGammaRamp(dc, values);
491 memcpy(ramp->
red, values[0],
sizeof(values[0]));
492 memcpy(ramp->
green, values[1],
sizeof(values[1]));
493 memcpy(ramp->
blue, values[2],
sizeof(values[2]));
503 if (ramp->
size != 256)
506 "Win32: Gamma ramp size must be 256");
510 memcpy(values[0], ramp->
red,
sizeof(values[0]));
511 memcpy(values[1], ramp->
green,
sizeof(values[1]));
512 memcpy(values[2], ramp->
blue,
sizeof(values[2]));
514 dc = CreateDCW(L
"DISPLAY", monitor->win32.adapterName,
NULL,
NULL);
515 SetDeviceGammaRamp(dc, values);
528 return monitor->win32.publicAdapterName;
535 return monitor->win32.publicDisplayName;
#define GLFW_DISCONNECTED
#define GLFW_PLATFORM_ERROR
A platform-specific error occurred that does not match any of the more specific categories.
struct GLFWmonitor GLFWmonitor
Opaque monitor object.
void _glfwInputError(int code, const char *format,...)
void _glfwInputMonitor(_GLFWmonitor *monitor, int action, int placement)
void _glfwSplitBPP(int bpp, int *red, int *green, int *blue)
const GLFWvidmode * _glfwChooseVideoMode(_GLFWmonitor *monitor, const GLFWvidmode *desired)
#define _GLFW_REQUIRE_INIT_OR_RETURN(x)
#define _GLFW_INSERT_FIRST
int _glfwCompareVideoModes(const GLFWvidmode *first, const GLFWvidmode *second)
_GLFWmonitor * _glfwAllocMonitor(const char *name, int widthMM, int heightMM)
#define _GLFW_INSERT_LAST
void _glfwAllocGammaArrays(GLFWgammaramp *ramp, unsigned int size)
char * _glfwCreateUTF8FromWideStringWin32(const WCHAR *source)
void _glfwPlatformFreeMonitor(_GLFWmonitor *monitor)
void _glfwPollMonitorsWin32(void)
void _glfwSetVideoModeWin32(_GLFWmonitor *monitor, const GLFWvidmode *desired)
GLFWvidmode * _glfwPlatformGetVideoModes(_GLFWmonitor *monitor, int *count)
void _glfwGetMonitorContentScaleWin32(HMONITOR handle, float *xscale, float *yscale)
GLFWAPI const char * glfwGetWin32Adapter(GLFWmonitor *handle)
void _glfwPlatformGetVideoMode(_GLFWmonitor *monitor, GLFWvidmode *mode)
void _glfwPlatformSetGammaRamp(_GLFWmonitor *monitor, const GLFWgammaramp *ramp)
void _glfwPlatformGetMonitorPos(_GLFWmonitor *monitor, int *xpos, int *ypos)
GLFWbool _glfwPlatformGetGammaRamp(_GLFWmonitor *monitor, GLFWgammaramp *ramp)
GLFWAPI const char * glfwGetWin32Monitor(GLFWmonitor *handle)
void _glfwPlatformGetMonitorContentScale(_GLFWmonitor *monitor, float *xscale, float *yscale)
void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor *monitor, int *xpos, int *ypos, int *width, int *height)
void _glfwRestoreVideoModeWin32(_GLFWmonitor *monitor)