summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntónio Fernandes <antoniof@gnome.org>2022-01-01 18:28:15 +0000
committerAntónio Fernandes <antoniof@gnome.org>2022-01-09 01:44:32 +0000
commit422b772cc18e19febce439f2edaa2e2aa53e53a4 (patch)
tree16ff93e0e1565d923c3d65d292d5fc47f4635a28
parentc8fa38f67d646c10ec7068fe6ffd6755f5352709 (diff)
downloadnautilus-422b772cc18e19febce439f2edaa2e2aa53e53a4.tar.gz
application: Unconditionally add custom styles
With libadwaita, the existing code wasn't loading the custom themes as it should. But thanks to libadwaita, we can make assumptions on the existing stylesheet. In the future we may want to unify our 2 css files and maybe adopt AdwApplication to have it load the custom styles automatically.
-rw-r--r--src/nautilus-application.c43
1 files changed, 5 insertions, 38 deletions
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index 505001f1a..d7854dcec 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -1113,45 +1113,29 @@ nautilus_application_init (NautilusApplication *self)
}
static void
-theme_changed (GtkSettings *settings)
+setup_theme_extensions (void)
{
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 (g_str_equal (theme, "Adwaita") || g_str_equal (theme, "Adwaita-dark"))
+ if (provider == NULL)
{
- 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);
- }
-
+ provider = gtk_css_provider_new ();
+ gtk_css_provider_load_from_resource (provider, "/org/gnome/nautilus/css/Adwaita.css");
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 ();
- file = g_file_new_for_uri ("resource:///org/gnome/nautilus/css/nautilus.css");
- gtk_css_provider_load_from_file (permanent_provider, file);
+ gtk_css_provider_load_from_resource (permanent_provider, "/org/gnome/nautilus/css/nautilus.css");
/* 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.
@@ -1159,24 +1143,7 @@ theme_changed (GtkSettings *settings)
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 *