/* test-randr.c --- playing with the Resize And Rotate extension.
- * xscreensaver, Copyright (c) 2004 Jamie Zawinski <jwz@jwz.org>
+ * xscreensaver, Copyright (c) 2004-2008 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
}
+static Bool error_handler_hit_p = False;
+
+static int
+ignore_all_errors_ehandler (Display *dpy, XErrorEvent *error)
+{
+ error_handler_hit_p = True;
+ return 0;
+}
+
+
int
main (int argc, char **argv)
{
- int event_number, error_number;
- int major, minor;
+ int event_number = -1, error_number = -1;
+ int major = -1, minor = -1;
int nscreens = 0;
int i;
for (i = 0; i < nscreens; i++)
{
- XRRScreenConfiguration *rrc =
- (major >= 0 ? XRRGetScreenInfo (dpy, RootWindow (dpy, i)) : 0);
+ XRRScreenConfiguration *rrc;
+ XErrorHandler old_handler;
+
+ XSync (dpy, False);
+ error_handler_hit_p = False;
+ old_handler = XSetErrorHandler (ignore_all_errors_ehandler);
+
+ rrc = (major >= 0 ? XRRGetScreenInfo (dpy, RootWindow (dpy, i)) : 0);
+
+ XSync (dpy, False);
+ XSetErrorHandler (old_handler);
+ XSync (dpy, False);
- if (rrc)
+ if (error_handler_hit_p)
+ {
+ fprintf(stderr, "%s: XRRGetScreenInfo(dpy, %d) ==> X error:\n",
+ blurb(), i);
+ /* do it again without the error handler to print the error */
+ rrc = XRRGetScreenInfo (dpy, RootWindow (dpy, i));
+ }
+ else if (rrc)
{
SizeID current_size = -1;
Rotation current_rotation = ~0;
XRRConfigCurrentConfiguration (rrc, ¤t_rotation);
/* Times */
+# if 0 /* #### This is wrong -- I don't understand what these two
+ timestamp numbers represent, or how they correlate
+ to the wall clock or to each other. */
{
Time server_time, config_time;
server_time = XRRConfigTimes (rrc, &config_time);
fprintf (stderr, "%s: config changed %lu seconds ago\n",
blurb(), (unsigned long) (server_time - config_time));
}
+# endif
/* Rotations */
{
fprintf(stderr, "%s: XRRGetScreenInfo(dpy, %d) ==> NULL\n",
blurb(), i);
}
+
+
+# ifdef HAVE_RANDR_12
+ if (major > 1 || (major == 1 && minor >= 2))
+ {
+ int j;
+ XRRScreenResources *res =
+ XRRGetScreenResources (dpy, RootWindow (dpy, i));
+ fprintf (stderr, "\n");
+ for (j = 0; j < res->noutput; j++)
+ {
+ int k;
+ XRROutputInfo *rroi =
+ XRRGetOutputInfo (dpy, res, res->outputs[j]);
+ fprintf (stderr, "%s: Output %d: %s: %s (%d)\n", blurb(), j,
+ rroi->name,
+ (rroi->connection == RR_Disconnected ? "disconnected" :
+ rroi->connection == RR_UnknownConnection ? "unknown" :
+ "connected"),
+ (int) rroi->crtc);
+ for (k = 0; k < rroi->ncrtc; k++)
+ {
+ XRRCrtcInfo *crtci = XRRGetCrtcInfo (dpy, res,
+ rroi->crtcs[k]);
+ fprintf(stderr, "%s: %c CRTC %d (%d): %dx%d+%d+%d\n",
+ blurb(),
+ (rroi->crtc == rroi->crtcs[k] ? '+' : ' '),
+ k, (int) rroi->crtcs[k],
+ crtci->width, crtci->height, crtci->x, crtci->y);
+ XRRFreeCrtcInfo (crtci);
+ }
+ XRRFreeOutputInfo (rroi);
+ fprintf (stderr, "\n");
+ }
+ XRRFreeScreenResources (res);
+ }
+# endif /* HAVE_RANDR_12 */
}
if (major > 0)
}
XSync (dpy, False);
- fprintf (stderr, "\n%s: awaiting events...\n", progname);
+
+ fprintf (stderr, "\n%s: awaiting events...\n\n"
+ "\t(If you resize the screen or add/remove monitors, this should\n"
+ "\tnotice that and print stuff. Otherwise, hit ^C.)\n\n",
+ progname);
while (1)
{
XEvent event;