1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
/* test-xinerama.c --- playing with XF86VidModeGetViewPort
* xscreensaver, Copyright (c) 2004 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Intrinsic.h>
#include <X11/Xproto.h>
#include <X11/extensions/xf86vmode.h>
#include <X11/extensions/Xinerama.h>
char *progname = 0;
char *progclass = "XScreenSaver";
static const char *
blurb (void)
{
static char buf[255];
time_t now = time ((time_t *) 0);
char *ct = (char *) ctime (&now);
int n = strlen(progname);
if (n > 100) n = 99;
strncpy(buf, progname, n);
buf[n++] = ':';
buf[n++] = ' ';
strncpy(buf+n, ct+11, 8);
strcpy(buf+n+9, ": ");
return buf;
}
static Bool error_handler_hit_p = False;
static int
ignore_all_errors_ehandler (Display *dpy, XErrorEvent *error)
{
error_handler_hit_p = True;
return 0;
}
static int
screen_count (Display *dpy)
{
int n = ScreenCount(dpy);
int xn = 0;
int event_number, error_number;
if (!XineramaQueryExtension (dpy, &event_number, &error_number))
{
fprintf(stderr, "%s: XineramaQueryExtension(dpy, ...) ==> False\n",
blurb());
goto DONE;
}
else
fprintf(stderr, "%s: XineramaQueryExtension(dpy, ...) ==> %d, %d\n",
blurb(), event_number, error_number);
if (!XineramaIsActive(dpy))
{
fprintf(stderr, "%s: XineramaIsActive(dpy) ==> False\n",
blurb());
goto DONE;
}
else
{
int major, minor;
XineramaScreenInfo *xsi;
fprintf(stderr, "%s: XineramaIsActive(dpy) ==> True\n",
blurb());
if (!XineramaQueryVersion(dpy, &major, &minor))
{
fprintf(stderr,
"%s: XineramaQueryVersion(dpy, ...) ==> False\n",
blurb());
goto DONE;
}
else
fprintf(stderr,
"%s: XineramaQueryVersion(dpy, ...) ==> %d, %d\n",
blurb(), major, minor);
xsi = XineramaQueryScreens (dpy, &xn);
if (xsi) XFree (xsi);
}
DONE:
fprintf (stderr, "\n");
fprintf (stderr, "%s: X client screens: %d\n", blurb(), n);
fprintf (stderr, "%s: Xinerama screens: %d\n", blurb(), xn);
fprintf (stderr, "\n");
if (xn > n) return xn;
else return n;
}
int
main (int argc, char **argv)
{
int event_number, error_number;
int major, minor;
int nscreens = 0;
int i;
XtAppContext app;
Widget toplevel_shell = XtAppInitialize (&app, progclass, 0, 0,
&argc, argv, 0, 0, 0);
Display *dpy = XtDisplay (toplevel_shell);
XtGetApplicationNameAndClass (dpy, &progname, &progclass);
if (!XF86VidModeQueryExtension(dpy, &event_number, &error_number))
{
fprintf(stderr, "%s: XF86VidModeQueryExtension(dpy, ...) ==> False\n",
blurb());
fprintf(stderr,
"%s: server does not support the XF86VidMode extension.\n",
blurb());
exit(1);
}
else
fprintf(stderr, "%s: XF86VidModeQueryExtension(dpy, ...) ==> %d, %d\n",
blurb(), event_number, error_number);
if (!XF86VidModeQueryVersion(dpy, &major, &minor))
{
fprintf(stderr, "%s: XF86VidModeQueryVersion(dpy, ...) ==> False\n",
blurb());
fprintf(stderr,
"%s: server didn't report XF86VidMode version numbers?\n",
blurb());
}
else
fprintf(stderr, "%s: XF86VidModeQueryVersion(dpy, ...) ==> %d, %d\n",
blurb(), major, minor);
nscreens = screen_count (dpy);
for (i = 0; i < nscreens; i++)
{
int result = 0;
int x = 0, y = 0, dot = 0;
XF86VidModeModeLine ml = { 0, };
XErrorHandler old_handler;
XSync (dpy, False);
error_handler_hit_p = False;
old_handler = XSetErrorHandler (ignore_all_errors_ehandler);
result = XF86VidModeGetViewPort (dpy, i, &x, &y);
XSync (dpy, False);
XSetErrorHandler (old_handler);
XSync (dpy, False);
if (error_handler_hit_p)
{
fprintf(stderr,
"%s: XF86VidModeGetViewPort(dpy, %d, ...) ==> X error\n",
blurb(), i);
continue;
}
if (! result)
fprintf(stderr, "%s: XF86VidModeGetViewPort(dpy, %d, ...) ==> %d\n",
blurb(), i, result);
result = XF86VidModeGetModeLine (dpy, i, &dot, &ml);
if (! result)
fprintf(stderr, "%s: XF86VidModeGetModeLine(dpy, %d, ...) ==> %d\n",
blurb(), i, result);
fprintf (stderr, "%s: screen %d: %dx%d; viewport: %dx%d+%d+%d\n",
blurb(), i,
DisplayWidth (dpy, i), DisplayHeight (dpy, i),
ml.hdisplay, ml.vdisplay, x, y
);
fprintf (stderr,
"%s: hsync start %d; end %d; total %d; skew %d;\n",
blurb(),
ml.hsyncstart, ml.hsyncend, ml.htotal, ml.hskew);
fprintf (stderr,
"%s: vsync start %d; end %d; total %d; flags 0x%04x;\n",
blurb(),
ml.vsyncstart, ml.vsyncend, ml.vtotal, ml.flags);
fprintf (stderr, "\n");
}
XSync (dpy, False);
exit (0);
}
|