+
+static unsigned long
+boxfit_draw (Display *dpy, Window window, void *closure)
+{
+ state *st = (state *) closure;
+ int delay;
+
+ 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 */
+ {
+ st->image = XGetImage (st->dpy,
+ (st->loading_pixmap ? st->loading_pixmap :
+ st->window),
+ 0, 0,
+ st->xgwa.width, st->xgwa.height, ~0L,
+ ZPixmap);
+ if (st->loading_pixmap) XFreePixmap (st->dpy, st->loading_pixmap);
+ XSetWindowBackground (st->dpy, st->window, st->bg_color);
+ if (st->loading_pixmap)
+ XClearWindow (st->dpy, st->window);
+ else
+ st->countdown = 2000000;
+ st->loading_pixmap = 0;
+ }
+ return st->delay;
+ }
+
+ if (st->countdown > 0)
+ {
+ st->countdown -= st->delay;
+ if (st->countdown <= 0)
+ {
+ st->countdown = 0;
+ XClearWindow (st->dpy, st->window);
+ }
+ return st->delay;
+ }
+
+ if (st->growing_p) {
+ draw_boxes (st);
+ delay = grow_boxes (st);
+ } else {
+ delay = shrink_boxes (st);
+ draw_boxes (st);
+ }
+ return delay;
+}
+