vcl/unx/gtk3/gtkinst.cxx |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

New commits:
commit 55d5648958f9d453688bba50706323c8deb30478
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Tue Apr 4 10:38:46 2023 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Tue Apr 4 20:42:16 2023 +0200

    tdf#154565 ignore unwanted crossing event from search to treeview on "enter"
    
    i.e if the crossing was triggered ultimately by a key stroke which is
    likely from exiting the search box.
    
    This way we can avoid the problem that with hover-selection that after
    "enter" is used in the search box, selecting a matching row, then during
    teardown of the widget the box is hidden, and the generated crossing
    notification triggers unwanted selection of a different row under the
    mouse.
    
    If needs be this could be refined further to only happen for a specific
    key or other details of the triggering event
    
    Change-Id: I7e64fb5fa31a446b85016d86ecd314d13130d7b9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150016
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 30ff8681f630..5bca492629de 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -14074,6 +14074,7 @@ private:
 #if !GTK_CHECK_VERSION(4, 0, 0)
     gulong m_nPopupMenuSignalId;
     gulong m_nKeyPressSignalId;
+    gulong m_nCrossingSignalid;
 #endif
     gulong m_nQueryTooltipSignalId;
     GtkAdjustment* m_pVAdjustment;
@@ -14755,6 +14756,28 @@ private:
         return false;
     }
 
+#if !GTK_CHECK_VERSION(4, 0, 0)
+    // tdf#154565 ignore the crossing event if it was triggered ultimately by a
+    // key stroke which is likely from exiting the search box. This way we can
+    // avoid the problem that with hover-selection that after return is used in
+    // the search box, selecting a matching row, that during teardown of the
+    // widget the box is hidden, and the crossing notification triggers
+    // selection of a different row under the mouse. If needs be this could be
+    // refined further to only happen for a specific key or other details of
+    // the triggering event
+    static gboolean signalCrossing(GtkWidget*, GdkEventCrossing*, gpointer)
+    {
+        if (GdkEvent *pEvent = gtk_get_current_event())
+        {
+            const bool bCrossingTriggeredByKeyStroke = 
gdk_event_get_event_type(pEvent) == GDK_KEY_PRESS;
+            gdk_event_free(pEvent);
+            return bCrossingTriggeredByKeyStroke;
+        }
+
+        return false;
+    }
+#endif
+
 public:
     GtkInstanceTreeView(GtkTreeView* pTreeView, GtkInstanceBuilder* pBuilder, 
bool bTakeOwnership)
         : GtkInstanceWidget(GTK_WIDGET(pTreeView), pBuilder, bTakeOwnership)
@@ -14778,6 +14801,7 @@ public:
 #if !GTK_CHECK_VERSION(4, 0, 0)
         , m_nPopupMenuSignalId(g_signal_connect(pTreeView, "popup-menu", 
G_CALLBACK(signalPopupMenu), this))
         , m_nKeyPressSignalId(g_signal_connect(pTreeView, "key-press-event", 
G_CALLBACK(signalKeyPress), this))
+        , m_nCrossingSignalid(g_signal_connect(pTreeView, 
"enter-notify-event", G_CALLBACK(signalCrossing), this))
 #endif
         , m_nQueryTooltipSignalId(0)
         , 
m_pVAdjustment(gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(pTreeView)))
@@ -16705,6 +16729,7 @@ public:
         if (m_nQueryTooltipSignalId)
             g_signal_handler_disconnect(m_pTreeView, m_nQueryTooltipSignalId);
 #if !GTK_CHECK_VERSION(4, 0, 0)
+        g_signal_handler_disconnect(m_pTreeView, m_nCrossingSignalid);
         g_signal_handler_disconnect(m_pTreeView, m_nKeyPressSignalId);
         g_signal_handler_disconnect(m_pTreeView, m_nPopupMenuSignalId);
 #endif

Reply via email to