#include <stdio.h>
#include <X11/Xlib.h>

static const char  *const TxtEventNames[] = {
   "Error", "Reply", "KeyPress", "KeyRelease", "ButtonPress",
   "ButtonRelease", "MotionNotify", "EnterNotify", "LeaveNotify", "FocusIn",
   "FocusOut", "KeymapNotify", "Expose", "GraphicsExpose", "NoExpose",
   "VisibilityNotify", "CreateNotify", "DestroyNotify", "UnmapNotify",
   "MapNotify",
   "MapRequest", "ReparentNotify", "ConfigureNotify", "ConfigureRequest",
   "GravityNotify",
   "ResizeRequest", "CirculateNotify", "CirculateRequest", "PropertyNotify",
   "SelectionClear",
   "SelectionRequest", "SelectionNotify", "ColormapNotify", "ClientMessage",
   "MappingNotify"
};
#define N_EVENT_NAMES (sizeof(TxtEventNames)/sizeof(char*))

int
main(int argc, char **argv)
{
   long                mask;
   Window              xwin;
   XSetWindowAttributes attr;
   XEvent              ev;
   Display            *disp;

   disp = XOpenDisplay(NULL);
   if (!disp)
     {
	printf("Failed to open display\n");
	return 1;
     }

   attr.background_pixel = 0x0000ff;
   xwin = XCreateWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 1,
			CopyFromParent, InputOutput, CopyFromParent,
			CWBackPixel, &attr);
   mask =
      KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
      EnterWindowMask | LeaveWindowMask | PointerMotionMask;
   XSelectInput(disp, xwin, mask);
   XMapWindow(disp, xwin);

   attr.background_pixel = 0xff0000;
   attr.do_not_propagate_mask = PointerMotionMask;
   xwin = XCreateWindow(disp, xwin, 0, 0, 50, 100, 1,
			CopyFromParent, InputOutput, CopyFromParent,
			CWBackPixel | CWDontPropagate, &attr);
   XMapWindow(disp, xwin);

   XSync(disp, False);

   for (;;)
     {
	XNextEvent(disp, &ev);
	printf("xev type=%2d: %s\n", ev.type, TxtEventNames[ev.type]);
     }

   return 0;
}
