@@ -45,6 +45,8 @@ Q_ENUM_NS(Enum);
45
45
// / A system tray item, roughly conforming to the [kde/freedesktop spec]
46
46
// / (there is no real spec, we just implemented whatever seemed to actually be used).
47
47
// /
48
+ // / The associated context menu can be retrieved using a [SystemTrayMenuWatcher](../systemtraymenuwatcher).
49
+ // /
48
50
// / [kde/freedesktop spec]: https://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/StatusNotifierItem/
49
51
class SystemTrayItem : public QObject {
50
52
using DBusMenuItem = qs::dbus::dbusmenu::DBusMenuItem;
@@ -60,8 +62,6 @@ class SystemTrayItem: public QObject {
60
62
Q_PROPERTY (QString icon READ icon NOTIFY iconChanged);
61
63
Q_PROPERTY (QString tooltipTitle READ tooltipTitle NOTIFY tooltipTitleChanged);
62
64
Q_PROPERTY (QString tooltipDescription READ tooltipDescription NOTIFY tooltipDescriptionChanged);
63
- // The context menu provided by the application, generally displayed via a right click.
64
- Q_PROPERTY (DBusMenuItem* menu READ menu NOTIFY menuChanged);
65
65
// / If this tray item only offers a menu and activation will do nothing.
66
66
Q_PROPERTY (bool onlyMenu READ onlyMenu NOTIFY onlyMenuChanged);
67
67
QML_ELEMENT;
@@ -71,13 +71,13 @@ class SystemTrayItem: public QObject {
71
71
explicit SystemTrayItem (qs::service::sni::StatusNotifierItem* item, QObject* parent = nullptr );
72
72
73
73
// / Primary activation action, generally triggered via a left click.
74
- Q_INVOKABLE void activate ();
74
+ Q_INVOKABLE void activate () const ;
75
75
76
76
// / Secondary activation action, generally triggered via a middle click.
77
- Q_INVOKABLE void secondaryActivate ();
77
+ Q_INVOKABLE void secondaryActivate () const ;
78
78
79
79
// / Scroll action, such as changing volume on a mixer.
80
- Q_INVOKABLE void scroll (qint32 delta, bool horizontal);
80
+ Q_INVOKABLE void scroll (qint32 delta, bool horizontal) const ;
81
81
82
82
[[nodiscard]] QString id () const ;
83
83
[[nodiscard]] QString title () const ;
@@ -86,9 +86,10 @@ class SystemTrayItem: public QObject {
86
86
[[nodiscard]] QString icon () const ;
87
87
[[nodiscard]] QString tooltipTitle () const ;
88
88
[[nodiscard]] QString tooltipDescription () const ;
89
- [[nodiscard]] DBusMenuItem* menu () const ;
90
89
[[nodiscard]] bool onlyMenu () const ;
91
90
91
+ qs::service::sni::StatusNotifierItem* item = nullptr ;
92
+
92
93
signals:
93
94
void idChanged ();
94
95
void titleChanged ();
@@ -97,17 +98,7 @@ class SystemTrayItem: public QObject {
97
98
void iconChanged ();
98
99
void tooltipTitleChanged ();
99
100
void tooltipDescriptionChanged ();
100
- void menuChanged ();
101
101
void onlyMenuChanged ();
102
-
103
- private slots:
104
- void onMenuPathChanged ();
105
-
106
- private:
107
- qs::service::sni::StatusNotifierItem* item = nullptr ;
108
- qs::dbus::dbusmenu::DBusMenu* mMenu = nullptr ;
109
-
110
- friend class SystemTray ;
111
102
};
112
103
113
104
// /! System tray
@@ -139,3 +130,39 @@ private slots:
139
130
140
131
QList<SystemTrayItem*> mItems ;
141
132
};
133
+
134
+ // /! Accessor for SystemTrayItem menus.
135
+ // / SystemTrayMenuWatcher provides access to the associated
136
+ // / [DBusMenuItem](../../quickshell.dbusmenu/dbusmenuitem) for a tray item.
137
+ class SystemTrayMenuWatcher : public QObject {
138
+ using DBusMenu = qs::dbus::dbusmenu::DBusMenu;
139
+ using DBusMenuItem = qs::dbus::dbusmenu::DBusMenuItem;
140
+
141
+ Q_OBJECT;
142
+ // / The tray item to watch.
143
+ Q_PROPERTY (SystemTrayItem* trayItem READ trayItem WRITE setTrayItem NOTIFY trayItemChanged);
144
+ // / The menu associated with the tray item. Will be null if `trayItem` is null
145
+ // / or has no associated menu.
146
+ Q_PROPERTY (DBusMenuItem* menu READ menu NOTIFY menuChanged);
147
+ QML_ELEMENT;
148
+
149
+ public:
150
+ explicit SystemTrayMenuWatcher (QObject* parent = nullptr ): QObject(parent) {}
151
+
152
+ [[nodiscard]] SystemTrayItem* trayItem () const ;
153
+ void setTrayItem (SystemTrayItem* item);
154
+
155
+ [[nodiscard]] DBusMenuItem* menu () const ;
156
+
157
+ signals:
158
+ void menuChanged ();
159
+ void trayItemChanged ();
160
+
161
+ private slots:
162
+ void onItemDestroyed ();
163
+ void onMenuPathChanged ();
164
+
165
+ private:
166
+ SystemTrayItem* item = nullptr ;
167
+ DBusMenu* mMenu = nullptr ;
168
+ };
0 commit comments