Merge branch 'wip/carlosg/for-master' into 'master'

Improve handling of ::active with touch and multiple foci

Closes #3348

See merge request GNOME/gtk!2821
This commit is contained in:
Matthias Clasen 2020-11-13 04:13:34 +00:00
commit c136f84584
3 changed files with 40 additions and 4 deletions

View File

@ -1362,9 +1362,9 @@ set_widget_active_state (GtkWidget *target,
while (w)
{
if (release)
gtk_widget_unset_state_flags (w, GTK_STATE_FLAG_ACTIVE);
gtk_widget_set_active_state (w, FALSE);
else
gtk_widget_set_state_flags (w, GTK_STATE_FLAG_ACTIVE, FALSE);
gtk_widget_set_active_state (w, TRUE);
w = _gtk_widget_get_parent (w);
}
@ -1413,7 +1413,9 @@ handle_pointing_event (GdkEvent *event)
case GDK_TOUCH_END:
case GDK_TOUCH_CANCEL:
old_target = update_pointer_focus_state (toplevel, event, NULL);
if (type == GDK_LEAVE_NOTIFY)
if (type == GDK_TOUCH_END || type == GDK_TOUCH_CANCEL)
set_widget_active_state (old_target, TRUE);
else if (type == GDK_LEAVE_NOTIFY)
gtk_synthesize_crossing_events (GTK_ROOT (toplevel), GTK_CROSSING_POINTER, old_target, NULL,
event, gdk_crossing_event_get_mode (event), NULL);
break;
@ -1465,7 +1467,10 @@ handle_pointing_event (GdkEvent *event)
gtk_drop_end_event (drop);
}
else if (type == GDK_TOUCH_BEGIN)
gtk_window_set_pointer_focus_grab (toplevel, device, sequence, target);
{
gtk_window_set_pointer_focus_grab (toplevel, device, sequence, target);
set_widget_active_state (target, FALSE);
}
/* Let it take the effective pointer focus anyway, as it may change due
* to implicit grabs.

View File

@ -12663,3 +12663,29 @@ gtk_widget_class_get_accessible_role (GtkWidgetClass *widget_class)
priv = widget_class->priv;
return priv->accessible_role;
}
void
gtk_widget_set_active_state (GtkWidget *widget,
gboolean active)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
if (active)
{
priv->n_active++;
gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_ACTIVE, FALSE);
}
else
{
if (priv->n_active == 0)
{
g_warning ("Broken accounting of active state for widget %p(%s)",
widget, G_OBJECT_TYPE_NAME (widget));
}
else
priv->n_active--;
if (priv->n_active == 0)
gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_ACTIVE);
}
}

View File

@ -115,6 +115,8 @@ struct _GtkWidgetPrivate
guint8 verifying_invariants_count;
#endif
guint8 n_active;
int width_request;
int height_request;
@ -324,6 +326,9 @@ void gtk_widget_get_surface_allocation (GtkWidget *widget,
GtkWidget * gtk_widget_common_ancestor (GtkWidget *widget_a,
GtkWidget *widget_b);
void gtk_widget_set_active_state (GtkWidget *widget,
gboolean active);
void gtk_widget_cancel_event_sequence (GtkWidget *widget,
GtkGesture *gesture,
GdkEventSequence *sequence,