[gnome-software] gs-feature-tile: Only change CSS on GTK widget if metadata has changed
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] gs-feature-tile: Only change CSS on GTK widget if metadata has changed
- Date: Tue, 9 Jun 2020 11:10:29 +0000 (UTC)
commit 5638bb1da2b716d1dd520f1f7c350db5d83667de
Author: Philip Withnall <withnall endlessm com>
Date: Mon Jun 8 16:42:58 2020 +0100
gs-feature-tile: Only change CSS on GTK widget if metadata has changed
`refresh()` gets called more than once on each `GsFeatureTile` during
startup of gnome-software, leading to multiple `GtkCssProvider`s being
created and attached to each `GsFeatureTile`. For feature tiles which
set an image background (most of them), this results in the background
being loaded multiple times and kept around in memory.
Signed-off-by: Philip Withnall <withnall endlessm com>
src/gs-feature-tile.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/src/gs-feature-tile.c b/src/gs-feature-tile.c
index b932b1eb..150364f9 100644
--- a/src/gs-feature-tile.c
+++ b/src/gs-feature-tile.c
@@ -21,6 +21,7 @@ struct _GsFeatureTile
GtkWidget *stack;
GtkWidget *title;
GtkWidget *subtitle;
+ const gchar *markup_cache; /* (unowned) (nullable) */
};
G_DEFINE_TYPE (GsFeatureTile, gs_feature_tile, GS_TYPE_APP_TILE)
@@ -33,7 +34,6 @@ gs_feature_tile_refresh (GsAppTile *self)
AtkObject *accessible;
const gchar *markup;
g_autofree gchar *name = NULL;
- g_autoptr(GsCss) css = NULL;
if (app == NULL)
return;
@@ -44,17 +44,21 @@ gs_feature_tile_refresh (GsAppTile *self)
gtk_label_set_label (GTK_LABEL (tile->title), gs_app_get_name (app));
gtk_label_set_label (GTK_LABEL (tile->subtitle), gs_app_get_summary (app));
- /* perhaps set custom css */
+ /* perhaps set custom css; cache it so that images don’t get reloaded
+ * unnecessarily */
markup = gs_app_get_metadata_item (app, "GnomeSoftware::FeatureTile-css");
- css = gs_css_new ();
- if (markup != NULL)
- gs_css_parse (css, markup, NULL);
- gs_utils_widget_set_css (GTK_WIDGET (tile), "feature-tile",
- gs_css_get_markup_for_id (css, "tile"));
- gs_utils_widget_set_css (tile->title, "feature-tile-name",
- gs_css_get_markup_for_id (css, "name"));
- gs_utils_widget_set_css (tile->subtitle, "feature-tile-subtitle",
- gs_css_get_markup_for_id (css, "summary"));
+ if (tile->markup_cache != markup) {
+ g_autoptr(GsCss) css = gs_css_new ();
+ if (markup != NULL)
+ gs_css_parse (css, markup, NULL);
+ gs_utils_widget_set_css (GTK_WIDGET (tile), "feature-tile",
+ gs_css_get_markup_for_id (css, "tile"));
+ gs_utils_widget_set_css (tile->title, "feature-tile-name",
+ gs_css_get_markup_for_id (css, "name"));
+ gs_utils_widget_set_css (tile->subtitle, "feature-tile-subtitle",
+ gs_css_get_markup_for_id (css, "summary"));
+ tile->markup_cache = markup;
+ }
accessible = gtk_widget_get_accessible (GTK_WIDGET (tile));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]