[gimp/wip/Jehan/layers-dockable-refresh: 86/105] libgimpwidgets: GimpCellRendererToggle fallback to "image-missing"…




commit 6086151794da48c0a0bcbcdadaef9195589d3c8e
Author: Jehan <jehan girinstud io>
Date:   Tue Nov 2 15:40:06 2021 +0100

    libgimpwidgets: GimpCellRendererToggle fallback to "image-missing"…
    
    … when appropriate icon failed to be found.
    
    gtk_icon_theme_lookup_icon_for_scale() apparently does all standard
    fallbacks, but not the last "image-missing" one which is supposed to
    always be present. To avoid crashing, let's add an explicit fallback
    ourselves.
    
    We also encountered this on the test-ui unit test because icons are not
    installed (but this could happen anyway when running GIMP normally with
    third-party icon themes).

 libgimpwidgets/gimpcellrenderertoggle.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
---
diff --git a/libgimpwidgets/gimpcellrenderertoggle.c b/libgimpwidgets/gimpcellrenderertoggle.c
index 93239088bd..58244101dd 100644
--- a/libgimpwidgets/gimpcellrenderertoggle.c
+++ b/libgimpwidgets/gimpcellrenderertoggle.c
@@ -492,6 +492,7 @@ gimp_cell_renderer_toggle_create_pixbuf (GimpCellRendererToggle *toggle,
 
   if (priv->icon_name)
     {
+      GdkPixbuf    *pixbuf;
       GdkScreen    *screen;
       GtkIconTheme *icon_theme;
       GtkIconInfo  *icon_info;
@@ -509,16 +510,21 @@ gimp_cell_renderer_toggle_create_pixbuf (GimpCellRendererToggle *toggle,
                                                         GTK_ICON_LOOKUP_GENERIC_FALLBACK);
 
       g_free (icon_name);
-      if (icon_info)
+      if (! icon_info)
         {
-          GdkPixbuf *pixbuf;
-
-          pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info,
-                                                            gtk_widget_get_style_context (widget),
-                                                            NULL, NULL);
-          priv->pixbuf = pixbuf;
-          g_object_unref (icon_info);
+          icon_info = gtk_icon_theme_lookup_icon_for_scale (icon_theme, "image-missing",
+                                                            priv->icon_size, scale_factor,
+                                                            GTK_ICON_LOOKUP_GENERIC_FALLBACK |
+                                                            GTK_ICON_LOOKUP_USE_BUILTIN);
         }
+
+      g_return_if_fail (icon_info != NULL);
+
+      pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info,
+                                                        gtk_widget_get_style_context (widget),
+                                                        NULL, NULL);
+      priv->pixbuf = pixbuf;
+      g_object_unref (icon_info);
     }
 }
 


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