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

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