PDA

View Full Version : Chaning X Video Modes



skw|d
09-27-2000, 03:12 AM
Has anyone messed with the XF86VIDMODE extensions? I can get a list of supported video modes from the X server, but XF86VidModeSwitchToMode() doesn't seem to work for me yet. Are there some docs out there that describe these functions besides the man pages, like source to a working program?

/skw|d

miq
09-27-2000, 07:24 AM
Hi skw|d,

it seems, that we both are trying to do similar thing at the moment http://www.opengl.org/discussion_boards/ubb/smile.gif. I think I have working mode-switch stuff. Here is comes the source:

XF86VidModeModeInfo deskMode;
XF86VidModeModeInfo **modes;
int modeNum;
int bestMode;

/* set bestMode to current mode */
bestMode = 0;
XF86VidModeGetAllModeLines(GLWin.dpy, GLWin.screen, &modeNum, &modes);
/* save desktop-resolution before switching modes */
deskMode = *modes[0];
/* look for mode with requested resolution */
for (i = 0; i < modeNum; i++)
{
if ((modes[i]->hdisplay == width) && (modes[i]->vdisplay == height))
{
bestMode = i;
}
}
/* switch to mode with requested resolution, if no matching mode was found, bestMode is 0 and the mode will not be switched */
XF86VidModeSwitchToMode(GLWin.dpy, GLWin.screen, modes[bestMode]);
/* set the viewport to upper left corner, where we let our fullscreen window appear, so that it fills the entire screen in the new resolution */
XF86VidModeSetViewPort(GLWin.dpy, GLWin.screen, 0, 0);
...
/* here you create the window with the resolution as width and height and let it appear in the upper left corner. To get input you perhaps would want to grab keyboard and pointer (confine the pointer to the fullscreenwindow is IMHO a good idea, because otherwise you can scroll around on the virtual desktop because the display size was not changed, only the screen resolution).*/
...
/* when you exit fullscreen mode you should restore the original resolution*/
XF86VidModeSwitchToMode(GLWin.dpy, GLWin.screen, &deskMode);
XF86VidModeSetViewPort(GLWin.dpy, GLWin.screen, 0, 0);

This works perfectly for me, although the code to find an apropriate mode is quite basic (it only gives you an exact match, not really the best available mode http://www.opengl.org/discussion_boards/ubb/frown.gif). I hope it works as a starting point for you too.
If you have any problems just tell me...

bxe Miq

skw|d
09-27-2000, 03:45 PM
Yeah, I have been messing with those functions to build a link list of display modes, though I was hoping to include bits-per-plane along with hdisplay and vdisplay. Looks like I will have to query each mode for the supported bit depth.

Thanks again for your post, you are doing some stuff that I had left out. Once I get this video mode / fullscreen source down, I am definitely going to save it for future projects.

Laters,
/skw|d