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, ": ");
54 static Bool error_handler_hit_p = False;
57 ignore_all_errors_ehandler (Display *dpy, XErrorEvent *error)
59 error_handler_hit_p = True;
65 screen_count (Display *dpy)
67 int n = ScreenCount(dpy);
69 int event_number, error_number;
71 if (!XineramaQueryExtension (dpy, &event_number, &error_number))
73 fprintf(stderr, "%s: XineramaQueryExtension(dpy, ...) ==> False\n",
78 fprintf(stderr, "%s: XineramaQueryExtension(dpy, ...) ==> %d, %d\n",
79 blurb(), event_number, error_number);
81 if (!XineramaIsActive(dpy))
83 fprintf(stderr, "%s: XineramaIsActive(dpy) ==> False\n",
90 XineramaScreenInfo *xsi;
91 fprintf(stderr, "%s: XineramaIsActive(dpy) ==> True\n",
93 if (!XineramaQueryVersion(dpy, &major, &minor))
96 "%s: XineramaQueryVersion(dpy, ...) ==> False\n",
102 "%s: XineramaQueryVersion(dpy, ...) ==> %d, %d\n",
103 blurb(), major, minor);
105 xsi = XineramaQueryScreens (dpy, &xn);
106 if (xsi) XFree (xsi);
110 fprintf (stderr, "\n");
111 fprintf (stderr, "%s: X client screens: %d\n", blurb(), n);
112 fprintf (stderr, "%s: Xinerama screens: %d\n", blurb(), xn);
113 fprintf (stderr, "\n");
115 if (xn > n) return xn;
121 main (int argc, char **argv)
123 int event_number, error_number;
129 Widget toplevel_shell = XtAppInitialize (&app, progclass, 0, 0,
130 &argc, argv, 0, 0, 0);
131 Display *dpy = XtDisplay (toplevel_shell);
132 XtGetApplicationNameAndClass (dpy, &progname, &progclass);
134 if (!XF86VidModeQueryExtension(dpy, &event_number, &error_number))
136 fprintf(stderr, "%s: XF86VidModeQueryExtension(dpy, ...) ==> False\n",
139 "%s: server does not support the XF86VidMode extension.\n",
144 fprintf(stderr, "%s: XF86VidModeQueryExtension(dpy, ...) ==> %d, %d\n",
145 blurb(), event_number, error_number);
147 if (!XF86VidModeQueryVersion(dpy, &major, &minor))
149 fprintf(stderr, "%s: XF86VidModeQueryVersion(dpy, ...) ==> False\n",
152 "%s: server didn't report XF86VidMode version numbers?\n",
156 fprintf(stderr, "%s: XF86VidModeQueryVersion(dpy, ...) ==> %d, %d\n",
157 blurb(), major, minor);
159 nscreens = screen_count (dpy);
161 for (i = 0; i < nscreens; i++)
164 int x = 0, y = 0, dot = 0;
165 XF86VidModeModeLine ml = { 0, };
166 XErrorHandler old_handler;
169 error_handler_hit_p = False;
170 old_handler = XSetErrorHandler (ignore_all_errors_ehandler);
172 result = XF86VidModeGetViewPort (dpy, i, &x, &y);
175 XSetErrorHandler (old_handler);
178 if (error_handler_hit_p)
181 "%s: XF86VidModeGetViewPort(dpy, %d, ...) ==> X error\n",
187 fprintf(stderr, "%s: XF86VidModeGetViewPort(dpy, %d, ...) ==> %d\n",
190 result = XF86VidModeGetModeLine (dpy, i, &dot, &ml);
192 fprintf(stderr, "%s: XF86VidModeGetModeLine(dpy, %d, ...) ==> %d\n",
195 fprintf (stderr, "%s: screen %d: %dx%d; viewport: %dx%d+%d+%d\n",
197 DisplayWidth (dpy, i), DisplayHeight (dpy, i),
198 ml.hdisplay, ml.vdisplay, x, y
202 "%s: hsync start %d; end %d; total %d; skew %d;\n",
204 ml.hsyncstart, ml.hsyncend, ml.htotal, ml.hskew);
206 "%s: vsync start %d; end %d; total %d; flags 0x%04x;\n",
208 ml.vsyncstart, ml.vsyncend, ml.vtotal, ml.flags);
209 fprintf (stderr, "\n");