+
+
+static void
+popsquares_reshape (Display *dpy, Window window, void *closure,
+ unsigned int w, unsigned int h)
+{
+ struct state *st = (struct state *) closure;
+ int x, y;
+ XGetWindowAttributes (st->dpy, st->window, &st->xgwa);
+ st->sw = st->xgwa.width / st->subdivision;
+ st->sh = st->xgwa.height / st->subdivision;
+ st->gw = st->sw ? st->xgwa.width / st->sw : 0;
+ st->gh = st->sh ? st->xgwa.height / st->sh : 0;
+ st->nsquares = st->gw * st->gh;
+ free (st->squares);
+ st->squares = (square *) calloc (st->nsquares, sizeof(square));
+
+ for (y = 0; y < st->gh; y++)
+ for (x = 0; x < st->gw; x++)
+ {
+ square *s = (square *) &st->squares[st->gw * y + x];
+ s->w = st->sw;
+ s->h = st->sh;
+ s->x = x * st->sw;
+ s->y = y * st->sh;
+ }
+
+ randomize_square_colors(st->squares, st->nsquares, st->ncolors);
+
+ if (st->dbuf) {
+ XFreePixmap (dpy, st->ba);
+ XFreePixmap (dpy, st->bb);
+ st->ba = XCreatePixmap (st->dpy, st->window, st->xgwa.width, st->xgwa.height, st->xgwa.depth);
+ st->bb = XCreatePixmap (st->dpy, st->window, st->xgwa.width, st->xgwa.height, st->xgwa.depth);
+ st->b = st->ba;
+ }
+}
+
+static Bool
+popsquares_event (Display *dpy, Window window, void *closure, XEvent *event)
+{
+ return False;
+}
+
+static void
+popsquares_free (Display *dpy, Window window, void *closure)
+{
+ struct state *st = (struct state *) closure;
+ free (st);
+}
+
+
+static const char *popsquares_defaults [] = {
+ ".background: #0000FF",
+ ".foreground: #00008B",
+ "*delay: 25000",
+ "*subdivision: 5",
+ "*border: 1",
+ "*ncolors: 128",
+ "*twitch: False",
+ "*doubleBuffer: False",
+#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
+ "*useDBE: True",
+ "*useDBEClear: True",
+#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */
+#ifdef USE_IPHONE
+ "*ignoreRotation: True",
+#endif
+ 0
+};
+
+static XrmOptionDescRec popsquares_options [] = {
+ { "-fg", ".foreground", XrmoptionSepArg, 0},
+ { "-bg", ".background", XrmoptionSepArg, 0},
+ { "-delay", ".delay", XrmoptionSepArg, 0 },
+ { "-subdivision", ".subdivision", XrmoptionSepArg, 0 },
+ { "-border", ".border", XrmoptionSepArg, 0},
+ { "-ncolors", ".ncolors", XrmoptionSepArg, 0 },
+ { "-twitch", ".twitch", XrmoptionNoArg, "True" },
+ { "-no-twitch", ".twitch", XrmoptionNoArg, "False" },
+ { "-db", ".doubleBuffer", XrmoptionNoArg, "True" },
+ { "-no-db", ".doubleBuffer", XrmoptionNoArg, "False" },
+ { 0, 0, 0, 0 }
+};
+
+
+XSCREENSAVER_MODULE ("PopSquares", popsquares)