This is a patch file for "xearth" 1.1. This patch adds support for the "q", "Q", and/or Escape keys to XEarth [but only for X11 "-noroot" mode]. If you run the program in X11 "-noroot" mode and press one of these keys, the program should exit in about one second [or slightly less]. This file should be compatible with all distros that support the orig- inal program. --- xearth-1.1.old/x11.c +++ xearth-1.1/x11.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include "kljcpyrt.h" @@ -537,6 +538,14 @@ void x11_output() { + int x_wait_time; + + if (xearth_window) + { + XSelectInput (dsply, xearth_window, + KeyPressMask | KeyReleaseMask); + } + while (1) { compute_positions(); @@ -564,27 +573,48 @@ return; } - /* schedule an alarm for wait_time seconds and pause. alarm() and - * pause() are used instead of sleep so that if xearth is sent a - * SIGSTOP and SIGCONT separated by more than wait_time, it will - * refresh the screen as soon as the SIGCONT is received. this - * facilitates graceful interaction with things like FvwmBacker. - * (thanks to Richard Everson for passing this along.) - */ - signal(SIGALRM, wakeup); - signal(SIGCONT, wakeup); - if (wait_time > 0) - { - /* only do the alarm()/pause() stuff if wait_time is non-zero, - * else alarm() will not behave as desired. - */ - alarm(wait_time); - pause(); +//-------------------------------------------------------------------- + +// This code adds support for the "q", "Q", and/or Escape keys to +// XEarth [but only for X11 "-noroot" mode]. If you run the program in +// X11 "-noroot" mode and press one of these keys, the program should +// exit in about one second [or slightly less]. Note: This code as- +// sumes that an appropriate XSelectInput operation was performed be- +// fore the main loop was started. + + for (x_wait_time = wait_time; x_wait_time > 0; x_wait_time--) + { + while (XPending (dsply)) + { + XEvent event; + XNextEvent (dsply, &event); + + if (event.type == KeyPress) + { + KeySym ks = XLookupKeysym (&event.xkey, 0); + if ((ks == XK_Escape) || + (ks == XK_q) || (ks == XK_Q)) return; + } + } + +/* schedule an alarm for one second and pause. alarm() and pause() are + * used instead of sleep so that if xearth is sent a SIGSTOP and + * SIGCONT separated by more than one second, it will refresh the + * screen as soon as the SIGCONT is received. this facilitates graceful + * interaction with things like FvwmBacker. (thanks to Richard Everson + * for passing this along.) + */ + signal (SIGALRM, wakeup); + signal (SIGCONT, wakeup); + alarm (1); + pause(); } + +//-------------------------------------------------------------------- + } } - /* no-op signal handler for catching SIGALRM and SIGCONT * (used to wake up from pause() system call) */