application: load custom css files
So that theme maintainers can drop their CSS here, and make Calendar look beautiful everywhere.
This commit is contained in:
@@ -20,7 +20,8 @@
|
|||||||
<file alias="week-view.ui" compressed="true" preprocess="xml-stripblanks">ui/week-view.ui</file>
|
<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="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="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>
|
||||||
|
|
||||||
<gresource prefix="/org/gnome/calendar/gtk">
|
<gresource prefix="/org/gnome/calendar/gtk">
|
||||||
|
|||||||
+32
-11
@@ -35,8 +35,6 @@
|
|||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
|
|
||||||
#define CSS_FILE "/org/gnome/calendar/gtk-styles.css"
|
|
||||||
|
|
||||||
struct _GcalApplication
|
struct _GcalApplication
|
||||||
{
|
{
|
||||||
GtkApplication parent;
|
GtkApplication parent;
|
||||||
@@ -155,6 +153,37 @@ process_sources (GcalApplication *application)
|
|||||||
g_free (new_css_data);
|
g_free (new_css_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
static void
|
||||||
gcal_application_finalize (GObject *object)
|
gcal_application_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
@@ -186,15 +215,7 @@ gcal_application_activate (GApplication *application)
|
|||||||
self = GCAL_APPLICATION (application);
|
self = GCAL_APPLICATION (application);
|
||||||
|
|
||||||
if (!self->provider)
|
if (!self->provider)
|
||||||
{
|
load_css_provider (self);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self->colors_provider)
|
if (self->colors_provider)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user