mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 04:54:35 +00:00
RandR and VidMode cleanup and formatting.
This commit is contained in:
parent
63a5e9a3de
commit
26aaf55872
@ -51,15 +51,15 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
|
||||
short* ratelist;
|
||||
XRRScreenConfiguration* sc;
|
||||
XRRScreenSize* sizelist;
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XRANDR*/
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
XF86VidModeModeInfo** modelist;
|
||||
int bestmode, modecount;
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
||||
|
||||
#if defined(_GLFW_HAS_XRANDR)
|
||||
if (_glfwLibrary.X11.RandR.available)
|
||||
{
|
||||
#if defined(_GLFW_HAS_XRANDR)
|
||||
sc = XRRGetScreenInfo(_glfwLibrary.X11.display,
|
||||
RootWindow(_glfwLibrary.X11.display, screen));
|
||||
|
||||
@ -113,14 +113,11 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
|
||||
|
||||
if (bestsize != -1)
|
||||
return bestsize;
|
||||
#endif /*_GLFW_HAS_XRANDR*/
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
// Use the XF86VidMode extension to control video resolution
|
||||
if (_glfwLibrary.X11.VidMode.available &&
|
||||
!_glfwLibrary.X11.RandR.available)
|
||||
else if (_glfwLibrary.X11.VidMode.available)
|
||||
{
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
// Get a list of all available display modes
|
||||
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen,
|
||||
&modecount, &modelist);
|
||||
@ -153,8 +150,8 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
|
||||
|
||||
if (bestmode != -1)
|
||||
return bestmode;
|
||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
||||
}
|
||||
#endif
|
||||
|
||||
// Default: Simply use the screen resolution
|
||||
*width = DisplayWidth(_glfwLibrary.X11.display, screen);
|
||||
@ -173,15 +170,15 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate)
|
||||
#if defined(_GLFW_HAS_XRANDR)
|
||||
XRRScreenConfiguration* sc;
|
||||
Window root;
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XRANDR*/
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
XF86VidModeModeInfo **modelist;
|
||||
int modecount;
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
||||
|
||||
#if defined(_GLFW_HAS_XRANDR)
|
||||
if (_glfwLibrary.X11.RandR.available)
|
||||
{
|
||||
#if defined(_GLFW_HAS_XRANDR)
|
||||
root = RootWindow(_glfwLibrary.X11.display, screen);
|
||||
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, root);
|
||||
|
||||
@ -218,14 +215,11 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate)
|
||||
}
|
||||
|
||||
XRRFreeScreenConfigInfo(sc);
|
||||
#endif /*_GLFW_HAS_XRANDR*/
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
// Use the XF86VidMode extension to control video resolution
|
||||
if (_glfwLibrary.X11.VidMode.available &&
|
||||
!_glfwLibrary.X11.RandR.available)
|
||||
else if (_glfwLibrary.X11.VidMode.available)
|
||||
{
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
// Get a list of all available display modes
|
||||
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen,
|
||||
&modecount, &modelist);
|
||||
@ -253,8 +247,8 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate)
|
||||
|
||||
// Free mode list
|
||||
XFree(modelist);
|
||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -282,9 +276,9 @@ void _glfwRestoreVideoMode(int screen)
|
||||
{
|
||||
if (_glfwLibrary.X11.FS.modeChanged)
|
||||
{
|
||||
#if defined(_GLFW_HAS_XRANDR)
|
||||
if (_glfwLibrary.X11.RandR.available)
|
||||
{
|
||||
#if defined(_GLFW_HAS_XRANDR)
|
||||
XRRScreenConfiguration* sc;
|
||||
|
||||
if (_glfwLibrary.X11.RandR.available)
|
||||
@ -301,12 +295,11 @@ void _glfwRestoreVideoMode(int screen)
|
||||
|
||||
XRRFreeScreenConfigInfo(sc);
|
||||
}
|
||||
#endif /*_GLFW_HAS_XRANDR*/
|
||||
}
|
||||
#endif
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
if (_glfwLibrary.X11.VidMode.available &&
|
||||
!_glfwLibrary.X11.RandR.available)
|
||||
else if (_glfwLibrary.X11.VidMode.available)
|
||||
{
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
// Unlock mode switch
|
||||
XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, screen, 0);
|
||||
|
||||
@ -314,8 +307,8 @@ void _glfwRestoreVideoMode(int screen)
|
||||
XF86VidModeSwitchToMode(_glfwLibrary.X11.display,
|
||||
screen,
|
||||
&_glfwLibrary.X11.FS.oldMode);
|
||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
||||
}
|
||||
#endif
|
||||
|
||||
_glfwLibrary.X11.FS.modeChanged = GL_FALSE;
|
||||
}
|
||||
@ -349,11 +342,11 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
XRRScreenConfiguration* sc;
|
||||
XRRScreenSize* sizelist;
|
||||
int sizecount;
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XRANDR*/
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
XF86VidModeModeInfo** modelist;
|
||||
int modecount, width, height;
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
||||
|
||||
// Get list of visuals
|
||||
vislist = XGetVisualInfo(_glfwLibrary.X11.display, 0, &dummy, &viscount);
|
||||
@ -400,9 +393,10 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
resarray = NULL;
|
||||
|
||||
// Build resolution array
|
||||
#if defined(_GLFW_HAS_XRANDR)
|
||||
|
||||
if (_glfwLibrary.X11.RandR.available)
|
||||
{
|
||||
#if defined(_GLFW_HAS_XRANDR)
|
||||
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root);
|
||||
sizelist = XRRConfigSizes(sc, &sizecount);
|
||||
|
||||
@ -416,13 +410,11 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
}
|
||||
|
||||
XRRFreeScreenConfigInfo(sc);
|
||||
#endif /*_GLFW_HAS_XRANDR*/
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
if (_glfwLibrary.X11.VidMode.available &&
|
||||
!_glfwLibrary.X11.RandR.available)
|
||||
else if (_glfwLibrary.X11.VidMode.available)
|
||||
{
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen, &modecount, &modelist);
|
||||
|
||||
resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * modecount);
|
||||
@ -448,8 +440,8 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
}
|
||||
|
||||
XFree(modelist);
|
||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!resarray)
|
||||
{
|
||||
@ -495,7 +487,7 @@ void _glfwPlatformGetDesktopMode(GLFWvidmode* mode)
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
XF86VidModeModeInfo** modelist;
|
||||
int modecount;
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
||||
|
||||
// Get display depth
|
||||
bpp = DefaultDepth(_glfwLibrary.X11.display, screen);
|
||||
@ -503,46 +495,27 @@ void _glfwPlatformGetDesktopMode(GLFWvidmode* mode)
|
||||
// Convert BPP to RGB bits
|
||||
_glfwSplitBPP(bpp, &mode->redBits, &mode->greenBits, &mode->blueBits);
|
||||
|
||||
#if defined(_GLFW_HAS_XRANDR)
|
||||
if (_glfwLibrary.X11.RandR.available)
|
||||
if (_glfwLibrary.X11.FS.modeChanged)
|
||||
{
|
||||
if (_glfwLibrary.X11.FS.modeChanged)
|
||||
if (_glfwLibrary.X11.RandR.available)
|
||||
{
|
||||
#if defined(_GLFW_HAS_XRANDR)
|
||||
mode->width = _glfwLibrary.X11.FS.oldWidth;
|
||||
mode->height = _glfwLibrary.X11.FS.oldHeight;
|
||||
return;
|
||||
#endif /*_GLFW_HAS_XRANDR*/
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
if (_glfwLibrary.X11.VidMode.available &&
|
||||
!_glfwLibrary.X11.RandR.available)
|
||||
{
|
||||
if (_glfwLibrary.X11.FS.modeChanged)
|
||||
else if (_glfwLibrary.X11.VidMode.available)
|
||||
{
|
||||
// The old (desktop) mode is stored in _glfwWin.FS.oldMode
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
mode->width = _glfwLibrary.X11.FS.oldMode.hdisplay;
|
||||
mode->height = _glfwLibrary.X11.FS.oldMode.vdisplay;
|
||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use the XF86VidMode extension to get list of video modes
|
||||
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen, &modecount, &modelist);
|
||||
|
||||
// The first mode in the list is the current (desktio) mode
|
||||
mode->width = modelist[0]->hdisplay;
|
||||
mode->height = modelist[0]->vdisplay;
|
||||
|
||||
// Free list
|
||||
XFree(modelist);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Get current display width and height
|
||||
mode->width = DisplayWidth(_glfwLibrary.X11.display, screen);
|
||||
mode->height = DisplayHeight(_glfwLibrary.X11.display, screen);
|
||||
else
|
||||
{
|
||||
mode->width = DisplayWidth(_glfwLibrary.X11.display, screen);
|
||||
mode->height = DisplayHeight(_glfwLibrary.X11.display, screen);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp)
|
||||
XRRFreeGamma(gamma);
|
||||
XRRFreeScreenResources(rr);
|
||||
}
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XRANDR*/
|
||||
else if (_glfwLibrary.X11.VidMode.available)
|
||||
{
|
||||
#if defined (_GLFW_HAS_XF86VIDMODE)
|
||||
@ -72,7 +72,7 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp)
|
||||
ramp->red,
|
||||
ramp->green,
|
||||
ramp->blue);
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp)
|
||||
|
||||
XRRFreeScreenResources(rr);
|
||||
}
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XRANDR*/
|
||||
else if (_glfwLibrary.X11.VidMode.available)
|
||||
{
|
||||
#if defined (_GLFW_HAS_XF86VIDMODE)
|
||||
@ -118,7 +118,7 @@ void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp)
|
||||
(unsigned short*) ramp->red,
|
||||
(unsigned short*) ramp->green,
|
||||
(unsigned short*) ramp->blue);
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ static GLboolean initDisplay(void)
|
||||
&_glfwLibrary.X11.VidMode.errorBase);
|
||||
#else
|
||||
_glfwLibrary.X11.VidMode.available = GL_FALSE;
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
||||
|
||||
// Check for XRandR extension
|
||||
#ifdef _GLFW_HAS_XRANDR
|
||||
@ -107,7 +107,7 @@ static GLboolean initDisplay(void)
|
||||
}
|
||||
#else
|
||||
_glfwLibrary.X11.RandR.available = GL_FALSE;
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XRANDR*/
|
||||
|
||||
// Check if GLX is supported on this display
|
||||
if (!glXQueryExtension(_glfwLibrary.X11.display, NULL, NULL))
|
||||
@ -162,7 +162,7 @@ static void initGammaRamp(void)
|
||||
|
||||
XRRFreeScreenResources(rr);
|
||||
}
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XRANDR*/
|
||||
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
if (_glfwLibrary.X11.VidMode.available &&
|
||||
@ -173,7 +173,7 @@ static void initGammaRamp(void)
|
||||
_glfwLibrary.X11.screen,
|
||||
&_glfwLibrary.originalRampSize);
|
||||
}
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
||||
|
||||
if (!_glfwLibrary.originalRampSize)
|
||||
fprintf(stderr, "Gamma ramp setting unsupported\n");
|
||||
|
@ -1380,7 +1380,7 @@ static void processSingleEvent(void)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XRANDR*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1444,7 +1444,8 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
window->X11.handle,
|
||||
RRScreenChangeNotifyMask);
|
||||
}
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XRANDR*/
|
||||
|
||||
enterFullscreenMode(window);
|
||||
}
|
||||
|
||||
@ -1670,12 +1671,12 @@ void _glfwPlatformRefreshWindowParams(void)
|
||||
GLXFBConfig* fbconfig;
|
||||
#if defined(_GLFW_HAS_XRANDR)
|
||||
XRRScreenConfiguration* sc;
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XRANDR*/
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
XF86VidModeModeLine modeline;
|
||||
int dotclock;
|
||||
float pixels_per_second, pixels_per_frame;
|
||||
#endif
|
||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
||||
_GLFWwindow* window = _glfwLibrary.currentWindow;
|
||||
|
||||
int attribs[] = { GLX_FBCONFIG_ID, window->GLX.fbconfigID, None };
|
||||
@ -1734,26 +1735,25 @@ void _glfwPlatformRefreshWindowParams(void)
|
||||
window->refreshRate = 0;
|
||||
|
||||
// Retrieve refresh rate if possible
|
||||
#if defined(_GLFW_HAS_XRANDR)
|
||||
if (_glfwLibrary.X11.RandR.available)
|
||||
{
|
||||
#if defined(_GLFW_HAS_XRANDR)
|
||||
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root);
|
||||
window->refreshRate = XRRConfigCurrentRate(sc);
|
||||
XRRFreeScreenConfigInfo(sc);
|
||||
#endif /*_GLFW_HAS_XRANDR*/
|
||||
}
|
||||
#endif
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
if (_glfwLibrary.X11.VidMode.available &&
|
||||
!_glfwLibrary.X11.RandR.available)
|
||||
else if (_glfwLibrary.X11.VidMode.available)
|
||||
{
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
// Use the XF86VidMode extension to get current video mode
|
||||
XF86VidModeGetModeLine(_glfwLibrary.X11.display, _glfwLibrary.X11.screen,
|
||||
&dotclock, &modeline);
|
||||
pixels_per_second = 1000.0f * (float) dotclock;
|
||||
pixels_per_frame = (float) modeline.htotal * modeline.vtotal;
|
||||
window->refreshRate = (int)(pixels_per_second/pixels_per_frame+0.5);
|
||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
||||
}
|
||||
#endif
|
||||
|
||||
XFree(fbconfig);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user