#include #include #include #include #include int main(void) { Display *d; Window w; XEvent e; cairo_surface_t *surface; cairo_t *cr; int s; d = XOpenDisplay(NULL); if (d == NULL) { fprintf(stderr, "Cannot open display\n"); exit(1); } s = DefaultScreen(d); w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1, BlackPixel(d, s), WhitePixel(d, s)); XSelectInput(d, w, ExposureMask | KeyPressMask); XMapWindow(d, w); surface = cairo_xlib_surface_create(d, w, DefaultVisual(d, s), 100, 100); cr = cairo_create(surface); while (1) { XNextEvent(d, &e); if (e.type == ConfigureNotify) { cairo_xlib_surface_set_size(surface, e.xconfigure.width, e.xconfigure.height); } if (e.type == Expose) { cairo_set_source_rgb(cr, 1, 1, 1); cairo_paint(cr); cairo_set_source_rgba(cr, 0, 0, 0, 0.2); cairo_rectangle(cr, 10, 10, 80, 80); cairo_fill(cr); cairo_rectangle(cr, 20, 20, 60, 60); cairo_fill(cr); cairo_rectangle(cr, 30, 30, 40, 40); cairo_fill(cr); cairo_rectangle(cr, 40, 40, 20, 20); cairo_fill(cr); cairo_surface_flush(surface); } if (e.type == KeyPress) break; } cairo_destroy(cr); cairo_surface_destroy(surface); XCloseDisplay(d); return 0; }