#include MUT_H
#include <stdio.h>
#include <signal.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>

/* Thanx :
   Mechanism explained to me by Steve Gallichio, steveg@cadkey.com. */

main(argc, argv)
int argc;
char **argv;
{
Window vwin, ewin, twin; /* All Genview windows since no Parent window exists */
int gpid;                /* Genview process id, to kill INT it */
XEvent event;
Display *display;
KeySym key;
char text;

	if (!(display = XOpenDisplay(argv[1]))) {
		fprintf(stderr, " %s unable to connect with server '%s'\n",
					argv[0], argv[1]);
		EXIT(-1);
	}
	vwin = atoi(argv[2]);
	ewin = atoi(argv[3]);
	twin = atoi(argv[4]);
	gpid = atoi(argv[5]);

	
	XSelectInput(display, vwin, KeyPressMask);
	XSelectInput(display, ewin, KeyPressMask);
	XSelectInput(display, twin, KeyPressMask);

	while (1) {
		XNextEvent(display, &event);
		switch (event.type) {
			case KeyPress:
				(void)XLookupString(&event.xkey, &text, 1, &key, 0);
				if (text == '\003') {
					kill(gpid, SIGINT);
					text = '\0';
					continue;
				}
		}
/*
		XPutBackEvent(display, &event);
*/
	}
}
