[gnome-panel] use separate .css files for Adwaita and HighContrast themes



commit 95c33e1f9162503a27936b7b34286cea4fb0fdbb
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Apr 13 19:56:24 2015 +0300

    use separate .css files for Adwaita and HighContrast themes

 gnome-panel/{gnome-panel.css => Adwaita.css}      |    0
 gnome-panel/{gnome-panel.css => HighContrast.css} |    0
 gnome-panel/Makefile.am                           |    3 +-
 gnome-panel/main.c                                |   49 ++++++++++++--------
 gnome-panel/panel.gresource.xml                   |    3 +-
 5 files changed, 33 insertions(+), 22 deletions(-)
---
diff --git a/gnome-panel/gnome-panel.css b/gnome-panel/Adwaita.css
similarity index 100%
copy from gnome-panel/gnome-panel.css
copy to gnome-panel/Adwaita.css
diff --git a/gnome-panel/gnome-panel.css b/gnome-panel/HighContrast.css
similarity index 100%
rename from gnome-panel/gnome-panel.css
rename to gnome-panel/HighContrast.css
diff --git a/gnome-panel/Makefile.am b/gnome-panel/Makefile.am
index 37948d7..912c146 100644
--- a/gnome-panel/Makefile.am
+++ b/gnome-panel/Makefile.am
@@ -253,7 +253,8 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
 EXTRA_DIST =                                   \
        $(ui_FILES)                             \
        panel.gresource.xml                     \
-       gnome-panel.css \
+       Adwaita.css \
+       HighContrast.css \
        $(uitest_FILES)                         \
        panel-test-applets.gresource.xml        \
        nothing.cP                              \
diff --git a/gnome-panel/main.c b/gnome-panel/main.c
index 35cf287..fde5534 100644
--- a/gnome-panel/main.c
+++ b/gnome-panel/main.c
@@ -42,35 +42,44 @@ static const GOptionEntry options[] = {
 };
 
 static void
+remove_style_provider (GdkScreen *screen)
+{
+  GtkStyleProvider *style_provider;
+
+  if (provider == NULL)
+    return;
+
+  style_provider = GTK_STYLE_PROVIDER (provider);
+  gtk_style_context_remove_provider_for_screen (screen, style_provider);
+  g_clear_object (&provider);
+}
+
+static void
 theme_changed (GtkSettings *settings)
 {
-       GdkScreen *screen;
-       gchar     *theme;
+  GdkScreen *screen;
+  gchar *theme;
 
-       screen = gdk_screen_get_default ();
-       g_object_get (settings, "gtk-theme-name", &theme, NULL);
+  screen = gdk_screen_get_default ();
+  g_object_get (settings, "gtk-theme-name", &theme, NULL);
 
-       if (g_str_equal (theme, "Adwaita") || g_str_equal (theme, "HighContrast")) {
-               if (provider == NULL) {
-                       GFile *file;
+  remove_style_provider (screen);
 
-                       file = g_file_new_for_uri ("resource:///org/gnome/panel/gnome-panel.css");
-                       provider = gtk_css_provider_new ();
+  if (g_strcmp0 (theme, "Adwaita") == 0 || g_strcmp0 (theme, "HighContrast") == 0)
+    {
+      gchar *resource;
 
-                       gtk_css_provider_load_from_file (provider, file, NULL);
+      provider = gtk_css_provider_new ();
 
-                       g_object_unref (file);
-               }
+      resource = g_strdup_printf ("/org/gnome/panel/%s.css", theme);
+      gtk_css_provider_load_from_resource (provider, resource);
+      g_free (resource);
 
-               gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider),
-                                                          GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
-       } else if (provider != NULL) {
-               gtk_style_context_remove_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider));
-               g_object_unref (provider);
-               provider = NULL;
-       }
+      gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider),
+                                                 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+    }
 
-       g_free (theme);
+  g_free (theme);
 }
 
 static gboolean
diff --git a/gnome-panel/panel.gresource.xml b/gnome-panel/panel.gresource.xml
index 0c2996c..85c4b28 100644
--- a/gnome-panel/panel.gresource.xml
+++ b/gnome-panel/panel.gresource.xml
@@ -4,6 +4,7 @@
     <file compressed="true">panel-properties-dialog.ui</file>
     <file compressed="true">panel-run-dialog.ui</file>
     <file alias="anim/wanda.png">../applets/fish/wanda.png</file>
-    <file>gnome-panel.css</file>
+    <file>Adwaita.css</file>
+    <file>HighContrast.css</file>
   </gresource>
 </gresources>


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