[gnome-calendar] application: load custom css files
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] application: load custom css files
- Date: Sun, 19 Nov 2017 15:43:07 +0000 (UTC)
commit a3d1bfcfc5e3530a564d3d7dc89e9279aeb9833b
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sun Nov 19 13:42:11 2017 -0200
application: load custom css files
So that theme maintainers can drop their CSS here,
and make Calendar look beautiful everywhere.
data/calendar.gresource.xml | 3 +-
data/theme/{gtk-styles.css => Adwaita.css} | 0
src/gcal-application.c | 43 ++++++++++++++++++++-------
3 files changed, 34 insertions(+), 12 deletions(-)
---
diff --git a/data/calendar.gresource.xml b/data/calendar.gresource.xml
index 1c11d23..db0ed4e 100644
--- a/data/calendar.gresource.xml
+++ b/data/calendar.gresource.xml
@@ -20,7 +20,8 @@
<file alias="week-view.ui" compressed="true" preprocess="xml-stripblanks">ui/week-view.ui</file>
<file alias="window.ui" compressed="true" preprocess="xml-stripblanks">ui/window.ui</file>
<file alias="year-view.ui" compressed="true" preprocess="xml-stripblanks">ui/year-view.ui</file>
- <file alias="gtk-styles.css" compressed="true">theme/gtk-styles.css</file>
+
+ <file>theme/Adwaita.css</file>
</gresource>
<gresource prefix="/org/gnome/calendar/gtk">
diff --git a/data/theme/gtk-styles.css b/data/theme/Adwaita.css
similarity index 100%
rename from data/theme/gtk-styles.css
rename to data/theme/Adwaita.css
diff --git a/src/gcal-application.c b/src/gcal-application.c
index 1aa9ca0..470f416 100644
--- a/src/gcal-application.c
+++ b/src/gcal-application.c
@@ -35,8 +35,6 @@
#include <gio/gio.h>
#include <glib/gi18n.h>
-#define CSS_FILE "/org/gnome/calendar/gtk-styles.css"
-
struct _GcalApplication
{
GtkApplication parent;
@@ -156,6 +154,37 @@ process_sources (GcalApplication *application)
}
static void
+load_css_provider (GcalApplication *self)
+{
+ g_autoptr (GFile) css_file = NULL;
+ g_autofree gchar *theme_name = NULL;
+ g_autofree gchar *theme_uri = NULL;
+
+ /* Apply the CSS provider */
+ self->provider = gtk_css_provider_new ();
+ gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
+ GTK_STYLE_PROVIDER (self->provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION + 1);
+
+ /* Retrieve the theme name */
+ g_object_get (gtk_settings_get_default (), "gtk-theme-name", &theme_name, NULL);
+ theme_uri = g_strconcat ("resource:///org/gnome/calendar/theme/", theme_name, ".css", NULL);
+
+ /* Try and load the CSS file */
+ css_file = g_file_new_for_uri (theme_uri);
+
+ if (g_file_query_exists (css_file, NULL))
+ gtk_css_provider_load_from_file (self->provider, css_file, NULL);
+ else
+ gtk_css_provider_load_from_resource (self->provider, "/org/gnome/calendar/theme/Adwaita.css");
+}
+
+
+/*
+ * GObject overrides
+ */
+
+static void
gcal_application_finalize (GObject *object)
{
GcalApplication *self = GCAL_APPLICATION (object);
@@ -186,15 +215,7 @@ gcal_application_activate (GApplication *application)
self = GCAL_APPLICATION (application);
if (!self->provider)
- {
- self->provider = gtk_css_provider_new ();
-
- gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
- GTK_STYLE_PROVIDER (self->provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION + 1);
-
- gtk_css_provider_load_from_resource (self->provider, CSS_FILE);
- }
+ load_css_provider (self);
if (self->colors_provider)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]