http://www.jwz.org/xscreensaver/xscreensaver-5.12.tar.gz
[xscreensaver] / hacks / noseguy.c
index f6502bef5621059f5214e5291c52bf0debcfd939..144e6859bd0f00d4e0d88620fac6ef91edb06d45 100644 (file)
@@ -1,5 +1,4 @@
-/* xscreensaver, Copyright (c) 1992, 1996, 1997, 1998, 2005, 2006
- *  Jamie Zawinski <jwz@jwz.org>
+/* xscreensaver, Copyright (c) 1992-2008 Jamie Zawinski <jwz@jwz.org>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -71,13 +70,7 @@ static void talk_1 (struct state *);
 static int think (struct state *);
 static unsigned long look (struct state *); 
 
-#define FROM_ARGV    1
-#define FROM_PROGRAM 2
-#define FROM_FILE    3
-#define FROM_RESRC   4
-
 #define IS_MOVING  1
-#define GET_PASSWD 2
 
 #if defined(HAVE_GDK_PIXBUF) || defined(HAVE_XPM)
 # include "images/noseguy/nose-f1.xpm"
@@ -117,7 +110,7 @@ init_images (struct state *st)
   images[i++] = &st->left_front;
   images[i++] = &st->right_front;
   images[i++] = &st->front;
-  images[i++] = &st->down;
+  images[i]   = &st->down;
 
 #if defined(HAVE_GDK_PIXBUF) || defined(HAVE_XPM)
 
@@ -129,7 +122,7 @@ init_images (struct state *st)
   bits[i++] = nose_f2_xpm;
   bits[i++] = nose_f3_xpm;
   bits[i++] = nose_f1_xpm;
-  bits[i++] = nose_f4_xpm;
+  bits[i]   = nose_f4_xpm;
 
   for (i = 0; i < sizeof (images) / sizeof(*images); i++)
     {
@@ -196,6 +189,17 @@ move (struct state *st)
                st->move_length = st->Width / 100 + random() % 90, tries = 8;
            else
                tries--;
+           /* There maybe the case that we won't be able to exit from
+              this routine (especially when the geometry is too small)!!
+
+              Ensure that we can exit from this routine.
+            */
+#if 1
+           if (!tries && (st->move_length <= 1)) {
+             st->move_length = 1;
+             break;
+           }
+#endif
            switch (random() % 8)
            {
            case 0:
@@ -239,7 +243,8 @@ move (struct state *st)
            }
        } while (!st->move_dir);
     }
-    walk(st, st->move_dir);
+    if (st->move_dir)
+      walk(st, st->move_dir);
     --st->move_length;
     st->next_fn = move;
 }
@@ -557,6 +562,7 @@ static const char *noseguy_defaults [] = {
   ".foreground:            #CCCCCC",
   "*textForeground: black",
   "*textBackground: #CCCCCC",
+  "*fpsSolid:  true",
   "*program:    xscreensaver-text --cols 40 | head -n15",
   ".font:       -*-new century schoolbook-*-r-*-*-*-180-*-*-*-*-*-*",
   0
@@ -596,8 +602,10 @@ noseguy_init (Display *d, Window w)
   if (!fontname || !*fontname)
     fprintf (stderr, "%s: no font specified.\n", progname);
   st->font = XLoadQueryFont(st->dpy, fontname);
-  if (!st->font)
+  if (!st->font) {
     fprintf (stderr, "%s: could not load font %s.\n", progname, fontname);
+    exit(1);
+  }
 
   fg = get_pixel_resource (st->dpy, cmap, "foreground", "Foreground");
   bg = get_pixel_resource (st->dpy, cmap, "background", "Background");