2010-09-07 11:34:51 -04:00
|
|
|
//========================================================================
|
2011-03-05 19:46:39 -05:00
|
|
|
// GLFW - An OpenGL library
|
2010-09-07 11:34:51 -04:00
|
|
|
// Platform: X11/GLX
|
2010-09-07 11:41:26 -04:00
|
|
|
// API version: 3.0
|
2010-09-07 11:34:51 -04:00
|
|
|
// 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 <limits.h>
|
2010-09-08 11:01:39 -04:00
|
|
|
#include <stdlib.h>
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
|
2010-09-15 10:44:43 -04:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
//========================================================================
|
|
|
|
// Finds the video mode closest in size to the specified desired size
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 09:58:43 -04:00
|
|
|
int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
int i, match, bestmatch;
|
|
|
|
|
2010-10-13 17:05:17 -04:00
|
|
|
if (_glfwLibrary.X11.RandR.available)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-10-14 09:13:51 -04:00
|
|
|
#if defined(_GLFW_HAS_XRANDR)
|
2011-09-26 09:38:11 -04:00
|
|
|
int sizecount, bestsize;
|
|
|
|
int ratecount, bestrate;
|
|
|
|
short* ratelist;
|
|
|
|
XRRScreenConfiguration* sc;
|
|
|
|
XRRScreenSize* sizelist;
|
|
|
|
|
2010-09-09 12:15:32 -04:00
|
|
|
sc = XRRGetScreenInfo(_glfwLibrary.X11.display,
|
|
|
|
RootWindow(_glfwLibrary.X11.display, screen));
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
sizelist = XRRConfigSizes(sc, &sizecount);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
// Find the best matching mode
|
|
|
|
bestsize = -1;
|
|
|
|
bestmatch = INT_MAX;
|
2010-09-08 09:51:25 -04:00
|
|
|
for (i = 0; i < sizecount; i++)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
match = (*width - sizelist[i].width) *
|
|
|
|
(*width - sizelist[i].width) +
|
|
|
|
(*height - sizelist[i].height) *
|
|
|
|
(*height - sizelist[i].height);
|
2010-09-08 09:51:25 -04:00
|
|
|
if (match < bestmatch)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
bestmatch = match;
|
|
|
|
bestsize = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
if (bestsize != -1)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
// Report width & height of best matching mode
|
|
|
|
*width = sizelist[bestsize].width;
|
|
|
|
*height = sizelist[bestsize].height;
|
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
if (*rate > 0)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 09:51:25 -04:00
|
|
|
ratelist = XRRConfigRates(sc, bestsize, &ratecount);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
bestrate = -1;
|
|
|
|
bestmatch = INT_MAX;
|
2010-09-08 09:51:25 -04:00
|
|
|
for (i = 0; i < ratecount; i++)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 09:51:25 -04:00
|
|
|
match = abs(ratelist[i] - *rate);
|
|
|
|
if (match < bestmatch)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
bestmatch = match;
|
|
|
|
bestrate = ratelist[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
if (bestrate != -1)
|
2010-09-07 11:34:51 -04:00
|
|
|
*rate = bestrate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
XRRFreeScreenConfigInfo(sc);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
if (bestsize != -1)
|
2010-09-07 11:34:51 -04:00
|
|
|
return bestsize;
|
2010-10-14 09:13:51 -04:00
|
|
|
#endif /*_GLFW_HAS_XRANDR*/
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
2010-10-14 09:13:51 -04:00
|
|
|
else if (_glfwLibrary.X11.VidMode.available)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-10-14 09:13:51 -04:00
|
|
|
#if defined(_GLFW_HAS_XF86VIDMODE)
|
2011-09-26 09:38:11 -04:00
|
|
|
XF86VidModeModeInfo** modelist;
|
|
|
|
int bestmode, modecount;
|
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
// Get a list of all available display modes
|
2010-10-13 17:01:17 -04:00
|
|
|
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen,
|
2010-09-08 09:51:25 -04:00
|
|
|
&modecount, &modelist);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
// Find the best matching mode
|
|
|
|
bestmode = -1;
|
|
|
|
bestmatch = INT_MAX;
|
2010-09-08 09:51:25 -04:00
|
|
|
for (i = 0; i < modecount; i++)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
match = (*width - modelist[i]->hdisplay) *
|
|
|
|
(*width - modelist[i]->hdisplay) +
|
|
|
|
(*height - modelist[i]->vdisplay) *
|
|
|
|
(*height - modelist[i]->vdisplay);
|
2010-09-08 09:51:25 -04:00
|
|
|
if (match < bestmatch)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
bestmatch = match;
|
|
|
|
bestmode = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
if (bestmode != -1)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
// Report width & height of best matching mode
|
2010-09-08 09:51:25 -04:00
|
|
|
*width = modelist[bestmode]->hdisplay;
|
|
|
|
*height = modelist[bestmode]->vdisplay;
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
XFree(modelist);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
if (bestmode != -1)
|
2010-09-07 11:34:51 -04:00
|
|
|
return bestmode;
|
2010-10-14 09:13:51 -04:00
|
|
|
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Default: Simply use the screen resolution
|
2010-09-09 12:15:32 -04:00
|
|
|
*width = DisplayWidth(_glfwLibrary.X11.display, screen);
|
|
|
|
*height = DisplayHeight(_glfwLibrary.X11.display, screen);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Change the current video mode
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
void _glfwSetVideoModeMODE(int screen, int mode, int rate)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-10-13 17:05:17 -04:00
|
|
|
if (_glfwLibrary.X11.RandR.available)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-10-14 09:13:51 -04:00
|
|
|
#if defined(_GLFW_HAS_XRANDR)
|
2011-09-26 09:38:11 -04:00
|
|
|
XRRScreenConfiguration* sc;
|
|
|
|
Window root;
|
|
|
|
|
2010-09-09 12:15:32 -04:00
|
|
|
root = RootWindow(_glfwLibrary.X11.display, screen);
|
|
|
|
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, root);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
// Remember old size and flag that we have changed the mode
|
2010-09-09 12:15:32 -04:00
|
|
|
if (!_glfwLibrary.X11.FS.modeChanged)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-09 12:15:32 -04:00
|
|
|
_glfwLibrary.X11.FS.oldSizeID = XRRConfigCurrentConfiguration(sc, &_glfwLibrary.X11.FS.oldRotation);
|
|
|
|
_glfwLibrary.X11.FS.oldWidth = DisplayWidth(_glfwLibrary.X11.display, screen);
|
|
|
|
_glfwLibrary.X11.FS.oldHeight = DisplayHeight(_glfwLibrary.X11.display, screen);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2010-09-09 12:15:32 -04:00
|
|
|
_glfwLibrary.X11.FS.modeChanged = GL_TRUE;
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
if (rate > 0)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
// Set desired configuration
|
2010-09-09 12:15:32 -04:00
|
|
|
XRRSetScreenConfigAndRate(_glfwLibrary.X11.display,
|
2010-09-08 09:51:25 -04:00
|
|
|
sc,
|
|
|
|
root,
|
|
|
|
mode,
|
|
|
|
RR_Rotate_0,
|
|
|
|
(short) rate,
|
|
|
|
CurrentTime);
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Set desired configuration
|
2010-09-09 12:15:32 -04:00
|
|
|
XRRSetScreenConfig(_glfwLibrary.X11.display,
|
2010-09-08 09:51:25 -04:00
|
|
|
sc,
|
|
|
|
root,
|
|
|
|
mode,
|
|
|
|
RR_Rotate_0,
|
|
|
|
CurrentTime);
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
XRRFreeScreenConfigInfo(sc);
|
2010-10-14 09:13:51 -04:00
|
|
|
#endif /*_GLFW_HAS_XRANDR*/
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
2010-10-14 09:13:51 -04:00
|
|
|
else if (_glfwLibrary.X11.VidMode.available)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-10-14 09:13:51 -04:00
|
|
|
#if defined(_GLFW_HAS_XF86VIDMODE)
|
2011-09-26 09:38:11 -04:00
|
|
|
XF86VidModeModeInfo **modelist;
|
|
|
|
int modecount;
|
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
// Get a list of all available display modes
|
2010-09-09 12:15:32 -04:00
|
|
|
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen,
|
2010-09-08 09:51:25 -04:00
|
|
|
&modecount, &modelist);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
// Unlock mode switch if necessary
|
2010-09-09 12:15:32 -04:00
|
|
|
if (_glfwLibrary.X11.FS.modeChanged)
|
|
|
|
XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, screen, 0);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
// Change the video mode to the desired mode
|
2011-09-26 09:38:11 -04:00
|
|
|
XF86VidModeSwitchToMode(_glfwLibrary.X11.display, screen, modelist[mode]);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
// Set viewport to upper left corner (where our window will be)
|
2010-09-09 12:15:32 -04:00
|
|
|
XF86VidModeSetViewPort(_glfwLibrary.X11.display, screen, 0, 0);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
// Lock mode switch
|
2010-09-09 12:15:32 -04:00
|
|
|
XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, screen, 1);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
// Remember old mode and flag that we have changed the mode
|
2010-09-09 12:15:32 -04:00
|
|
|
if (!_glfwLibrary.X11.FS.modeChanged)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-09 12:15:32 -04:00
|
|
|
_glfwLibrary.X11.FS.oldMode = *modelist[0];
|
|
|
|
_glfwLibrary.X11.FS.modeChanged = GL_TRUE;
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
XFree(modelist);
|
2010-10-14 09:13:51 -04:00
|
|
|
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Change the current video mode
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 09:58:43 -04:00
|
|
|
void _glfwSetVideoMode(int screen, int* width, int* height, int* rate)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-07 22:15:49 -04:00
|
|
|
int bestmode;
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
// Find a best match mode
|
2010-09-08 09:51:25 -04:00
|
|
|
bestmode = _glfwGetClosestVideoMode(screen, width, height, rate);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
// Change mode
|
2010-09-08 09:51:25 -04:00
|
|
|
_glfwSetVideoModeMODE(screen, bestmode, *rate);
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Restore the previously saved (original) video mode
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-09 12:15:32 -04:00
|
|
|
void _glfwRestoreVideoMode(int screen)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-09 12:15:32 -04:00
|
|
|
if (_glfwLibrary.X11.FS.modeChanged)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-10-13 17:05:17 -04:00
|
|
|
if (_glfwLibrary.X11.RandR.available)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-10-14 09:13:51 -04:00
|
|
|
#if defined(_GLFW_HAS_XRANDR)
|
2010-09-08 09:58:43 -04:00
|
|
|
XRRScreenConfiguration* sc;
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2010-10-13 17:05:17 -04:00
|
|
|
if (_glfwLibrary.X11.RandR.available)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-10-13 17:01:17 -04:00
|
|
|
sc = XRRGetScreenInfo(_glfwLibrary.X11.display,
|
|
|
|
_glfwLibrary.X11.root);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2010-09-09 12:15:32 -04:00
|
|
|
XRRSetScreenConfig(_glfwLibrary.X11.display,
|
2010-09-08 09:51:25 -04:00
|
|
|
sc,
|
2010-10-13 17:01:17 -04:00
|
|
|
_glfwLibrary.X11.root,
|
2010-09-09 12:15:32 -04:00
|
|
|
_glfwLibrary.X11.FS.oldSizeID,
|
|
|
|
_glfwLibrary.X11.FS.oldRotation,
|
2010-09-08 09:51:25 -04:00
|
|
|
CurrentTime);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
XRRFreeScreenConfigInfo(sc);
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
2010-10-14 09:13:51 -04:00
|
|
|
#endif /*_GLFW_HAS_XRANDR*/
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
2010-10-14 09:13:51 -04:00
|
|
|
else if (_glfwLibrary.X11.VidMode.available)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-10-14 09:13:51 -04:00
|
|
|
#if defined(_GLFW_HAS_XF86VIDMODE)
|
2010-09-07 11:34:51 -04:00
|
|
|
// Unlock mode switch
|
2010-09-09 12:15:32 -04:00
|
|
|
XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, screen, 0);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
// Change the video mode back to the old mode
|
2010-09-09 12:15:32 -04:00
|
|
|
XF86VidModeSwitchToMode(_glfwLibrary.X11.display,
|
|
|
|
screen,
|
|
|
|
&_glfwLibrary.X11.FS.oldMode);
|
2010-10-14 09:13:51 -04:00
|
|
|
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
2010-10-13 17:01:17 -04:00
|
|
|
|
2010-09-09 12:15:32 -04:00
|
|
|
_glfwLibrary.X11.FS.modeChanged = GL_FALSE;
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-15 10:44:43 -04:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
struct _glfwResolution
|
|
|
|
{
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
};
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// List available video modes
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 09:58:43 -04:00
|
|
|
int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
int count, k, l, r, g, b, rgba, gl;
|
|
|
|
int depth, screen;
|
2010-09-08 09:58:43 -04:00
|
|
|
XVisualInfo* vislist;
|
|
|
|
XVisualInfo dummy;
|
2010-09-07 11:34:51 -04:00
|
|
|
int viscount, rgbcount, rescount;
|
2010-09-08 09:58:43 -04:00
|
|
|
int* rgbarray;
|
|
|
|
struct _glfwResolution* resarray;
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
// Get list of visuals
|
2010-10-13 17:01:17 -04:00
|
|
|
vislist = XGetVisualInfo(_glfwLibrary.X11.display, 0, &dummy, &viscount);
|
2010-09-08 09:51:25 -04:00
|
|
|
if (vislist == NULL)
|
2010-09-09 15:52:31 -04:00
|
|
|
{
|
2011-09-26 09:40:18 -04:00
|
|
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
|
|
|
"X11/GLX: Failed to retrieve the available visuals");
|
2010-09-07 11:34:51 -04:00
|
|
|
return 0;
|
2010-09-09 15:52:31 -04:00
|
|
|
}
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2012-02-07 08:58:58 -05:00
|
|
|
rgbarray = (int*) malloc(sizeof(int) * viscount);
|
2010-09-07 11:34:51 -04:00
|
|
|
rgbcount = 0;
|
|
|
|
|
|
|
|
// Build RGB array
|
2010-09-08 09:51:25 -04:00
|
|
|
for (k = 0; k < viscount; k++)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
// Does the visual support OpenGL & true color?
|
2010-10-13 17:01:17 -04:00
|
|
|
glXGetConfig(_glfwLibrary.X11.display, &vislist[k], GLX_USE_GL, &gl);
|
|
|
|
glXGetConfig(_glfwLibrary.X11.display, &vislist[k], GLX_RGBA, &rgba);
|
2010-09-08 09:51:25 -04:00
|
|
|
if (gl && rgba)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
// Get color depth for this visual
|
|
|
|
depth = vislist[k].depth;
|
|
|
|
|
|
|
|
// Convert to RGB
|
2010-09-15 21:48:19 -04:00
|
|
|
_glfwSplitBPP(depth, &r, &g, &b);
|
2010-09-08 09:51:25 -04:00
|
|
|
depth = (r << 16) | (g << 8) | b;
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
// Is this mode unique?
|
2010-09-08 09:51:25 -04:00
|
|
|
for (l = 0; l < rgbcount; l++)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 09:51:25 -04:00
|
|
|
if (depth == rgbarray[l])
|
2010-09-07 11:34:51 -04:00
|
|
|
break;
|
|
|
|
}
|
2010-09-07 22:15:49 -04:00
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
if (l >= rgbcount)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 09:51:25 -04:00
|
|
|
rgbarray[rgbcount] = depth;
|
2010-09-07 11:34:51 -04:00
|
|
|
rgbcount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-07 12:38:08 -05:00
|
|
|
XFree(vislist);
|
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
rescount = 0;
|
|
|
|
resarray = NULL;
|
|
|
|
|
|
|
|
// Build resolution array
|
2010-10-14 09:13:51 -04:00
|
|
|
|
2010-10-13 17:05:17 -04:00
|
|
|
if (_glfwLibrary.X11.RandR.available)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-10-14 09:13:51 -04:00
|
|
|
#if defined(_GLFW_HAS_XRANDR)
|
2011-09-26 09:38:11 -04:00
|
|
|
XRRScreenConfiguration* sc;
|
|
|
|
XRRScreenSize* sizelist;
|
|
|
|
int sizecount;
|
|
|
|
|
2010-10-13 17:01:17 -04:00
|
|
|
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root);
|
2010-09-08 09:51:25 -04:00
|
|
|
sizelist = XRRConfigSizes(sc, &sizecount);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2012-02-07 08:58:58 -05:00
|
|
|
resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * sizecount);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
for (k = 0; k < sizecount; k++)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 09:51:25 -04:00
|
|
|
resarray[rescount].width = sizelist[k].width;
|
|
|
|
resarray[rescount].height = sizelist[k].height;
|
2010-09-07 11:34:51 -04:00
|
|
|
rescount++;
|
|
|
|
}
|
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
XRRFreeScreenConfigInfo(sc);
|
2010-10-14 09:13:51 -04:00
|
|
|
#endif /*_GLFW_HAS_XRANDR*/
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
2010-10-14 09:13:51 -04:00
|
|
|
else if (_glfwLibrary.X11.VidMode.available)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-10-14 09:13:51 -04:00
|
|
|
#if defined(_GLFW_HAS_XF86VIDMODE)
|
2011-09-26 09:38:11 -04:00
|
|
|
XF86VidModeModeInfo** modelist;
|
|
|
|
int modecount, width, height;
|
|
|
|
|
2010-10-13 17:01:17 -04:00
|
|
|
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen, &modecount, &modelist);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2012-02-07 08:58:58 -05:00
|
|
|
resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * modecount);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
for (k = 0; k < modecount; k++)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 09:51:25 -04:00
|
|
|
width = modelist[k]->hdisplay;
|
|
|
|
height = modelist[k]->vdisplay;
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
// Is this mode unique?
|
2010-09-08 09:51:25 -04:00
|
|
|
for (l = 0; l < rescount; l++)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 09:51:25 -04:00
|
|
|
if (width == resarray[l].width && height == resarray[l].height)
|
2010-09-07 11:34:51 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
if (l >= rescount)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 09:51:25 -04:00
|
|
|
resarray[rescount].width = width;
|
|
|
|
resarray[rescount].height = height;
|
2010-09-07 11:34:51 -04:00
|
|
|
rescount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
XFree(modelist);
|
2010-10-14 09:13:51 -04:00
|
|
|
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2010-09-08 09:51:25 -04:00
|
|
|
if (!resarray)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
rescount = 1;
|
2012-02-07 08:58:58 -05:00
|
|
|
resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * rescount);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2010-10-13 17:01:17 -04:00
|
|
|
resarray[0].width = DisplayWidth(_glfwLibrary.X11.display, screen);
|
|
|
|
resarray[0].height = DisplayHeight(_glfwLibrary.X11.display, screen);
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Build permutations of colors and resolutions
|
|
|
|
count = 0;
|
2010-09-08 09:51:25 -04:00
|
|
|
for (k = 0; k < rgbcount && count < maxcount; k++)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 09:51:25 -04:00
|
|
|
for (l = 0; l < rescount && count < maxcount; l++)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-09-08 10:50:50 -04:00
|
|
|
list[count].width = resarray[l].width;
|
|
|
|
list[count].height = resarray[l].height;
|
|
|
|
list[count].redBits = (rgbarray[k] >> 16) & 255;
|
|
|
|
list[count].greenBits = (rgbarray[k] >> 8) & 255;
|
|
|
|
list[count].blueBits = rgbarray[k] & 255;
|
2010-09-07 11:34:51 -04:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-07 08:58:58 -05:00
|
|
|
free(resarray);
|
|
|
|
free(rgbarray);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Get the desktop video mode
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-08 09:58:43 -04:00
|
|
|
void _glfwPlatformGetDesktopMode(GLFWvidmode* mode)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-10-30 16:58:54 -04:00
|
|
|
int bpp;
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2011-09-26 09:38:11 -04:00
|
|
|
// Get and split display depth
|
2010-10-30 16:58:54 -04:00
|
|
|
bpp = DefaultDepth(_glfwLibrary.X11.display, _glfwLibrary.X11.screen);
|
2010-09-15 21:48:19 -04:00
|
|
|
_glfwSplitBPP(bpp, &mode->redBits, &mode->greenBits, &mode->blueBits);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2010-10-14 09:13:51 -04:00
|
|
|
if (_glfwLibrary.X11.FS.modeChanged)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-10-14 09:13:51 -04:00
|
|
|
if (_glfwLibrary.X11.RandR.available)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-10-14 09:13:51 -04:00
|
|
|
#if defined(_GLFW_HAS_XRANDR)
|
2010-09-09 12:15:32 -04:00
|
|
|
mode->width = _glfwLibrary.X11.FS.oldWidth;
|
|
|
|
mode->height = _glfwLibrary.X11.FS.oldHeight;
|
2010-10-14 09:13:51 -04:00
|
|
|
#endif /*_GLFW_HAS_XRANDR*/
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
2010-10-14 09:13:51 -04:00
|
|
|
else if (_glfwLibrary.X11.VidMode.available)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2010-10-14 09:13:51 -04:00
|
|
|
#if defined(_GLFW_HAS_XF86VIDMODE)
|
2010-09-09 12:15:32 -04:00
|
|
|
mode->width = _glfwLibrary.X11.FS.oldMode.hdisplay;
|
|
|
|
mode->height = _glfwLibrary.X11.FS.oldMode.vdisplay;
|
2010-10-14 09:13:51 -04:00
|
|
|
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
}
|
2010-10-14 09:13:51 -04:00
|
|
|
else
|
|
|
|
{
|
2010-11-04 18:16:57 -04:00
|
|
|
mode->width = DisplayWidth(_glfwLibrary.X11.display,
|
|
|
|
_glfwLibrary.X11.screen);
|
|
|
|
mode->height = DisplayHeight(_glfwLibrary.X11.display,
|
|
|
|
_glfwLibrary.X11.screen);
|
2010-10-14 09:13:51 -04:00
|
|
|
}
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|