summaryrefslogtreecommitdiff
path: root/chromium/tools/gtk_clipboard_dump
diff options
context:
space:
mode:
authorZeno Albisser <zeno.albisser@digia.com>2013-08-15 21:46:11 +0200
committerZeno Albisser <zeno.albisser@digia.com>2013-08-15 21:46:11 +0200
commit679147eead574d186ebf3069647b4c23e8ccace6 (patch)
treefc247a0ac8ff119f7c8550879ebb6d3dd8d1ff69 /chromium/tools/gtk_clipboard_dump
downloadqtwebengine-chromium-679147eead574d186ebf3069647b4c23e8ccace6.tar.gz
Initial import.
Diffstat (limited to 'chromium/tools/gtk_clipboard_dump')
-rw-r--r--chromium/tools/gtk_clipboard_dump/gtk_clipboard_dump.cc85
-rw-r--r--chromium/tools/gtk_clipboard_dump/gtk_clipboard_dump.gyp14
2 files changed, 99 insertions, 0 deletions
diff --git a/chromium/tools/gtk_clipboard_dump/gtk_clipboard_dump.cc b/chromium/tools/gtk_clipboard_dump/gtk_clipboard_dump.cc
new file mode 100644
index 00000000000..4ddf1a2a73a
--- /dev/null
+++ b/chromium/tools/gtk_clipboard_dump/gtk_clipboard_dump.cc
@@ -0,0 +1,85 @@
+// 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>
+#include <string>
+
+namespace {
+
+void PrintClipboardContents(GtkClipboard* clip) {
+ GdkAtom* targets;
+ int num_targets = 0;
+
+ // This call is bugged, the cache it checks is often stale; see
+ // <http://bugzilla.gnome.org/show_bug.cgi?id=557315>.
+ // gtk_clipboard_wait_for_targets(clip, &targets, &num_targets);
+
+ GtkSelectionData* target_data =
+ gtk_clipboard_wait_for_contents(clip,
+ gdk_atom_intern("TARGETS", false));
+ if (!target_data) {
+ printf("failed to get the contents!\n");
+ return;
+ }
+
+ gtk_selection_data_get_targets(target_data, &targets, &num_targets);
+
+ printf("%d available targets:\n---------------\n", num_targets);
+
+ for (int i = 0; i < num_targets; i++) {
+ gchar* target_name_cstr = gdk_atom_name(targets[i]);
+ std::string target_name(target_name_cstr);
+ g_free(target_name_cstr);
+ printf(" [format: %s", target_name.c_str());
+ 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);
+
+ if (strstr(target_name.c_str(), "image")) {
+ printf("(image omitted)\n\n");
+ } else if (strstr(target_name.c_str(), "TIMESTAMP")) {
+ // TODO(estade): Print the time stamp in human readable format.
+ printf("(time omitted)\n\n");
+ } else {
+ 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");
+ }
+ gtk_selection_data_free(data);
+ }
+
+ if (num_targets <= 0) {
+ printf("No targets advertised. Text is: ");
+ gchar* text = gtk_clipboard_wait_for_text(clip);
+ printf("%s\n", text ? text : "NULL");
+ g_free(text);
+ }
+
+ g_free(targets);
+ gtk_selection_data_free(target_data);
+}
+
+}
+
+/* Small program to dump the contents of GTK's clipboards to the terminal.
+ * Feel free to add to it or improve formatting or whatnot.
+ */
+int main(int argc, char* argv[]) {
+ gtk_init(&argc, &argv);
+
+ printf("Desktop clipboard\n");
+ PrintClipboardContents(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
+
+ printf("X clipboard\n");
+ PrintClipboardContents(gtk_clipboard_get(GDK_SELECTION_PRIMARY));
+}
diff --git a/chromium/tools/gtk_clipboard_dump/gtk_clipboard_dump.gyp b/chromium/tools/gtk_clipboard_dump/gtk_clipboard_dump.gyp
new file mode 100644
index 00000000000..21121089a30
--- /dev/null
+++ b/chromium/tools/gtk_clipboard_dump/gtk_clipboard_dump.gyp
@@ -0,0 +1,14 @@
+{
+ 'targets': [
+ {
+ 'target_name': 'gtk_clipboard_dump',
+ 'type': 'executable',
+ 'dependencies': [
+ '../../build/linux/system.gyp:gtk',
+ ],
+ 'sources': [
+ 'gtk_clipboard_dump.cc',
+ ],
+ },
+ ],
+}