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