diff --git a/src/panel/widgets/window-list/toplevel.cpp b/src/panel/widgets/window-list/toplevel.cpp index 69e5f0e1..d8f4d5c0 100644 --- a/src/panel/widgets/window-list/toplevel.cpp +++ b/src/panel/widgets/window-list/toplevel.cpp @@ -22,12 +22,6 @@ namespace extern zwlr_foreign_toplevel_handle_v1_listener toplevel_handle_v1_impl; } -namespace IconProvider -{ - void set_image_from_icon(Gtk::Image& image, - std::string app_id_list, int size, int scale); -} - class WayfireToplevel::impl { zwlr_foreign_toplevel_handle_v1 *handle, *parent; @@ -277,8 +271,7 @@ class WayfireToplevel::impl void set_app_id(std::string app_id) { this->app_id = app_id; - IconProvider::set_image_from_icon(image, app_id, - 24, button.get_scale_factor()); + set_image_from_icon(image, app_id, 24, button.get_scale_factor()); } void send_rectangle_hint() @@ -573,104 +566,3 @@ struct zwlr_foreign_toplevel_handle_v1_listener toplevel_handle_v1_impl = { .parent = handle_toplevel_parent }; } - -/* Icon loading functions */ -namespace IconProvider -{ - using Icon = Glib::RefPtr; - - namespace - { - std::string tolower(std::string str) - { - for (auto& c : str) - c = std::tolower(c); - return str; - } - } - - /* Gio::DesktopAppInfo - * - * Usually knowing the app_id, we can get a desktop app info from Gio - * The filename is either the app_id + ".desktop" or lower_app_id + ".desktop" */ - Icon get_from_desktop_app_info(std::string app_id) - { - Glib::RefPtr app_info; - - std::vector prefixes = { - "", - "/usr/share/applications/", - "/usr/share/applications/kde/", - "/usr/share/applications/org.kde.", - "/usr/local/share/applications/", - "/usr/local/share/applications/org.kde.", - }; - - std::vector app_id_variations = { - app_id, - tolower(app_id), - }; - - std::vector suffixes = { - "", - ".desktop" - }; - - for (auto& prefix : prefixes) - { - for (auto& id : app_id_variations) - { - for (auto& suffix : suffixes) - { - if (!app_info) - { - app_info = Gio::DesktopAppInfo - ::create_from_filename(prefix + id + suffix); - } - } - } - } - - if (app_info) // success - return app_info->get_icon(); - - return Icon{}; - } - - /* Second method: Just look up the built-in icon theme, - * perhaps some icon can be found there */ - - void set_image_from_icon(Gtk::Image& image, - std::string app_id_list, int size, int scale) - { - std::string app_id; - std::istringstream stream(app_id_list); - - /* Wayfire sends a list of app-id's in space separated format, other compositors - * send a single app-id, but in any case this works fine */ - while (stream >> app_id) - { - auto icon = get_from_desktop_app_info(app_id); - std::string icon_name = "unknown"; - - if (!icon) - { - /* Perhaps no desktop app info, but we might still be able to - * get an icon directly from the icon theme */ - if (Gtk::IconTheme::get_default()->lookup_icon(app_id, 24)) - icon_name = app_id; - } else - { - icon_name = icon->to_string(); - } - - WfIconLoadOptions options; - options.user_scale = scale; - set_image_icon(image, icon_name, size, options); - - /* finally found some icon */ - if (icon_name != "unknown") - break; - } - } -};