gtklabel: Fix touch link handling under wayland

Refactor the code updating the active link under the current coordinates
into a separate function, and call it on GtkGestureMultiPress::pressed
so the link is updated on GDK_TOUCH_BEGIN. Based on a patch by
Jan-Michael Brummer <jan.brummer@tabos.org>.

https://bugzilla.gnome.org/show_bug.cgi?id=776903
This commit is contained in:
Carlos Garnacho 2017-07-25 16:18:07 +02:00
parent 21062fab02
commit 2d3882c7eb

View File

@ -459,6 +459,9 @@ static void gtk_label_select_region_index (GtkLabel *label,
gint anchor_index, gint anchor_index,
gint end_index); gint end_index);
static void gtk_label_update_active_link (GtkWidget *widget,
gdouble x,
gdouble y);
static gboolean gtk_label_mnemonic_activate (GtkWidget *widget, static gboolean gtk_label_mnemonic_activate (GtkWidget *widget,
gboolean group_cycling); gboolean group_cycling);
@ -4514,6 +4517,7 @@ gtk_label_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)); button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture)); sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence); event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence);
gtk_label_update_active_link (widget, widget_x, widget_y);
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED); gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
@ -4854,9 +4858,10 @@ gtk_label_drag_gesture_update (GtkGestureDrag *gesture,
} }
} }
static gboolean static void
gtk_label_motion (GtkWidget *widget, gtk_label_update_active_link (GtkWidget *widget,
GdkEventMotion *event) gdouble x,
gdouble y)
{ {
GtkLabel *label = GTK_LABEL (widget); GtkLabel *label = GTK_LABEL (widget);
GtkLabelPrivate *priv = label->priv; GtkLabelPrivate *priv = label->priv;
@ -4864,7 +4869,7 @@ gtk_label_motion (GtkWidget *widget,
gint index; gint index;
if (info == NULL) if (info == NULL)
return FALSE; return;
if (info->links && !info->in_drag) if (info->links && !info->in_drag)
{ {
@ -4874,7 +4879,7 @@ gtk_label_motion (GtkWidget *widget,
if (info->selection_anchor == info->selection_end) if (info->selection_anchor == info->selection_end)
{ {
if (get_layout_index (label, event->x, event->y, &index)) if (get_layout_index (label, x, y, &index))
{ {
for (l = info->links; l != NULL; l = l->next) for (l = info->links; l != NULL; l = l->next)
{ {
@ -4912,6 +4917,16 @@ gtk_label_motion (GtkWidget *widget,
} }
} }
} }
}
static gboolean
gtk_label_motion (GtkWidget *widget,
GdkEventMotion *event)
{
gdouble x, y;
gdk_event_get_coords ((GdkEvent *) event, &x, &y);
gtk_label_update_active_link (widget, x, y);
return GTK_WIDGET_CLASS (gtk_label_parent_class)->motion_notify_event (widget, event); return GTK_WIDGET_CLASS (gtk_label_parent_class)->motion_notify_event (widget, event);
} }