Blame SOURCES/0003-shell-app-system-Monitor-for-icon-theme-changes.patch

e251e4
From c9277326055c96185a80b68d4228eee360bb0e7c Mon Sep 17 00:00:00 2001
e251e4
From: Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
e251e4
Date: Thu, 1 Aug 2019 20:58:20 -0300
e251e4
Subject: [PATCH 3/6] shell/app-system: Monitor for icon theme changes
e251e4
e251e4
Whenever an app is installed, the usual routine is
e251e4
to run 'gtk-update-icon-cache' after installing all
e251e4
of the app's files.
e251e4
e251e4
The side effect of that is that the .desktop file of
e251e4
the application is installed before the icon theme
e251e4
is updated. By the time GAppInfoMonitor emits the
e251e4
'changed' signal, the icon theme is not yet updated,
e251e4
leading to StIcon use the fallback icon.
e251e4
e251e4
Under some circumstances (e.g. on very slow spinning
e251e4
disks) the app icon is never actually loaded, and we
e251e4
see the fallback icon forever.
e251e4
e251e4
Monitor the icon theme for changes when an app is
e251e4
installed. Try as many as 6 times before giving up
e251e4
on detecting an icon theme update.
e251e4
e251e4
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/661
e251e4
---
e251e4
 src/shell-app-system.c    | 54 +++++++++++++++++++++++++++++++++++++++
e251e4
 src/st/st-texture-cache.c |  8 ++++++
e251e4
 src/st/st-texture-cache.h |  2 ++
e251e4
 3 files changed, 64 insertions(+)
e251e4
e251e4
diff --git a/src/shell-app-system.c b/src/shell-app-system.c
e251e4
index f632cbe54..127f29ef0 100644
e251e4
--- a/src/shell-app-system.c
e251e4
+++ b/src/shell-app-system.c
e251e4
@@ -14,6 +14,14 @@
e251e4
 #include "shell-app-system-private.h"
e251e4
 #include "shell-global.h"
e251e4
 #include "shell-util.h"
e251e4
+#include "st.h"
e251e4
+
e251e4
+/* Rescan for at most RESCAN_TIMEOUT_MS * MAX_RESCAN_RETRIES. That
e251e4
+ * should be plenty of time for even a slow spinning drive to update
e251e4
+ * the icon cache.
e251e4
+ */
e251e4
+#define RESCAN_TIMEOUT_MS 2500
e251e4
+#define MAX_RESCAN_RETRIES 6
e251e4
 
