From 5ab14ff7f62baac591cbf44b6af63e44446c3f1e Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Thu, 19 Nov 2020 20:12:58 +0100 Subject: [PATCH] gtk/main: Do not unset active state on button release w/o implicit grab If an active grab gets undone on button press (e.g. closing a menu), we will receive a button release on the new target even though it didn't handle the button press, and disable ::active state. This causes warnings when handling the button release, as it tries to undo ::active state that is not really there. In order to fix this, check that the pointer focus actually had an implicit grab at the time of receiving the button release, before trying to unset the ::active state. --- gtk/gtkmain.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c index 8b246477be..b9d12e19aa 100644 --- a/gtk/gtkmain.c +++ b/gtk/gtkmain.c @@ -1374,6 +1374,7 @@ handle_pointing_event (GdkEvent *event) double native_x, native_y; GtkWidget *native; GdkEventType type; + gboolean has_implicit; event_widget = gtk_get_event_widget (event); device = gdk_event_get_device (event); @@ -1475,6 +1476,11 @@ handle_pointing_event (GdkEvent *event) target = gtk_window_lookup_effective_pointer_focus_widget (toplevel, device, sequence); + has_implicit = + gtk_window_lookup_pointer_focus_implicit_grab (toplevel, + device, + sequence) != NULL; + gtk_window_set_pointer_focus_grab (toplevel, device, sequence, type == GDK_BUTTON_PRESS ? target : NULL); @@ -1491,7 +1497,10 @@ handle_pointing_event (GdkEvent *event) update_pointer_focus_state (toplevel, event, new_target); } - set_widget_active_state (target, type == GDK_BUTTON_RELEASE); + if (type == GDK_BUTTON_PRESS) + set_widget_active_state (target, FALSE); + else if (has_implicit) + set_widget_active_state (target, TRUE); break; case GDK_SCROLL: