summaryrefslogtreecommitdiff
path: root/kde-plasma/plasma-workspace/files/plasma-workspace-5.24.5-applets-systemtray-prefer-IconName-over-IconPixmap.patch
blob: 0ac8ed788ade63905d0c0e020e9fe5b1e41c2ca8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
From ea2833e4dd7114f8bf22a322a26c6c05ebf767f2 Mon Sep 17 00:00:00 2001
From: Vlad Zahorodnii <vlad.zahorodnii@kde.org>
Date: Mon, 25 Apr 2022 21:58:58 +0300
Subject: [PATCH 3/8] applets/systemtray: Prefer IconName over IconPixmap

In case both IconName and IconPixmap are provided, the system tray
applet is going to prefer the pixmap.

That can create a dark icon on dark background bug because plasma can't
recolor pixmaps.

The SNI spec recommends visualizations to prefer icons over pixmaps:

> An icon can either be identified by its Freedesktop-compliant icon
> name, carried by this property of by the icon data itself, carried by
> the property IconPixmap. Visualizations are encouraged to prefer icon
> names over icon pixmaps if both are available (FIXME: still not very
> defined: could e the pixmap used as fallback if an icon name is not found?)

BUG: 418996

- Unset iconName when icon can't be loaded
- no code duplication
(cherry picked from commit 7363d0e0f3c1a447e6264e92762735bd33da2682)
---
 .../systemtray/statusnotifieritemsource.cpp   | 82 ++++++++-----------
 1 file changed, 33 insertions(+), 49 deletions(-)

diff --git a/applets/systemtray/statusnotifieritemsource.cpp b/applets/systemtray/statusnotifieritemsource.cpp
index f67845e42..731aecadc 100644
--- a/applets/systemtray/statusnotifieritemsource.cpp
+++ b/applets/systemtray/statusnotifieritemsource.cpp
@@ -286,68 +286,52 @@ void StatusNotifierItemSource::refreshCallback(QDBusPendingCallWatcher *call)
         QIcon overlay;
         QStringList overlayNames;
 
-        // Icon
+        // Overlay icon
         {
-            KDbusImageVector image;
-            QIcon icon;
-            QString iconName;
-
-            properties[QStringLiteral("OverlayIconPixmap")].value<QDBusArgument>() >> image;
-            if (image.isEmpty()) {
-                QString iconName = properties[QStringLiteral("OverlayIconName")].toString();
-                m_overlayIconName = iconName;
-                if (!iconName.isEmpty()) {
+            m_overlayIconName = QString();
+
+            const QString iconName = properties[QStringLiteral("OverlayIconName")].toString();
+            if (!iconName.isEmpty()) {
+                overlay = QIcon(new KIconEngine(iconName, iconLoader()));
+                if (!overlay.isNull()) {
+                    m_overlayIconName = iconName;
                     overlayNames << iconName;
-                    overlay = QIcon(new KIconEngine(iconName, iconLoader()));
                 }
-            } else {
-                overlay = imageVectorToPixmap(image);
             }
+            if (overlay.isNull()) {
+                KDbusImageVector image;
+                properties[QStringLiteral("OverlayIconPixmap")].value<QDBusArgument>() >> image;
+                if (!image.isEmpty()) {
+                    overlay = imageVectorToPixmap(image);
+                }
+            }
+        }
 
-            properties[QStringLiteral("IconPixmap")].value<QDBusArgument>() >> image;
-            if (image.isEmpty()) {
-                iconName = properties[QStringLiteral("IconName")].toString();
-                if (!iconName.isEmpty()) {
-                    icon = QIcon(new KIconEngine(iconName, iconLoader(), overlayNames));
-
-                    if (overlayNames.isEmpty() && !overlay.isNull()) {
+        auto loadIcon = [this, &properties, &overlay, &overlayNames](const QString &iconKey, const QString &pixmapKey) -> std::tuple<QIcon, QString> {
+            const QString iconName = properties[iconKey].toString();
+            if (!iconName.isEmpty()) {
+                QIcon icon = QIcon(new KIconEngine(iconName, iconLoader(), overlayNames));
+                if (!icon.isNull()) {
+                    if (!overlay.isNull() && overlayNames.isEmpty()) {
                         overlayIcon(&icon, &overlay);
                     }
+                    return {icon, iconName};
                 }
-            } else {
-                icon = imageVectorToPixmap(image);
+            }
+            KDbusImageVector image;
+            properties[pixmapKey].value<QDBusArgument>() >> image;
+            if (!image.isEmpty()) {
+                QIcon icon = imageVectorToPixmap(image);
                 if (!icon.isNull() && !overlay.isNull()) {
                     overlayIcon(&icon, &overlay);
                 }
+                return {icon, QString()};
             }
-            m_icon = icon;
-            m_iconName = iconName;
-        }
+            return {};
+        };
 
-        // Attention icon
-        {
-            KDbusImageVector image;
-            QIcon attentionIcon;
-
-            properties[QStringLiteral("AttentionIconPixmap")].value<QDBusArgument>() >> image;
-            if (image.isEmpty()) {
-                QString iconName = properties[QStringLiteral("AttentionIconName")].toString();
-                m_attentionIconName = iconName;
-                if (!iconName.isEmpty()) {
-                    attentionIcon = QIcon(new KIconEngine(iconName, iconLoader(), overlayNames));
-
-                    if (overlayNames.isEmpty() && !overlay.isNull()) {
-                        overlayIcon(&attentionIcon, &overlay);
-                    }
-                }
-            } else {
-                attentionIcon = imageVectorToPixmap(image);
-                if (!attentionIcon.isNull() && !overlay.isNull()) {
-                    overlayIcon(&attentionIcon, &overlay);
-                }
-            }
-            m_attentionIcon = attentionIcon;
-        }
+        std::tie(m_icon, m_iconName) = loadIcon(QStringLiteral("IconName"), QStringLiteral("IconPixmap"));
+        std::tie(m_attentionIcon, m_attentionIconName) = loadIcon(QStringLiteral("AttentionIconName"), QStringLiteral("AttentionIconPixmap"));
 
         // ToolTip
         {
-- 
2.35.1