Sử dụng khung trên OS X, tôi có thể sử dụng sau đây để sao chép một PNG với tông (trong C - rõ ràng là tôi có thể sử dụng NSPasteboard với Cocoa):Làm thế nào để sao chép vào clipboard bằng X11?
#include <ApplicationServices/ApplicationServices.h>
int copyThatThing(void)
{
PasteboardRef clipboard;
if (PasteboardCreate(kPasteboardClipboard, &clipboard) != noErr) {
return -1;
}
if (PasteboardClear(clipboard) != noErr) {
CFRelease(clipboard);
return -1;
}
size_t len;
char *pngbuf = createMyPNGBuffer(&len); /* Defined somewhere else */
if (pngbuf == NULL) {
CFRelease(clipboard);
return -1;
}
CFDataRef data = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, pngbuf,
len, kCFAllocatorNull);
if (data == NULL) {
CFRelease(clipboard);
free(pngbuf);
return -1;
}
OSStatus err;
err = PasteboardPutItemFlavor(clipboard, NULL, kUTTypePNG, data, 0);
CFRelease(clipboard);
CFRelease(data);
free(pngbuf);
return 0;
}
Tôi quan tâm đến porting chức năng này để Nền tảng Linux/* BSD. Làm thế nào tôi có thể tái tạo điều này bằng cách sử dụng X?
Cảm ơn rất nhiều. Rất hữu ích, với công cụ chụp màn hình compiz! – Drasill
Kịch bản gọn gàng! Các mục sau đây trên superuser cũng chứa một kịch bản python tương tự, nhưng nó chỉ hoạt động theo gnome: http://superuser.com/questions/301851/how-to-copy-a-picture-to-clipboard-from-command-line -in-linux – qed
Có nhiều cách để cải thiện điều này. Ví dụ: chúng ta có thể làm cho nó tự động giết gtk.main khi nội dung trong clipboard được dán không? – qed