Skip to content

Commit ce4e697

Browse files
committed
service/tray: use bilinear scaling for tray icons
Apparently some programs think it is a good idea to send 1000x+ images.
1 parent c6e5a35 commit ce4e697

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/services/status_notifier/item.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <qicon.h>
77
#include <qlogging.h>
88
#include <qloggingcategory.h>
9+
#include <qnamespace.h>
910
#include <qobject.h>
1011
#include <qpainter.h>
1112
#include <qpixmap.h>
@@ -123,15 +124,27 @@ QPixmap StatusNotifierItem::createPixmap(const QSize& size) const {
123124
pixmap = icon.pixmap(size.width(), size.height());
124125
} else {
125126
const auto* icon = closestPixmap(size, this->attentionIconPixmaps.get());
126-
if (icon != nullptr) pixmap = QPixmap::fromImage(icon->createImage());
127+
128+
if (icon != nullptr) {
129+
const auto image =
130+
icon->createImage().scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
131+
132+
pixmap = QPixmap::fromImage(image);
133+
}
127134
}
128135
} else {
129136
if (!this->iconName.get().isEmpty()) {
130137
auto icon = QIcon::fromTheme(this->iconName.get());
131138
pixmap = icon.pixmap(size.width(), size.height());
132139
} else {
133140
const auto* icon = closestPixmap(size, this->iconPixmaps.get());
134-
if (icon != nullptr) pixmap = QPixmap::fromImage(icon->createImage());
141+
142+
if (icon != nullptr) {
143+
const auto image =
144+
icon->createImage().scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
145+
146+
pixmap = QPixmap::fromImage(image);
147+
}
135148
}
136149

137150
QPixmap overlay;
@@ -140,7 +153,13 @@ QPixmap StatusNotifierItem::createPixmap(const QSize& size) const {
140153
overlay = icon.pixmap(pixmap.width(), pixmap.height());
141154
} else {
142155
const auto* icon = closestPixmap(pixmap.size(), this->overlayIconPixmaps.get());
143-
if (icon != nullptr) overlay = QPixmap::fromImage(icon->createImage());
156+
157+
if (icon != nullptr) {
158+
const auto image =
159+
icon->createImage().scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
160+
161+
overlay = QPixmap::fromImage(image);
162+
}
144163
}
145164

146165
if (!overlay.isNull()) {

0 commit comments

Comments
 (0)