void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) { if (_glfw.x11.randr.available) { XRRScreenResources* sr; XRRCrtcInfo* ci; sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root); ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); mode->width = ci->width; mode->height = ci->height; mode->refreshRate = calculateRefreshRate(getModeInfo(sr, ci->mode)); XRRFreeCrtcInfo(ci); XRRFreeScreenResources(sr); } else { mode->width = DisplayWidth(_glfw.x11.display, _glfw.x11.screen); mode->height = DisplayHeight(_glfw.x11.display, _glfw.x11.screen); mode->refreshRate = 0; } _glfwSplitBPP(DefaultDepth(_glfw.x11.display, _glfw.x11.screen), &mode->redBits, &mode->greenBits, &mode->blueBits); }
// Convert RandR mode info to GLFW video mode // static GLFWvidmode vidmodeFromModeInfo(const XRRModeInfo* mi) { GLFWvidmode mode; mode.width = mi->width; mode.height = mi->height; mode.refreshRate = calculateRefreshRate(mi); _glfwSplitBPP(DefaultDepth(_glfw.x11.display, _glfw.x11.screen), &mode.redBits, &mode.greenBits, &mode.blueBits); return mode; }
// Set the current video mode for the specified monitor // void _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired) { if (_glfw.x11.randr.available) { int i; XRRScreenResources* sr; XRRCrtcInfo* ci; RRMode bestMode = 0; unsigned int leastSizeDiff = UINT_MAX, leastRateDiff = UINT_MAX; sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root); ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); for (i = 0; i < sr->nmode; i++) { XRRModeInfo* mi = sr->modes + i; if (mi->modeFlags & RR_Interlace) continue; const unsigned int sizeDiff = (mi->width - desired->width) * (mi->width - desired->width) + (mi->height - desired->height) * (mi->height - desired->height); const unsigned int rateDiff = abs(calculateRefreshRate(mi) - desired->refreshRate); if ((sizeDiff < leastSizeDiff) || (sizeDiff == leastSizeDiff && rateDiff < leastRateDiff)) { bestMode = mi->id; leastSizeDiff = sizeDiff; leastRateDiff = rateDiff; } } monitor->x11.oldMode = ci->mode; XRRSetCrtcConfig(_glfw.x11.display, sr, monitor->x11.crtc, CurrentTime, ci->x, ci->y, bestMode, ci->rotation, ci->outputs, ci->noutput); XRRFreeCrtcInfo(ci); XRRFreeScreenResources(sr); } }
// Convert RandR mode info to GLFW video mode // static GLFWvidmode vidmodeFromModeInfo(const XRRModeInfo* mi, const XRRCrtcInfo* ci) { GLFWvidmode mode; if (ci->rotation == RR_Rotate_90 || ci->rotation == RR_Rotate_270) { mode.width = mi->height; mode.height = mi->width; } else { mode.width = mi->width; mode.height = mi->height; } mode.refreshRate = calculateRefreshRate(mi); _glfwSplitBPP(DefaultDepth(_glfw.x11.display, _glfw.x11.screen), &mode.redBits, &mode.greenBits, &mode.blueBits); return mode; }
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) { GLFWvidmode* result; int depth, r, g, b; depth = DefaultDepth(_glfw.x11.display, _glfw.x11.screen); _glfwSplitBPP(depth, &r, &g, &b); *found = 0; // Build array of available resolutions if (_glfw.x11.randr.available) { int i, j; XRRScreenResources* sr; XRROutputInfo* oi; sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root); oi = XRRGetOutputInfo(_glfw.x11.display, sr, monitor->x11.output); result = calloc(oi->nmode, sizeof(GLFWvidmode)); for (i = 0; i < oi->nmode; i++) { GLFWvidmode mode; const XRRModeInfo* mi = getModeInfo(sr, oi->modes[i]); mode.width = mi->width; mode.height = mi->height; mode.refreshRate = calculateRefreshRate(mi); for (j = 0; j < *found; j++) { if (result[j].width == mode.width && result[j].height == mode.height && result[j].refreshRate == mode.refreshRate) { break; } } if (j < *found) { // This is a duplicate, so skip it continue; } mode.redBits = r; mode.greenBits = g; mode.blueBits = b; result[*found] = mode; (*found)++; } XRRFreeOutputInfo(oi); XRRFreeScreenResources(sr); } else { *found = 1; result = calloc(1, sizeof(GLFWvidmode)); result[0].width = DisplayWidth(_glfw.x11.display, _glfw.x11.screen); result[0].height = DisplayHeight(_glfw.x11.display, _glfw.x11.screen); result[0].redBits = r; result[0].greenBits = g; result[0].blueBits = b; result[0].refreshRate = 0; } return result; }