fix(tray): icons

This commit is contained in:
Alexis 2018-10-26 11:59:03 +02:00
parent e8f3c1c6b3
commit 5010227e6b
2 changed files with 12 additions and 15 deletions

View File

@ -2,6 +2,7 @@
#include <dbus-status-notifier-item.h> #include <dbus-status-notifier-item.h>
#include <gtkmm.h> #include <gtkmm.h>
#include <filesystem>
namespace waybar::modules::SNI { namespace waybar::modules::SNI {

View File

@ -167,32 +167,28 @@ waybar::modules::SNI::Item::extractPixBuf(GVariant *variant) {
void waybar::modules::SNI::Item::updateImage() void waybar::modules::SNI::Item::updateImage()
{ {
image->set_from_icon_name("image-missing", Gtk::ICON_SIZE_MENU);
image->set_pixel_size(icon_size);
if (!icon_name.empty()) { if (!icon_name.empty()) {
auto pixbuf = getIconByName(icon_name, icon_size);
if (pixbuf->gobj() == nullptr) {
// Try to find icons specified by path and filename
try { try {
pixbuf = Gdk::Pixbuf::create_from_file(icon_name); // Try to find icons specified by path and filename
if (std::filesystem::exists(icon_name)) {
auto pixbuf = Gdk::Pixbuf::create_from_file(icon_name);
if (pixbuf->gobj() != nullptr) { if (pixbuf->gobj() != nullptr) {
// An icon specified by path and filename may be the wrong size for // An icon specified by path and filename may be the wrong size for
// the tray // the tray
pixbuf->scale_simple(icon_size - 2, icon_size - 2, pixbuf->scale_simple(icon_size - 2, icon_size - 2,
Gdk::InterpType::INTERP_BILINEAR); Gdk::InterpType::INTERP_BILINEAR);
image->set(pixbuf);
}
} else {
image->set(getIconByName(icon_name, icon_size));
} }
} catch (Glib::Error &e) { } catch (Glib::Error &e) {
std::cerr << "Exception: " << e.what() << std::endl; std::cerr << "Exception: " << e.what() << std::endl;
pixbuf = getIconByName("image-missing", icon_size);
} }
}
if (pixbuf->gobj() == nullptr) {
pixbuf = getIconByName("image-missing", icon_size);
}
image->set(pixbuf);
} else if (icon_pixmap) { } else if (icon_pixmap) {
image->set(icon_pixmap); image->set(icon_pixmap);
} else {
image->set_from_icon_name("image-missing", Gtk::ICON_SIZE_MENU);
image->set_pixel_size(icon_size);
} }
if (!menu.empty()) { if (!menu.empty()) {
auto *dbmenu = dbusmenu_gtkmenu_new(bus_name.data(), menu.data()); auto *dbmenu = dbusmenu_gtkmenu_new(bus_name.data(), menu.data());