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



commit 54865914db9ed1a3c62dc5e3765d56f2eca758c3
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 c5c3d7ec65..d13cfbd9c8 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -2376,6 +2376,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;
 
@@ -2442,6 +2443,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;
 
@@ -11250,19 +11257,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]