[gtk/wip/baedert/for-master: 19/38] widget: Create style context in _init



commit ef30e0a3e3037b832c9feff7edffee01291704cd
Author: Timm Bäder <mail baedert org>
Date:   Mon Feb 3 11:25:58 2020 +0100

    widget: Create style context in _init
    
    Otherwise we end up with widgets without a style context all the time
    now since we tend to just access their css node directly.

 gtk/gtkwidget.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 8175497d54..d812027bf2 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -2360,6 +2360,7 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
   GtkWidget *widget = GTK_WIDGET (instance);
   GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
   GType layout_manager_type;
+  GdkDisplay *display;
 
   widget->priv = priv;
 
@@ -2426,6 +2427,12 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
   /* need to set correct name here, and only class has the correct type here */
   gtk_css_node_set_name (priv->cssnode, GTK_WIDGET_CLASS (g_class)->priv->css_name);
 
+  priv->context = gtk_style_context_new_for_node (priv->cssnode);
+  gtk_style_context_set_scale (priv->context, gtk_widget_get_scale_factor (widget));
+  display = _gtk_widget_get_display (widget);
+  if (display)
+    gtk_style_context_set_display (priv->context, display);
+
   if (g_type_is_a (G_TYPE_FROM_CLASS (g_class), GTK_TYPE_ROOT))
     priv->root = (GtkRoot *) widget;
 
@@ -11218,19 +11225,6 @@ gtk_widget_get_style_context (GtkWidget *widget)
 
   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
 
-  if (G_UNLIKELY (priv->context == NULL))
-    {
-      GdkDisplay *display;
-
-      priv->context = gtk_style_context_new_for_node (priv->cssnode);
-
-      gtk_style_context_set_scale (priv->context, gtk_widget_get_scale_factor (widget));
-
-      display = _gtk_widget_get_display (widget);
-      if (display)
-        gtk_style_context_set_display (priv->context, display);
-    }
-
   return priv->context;
 }
 


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