/* * gcc -o subwindow-field $(pkg-config --cflags --libs x11) subwindow-field.c */ #include #include #include #include #include #include #include #include int main(int argc, char **argv) { Display *dpy; Screen *scr; Window win, subwin; XEvent ev; unsigned long pixel; dpy = XOpenDisplay(NULL); if (dpy == NULL) { fprintf (stderr, "Failed to open display\n"); exit (1); } scr = DefaultScreenOfDisplay (dpy); pixel = BlackPixel (dpy, DefaultScreen (dpy)); win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 500, 500, 0, pixel, pixel); subwin = XCreateSimpleWindow(dpy, win, 0, 0, 500, 500, 0, pixel, pixel); XSelectInput(dpy, win, ButtonPressMask|ButtonReleaseMask); XMapWindow(dpy, subwin); XMapWindow(dpy, win); while (1) { XNextEvent(dpy, &ev); if (ev.type == ButtonPress) { XButtonEvent *bev = (XButtonEvent *) &ev; fprintf (stdout, "ButtonPress %i received in window 0x%lx, subwindow 0x%lx\n", bev->button, bev->window, bev->subwindow); if (bev->subwindow == subwin) fprintf (stdout, "*** SUCCESS *** Subwindow is set\n"); else fprintf (stderr, "*** FAILURE *** Subwindow is not set\n"); } } return 0; }