diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/clipboard.h | 2 | ||||
-rw-r--r-- | base/clipboard_linux.cc | 28 |
2 files changed, 24 insertions, 6 deletions
diff --git a/base/clipboard.h b/base/clipboard.h index a404418..a0a7827 100644 --- a/base/clipboard.h +++ b/base/clipboard.h @@ -40,7 +40,7 @@ class Clipboard { CBF_FILES, CBF_WEBKIT, CBF_BITMAP, - CBF_SMBITMAP // bitmap from shared memory + CBF_SMBITMAP // bitmap from shared memory }; // ObjectMap is a map from ObjectType to associated data. diff --git a/base/clipboard_linux.cc b/base/clipboard_linux.cc index 10c0deb..eb5012c 100644 --- a/base/clipboard_linux.cc +++ b/base/clipboard_linux.cc @@ -214,11 +214,14 @@ void Clipboard::WriteFiles(const char* file_data, size_t file_len) { // We do not use gtk_clipboard_wait_is_target_available because of // a bug with the gtk clipboard. It caches the available targets // and does not always refresh the cache when it is appropriate. -// TODO(estade): When gnome bug 557315 is resolved, change this function -// to use gtk_clipboard_wait_is_target_available. Also, catch requests -// for plain text and change them to gtk_clipboard_wait_is_text_available -// (which checks for several standard text targets). bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format) const { + bool format_is_plain_text = GetPlainTextFormatType() == format; + if (format_is_plain_text) { + // This tries a number of common text targets. + if (gtk_clipboard_wait_is_text_available(clipboard_)) + return true; + } + bool retval = false; GdkAtom* targets = NULL; GtkSelectionData* data = @@ -231,6 +234,21 @@ bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format) const { int num = 0; gtk_selection_data_get_targets(data, &targets, &num); + // Some programs post data to the clipboard without any targets. If this is + // the case we attempt to make sense of the contents as text. This is pretty + // unfortunate since it means we have to actually copy the data to see if it + // is available, but at least this path shouldn't be hit for conforming + // programs. + if (num <= 0) { + if (format_is_plain_text) { + gchar* text = gtk_clipboard_wait_for_text(clipboard_); + if (text) { + g_free(text); + retval = true; + } + } + } + GdkAtom format_atom = StringToGdkAtom(format); for (int i = 0; i < num; i++) { @@ -240,8 +258,8 @@ bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format) const { } } - gtk_selection_data_free(data); g_free(targets); + gtk_selection_data_free(data); return retval; } |