[gnome-shell/wip/carlosg/cleanup-gtk-usage: 77/77] st-texture-cache: Use GtkIconTheme separate from GTK+



commit 52ee6ca06d57c0128d9bd177ce70789564782744
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Nov 27 22:07:25 2018 +0100

    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.

 js/ui/main.js             |  2 --
 src/st/st-texture-cache.c | 28 ++++++++++++++++++----------
 2 files changed, 18 insertions(+), 12 deletions(-)
---
diff --git a/js/ui/main.js b/js/ui/main.js
index 84aefe7d5..5bb63327b 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;
@@ -131,7 +130,6 @@ function start() {
 
     _interfaceSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
     _interfaceSettings.connect('changed::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 ad177b35e..c951000c2 100644
--- a/src/st/st-texture-cache.c
+++ b/src/st/st-texture-cache.c
@@ -34,6 +34,7 @@
 struct _StTextureCachePrivate
 {
   GtkIconTheme *icon_theme;
+  GSettings *settings;
 
   /* Things that were loaded with a cache policy != NONE */
   GHashTable *keyed_cache; /* char * -> ClutterImage* */
@@ -131,10 +132,18 @@ st_texture_cache_evict_icons (StTextureCache *cache)
 }
 
 static void
-on_icon_theme_changed (GtkIconTheme   *icon_theme,
+on_icon_theme_changed (GSettings      *settings,
+                       const gchar    *key,
                        StTextureCache *cache)
 {
+  gchar *theme;
+
   st_texture_cache_evict_icons (cache);
+
+  theme = g_settings_get_string (settings, "gtk-icon-theme");
+  gtk_icon_theme_set_custom_theme (cache->priv->icon_theme, theme);
+  g_free (theme);
+
   g_signal_emit (cache, signals[ICON_THEME_CHANGED], 0);
 }
 
@@ -143,8 +152,12 @@ st_texture_cache_init (StTextureCache *self)
 {
   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");
+
+  self->priv->settings = g_settings_new ("org.gnome.desktop.interface");
+  g_signal_connect (self->priv->settings, "changed::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,
@@ -165,13 +178,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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]