From 6d6df4be0013b6632a18d78a21174c7a71d80ecb Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 17 Apr 2019 22:15:18 +0200 Subject: [PATCH] refactor(sni-item): better way to search in default theme --- include/modules/sni/item.hpp | 1 - src/modules/sni/item.cpp | 17 ++++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/modules/sni/item.hpp b/include/modules/sni/item.hpp index fab966e..ac0c38a 100644 --- a/include/modules/sni/item.hpp +++ b/include/modules/sni/item.hpp @@ -65,7 +65,6 @@ class Item : public sigc::trackable { Glib::RefPtr cancellable_; Glib::RefPtr proxy_; - std::vector default_icon_path_; bool update_pending_; }; diff --git a/src/modules/sni/item.cpp b/src/modules/sni/item.cpp index 47b164d..cb2e6d7 100644 --- a/src/modules/sni/item.cpp +++ b/src/modules/sni/item.cpp @@ -18,8 +18,6 @@ waybar::modules::SNI::Item::Item(std::string bn, std::string op, const Json::Val if (config["icon-size"].isUInt()) { icon_size = config["icon-size"].asUInt(); } - default_icon_path_ = Gtk::IconTheme::get_default()->get_search_path(); - icon_theme->set_search_path(default_icon_path_); event_box.add(image); event_box.add_events(Gdk::BUTTON_PRESS_MASK); event_box.signal_button_press_event().connect(sigc::mem_fun(*this, &Item::handleClick)); @@ -97,9 +95,7 @@ void waybar::modules::SNI::Item::setProperty(const ustring& name, VariantBase& v } else if (name == "IconThemePath") { icon_theme_path = get_variant(value); if (!icon_theme_path.empty()) { - std::vector paths(default_icon_path_); - paths.push_back(icon_theme_path); - icon_theme->set_search_path(paths); + icon_theme->set_search_path({icon_theme_path}); } } else if (name == "Menu") { menu = get_variant(value); @@ -254,8 +250,15 @@ Glib::RefPtr waybar::modules::SNI::Item::getIconByName(std::string if (tmp_size == 0) { tmp_size = request_size; } - return icon_theme->load_icon(name.c_str(), tmp_size, - Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE); + auto icon = + icon_theme->load_icon(name.c_str(), tmp_size, Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE); + if (!icon) { + Glib::RefPtr default_theme = Gtk::IconTheme::get_default(); + default_theme->rescan_if_needed(); + return default_theme->load_icon(name.c_str(), tmp_size, + Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE); + } + return icon; } void waybar::modules::SNI::Item::onMenuDestroyed(Item* self) {