Moved platform specific monitor list creation part to separate functions.

This commit is contained in:
Marcel Metz 2012-01-30 12:33:32 +01:00
parent 6f970f5753
commit f228d23024
6 changed files with 36 additions and 51 deletions

View File

@ -65,6 +65,13 @@
// extensions and not all operating systems come with an up-to-date version
#include "../support/GL/glext.h"
typedef struct _GLFWhints _GLFWhints;
typedef struct _GLFWwndconfig _GLFWwndconfig;
typedef struct _GLFWfbconfig _GLFWfbconfig;
typedef struct _GLFWwindow _GLFWwindow;
typedef struct _GLFWlibrary _GLFWlibrary;
typedef struct _GLFWmonitor _GLFWmonitor;
#if defined(_GLFW_COCOA_NSGL)
#include "cocoa_platform.h"
#elif defined(_GLFW_WIN32_WGL)
@ -75,14 +82,6 @@
#error "No supported platform selected"
#endif
typedef struct _GLFWhints _GLFWhints;
typedef struct _GLFWwndconfig _GLFWwndconfig;
typedef struct _GLFWfbconfig _GLFWfbconfig;
typedef struct _GLFWwindow _GLFWwindow;
typedef struct _GLFWlibrary _GLFWlibrary;
typedef struct _GLFWmonitor _GLFWmonitor;
//------------------------------------------------------------------------
// Window hints, set by glfwOpenWindowHint and consumed by glfwOpenWindow
// A bucket of semi-random stuff lumped together for historical reasons
@ -388,9 +387,7 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig);
GLboolean _glfwIsValidContext(_GLFWwindow* window, _GLFWwndconfig* wndconfig);
// Monitor management (monitor.c)
void _glfwInitMonitors(void);
void _glfwTerminateMonitors(void);
// platform specific (*_monitor.c)
_GLFWmonitor* _glfwDestroyMonitor(_GLFWmonitor* monitor);
#endif // _internal_h_

View File

@ -145,6 +145,15 @@ GLFWAPI void glfwSetMonitorDeviceCallback(GLFWmonitordevicefun cbfun)
_glfwLibrary.monitorCallback= cbfun;
}
//========================================================================
// Initialize the monitor list.
//========================================================================
void _glfwInitMonitors(void)
{
_glfwLibrary.monitorListHead = _glfwCreateMonitors();
}
//========================================================================
// Delete the monitor list.
//========================================================================

View File

@ -83,29 +83,21 @@ _GLFWmonitor* _glfwDestroyMonitor(_GLFWmonitor* monitor)
return result;
}
// todo: This is ugly. The platform should only allocate a list of the current devices.
// The platform independent code should be in charge of the handling for the initial
// setup, refreshing and freeing the list.
void _glfwInitMonitors(void)
_GLFWmonitor* _glfwCreateMonitors(void)
{
_GLFWmonitor** curMonitor;
DISPLAY_DEVICE adapter;
DWORD adapterNum;
DISPLAY_DEVICE monitor;
DEVMODE setting;
DWORD settingNum;
curMonitor = &_glfwLibrary.monitorListHead;
_GLFWmonitor* monitorList;
_GLFWmonitor** curMonitor;
adapter.cb = sizeof(DISPLAY_DEVICE);
adapterNum = 0;
monitor.cb = sizeof(DISPLAY_DEVICE);
setting.dmSize = sizeof(DEVMODE);
settingNum = 0;
monitorList = NULL;
curMonitor = &monitorList;
while (EnumDisplayDevices(NULL, adapterNum++, &adapter, 0))
{
@ -121,36 +113,16 @@ void _glfwInitMonitors(void)
curMonitor = _glfwCreateMonitor(curMonitor, &adapter, &monitor, &setting);
}
return monitorList;
}
void _glfwRefreshMonitors(void)
{
DISPLAY_DEVICE adapter;
DWORD adapterNum = 0;
DISPLAY_DEVICE monitor;
DEVMODE setting;
_GLFWmonitor* newMonitorList = NULL;
_GLFWmonitor** curMonitor = &newMonitorList;
_GLFWmonitor* curNewMonitor;
_GLFWmonitor* curOldMonitor;
while (EnumDisplayDevices(NULL, adapterNum++, &adapter, 0))
{
if (adapter.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER || !(adapter.StateFlags & DISPLAY_DEVICE_ACTIVE))
continue;
EnumDisplaySettingsEx(adapter.DeviceName, ENUM_CURRENT_SETTINGS, &setting, EDS_ROTATEDMODE);
EnumDisplayDevices(adapter.DeviceName, 0, &monitor, 0);
curMonitor = _glfwCreateMonitor(curMonitor, &adapter, &monitor, &setting);
}
curNewMonitor = newMonitorList;
curNewMonitor = _glfwCreateMonitors();
curOldMonitor = _glfwLibrary.monitorListHead;
while (_glfwLibrary.monitorCallback && (curNewMonitor || curOldMonitor))

View File

@ -339,6 +339,8 @@ void _glfwInitTimer(void);
// Monitor support
void _glfwInitMonitors(void);
void _glfwRefreshMonitors(void);
_GLFWmonitor* _glfwCreateMonitors(void);
_GLFWmonitor* _glfwDestroyMonitor(_GLFWmonitor* monitor);
// Fullscreen support
void _glfwSetVideoMode(int* width, int* height,

View File

@ -77,9 +77,11 @@ _GLFWmonitor* _glfwDestroyMonitor(_GLFWmonitor* monitor)
return result;
}
void _glfwInitMonitors(void)
_GLFWmonitor* _glfwCreateMonitors(void)
{
_glfwLibrary.monitorListHead = NULL;
_GLFWmonitor* monitorList;
monitorList = NULL;
if (_glfwLibrary.X11.RandR.available)
{
@ -88,7 +90,7 @@ void _glfwInitMonitors(void)
int outputIDX;
_GLFWmonitor** curMonitor;
curMonitor = &_glfwLibrary.monitorListHead;
curMonitor = &monitorList;
resources = XRRGetScreenResources(_glfwLibrary.X11.display,
_glfwLibrary.X11.root);
@ -126,5 +128,7 @@ void _glfwInitMonitors(void)
}
#endif /*_GLFW_HAS_XRANDR*/
}
return monitorList;
}

View File

@ -280,7 +280,8 @@ void _glfwInitJoysticks(void);
void _glfwTerminateJoysticks(void);
// Monitors
void _glfwInitMonitors(void);
_GLFWmonitor* _glfwCreateMonitors(void);
_GLFWmonitor* _glfwDestroyMonitor(_GLFWmonitor* monitor);
// Unicode support
long _glfwKeySym2Unicode(KeySym keysym);