diff --git a/src/core/iconimageprovider.cpp b/src/core/iconimageprovider.cpp index f42643fa..f4710fb8 100644 --- a/src/core/iconimageprovider.cpp +++ b/src/core/iconimageprovider.cpp @@ -10,7 +10,19 @@ QPixmap IconImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) { - auto icon = QIcon::fromTheme(id); + QString iconName; + QString path; + auto splitIdx = id.indexOf("?path="); + if (splitIdx != -1) { + iconName = id.sliced(0, splitIdx); + path = id.sliced(splitIdx + 6); + qWarning() << "Searching custom icon paths is not yet supported. Icon path will be ignored for" + << id; + } else { + iconName = id; + } + + auto icon = QIcon::fromTheme(iconName); auto targetSize = requestedSize.isValid() ? requestedSize : QSize(100, 100); if (targetSize.width() == 0 || targetSize.height() == 0) targetSize = QSize(2, 2); @@ -42,3 +54,13 @@ QPixmap IconImageProvider::missingPixmap(const QSize& size) { painter.fillRect(0, halfHeight, halfWidth, halfHeight, purple); return pixmap; } + +QString IconImageProvider::requestString(const QString& icon, const QString& path) { + auto req = "image://icon/" + icon; + + if (!path.isEmpty()) { + req += "?path=" + path; + } + + return req; +} diff --git a/src/core/iconimageprovider.hpp b/src/core/iconimageprovider.hpp index 8858f4ba..167d93bd 100644 --- a/src/core/iconimageprovider.hpp +++ b/src/core/iconimageprovider.hpp @@ -10,4 +10,5 @@ public: QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override; static QPixmap missingPixmap(const QSize& size); + static QString requestString(const QString& icon, const QString& path); }; diff --git a/src/services/status_notifier/item.cpp b/src/services/status_notifier/item.cpp index 713d455c..51047786 100644 --- a/src/services/status_notifier/item.cpp +++ b/src/services/status_notifier/item.cpp @@ -15,6 +15,7 @@ #include #include +#include "../../core/iconimageprovider.hpp" #include "../../dbus/dbusutil.hpp" #include "dbus_item.h" #include "dbus_item_types.hpp" @@ -49,15 +50,16 @@ StatusNotifierItem::StatusNotifierItem(const QString& address, QObject* parent) QObject::connect(this->item, &DBusStatusNotifierItem::NewTitle, &this->title, &AbstractDBusProperty::update); QObject::connect(this->item, &DBusStatusNotifierItem::NewIcon, &this->iconName, &AbstractDBusProperty::update); QObject::connect(this->item, &DBusStatusNotifierItem::NewIcon, &this->iconPixmaps, &AbstractDBusProperty::update); - //QObject::connect(this->item, &DBusStatusNotifierItem::NewIcon, &this->iconThemePath, &AbstractDBusProperty::update); + QObject::connect(this->item, &DBusStatusNotifierItem::NewIcon, &this->iconThemePath, &AbstractDBusProperty::update); QObject::connect(this->item, &DBusStatusNotifierItem::NewOverlayIcon, &this->overlayIconName, &AbstractDBusProperty::update); QObject::connect(this->item, &DBusStatusNotifierItem::NewOverlayIcon, &this->overlayIconPixmaps, &AbstractDBusProperty::update); - //QObject::connect(this->item, &DBusStatusNotifierItem::NewOverlayIcon, &this->iconThemePath, &AbstractDBusProperty::update); + QObject::connect(this->item, &DBusStatusNotifierItem::NewOverlayIcon, &this->iconThemePath, &AbstractDBusProperty::update); QObject::connect(this->item, &DBusStatusNotifierItem::NewAttentionIcon, &this->attentionIconName, &AbstractDBusProperty::update); QObject::connect(this->item, &DBusStatusNotifierItem::NewAttentionIcon, &this->attentionIconPixmaps, &AbstractDBusProperty::update); - //QObject::connect(this->item, &DBusStatusNotifierItem::NewAttentionIcon, &this->iconThemePath, &AbstractDBusProperty::update); + QObject::connect(this->item, &DBusStatusNotifierItem::NewAttentionIcon, &this->iconThemePath, &AbstractDBusProperty::update); QObject::connect(this->item, &DBusStatusNotifierItem::NewToolTip, &this->tooltip, &AbstractDBusProperty::update); + QObject::connect(&this->iconThemePath, &AbstractDBusProperty::changed, this, &StatusNotifierItem::updateIcon); QObject::connect(&this->iconName, &AbstractDBusProperty::changed, this, &StatusNotifierItem::updateIcon); QObject::connect(&this->attentionIconName, &AbstractDBusProperty::changed, this, &StatusNotifierItem::updateIcon); QObject::connect(&this->overlayIconName, &AbstractDBusProperty::changed, this, &StatusNotifierItem::updateIcon); @@ -83,11 +85,12 @@ bool StatusNotifierItem::isReady() const { return this->mReady; } QString StatusNotifierItem::iconId() const { if (this->status.get() == "NeedsAttention") { auto name = this->attentionIconName.get(); - if (!name.isEmpty()) return QString("image://icon/") + name; + if (!name.isEmpty()) return IconImageProvider::requestString(name, this->iconThemePath.get()); } else { auto name = this->iconName.get(); auto overlayName = this->overlayIconName.get(); - if (!name.isEmpty() && overlayName.isEmpty()) return QString("image://icon/") + name; + if (!name.isEmpty() && overlayName.isEmpty()) + return IconImageProvider::requestString(name, this->iconThemePath.get()); } return QString("image://service.sni/") + this->watcherId + "/" + QString::number(this->iconIndex); diff --git a/src/services/status_notifier/item.hpp b/src/services/status_notifier/item.hpp index 22de7946..cbe21ff2 100644 --- a/src/services/status_notifier/item.hpp +++ b/src/services/status_notifier/item.hpp @@ -39,7 +39,7 @@ public: dbus::DBusProperty status {this->properties, "Status"}; dbus::DBusProperty category {this->properties, "Category"}; dbus::DBusProperty windowId {this->properties, "WindowId"}; - //dbus::DBusProperty iconThemePath {this->properties, "IconThemePath"}; + dbus::DBusProperty iconThemePath {this->properties, "IconThemePath"}; dbus::DBusProperty iconName {this->properties, "IconName"}; dbus::DBusProperty iconPixmaps {this->properties, "IconPixmap"}; dbus::DBusProperty overlayIconName {this->properties, "OverlayIconName"};