SNI: Allow absolute path for icons

Even though this is non-standard behavior, some apps still do this (e.g.
spotube)

Fixes: https://github.com/scorpion-26/gBar/issues/92
This commit is contained in:
scorpion-26 2024-05-02 11:19:48 +02:00
parent 808d6d5989
commit 3147ff21d8

View file

@ -228,15 +228,31 @@ namespace SNI
} }
if (iconName != "") if (iconName != "")
{ {
GError* err = nullptr; GdkPixbuf* pixbuf = nullptr;
GtkIconTheme* defaultTheme = gtk_icon_theme_get_default(); if (std::filesystem::path(iconName).is_absolute())
GdkPixbuf* pixbuf = gtk_icon_theme_load_icon(defaultTheme, iconName.c_str(), 64, GTK_ICON_LOOKUP_FORCE_SVG, &err);
if (err)
{ {
LOG("SNI: gtk_icon_theme_load_icon failed: " << err->message); // The icon name is an absolute path. This is not according to spec, but some apps (e.g. Spotube) still do it this way.
g_error_free(err); LOG("SNI: Warning: IconName shouldn't be a full path!");
GError* err = nullptr;
pixbuf = gdk_pixbuf_new_from_file(iconName.c_str(), &err);
if (err)
{
LOG("SNI: gdk_pixbuf_new_from_file failed: " << err->message);
}
} }
else if (pixbuf) else
{
GError* err = nullptr;
GtkIconTheme* defaultTheme = gtk_icon_theme_get_default();
pixbuf = gtk_icon_theme_load_icon(defaultTheme, iconName.c_str(), 64, GTK_ICON_LOOKUP_FORCE_SVG, &err);
if (err)
{
LOG("SNI: gtk_icon_theme_load_icon failed: " << err->message);
g_error_free(err);
}
}
if (pixbuf)
{ {
LOG("SNI: Creating icon from \"" << iconName << "\""); LOG("SNI: Creating icon from \"" << iconName << "\"");
data->item.pixbuf = pixbuf; data->item.pixbuf = pixbuf;