#include #include #include #include static int comp_event; static int comp_error; /* This program shows that calling XCompositeUnredirect() on a window * will cause underlying _redirected_ windows to be exposed. */ static void disaster (const char *what) { fprintf (stderr, "Error: %s\n", what); exit (0); } static char * get_event_name (int type) { if (type == Expose) return "Expose"; else return "Unknown event type"; } static void dump_events (Display *dpy, const char *header) { XSync (dpy, False); if (header) printf ("%s", header); while (XPending (dpy)) { XEvent event; XNextEvent (dpy, &event); if (header) { printf (" event: %s (%lx)\n", get_event_name (event.type), event.xany.window); } } } int main (int argc, char **argv) { Display *dpy; Window main_window; Window redirected_window; Window non_redirected_window; dpy = XOpenDisplay (NULL); if (!XCompositeQueryExtension (dpy, &comp_event, &comp_error)) disaster ("No composite extension found\n"); /* Create main window */ main_window = XCreateSimpleWindow (dpy, XDefaultRootWindow (dpy), 100, 100, 600, 400, 0, 0, 0xffffffff); XMapWindow (dpy, main_window); XCompositeRedirectSubwindows (dpy, main_window, CompositeRedirectManual); /* Create redirected subwindow */ redirected_window = XCreateSimpleWindow (dpy, main_window, 50, 50, 500, 300, 0, 0, 0x000000ff); printf ("redirected window is %lx\n", redirected_window); XSelectInput (dpy, redirected_window, ExposureMask); XMapWindow (dpy, redirected_window); /* discard all events resulting from the map */ dump_events (dpy, NULL); /* Create unredirected subwindow, completely covering * the redirected one */ non_redirected_window = XCreateSimpleWindow (dpy, main_window, 25, 25, 550, 350, 0, 0, 0xaaaaaaaa); XMapWindow (dpy, non_redirected_window); /* discard all events resulting from the map */ dump_events (dpy, NULL); XCompositeUnredirectWindow (dpy, non_redirected_window, CompositeRedirectManual); dump_events (dpy, "events caused by unredirecting\n"); sleep (100); }