[gtk+/gtk-style-context] Add generic providers per-screen.



commit 6ba24800d6f9316356e4b685b43ebe3bb67bc068
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Sep 11 12:48:27 2010 +0200

    Add generic providers per-screen.
    
    The providers are added as soon as gtk GtkSettings object for the screen
    is created.

 gtk/gtksettings.c |   44 +++++++++++++++++++++++++++++++++++++++++++-
 gtk/gtkwidget.c   |   38 --------------------------------------
 2 files changed, 43 insertions(+), 39 deletions(-)
---
diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c
index b77a2ab..5979e9b 100644
--- a/gtk/gtksettings.c
+++ b/gtk/gtksettings.c
@@ -28,6 +28,8 @@
 #include "gtkintl.h"
 #include "gtkwidget.h"
 #include "gtkprivate.h"
+#include "gtkcssprovider.h"
+#include "gtkversion.h"
 
 #ifdef GDK_WINDOWING_X11
 #include "x11/gdkx.h"
@@ -1138,6 +1140,46 @@ gtk_settings_finalize (GObject *object)
   G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
 }
 
+static void
+settings_init_style (GtkSettings *settings)
+{
+  static GtkCssProvider *css_provider = NULL;
+  GtkCssProvider *default_provider;
+
+  /* Add provider for user file */
+  if (G_UNLIKELY (!css_provider))
+    {
+      GFile *home_dir, *css_file;
+      gchar *filename;
+
+      css_provider = gtk_css_provider_new ();
+      home_dir = g_file_new_for_path (g_get_home_dir ());
+
+      filename = g_strdup_printf (".gtk-%d.0.css", GTK_MAJOR_VERSION);
+      css_file = g_file_get_child (home_dir, filename);
+      g_free (filename);
+
+      if (g_file_query_exists (css_file, NULL))
+        gtk_css_provider_load_from_file (css_provider, css_file, NULL);
+
+      g_object_unref (home_dir);
+      g_object_unref (css_file);
+    }
+
+  gtk_style_context_add_provider_for_screen (settings->screen,
+                                             GTK_STYLE_PROVIDER (css_provider),
+                                             GTK_STYLE_PROVIDER_PRIORITY_USER);
+
+  default_provider = gtk_css_provider_get_default ();
+  gtk_style_context_add_provider_for_screen (settings->screen,
+                                             GTK_STYLE_PROVIDER (default_provider),
+                                             GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
+
+  gtk_style_context_add_provider_for_screen (settings->screen,
+                                             GTK_STYLE_PROVIDER (settings),
+                                             GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
+}
+
 /**
  * gtk_settings_get_for_screen:
  * @screen : a #GdkScreen.
@@ -1163,7 +1205,7 @@ gtk_settings_get_for_screen (GdkScreen *screen)
       g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"), 
 			      settings, g_object_unref);
 
-      gtk_rc_reparse_all_for_settings (settings, TRUE);
+      settings_init_style (settings);
       settings_update_double_click (settings);
 #ifdef GDK_WINDOWING_X11
       settings_update_cursor_theme (settings);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 24d095a..1fc3151 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -57,8 +57,6 @@
 #include "gtkbuilderprivate.h"
 #include "gtksizerequest.h"
 #include "gtkstylecontext.h"
-#include "gtkcssprovider.h"
-#include "gtkversion.h"
 
 /**
  * SECTION:gtkwidget
@@ -11770,10 +11768,7 @@ gtk_widget_get_style_context (GtkWidget *widget)
 
   if (G_UNLIKELY (!context))
     {
-      static GtkCssProvider *css_provider = NULL;
-      GtkCssProvider *default_provider;
       GtkWidgetPath *path;
-      GtkSettings *settings;
 
       context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
                               "direction", gtk_widget_get_direction (widget),
@@ -11786,39 +11781,6 @@ gtk_widget_get_style_context (GtkWidget *widget)
                                quark_style_context, context,
                                (GDestroyNotify) g_object_unref);
 
-      /* Add provider for user file */
-      if (G_UNLIKELY (!css_provider))
-        {
-          GFile *home_dir, *css_file;
-          gchar *filename;
-
-          css_provider = gtk_css_provider_new ();
-          home_dir = g_file_new_for_path (g_get_home_dir ());
-
-          filename = g_strdup_printf (".gtk-%d.0.css", GTK_MAJOR_VERSION);
-          css_file = g_file_get_child (home_dir, filename);
-          g_free (filename);
-
-          if (g_file_query_exists (css_file, NULL))
-            gtk_css_provider_load_from_file (css_provider, css_file, NULL);
-
-          g_object_unref (home_dir);
-          g_object_unref (css_file);
-        }
-
-      gtk_style_context_add_provider (context,
-                                      GTK_STYLE_PROVIDER (css_provider),
-                                      GTK_STYLE_PROVIDER_PRIORITY_USER);
-
-      default_provider = gtk_css_provider_get_default ();
-      gtk_style_context_add_provider (context,
-                                      GTK_STYLE_PROVIDER (default_provider),
-                                      GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
-
-      settings = gtk_widget_get_settings (widget);
-      gtk_style_context_add_provider (context,
-                                      GTK_STYLE_PROVIDER (settings),
-                                      GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
       gtk_style_context_set_screen (context,
                                     gtk_widget_get_screen (widget));
 



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