Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wlr/taskbar] Fix unhandled exception crash when icon name is a path. #1018

Merged
merged 3 commits into from
Feb 4, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/modules/wlr/taskbar.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "modules/wlr/taskbar.hpp"

#include "glibmm/error.h"
#include "glibmm/fileutils.h"
#include "glibmm/refptr.h"
#include "util/format.hpp"

Expand Down Expand Up @@ -74,6 +76,18 @@ static std::vector<std::string> search_prefix()
return prefixes;
}

static Glib::RefPtr<Gdk::Pixbuf> load_icon_from_file(std::string icon_path, int size)
{
try {
auto pb = Gdk::Pixbuf::create_from_file(icon_path, size, size);
return pb;
} catch(Glib::Error&) {
jgmdev marked this conversation as resolved.
Show resolved Hide resolved
return {};
} catch(...) {
return {};
}
}

/* Method 1 - get the correct icon name from the desktop file */
static std::string get_from_desktop_app_info(const std::string &app_id)
{
Expand Down Expand Up @@ -172,7 +186,17 @@ static bool image_load_icon(Gtk::Image& image, const Glib::RefPtr<Gtk::IconTheme
if (icon_name.empty())
icon_name = "unknown";

auto pixbuf = icon_theme->load_icon(icon_name, size, Gtk::ICON_LOOKUP_FORCE_SIZE);
Glib::RefPtr<Gdk::Pixbuf> pixbuf;

try {
pixbuf = icon_theme->load_icon(icon_name, size, Gtk::ICON_LOOKUP_FORCE_SIZE);
} catch(...) {
if (Glib::file_test(icon_name, Glib::FILE_TEST_EXISTS))
pixbuf = load_icon_from_file(icon_name, size);
else
pixbuf = {};
}

if (pixbuf) {
image.set(pixbuf);
found = true;
Expand Down