http://ftp.x.org/contrib/applications/xscreensaver-2.17.tar.gz
[xscreensaver] / driver / xscreensaver.c
index 0d5796b82fbc0de5f94a07618e785ff4b23e0b9b..07633112d2a4022bea5c30c8fcd6d68f48f3b8f6 100644 (file)
@@ -1,4 +1,4 @@
-/* xscreensaver, Copyright (c) 1991-1997 Jamie Zawinski <jwz@netscape.com>
+/* xscreensaver, Copyright (c) 1991-1998 Jamie Zawinski <jwz@netscape.com>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
  *       window exposed.
  *     - If you run your debugger under XEmacs, try M-ESC (x-grab-keyboard)
  *       to keep your emacs window alive even when xscreensaver has grabbed.
- *     - Go read the code related to -DDEBUG.
+ *     - Go read the code related to `debug_p'.
  *     - You probably can't set breakpoints in functions that are called on
  *       the other side of a call to fork() -- if your clients are dying 
  *       with signal 5, Trace/BPT Trap, you're losing in this way.
@@ -193,7 +193,7 @@ static void
 do_help (saver_info *si)
 {
   printf ("\
-xscreensaver %s, copyright (c) 1991-1997 by Jamie Zawinski <jwz@netscape.com>\n\
+xscreensaver %s, copyright (c) 1991-1998 by Jamie Zawinski <jwz@netscape.com>\n\
 The standard Xt command-line options are accepted; other options include:\n\
 \n\
     -timeout <minutes>         When the screensaver should activate.\n\
@@ -249,7 +249,7 @@ reformat_hack(const char *hack)
   char *out = h2;
 
   while (isspace(*in)) in++;           /* skip whitespace */
-  while (!isspace(*in) && *in != ':')
+  while (*in && !isspace(*in) && *in != ':')
     *out++ = *in++;                    /* snarf first token */
   while (isspace(*in)) in++;           /* skip whitespace */
 
@@ -348,8 +348,11 @@ get_screenhacks (saver_info *si)
              for (s2 = s+j+1; *s2 == ' ' || *s2 == '\t'; s2++)
                k++;
              if (k > 0)
-               for (s2 = s + j + 1; *s2; s2++)
-                 s2 [0] = s2 [k];
+               {
+                 for (s2 = s+j+1; s2[k]; s2++)
+                   *s2 = s2[k];
+                 *s2 = 0;
+               }
              break;
            }
        }
@@ -479,14 +482,12 @@ get_resources (saver_info *si)
 
   get_screenhacks (si);
 
-#ifdef DEBUG
   if (p->debug_p)
     {
       XSynchronize(si->dpy, True);
       p->verbose_p = True;
       p->initial_delay = 0;
     }
-#endif /* DEBUG */
 }
 
 
@@ -544,10 +545,10 @@ initialize_connection (saver_info *si, int argc, char **argv)
 
   if (argc == 2 && !strcmp (argv[1], "-help"))
     do_help (si);
-#ifdef DEBUG
+
   else if (argc == 2 && !strcmp (argv[1], "-debug"))
     si->prefs.debug_p = True;  /* no resource for this one, out of paranoia. */
-#endif /* DEBUG */
+
   else if (argc > 1)
     {
       fprintf (stderr, "%s: unknown option %s\n", progname, argv [1]);
@@ -660,7 +661,7 @@ initialize (saver_info *si, int argc, char **argv)
 
   if (p->verbose_p)
     printf ("\
-%s %s, copyright (c) 1991-1997 by Jamie Zawinski <jwz@netscape.com>\n\
+%s %s, copyright (c) 1991-1998 by Jamie Zawinski <jwz@netscape.com>\n\
  pid = %d.\n", progname, si->version, (int) getpid ());
 
   
@@ -817,7 +818,7 @@ main_loop (saver_info *si)
       if (si->demo_mode_p)
        demo_mode (si);
       else
-#endif
+#endif /* !NO_DEMO_MODE */
        {
          if (p->verbose_p)
            printf ("%s: user is idle; waking up at %s.\n", progname,
@@ -836,7 +837,7 @@ main_loop (saver_info *si)
            si->lock_id = XtAppAddTimeOut (si->app, p->lock_timeout,
                                           activate_lock_timer,
                                           (XtPointer) si);
-#endif
+#endif /* !NO_LOCKING */
 
        PASSWD_INVALID:
 
@@ -860,7 +861,7 @@ main_loop (saver_info *si)
                 just after the server is grabbed, closing this window
                 entirely.
               */
-             /* ungrab_keyboard_and_mouse (); */
+             /* ungrab_keyboard_and_mouse (si); */
 
              {
                saver_screen_info *ssi = si->default_screen;
@@ -878,7 +879,7 @@ main_loop (saver_info *si)
                /* I think this grab is now redundant, but it shouldn't hurt.
                 */
                if (!si->demo_mode_p)
-                 grab_keyboard_and_mouse (si->dpy, ssi->screensaver_window,
+                 grab_keyboard_and_mouse (si, ssi->screensaver_window,
                                           ssi->cursor);
              }
 
@@ -886,21 +887,27 @@ main_loop (saver_info *si)
                goto PASSWD_INVALID;
              si->locked_p = False;
            }
-#endif
-         unblank_screen (si);
+#endif /* !NO_LOCKING */
+
+         /* Let's kill it before unblanking, to get it to stop drawing as
+            soon as possible... */
          kill_screenhack (si);
+         unblank_screen (si);
+
          if (si->cycle_id)
            {
              XtRemoveTimeOut (si->cycle_id);
              si->cycle_id = 0;
            }
+
 #ifndef NO_LOCKING
          if (si->lock_id)
            {
              XtRemoveTimeOut (si->lock_id);
              si->lock_id = 0;
            }
-#endif
+#endif /* !NO_LOCKING */
+
          if (p->verbose_p)
            printf ("%s: user is active; going to sleep at %s.\n", progname,
                    timestring ());