+
+\f
+/* Some random diagnostics printed in -verbose mode.
+ */
+
+static void
+analyze_display (saver_info *si)
+{
+ int i, j;
+ static struct {
+ const char *name; const char *desc;
+ Bool useful_p;
+ Status (*version_fn) (Display *, int *majP, int *minP);
+ } exts[] = {
+
+ { "SCREEN_SAVER", /* underscore */ "SGI Screen-Saver",
+# ifdef HAVE_SGI_SAVER_EXTENSION
+ True, 0
+# else
+ False, 0
+# endif
+ }, { "SCREEN-SAVER", /* dash */ "SGI Screen-Saver",
+# ifdef HAVE_SGI_SAVER_EXTENSION
+ True, 0
+# else
+ False, 0
+# endif
+ }, { "MIT-SCREEN-SAVER", "MIT Screen-Saver",
+# ifdef HAVE_MIT_SAVER_EXTENSION
+ True, XScreenSaverQueryVersion
+# else
+ False, 0
+# endif
+ }, { "XIDLE", "XIdle",
+# ifdef HAVE_XIDLE_EXTENSION
+ True, 0
+# else
+ False, 0
+# endif
+ }, { "SGI-VIDEO-CONTROL", "SGI Video-Control",
+# ifdef HAVE_SGI_VC_EXTENSION
+ True, XSGIvcQueryVersion
+# else
+ False, 0
+# endif
+ }, { "READDISPLAY", "SGI Read-Display",
+# ifdef HAVE_READ_DISPLAY_EXTENSION
+ True, XReadDisplayQueryVersion
+# else
+ False, 0
+# endif
+ }, { "MIT-SHM", "Shared Memory",
+# ifdef HAVE_XSHM_EXTENSION
+ True, (Status (*) (Display*,int*,int*)) XShmQueryVersion /* 4 args */
+# else
+ False, 0
+# endif
+ }, { "DOUBLE-BUFFER", "Double-Buffering",
+# ifdef HAVE_DOUBLE_BUFFER_EXTENSION
+ True, XdbeQueryExtension
+# else
+ False, 0
+# endif
+ }, { "DPMS", "Power Management",
+# ifdef HAVE_DPMS_EXTENSION
+ True, DPMSGetVersion
+# else
+ False, 0
+# endif
+ }, { "GLX", "GLX",
+# ifdef HAVE_GL
+ True, 0
+# else
+ False, 0
+# endif
+ }, { "XFree86-VidModeExtension", "XF86 Video-Mode",
+# ifdef HAVE_XF86VMODE
+ True, XF86VidModeQueryVersion
+# else
+ False, 0
+# endif
+ }, { "XC-VidModeExtension", "XC Video-Mode",
+# ifdef HAVE_XF86VMODE
+ True, XF86VidModeQueryVersion
+# else
+ False, 0
+# endif
+ }, { "XFree86-MISC", "XF86 Misc",
+# ifdef HAVE_XF86MISCSETGRABKEYSSTATE
+ True, XF86MiscQueryVersion
+# else
+ False, 0
+# endif
+ }, { "XC-MISC", "XC Misc",
+# ifdef HAVE_XF86MISCSETGRABKEYSSTATE
+ True, XF86MiscQueryVersion
+# else
+ False, 0
+# endif
+ }, { "XINERAMA", "Xinerama",
+# ifdef HAVE_XINERAMA
+ True, XineramaQueryVersion
+# else
+ False, 0
+# endif
+ }, { "RANDR", "Resize-and-Rotate",
+# ifdef HAVE_RANDR
+ True, XRRQueryVersion
+# else
+ False, 0
+# endif
+ }, { "DRI", "DRI",
+ True, 0
+ }, { "Apple-DRI", "Apple-DRI (XDarwin)",
+ True, 0
+ },
+ };
+
+ fprintf (stderr, "%s: running on display \"%s\"\n", blurb(),
+ DisplayString(si->dpy));
+ fprintf (stderr, "%s: vendor is %s, %d.\n", blurb(),
+ ServerVendor(si->dpy), VendorRelease(si->dpy));
+
+ fprintf (stderr, "%s: useful extensions:\n", blurb());
+ for (i = 0; i < countof(exts); i++)
+ {
+ int op = 0, event = 0, error = 0;
+ char buf [255];
+ int maj = 0, min = 0;
+ int dummy1, dummy2, dummy3;
+ int j;
+
+ /* Most of the extension version functions take 3 args,
+ writing results into args 2 and 3, but some take more.
+ We only ever care about the first two results, but we
+ pass in three extra pointers just in case.
+ */
+ Status (*version_fn_2) (Display*,int*,int*,int*,int*,int*) =
+ (Status (*) (Display*,int*,int*,int*,int*,int*)) exts[i].version_fn;
+
+ if (!XQueryExtension (si->dpy, exts[i].name, &op, &event, &error))
+ continue;
+ sprintf (buf, "%s: ", blurb());
+ j = strlen (buf);
+ strcat (buf, exts[i].desc);
+
+ if (!version_fn_2)
+ ;
+ else if (version_fn_2 (si->dpy, &maj, &min, &dummy1, &dummy2, &dummy3))
+ sprintf (buf+strlen(buf), " (%d.%d)", maj, min);
+ else
+ strcat (buf, " (unavailable)");
+
+ if (!exts[i].useful_p)
+ strcat (buf, " (disabled at compile time)");
+ fprintf (stderr, "%s\n", buf);
+ }
+
+ for (i = 0; i < si->nscreens; i++)
+ {
+ saver_screen_info *ssi = &si->screens[i];
+ unsigned long colormapped_depths = 0;
+ unsigned long non_mapped_depths = 0;
+ XVisualInfo vi_in, *vi_out;
+ int out_count;
+
+ if (!ssi->real_screen_p) continue;
+
+ vi_in.screen = ssi->real_screen_number;
+ vi_out = XGetVisualInfo (si->dpy, VisualScreenMask, &vi_in, &out_count);
+ if (!vi_out) continue;
+ for (j = 0; j < out_count; j++)
+ if (vi_out[j].class == PseudoColor)
+ colormapped_depths |= (1 << vi_out[j].depth);
+ else
+ non_mapped_depths |= (1 << vi_out[j].depth);
+ XFree ((char *) vi_out);
+
+ if (colormapped_depths)
+ {
+ fprintf (stderr, "%s: screen %d colormapped depths:", blurb(),
+ ssi->real_screen_number);
+ for (j = 0; j < 32; j++)
+ if (colormapped_depths & (1 << j))
+ fprintf (stderr, " %d", j);
+ fprintf (stderr, ".\n");
+ }
+ if (non_mapped_depths)
+ {
+ fprintf (stderr, "%s: screen %d non-colormapped depths:",
+ blurb(), ssi->real_screen_number);
+ for (j = 0; j < 32; j++)
+ if (non_mapped_depths & (1 << j))
+ fprintf (stderr, " %d", j);
+ fprintf (stderr, ".\n");
+ }
+ }
+
+ describe_monitor_layout (si);
+}
+
+
+Bool
+display_is_on_console_p (saver_info *si)
+{
+ Bool not_on_console = True;
+ char *dpystr = DisplayString (si->dpy);
+ char *tail = (char *) strchr (dpystr, ':');
+ if (! tail || strncmp (tail, ":0", 2))
+ not_on_console = True;
+ else
+ {
+ char dpyname[255], localname[255];
+ strncpy (dpyname, dpystr, tail-dpystr);
+ dpyname [tail-dpystr] = 0;
+ if (!*dpyname ||
+ !strcmp(dpyname, "unix") ||
+ !strcmp(dpyname, "localhost"))
+ not_on_console = False;
+ else if (gethostname (localname, sizeof (localname)))
+ not_on_console = True; /* can't find hostname? */
+ else if (!strncmp (dpyname, "/tmp/launch-", 12)) /* MacOS X launchd */
+ not_on_console = False;
+ else
+ {
+ /* We have to call gethostbyname() on the result of gethostname()
+ because the two aren't guarenteed to be the same name for the
+ same host: on some losing systems, one is a FQDN and the other
+ is not. Here in the wide wonderful world of Unix it's rocket
+ science to obtain the local hostname in a portable fashion.
+
+ And don't forget, gethostbyname() reuses the structure it
+ returns, so we have to copy the fucker before calling it again.
+ Thank you master, may I have another.
+ */
+ struct hostent *h = gethostbyname (dpyname);
+ if (!h)
+ not_on_console = True;
+ else
+ {
+ char hn [255];
+ struct hostent *l;
+ strcpy (hn, h->h_name);
+ l = gethostbyname (localname);
+ not_on_console = (!l || !!(strcmp (l->h_name, hn)));
+ }
+ }
+ }
+ return !not_on_console;
+}
+
+
+/* Do a little bit of heap introspection...
+ */
+void
+check_for_leaks (const char *where)
+{
+#if defined(HAVE_SBRK) && defined(LEAK_PARANOIA)
+ static unsigned long last_brk = 0;
+ int b = (unsigned long) sbrk(0);
+ if (last_brk && last_brk < b)
+ fprintf (stderr, "%s: %s: brk grew by %luK.\n",
+ blurb(), where,
+ (((b - last_brk) + 1023) / 1024));
+ last_brk = b;
+#endif /* HAVE_SBRK */
+}