~ubuntu-branches/ubuntu/dapper/xscreensaver/dapper-updates

« back to all changes in this revision

Viewing changes to driver/xscreensaver-command.c

  • Committer: Bazaar Package Importer
  • Author(s): Ralf Hildebrandt
  • Date: 2005-04-09 00:06:43 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20050409000643-z0abtifbt9s20pcc
Tags: 4.21-3
Patch by Joachim Breitner to check more frequently if DPMS kicked in (closes: #303374, #286664).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* xscreensaver-command, Copyright (c) 1991-2001
2
 
 *  by Jamie Zawinski <jwz@jwz.org>
 
1
/* xscreensaver-command, Copyright (c) 1991-2004 Jamie Zawinski <jwz@jwz.org>
3
2
 *
4
3
 * Permission to use, copy, modify, distribute, and sell this software and its
5
4
 * documentation for any purpose is hereby granted without fee, provided that
16
15
 
17
16
#include <stdio.h>
18
17
#include <stdlib.h>
 
18
#include <time.h>
19
19
#include <sys/time.h>
20
20
#include <sys/types.h>
21
21
 
48
48
static Atom XA_RESTART, XA_PREFS, XA_THROTTLE, XA_UNTHROTTLE;
49
49
 
50
50
static char *screensaver_version;
 
51
# ifdef __GNUC__
 
52
  __extension__   /* don't warn about "string length is greater than the
 
53
                     length ISO C89 compilers are required to support" in the
 
54
                     usage string... */
 
55
# endif
51
56
static char *usage = "\n\
52
57
usage: %s -<option>\n\
53
58
\n\
54
59
  This program provides external control of a running xscreensaver process.\n\
55
 
  Version %s, copyright (c) 1991-2001 Jamie Zawinski <jwz@jwz.org>.\n\
 
60
  Version %s, copyright (c) 1991-2005 Jamie Zawinski <jwz@jwz.org>.\n\
56
61
\n\
57
62
  The xscreensaver program is a daemon that runs in the background.\n\
58
63
  You control a running xscreensaver process by sending it messages\n\
105
110
                well, even if locking is not the default.  If the saver is\n\
106
111
                already active, this causes it to be locked as well.\n\
107
112
\n\
108
 
  -throttle     Temporarily switch to ``blank screen'' mode, and don't run\n\
109
 
                any display modes at all, until the screensaver is next\n\
110
 
                de-activated.  This is useful if you're using a machine\n\
111
 
                remotely, and you find that some display modes are using too\n\
112
 
                much CPU.\n\
113
 
\n\
114
 
  -unthrottle   Turn `-throttle' off and resume normal behavior.\n\
115
 
\n\
116
113
  -version      Prints the version of xscreensaver that is currently running\n\
117
114
                on the display -- that is, the actual version number of the\n\
118
115
                running xscreensaver background process, rather than the\n\
133
130
  For updates, check http://www.jwz.org/xscreensaver/\n\
134
131
\n";
135
132
 
 
133
/* Note: The "-throttle" command is deprecated -- it predates the XDPMS
 
134
   extension.  Instead of using -throttle, users should instead just
 
135
   power off the monitor (e.g., "xset dpms force off".)  In a few
 
136
   minutes, the xscreensaver daemon will notice that the monitor is
 
137
   off, and cease running hacks.
 
138
 */
 
139
 
136
140
#define USAGE() do { \
137
141
 fprintf (stderr, usage, progname, screensaver_version); exit (1); \
138
142
 } while(0)
148
152
  Atom *cmd = 0;
149
153
  long arg = 0L;
150
154
  char *s;
 
155
  Atom XA_WATCH = 0;  /* kludge: not really an atom */
151
156
 
152
157
  progname = argv[0];
153
158
  s = strrchr (progname, '/');
182
187
      else if (!strncmp (s, "-unthrottle", L)) cmd = &XA_UNTHROTTLE;
183
188
      else if (!strncmp (s, "-version", L))    cmd = &XA_SCREENSAVER_VERSION;
184
189
      else if (!strncmp (s, "-time", L))       cmd = &XA_SCREENSAVER_STATUS;
185
 
      else if (!strncmp (s, "-watch", L))      cmd = (Atom *) &watch;
 
190
      else if (!strncmp (s, "-watch", L))      cmd = &XA_WATCH;
186
191
      else USAGE ();
187
192
 
188
193
      if (cmd == &XA_SELECT || cmd == &XA_DEMO)
296
301
 
297
302
  XSync (dpy, 0);
298
303
 
299
 
  if (cmd == (Atom *) &watch)
 
304
  if (cmd == &XA_WATCH)
300
305
    {
301
306
      i = watch (dpy);
302
307
      exit (i);
337
342
          Atom type;
338
343
          int format;
339
344
          unsigned long nitems, bytesafter;
340
 
          CARD32 *data = 0;
 
345
          unsigned char *dataP = 0;
341
346
 
342
347
          if (XGetWindowProperty (dpy,
343
348
                                  RootWindow (dpy, 0),  /* always screen #0 */
344
349
                                  XA_SCREENSAVER_STATUS,
345
350
                                  0, 999, False, XA_INTEGER,
346
351
                                  &type, &format, &nitems, &bytesafter,
347
 
                                  (unsigned char **) &data)
 
352
                                  &dataP)
348
353
              == Success
349
354
              && type
350
 
              && data)
 
355
              && dataP)
351
356
            {
352
357
              time_t tt;
353
358
              char *s;
354
359
              Bool changed = False;
355
360
              Bool running = False;
 
361
              CARD32 *data = (CARD32 *) dataP;
356
362
 
357
363
              if (type != XA_INTEGER || nitems < 3)
358
364
                {
359
365
                STATUS_LOSE:
360
 
                  if (last) free (last);
361
 
                  if (data) free (data);
 
366
                  if (last) XFree (last);
 
367
                  if (data) XFree (data);
362
368
                  fprintf (stderr, "%s: bad status format on root window.\n",
363
369
                           progname);
364
370
                  return -1;
402
408
              if (running && changed)
403
409
                {
404
410
                  int i;
405
 
                  fprintf (stdout, "RUN", s);
 
411
                  fprintf (stdout, "RUN");
406
412
                  for (i = 2; i < nitems; i++)
407
413
                    fprintf (stdout, " %d", (int) data[i]);
408
414
                  fprintf (stdout, "\n");
410
416
 
411
417
              fflush (stdout);
412
418
 
413
 
              if (last) free (last);
 
419
              if (last) XFree (last);
414
420
              last = data;
415
421
            }
416
422
          else
417
423
            {
418
 
              if (last) free (last);
419
 
              if (data) free (data);
 
424
              if (last) XFree (last);
 
425
              if (dataP) XFree (dataP);
420
426
              fprintf (stderr, "%s: no saver status on root window.\n",
421
427
                       progname);
422
428
              return -1;