Skip to content

Commit 7cfb188

Browse files
committed
[wf-panel/window-list] replaced IconProvider with gtk-utils function.
1 parent f2a9667 commit 7cfb188

1 file changed

Lines changed: 1 addition & 109 deletions

File tree

src/panel/widgets/window-list/toplevel.cpp

Lines changed: 1 addition & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ namespace
2222
extern zwlr_foreign_toplevel_handle_v1_listener toplevel_handle_v1_impl;
2323
}
2424

25-
namespace IconProvider
26-
{
27-
void set_image_from_icon(Gtk::Image& image,
28-
std::string app_id_list, int size, int scale);
29-
}
30-
3125
class WayfireToplevel::impl
3226
{
3327
zwlr_foreign_toplevel_handle_v1 *handle, *parent;
@@ -277,8 +271,7 @@ class WayfireToplevel::impl
277271
void set_app_id(std::string app_id)
278272
{
279273
this->app_id = app_id;
280-
IconProvider::set_image_from_icon(image, app_id,
281-
24, button.get_scale_factor());
274+
set_image_from_icon(image, app_id, 24, button.get_scale_factor());
282275
}
283276

284277
void send_rectangle_hint()
@@ -573,104 +566,3 @@ struct zwlr_foreign_toplevel_handle_v1_listener toplevel_handle_v1_impl = {
573566
.parent = handle_toplevel_parent
574567
};
575568
}
576-
577-
/* Icon loading functions */
578-
namespace IconProvider
579-
{
580-
using Icon = Glib::RefPtr<Gio::Icon>;
581-
582-
namespace
583-
{
584-
std::string tolower(std::string str)
585-
{
586-
for (auto& c : str)
587-
c = std::tolower(c);
588-
return str;
589-
}
590-
}
591-
592-
/* Gio::DesktopAppInfo
593-
*
594-
* Usually knowing the app_id, we can get a desktop app info from Gio
595-
* The filename is either the app_id + ".desktop" or lower_app_id + ".desktop" */
596-
Icon get_from_desktop_app_info(std::string app_id)
597-
{
598-
Glib::RefPtr<Gio::DesktopAppInfo> app_info;
599-
600-
std::vector<std::string> prefixes = {
601-
"",
602-
"/usr/share/applications/",
603-
"/usr/share/applications/kde/",
604-
"/usr/share/applications/org.kde.",
605-
"/usr/local/share/applications/",
606-
"/usr/local/share/applications/org.kde.",
607-
};
608-
609-
std::vector<std::string> app_id_variations = {
610-
app_id,
611-
tolower(app_id),
612-
};
613-
614-
std::vector<std::string> suffixes = {
615-
"",
616-
".desktop"
617-
};
618-
619-
for (auto& prefix : prefixes)
620-
{
621-
for (auto& id : app_id_variations)
622-
{
623-
for (auto& suffix : suffixes)
624-
{
625-
if (!app_info)
626-
{
627-
app_info = Gio::DesktopAppInfo
628-
::create_from_filename(prefix + id + suffix);
629-
}
630-
}
631-
}
632-
}
633-
634-
if (app_info) // success
635-
return app_info->get_icon();
636-
637-
return Icon{};
638-
}
639-
640-
/* Second method: Just look up the built-in icon theme,
641-
* perhaps some icon can be found there */
642-
643-
void set_image_from_icon(Gtk::Image& image,
644-
std::string app_id_list, int size, int scale)
645-
{
646-
std::string app_id;
647-
std::istringstream stream(app_id_list);
648-
649-
/* Wayfire sends a list of app-id's in space separated format, other compositors
650-
* send a single app-id, but in any case this works fine */
651-
while (stream >> app_id)
652-
{
653-
auto icon = get_from_desktop_app_info(app_id);
654-
std::string icon_name = "unknown";
655-
656-
if (!icon)
657-
{
658-
/* Perhaps no desktop app info, but we might still be able to
659-
* get an icon directly from the icon theme */
660-
if (Gtk::IconTheme::get_default()->lookup_icon(app_id, 24))
661-
icon_name = app_id;
662-
} else
663-
{
664-
icon_name = icon->to_string();
665-
}
666-
667-
WfIconLoadOptions options;
668-
options.user_scale = scale;
669-
set_image_icon(image, icon_name, size, options);
670-
671-
/* finally found some icon */
672-
if (icon_name != "unknown")
673-
break;
674-
}
675-
}
676-
};

0 commit comments

Comments
 (0)