[email protected] | 7ab7116 | 2009-01-05 22:28:53 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include <gtk/gtk.h> |
| 6 | #include <stdio.h> |
| 7 | #include <string.h> |
| 8 | |
| 9 | /* Small program to dump the contents of GTK's clipboard to the terminal. |
| 10 | * Feel free to add to it or improve formatting or whatnot. |
| 11 | */ |
| 12 | int main(int argc, char* argv[]) { |
| 13 | gtk_init(&argc, &argv); |
| 14 | GdkAtom* targets; |
| 15 | int num_targets = 0; |
| 16 | // For now only look at GDK_SELECTION_CLIPBOARD. This could be extended |
| 17 | // to look at GDK_SELECTION_PRIMARY (the X clipboard). |
| 18 | GtkClipboard* clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); |
| 19 | |
| 20 | gtk_clipboard_wait_for_targets(clip, &targets, &num_targets); |
| 21 | |
| 22 | printf("Available targets:\n---------------\n"); |
| 23 | |
| 24 | for (int i = 0; i < num_targets; i++) { |
| 25 | printf(" [format: %s", gdk_atom_name(targets[i])); |
| 26 | GtkSelectionData* data = gtk_clipboard_wait_for_contents(clip, targets[i]); |
| 27 | if (!data) { |
| 28 | printf("]: NULL\n\n"); |
| 29 | continue; |
| 30 | } |
| 31 | |
| 32 | printf(" / length: %d / bits %d]: ", data->length, data->format); |
| 33 | for (int j = 0; j < data->length; j++) { |
| 34 | // Output data one byte at a time. Currently wide strings look |
| 35 | // pretty weird. |
| 36 | printf("%c", (data->data[j] == 0 ? '_' : data->data[j])); |
| 37 | } |
| 38 | printf("\n\n"); |
| 39 | } |
| 40 | } |
| 41 | |