From fc9a3909774e8ea012f528f09045a98e8997dc30 Mon Sep 17 00:00:00 2001 From: Marvin Dostal Date: Sun, 17 Jul 2022 13:34:01 +0200 Subject: [PATCH 1/5] sni: Use the given pixmap even if there is a name given --- src/modules/sni/item.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/sni/item.cpp b/src/modules/sni/item.cpp index 0295153e..b2c41edb 100644 --- a/src/modules/sni/item.cpp +++ b/src/modules/sni/item.cpp @@ -319,14 +319,15 @@ void Item::updateImage() { Glib::RefPtr Item::getIconPixbuf() { try { + if (icon_pixmap) { + return icon_pixmap; + } if (!icon_name.empty()) { std::ifstream temp(icon_name); if (temp.is_open()) { return Gdk::Pixbuf::create_from_file(icon_name); } return getIconByName(icon_name, getScaledIconSize()); - } else if (icon_pixmap) { - return icon_pixmap; } } catch (Glib::Error& e) { spdlog::error("Item '{}': {}", id, static_cast(e.what())); From f437bf96e38f6edb5e271ebc4792dc2d92c60c36 Mon Sep 17 00:00:00 2001 From: Marvin Dostal Date: Sun, 17 Jul 2022 22:11:08 +0200 Subject: [PATCH 2/5] sni: Prefer system icons over pixmap --- src/modules/sni/item.cpp | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/modules/sni/item.cpp b/src/modules/sni/item.cpp index b2c41edb..cd77964c 100644 --- a/src/modules/sni/item.cpp +++ b/src/modules/sni/item.cpp @@ -318,20 +318,42 @@ void Item::updateImage() { } Glib::RefPtr Item::getIconPixbuf() { - try { - if (icon_pixmap) { - return icon_pixmap; - } - if (!icon_name.empty()) { + + if (!icon_name.empty()) { + + try { std::ifstream temp(icon_name); if (temp.is_open()) { return Gdk::Pixbuf::create_from_file(icon_name); } - return getIconByName(icon_name, getScaledIconSize()); + } catch (Glib::Error& e) { + // Ignore because we want to also try different methods of getting an icon. + // + // But a warning is logged, as the file apparently exists, but there was + // a failure in creating a pixbuf out of it. + + spdlog::warn("Item '{}': {}", id, static_cast(e.what())); + } + + try { + // Will throw if it can not find an icon. + return getIconByName(icon_name, getScaledIconSize()); + } catch (Glib::Error& e) { + spdlog::info("Item '{}': {}", id, static_cast(e.what())); } - } catch (Glib::Error& e) { - spdlog::error("Item '{}': {}", id, static_cast(e.what())); } + + // Return the pixmap only if an icon for the given name could not be found. + if (icon_pixmap) { + return icon_pixmap; + } + + if (icon_name.empty()) { + spdlog::error("Item '{}': No icon name or pixmap given.", id, icon_name); + } else { + spdlog::error("Item '{}': Could not find an icon named '{}' and no pixmap given.", id, icon_name); + } + return getIconByName("image-missing", getScaledIconSize()); } From 699f732146fc15034756d297ebb88df2d7f1e84b Mon Sep 17 00:00:00 2001 From: Marvin Dostal Date: Sun, 17 Jul 2022 22:13:20 +0200 Subject: [PATCH 3/5] sni: Remove unnecessary getIconByName call --- src/modules/sni/item.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/modules/sni/item.cpp b/src/modules/sni/item.cpp index cd77964c..e30e5e8c 100644 --- a/src/modules/sni/item.cpp +++ b/src/modules/sni/item.cpp @@ -300,10 +300,6 @@ void Item::updateImage() { auto pixbuf = getIconPixbuf(); auto scaled_icon_size = getScaledIconSize(); - if (!pixbuf) { - pixbuf = getIconByName("image-missing", getScaledIconSize()); - } - // If the loaded icon is not square, assume that the icon height should match the // requested icon size, but the width is allowed to be different. As such, if the // height of the image does not match the requested icon size, resize the icon such that From 04d66de866c58ff22546ecd647380597690ef7e7 Mon Sep 17 00:00:00 2001 From: Marvin Dostal Date: Sun, 17 Jul 2022 22:20:24 +0200 Subject: [PATCH 4/5] sni: remove unnecesary parameter --- src/modules/sni/item.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/sni/item.cpp b/src/modules/sni/item.cpp index e30e5e8c..07ebeba8 100644 --- a/src/modules/sni/item.cpp +++ b/src/modules/sni/item.cpp @@ -345,7 +345,7 @@ Glib::RefPtr Item::getIconPixbuf() { } if (icon_name.empty()) { - spdlog::error("Item '{}': No icon name or pixmap given.", id, icon_name); + spdlog::error("Item '{}': No icon name or pixmap given.", id); } else { spdlog::error("Item '{}': Could not find an icon named '{}' and no pixmap given.", id, icon_name); } From 95b5348c24ee88dd389cd65d2c513ac212e07015 Mon Sep 17 00:00:00 2001 From: Marvin Dostal Date: Wed, 3 Aug 2022 17:34:34 +0200 Subject: [PATCH 5/5] sni: change missing icon in theme logging from info to trace --- src/modules/sni/item.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/sni/item.cpp b/src/modules/sni/item.cpp index 07ebeba8..773cfdae 100644 --- a/src/modules/sni/item.cpp +++ b/src/modules/sni/item.cpp @@ -335,7 +335,7 @@ Glib::RefPtr Item::getIconPixbuf() { // Will throw if it can not find an icon. return getIconByName(icon_name, getScaledIconSize()); } catch (Glib::Error& e) { - spdlog::info("Item '{}': {}", id, static_cast(e.what())); + spdlog::trace("Item '{}': {}", id, static_cast(e.what())); } }