Unified menu icon loading so zc-menu-* icons can be loaded directly from the bundled data/icons/menu/light/*.svg resource set via a new helper (gtkutil_menu_icon_pixbuf_new), instead of depending only on platform stock themes. This makes menu icon resolution consistent across platforms for the custom menu icon namespace.

Updated the GTK2 (!HAVE_GTK3) code path in gtkutil_image_new_from_stock to first try the bundled zc-menu-* SVG resource icons and only fall back to GTK stock icons if a bundled icon cannot be loaded.
This commit is contained in:
2026-02-18 00:41:55 -07:00
parent 45d4025ad7
commit 5df6f68cd9

View File

@@ -163,6 +163,22 @@ gtkutil_stock_from_menu_custom_icon (const char *custom_icon)
} }
#endif #endif
static GdkPixbuf *
gtkutil_menu_icon_pixbuf_new (const char *icon_name)
{
GdkPixbuf *pixbuf = NULL;
char *resource_path;
if (!icon_name || !g_str_has_prefix (icon_name, "zc-menu-"))
return NULL;
resource_path = g_strdup_printf ("/icons/menu/light/%s.svg", icon_name + strlen ("zc-menu-"));
pixbuf = gdk_pixbuf_new_from_resource_at_scale (resource_path, -1, -1, TRUE, NULL);
g_free (resource_path);
return pixbuf;
}
#if HAVE_GTK3 #if HAVE_GTK3
const char * const char *
gtkutil_icon_name_from_stock (const char *stock_name) gtkutil_icon_name_from_stock (const char *stock_name)
@@ -317,6 +333,18 @@ gtkutil_image_new_from_stock (const char *stock, GtkIconSize size)
return gtk_image_new_from_icon_name (icon_name, size); return gtk_image_new_from_icon_name (icon_name, size);
#elif !HAVE_GTK3 #elif !HAVE_GTK3
if (stock && g_str_has_prefix (stock, "zc-menu-"))
{
GdkPixbuf *pixbuf = gtkutil_menu_icon_pixbuf_new (stock);
if (pixbuf)
{
GtkWidget *image = gtk_image_new_from_pixbuf (pixbuf);
g_object_unref (pixbuf);
return image;
}
}
if (stock && g_str_has_prefix (stock, "zc-menu-")) if (stock && g_str_has_prefix (stock, "zc-menu-"))
stock = gtkutil_stock_from_menu_custom_icon (stock); stock = gtkutil_stock_from_menu_custom_icon (stock);
return gtk_image_new_from_stock (stock, size); return gtk_image_new_from_stock (stock, size);