mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
refactor(sni-item): better way to search in default theme
This commit is contained in:
parent
9564adb5b4
commit
6d6df4be00
@ -65,7 +65,6 @@ class Item : public sigc::trackable {
|
||||
|
||||
Glib::RefPtr<Gio::Cancellable> cancellable_;
|
||||
Glib::RefPtr<Gio::DBus::Proxy> proxy_;
|
||||
std::vector<Glib::ustring> default_icon_path_;
|
||||
bool update_pending_;
|
||||
};
|
||||
|
||||
|
@ -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<std::string>(value);
|
||||
if (!icon_theme_path.empty()) {
|
||||
std::vector<Glib::ustring> 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<std::string>(value);
|
||||
@ -254,9 +250,16 @@ Glib::RefPtr<Gdk::Pixbuf> 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,
|
||||
auto icon =
|
||||
icon_theme->load_icon(name.c_str(), tmp_size, Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
|
||||
if (!icon) {
|
||||
Glib::RefPtr<Gtk::IconTheme> 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) {
|
||||
self->gtk_menu = nullptr;
|
||||
|
Loading…
Reference in New Issue
Block a user