2011-05-07 10:53:50 +02:00
|
|
|
//========================================================================
|
|
|
|
// 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-08-16 19:11:31 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-07-06 14:36:29 +02:00
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Return a list of available monitors
|
|
|
|
//========================================================================
|
|
|
|
|
2012-09-12 19:35:52 +02:00
|
|
|
_GLFWmonitor** _glfwPlatformGetMonitors(int* count)
|
2011-05-07 10:53:50 +02:00
|
|
|
{
|
2012-09-12 19:35:52 +02:00
|
|
|
int found = 0;
|
|
|
|
_GLFWmonitor** monitors = NULL;
|
2011-10-03 18:48:59 +02:00
|
|
|
|
2011-10-06 23:28:56 +02:00
|
|
|
if (_glfwLibrary.X11.RandR.available)
|
2011-05-07 10:53:50 +02:00
|
|
|
{
|
2011-10-03 18:48:59 +02:00
|
|
|
#if defined (_GLFW_HAS_XRANDR)
|
2012-09-12 19:35:52 +02:00
|
|
|
int i;
|
|
|
|
XRRScreenResources* sr;
|
2011-05-07 10:53:50 +02:00
|
|
|
|
2012-09-12 19:35:52 +02:00
|
|
|
sr = XRRGetScreenResources(_glfwLibrary.X11.display,
|
|
|
|
_glfwLibrary.X11.root);
|
|
|
|
|
|
|
|
monitors = (_GLFWmonitor**) calloc(sr->noutput, sizeof(_GLFWmonitor*));
|
|
|
|
if (!monitors)
|
|
|
|
{
|
|
|
|
_glfwSetError(GLFW_OUT_OF_MEMORY, NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-05-07 10:53:50 +02:00
|
|
|
|
2012-09-12 19:35:52 +02:00
|
|
|
for (i = 0; i < sr->noutput; i++)
|
2011-05-07 10:53:50 +02:00
|
|
|
{
|
2012-09-12 19:35:52 +02:00
|
|
|
XRROutputInfo* oi;
|
|
|
|
XRRCrtcInfo* ci;
|
2011-05-07 10:53:50 +02:00
|
|
|
|
2012-09-12 19:35:52 +02:00
|
|
|
oi = XRRGetOutputInfo(_glfwLibrary.X11.display, sr, sr->outputs[i]);
|
|
|
|
if (oi->connection != RR_Connected)
|
|
|
|
{
|
|
|
|
XRRFreeOutputInfo(oi);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ci = XRRGetCrtcInfo(_glfwLibrary.X11.display, sr, oi->crtc);
|
2011-05-07 10:53:50 +02:00
|
|
|
|
2012-09-12 19:35:52 +02:00
|
|
|
monitors[found] = _glfwCreateMonitor(oi->name,
|
|
|
|
oi->mm_width, oi->mm_height,
|
|
|
|
ci->x, ci->y);
|
|
|
|
|
|
|
|
XRRFreeCrtcInfo(ci);
|
|
|
|
|
|
|
|
if (!monitors[found])
|
2011-05-07 10:53:50 +02:00
|
|
|
{
|
2012-09-12 19:35:52 +02:00
|
|
|
// TODO: wat
|
|
|
|
return NULL;
|
2011-05-07 10:53:50 +02:00
|
|
|
}
|
2012-09-12 19:35:52 +02:00
|
|
|
|
|
|
|
// This is retained until the monitor object is destroyed
|
|
|
|
monitors[found]->X11.output = oi;
|
|
|
|
found++;
|
2011-05-07 10:53:50 +02:00
|
|
|
}
|
2011-10-03 18:48:59 +02:00
|
|
|
#endif /*_GLFW_HAS_XRANDR*/
|
2011-05-07 10:53:50 +02:00
|
|
|
}
|
2012-01-30 12:33:32 +01:00
|
|
|
|
2012-09-12 19:35:52 +02:00
|
|
|
*count = found;
|
|
|
|
return monitors;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Destroy a monitor struct
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
void _glfwPlatformDestroyMonitor(_GLFWmonitor* monitor)
|
|
|
|
{
|
|
|
|
#if defined (_GLFW_HAS_XRANDR)
|
|
|
|
XRRFreeOutputInfo(monitor->X11.output);
|
|
|
|
#endif /*_GLFW_HAS_XRANDR*/
|
2011-05-07 10:53:50 +02:00
|
|
|
}
|
|
|
|
|