#include #include #include #include #include static int comp_event; static int comp_error; /* This program demonstrates that redirected windows that are * raised on top of non-redirected ones get their backgrounds * drawn and have expose events sent. */ static void disaster (const char *what) { fprintf (stderr, "Error: %s\n", what); exit (0); } 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: %d (%lx)\n", event.type, event.xany.window); } } int main (int argc, char **argv) { Display *dpy; Window main_window; Window redirected_window; Window non_redirected_window; XGCValues gc_values; GC gc; dpy = XOpenDisplay (NULL); /* Create main window */ main_window = XCreateSimpleWindow (dpy, XDefaultRootWindow (dpy), 100, 100, 600, 400, 0, 0, 0xffffffff); XMapWindow (dpy, main_window); if (!XCompositeQueryExtension (dpy, &comp_event, &comp_error)) disaster ("No composite extension found\n"); XCompositeRedirectSubwindows (dpy, main_window, CompositeRedirectManual); /* (1) Create redirected subwindow with a blue background */ redirected_window = XCreateSimpleWindow (dpy, main_window, 50, 50, 500, 300, 0, 0, 0x000000ff); XSelectInput (dpy, redirected_window, ExposureMask); XMapWindow (dpy, redirected_window); /* (2) 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); XCompositeUnredirectWindow (dpy, non_redirected_window, CompositeRedirectManual); /* Discard events caused by unredirect */ dump_events (dpy, NULL); /* (3) Paint the redirected window pink */ gc_values.foreground = 0x00ff00ff; /* pink */ gc = XCreateGC (dpy, redirected_window, GCForeground, &gc_values); XFillRectangle (dpy, redirected_window, gc, 0, 0, 1000, 300); /* (4) Copy all of the redirected window to the non-redirected one, * making the non-redirected window mostly pink */ XCopyArea (dpy, redirected_window, non_redirected_window, gc, 0, 0, 500, 300, 0, 0); /* Discard all events so far */ dump_events (dpy, NULL); /* (5) Sleep for one second, during which the non-redirected window should * be pink */ sleep (1); /* (6) Raise the redirected window. Since it's redirected, this * should have no effect, but it does: * * - expose events are sent * - the redirected window has its background painted * - damage events are also sent (not demonstrated by this program) * */ XRaiseWindow (dpy, redirected_window); dump_events (dpy, "Events after raising the redirected window"); /* (7) Raise the non redirected window again */ XRaiseWindow (dpy, non_redirected_window); /* (8) Paint it black */ gc_values.foreground = 0x00000000; gc = XCreateGC (dpy, non_redirected_window, GCForeground, &gc_values); XFillRectangle (dpy, non_redirected_window, gc, 0, 0, 550, 350); /* (9) Copy all of the redirected window to the non-redirected one */ XCopyArea (dpy, redirected_window, non_redirected_window, gc, 0, 0, 500, 300, 0, 0); XFlush (dpy); /* (10) We should now be seeing a pink rectangle, but we do in fact * see a blue one, since the redirected window had its background * painted */ sleep (100); }