diff --git a/src/x11_gamma.c b/src/x11_gamma.c index fe02a939..04280a06 100644 --- a/src/x11_gamma.c +++ b/src/x11_gamma.c @@ -31,6 +31,66 @@ #include #include +#include + + +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + +//======================================================================== +// Detect gamma ramp support and save original gamma ramp, if available +//======================================================================== + +void _glfwInitGammaRamp(void) +{ +#ifdef _GLFW_HAS_XRANDR + // RandR gamma support is only available with version 1.2 and above + if (_glfwLibrary.X11.RandR.available && + (_glfwLibrary.X11.RandR.majorVersion > 1 || + (_glfwLibrary.X11.RandR.majorVersion == 1 && + _glfwLibrary.X11.RandR.minorVersion >= 2))) + { + // FIXME: Assumes that all monitors have the same size gamma tables + // This is reasonable as I suspect the that if they did differ, it + // would imply that setting the gamma size to an arbitary size is + // possible as well. + XRRScreenResources* rr = XRRGetScreenResources(_glfwLibrary.X11.display, + _glfwLibrary.X11.root); + + _glfwLibrary.originalRampSize = XRRGetCrtcGammaSize(_glfwLibrary.X11.display, + rr->crtcs[0]); + if (!_glfwLibrary.originalRampSize) + { + // This is probably Nvidia RandR with broken gamma support + // Flag it as useless and try Xf86VidMode below, if available + _glfwLibrary.X11.RandR.gammaBroken = GL_TRUE; + fprintf(stderr, + "Ignoring broken nVidia implementation of RandR 1.2+ gamma\n"); + } + + XRRFreeScreenResources(rr); + } +#endif /*_GLFW_HAS_XRANDR*/ + +#if defined(_GLFW_HAS_XF86VIDMODE) + if (_glfwLibrary.X11.VidMode.available && + !_glfwLibrary.originalRampSize) + { + // Get the gamma size using XF86VidMode + XF86VidModeGetGammaRampSize(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, + &_glfwLibrary.originalRampSize); + } +#endif /*_GLFW_HAS_XF86VIDMODE*/ + + if (!_glfwLibrary.originalRampSize) + fprintf(stderr, "No supported gamma ramp API found\n"); + + // Save the original gamma ramp + _glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp); + _glfwLibrary.currentRamp = _glfwLibrary.originalRamp; +} ////////////////////////////////////////////////////////////////////////// diff --git a/src/x11_init.c b/src/x11_init.c index d59fbcc6..6ea80351 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -30,7 +30,6 @@ #include "internal.h" -#include #include #include #include @@ -621,61 +620,6 @@ static GLboolean initDisplay(void) } -//======================================================================== -// Detect gamma ramp support and save original gamma ramp, if available -//======================================================================== - -static void initGammaRamp(void) -{ -#ifdef _GLFW_HAS_XRANDR - // RandR gamma support is only available with version 1.2 and above - if (_glfwLibrary.X11.RandR.available && - (_glfwLibrary.X11.RandR.majorVersion > 1 || - (_glfwLibrary.X11.RandR.majorVersion == 1 && - _glfwLibrary.X11.RandR.minorVersion >= 2))) - { - // FIXME: Assumes that all monitors have the same size gamma tables - // This is reasonable as I suspect the that if they did differ, it - // would imply that setting the gamma size to an arbitary size is - // possible as well. - XRRScreenResources* rr = XRRGetScreenResources(_glfwLibrary.X11.display, - _glfwLibrary.X11.root); - - _glfwLibrary.originalRampSize = XRRGetCrtcGammaSize(_glfwLibrary.X11.display, - rr->crtcs[0]); - if (!_glfwLibrary.originalRampSize) - { - // This is probably Nvidia RandR with broken gamma support - // Flag it as useless and try Xf86VidMode below, if available - _glfwLibrary.X11.RandR.gammaBroken = GL_TRUE; - fprintf(stderr, - "Ignoring broken nVidia implementation of RandR 1.2+ gamma\n"); - } - - XRRFreeScreenResources(rr); - } -#endif /*_GLFW_HAS_XRANDR*/ - -#if defined(_GLFW_HAS_XF86VIDMODE) - if (_glfwLibrary.X11.VidMode.available && - !_glfwLibrary.originalRampSize) - { - // Get the gamma size using XF86VidMode - XF86VidModeGetGammaRampSize(_glfwLibrary.X11.display, - _glfwLibrary.X11.screen, - &_glfwLibrary.originalRampSize); - } -#endif /*_GLFW_HAS_XF86VIDMODE*/ - - if (!_glfwLibrary.originalRampSize) - fprintf(stderr, "No supported gamma ramp API found\n"); - - // Save the original gamma ramp - _glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp); - _glfwLibrary.currentRamp = _glfwLibrary.originalRamp; -} - - //======================================================================== // Create a blank cursor (for locked mouse mode) //======================================================================== @@ -739,7 +683,7 @@ int _glfwPlatformInit(void) if (!initDisplay()) return GL_FALSE; - initGammaRamp(); + _glfwInitGammaRamp(); initEWMH(); diff --git a/src/x11_platform.h b/src/x11_platform.h index 013ca4e0..e4fbfe08 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -283,6 +283,9 @@ GLFWGLOBAL struct { // Time void _glfwInitTimer(void); +// Gamma +void _glfwInitGammaRamp(void); + // Fullscreen support int _glfwGetClosestVideoMode(int* width, int* height, int* rate); void _glfwSetVideoModeMODE(int mode, int rate);