#include #include #include #include #include #include #include // This function comes from GIMP packages (tools/test-clipboard.c) static gboolean test_clipboard_paste (GtkClipboard *clipboard, const gchar *target, const gchar *filename) { GtkSelectionData *sel_data; sel_data = gtk_clipboard_wait_for_contents (clipboard, gdk_atom_intern (target, FALSE)); if (sel_data) { const guchar *data; gint length; gint fd; if (! strcmp (filename, "-")) fd = 1; else fd = open (filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) { g_printerr ("%s: open() filed: %s", g_get_prgname (), g_strerror (errno)); return FALSE; } data = gtk_selection_data_get_data (sel_data); length = gtk_selection_data_get_length (sel_data); if (write (fd, data, length) < length) { close (fd); g_printerr ("%s: write() failed: %s", g_get_prgname (), g_strerror (errno)); return FALSE; } if (close (fd) < 0) { g_printerr ("%s: close() failed: %s", g_get_prgname (), g_strerror (errno)); return FALSE; } gtk_selection_data_free (sel_data); } return TRUE; } int main(int argc, char** argv) { GtkClipboard *clipboard; gtk_init(&argc, &argv); GdkDisplay* display = gdk_display_get_default(); if(display == NULL) { perror("gdk_display_get_default"); exit(1); } clipboard = gtk_clipboard_get_for_display (display, GDK_SELECTION_CLIPBOARD); test_clipboard_paste(clipboard, "image/png", "./out.bin"); exit(0); }