#include #include #include int main(int argc, char **argv) { Display *display; Screen *screen; Window root, window; GC gc; Pixmap pixmap; int sw = 320, sh = 320, dw = 320, dh = 320; int event_base, error_base, major_version, minor_version; XRenderPictFormat *format; Picture dest_pict, src_pict; XTransform transform = { { {1 << 16, 0, 0}, {0, 1 << 16, 0}, {0, 0, 1 << 16} } }; long black_pixel; XRenderColor white = {0xffff, 0xffff, 0xffff, 0xffff}; display = XOpenDisplay(NULL); if (display == NULL) { return 1; } if (!XRenderQueryExtension(display, &event_base, &error_base) || !XRenderQueryVersion(display, &major_version, &minor_version) || (major_version != 0 || minor_version < 6)) { XCloseDisplay(display); return 1; } screen = DefaultScreenOfDisplay(display); root = RootWindowOfScreen(screen); black_pixel = BlackPixelOfScreen(screen); format = XRenderFindVisualFormat(display, DefaultVisualOfScreen(screen)); pixmap = XCreatePixmap(display, root, sw, sh, DefaultDepthOfScreen(screen)); src_pict = XRenderCreatePicture(display, pixmap, format, 0, NULL); XRenderFillRectangle(display, PictOpSrc, src_pict, &white, 0, 0, sw, sh); window = XCreateSimpleWindow(display, root, 0, 0, dw, dh, 1, black_pixel, black_pixel); gc = XCreateGC(display, window, 0, NULL); XSelectInput(display, window, KeyPressMask | ButtonPressMask | ExposureMask | StructureNotifyMask); dest_pict = XRenderCreatePicture(display, window, format, 0, NULL); XMapWindow(display, window); while (1) { XEvent event; XNextEvent(display, &event); switch (event.type) { case KeyPress: case ButtonPress: break; case Expose: if (event.xexpose.count == 0) { XRenderComposite(display, PictOpSrc, src_pict, None, dest_pict, 0, 0, 0, 0, 0, 0, dw, dh); } continue; case ConfigureNotify: if (event.xconfigure.width != dw || event.xconfigure.height != dh) { dw = event.xconfigure.width; dh = event.xconfigure.height; transform.matrix[0][0] = (sw << 16) / dw; transform.matrix[1][1] = (sh << 16) / dh; XRenderSetPictureTransform(display, src_pict, &transform); XRenderComposite(display, PictOpSrc, src_pict, None, dest_pict, 0, 0, 0, 0, 0, 0, dw, dh); } continue; default: continue; } break; } XRenderFreePicture(display, src_pict); XRenderFreePicture(display, dest_pict); XDestroyWindow(display, window); XCloseDisplay(display); return 0; }