1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-10-08 23:27:25 -04:00
glfw/src/x11_monitor.c

116 lines
3.6 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-08-16 13:11:31 -04:00
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
2012-07-06 08:36:29 -04:00
//========================================================================
// Return a list of available monitors
//========================================================================
2012-09-12 13:35:52 -04:00
_GLFWmonitor** _glfwPlatformGetMonitors(int* count)
{
2012-09-12 13:35:52 -04:00
int found = 0;
_GLFWmonitor** monitors = NULL;
2011-10-03 12:48:59 -04:00
if (_glfwLibrary.X11.RandR.available)
{
2011-10-03 12:48:59 -04:00
#if defined (_GLFW_HAS_XRANDR)
2012-09-12 13:35:52 -04:00
int i;
XRRScreenResources* sr;
2012-09-12 13:35:52 -04: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;
}
2012-09-12 13:35:52 -04:00
for (i = 0; i < sr->noutput; i++)
{
2012-09-12 13:35:52 -04:00
XRROutputInfo* oi;
XRRCrtcInfo* ci;
2012-09-12 13:35:52 -04: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);
2012-09-12 13:35:52 -04:00
monitors[found] = _glfwCreateMonitor(oi->name,
oi->mm_width, oi->mm_height,
ci->x, ci->y);
XRRFreeCrtcInfo(ci);
if (!monitors[found])
{
2012-09-12 13:35:52 -04:00
// TODO: wat
return NULL;
}
2012-09-12 13:35:52 -04:00
// This is retained until the monitor object is destroyed
monitors[found]->X11.output = oi;
found++;
}
2011-10-03 12:48:59 -04:00
#endif /*_GLFW_HAS_XRANDR*/
}
2012-09-12 13:35:52 -04: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*/
}