/* gcc -o test test.c -Wall -g `pkg-config --cflags --libs x11 cairo-xlib` */ #include #include #include #include #include #include static Visual *findArgbVisual (Display *d) { int screen = DefaultScreen (d); XVisualInfo *xvi; XVisualInfo temp; int nvi; int i; XRenderPictFormat *format; Visual *visual; temp.screen = screen; temp.depth = 32; temp.class = TrueColor; xvi = XGetVisualInfo (d, VisualScreenMask | VisualDepthMask | VisualClassMask, &temp, &nvi); if (!xvi) return 0; visual = 0; for (i = 0; i < nvi; i++) { format = XRenderFindVisualFormat (d, xvi[i].visual); if (format->type == PictTypeDirect && format->direct.alphaMask) { visual = xvi[i].visual; break; } } XFree (xvi); return visual; } int main (int argc, char **argv) { Display *d; Visual *v; XWindowAttributes wa; Window w, w2; cairo_surface_t *s, *s2; cairo_t *cr; d = XOpenDisplay(NULL); if(!d) return 1; v = findArgbVisual (d); if(!v) abort (); XSetWindowAttributes attr = {}; attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap (d, RootWindow(d, 0), v, AllocNone); w = XCreateWindow(d, RootWindow(d, 0), 0, 0, 1024, 768, 0, 32, InputOutput, v, CWBackPixel | CWBorderPixel | CWColormap, &attr); XMapWindow (d, w); s = cairo_xlib_surface_create (d, w, v, 1024, 768); cr = cairo_create (s); w2 = XCreateSimpleWindow (d, RootWindow(d, 0), 0, 0, 400, 400, 0, 0, 1234567); XMapWindow (d, w2); XGetWindowAttributes(d, w2, &wa); s2 = cairo_xlib_surface_create (d, w2, wa.visual, wa.width, wa.height); XFlush (d); XSync (d, w); cairo_save (cr); cairo_set_source_rgba (cr, 1.0, 0.0, 0.0, 0.5); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_paint (cr); cairo_restore (cr); cairo_matrix_t m; m.xx = m.yy = 2.0; /* XXX 1.0 doesn't crash xserver XXX */ m.xy = m.yx = 0.0; m.x0 = m.y0 = 0.0; cairo_pattern_t *p = cairo_pattern_create_for_surface (s2); cairo_pattern_set_matrix (p, &m); cairo_set_source (cr, p); cairo_paint (cr); cairo_pattern_destroy (p); XFlush (d); XSync (d, w); return 0; }