1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
11 void PrintClipboardContents(GtkClipboard
* clip
) {
15 // This call is bugged, the cache it checks is often stale; see
16 // <http://bugzilla.gnome.org/show_bug.cgi?id=557315>.
17 // gtk_clipboard_wait_for_targets(clip, &targets, &num_targets);
19 GtkSelectionData
* target_data
=
20 gtk_clipboard_wait_for_contents(clip
,
21 gdk_atom_intern("TARGETS", false));
23 printf("failed to get the contents!\n");
27 gtk_selection_data_get_targets(target_data
, &targets
, &num_targets
);
29 printf("%d available targets:\n---------------\n", num_targets
);
31 for (int i
= 0; i
< num_targets
; i
++) {
32 printf(" [format: %s", gdk_atom_name(targets
[i
]));
33 GtkSelectionData
* data
= gtk_clipboard_wait_for_contents(clip
, targets
[i
]);
35 printf("]: NULL\n\n");
39 printf(" / length: %d / bits %d]: ", data
->length
, data
->format
);
41 if (strstr(gdk_atom_name(targets
[i
]), "image")) {
42 printf("(image omitted)\n\n");
44 } else if (strstr(gdk_atom_name(targets
[i
]), "TIMESTAMP")) {
45 // TODO(estade): Print the time stamp in human readable format.
46 printf("(time omitted)\n\n");
50 for (int j
= 0; j
< data
->length
; j
++) {
51 // Output data one byte at a time. Currently wide strings look
53 printf("%c", (data
->data
[j
] == 0 ? '_' : data
->data
[j
]));
58 if (num_targets
<= 0) {
59 printf("No targets advertised. Text is: ");
60 gchar
* text
= gtk_clipboard_wait_for_text(clip
);
61 printf("%s\n", text
? text
: "NULL");
70 /* Small program to dump the contents of GTK's clipboards to the terminal.
71 * Feel free to add to it or improve formatting or whatnot.
73 int main(int argc
, char* argv
[]) {
74 gtk_init(&argc
, &argv
);
76 printf("Desktop clipboard\n");
77 PrintClipboardContents(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD
));
79 printf("X clipboard\n");
80 PrintClipboardContents(gtk_clipboard_get(GDK_SELECTION_PRIMARY
));