#include #include #include static void print_event(XEvent *e) { switch (e->type) { case MapNotify: printf("got MapNotify event: window %lu event %lu\n", e->xmap.window, e->xmap.event); break; case ReparentNotify: printf("got ReparentNotify event: window %lu\n", e->xreparent.window); break; case MotionNotify: printf("got MotionNotify event: window %lu (%d,%d)\n", e->xmotion.window, e->xmotion.x, e->xmotion.y); break; case ButtonPress: printf("got ButtonPress event: window %lu (%d,%d)\n", e->xbutton.window, e->xbutton.x, e->xbutton.y); break; case ButtonRelease: printf("got ButtonRelease event: window %lu (%d,%d)\n", e->xbutton.window, e->xbutton.x, e->xbutton.y); break; case EnterNotify: printf("got EnterNotify event: window %lu (%d,%d)\n", e->xcrossing.window, e->xcrossing.x, e->xcrossing.y); break; case LeaveNotify: printf("got LeaveaNotify event: window %lu\n", e->xcrossing.window); break; case CreateNotify: printf("got CreateNotify event: window %lu, parent %lu\n", e->xcreatewindow.window, e->xcreatewindow.parent); break; case Expose: printf("got Expose event: window %lu at %d,%d size %dx%d\n", e->xexpose.window, e->xexpose.x, e->xexpose.y, e->xexpose.width, e->xexpose.height); break; case ConfigureNotify: printf("got ConfigureNotify event: window %lu event %lu at %d,%d size %dx%d\n", e->xconfigure.window, e->xconfigure.event, e->xconfigure.x, e->xconfigure.y, e->xconfigure.width, e->xconfigure.height); break; default: printf("got event type %d\n", e->type); break; } } static void run(Display *display, int event) { XEvent e; while (1) { XNextEvent(display, &e); print_event(&e); if (e.type == event) break; } } int main(int argc, char *argv[]) { Display *display; Window win, sub; XID root; XSetWindowAttributes attributes; Atom atom; display = XOpenDisplay(NULL); root = XRootWindow(display, 0); printf("opened display %p, root window is %lu\n", display, root); attributes.event_mask = ExposureMask | LeaveWindowMask | EnterWindowMask | Button1MotionMask | ButtonPressMask | ButtonReleaseMask | SubstructureNotifyMask | StructureNotifyMask; win = XCreateWindow(display, root, 100, 100, 200, 200, 0, 24, InputOutput, NULL, CWEventMask, &attributes); sub = XCreateWindow(display, win, 50, 50, 100, 100, 0, 24, InputOutput, NULL, CWEventMask, &attributes); printf("created window %lu and subwindow %lu\n", win, sub); atom = XInternAtom(display, "FOO", False); printf("FOO atom is %lu\n", atom); atom = XInternAtom(display, "BAR", False); printf("BAR atom is %lu\n", atom); atom = XInternAtom(display, "WINDOW", False); printf("WINDOW atom is %lu\n", atom); XMapWindow(display, win); /* Wait for ReparentNotify to get more similar behavior between csx and xlib: run(display, ReparentNotify); */ XMapWindow(display, sub); XMoveWindow(display, sub, 60, 60); XFlush(display); run(display, ButtonPress); XCloseDisplay(display); return 0; }