Merge branch 'wip/carlosg/gesture-state-in-entries' into 'master'

Claim clicks further at GtkEntry/GtkSearchEntry

See merge request GNOME/gtk!3873
This commit is contained in:
Matthias Clasen 2021-08-24 17:20:20 +00:00
commit b9c51e65c1
4 changed files with 72 additions and 1 deletions

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

View File

@ -141,6 +141,12 @@ focus_changed (GtkWidget *widget)
caps_lock_state_changed (entry->keyboard, NULL, widget);
}
static void
gtk_password_entry_icon_press (GtkGesture *gesture)
{
gtk_gesture_set_state (gesture, GTK_EVENT_SEQUENCE_CLAIMED);
}
/*< private >
* gtk_password_entry_toggle_peek:
* @entry: a `GtkPasswordEntry`
@ -182,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 ();
@ -201,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);
@ -607,6 +630,8 @@ gtk_password_entry_set_show_peek_icon (GtkPasswordEntry *entry,
gtk_widget_set_parent (entry->peek_icon, GTK_WIDGET (entry));
press = gtk_gesture_click_new ();
g_signal_connect (press, "pressed",
G_CALLBACK (gtk_password_entry_icon_press), entry);
g_signal_connect_swapped (press, "released",
G_CALLBACK (gtk_password_entry_toggle_peek), entry);
gtk_widget_add_controller (entry->peek_icon, GTK_EVENT_CONTROLLER (press));

View File

@ -490,6 +490,16 @@ gtk_search_entry_accessible_init (GtkAccessibleInterface *iface)
iface->get_platform_state = gtk_search_entry_accessible_get_platform_state;
}
static void
gtk_search_entry_icon_press (GtkGestureClick *press,
int n_press,
double x,
double y,
GtkSearchEntry *entry)
{
gtk_gesture_set_state (GTK_GESTURE (press), GTK_EVENT_SEQUENCE_CLAIMED);
}
static void
gtk_search_entry_icon_release (GtkGestureClick *press,
int n_press,
@ -569,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,
@ -601,9 +621,16 @@ gtk_search_entry_init (GtkSearchEntry *entry)
gtk_widget_set_child_visible (entry->icon, FALSE);
press = gtk_gesture_click_new ();
g_signal_connect (press, "pressed", G_CALLBACK (gtk_search_entry_icon_press), 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"));
}

View File

@ -2773,6 +2773,8 @@ gtk_text_click_gesture_pressed (GtkGestureClick *gesture,
GdkDevice *source;
guint state;
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
sel_start = priv->selection_bound;
sel_end = priv->current_pos;
have_selection = sel_start != sel_end;