+static void *
+ripples_init (Display *disp, Window win)
+{
+ struct state *st = (struct state *) calloc (1, sizeof(*st));
+ st->dpy = disp;
+ st->window = win;
+ st->iterations = 0;
+ st->delay = get_integer_resource(disp, "delay", "Integer");
+ st->duration = get_integer_resource (st->dpy, "duration", "Seconds");
+ st->rate = get_integer_resource(disp, "rate", "Integer");
+ st->box = get_integer_resource(disp, "box", "Integer");
+ st->oily = get_boolean_resource(disp, "oily", "Boolean");
+ st->stir = get_boolean_resource(disp, "stir", "Boolean");
+ st->fluidity = get_integer_resource(disp, "fluidity", "Integer");
+ st->transparent = get_boolean_resource(disp, "water", "Boolean");
+ st->grayscale_p = get_boolean_resource(disp, "grayscale", "Boolean");
+#ifdef HAVE_XSHM_EXTENSION
+ st->use_shm = get_boolean_resource(disp, "useSHM", "Boolean");
+#endif /* HAVE_XSHM_EXTENSION */
+ st->light = get_integer_resource(disp, "light", "Integer");
+
+ if (st->delay < 0) st->delay = 0;
+ if (st->duration < 1) st->duration = 1;
+ if (st->fluidity <= 1) st->fluidity = 1;
+ if (st->fluidity > 16) st->fluidity = 16; /* 16 = sizeof(short) */
+ if (st->light < 0) st->light = 0;
+
+ init_cos_tab(st);
+ setup_X(st);
+
+ st->ncolors = get_integer_resource (disp, "colors", "Colors");
+ if (0 == st->ncolors) /* English spelling? */
+ st->ncolors = get_integer_resource (disp, "colours", "Colors");
+
+ if (st->ncolors > sizeof(st->ctab)/sizeof(*st->ctab))
+ st->ncolors = sizeof(st->ctab)/sizeof(*st->ctab);
+
+ if (st->oily)
+ init_oily_colors(st);
+ else
+ init_linear_colors(st);
+
+ if (st->transparent && st->light > 0) {
+ int maxbits;
+ st->draw_transparent = draw_transparent_light;
+ set_mask(st->visual->red_mask, &st->rmask, &st->rshift);
+ set_mask(st->visual->green_mask, &st->gmask, &st->gshift);
+ set_mask(st->visual->blue_mask, &st->bmask, &st->bshift);
+ if (st->rmask == 0) st->draw_transparent = draw_transparent_vanilla;
+
+ /* Adjust the shift value "light" when we don't have 8 bits per colour */
+ maxbits = MIN(MIN(BITCOUNT(st->rmask), BITCOUNT(st->gmask)), BITCOUNT(st->bmask));
+ st->light -= 8-maxbits;
+ if (st->light < 0) st->light = 0;
+ } else {
+ if (st->grayscale_p)
+ {
+ set_mask(st->visual->red_mask, &st->rmask, &st->rshift);
+ set_mask(st->visual->green_mask, &st->gmask, &st->gshift);
+ set_mask(st->visual->blue_mask, &st->bmask, &st->bshift);
+ }
+ st->draw_transparent = draw_transparent_vanilla;
+ }
+
+ if (!st->transparent)
+ init_ripples(st, 0, -SPLASH); /* Start off without any drops */
+
+ return st;
+}
+
+static unsigned long
+ripples_draw (Display *dpy, Window window, void *closure)
+{
+ struct state *st = (struct state *) closure;
+
+ if (st->img_loader) /* still loading */
+ {
+ st->img_loader = load_image_async_simple (st->img_loader, 0, 0, 0, 0, 0);
+ if (! st->img_loader) { /* just finished */
+ XWindowAttributes xgwa;
+ XGetWindowAttributes(st->dpy, st->window, &xgwa);
+ st->start_time = time ((time_t) 0);
+ st->orig_map = XGetImage (st->dpy, st->window, 0, 0,
+ xgwa.width, xgwa.height,
+ ~0L, ZPixmap);
+ init_ripples(st, 0, -SPLASH); /* Start off without any drops */
+ }
+ return st->delay;
+ }
+
+ if (!st->img_loader &&
+ st->start_time + st->duration < time ((time_t) 0)) {
+ XWindowAttributes xgwa;
+ XGetWindowAttributes(st->dpy, st->window, &xgwa);
+ st->img_loader = load_image_async_simple (0, xgwa.screen, st->window,
+ st->window, 0, 0);
+ st->start_time = time ((time_t) 0);
+ return st->delay;
+ }
+
+ if (st->rate > 0 && (st->iterations % st->rate) == 0)
+ add_drop(st, ripple_blob, -SPLASH);
+ if (st->stir)
+ add_drop(st, ripple_stir, -SPLASH);
+ if (st->box > 0 && (random() % st->box) == 0)
+ add_drop(st, ripple_box, -SPLASH);
+
+ ripple(st);
+ DisplayImage(st);
+
+ st->iterations++;
+
+ return st->delay;
+}
+
+
+static void
+ripples_reshape (Display *dpy, Window window, void *closure,
+ unsigned int w, unsigned int h)
+{
+}
+
+static Bool
+ripples_event (Display *dpy, Window window, void *closure, XEvent *event)
+{
+ return False;
+}