From 692cc42e1023ec439d2fa1a0b9456e8cbfe1cec8 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 22 Jun 2020 12:47:27 -0400 Subject: [PATCH] Add gtk_widget_prepend_controller Add a variant of gtk_widget_add_controller that inserts the controller at the beginning, instead of the end. This will be used in entry completion to make sure the entry completion key event handling supersedes the entry one while the popup is open. Keep this private for now, until we determine if it needs to be public api. --- gtk/gtkwidget.c | 17 +++++++++++++++++ gtk/gtkwidgetprivate.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 2cedb2508f..61ae38f0b5 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -11415,6 +11415,23 @@ gtk_widget_add_controller (GtkWidget *widget, gtk_list_list_model_item_added_at (priv->controller_observer, priv->controllers->len - 1); } +void +gtk_widget_prepend_controller (GtkWidget *widget, + GtkEventController *controller) +{ + GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget); + + GTK_EVENT_CONTROLLER_GET_CLASS (controller)->set_widget (controller, widget); + + if (G_UNLIKELY (!priv->controllers)) + priv->controllers = g_ptr_array_new (); + + g_ptr_array_insert (priv->controllers, 0, controller); + + if (priv->controller_observer) + gtk_list_list_model_item_added_at (priv->controller_observer, 0); +} + /** * gtk_widget_remove_controller: * @widget: a #GtkWidget diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h index e7688a65cd..d281dd0f43 100644 --- a/gtk/gtkwidgetprivate.h +++ b/gtk/gtkwidgetprivate.h @@ -346,6 +346,9 @@ gboolean gtk_widget_run_controllers (GtkWidget double x, double y, GtkPropagationPhase phase); + +void gtk_widget_prepend_controller (GtkWidget *widget, + GtkEventController *controller); void gtk_widget_handle_crossing (GtkWidget *widget, const GtkCrossingData *crossing, double x,