1 /* test-xinerama.c --- playing with XF86VidModeGetViewPort
2 * xscreensaver, Copyright (c) 2004 Jamie Zawinski <jwz@jwz.org>
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation. No representations are made about the suitability of this
9 * software for any purpose. It is provided "as is" without express or
27 #include <X11/Xatom.h>
28 #include <X11/Intrinsic.h>
30 #include <X11/Xproto.h>
31 #include <X11/extensions/xf86vmode.h>
32 #include <X11/extensions/Xinerama.h>
35 char *progclass = "XScreenSaver";
41 time_t now = time ((time_t *) 0);
42 char *ct = (char *) ctime (&now);
43 int n = strlen(progname);
45 strncpy(buf, progname, n);
48 strncpy(buf+n, ct+11, 8);
49 strcpy(buf+n+9, ": ");
55 screen_count (Display *dpy)
57 int n = ScreenCount(dpy);
59 int event_number, error_number;
61 if (!XineramaQueryExtension (dpy, &event_number, &error_number))
63 fprintf(stderr, "%s: XineramaQueryExtension(dpy, ...) ==> False\n",
68 fprintf(stderr, "%s: XineramaQueryExtension(dpy, ...) ==> %d, %d\n",
69 blurb(), event_number, error_number);
71 if (!XineramaIsActive(dpy))
73 fprintf(stderr, "%s: XineramaIsActive(dpy) ==> False\n",
80 XineramaScreenInfo *xsi;
81 fprintf(stderr, "%s: XineramaIsActive(dpy) ==> True\n",
83 if (!XineramaQueryVersion(dpy, &major, &minor))
86 "%s: XineramaQueryVersion(dpy, ...) ==> False\n",
92 "%s: XineramaQueryVersion(dpy, ...) ==> %d, %d\n",
93 blurb(), major, minor);
95 xsi = XineramaQueryScreens (dpy, &xn);
100 fprintf (stderr, "\n");
101 fprintf (stderr, "%s: X client screens: %d\n", blurb(), n);
102 fprintf (stderr, "%s: Xinerama screens: %d\n", blurb(), xn);
103 fprintf (stderr, "\n");
105 if (xn > n) return xn;
111 main (int argc, char **argv)
113 int event_number, error_number;
119 Widget toplevel_shell = XtAppInitialize (&app, progclass, 0, 0,
120 &argc, argv, 0, 0, 0);
121 Display *dpy = XtDisplay (toplevel_shell);
122 XtGetApplicationNameAndClass (dpy, &progname, &progclass);
124 if (!XF86VidModeQueryExtension(dpy, &event_number, &error_number))
126 fprintf(stderr, "%s: XF86VidModeQueryExtension(dpy, ...) ==> False\n",
129 "%s: server does not support the XF86VidMode extension.\n",
134 fprintf(stderr, "%s: XF86VidModeQueryExtension(dpy, ...) ==> %d, %d\n",
135 blurb(), event_number, error_number);
137 if (!XF86VidModeQueryVersion(dpy, &major, &minor))
139 fprintf(stderr, "%s: XF86VidModeQueryVersion(dpy, ...) ==> False\n",
142 "%s: server didn't report XF86VidMode version numbers?\n",
146 fprintf(stderr, "%s: XF86VidModeQueryVersion(dpy, ...) ==> %d, %d\n",
147 blurb(), major, minor);
149 nscreens = screen_count (dpy);
151 for (i = 0; i < nscreens; i++)
154 int x = 0, y = 0, dot = 0;
155 XF86VidModeModeLine ml = { 0, };
157 result = XF86VidModeGetViewPort (dpy, i, &x, &y);
159 fprintf(stderr, "%s: XF86VidModeGetViewPort(dpy, %d, ...) ==> %d\n",
162 result = XF86VidModeGetModeLine (dpy, i, &dot, &ml);
164 fprintf(stderr, "%s: XF86VidModeGetModeLine(dpy, %d, ...) ==> %d\n",
167 fprintf (stderr, "%s: screen %d: %dx%d; viewport: %dx%d+%d+%d\n",
169 DisplayWidth (dpy, i), DisplayHeight (dpy, i),
170 ml.hdisplay, ml.vdisplay, x, y
174 "%s: hsync start %d; end %d; total %d; skew %d;\n",
176 ml.hsyncstart, ml.hsyncend, ml.htotal, ml.hskew);
178 "%s: vsync start %d; end %d; total %d; flags 0x%04x;\n",
180 ml.vsyncstart, ml.vsyncend, ml.vtotal, ml.flags);
181 fprintf (stderr, "\n");