Implemented display aware glfwVideoModes function for X11 XRandR and win32.

This commit is contained in:
Marcel Metz
2011-10-02 16:13:47 -04:00
parent a905e671b3
commit 58d4323ece
8 changed files with 80 additions and 15 deletions
+42 -9
View File
@@ -325,11 +325,26 @@ struct _glfwResolution
int height;
};
int _glfwCompareResolution(const void* left, const void* right)
{
int result = 0;
const struct _glfwResolution* leftResolution = left;
const struct _glfwResolution* rightResolution = right;
result = leftResolution->height - rightResolution->height;
if (result == 0)
{
result = leftResolution->width - rightResolution->width;
}
return result;
}
//========================================================================
// List available video modes
//========================================================================
int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
int _glfwPlatformGetVideoModes(GLFWdisplay display, GLFWvidmode* list, int maxcount)
{
int count, k, l, r, g, b, rgba, gl;
int depth, screen;
@@ -397,19 +412,37 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
if (_glfwLibrary.X11.RandR.available)
{
#if defined(_GLFW_HAS_XRANDR)
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root);
sizelist = XRRConfigSizes(sc, &sizecount);
XRRScreenResources* resource;
unsigned int a;
resource = XRRGetScreenResources(_glfwLibrary.X11.display, _glfwLibrary.X11.root);
resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * sizecount);
resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * display->X11.output->nmode);
for (k = 0; k < sizecount; k++)
for (k = 0; k < display->X11.output->nmode; k++)
{
resarray[rescount].width = sizelist[k].width;
resarray[rescount].height = sizelist[k].height;
rescount++;
for (a = 0; a < resource->nmode; a++)
{
if (resource->modes[a].id != display->X11.output->modes[k])
{
continue;
}
struct _glfwResolution res = {
resource->modes[a].width,
resource->modes[a].height
};
if (!bsearch(&res, resarray, rescount, sizeof(struct _glfwResolution), _glfwCompareResolution))
{
resarray[rescount].width = resource->modes[a].width;
resarray[rescount].height = resource->modes[a].height;
rescount++;
qsort(resarray, rescount, sizeof(struct _glfwResolution), _glfwCompareResolution);
}
}
}
XRRFreeScreenConfigInfo(sc);
XRRFreeScreenResources(resource);
#endif /*_GLFW_HAS_XRANDR*/
}
else if (_glfwLibrary.X11.VidMode.available)