mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-03-17 11:10:18 +00:00
Added a centralized menu icon resolver in menu.c so menu items consistently prefer the bundled zc-menu-* resource icons (from data/icons/menu) instead of relying on platform/theme fallback behavior. This includes:
checking whether a matching zc-menu-* resource exists,
preserving support for absolute file paths and <config>/... relative icon paths,
mapping plain icon names (for example, copy) to zc-menu-copy when available.
Updated menu_quick_item() to use the new resolver (menu_icon_widget_new) for all icon-bearing quick/popup menu entries, making icon rendering behavior consistent across platforms.
This commit is contained in:
@@ -65,6 +65,60 @@
|
|||||||
|
|
||||||
static GSList *submenu_list;
|
static GSList *submenu_list;
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
menu_icon_exists_in_resource (const char *icon_name)
|
||||||
|
{
|
||||||
|
char *resource_path;
|
||||||
|
gboolean found;
|
||||||
|
|
||||||
|
if (!icon_name || !g_str_has_prefix (icon_name, "zc-menu-"))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
resource_path = g_strdup_printf ("/icons/menu/light/%s.svg", icon_name + strlen ("zc-menu-"));
|
||||||
|
found = g_resources_get_info (resource_path, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL, NULL, NULL);
|
||||||
|
g_free (resource_path);
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GtkWidget *
|
||||||
|
menu_icon_widget_new (const char *icon)
|
||||||
|
{
|
||||||
|
GtkWidget *img = NULL;
|
||||||
|
char *path;
|
||||||
|
|
||||||
|
if (!icon)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (access (icon, R_OK) == 0)
|
||||||
|
return gtk_image_new_from_file (icon);
|
||||||
|
|
||||||
|
path = g_build_filename (get_xdir (), icon, NULL);
|
||||||
|
if (access (path, R_OK) == 0)
|
||||||
|
{
|
||||||
|
img = gtk_image_new_from_file (path);
|
||||||
|
}
|
||||||
|
else if (g_str_has_prefix (icon, "zc-menu-") || g_str_has_prefix (icon, "gtk-"))
|
||||||
|
{
|
||||||
|
img = gtkutil_image_new_from_stock (icon, GTK_ICON_SIZE_MENU);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char *menu_icon_name = g_strdup_printf ("zc-menu-%s", icon);
|
||||||
|
|
||||||
|
if (menu_icon_exists_in_resource (menu_icon_name))
|
||||||
|
img = gtkutil_image_new_from_stock (menu_icon_name, GTK_ICON_SIZE_MENU);
|
||||||
|
else
|
||||||
|
img = gtkutil_image_new_from_stock (icon, GTK_ICON_SIZE_MENU);
|
||||||
|
|
||||||
|
g_free (menu_icon_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free (path);
|
||||||
|
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
|
||||||
static GtkWidget *
|
static GtkWidget *
|
||||||
menu_new (void)
|
menu_new (void)
|
||||||
{
|
{
|
||||||
@@ -278,7 +332,6 @@ menu_quick_item (char *cmd, char *label, GtkWidget * menu, int flags,
|
|||||||
gpointer userdata, char *icon)
|
gpointer userdata, char *icon)
|
||||||
{
|
{
|
||||||
GtkWidget *img, *item;
|
GtkWidget *img, *item;
|
||||||
char *path;
|
|
||||||
#if HAVE_GTK3
|
#if HAVE_GTK3
|
||||||
GtkWidget *box;
|
GtkWidget *box;
|
||||||
GtkWidget *image = NULL;
|
GtkWidget *image = NULL;
|
||||||
@@ -294,19 +347,7 @@ menu_quick_item (char *cmd, char *label, GtkWidget * menu, int flags,
|
|||||||
/*if (flags & XCMENU_MARKUP)
|
/*if (flags & XCMENU_MARKUP)
|
||||||
item = gtk_image_menu_item_new_with_markup (label);
|
item = gtk_image_menu_item_new_with_markup (label);
|
||||||
else*/
|
else*/
|
||||||
img = NULL;
|
img = menu_icon_widget_new (icon);
|
||||||
if (access (icon, R_OK) == 0) /* try fullpath */
|
|
||||||
img = gtk_image_new_from_file (icon);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* try relative to <xdir> */
|
|
||||||
path = g_build_filename (get_xdir (), icon, NULL);
|
|
||||||
if (access (path, R_OK) == 0)
|
|
||||||
img = gtk_image_new_from_file (path);
|
|
||||||
else
|
|
||||||
img = gtkutil_image_new_from_stock (icon, GTK_ICON_SIZE_MENU);
|
|
||||||
g_free (path);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if HAVE_GTK3
|
#if HAVE_GTK3
|
||||||
item = gtk_menu_item_new ();
|
item = gtk_menu_item_new ();
|
||||||
|
|||||||
Reference in New Issue
Block a user