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

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