e251e4
 /* Vendor prefixes are something that can be preprended to a .desktop
e251e4
  * file name.  Undo this.
e251e4
@@ -51,6 +59,9 @@ struct _ShellAppSystemPrivate {
e251e4
   GHashTable *id_to_app;
e251e4
   GHashTable *startup_wm_class_to_id;
e251e4
   GList *installed_apps;
e251e4
+
e251e4
+  guint rescan_icons_timeout_id;
e251e4
+  guint n_rescan_retries;
e251e4
 };
e251e4
 
e251e4
 static void shell_app_system_finalize (GObject *object);
e251e4
@@ -157,12 +168,54 @@ stale_app_remove_func (gpointer key,
e251e4
   return app_is_stale (value);
e251e4
 }
e251e4
 
e251e4
+static gboolean
e251e4
+rescan_icon_theme_cb (gpointer user_data)
e251e4
+{
e251e4
+  ShellAppSystemPrivate *priv;
e251e4
+  ShellAppSystem *self;
e251e4
+  StTextureCache *texture_cache;
e251e4
+  gboolean rescanned;
e251e4
+
e251e4
+  self = (ShellAppSystem *) user_data;
e251e4
+  priv = self->priv;
e251e4
+
e251e4
+  texture_cache = st_texture_cache_get_default ();
e251e4
+  rescanned = st_texture_cache_rescan_icon_theme (texture_cache);
e251e4
+
e251e4
+  priv->n_rescan_retries++;
e251e4
+
e251e4
+  if (rescanned || priv->n_rescan_retries >= MAX_RESCAN_RETRIES)
e251e4
+    {
e251e4
+      priv->n_rescan_retries = 0;
e251e4
+      priv->rescan_icons_timeout_id = 0;
e251e4
+      return G_SOURCE_REMOVE;
e251e4
+    }
e251e4
+
e251e4
+  return G_SOURCE_CONTINUE;
e251e4
+}
e251e4
+
e251e4
+static void
e251e4
+rescan_icon_theme (ShellAppSystem *self)
e251e4
+{
e251e4
+  ShellAppSystemPrivate *priv = self->priv;
e251e4
+
e251e4
+  priv->n_rescan_retries = 0;
e251e4
+
e251e4
+  if (priv->rescan_icons_timeout_id > 0)
e251e4
+    return;
e251e4
+
e251e4
+  priv->rescan_icons_timeout_id = g_timeout_add (RESCAN_TIMEOUT_MS,
e251e4
+                                                 rescan_icon_theme_cb,
e251e4
+                                                 self);
e251e4
+}
e251e4
+
e251e4
 static void
e251e4
 installed_changed (GAppInfoMonitor *monitor,
e251e4
                    gpointer         user_data)
e251e4
 {
e251e4
   ShellAppSystem *self = user_data;
e251e4
 
e251e4
+  rescan_icon_theme (self);
e251e4
   scan_startup_wm_class_to_id (self);
e251e4
 
e251e4
   g_hash_table_foreach_remove (self->priv->id_to_app, stale_app_remove_func, NULL);
e251e4
@@ -200,6 +253,7 @@ shell_app_system_finalize (GObject *object)
e251e4
   g_hash_table_destroy (priv->id_to_app);
e251e4
   g_hash_table_destroy (priv->startup_wm_class_to_id);
e251e4
   g_list_free_full (priv->installed_apps, g_object_unref);
e251e4
+  g_clear_handle_id (&priv->rescan_icons_timeout_id, g_source_remove);
e251e4
 
e251e4
   G_OBJECT_CLASS (shell_app_system_parent_class)->finalize (object);
e251e4
 }
e251e4
diff --git a/src/st/st-texture-cache.c b/src/st/st-texture-cache.c
e251e4
index c1331747f..4d0d617c4 100644
e251e4
--- a/src/st/st-texture-cache.c
e251e4
+++ b/src/st/st-texture-cache.c
e251e4
@@ -1554,3 +1554,11 @@ st_texture_cache_get_default (void)
e251e4
     instance = g_object_new (ST_TYPE_TEXTURE_CACHE, NULL);
e251e4
   return instance;
e251e4
 }
e251e4
+
e251e4
+gboolean
e251e4
+st_texture_cache_rescan_icon_theme (StTextureCache *cache)
e251e4
+{
e251e4
+  StTextureCachePrivate *priv = cache->priv;
e251e4
+
e251e4
+  return gtk_icon_theme_rescan_if_needed (priv->icon_theme);
e251e4
+}
e251e4
diff --git a/src/st/st-texture-cache.h b/src/st/st-texture-cache.h
e251e4
index 11d1c4e64..a99316da8 100644
e251e4
--- a/src/st/st-texture-cache.h
e251e4
+++ b/src/st/st-texture-cache.h
e251e4
@@ -113,4 +113,6 @@ CoglTexture * st_texture_cache_load (StTextureCache       *cache,
e251e4
                                      void                 *data,
e251e4
                                      GError              **error);
e251e4
 
e251e4
+gboolean st_texture_cache_rescan_icon_theme (StTextureCache *cache);
e251e4
+
e251e4
 #endif /* __ST_TEXTURE_CACHE_H__ */
e251e4
-- 
e251e4
2.26.2
e251e4