glfw/src/win32_monitor.c

167 lines
5.0 KiB
C
Raw Normal View History

//========================================================================
// GLFW - An OpenGL library
// Platform: X11 (Unix)
// API version: 3.0
// WWW: http://www.glfw.org/
//------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
//
// 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.
//
//========================================================================
#include "internal.h"
#include <stdlib.h>
#include <string.h>
2012-09-12 18:46:54 +00:00
// These constants are missing on MinGW
#ifndef EDS_ROTATEDMODE
2012-09-12 18:46:54 +00:00
#define EDS_ROTATEDMODE 0x00000004
#endif
2012-01-31 22:47:01 +00:00
#ifndef DISPLAY_DEVICE_ACTIVE
2012-09-12 18:46:54 +00:00
#define DISPLAY_DEVICE_ACTIVE 0x00000001
2012-01-31 22:47:01 +00:00
#endif
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
2012-07-06 12:36:29 +00:00
//========================================================================
2012-09-12 17:35:52 +00:00
// Return a list of available monitors
2012-07-06 12:36:29 +00:00
//========================================================================
2012-09-12 17:35:52 +00:00
_GLFWmonitor** _glfwPlatformGetMonitors(int* count)
{
2012-09-12 17:35:52 +00:00
int size = 0, found = 0;
_GLFWmonitor** monitors = NULL;
DWORD adapterIndex = 0;
2012-09-12 17:35:52 +00:00
for (;;)
{
2012-09-12 18:54:12 +00:00
// Enumerate display adapters
2012-09-12 17:35:52 +00:00
DISPLAY_DEVICE adapter;
DWORD monitorIndex = 0;
2012-09-12 17:35:52 +00:00
ZeroMemory(&adapter, sizeof(DISPLAY_DEVICE));
adapter.cb = sizeof(DISPLAY_DEVICE);
2012-09-12 17:35:52 +00:00
if (!EnumDisplayDevices(NULL, adapterIndex, &adapter, 0))
break;
2012-09-12 17:35:52 +00:00
adapterIndex++;
2012-09-12 17:35:52 +00:00
if ((adapter.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) ||
!(adapter.StateFlags & DISPLAY_DEVICE_ACTIVE))
{
continue;
}
for (;;)
{
2012-09-12 18:54:12 +00:00
// Enumerate monitors for the display adapter
2012-09-12 17:35:52 +00:00
DISPLAY_DEVICE monitor;
DEVMODE settings;
const char* name;
HDC dc;
ZeroMemory(&monitor, sizeof(DISPLAY_DEVICE));
monitor.cb = sizeof(DISPLAY_DEVICE);
if (!EnumDisplayDevices(adapter.DeviceName, monitorIndex, &monitor, 0))
break;
2012-09-12 18:46:54 +00:00
monitorIndex++;
2012-09-12 17:35:52 +00:00
ZeroMemory(&settings, sizeof(DEVMODE));
settings.dmSize = sizeof(DEVMODE);
EnumDisplaySettingsEx(adapter.DeviceName,
ENUM_CURRENT_SETTINGS,
&settings,
EDS_ROTATEDMODE);
name = _glfwCreateUTF8FromWideString(monitor.DeviceName);
if (!name)
{
// TODO: wat
return NULL;
}
dc = CreateDC(L"DISPLAY", monitor.DeviceString, NULL, NULL);
if (!dc)
{
// TODO: wat
return NULL;
}
if (found == size)
{
if (size)
size *= 2;
else
size = 4;
monitors = (_GLFWmonitor**) realloc(monitors, sizeof(_GLFWmonitor*) * size);
2012-09-12 18:54:45 +00:00
if (!monitors)
{
// TODO: wat
return NULL;
}
2012-09-12 17:35:52 +00:00
}
monitors[found] = _glfwCreateMonitor(name,
GetDeviceCaps(dc, HORZSIZE),
GetDeviceCaps(dc, VERTSIZE),
settings.dmPosition.x,
settings.dmPosition.y);
DeleteDC(dc);
if (!monitors[found])
{
// TODO: wat
return NULL;
}
monitors[found]->Win32.name = wcsdup(monitor.DeviceName);
found++;
}
}
2012-07-06 11:55:54 +00:00
2012-09-12 17:35:52 +00:00
*count = found;
return monitors;
}
2012-07-06 12:36:29 +00:00
//========================================================================
// Destroy a monitor struct
//========================================================================
2012-09-12 17:35:52 +00:00
void _glfwPlatformDestroyMonitor(_GLFWmonitor* monitor)
{
2012-07-06 11:55:54 +00:00
free(monitor->Win32.name);
}