//This is a neat program, it dump the x-windows clipboard to stdout. //gcc -O2 -Wall t.c -o t -lXxf86vm #include #include #include #include #define MAX_CLIP_SIZE 16384 Display *disp; Window w; Atom x11_clipboard; char nothing; char *clip_get(void) { unsigned char *xdata; Atom prop, type; unsigned long len, dummy; int fmt; if(!(x11_clipboard = XInternAtom(disp, "CLIPBOARD", True))) return ¬hing; w = XGetSelectionOwner(disp, x11_clipboard); if(w==0) return ¬hing; prop = 1; XChangeProperty(disp, w, prop, XA_STRING, 8, PropModeReplace, (unsigned char *)"", 0); XConvertSelection(disp,x11_clipboard, XA_STRING, prop, w, CurrentTime); XFlush(disp); XGetWindowProperty(disp, w, prop, 0, MAX_CLIP_SIZE,0, AnyPropertyType, &type, &fmt, &len, &dummy, &xdata); if(len == 0) return ¬hing; if(len>MAX_CLIP_SIZE) return ¬hing; return xdata; } int main(void) { if(!(disp = XOpenDisplay(NULL))) { fprintf(stderr,"cannot open display\n"); exit(-1); } nothing = 0; printf(clip_get()); }