-/* check_events(); originally from XScreensaver: hacks/maze.c,
- * but now quite heavily modified.
- *
- * Reaction to events:-
- *
- * Mouse 1 -- new figure }
- * 2 -- new figure }-- ignored when running on root window.
- * 3 -- exit }
- *
- * Window resized or exposed -- new figure.
- * Window iconised -- wait until it's re-mapped, then start a new figure.
- */
-static int
-check_events (void) /* X event handler [ rhess ] */
-{
- XEvent e;
- int unmapped = 0;
-
- while (unmapped || XPending(dpy))
- {
- XNextEvent(dpy, &e);
-
- switch (e.type)
- {
- case ButtonPress:
- switch (e.xbutton.button)
- {
- case 3:
- exit (0);
- break;
-
- case 2:
- case 1:
- default:
- restart = 1 ;
- stop = 0 ;
- break;
- }
- break;
-
- case ConfigureNotify:
- restart = 1;
- break;
-
- case UnmapNotify:
- printf("unmapped!\n");
- unmapped = 1;
- restart = 1; /* restart with new fig. when re-mapped. */
- break;
-
- case Expose:
- if (0 == e.xexpose.count)
- {
- /* We can get several expose events in the queue.
- * Only the last one has a zero count. We eat
- * events in this function so as to avoid restarting
- * the screensaver many times in quick succession.
- */
- restart = 1;
- }
- /* If we had been unmapped and are now waiting to be re-mapped,
- * indicate that we condition we are waiting for is now met.
- */
- if (unmapped)
- printf("re-mapped!\n");
- unmapped = 0;
- break;
- }
-
- /* If we're unmapped, don't return to the caller. This
- * prevents us wasting CPU, calculating new positions for
- * things that will never be plotted. This is a real CPU
- * saver.
- */
- if (!unmapped)
- return 1;
- }
- return 0;
-}