Simplified X11 screen handling.

This commit is contained in:
Camilla Berglund 2012-04-05 16:14:01 +02:00
parent 2753577dbd
commit 61264339a7
3 changed files with 52 additions and 35 deletions

View File

@ -42,7 +42,7 @@
// Finds the video mode closest in size to the specified desired size // Finds the video mode closest in size to the specified desired size
//======================================================================== //========================================================================
int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate) int _glfwGetClosestVideoMode(int* width, int* height, int* rate)
{ {
int i, match, bestmatch; int i, match, bestmatch;
@ -55,8 +55,7 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
XRRScreenConfiguration* sc; XRRScreenConfiguration* sc;
XRRScreenSize* sizelist; XRRScreenSize* sizelist;
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root);
RootWindow(_glfwLibrary.X11.display, screen));
sizelist = XRRConfigSizes(sc, &sizecount); sizelist = XRRConfigSizes(sc, &sizecount);
@ -116,7 +115,8 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
int bestmode, modecount; int bestmode, modecount;
// Get a list of all available display modes // Get a list of all available display modes
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen, XF86VidModeGetAllModeLines(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen,
&modecount, &modelist); &modecount, &modelist);
// Find the best matching mode // Find the best matching mode
@ -150,8 +150,8 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
} }
// Default: Simply use the screen resolution // Default: Simply use the screen resolution
*width = DisplayWidth(_glfwLibrary.X11.display, screen); *width = DisplayWidth(_glfwLibrary.X11.display, _glfwLibrary.X11.screen);
*height = DisplayHeight(_glfwLibrary.X11.display, screen); *height = DisplayHeight(_glfwLibrary.X11.display, _glfwLibrary.X11.screen);
return 0; return 0;
} }
@ -161,7 +161,7 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
// Change the current video mode // Change the current video mode
//======================================================================== //========================================================================
void _glfwSetVideoModeMODE(int screen, int mode, int rate) void _glfwSetVideoModeMODE(int mode, int rate)
{ {
if (_glfwLibrary.X11.RandR.available) if (_glfwLibrary.X11.RandR.available)
{ {
@ -169,15 +169,17 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate)
XRRScreenConfiguration* sc; XRRScreenConfiguration* sc;
Window root; Window root;
root = RootWindow(_glfwLibrary.X11.display, screen); root = _glfwLibrary.X11.root;
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, root); sc = XRRGetScreenInfo(_glfwLibrary.X11.display, root);
// Remember old size and flag that we have changed the mode // Remember old size and flag that we have changed the mode
if (!_glfwLibrary.X11.FS.modeChanged) if (!_glfwLibrary.X11.FS.modeChanged)
{ {
_glfwLibrary.X11.FS.oldSizeID = XRRConfigCurrentConfiguration(sc, &_glfwLibrary.X11.FS.oldRotation); _glfwLibrary.X11.FS.oldSizeID = XRRConfigCurrentConfiguration(sc, &_glfwLibrary.X11.FS.oldRotation);
_glfwLibrary.X11.FS.oldWidth = DisplayWidth(_glfwLibrary.X11.display, screen); _glfwLibrary.X11.FS.oldWidth = DisplayWidth(_glfwLibrary.X11.display,
_glfwLibrary.X11.FS.oldHeight = DisplayHeight(_glfwLibrary.X11.display, screen); _glfwLibrary.X11.screen);
_glfwLibrary.X11.FS.oldHeight = DisplayHeight(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen);
_glfwLibrary.X11.FS.modeChanged = GL_TRUE; _glfwLibrary.X11.FS.modeChanged = GL_TRUE;
} }
@ -214,21 +216,32 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate)
int modecount; int modecount;
// Get a list of all available display modes // Get a list of all available display modes
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen, XF86VidModeGetAllModeLines(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen,
&modecount, &modelist); &modecount, &modelist);
// Unlock mode switch if necessary // Unlock mode switch if necessary
if (_glfwLibrary.X11.FS.modeChanged) if (_glfwLibrary.X11.FS.modeChanged)
XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, screen, 0); {
XF86VidModeLockModeSwitch(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen,
0);
}
// Change the video mode to the desired mode // Change the video mode to the desired mode
XF86VidModeSwitchToMode(_glfwLibrary.X11.display, screen, modelist[mode]); XF86VidModeSwitchToMode(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen,
modelist[mode]);
// Set viewport to upper left corner (where our window will be) // Set viewport to upper left corner (where our window will be)
XF86VidModeSetViewPort(_glfwLibrary.X11.display, screen, 0, 0); XF86VidModeSetViewPort(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen,
0, 0);
// Lock mode switch // Lock mode switch
XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, screen, 1); XF86VidModeLockModeSwitch(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen,
1);
// Remember old mode and flag that we have changed the mode // Remember old mode and flag that we have changed the mode
if (!_glfwLibrary.X11.FS.modeChanged) if (!_glfwLibrary.X11.FS.modeChanged)
@ -247,15 +260,15 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate)
// Change the current video mode // Change the current video mode
//======================================================================== //========================================================================
void _glfwSetVideoMode(int screen, int* width, int* height, int* rate) void _glfwSetVideoMode(int* width, int* height, int* rate)
{ {
int bestmode; int bestmode;
// Find a best match mode // Find a best match mode
bestmode = _glfwGetClosestVideoMode(screen, width, height, rate); bestmode = _glfwGetClosestVideoMode(width, height, rate);
// Change mode // Change mode
_glfwSetVideoModeMODE(screen, bestmode, *rate); _glfwSetVideoModeMODE(bestmode, *rate);
} }
@ -263,7 +276,7 @@ void _glfwSetVideoMode(int screen, int* width, int* height, int* rate)
// Restore the previously saved (original) video mode // Restore the previously saved (original) video mode
//======================================================================== //========================================================================
void _glfwRestoreVideoMode(int screen) void _glfwRestoreVideoMode(void)
{ {
if (_glfwLibrary.X11.FS.modeChanged) if (_glfwLibrary.X11.FS.modeChanged)
{ {
@ -292,11 +305,13 @@ void _glfwRestoreVideoMode(int screen)
{ {
#if defined(_GLFW_HAS_XF86VIDMODE) #if defined(_GLFW_HAS_XF86VIDMODE)
// Unlock mode switch // Unlock mode switch
XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, screen, 0); XF86VidModeLockModeSwitch(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen,
0);
// Change the video mode back to the old mode // Change the video mode back to the old mode
XF86VidModeSwitchToMode(_glfwLibrary.X11.display, XF86VidModeSwitchToMode(_glfwLibrary.X11.display,
screen, _glfwLibrary.X11.screen,
&_glfwLibrary.X11.FS.oldMode); &_glfwLibrary.X11.FS.oldMode);
#endif /*_GLFW_HAS_XF86VIDMODE*/ #endif /*_GLFW_HAS_XF86VIDMODE*/
} }
@ -323,7 +338,7 @@ struct _glfwResolution
int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
{ {
int count, k, l, r, g, b, rgba, gl; int count, k, l, r, g, b, rgba, gl;
int depth, screen = DefaultScreen(_glfwLibrary.X11.display); int depth;
XVisualInfo* vislist; XVisualInfo* vislist;
XVisualInfo dummy; XVisualInfo dummy;
int viscount, rgbcount, rescount; int viscount, rgbcount, rescount;
@ -407,7 +422,9 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
XF86VidModeModeInfo** modelist; XF86VidModeModeInfo** modelist;
int modecount, width, height; int modecount, width, height;
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen, &modecount, &modelist); XF86VidModeGetAllModeLines(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen,
&modecount, &modelist);
resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * modecount); resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * modecount);
@ -440,8 +457,10 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
rescount = 1; rescount = 1;
resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * rescount); resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * rescount);
resarray[0].width = DisplayWidth(_glfwLibrary.X11.display, screen); resarray[0].width = DisplayWidth(_glfwLibrary.X11.display,
resarray[0].height = DisplayHeight(_glfwLibrary.X11.display, screen); _glfwLibrary.X11.screen);
resarray[0].height = DisplayHeight(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen);
} }
// Build permutations of colors and resolutions // Build permutations of colors and resolutions

