summaryrefslogtreecommitdiffstats
path: root/tools/gtk_clipboard_dump
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-05 22:28:53 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-05 22:28:53 +0000
commit7ab71165aa4e44d7f3f8f925d5916e17c72fc63c (patch)
treeb4f99f2bfaeab49a3a3999fe4576cdea0a4aa2d2 /tools/gtk_clipboard_dump
parent12158c1a8a9f5e945bd2019ded308520c7b93518 (diff)
downloadchromium_src-7ab71165aa4e44d7f3f8f925d5916e17c72fc63c.zip
chromium_src-7ab71165aa4e44d7f3f8f925d5916e17c72fc63c.tar.gz
chromium_src-7ab71165aa4e44d7f3f8f925d5916e17c72fc63c.tar.bz2
Add a small utility for dumping the system clipboard's contents on GTK.
Review URL: http://codereview.chromium.org/14175 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7562 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/gtk_clipboard_dump')
-rw-r--r--tools/gtk_clipboard_dump/gcd.scons19
-rw-r--r--tools/gtk_clipboard_dump/gtk_clipboard_dump.cc41
2 files changed, 60 insertions, 0 deletions
diff --git a/tools/gtk_clipboard_dump/gcd.scons b/tools/gtk_clipboard_dump/gcd.scons
new file mode 100644
index 0000000..57117f9
--- /dev/null
+++ b/tools/gtk_clipboard_dump/gcd.scons
@@ -0,0 +1,19 @@
+Import('env')
+
+if not env.Bit('linux'):
+ Return()
+
+env = env.Clone()
+
+env.Prepend(
+ CPPPATH = [
+ '$CHROME_SRC_DIR',
+ ],
+)
+
+input_files = [
+ 'gtk_clipboard_dump.cc',
+]
+
+env.ChromeProgram('gtk_clipboard_dump', input_files)
+
diff --git a/tools/gtk_clipboard_dump/gtk_clipboard_dump.cc b/tools/gtk_clipboard_dump/gtk_clipboard_dump.cc
new file mode 100644
index 0000000..9876e02
--- /dev/null
+++ b/tools/gtk_clipboard_dump/gtk_clipboard_dump.cc
@@ -0,0 +1,41 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <gtk/gtk.h>
+#include <stdio.h>
+#include <string.h>
+
+/* Small program to dump the contents of GTK's clipboard to the terminal.
+ * Feel free to add to it or improve formatting or whatnot.
+ */
+int main(int argc, char* argv[]) {
+ gtk_init(&argc, &argv);
+ GdkAtom* targets;
+ int num_targets = 0;
+ // For now only look at GDK_SELECTION_CLIPBOARD. This could be extended
+ // to look at GDK_SELECTION_PRIMARY (the X clipboard).
+ GtkClipboard* clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
+
+ gtk_clipboard_wait_for_targets(clip, &targets, &num_targets);
+
+ printf("Available targets:\n---------------\n");
+
+ for (int i = 0; i < num_targets; i++) {
+ printf(" [format: %s", gdk_atom_name(targets[i]));
+ GtkSelectionData* data = gtk_clipboard_wait_for_contents(clip, targets[i]);
+ if (!data) {
+ printf("]: NULL\n\n");
+ continue;
+ }
+
+ printf(" / length: %d / bits %d]: ", data->length, data->format);
+ for (int j = 0; j < data->length; j++) {
+ // Output data one byte at a time. Currently wide strings look
+ // pretty weird.
+ printf("%c", (data->data[j] == 0 ? '_' : data->data[j]));
+ }
+ printf("\n\n");
+ }
+}
+