[bijiben] add own CSS style for notebooks



commit 2f47eca65c8ad6821376281a95e274d7787e42cc
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Wed Jul 1 00:09:07 2015 +0200

    add own CSS style for notebooks
    
    Since Adwaita moved to GTK+, it doesn't hold CSS for applications.
    Well-behaved applications will only load the Adwaita CSS when the theme
    is set to Adwaita; this code was originally written by Matthias Clasen
    and is imported from Nautilus.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751683

 src/Makefile.am             |    1 +
 src/bjb-bijiben.c           |   46 +++++++++++++++++++++++++++++++++++++++++++
 src/bjb.gresource.xml       |    1 +
 src/libbiji/biji-notebook.c |    2 +-
 src/resources/Adwaita.css   |    4 +++
 5 files changed, 53 insertions(+), 1 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index d5b31cc..1075ab1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -33,6 +33,7 @@ bijiben_LDFLAGS = \
        -Wl,--export-dynamic
 
 resource_files = \
+       resources/Adwaita.css \
        resources/app-menu.ui \
        resources/thumbnail-frame.png
 
diff --git a/src/bjb-bijiben.c b/src/bjb-bijiben.c
index ddc876f..fdd993f 100644
--- a/src/bjb-bijiben.c
+++ b/src/bjb-bijiben.c
@@ -345,10 +345,55 @@ on_registry_got (GObject *obj,
 }
 
 
+static void
+theme_changed (GtkSettings *settings)
+{
+  static GtkCssProvider *provider = NULL;
+  gchar *theme;
+  GdkScreen *screen;
 
+  g_object_get (settings, "gtk-theme-name", &theme, NULL);
+  screen = gdk_screen_get_default ();
+
+  if (g_str_equal (theme, "Adwaita"))
+  {
+    if (provider == NULL)
+    {
+        GFile *file;
+
+        provider = gtk_css_provider_new ();
+        file = g_file_new_for_uri ("resource:///org/gnome/bijiben/Adwaita.css");
+        gtk_css_provider_load_from_file (provider, file, NULL);
+        g_object_unref (file);
+    }
 
+    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_clear_object (&provider);
+  }
 
+  g_free (theme);
+}
 
+static void
+bjb_apply_style (void)
+{
+  GtkSettings *settings;
+
+  /* Set up a handler to load our custom css for Adwaita.
+   * See https://bugzilla.gnome.org/show_bug.cgi?id=732959
+   * for a more automatic solution that is still under discussion.
+   */
+  settings = gtk_settings_get_default ();
+  g_signal_connect (settings, "notify::gtk-theme-name", G_CALLBACK (theme_changed), NULL);
+  theme_changed (settings);
+}
 
 static void
 bijiben_startup (GApplication *application)
@@ -365,6 +410,7 @@ bijiben_startup (GApplication *application)
   self = BIJIBEN_APPLICATION (application);
   error = NULL;
 
+  bjb_apply_style ();
 
   bjb_app_menu_set(application);
 
diff --git a/src/bjb.gresource.xml b/src/bjb.gresource.xml
index 678c6d0..f156788 100644
--- a/src/bjb.gresource.xml
+++ b/src/bjb.gresource.xml
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
   <gresource prefix="/org/gnome/bijiben">
+    <file alias="Adwaita.css">resources/Adwaita.css</file>
     <file alias="app-menu.ui">resources/app-menu.ui</file>
     <file alias="thumbnail-frame.png">resources/thumbnail-frame.png</file>
   </gresource>
diff --git a/src/libbiji/biji-notebook.c b/src/libbiji/biji-notebook.c
index ec5ca8c..824c0f9 100644
--- a/src/libbiji/biji-notebook.c
+++ b/src/libbiji/biji-notebook.c
@@ -126,7 +126,7 @@ biji_create_notebook_icon (gint base_size, gint scale, GList *surfaces)
   tile_size = (base_size - (3 * padding)) / 2;
 
   context = gtk_style_context_new ();
-  gtk_style_context_add_class (context, "documents-collection-icon");
+  gtk_style_context_add_class (context, "biji-notebook-icon");
 
   path = gtk_widget_path_new ();
   gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW);
diff --git a/src/resources/Adwaita.css b/src/resources/Adwaita.css
new file mode 100644
index 0000000..b7475af
--- /dev/null
+++ b/src/resources/Adwaita.css
@@ -0,0 +1,4 @@
+.biji-notebook-icon {
+    background-color: #d3d7cf;
+    border-radius: 8px;
+}


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