-static struct coo xy_coo[10];
-
-static int delay, radius, speed, number, blackhole, vortex, magnify, reflect, slow;
-static XWindowAttributes xgwa;
-static GC gc;
-static Window g_window;
-static Display *g_dpy;
-static unsigned long black_pixel;
-
-static XImage *orig_map, *buffer_map;
-static unsigned long *buffer_map_cache;
-
-static int ***from;
-static int ****from_array;
-static int *fast_from = NULL;
-static void (*effect) (int) = NULL;
-static void move_lense(int);
-static void swamp_thing(int);
-static void new_rnd_coo(int);
-static void init_round_lense(void);
-static void (*draw) (int) = NULL;
-static void reflect_draw(int);
-static void plain_draw(int);
-
-static void (*draw_routine)(XImage *, XImage *, int, int, int *) = NULL;
-static void fast_draw_8(XImage *, XImage *, int, int, int *);
-static void fast_draw_16(XImage *, XImage *, int, int, int *);
-static void fast_draw_32(XImage *, XImage *, int, int, int *);
-static void generic_draw(XImage *, XImage *, int, int, int *);
-static int bpp_size = 0;
-
-
-static void init_distort(Display *dpy, Window window)
+
+struct state {
+ Display *dpy;
+ Window window;
+
+ struct coo xy_coo[10];
+
+ int delay, radius, speed, number, blackhole, vortex, magnify, reflect, slow;
+ int duration;
+ time_t start_time;
+
+ XWindowAttributes xgwa;
+ GC gc;
+ unsigned long black_pixel;
+
+ XImage *orig_map, *buffer_map;
+ unsigned long *buffer_map_cache;
+
+ int ***from;
+ int ****from_array;
+ int *fast_from;
+
+ int bpp_size;
+
+#ifdef HAVE_XSHM_EXTENSION
+ Bool use_shm;
+ XShmSegmentInfo shm_info;
+#endif /* HAVE_XSHM_EXTENSION */
+
+ void (*effect) (struct state *, int);
+ void (*draw) (struct state *, int);
+ void (*draw_routine) (struct state *st, XImage *, XImage *, int, int, int *);
+
+ async_load_state *img_loader;
+};
+
+
+static void move_lense(struct state *, int);
+static void swamp_thing(struct state *, int);
+static void new_rnd_coo(struct state *, int);
+static void init_round_lense(struct state *st);
+static void reflect_draw(struct state *, int);
+static void plain_draw(struct state *, int);
+
+static void fast_draw_8 (struct state *st, XImage *, XImage *, int, int, int *);
+static void fast_draw_16(struct state *st, XImage *, XImage *, int, int, int *);
+static void fast_draw_32(struct state *st, XImage *, XImage *, int, int, int *);
+static void generic_draw(struct state *st, XImage *, XImage *, int, int, int *);
+
+
+static void distort_finish_loading (struct state *);
+
+static void *
+distort_init (Display *dpy, Window window)