[vte/vte-0-44] widget: Don't deselect when updating the clipboard



commit 288068ee0ee9202f696d120e75340fa12774a26e
Author: Christian Persch <chpe gnome org>
Date:   Thu Feb 25 18:42:00 2016 +0100

    widget: Don't deselect when updating the clipboard
    
    gtk_clipboard_set_with_data() differs from gtk_clipboard_set_with_owner()
    in that the old clear callback is *always* invoked instead of only
    when the owner (user_data) is different from the last owner (user_data).
    I think this is a gtk+ bug, but that code has been that way since 2000,
    so who knows why it does it this way.
    
    Adapt to this by guarding the clear callback to gtk_clipboard_set_with_owner()
    with a bool that is set/unset around the call and makes the callback
    bail out early if we're updating the clipboard from within vte.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=762446
    (cherry picked from commit cf72edc15a73cdaa21a459fa2b5e8f470334e3ea)

 src/vte.cc         |    9 ++++++++-
 src/vteinternal.hh |    1 +
 2 files changed, 9 insertions(+), 1 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index 97e8782..6f2f99d 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -5874,8 +5874,12 @@ clipboard_clear_cb(GtkClipboard *clipboard,
 void
 VteTerminalPrivate::widget_clipboard_cleared(GtkClipboard *clipboard_)
 {
+        if (m_changing_selection)
+                return;
+
        if (clipboard_ == m_clipboard[VTE_SELECTION_PRIMARY]) {
-               if (m_has_selection) {
+               if (m_selection_owned[VTE_SELECTION_PRIMARY] &&
+                    m_has_selection) {
                        _vte_debug_print(VTE_DEBUG_SELECTION, "Lost selection.\n");
                        deselect_all();
                }
@@ -6386,12 +6390,15 @@ VteTerminalPrivate::widget_copy(VteSelection sel)
                        gtk_target_list_unref (list);
                }
 
+                m_changing_selection = true;
                gtk_clipboard_set_with_data(m_clipboard[sel],
                                             targets,
                                             n_targets,
                                             clipboard_copy_cb,
                                             clipboard_clear_cb,
                                             this);
+                m_changing_selection = false;
+
                gtk_clipboard_set_can_store(m_clipboard[sel], NULL, 0);
                 m_selection_owned[sel] = true;
        }
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 04edeeb..696750b 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -375,6 +375,7 @@ public:
        /* Clipboard data information. */
         // FIXMEchpe check if this can make m_has_selection obsolete!
         bool m_selection_owned[LAST_VTE_SELECTION];
+        bool m_changing_selection;
         char *m_selection_text[LAST_VTE_SELECTION];
 #ifdef HTML_SELECTION
         char *m_selection_html[LAST_VTE_SELECTION];


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]