[vte/vte-0-64] widget: Move clipboard store from finalize to unrealize



commit eac4a8178e2036ec158a803b762dec81956d6f00
Author: Joan Bruguera <joanbrugueram gmail com>
Date:   Sun Apr 11 22:58:37 2021 +0200

    widget: Move clipboard store from finalize to unrealize
    
    Fixes a regression from commit 0136048d32d29412de3381828bb21f05563c799f.
    
    Unfortunately, this causes a regression in the following simple case:
    * Open two instances of a terminal like xfce4-terminal.
    * Go to the first instance, copy some string of text, and close it.
    * Go to the second instance and paste it. Due to the regression, it won't work.
    
    The cause is that Widget::unrealize calls Terminal::widget_clipboard_data_clear,
    this will set m_selection_owned[type] = false. Later when Terminal::~Terminal is
    run, the piece of code that calls clipboard_set_text will not be run, because it
    depends on m_selection_owned[type] being set (but it ran before on 0.62.3).
    
    This commit moves this last piece of code to Terminal::widget_unrealize, which
    is called before setting m_selection_owned[type] = false.
    
    Fixes: https://gitlab.gnome.org/GNOME/vte/-/issues/349
    (cherry picked from commit 94d6a3c10fcaae65b38c17687bc98defb6dfac33)

 src/vte.cc | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index 6f16873b..4ea466bd 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -7861,6 +7861,25 @@ Terminal::widget_unrealize()
 
        /* Clear modifiers. */
        m_modifiers = 0;
+
+       /* Free any selected text, but if we currently own the selection,
+        * throw the text onto the clipboard without an owner so that it
+        * doesn't just disappear. */
+        for (auto sel_type : {vte::platform::ClipboardType::CLIPBOARD,
+                              vte::platform::ClipboardType::PRIMARY}) {
+                auto const sel = vte::to_integral(sel_type);
+               if (m_selection[sel] != nullptr) {
+                       if (m_selection_owned[sel]) {
+                                // FIXMEchpe we should check m_selection_format[sel]
+                                // and also put text/html on if it's HTML format
+                                widget()->clipboard_set_text(sel_type,
+                                                             {m_selection[sel]->str,
+                                                              m_selection[sel]->len});
+                       }
+                       g_string_free(m_selection[sel], TRUE);
+                        m_selection[sel] = nullptr;
+               }
+       }
 }
 
 void
@@ -7911,25 +7930,6 @@ Terminal::~Terminal()
        /* Cancel pending adjustment change notifications. */
        m_adjustment_changed_pending = FALSE;
 
-       /* Free any selected text, but if we currently own the selection,
-        * throw the text onto the clipboard without an owner so that it
-        * doesn't just disappear. */
-        for (auto sel_type : {vte::platform::ClipboardType::CLIPBOARD,
-                              vte::platform::ClipboardType::PRIMARY}) {
-                auto const sel = vte::to_integral(sel_type);
-               if (m_selection[sel] != nullptr) {
-                       if (m_selection_owned[sel]) {
-                                // FIXMEchpe we should check m_selection_format[sel]
-                                // and also put text/html on if it's HTML format
-                                widget()->clipboard_set_text(sel_type,
-                                                             {m_selection[sel]->str,
-                                                              m_selection[sel]->len});
-                       }
-                       g_string_free(m_selection[sel], TRUE);
-                        m_selection[sel] = nullptr;
-               }
-       }
-
         /* Stop listening for child-exited signals. */
         if (m_reaper) {
                 g_signal_handlers_disconnect_by_func(m_reaper,


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