summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorColomban Wendling <[email protected]>2019-06-27 11:52:10 +0200
committerraveit65 <[email protected]>2022-07-20 18:47:38 +0200
commit5e5e66ca7b01405666c220bd3d80e85e75110dd3 (patch)
tree44ddeccdd51fc56819a0bc8ab32b45414289a266 /src
parent9ead522d48b09816db5e1a12e65e8d57b8e5651f (diff)
downloadcaja-5e5e66ca7b01405666c220bd3d80e85e75110dd3.tar.bz2
caja-5e5e66ca7b01405666c220bd3d80e85e75110dd3.tar.xz
Add support for loading theme-specific caja-desktop CSS
Add support for loading a specific CSS named after the theme for theming the desktop, "caja-desktop-$THEME.css". This allows specific overrides for themes with specific needs, like HighContrast and such.
Diffstat (limited to 'src')
-rw-r--r--src/caja-application.c45
1 files changed, 40 insertions, 5 deletions
diff --git a/src/caja-application.c b/src/caja-application.c
index a69af758..5eedc6ae 100644
--- a/src/caja-application.c
+++ b/src/caja-application.c
@@ -2025,14 +2025,18 @@ caja_application_local_command_line (GApplication *application,
}
static void
-load_custom_css (const gchar *filename,
+load_custom_css (GtkCssProvider *provider,
+ const gchar *filename,
guint priority)
{
- GtkCssProvider *provider;
GError *error = NULL;
gchar *path = g_build_filename (CAJA_DATADIR, filename, NULL);
- provider = gtk_css_provider_new ();
+ if (provider)
+ g_object_ref (provider);
+ else
+ provider = gtk_css_provider_new ();
+
gtk_css_provider_load_from_path (provider, path, &error);
if (error != NULL) {
@@ -2050,12 +2054,43 @@ load_custom_css (const gchar *filename,
}
static void
+reload_theme_css (GtkSettings *settings,
+ GParamSpec *unused G_GNUC_UNUSED,
+ GtkCssProvider *provider)
+{
+ gchar *theme_name;
+ gchar *css_theme_name;
+ gchar *path;
+
+ g_object_get (settings, "gtk-theme-name", &theme_name, NULL);
+ css_theme_name = g_strconcat ("caja-desktop-", theme_name, ".css", NULL);
+ path = g_build_filename (CAJA_DATADIR, css_theme_name, NULL);
+
+ if (g_file_test (path, G_FILE_TEST_EXISTS))
+ load_custom_css (provider, css_theme_name, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ else /* just empty the provider */
+ gtk_css_provider_load_from_data (provider, "", 0, NULL);
+
+ g_free (path);
+ g_free (css_theme_name);
+ g_free (theme_name);
+}
+
+static void
init_icons_and_styles (void)
{
+ GtkSettings *settings = gtk_settings_get_default ();
+ GtkCssProvider *provider;
+
/* add our custom CSS provider */
- load_custom_css ("caja.css", GTK_STYLE_PROVIDER_PRIORITY_THEME);
+ load_custom_css (NULL, "caja.css", GTK_STYLE_PROVIDER_PRIORITY_THEME);
/* add our desktop CSS provider, ensures the desktop background does not get covered */
- load_custom_css ("caja-desktop.css", GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ load_custom_css (NULL, "caja-desktop.css", GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ /* add theme-specific desktop CSS */
+ provider = gtk_css_provider_new ();
+ reload_theme_css (settings, NULL, provider);
+ g_signal_connect_data (settings, "notify::gtk-theme-name", G_CALLBACK (reload_theme_css),
+ provider, (GClosureNotify) g_object_unref, 0);
/* initialize search path for custom icons */
gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),