[gtk/wip/carlosg/gesture-state-in-entries: 2/3] gtkentry: Add a "catchall" click gesture handler




commit c5cd1ac63079622e5876f3a48759663de5533b27
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Aug 23 15:31:37 2021 +0200

    gtkentry: Add a "catchall" click gesture handler
    
    This gesture is set on the whole widget surface, since there's
    multiple input targets inside an entry (icons, the GtkText itself)
    it makes sense to consider the full entry an area handling clicks.
    Ensure these events don't propagate further up, and result in other
    actions.

 gtk/gtkentry.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
---
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index e03127f134..9ad392ba3c 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -1464,16 +1464,33 @@ disconnect_text_signals (GtkEntry *entry)
   g_signal_handlers_disconnect_by_func (priv->text, notify_cb, entry);
 }
 
+static void
+catchall_click_press (GtkGestureClick *gesture,
+                      int              n_press,
+                      double           x,
+                      double           y,
+                      gpointer         user_data)
+{
+  gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
+}
+
 static void
 gtk_entry_init (GtkEntry *entry)
 {
   GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry);
+  GtkGesture *catchall;
 
   priv->text = gtk_text_new ();
   gtk_widget_set_parent (priv->text, GTK_WIDGET (entry));
   gtk_editable_init_delegate (GTK_EDITABLE (entry));
   connect_text_signals (entry);
 
+  catchall = gtk_gesture_click_new ();
+  g_signal_connect (catchall, "pressed",
+                    G_CALLBACK (catchall_click_press), entry);
+  gtk_widget_add_controller (GTK_WIDGET (entry),
+                             GTK_EVENT_CONTROLLER (catchall));
+
   priv->editing_canceled = FALSE;
 }
 


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