Adam Nielsen wrote:

> Please let me know if anyone knows how to change X11 screen resolutions
> without closing down everything and restarting.

The following uses XFree86-VidModeExtension:

/* make xvidmode CFLAGS='-Wall' LDFLAGS='-L/usr/X11R6/lib' LDLIBS='-lX11 
-lXxf86vm -lXext' */

#include <X11/Xlib.h>
#include <X11/extensions/xf86vmode.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char **argv)
{
        Display *dpy;
        int num_modes;
        XF86VidModeModeInfo **modes;
        int width, height;
        int i;
        XF86VidModeModeInfo *best_mode = NULL;

        if (argc != 3) {
                fprintf(stderr, "Usage: %s <width> <height>\n", argv[0]);
                return 1;
        }

        width  = atoi(argv[1]);
        height = atoi(argv[2]);

        dpy = XOpenDisplay(NULL);
        if (!dpy) {
                fprintf(stderr, "Unable to open display\n");
                return 1;
        }

        if (!XF86VidModeGetAllModeLines(dpy, DefaultScreen(dpy), &num_modes, 
&modes)) {
                fprintf(stderr, "Unable to query modes\n");
                return 1;
        }

        for (i = 0; i < num_modes; i++) {
                XF86VidModeModeInfo *mode = modes[i];
                if (mode->hdisplay < width || mode->vdisplay < height)
                        continue;
                if (best_mode && (mode->hdisplay > best_mode->hdisplay || 
mode->vdisplay > best_mode->vdisplay))
                        continue;
                best_mode = mode;
        }
        
        if (!best_mode) {
                fprintf(stderr, "Unable to find a suitable mode\n");
                return 1;
        }

        XWarpPointer(dpy, None, DefaultRootWindow(dpy), 0, 0, 0, 0, 0, 0);
        XF86VidModeSwitchToMode(dpy, DefaultScreen(dpy), best_mode);
        XF86VidModeSetViewPort(dpy, DefaultScreen(dpy), 0, 0);
        XFree(modes);
        XCloseDisplay(dpy);

        return 0;
}

-- 
Glynn Clements <[email protected]>
_______________________________________________
xorg mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/xorg

Reply via email to