mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge pull request #1006 from jgmdev/taskbar-icons
Improved wlr/taskbar icon search.
This commit is contained in:
commit
be777b8525
@ -26,19 +26,19 @@ const std::string WHITESPACE = " \n\r\t\f\v";
|
|||||||
|
|
||||||
static std::string ltrim(const std::string& s)
|
static std::string ltrim(const std::string& s)
|
||||||
{
|
{
|
||||||
size_t start = s.find_first_not_of(WHITESPACE);
|
size_t start = s.find_first_not_of(WHITESPACE);
|
||||||
return (start == std::string::npos) ? "" : s.substr(start);
|
return (start == std::string::npos) ? "" : s.substr(start);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string rtrim(const std::string& s)
|
static std::string rtrim(const std::string& s)
|
||||||
{
|
{
|
||||||
size_t end = s.find_last_not_of(WHITESPACE);
|
size_t end = s.find_last_not_of(WHITESPACE);
|
||||||
return (end == std::string::npos) ? "" : s.substr(0, end + 1);
|
return (end == std::string::npos) ? "" : s.substr(0, end + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string trim(const std::string& s)
|
static std::string trim(const std::string& s)
|
||||||
{
|
{
|
||||||
return rtrim(ltrim(s));
|
return rtrim(ltrim(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -103,8 +103,8 @@ static std::string get_from_desktop_app_info(const std::string &app_id)
|
|||||||
|
|
||||||
/* Method 2 - use the app_id and check whether there is an icon with this name in the icon theme */
|
/* Method 2 - use the app_id and check whether there is an icon with this name in the icon theme */
|
||||||
static std::string get_from_icon_theme(const Glib::RefPtr<Gtk::IconTheme>& icon_theme,
|
static std::string get_from_icon_theme(const Glib::RefPtr<Gtk::IconTheme>& icon_theme,
|
||||||
const std::string &app_id) {
|
const std::string &app_id)
|
||||||
|
{
|
||||||
if (icon_theme->lookup_icon(app_id, 24))
|
if (icon_theme->lookup_icon(app_id, 24))
|
||||||
return app_id;
|
return app_id;
|
||||||
|
|
||||||
@ -122,6 +122,10 @@ static bool image_load_icon(Gtk::Image& image, const Glib::RefPtr<Gtk::IconTheme
|
|||||||
* send a single app-id, but in any case this works fine */
|
* send a single app-id, but in any case this works fine */
|
||||||
while (stream >> app_id)
|
while (stream >> app_id)
|
||||||
{
|
{
|
||||||
|
size_t start = 0, end = app_id.size();
|
||||||
|
start = app_id.rfind(".", end);
|
||||||
|
std::string app_name = app_id.substr(start+1, app_id.size());
|
||||||
|
|
||||||
auto lower_app_id = app_id;
|
auto lower_app_id = app_id;
|
||||||
std::transform(lower_app_id.begin(), lower_app_id.end(), lower_app_id.begin(),
|
std::transform(lower_app_id.begin(), lower_app_id.end(), lower_app_id.begin(),
|
||||||
[](char c){ return std::tolower(c); });
|
[](char c){ return std::tolower(c); });
|
||||||
@ -130,10 +134,14 @@ static bool image_load_icon(Gtk::Image& image, const Glib::RefPtr<Gtk::IconTheme
|
|||||||
|
|
||||||
if (icon_name.empty())
|
if (icon_name.empty())
|
||||||
icon_name = get_from_icon_theme(icon_theme, lower_app_id);
|
icon_name = get_from_icon_theme(icon_theme, lower_app_id);
|
||||||
|
if (icon_name.empty())
|
||||||
|
icon_name = get_from_icon_theme(icon_theme, app_name);
|
||||||
if (icon_name.empty())
|
if (icon_name.empty())
|
||||||
icon_name = get_from_desktop_app_info(app_id);
|
icon_name = get_from_desktop_app_info(app_id);
|
||||||
if (icon_name.empty())
|
if (icon_name.empty())
|
||||||
icon_name = get_from_desktop_app_info(lower_app_id);
|
icon_name = get_from_desktop_app_info(lower_app_id);
|
||||||
|
if (icon_name.empty())
|
||||||
|
icon_name = get_from_desktop_app_info(app_name);
|
||||||
|
|
||||||
if (icon_name.empty())
|
if (icon_name.empty())
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user