+
+\f
+/* Some random diagnostics printed in -verbose mode.
+ */
+
+static void
+analyze_display (saver_info *si)
+{
+ int i, j;
+ static const char *exts[][2] = {
+ { "SCREEN_SAVER", "SGI Screen-Saver" },
+ { "SCREEN-SAVER", "SGI Screen-Saver" },
+ { "MIT-SCREEN-SAVER", "MIT Screen-Saver" },
+ { "XIDLE", "XIdle" },
+ { "SGI-VIDEO-CONTROL", "SGI Video-Control" },
+ { "READDISPLAY", "SGI Read-Display" },
+ { "MIT-SHM", "Shared Memory" },
+ { "DOUBLE-BUFFER", "Double-Buffering" },
+ { "DPMS", "Power Management" },
+ { "GLX", "GLX" },
+ { "XFree86-VidModeExtension", "XF86 Video-Mode" },
+ { "XINERAMA", "Xinerama" }
+ };
+
+ 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;
+ if (XQueryExtension (si->dpy, exts[i][0], &op, &event, &error))
+ fprintf (stderr, "%s: %s\n", blurb(), exts[i][1]);
+ }
+
+ for (i = 0; i < si->nscreens; i++)
+ {
+ unsigned long colormapped_depths = 0;
+ unsigned long non_mapped_depths = 0;
+ XVisualInfo vi_in, *vi_out;
+ int out_count;
+ vi_in.screen = i;
+ 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(), i);
+ 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-mapped depths:", blurb(), i);
+ for (j = 0; j < 32; j++)
+ if (non_mapped_depths & (1 << j))
+ fprintf (stderr, " %d", j);
+ fprintf (stderr, "\n");
+ }
+ }
+}
+
+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
+ {
+ /* 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;
+}