[gnome-software: 17/18] gs-details-page: Allow fallback sizes for icon




commit e7cfa823566d46627d9994e5a452f5c460755a0e
Author: Philip Withnall <pwithnall endlessos org>
Date:   Tue Mar 9 15:17:39 2021 +0000

    gs-details-page: Allow fallback sizes for icon
    
    When running on hi-DPI screens, some apps don’t have a suitable icon to
    display at 96px at scale factor 2 (i.e. 192px). Rather than displaying
    a generic icon, fall back to 64px at 2× scale (i.e. 128px), which all
    apps have.
    
    Spotted by Milan Crha.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1147

 src/gs-details-page.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)
---
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index 4b5ad230e..420d23681 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -1112,6 +1112,7 @@ gs_details_page_refresh_all (GsDetailsPage *self)
        gboolean show_support_box = FALSE;
        g_autofree gchar *origin = NULL;
        GPtrArray *version_history;
+       guint icon_size;
 
        /* change widgets */
        tmp = gs_app_get_name (self->app);
@@ -1137,13 +1138,31 @@ gs_details_page_refresh_all (GsDetailsPage *self)
        tmp = gs_app_get_description (self->app);
        gs_details_page_set_description (self, tmp);
 
-       /* set the icon */
+       /* set the icon; fall back to 64px if 96px isn’t available, which sometimes
+        * happens at 2× scale factor (hi-DPI) */
+       icon_size = 96;
        icon = gs_app_get_icon_for_size (self->app,
-                                        gtk_image_get_pixel_size (GTK_IMAGE 
(self->application_details_icon)),
+                                        icon_size,
                                         gtk_widget_get_scale_factor (self->application_details_icon),
-                                        "application-x-executable");
+                                        NULL);
+       if (icon == NULL) {
+               icon_size = 64;
+               icon = gs_app_get_icon_for_size (self->app,
+                                                icon_size,
+                                                gtk_widget_get_scale_factor (self->application_details_icon),
+                                                NULL);
+       }
+       if (icon == NULL) {
+               icon_size = 96;
+               icon = gs_app_get_icon_for_size (self->app,
+                                                icon_size,
+                                                gtk_widget_get_scale_factor (self->application_details_icon),
+                                                "application-x-executable");
+       }
+
+       gtk_image_set_pixel_size (GTK_IMAGE (self->application_details_icon), icon_size);
        gtk_image_set_from_gicon (GTK_IMAGE (self->application_details_icon), icon,
-                                 GTK_ICON_SIZE_DIALOG);
+                                 GTK_ICON_SIZE_INVALID);
 
        tmp = gs_app_get_url (self->app, AS_URL_KIND_HOMEPAGE);
        if (tmp != NULL && tmp[0] != '\0') {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]