-static Window
-find_screensaver_window (Display *dpy, char **version)
-{
- int i;
- Window root = RootWindowOfScreen (DefaultScreenOfDisplay (dpy));
- Window root2, parent, *kids;
- unsigned int nkids;
-
- if (version) *version = 0;
-
- if (! XQueryTree (dpy, root, &root2, &parent, &kids, &nkids))
- abort ();
- if (root != root2)
- abort ();
- if (parent)
- abort ();
- if (! (kids && nkids))
- abort ();
- for (i = 0; i < nkids; i++)
- {
- Atom type;
- int format;
- unsigned long nitems, bytesafter;
- char *v;
-
- if (XGetWindowProperty (dpy, kids[i],
- XA_SCREENSAVER_VERSION,
- 0, 200, False, XA_STRING,
- &type, &format, &nitems, &bytesafter,
- (unsigned char **) &v)
- == Success
- && type != None)
- {
- if (version)
- *version = v;
- return kids[i];
- }
- }
- fprintf (stderr, "%s: no screensaver is running on display %s\n", progname,
- DisplayString (dpy));
- exit (1);
-}
-
-
-void
-xscreensaver_command (Display *dpy, Atom command)
-{
- char *v = 0;
- Window window = find_screensaver_window (dpy, &v);
-
- if (command == XA_SCREENSAVER_TIME ||
- command == XA_SCREENSAVER_VERSION)
- {
- XClassHint hint;
- memset (&hint, 0, sizeof(hint));
- if (!v || !*v)
- {
- fprintf (stderr, "%s: version property not set on window 0x%x?\n",
- progname, (unsigned int) window);
- exit (1);
- }
-
- XGetClassHint(dpy, window, &hint);
- if (!hint.res_class)
- {
- fprintf (stderr, "%s: class hints not set on window 0x%x?\n",
- progname, (unsigned int) window);
- exit (1);
- }
-
- fprintf (stdout, "%s %s", hint.res_class, v);
-
- if (command != XA_SCREENSAVER_TIME)
- {
- fprintf (stdout, "\n");
- }
- else
- {
- Atom type;
- int format;
- unsigned long nitems, bytesafter;
- unsigned char *data = 0;
- XWindowAttributes xgwa;
- Bool active_p = False;