From 22ed153004e904ed58fe3d4817576552ff1fa57b Mon Sep 17 00:00:00 2001 From: jgmdev Date: Wed, 3 Feb 2021 21:04:10 -0400 Subject: [PATCH 1/3] [wlr/taskbar] Fix unhandled exception crash when icon name is a path. --- src/modules/wlr/taskbar.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index 15b927a8..93c6a77f 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -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" @@ -74,6 +76,18 @@ static std::vector search_prefix() return prefixes; } +Glib::RefPtr 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&) { + 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) { @@ -172,7 +186,17 @@ static bool image_load_icon(Gtk::Image& image, const Glib::RefPtrload_icon(icon_name, size, Gtk::ICON_LOOKUP_FORCE_SIZE); + Glib::RefPtr 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; From 8a284e7c74e25c07a603612393a9a07bf31baee7 Mon Sep 17 00:00:00 2001 From: jgmdev Date: Wed, 3 Feb 2021 21:14:04 -0400 Subject: [PATCH 2/3] [wlr/taskbar] Declared load_icon_from_file() static. --- src/modules/wlr/taskbar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index 93c6a77f..1135a8e5 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -76,7 +76,7 @@ static std::vector search_prefix() return prefixes; } -Glib::RefPtr load_icon_from_file(std::string icon_path, int size) +static Glib::RefPtr load_icon_from_file(std::string icon_path, int size) { try { auto pb = Gdk::Pixbuf::create_from_file(icon_path, size, size); From e293b89f6ba08ca92c834bad4473d708530521de Mon Sep 17 00:00:00 2001 From: jgmdev Date: Thu, 4 Feb 2021 04:57:08 -0400 Subject: [PATCH 3/3] [wlr/taskbar] Removed unnecessary catch statement. --- src/modules/wlr/taskbar.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index 1135a8e5..c2acbd9a 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -81,8 +81,6 @@ static Glib::RefPtr load_icon_from_file(std::string icon_path, int try { auto pb = Gdk::Pixbuf::create_from_file(icon_path, size, size); return pb; - } catch(Glib::Error&) { - return {}; } catch(...) { return {}; }