#include #include #include #include #include #include #include #include int main(int argc, char *argv[]) { Display *display; Window win, root; XEvent event; GC gc; XSetWindowAttributes a; int screen, depth, white, black, press; int x1, x2, y1, y2, x, y, w, h, m, quit; char buffer[10]; XpmAttributes xa; Pixmap pixmap, shape; Colormap colormap; if (!(display = XOpenDisplay(getenv("DISPLAY")))) { fprintf(stderr, "%s: unable to open display: %s\n", argv[0], getenv("DISPLAY")); exit(1); } screen = DefaultScreen(display); root = RootWindow(display, screen); depth = DefaultDepth(display, screen); colormap = DefaultColormap(display, screen); white = WhitePixel(display, screen); black = BlackPixel(display, screen); m = quit = 0; memset(&xa, 0, sizeof(XpmAttributes)); xa.valuemask = (XpmVisual | XpmDepth | XpmColormap); xa.visual = DefaultVisual(display, DefaultScreen(display)); xa.depth = depth; xa.colormap = colormap; XpmReadFileToPixmap(display, root, argv[1], &pixmap, &shape, &xa); x = y = 100; w = xa.width; h = xa.height; win = XCreateSimpleWindow(display, root, x, y, w, h, 0, black, black); XShapeCombineMask(display, win, ShapeBounding, 0, 0, shape, ShapeSet); gc = XCreateGC(display, pixmap, 0, 0); a.override_redirect = True; XChangeWindowAttributes(display, win, CWOverrideRedirect, &a); XSelectInput(display, win, ExposureMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask); XMapWindow(display, win); while (!quit) { XNextEvent(display, &event); switch(event.type) { case Expose: XCopyArea(display, pixmap, win, gc, 0, 0, w, h, 0, 0); break; case ButtonPress: press = 1; x1 = event.xbutton.x; y1 = event.xbutton.y; break; case ButtonRelease: press = 0; x1 = y1 = 0; break; case MotionNotify: x += event.xmotion.x-x1; y += event.xmotion.y-y1; XMoveWindow(display, win, x, y); break; } } printf("done\n"); XCloseDisplay(display); return 0; }