summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorTimm Bäder <mail@baedert.org>2020-03-28 20:37:29 +0100
committerTimm Bäder <mail@baedert.org>2020-03-29 15:32:54 +0200
commit785b33f169db0c3788f466037115ed3027b145b2 (patch)
tree2efa08b0e71804b89541cb099e7846607f837f23 /gtk
parentaf749dc1dc83810e6bbf0658dd608c1c1b75cb9e (diff)
downloadgtk+-785b33f169db0c3788f466037115ed3027b145b2.tar.gz
widget: Return an array from list_controllers
Minimize the GList usage throughout the code base.
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkcombobox.c19
-rw-r--r--gtk/gtkpopovermenu.c11
-rw-r--r--gtk/gtktreeview.c18
-rw-r--r--gtk/gtkwidget.c16
-rw-r--r--gtk/gtkwidgetprivate.h5
5 files changed, 41 insertions, 28 deletions
diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c
index cdf69804e9..c1e97debb0 100644
--- a/gtk/gtkcombobox.c
+++ b/gtk/gtkcombobox.c
@@ -846,7 +846,8 @@ gtk_combo_box_init (GtkComboBox *combo_box)
{
GtkComboBoxPrivate *priv = gtk_combo_box_get_instance_private (combo_box);
GtkEventController *controller;
- GList *controllers, *list;
+ GtkEventController **controllers;
+ guint n_controllers, i;
priv->active = -1;
priv->active_row = NULL;
@@ -882,18 +883,20 @@ gtk_combo_box_init (GtkComboBox *combo_box)
combo_box);
gtk_widget_add_controller (GTK_WIDGET (combo_box), controller);
- controllers = gtk_widget_list_controllers (priv->popup_widget, GTK_PHASE_BUBBLE);
- for (list = controllers; list; list = list->next)
+ controllers = gtk_widget_list_controllers (priv->popup_widget, GTK_PHASE_BUBBLE, &n_controllers);
+ for (i = 0; i < n_controllers; i ++)
{
- if (GTK_IS_SHORTCUT_CONTROLLER (list->data))
+ controller = controllers[i];
+
+ if (GTK_IS_SHORTCUT_CONTROLLER (controller))
{
- g_object_ref (list->data);
- gtk_widget_remove_controller (priv->popup_widget, list->data);
- gtk_widget_add_controller (priv->popup_widget, list->data);
+ g_object_ref (controller);
+ gtk_widget_remove_controller (priv->popup_widget, controller);
+ gtk_widget_add_controller (priv->popup_widget, controller);
break;
}
}
- g_list_free (controllers);
+ g_free (controllers);
}
static void
diff --git a/gtk/gtkpopovermenu.c b/gtk/gtkpopovermenu.c
index 39c159ad45..12424e4bb2 100644
--- a/gtk/gtkpopovermenu.c
+++ b/gtk/gtkpopovermenu.c
@@ -201,7 +201,8 @@ gtk_popover_menu_init (GtkPopoverMenu *popover)
{
GtkWidget *stack;
GtkEventController *controller;
- GList *controllers, *l;
+ GtkEventController **controllers;
+ guint n_controllers, i;
stack = gtk_stack_new ();
gtk_stack_set_vhomogeneous (GTK_STACK (stack), FALSE);
@@ -221,15 +222,15 @@ gtk_popover_menu_init (GtkPopoverMenu *popover)
g_signal_connect (controller, "leave", G_CALLBACK (leave_cb), popover);
gtk_widget_add_controller (GTK_WIDGET (popover), controller);
- controllers = gtk_widget_list_controllers (GTK_WIDGET (popover), GTK_PHASE_CAPTURE);
- for (l = controllers; l; l = l->next)
+ controllers = gtk_widget_list_controllers (GTK_WIDGET (popover), GTK_PHASE_CAPTURE, &n_controllers);
+ for (i = 0; i < n_controllers; i ++)
{
- controller = l->data;
+ controller = controllers[i];
if (GTK_IS_SHORTCUT_CONTROLLER (controller) &&
strcmp (gtk_event_controller_get_name (controller), "gtk-shortcut-manager-capture") == 0)
gtk_shortcut_controller_set_mnemonics_modifiers (GTK_SHORTCUT_CONTROLLER (controller), 0);
}
- g_list_free (controllers);
+ g_free (controllers);
gtk_popover_disable_auto_mnemonics (GTK_POPOVER (popover));
}
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index 51fa6d5229..548034619c 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -1704,7 +1704,8 @@ gtk_tree_view_init (GtkTreeView *tree_view)
GtkCssNode *widget_node;
GtkGesture *gesture;
GtkEventController *controller;
- GList *list, *controllers;
+ GtkEventController **controllers;
+ guint n_controllers, i;
gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
gtk_widget_set_overflow (GTK_WIDGET (tree_view), GTK_OVERFLOW_HIDDEN);
@@ -1771,18 +1772,19 @@ gtk_tree_view_init (GtkTreeView *tree_view)
G_CALLBACK (gtk_tree_view_forward_controller_key_pressed), tree_view);
gtk_widget_add_controller (GTK_WIDGET (tree_view), controller);
- controllers = gtk_widget_list_controllers (GTK_WIDGET (tree_view), GTK_PHASE_BUBBLE);
- for (list = controllers; list; list = list->next)
+ controllers = gtk_widget_list_controllers (GTK_WIDGET (tree_view), GTK_PHASE_BUBBLE, &n_controllers);
+ for (i = 0; i < n_controllers; i ++)
{
- if (GTK_IS_SHORTCUT_CONTROLLER (list->data))
+ controller = controllers[i];
+ if (GTK_IS_SHORTCUT_CONTROLLER (controller))
{
- g_object_ref (list->data);
- gtk_widget_remove_controller (GTK_WIDGET (tree_view), list->data);
- gtk_widget_add_controller (GTK_WIDGET (tree_view), list->data);
+ g_object_ref (controller);
+ gtk_widget_remove_controller (GTK_WIDGET (tree_view), controller);
+ gtk_widget_add_controller (GTK_WIDGET (tree_view), controller);
break;
}
}
- g_list_free (controllers);
+ g_free (controllers);
tree_view->click_gesture = gtk_gesture_click_new ();
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (tree_view->click_gesture), 0);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 46a7e336ac..a276b3369b 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -11474,22 +11474,28 @@ gtk_widget_reset_controllers (GtkWidget *widget)
}
}
-GList *
+GtkEventController **
gtk_widget_list_controllers (GtkWidget *widget,
- GtkPropagationPhase phase)
+ GtkPropagationPhase phase,
+ guint *out_n_controllers)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
- GList *res = NULL, *l;
+ GPtrArray *controllers = g_ptr_array_new ();
+ GList *l;
+
+ g_assert (out_n_controllers);
for (l = priv->event_controllers; l; l = l->next)
{
GtkEventController *controller = l->data;
if (gtk_event_controller_get_propagation_phase (controller) == phase)
- res = g_list_prepend (res, controller);
+ g_ptr_array_add (controllers, controller);
}
- return g_list_reverse (res);
+ *out_n_controllers = controllers->len;
+
+ return (GtkEventController **)g_ptr_array_free (controllers, FALSE);
}
static inline void
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index a89dc21b17..53467aeae1 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -295,8 +295,9 @@ gboolean gtk_widget_has_size_request (GtkWidget *widget);
void gtk_widget_reset_controllers (GtkWidget *widget);
-GList * gtk_widget_list_controllers (GtkWidget *widget,
- GtkPropagationPhase phase);
+GtkEventController **gtk_widget_list_controllers (GtkWidget *widget,
+ GtkPropagationPhase phase,
+ guint *out_n_controllers);
gboolean gtk_widget_query_tooltip (GtkWidget *widget,
gint x,