From 036e67049b9a377ba070e37c38a33850b4ca10cb Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Tue, 27 Nov 2018 22:07:25 +0100 Subject: [PATCH] st-texture-cache: Use GtkIconTheme separate from GTK+ Using the default icon theme just has automatic theme updates as an added value. We can do that ourselves, and stop relying on XSettings internally. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/317 --- js/ui/main.js | 2 -- src/st/st-texture-cache.c | 31 +++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/js/ui/main.js b/js/ui/main.js index e827eb9c5..ccecb49d4 100644 --- a/js/ui/main.js +++ b/js/ui/main.js @@ -3,7 +3,6 @@ const Clutter = imports.gi.Clutter; const Gio = imports.gi.Gio; const GLib = imports.gi.GLib; -const Gtk = imports.gi.Gtk; const Mainloop = imports.mainloop; const Meta = imports.gi.Meta; const Shell = imports.gi.Shell; @@ -129,7 +128,6 @@ function start() { sessionMode.connect('updated', _sessionUpdated); St.Settings.get().connect('notify::gtk-theme', _loadDefaultStylesheet); - Gtk.IconTheme.get_default().add_resource_path('/org/gnome/shell/theme/icons'); _initializeUI(); shellAccessDialogDBusService = new AccessDialog.AccessDialogDBus(); diff --git a/src/st/st-texture-cache.c b/src/st/st-texture-cache.c index d9c0a9673..1d11ce71c 100644 --- a/src/st/st-texture-cache.c +++ b/src/st/st-texture-cache.c @@ -23,6 +23,7 @@ #include "st-texture-cache.h" #include "st-private.h" +#include "st-settings.h" #include #include #include @@ -34,6 +35,7 @@ struct _StTextureCachePrivate { GtkIconTheme *icon_theme; + GSettings *settings; /* Things that were loaded with a cache policy != NONE */ GHashTable *keyed_cache; /* char * -> ClutterImage* */ @@ -131,20 +133,33 @@ st_texture_cache_evict_icons (StTextureCache *cache) } static void -on_icon_theme_changed (GtkIconTheme *icon_theme, +on_icon_theme_changed (StSettings *settings, + GParamSpec *pspec, StTextureCache *cache) { + g_autofree gchar *theme; + st_texture_cache_evict_icons (cache); + + g_object_get (settings, "gtk-icon-theme", &theme, NULL); + gtk_icon_theme_set_custom_theme (cache->priv->icon_theme, theme); + g_signal_emit (cache, signals[ICON_THEME_CHANGED], 0); } static void st_texture_cache_init (StTextureCache *self) { + StSettings *settings; + self->priv = g_new0 (StTextureCachePrivate, 1); - self->priv->icon_theme = gtk_icon_theme_get_default (); - g_signal_connect (self->priv->icon_theme, "changed", + self->priv->icon_theme = gtk_icon_theme_new (); + gtk_icon_theme_add_resource_path (self->priv->icon_theme, + "/org/gnome/shell/theme/icons"); + + settings = st_settings_get (); + g_signal_connect (settings, "notify::gtk-icon-theme", G_CALLBACK (on_icon_theme_changed), self); self->priv->keyed_cache = g_hash_table_new_full (g_str_hash, g_str_equal, @@ -158,6 +173,7 @@ st_texture_cache_init (StTextureCache *self) self->priv->file_monitors = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal, g_object_unref, g_object_unref); + on_icon_theme_changed (settings, NULL, self); } static void @@ -165,13 +181,8 @@ st_texture_cache_dispose (GObject *object) { StTextureCache *self = (StTextureCache*)object; - if (self->priv->icon_theme) - { - g_signal_handlers_disconnect_by_func (self->priv->icon_theme, - (gpointer) on_icon_theme_changed, - self); - self->priv->icon_theme = NULL; - } + g_clear_object (&self->priv->settings); + g_clear_object (&self->priv->icon_theme); g_clear_pointer (&self->priv->keyed_cache, g_hash_table_destroy); g_clear_pointer (&self->priv->keyed_surface_cache, g_hash_table_destroy);