[sushi/wip/cosimoc/no-clutter: 65/66] media-bin: don't initialize style with class



commit 8402bf0cf4ac549960848ce7a4e2fe7bb506bcc4
Author: Cosimo Cecchi <cosimo endlessm com>
Date:   Sat Jun 8 11:32:34 2019 -0700

    media-bin: don't initialize style with class
    
    Looks like this is a bit too early now that the library does not
    get linked together with the C executable.
    Instead, we just load it in a g_once_init section when the first
    instance is created.

 src/libsushi/sushi-media-bin.c | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)
---
diff --git a/src/libsushi/sushi-media-bin.c b/src/libsushi/sushi-media-bin.c
index d981e13..40967a3 100644
--- a/src/libsushi/sushi-media-bin.c
+++ b/src/libsushi/sushi-media-bin.c
@@ -848,6 +848,25 @@ sushi_media_bin_init_volume_button (SushiMediaBin    *self,
   gtk_style_context_add_class (gtk_widget_get_style_context (popup), "sushi-media-bin");
 }
 
+static void
+sushi_media_bin_init_style (SushiMediaBin *self)
+{
+  static gsize style_initialized = 0;
+
+  if (g_once_init_enter (&style_initialized))
+    {
+      GtkCssProvider *css_provider = gtk_css_provider_new ();
+
+      gtk_css_provider_load_from_resource (css_provider, "/org/gnome/Sushi/libsushi/sushi-media-bin.css");
+      gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
+                                                 GTK_STYLE_PROVIDER (css_provider),
+                                                 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION-10);
+      g_object_unref (css_provider);
+
+      g_once_init_leave (&style_initialized, 1);
+    }
+}
+
 static void
 sushi_media_bin_init (SushiMediaBin *self)
 {
@@ -856,6 +875,8 @@ sushi_media_bin_init (SushiMediaBin *self)
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
+  sushi_media_bin_init_style (self);
+
   priv->state = SMB_INITIAL_STATE;
   priv->autohide_timeout = AUTOHIDE_TIMEOUT_DEFAULT;
   priv->pressed_button_type = GDK_NOTHING;
@@ -1239,17 +1260,6 @@ sushi_media_bin_class_init (SushiMediaBinClass *klass)
   /* Setup CSS */
   gtk_widget_class_set_css_name (widget_class, "sushi-media-bin");
 
-  if (gdk_screen_get_default ())
-    {
-      GtkCssProvider *css_provider = gtk_css_provider_new ();
-
-      gtk_css_provider_load_from_resource (css_provider, "/org/gnome/Sushi/libsushi/sushi-media-bin.css");
-      gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
-                                                 GTK_STYLE_PROVIDER (css_provider),
-                                                 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION-10);
-      g_object_unref (css_provider);
-    }
-
   /* Init GStreamer */
   gst_init_check (NULL, NULL, NULL);
   GST_DEBUG_CATEGORY_INIT (sushi_media_bin_debug, "SushiMediaBin", 0, "SushiMediaBin audio/video widget");


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