Merge branch 'wip/carlosg/reset-after-grab' into 'master'

Fixes to GTK grab notification

Closes #3942

See merge request GNOME/gtk!3561
This commit is contained in:
Matthias Clasen 2021-05-17 23:35:26 +00:00
commit ab6e4bfc8d
3 changed files with 26 additions and 50 deletions

View File

@ -748,34 +748,6 @@ gtk_widget_real_contains (GtkWidget *widget,
&GRAPHENE_POINT_INIT (x, y)); &GRAPHENE_POINT_INIT (x, y));
} }
/*
* _gtk_widget_grab_notify:
* @widget: a `GtkWidget`
* @was_grabbed: whether a grab is now in effect
*
* Emits the `GtkWidget`::grab-notify signal on @widget.
*/
void
_gtk_widget_grab_notify (GtkWidget *widget,
gboolean was_grabbed)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
GList *l;
if (was_grabbed)
return;
for (l = g_list_last (priv->event_controllers); l; l = l->prev)
{
GtkEventController *controller = l->data;
gtk_event_controller_reset (controller);
}
if (GTK_IS_NATIVE (widget))
gtk_widget_hide (widget);
}
static void static void
gtk_widget_real_root (GtkWidget *widget) gtk_widget_real_root (GtkWidget *widget)
{ {

View File

@ -247,8 +247,6 @@ void _gtk_widget_set_has_grab (GtkWidget *widget,
gboolean has_grab); gboolean has_grab);
gboolean gtk_widget_has_grab (GtkWidget *widget); gboolean gtk_widget_has_grab (GtkWidget *widget);
void _gtk_widget_grab_notify (GtkWidget *widget,
gboolean was_grabbed);
void _gtk_widget_propagate_display_changed (GtkWidget *widget, void _gtk_widget_propagate_display_changed (GtkWidget *widget,
GdkDisplay *previous_display); GdkDisplay *previous_display);

View File

@ -6703,13 +6703,13 @@ gtk_window_get_foci_on_widget (GtkWindow *window,
} }
static void static void
gtk_grab_notify_foreach (GtkWidget *child, gtk_synthesize_grab_crossing (GtkWidget *child,
GdkDevice *device, GdkDevice *device,
GtkWidget *new_grab_widget, GtkWidget *new_grab_widget,
GtkWidget *old_grab_widget, GtkWidget *old_grab_widget,
gboolean from_grab, gboolean from_grab,
gboolean was_shadowed, gboolean was_shadowed,
gboolean is_shadowed) gboolean is_shadowed)
{ {
g_object_ref (child); g_object_ref (child);
@ -6732,8 +6732,6 @@ gtk_grab_notify_foreach (GtkWidget *child,
GDK_CROSSING_GTK_UNGRAB); GDK_CROSSING_GTK_UNGRAB);
} }
_gtk_widget_grab_notify (child, was_shadowed);
g_object_unref (child); g_object_unref (child);
} }
@ -6750,6 +6748,10 @@ gtk_window_propagate_grab_notify (GtkWindow *window,
while (target) while (target)
{ {
if (target == old_grab_widget)
was_grabbed = TRUE;
if (target == new_grab_widget)
is_grabbed = TRUE;
widgets = g_list_prepend (widgets, g_object_ref (target)); widgets = g_list_prepend (widgets, g_object_ref (target));
target = gtk_widget_get_parent (target); target = gtk_widget_get_parent (target);
} }
@ -6760,22 +6762,26 @@ gtk_window_propagate_grab_notify (GtkWindow *window,
{ {
gboolean was_shadowed, is_shadowed; gboolean was_shadowed, is_shadowed;
was_grabbed |= (l->data == old_grab_widget);
is_grabbed |= (l->data == new_grab_widget);
was_shadowed = old_grab_widget && !was_grabbed; was_shadowed = old_grab_widget && !was_grabbed;
is_shadowed = new_grab_widget && is_grabbed; is_shadowed = new_grab_widget && !is_grabbed;
if (l->data == old_grab_widget)
was_grabbed = FALSE;
if (l->data == new_grab_widget)
is_grabbed = FALSE;
if (was_shadowed == is_shadowed) if (was_shadowed == is_shadowed)
break; break;
gtk_grab_notify_foreach (l->data, gtk_synthesize_grab_crossing (l->data,
device, device,
old_grab_widget, old_grab_widget,
new_grab_widget, new_grab_widget,
from_grab, from_grab,
was_shadowed, was_shadowed,
is_shadowed); is_shadowed);
gtk_widget_reset_controllers (l->data);
} }
g_list_free_full (widgets, g_object_unref); g_list_free_full (widgets, g_object_unref);