From 120ee17e095190db9192a91065433f2945ebe2e8 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 18 Feb 2019 20:00:19 +0100 Subject: [PATCH 1/5] gtksearchbar: Do not handle captured events for unmapped bars If the bar is currently unmapped, it should not attempt to capture and handle events. Related: https://gitlab.gnome.org/GNOME/gtk/issues/1205 --- gtk/gtksearchbar.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gtk/gtksearchbar.c b/gtk/gtksearchbar.c index 0b3f916344..7c0222ef60 100644 --- a/gtk/gtksearchbar.c +++ b/gtk/gtksearchbar.c @@ -643,6 +643,9 @@ capture_widget_key_handled (GtkEventControllerKey *controller, GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar); gboolean handled; + if (!gtk_widget_get_mapped (GTK_WIDGET (bar))) + return GDK_EVENT_PROPAGATE; + if (priv->reveal_child) return GDK_EVENT_PROPAGATE; From c739071d31e4f87a57bcd4776384aee8900187da Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Tue, 19 Feb 2019 13:51:37 +0100 Subject: [PATCH 2/5] gtksearchentry: Forward captured events to the child GtkText Catch up with the GtkEditable shuffling. --- gtk/gtksearchentry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtk/gtksearchentry.c b/gtk/gtksearchentry.c index a73e32963d..930445f50d 100644 --- a/gtk/gtksearchentry.c +++ b/gtk/gtksearchentry.c @@ -622,7 +622,7 @@ capture_widget_key_handled (GtkEventControllerKey *controller, priv->content_changed = FALSE; priv->search_stopped = FALSE; - handled = gtk_event_controller_key_forward (controller, entry); + handled = gtk_event_controller_key_forward (controller, priv->entry); return handled && priv->content_changed && !priv->search_stopped ? GDK_EVENT_STOP : GDK_EVENT_PROPAGATE; } From 9ca392b38db0a700e76f27968ba52c5da84bc795 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 20 Feb 2019 12:41:00 +0100 Subject: [PATCH 3/5] gtkwidget: Expose gtk_widget_run_controllers() in private header Allows for more fine grained access than gtk_widget(_captured)_event which are meant to work across a hierarchy. --- gtk/gtkwidget.c | 14 +++++++------- gtk/gtkwidgetprivate.h | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index a139d29579..124ecc5628 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -5099,10 +5099,10 @@ _gtk_widget_set_captured_event_handler (GtkWidget *widget, g_object_set_data (G_OBJECT (widget), I_("captured-event-handler"), callback); } -static gboolean -_gtk_widget_run_controllers (GtkWidget *widget, - const GdkEvent *event, - GtkPropagationPhase phase) +gboolean +gtk_widget_run_controllers (GtkWidget *widget, + const GdkEvent *event, + GtkPropagationPhase phase) { GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget); GtkEventController *controller; @@ -5170,7 +5170,7 @@ _gtk_widget_captured_event (GtkWidget *widget, event_copy = gdk_event_copy (event); translate_event_coordinates (event_copy, widget); - return_val = _gtk_widget_run_controllers (widget, event_copy, GTK_PHASE_CAPTURE); + return_val = gtk_widget_run_controllers (widget, event_copy, GTK_PHASE_CAPTURE); handler = g_object_get_data (G_OBJECT (widget), I_("captured-event-handler")); if (!handler) @@ -5270,10 +5270,10 @@ gtk_widget_event_internal (GtkWidget *widget, translate_event_coordinates (event_copy, widget); if (widget == gtk_get_event_target (event_copy)) - return_val |= _gtk_widget_run_controllers (widget, event_copy, GTK_PHASE_TARGET); + return_val |= gtk_widget_run_controllers (widget, event_copy, GTK_PHASE_TARGET); if (return_val == FALSE) - return_val |= _gtk_widget_run_controllers (widget, event_copy, GTK_PHASE_BUBBLE); + return_val |= gtk_widget_run_controllers (widget, event_copy, GTK_PHASE_BUBBLE); g_object_unref (event_copy); if (return_val == FALSE && diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h index 31356ae5a5..e22795ad2b 100644 --- a/gtk/gtkwidgetprivate.h +++ b/gtk/gtkwidgetprivate.h @@ -342,9 +342,9 @@ void gtk_widget_cancel_event_sequence (GtkWidget GdkEventSequence *sequence, GtkEventSequenceState state); - - - +gboolean gtk_widget_run_controllers (GtkWidget *widget, + const GdkEvent *event, + GtkPropagationPhase phase); /* inline getters */ From 19bf937401947a38bc63203b0958f9c2f513db12 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 20 Feb 2019 12:48:08 +0100 Subject: [PATCH 4/5] eventcontrollerkey: Use run_controllers() API to forward key events All 3 phases are run ATM, but just on the specific widget. --- gtk/gtkeventcontrollerkey.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gtk/gtkeventcontrollerkey.c b/gtk/gtkeventcontrollerkey.c index 91254f8bbc..f1b28d999b 100644 --- a/gtk/gtkeventcontrollerkey.c +++ b/gtk/gtkeventcontrollerkey.c @@ -35,6 +35,7 @@ #include "gtkeventcontrollerprivate.h" #include "gtkeventcontrollerkey.h" #include "gtkbindings.h" +#include "gtkenums.h" #include @@ -342,9 +343,14 @@ gtk_event_controller_key_forward (GtkEventControllerKey *controller, if (!gtk_widget_get_realized (widget)) gtk_widget_realize (widget); - if (_gtk_widget_captured_event (widget, controller->current_event)) + if (gtk_widget_run_controllers (widget, controller->current_event, + GTK_PHASE_CAPTURE)) return TRUE; - if (gtk_widget_event (widget, controller->current_event)) + if (gtk_widget_run_controllers (widget, controller->current_event, + GTK_PHASE_TARGET)) + return TRUE; + if (gtk_widget_run_controllers (widget, controller->current_event, + GTK_PHASE_BUBBLE)) return TRUE; return FALSE; From b741d36cedbf57f02879aac9f0ea57f16fb2b6f2 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 20 Feb 2019 16:41:39 +0100 Subject: [PATCH 5/5] inspector: Update callback to GtkText shuffling Instead of trying to access the GtkText, use GtkEditable API. --- gtk/inspector/resource-list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtk/inspector/resource-list.c b/gtk/inspector/resource-list.c index b1d99223fd..3dd38a8d52 100644 --- a/gtk/inspector/resource-list.c +++ b/gtk/inspector/resource-list.c @@ -508,7 +508,7 @@ on_search_changed (GtkSearchEntry *entry, gint length; gboolean backwards; - length = strlen (gtk_entry_get_text (GTK_ENTRY (entry))); + length = strlen (gtk_editable_get_text (GTK_EDITABLE (entry))); backwards = length < sl->priv->search_length; sl->priv->search_length = length;