+static void
+xlockmore_check_init (ModeInfo *mi)
+{
+ if (! xlockmore_got_init (mi)) {
+ xlockmore_abort_erase (mi);
+ xlockmore_do_init (mi);
+ }
+}
+
+
+static unsigned long
+xlockmore_draw (Display *dpy, Window window, void *closure)
+{
+ ModeInfo *mi = (ModeInfo *) closure;
+ unsigned long orig_pause = mi->pause;
+ unsigned long this_pause;
+
+ if (mi->needs_clear) {
+ /* OpenGL hacks never get here. */
+ if (!mi->is_drawn) {
+ xlockmore_clear (mi);
+ } else {
+ mi->eraser = erase_window (dpy, window, mi->eraser);
+ /* Delay calls to xlockmore hooks while the erase animation is running. */
+ if (mi->eraser)
+ return 33333;
+ }
+ mi->needs_clear = False;
+ }
+
+ xlockmore_check_init (mi);
+ if (mi->needs_clear)
+ return 0;
+ mi->xlmft->hack_draw (mi);
+
+ this_pause = mi->pause;
+ mi->pause = orig_pause;
+ return mi->needs_clear ? 0 : this_pause;
+}
+
+
+static void
+xlockmore_reshape (Display *dpy, Window window, void *closure,
+ unsigned int w, unsigned int h)
+{
+ ModeInfo *mi = (ModeInfo *) closure;
+ if (mi) {
+ /* Ignore spurious resize events, because xlockmore_do_init usually clears
+ the screen, and there's no reason to do that if we don't have to.
+ */
+# ifndef HAVE_MOBILE
+ /* These are not spurious on mobile: they are rotations. */
+ if (mi->xgwa.width == w && mi->xgwa.height == h)
+ return;
+# endif
+ mi->xgwa.width = w;
+ mi->xgwa.height = h;
+
+ /* Finish any erase operations. */
+ if (mi->needs_clear) {
+ xlockmore_abort_erase (mi);
+ xlockmore_clear (mi);
+ }
+
+ /* If there hasn't been an init yet, init now, but don't call reshape_##.
+ */
+ if (xlockmore_got_init (mi) && mi->xlmft->hack_reshape) {
+ mi->xlmft->hack_reshape (mi, mi->xgwa.width, mi->xgwa.height);
+ } else {
+ mi->is_drawn = False;
+ xlockmore_do_init (mi);
+ }
+ }
+}
+
+static Bool
+xlockmore_event (Display *dpy, Window window, void *closure, XEvent *event)
+{
+ ModeInfo *mi = (ModeInfo *) closure;
+ if (mi) {
+ if (mi->xlmft->hack_handle_events) {
+ xlockmore_check_init (mi);
+ return mi->xlmft->hack_handle_events (mi, event);
+ }
+
+ if (screenhack_event_helper (mi->dpy, mi->window, event)) {
+ /* If a clear is in progress, don't interrupt or restart it. */
+ if (mi->needs_clear)
+ mi->xlmft->got_init &= ~(1ul << mi->screen_number);
+ else
+ mi->xlmft->hack_init (mi);
+ return True;
+ }
+ }
+ return False;
+}
+
+void
+xlockmore_do_fps (Display *dpy, Window w, fps_state *fpst, void *closure)
+{
+ ModeInfo *mi = (ModeInfo *) closure;
+ fps_compute (fpst, 0, mi ? mi->recursion_depth : -1);
+ fps_draw (fpst);
+}
+
+
+static void
+xlockmore_free (Display *dpy, Window window, void *closure)
+{
+ ModeInfo *mi = (ModeInfo *) closure;
+
+ if (mi->eraser)
+ eraser_free (mi->eraser);
+
+ /* Some hacks may need to do things with their Display * on cleanup. And
+ under JWXYZ, the Display * for this hack gets cleaned up right after
+ xlockmore_free returns. Thus, hack_free has to happen now, rather than
+ after the final screen has been released.
+ */
+ if (mi->xlmft->hack_free)
+ mi->xlmft->hack_free (mi);
+
+ /* Find us in live_displays and clear that slot. */
+ assert (mi->xlmft->live_displays & (1ul << mi->screen_number));
+ mi->xlmft->live_displays &= ~(1ul << mi->screen_number);
+ if (!mi->xlmft->live_displays)
+ xlockmore_release_screens (mi);