BaseTexturePtr LauncherIcon::TextureFromGtkTheme(std::string icon_name, int size, bool update_glow_colors)
{
GtkIconTheme* default_theme;
BaseTexturePtr result;
if (icon_name.empty())
icon_name = DEFAULT_ICON;
default_theme = gtk_icon_theme_get_default();
result = TextureFromSpecificGtkTheme(default_theme, icon_name, size, update_glow_colors);
if (!result)
result = TextureFromSpecificGtkTheme(GetUnityTheme(), icon_name, size, update_glow_colors);
if (!result)
result = TextureFromSpecificGtkTheme(default_theme, icon_name, size, update_glow_colors, true);
if (!result)
{
if (icon_name != "folder")
result = TextureFromSpecificGtkTheme(default_theme, "folder", size, update_glow_colors);
}
return result;
}
BaseTexturePtr LauncherIcon::TextureFromSpecificGtkTheme(GtkIconTheme* theme,
std::string const& icon_name,
int size,
bool update_glow_colors,
bool is_default_theme)
{
glib::Object<GIcon> icon(g_icon_new_for_string(icon_name.c_str(), nullptr));
gtk::IconInfo info;
auto flags = static_cast<GtkIconLookupFlags>(0);
if (icon.IsType(G_TYPE_ICON))
{
info = gtk_icon_theme_lookup_by_gicon(theme, icon, size, flags);
}
else
{
info = gtk_icon_theme_lookup_icon(theme, icon_name.c_str(), size, flags);
}
if (!info && !is_default_theme)
return BaseTexturePtr();
if (!info)
{
info = gtk_icon_theme_lookup_icon(theme, DEFAULT_ICON.c_str(), size, flags);
}
if (!gtk_icon_info_get_filename(info))
{
info = gtk_icon_theme_lookup_icon(theme, DEFAULT_ICON.c_str(), size, flags);
}
glib::Error error;
glib::Object<GdkPixbuf> pbuf(gtk_icon_info_load_icon(info, &error));
if (pbuf.IsType(GDK_TYPE_PIXBUF))
{
if (update_glow_colors)
ColorForIcon(pbuf, _background_color, _glow_color);
BaseTexturePtr result;
result.Adopt(nux::CreateTexture2DFromPixbuf(pbuf, true));
return result;
}
else
{
LOG_WARN(logger) << "Unable to load '" << icon_name
<< "' from icon theme: " << error;
}
return BaseTexturePtr();
}