http://ftp.x.org/contrib/applications/xscreensaver-3.26.tar.gz
[xscreensaver] / hacks / phosphor.c
index c575bb2aebc460dbee8aecdc08806aa0144705be..1188f2e60696504e35889b621005504dcebb0558 100644 (file)
@@ -1,4 +1,4 @@
-/* xscreensaver, Copyright (c) 1999 Jamie Zawinski <jwz@jwz.org>
+/* xscreensaver, Copyright (c) 1999, 2000 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
@@ -28,6 +28,7 @@ extern XtAppContext app;
 #define FLARE  1
 #define NORMAL 2
 #define FADE   3
+#define STATE_MAX FADE
 
 #define CURSOR_INDEX 128
 
@@ -144,7 +145,7 @@ init_phosphor (Display *dpy, Window window)
 
   font = state->font;
   state->scale = get_integer_resource ("scale", "Integer");
-  state->ticks = 3 + get_integer_resource ("ticks", "Integer");
+  state->ticks = STATE_MAX + get_integer_resource ("ticks", "Integer");
 
 #if 0
   for (i = 0; i < font->n_properties; i++)
@@ -199,6 +200,9 @@ init_phosphor (Display *dpy, Window window)
                      colors, &ncolors,
                      False, True, False);
 
+    /* Adjust to the number of colors we actually got. */
+    state->ticks = ncolors + STATE_MAX;
+
     /* Now, GCs all around.
      */
     state->gcv.font = font->fid;
@@ -233,8 +237,8 @@ init_phosphor (Display *dpy, Window window)
     for (i = 0; i < ncolors; i++)
       {
         state->gcv.foreground = colors[i].pixel;
-        state->gcs[FADE + i] = XCreateGC (state->dpy, state->window,
-                                          flags, &state->gcv);
+        state->gcs[STATE_MAX + i] = XCreateGC (state->dpy, state->window,
+                                               flags, &state->gcv);
       }
   }
 
@@ -296,7 +300,7 @@ capture_font_bits (p_state *state)
         continue;
       XDrawString (state->dpy, p, state->gc1,
                    i * safe_width, font->ascent,
-                   string + i, 1);
+                   (char *) (string + i), 1);
     }
 
   /* Draw the cursor. */
@@ -525,9 +529,10 @@ static void
 scroll (p_state *state)
 {
   int x, y;
+
   for (x = 0; x < state->grid_width; x++)
     {
-      p_cell *from, *to;
+      p_cell *from = 0, *to = 0;
       for (y = 1; y < state->grid_height; y++)
         {
           from = &state->cells[state->grid_width * y     + x];
@@ -549,7 +554,7 @@ scroll (p_state *state)
         }
 
       to = from;
-      if (to->state == FLARE || to->state == NORMAL)
+      if (to && (to->state == FLARE || to->state == NORMAL))
         {
           to->state = FADE;
           to->changed = True;
@@ -640,9 +645,10 @@ update_display (p_state *state, Bool changed_only)
             GC gc2 = ((cell->state + 2) < state->ticks
                       ? state->gcs[cell->state + 2]
                       : 0);
-            XCopyPlane (state->dpy, cell->p_char->pixmap, state->window,
-                        (gc2 ? gc2 : gc1),
-                        0, 0, width, height, tx, ty, 1L);
+            GC gc3 = (gc2 ? gc2 : gc1);
+            if (gc3)
+              XCopyPlane (state->dpy, cell->p_char->pixmap, state->window, gc3,
+                          0, 0, width, height, tx, ty, 1L);
             if (gc2)
               {
                 XSetClipMask (state->dpy, gc1, cell->p_char->pixmap2);
@@ -723,7 +729,7 @@ drain_input (p_state *state)
 {
   if (state->input_available_p)
     {
-      char s[2];
+      unsigned char s[2];
       int n = read (fileno (state->pipe), (void *) s, 1);
       if (n == 1)
         {
@@ -793,8 +799,8 @@ screenhack (Display *dpy, Window window)
       XSync (dpy, False);
       screenhack_handle_events (dpy);
 
-      if (XtAppPending (app) & (XtIMTimer|XtIMAlternateInput|XtIMSignal))
-        XtAppProcessEvent (app, XtIMTimer|XtIMAlternateInput|XtIMSignal);
+      if (XtAppPending (app) & (XtIMTimer|XtIMAlternateInput))
+        XtAppProcessEvent (app, XtIMTimer|XtIMAlternateInput);
 
       if (delay) usleep (delay);
     }