#include #include #include #include #include static int damage_event; static int damage_error; /* This program demonstrates that just moving a window * around generates damage events on it. */ static void disaster (const char *what) { fprintf (stderr, "Error: %s\n", what); exit (0); } static void dump_events (Display *dpy, const char *header) { int did_header = 0; XSync (dpy, False); while (XPending (dpy)) { XEvent event; XNextEvent (dpy, &event); if (header) { if (!did_header) { printf ("%s", header); did_header = 1; } if (event.type == damage_event) { printf (" event: damage (%lx)\n", event.xany.window); } } } } int main (int argc, char **argv) { Display *dpy; Window main_window; Window subwindow; int pos; int i; dpy = XOpenDisplay (NULL); if (!XDamageQueryExtension (dpy, &damage_event, &damage_error)) ; /* Create main window */ main_window = XCreateSimpleWindow (dpy, XDefaultRootWindow (dpy), 100, 100, 600, 400, 0, 0, 0xffffffff); XMapWindow (dpy, main_window); /* (1) Create blue subwindow */ subwindow = XCreateSimpleWindow (dpy, main_window, 50, 50, 500, 300, 0, 0, 0x000000ff); printf ("ID of subwindow: %lx\n", subwindow); XDamageCreate (dpy, subwindow, XDamageReportRawRectangles); XMapWindow (dpy, subwindow); XFlush (dpy); pos = 50; for (i = 0; i < 10; ++i) { dump_events (dpy, "events\n"); pos += 5; if (pos > 100) pos = 0; XMoveWindow (dpy, subwindow, pos, 50); usleep (5000); XFlush (dpy); } sleep (10); }