I'm working on changing resolutions in Linux under X. Now, I've figured out (with help) how to change the resolution in X. My issue is, I want to poll the resolution the user currently has so I can return to it when all is said and done.
However, I keep getting segmentation faults. I know that the change resolution code works, what's a problem is retaining the old mode and using it (it keeps complaining about incompatible pointer types).
Can someone help?
Code, information, and output below.
///////XFree Info/////////////////////// # XFree86 -version
XFree86 Version 4.3.0 (Red Hat Linux release: 4.3.0-2) Release Date: 27 February 2003 X Protocol Version 11, Revision 0, Release 6.6 Build Operating System: Linux 2.4.20-3bigmem i686 [ELF] Build Date: 27 February 2003 Build Host: porky.devel.redhat.com
Before reporting problems, check http://www.XFree86.Org/
to make sure that you have the latest version.
Module Loader present
OS Kernel: Linux version 2.4.20-8 ([EMAIL PROTECTED]) (gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) #1 Thu Mar 13 17:54:28 EST 2003
///////Compiler Output//////////////////
# gcc -o screen screen.c -L/usr/X11R6/lib -lX11 -lXext -lXxf86vm
screen.c: In function `changeResolution':
screen.c:45: warning: passing arg 4 of `XF86VidModeGetModeLine' from incompatible pointer type
screen.c: In function `changeResBack':
screen.c:70: warning: passing arg 3 of `XF86VidModeSwitchToMode' from incompatible pointer type
screen.c:71: warning: passing arg 3 of `XF86VidModeSwitchToMode' from incompatible pointer type
///////Execution Output////////////////// # ./screen VidMode Extension version 2.2 Segmentation fault
///////Program Code/////////////////////// #include <X11/X.h> #include <X11/Xlib.h> #include <X11/extensions/xf86vmode.h> #include <stdio.h> #include <string.h>
/* The documentation says that XF86VidModeModeInfo wants a double * pointer. But the function definition says that it wants a triple * pointer. So, we declare a double and pass the address * XF86VidModeModeInfo **modes; */
XF86VidModeModeInfo **modes; XF86VidModeModeInfo **oldMode;
Display *dpy;
int changeResolution( int horRes, int verRes )
{
unsigned int ver, rev, eventB, errorB, reqB, h, v, ht,vt;
char *displayname = NULL;int i,j; int modecount, dotclock;
if(!(dpy = XOpenDisplay(displayname))) {
fprintf(stderr, "xvidmode: Unable to open display %s\n",
(displayname != NULL) ? displayname : XDisplayName(NULL));
exit(-1);
}if (XF86VidModeQueryExtension(dpy,&eventB, &errorB))
{
XF86VidModeQueryVersion(dpy, &ver, &rev);
fprintf(stderr, "VidMode Extension version %i.%i\n", ver, rev);
}
else
{
fprintf(stderr,"xvidmode: No VidMode Extension on %s\n",
(displayname != NULL) ? displayname : XDisplayName(NULL));
exit(0);
}/* Added line here. This grabs the current video mode to be switched * back to when the time comes. */
XF86VidModeGetModeLine(dpy, 0, &dotclock, &modes);
/* Assigns to global the current video mode. */
**oldMode = **modes;
XF86VidModeGetAllModeLines(dpy,0,&modecount, &modes);
j=0;
for (i=0; i {
if ( ((*modes).hdisplay== horRes ) && ((*modes[i]).vdisplay== verRes) )
j=i;
}/* I don't know why this call needs to be made twice to actually * work, but a single call doesn't do anything. */ XF86VidModeSwitchToMode(dpy,0,modes[j]); XF86VidModeSwitchToMode(dpy,0,modes[j]);
free(modes); }
void changeResBack()
{
XF86VidModeSwitchToMode(dpy,0,oldMode);
XF86VidModeSwitchToMode(dpy,0,oldMode);free(oldMode); }
int main()
{
changeResolution( 640, 480 );
int i;
while ( i < 1000000 )
i++;
changeResBack();return 1; }
_______________________________________________ XFree86 mailing list [EMAIL PROTECTED] http://XFree86.Org/mailman/listinfo/xfree86

