From 747b6d880563c0461df028d9e287652f16de7b17 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sat, 12 Jan 2013 18:10:18 +0100 Subject: [PATCH] RandR and fallback path fixes. --- src/x11_init.c | 9 +++++++- src/x11_monitor.c | 56 +++++++++++++++++++++++++++-------------------- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/x11_init.c b/src/x11_init.c index ad4398ae..ffcb7195 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -492,7 +492,7 @@ static GLboolean initDisplay(void) _glfw.x11.vidmode.available = GL_FALSE; #endif /*_GLFW_HAS_XF86VIDMODE*/ - // Check for XRandR extension + // Check for RandR extension #ifdef _GLFW_HAS_XRANDR _glfw.x11.randr.available = XRRQueryExtension(_glfw.x11.display, @@ -509,6 +509,13 @@ static GLboolean initDisplay(void) "X11: Failed to query RandR version"); return GL_FALSE; } + + // The GLFW RandR path requires at least version 1.3 + if (_glfw.x11.randr.versionMajor == 1 && + _glfw.x11.randr.versionMinor < 3) + { + _glfw.x11.randr.available = GL_FALSE; + } } #else _glfw.x11.randr.available = GL_FALSE; diff --git a/src/x11_monitor.c b/src/x11_monitor.c index c66ec819..3cee50d6 100644 --- a/src/x11_monitor.c +++ b/src/x11_monitor.c @@ -192,11 +192,12 @@ void _glfwRestoreVideoMode(_GLFWmonitor* monitor) // Return a list of available monitors //======================================================================== -_GLFWmonitor** _glfwPlatformGetMonitors(int* count) +_GLFWmonitor** _glfwPlatformGetMonitors(int* found) { - int found = 0; _GLFWmonitor** monitors = NULL; + *found = 0; + if (_glfw.x11.randr.available) { #if defined (_GLFW_HAS_XRANDR) @@ -221,7 +222,6 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) { XRROutputInfo* oi; XRRCrtcInfo* ci; - int widthMM, heightMM; oi = XRRGetOutputInfo(_glfw.x11.display, sr, sr->outputs[i]); if (oi->connection != RR_Connected) @@ -230,40 +230,49 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) continue; } - if (oi->mm_width && oi->mm_height) - { - widthMM = oi->mm_width; - heightMM = oi->mm_height; - } - else - { - widthMM = DisplayWidthMM(_glfw.x11.display, _glfw.x11.screen); - heightMM = DisplayHeightMM(_glfw.x11.display, _glfw.x11.screen); - } - ci = XRRGetCrtcInfo(_glfw.x11.display, sr, oi->crtc); - monitors[found] = _glfwCreateMonitor(oi->name, - sr->outputs[i] == primary, - widthMM, heightMM, - ci->x, ci->y); + monitors[*found] = _glfwCreateMonitor(oi->name, + sr->outputs[i] == primary, + oi->mm_width, oi->mm_height, + ci->x, ci->y); XRRFreeCrtcInfo(ci); - if (!monitors[found]) + if (!monitors[*found]) { // TODO: wat return NULL; } // This is retained until the monitor object is destroyed - monitors[found]->x11.output = oi; - found++; + monitors[*found]->x11.output = oi; + (*found)++; } #endif /*_GLFW_HAS_XRANDR*/ } + else + { + int widthMM, heightMM; + + monitors = (_GLFWmonitor**) calloc(1, sizeof(_GLFWmonitor*)); + if (!monitors) + { + _glfwInputError(GLFW_OUT_OF_MEMORY, NULL); + return NULL; + } + + widthMM = DisplayWidthMM(_glfw.x11.display, _glfw.x11.screen); + heightMM = DisplayHeightMM(_glfw.x11.display, _glfw.x11.screen); + + monitors[0] = _glfwCreateMonitor("Display", + GL_TRUE, + widthMM, heightMM, + 0, 0); + + *found = 1; + } - *count = found; return monitors; } @@ -356,8 +365,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) XRRFreeScreenResources(sr); #endif /*_GLFW_HAS_XRANDR*/ } - - if (result == NULL) + else { *found = 1;