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



commit e652054d505bf12b52130ec42baf89f9e3753a42
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Aug 24 01:13:29 2021 +0200

    gtkpasswordentry: 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/gtkpasswordentry.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
---
diff --git a/gtk/gtkpasswordentry.c b/gtk/gtkpasswordentry.c
index ba91de58f4..7e375a05bc 100644
--- a/gtk/gtkpasswordentry.c
+++ b/gtk/gtkpasswordentry.c
@@ -188,9 +188,20 @@ activate_cb (GtkPasswordEntry *entry)
   g_signal_emit (entry, 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_password_entry_init (GtkPasswordEntry *entry)
 {
+  GtkGesture *catchall;
   GtkEntryBuffer *buffer = gtk_password_entry_buffer_new ();
 
   entry->entry = gtk_text_new ();
@@ -207,6 +218,12 @@ gtk_password_entry_init (GtkPasswordEntry *entry)
   gtk_widget_set_cursor (entry->icon, gtk_widget_get_cursor (entry->entry));
   gtk_widget_set_parent (entry->icon, GTK_WIDGET (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));
+
   gtk_widget_add_css_class (GTK_WIDGET (entry), I_("password"));
 
   gtk_password_entry_set_extra_menu (entry, NULL);


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