Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(889)

Side by Side Diff: tools/gtk_clipboard_dump/gtk_clipboard_dump.cc

Issue 55052: Copy selection to x clipboard. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/render_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <gtk/gtk.h> 5 #include <gtk/gtk.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 /* Small program to dump the contents of GTK's clipboard to the terminal. 9 namespace {
10 * Feel free to add to it or improve formatting or whatnot. 10
11 */ 11 void PrintClipboardContents(GtkClipboard* clip) {
12 int main(int argc, char* argv[]) {
13 gtk_init(&argc, &argv);
14 GdkAtom* targets; 12 GdkAtom* targets;
15 int num_targets = 0; 13 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); 14 gtk_clipboard_wait_for_targets(clip, &targets, &num_targets);
21 15
22 printf("Available targets:\n---------------\n"); 16 printf("Available targets:\n---------------\n");
23 17
24 for (int i = 0; i < num_targets; i++) { 18 for (int i = 0; i < num_targets; i++) {
25 printf(" [format: %s", gdk_atom_name(targets[i])); 19 printf(" [format: %s", gdk_atom_name(targets[i]));
26 GtkSelectionData* data = gtk_clipboard_wait_for_contents(clip, targets[i]); 20 GtkSelectionData* data = gtk_clipboard_wait_for_contents(clip, targets[i]);
27 if (!data) { 21 if (!data) {
28 printf("]: NULL\n\n"); 22 printf("]: NULL\n\n");
29 continue; 23 continue;
30 } 24 }
31 25
32 printf(" / length: %d / bits %d]: ", data->length, data->format); 26 printf(" / length: %d / bits %d]: ", data->length, data->format);
33 27
34 if (strstr(gdk_atom_name(targets[i]), "image")) { 28 if (strstr(gdk_atom_name(targets[i]), "image")) {
35 printf("(image omitted)\n\n"); 29 printf("(image omitted)\n\n");
36 continue; 30 continue;
31 } else if (strstr(gdk_atom_name(targets[i]), "TIMESTAMP")) {
32 // TODO(estade): Print the time stamp in human readable format.
33 printf("(time omitted)\n\n");
34 continue;
37 } 35 }
38 36
39 for (int j = 0; j < data->length; j++) { 37 for (int j = 0; j < data->length; j++) {
40 // Output data one byte at a time. Currently wide strings look 38 // Output data one byte at a time. Currently wide strings look
41 // pretty weird. 39 // pretty weird.
42 printf("%c", (data->data[j] == 0 ? '_' : data->data[j])); 40 printf("%c", (data->data[j] == 0 ? '_' : data->data[j]));
43 } 41 }
44 printf("\n\n"); 42 printf("\n\n");
45 } 43 }
46 } 44 }
45
46 }
47
48 /* Small program to dump the contents of GTK's clipboards to the terminal.
49 * Feel free to add to it or improve formatting or whatnot.
50 */
51 int main(int argc, char* argv[]) {
52 gtk_init(&argc, &argv);
53
54 printf("Desktop clipboard\n");
55 PrintClipboardContents(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
56
57 printf("X clipboard\n");
58 PrintClipboardContents(gtk_clipboard_get(GDK_SELECTION_PRIMARY));
59 }
OLDNEW
« no previous file with comments | « chrome/renderer/render_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698