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




commit 7a4afb08bdd39916aaccb624ef6cbb62291e91d7
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Aug 23 15:33:32 2021 +0200

    gtksearchentry: 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/gtksearchentry.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtksearchentry.c b/gtk/gtksearchentry.c
index ebee742622..6708fcc3af 100644
--- a/gtk/gtksearchentry.c
+++ b/gtk/gtksearchentry.c
@@ -579,11 +579,21 @@ activate_cb (GtkText  *text,
   g_signal_emit (data, signals[ACTIVATE], 0);
 }
 
+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_search_entry_init (GtkSearchEntry *entry)
 {
   GtkWidget *icon;
-  GtkGesture *press;
+  GtkGesture *press, *catchall;
 
   /* The search icon is purely presentational */
   icon = g_object_new (GTK_TYPE_IMAGE,
@@ -615,6 +625,12 @@ gtk_search_entry_init (GtkSearchEntry *entry)
   g_signal_connect (press, "released", G_CALLBACK (gtk_search_entry_icon_release), entry);
   gtk_widget_add_controller (entry->icon, GTK_EVENT_CONTROLLER (press));
 
+  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));
+
   gtk_widget_add_css_class (GTK_WIDGET (entry), I_("search"));
 }
 


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