X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=driver%2Fxscreensaver-command.c;h=a267f4e7538659fec2a1cc15a984f342bbd2a296;hp=8ace1506e486b32ef318ec98c9597f65db571915;hb=ffd8c0873576a9e3065696a624dce6b766b77062;hpb=c6b273ef7292ba10943694df1656b05203d7b62f diff --git a/driver/xscreensaver-command.c b/driver/xscreensaver-command.c index 8ace1506..a267f4e7 100644 --- a/driver/xscreensaver-command.c +++ b/driver/xscreensaver-command.c @@ -1,5 +1,4 @@ -/* xscreensaver-command, Copyright (c) 1991-1998 - * by Jamie Zawinski +/* xscreensaver-command, Copyright (c) 1991-2004 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -10,14 +9,15 @@ * implied warranty. */ -#define STANDALONE - #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #include +#include +#include +#include #ifdef HAVE_UNISTD_H # include @@ -31,184 +31,33 @@ #include /* only needed to get through xscreensaver.h */ +#include "remote.h" #include "version.h" -#ifdef STANDALONE - static char *progname; - static Atom XA_VROOT; - static Atom XA_SCREENSAVER, XA_SCREENSAVER_VERSION, XA_SCREENSAVER_TIME; -#else /* !STANDALONE */ -# include "xscreensaver.h" -#endif /* !STANDALONE */ - - #ifdef _VROOT_H_ ERROR! you must not include vroot.h in this file #endif -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; - - xgwa.map_state = IsViewable; - XGetWindowAttributes (dpy, window, &xgwa); - - if (XGetWindowProperty (dpy, window, XA_VROOT, - 0, 0, False, XA_WINDOW, - &type, &format, &nitems, &bytesafter, - &data) - == Success - && type != None) - active_p = True; - - if (data) free (data); - data = 0; - - if (XGetWindowProperty (dpy, window, - XA_SCREENSAVER_TIME, - 0, 1, False, XA_INTEGER, - &type, &format, &nitems, &bytesafter, - &data) - == Success - && type == XA_INTEGER - && data) - { - CARD32 time32 = *((CARD32 *)data); - time_t tt = (time_t) time32; - - if (active_p) - fprintf (stdout, ": screen blanked since "); - else - /* suggestions for a better way to phrase this are welcome. */ - fprintf (stdout, ": screen non-blanked since "); - fprintf (stdout, "%s", ctime(&tt)); - if (data) free (data); - } - else - { - if (data) free (data); - fprintf (stdout, "\n"); - fflush (stdout); - fprintf (stderr, "%s: no time on window 0x%x (%s %s).\n", - progname, (unsigned int) window, - hint.res_class, (v ? v : "???")); - exit (1); - } - } - } - else - { - XEvent event; - event.xany.type = ClientMessage; - event.xclient.display = dpy; - event.xclient.window = window; - event.xclient.message_type = XA_SCREENSAVER; - event.xclient.format = 32; - event.xclient.data.l[0] = (long) command; - if (! XSendEvent (dpy, window, False, 0L, &event)) - { - fprintf (stderr, "%s: XSendEvent(dpy, 0x%x ...) failed.\n", - progname, (unsigned int) window); - exit (1); - } - } - XSync (dpy, 0); -} - +char *progname; - -#ifdef STANDALONE +Atom XA_VROOT; +Atom XA_SCREENSAVER, XA_SCREENSAVER_VERSION, XA_SCREENSAVER_RESPONSE; +Atom XA_SCREENSAVER_ID, XA_SCREENSAVER_STATUS, XA_SELECT, XA_DEMO, XA_EXIT; +Atom XA_BLANK, XA_LOCK; static Atom XA_ACTIVATE, XA_DEACTIVATE, XA_CYCLE, XA_NEXT, XA_PREV; -static Atom XA_EXIT, XA_RESTART, XA_DEMO, XA_LOCK; +static Atom XA_RESTART, XA_PREFS, XA_THROTTLE, XA_UNTHROTTLE; -static char *progname; static char *screensaver_version; +# ifdef __GNUC__ + __extension__ /* don't warn about "string length is greater than the + length ISO C89 compilers are required to support" in the + usage string... */ +# endif static char *usage = "\n\ -usage: %s -\n\ +usage: %s -