[gtk+/gtk-style-context] GtkSettings: Add a new provider for the theme CSS file.



commit 20b83be61bc8fa1f104c252375ef6265ebe29476
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Sep 22 23:44:06 2010 +0200

    GtkSettings: Add a new provider for the theme CSS file.

 gtk/gtksettings.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c
index 5979e9b..2250328 100644
--- a/gtk/gtksettings.c
+++ b/gtk/gtksettings.c
@@ -158,6 +158,7 @@ static void    settings_update_font_options      (GtkSettings           *setting
 static gboolean settings_update_fontconfig       (GtkSettings           *settings);
 #endif
 static void    settings_update_color_scheme      (GtkSettings *settings);
+static void    settings_update_theme             (GtkSettings *settings);
 
 static void    merge_color_scheme                (GtkSettings           *settings, 
 						  const GValue          *value, 
@@ -1355,6 +1356,10 @@ gtk_settings_notify (GObject    *object,
       break;
     case PROP_COLOR_SCHEME:
       settings_update_color_scheme (settings);
+      gtk_style_context_reset_widgets (settings->screen);
+      break;
+    case PROP_THEME_NAME:
+      settings_update_theme (settings);
       break;
 #ifdef GDK_WINDOWING_X11
     case PROP_XFT_DPI:
@@ -2388,6 +2393,49 @@ settings_update_color_scheme (GtkSettings *settings)
    }
 }
 
+static void
+settings_update_theme (GtkSettings *settings)
+{
+  static GQuark quark_theme_name = 0;
+  GtkCssProvider *provider, *new_provider = NULL;
+  gboolean prefer_dark_theme;
+  gchar *theme_name;
+
+  if (G_UNLIKELY (!quark_theme_name))
+    quark_theme_name = g_quark_from_static_string ("gtk-settings-theme-name");
+
+  provider = g_object_get_qdata (G_OBJECT (settings), quark_theme_name);
+
+  g_object_get (settings,
+                "gtk-theme-name", &theme_name,
+                "gtk-application-prefer-dark-theme", &prefer_dark_theme,
+                NULL);
+
+  if (theme_name && *theme_name)
+    {
+      gchar *variant = NULL;
+
+      if (prefer_dark_theme)
+        variant = "dark";
+
+      new_provider = gtk_css_provider_get_named (theme_name, variant);
+      g_free (theme_name);
+    }
+
+  if (new_provider != provider)
+    {
+      if (provider)
+        gtk_style_context_remove_provider_for_screen (settings->screen, provider);
+
+      if (new_provider)
+        gtk_style_context_add_provider_for_screen (settings->screen, new_provider,
+                                                   GTK_STYLE_PROVIDER_PRIORITY_SETTINGS + 1);
+
+      g_object_set_qdata_full (G_OBJECT (settings), quark_theme_name,
+                              new_provider, (GDestroyNotify) g_object_unref);
+    }
+}
+
 static gboolean
 add_color_to_hash (gchar      *name,
 		   GdkColor   *color,



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