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.
This commit is contained in:
Carlos Garnacho 2021-08-23 15:31:37 +02:00
parent 90edb76415
commit c5cd1ac630

View File

@ -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;
}