summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndrej Holy <oholy@redhat.com>2022-02-11 13:50:43 +0100
committerOndrej Holy <oholy@redhat.com>2022-02-11 14:59:48 +0100
commitf53522a4fac198b5223448e100b0a26087e09429 (patch)
treeff154f1004dbf7f65a21a39290cab8b15e547354
parent3ae766da517bd5d92a686ef9ea6ea58c8e609aa1 (diff)
downloadnautilus-f53522a4fac198b5223448e100b0a26087e09429.tar.gz
Revert "application: Unconditionally add custom styles"
This reverts commit 422b772cc18e19febce439f2edaa2e2aa53e53a4.
-rw-r--r--src/nautilus-application.c43
1 files changed, 38 insertions, 5 deletions
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index d7854dcec..505001f1a 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -1113,29 +1113,45 @@ nautilus_application_init (NautilusApplication *self)
}
static void
-setup_theme_extensions (void)
+theme_changed (GtkSettings *settings)
{
static GtkCssProvider *provider = NULL;
static GtkCssProvider *permanent_provider = NULL;
+ gchar *theme;
GdkDisplay *display;
+ GFile *file;
+ g_object_get (settings, "gtk-theme-name", &theme, NULL);
display = gdk_display_get_default ();
/* CSS that themes can override */
- if (provider == NULL)
+ if (g_str_equal (theme, "Adwaita") || g_str_equal (theme, "Adwaita-dark"))
{
- provider = gtk_css_provider_new ();
- gtk_css_provider_load_from_resource (provider, "/org/gnome/nautilus/css/Adwaita.css");
+ if (provider == NULL)
+ {
+ provider = gtk_css_provider_new ();
+ file = g_file_new_for_uri ("resource:///org/gnome/nautilus/css/Adwaita.css");
+ gtk_css_provider_load_from_file (provider, file);
+ g_object_unref (file);
+ }
+
gtk_style_context_add_provider_for_display (display,
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
+ else if (provider != NULL)
+ {
+ gtk_style_context_remove_provider_for_display (display,
+ GTK_STYLE_PROVIDER (provider));
+ g_clear_object (&provider);
+ }
/* CSS we want to always load for any theme */
if (permanent_provider == NULL)
{
permanent_provider = gtk_css_provider_new ();
- gtk_css_provider_load_from_resource (permanent_provider, "/org/gnome/nautilus/css/nautilus.css");
+ file = g_file_new_for_uri ("resource:///org/gnome/nautilus/css/nautilus.css");
+ gtk_css_provider_load_from_file (permanent_provider, file);
/* The behavior of two style providers with the same priority is
* undefined and gtk happens to prefer the provider that got added last.
* Use a higher priority here to avoid this problem.
@@ -1143,7 +1159,24 @@ setup_theme_extensions (void)
gtk_style_context_add_provider_for_display (display,
GTK_STYLE_PROVIDER (permanent_provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION + 1);
+ g_object_unref (file);
}
+
+ g_free (theme);
+}
+
+static void
+setup_theme_extensions (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);
}
NautilusApplication *