View File

@ -250,10 +250,10 @@ GLFWGLOBAL struct {
void _glfwInitTimer(void); void _glfwInitTimer(void);
// Fullscreen support // Fullscreen support
int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate); int _glfwGetClosestVideoMode(int* width, int* height, int* rate);
void _glfwSetVideoModeMODE(int screen, int mode, int rate); void _glfwSetVideoModeMODE(int mode, int rate);
void _glfwSetVideoMode(int screen, int* width, int* height, int* rate); void _glfwSetVideoMode(int* width, int* height, int* rate);
void _glfwRestoreVideoMode(int screen); void _glfwRestoreVideoMode(void);
// Joystick input // Joystick input
void _glfwInitJoysticks(void); void _glfwInitJoysticks(void);

View File

@ -908,8 +908,7 @@ static void enterFullscreenMode(_GLFWwindow* window)
_glfwLibrary.X11.saver.changed = GL_TRUE; _glfwLibrary.X11.saver.changed = GL_TRUE;
} }
_glfwSetVideoMode(_glfwLibrary.X11.screen, _glfwSetVideoMode(&window->width, &window->height,
&window->width, &window->height,
&window->refreshRate); &window->refreshRate);
if (window->X11.hasEWMH && if (window->X11.hasEWMH &&
@ -989,7 +988,7 @@ static void enterFullscreenMode(_GLFWwindow* window)
static void leaveFullscreenMode(_GLFWwindow* window) static void leaveFullscreenMode(_GLFWwindow* window)
{ {
_glfwRestoreVideoMode(_glfwLibrary.X11.screen); _glfwRestoreVideoMode();
// Did we change the screen saver setting? // Did we change the screen saver setting?
if (_glfwLibrary.X11.saver.changed) if (_glfwLibrary.X11.saver.changed)
@ -1600,8 +1599,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
if (window->mode == GLFW_FULLSCREEN) if (window->mode == GLFW_FULLSCREEN)
{ {
// Get the closest matching video mode for the specified window size // Get the closest matching video mode for the specified window size
mode = _glfwGetClosestVideoMode(_glfwLibrary.X11.screen, mode = _glfwGetClosestVideoMode(&width, &height, &rate);
&width, &height, &rate);
} }
if (!window->resizable) if (!window->resizable)
@ -1628,7 +1626,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
if (window->mode == GLFW_FULLSCREEN) if (window->mode == GLFW_FULLSCREEN)
{ {
// Change video mode, keeping current refresh rate // Change video mode, keeping current refresh rate
_glfwSetVideoModeMODE(_glfwLibrary.X11.screen, mode, window->refreshRate); _glfwSetVideoModeMODE(mode, window->refreshRate);
} }
// Set window size (if not already changed) // Set window size (if not already changed)