#include #include #include #include #include static int comp_event; static int comp_error; /* This program demonstrates that moving a redirected window around * when it is completely covered by a non-redirected one causes drawing * to happen in the wrong place. */ 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); } } static void paint_window (Display *dpy, Window window, unsigned long pixel) { XGCValues gc_values; GC gc; gc_values.foreground = pixel; gc = XCreateGC (dpy, window, GCForeground, &gc_values); XFillRectangle (dpy, window, gc, 0, 0, 32000, 32000); XFreeGC (dpy, gc); } 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); /* (4) paint the non-redirected window pink */ paint_window (dpy, non_redirected_window, 0x00ff00ff); /* pink */ /* (5) Paint the redirected window green */ paint_window (dpy, redirected_window, 0x0000ff00); /* green */ /* (6) Move the redirected window (10, 10) pixels (from 50,50 to 60,60) */ XMoveWindow (dpy, redirected_window, 60, 60); /* (7) Paint the redirected window yellow, eradicating all * traces of green */ paint_window (dpy, redirected_window, 0x00ffff00); /* yellow */ /* (8) Copy all of the redirected window to the non-redirected one. */ gc = XCreateGC (dpy, redirected_window, 0L, NULL); XCopyArea (dpy, redirected_window, non_redirected_window, gc, 0, 0, 500, 300, 0, 0); /* (9) Draw a black rectangle around the area where we copied the * redirected window */ XDrawRectangle (dpy, non_redirected_window, gc, 0, 0, 500, 300); /* * At this point, the non-redirected window should be mostly yellow * with a pink L-shaped region in the lower right corner. * There should be no trace of green since that was completely painted * over in step (7). * * However, we _do_ see an L-shaped, 10 pixels wide strip of green, * because somehow the borderClip didn't get updated correctly by the * MoveWindow request. */ XFlush (dpy); sleep (100); }