[gtk/wip/matthiasc/shortcut-4: 26/85] widget: Only create a controller if we have shortcuts



commit 34987c0b5cae667dbed1a3651ded4e126c0b44d5
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Mar 15 18:24:52 2020 -0400

    widget: Only create a controller if we have shortcuts
    
    No point in creating objects that just hold empty lists.

 gtk/gtkwidget.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index b5bdd95854..86a9b31e2c 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -2459,9 +2459,12 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
   if (layout_manager_type != G_TYPE_INVALID)
     gtk_widget_set_layout_manager (widget, g_object_new (layout_manager_type, NULL));
 
-  controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (GTK_WIDGET_CLASS 
(g_class)->priv->shortcuts));
-  gtk_event_controller_set_name (controller, "gtk-widget-class-shortcuts");
-  gtk_widget_add_controller (widget, controller);
+  if (g_list_model_get_n_items (G_LIST_MODEL (GTK_WIDGET_CLASS (g_class)->priv->shortcuts)) > 0)
+    {
+      controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (GTK_WIDGET_CLASS 
(g_class)->priv->shortcuts));
+      gtk_event_controller_set_name (controller, "gtk-widget-class-shortcuts");
+      gtk_widget_add_controller (widget, controller);
+    }
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]