Skip to content

Commit 658f3cf

Browse files
committed
docs: add API documentation for SystemTray and DBusMenu
1 parent 6106164 commit 658f3cf

File tree

5 files changed

+88
-17
lines changed

5 files changed

+88
-17
lines changed

docs

Submodule docs updated from 7c6cdbc to 6baa630

src/dbus/dbusmenu/dbusmenu.hpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ Q_NAMESPACE;
2424
QML_ELEMENT;
2525

2626
enum Enum {
27+
/// This menu item does not have a checkbox or a radiobutton associated with it.
2728
None = 0,
29+
/// This menu item should draw a checkbox.
2830
CheckBox = 1,
31+
/// This menu item should draw a radiobutton.
2932
RadioButton = 2,
3033
};
3134
Q_ENUM_NS(Enum);
@@ -41,19 +44,64 @@ QDebug operator<<(QDebug debug, const ToggleButtonType::Enum& toggleType);
4144
class DBusMenu;
4245
class DBusMenuPngImage;
4346

47+
///! Menu item shared by an external program.
48+
/// Menu item shared by an external program via the
49+
/// [DBusMenu specification](https://github.com/AyatanaIndicators/libdbusmenu/blob/master/libdbusmenu-glib/dbus-menu.xml).
4450
class DBusMenuItem: public QObject {
4551
Q_OBJECT;
4652
// clang-format off
53+
/// Handle to the root of this menu.
4754
Q_PROPERTY(DBusMenu* menuHandle READ menuHandle CONSTANT);
55+
/// Text of the menu item, including hotkey markup.
4856
Q_PROPERTY(QString label READ label NOTIFY labelChanged);
57+
/// Text of the menu item without hotkey markup.
4958
Q_PROPERTY(QString cleanLabel READ cleanLabel NOTIFY labelChanged);
59+
/// If the menu item should be shown as enabled.
60+
///
61+
/// > [!INFO] Disabled menu items are often used as headers in addition
62+
/// > to actual disabled entries.
5063
Q_PROPERTY(bool enabled READ enabled NOTIFY enabledChanged);
64+
/// Url of the menu item's icon or `""` if it doesn't have one.
65+
///
66+
/// This can be passed to [Image.source](https://doc.qt.io/qt-6/qml-qtquick-image.html#source-prop)
67+
/// as shown below.
68+
///
69+
/// ```qml
70+
/// Image {
71+
/// source: menuItem.icon
72+
/// // To get the best image quality, set the image source size to the same size
73+
/// // as the rendered image.
74+
/// sourceSize.width: width
75+
/// sourceSize.height: height
76+
/// }
77+
/// ```
5178
Q_PROPERTY(QString icon READ icon NOTIFY iconChanged);
79+
/// If this menu item has an associated checkbox or radiobutton.
80+
///
81+
/// > [!INFO] It is the responsibility of the remote application to update the state of
82+
/// > checkboxes and radiobuttons via [checkState](#prop.checkState).
5283
Q_PROPERTY(ToggleButtonType::Enum toggleType READ toggleType NOTIFY toggleTypeChanged);
84+
/// The check state of the checkbox or radiobutton if applicable, as a
85+
/// [Qt.CheckState](https://doc.qt.io/qt-6/qt.html#CheckState-enum).
5386
Q_PROPERTY(Qt::CheckState checkState READ checkState NOTIFY checkStateChanged);
87+
/// If this menu item should be rendered as a separator between other items.
88+
///
89+
/// No other properties have a meaningful value when `isSeparator` is true.
5490
Q_PROPERTY(bool isSeparator READ isSeparator NOTIFY separatorChanged);
91+
/// If this menu item reveals a submenu containing more items.
92+
///
93+
/// Any submenu items must be requested by setting [showChildren](#prop.showChildren).
5594
Q_PROPERTY(bool hasChildren READ hasChildren NOTIFY hasChildrenChanged);
95+
/// If submenu entries of this item should be shown.
96+
///
97+
/// When true, children of this menu item will be exposed via [children](#prop.children).
98+
/// Setting this property will additionally send the `opened` and `closed` events to the
99+
/// process that provided the menu.
56100
Q_PROPERTY(bool showChildren READ isShowingChildren WRITE setShowChildren NOTIFY showingChildrenChanged);
101+
/// Children of this menu item. Only populated when [showChildren](#prop.showChildren) is true.
102+
///
103+
/// > [!INFO] Use [hasChildren](#prop.hasChildren) to check if this item should reveal a submenu
104+
/// > instead of checking if `children` is empty.
57105
Q_PROPERTY(QQmlListProperty<DBusMenuItem> children READ children NOTIFY childrenChanged);
58106
// clang-format on
59107
QML_NAMED_ELEMENT(DBusMenu);
@@ -62,7 +110,12 @@ class DBusMenuItem: public QObject {
62110
public:
63111
explicit DBusMenuItem(qint32 id, DBusMenu* menu, DBusMenuItem* parentMenu);
64112

113+
/// Send a `clicked` event to the remote application for this menu item.
65114
Q_INVOKABLE void click();
115+
116+
/// Send a `hovered` event to the remote application for this menu item.
117+
///
118+
/// Note: we are not aware of any programs that use this in any meaningful way.
66119
Q_INVOKABLE void hover() const;
67120

68121
[[nodiscard]] DBusMenu* menuHandle() const;
@@ -122,6 +175,8 @@ class DBusMenuItem: public QObject {
122175

123176
QDebug operator<<(QDebug debug, DBusMenuItem* item);
124177

178+
///! Handle to a DBusMenu tree.
179+
/// Handle to a menu tree provided by a remote process.
125180
class DBusMenu: public QObject {
126181
Q_OBJECT;
127182
Q_PROPERTY(DBusMenuItem* menu READ menu CONSTANT);

src/dbus/dbusmenu/module.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name = "Quickshell.DBusMenu"
2+
description = "Types related to DBusMenu (used in system tray)"
3+
headers = [ "dbusmenu.hpp" ]
4+
-----
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name = "Quickshell.Service.SystemTray"
2+
description = "Types for implementing a system tray"
3+
headers = [ "qml.hpp" ]
4+
-----

src/services/status_notifier/qml.hpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ Q_NAMESPACE;
1313
QML_ELEMENT;
1414

1515
enum Enum {
16-
// A passive item does not convey important information and can be considered idle. You may want to hide these.
16+
/// A passive item does not convey important information and can be considered idle. You may want to hide these.
1717
Passive = 0,
18-
// An active item may have information more important than a passive one and you probably do not want to hide it.
18+
/// An active item may have information more important than a passive one and you probably do not want to hide it.
1919
Active = 1,
20-
// An item that needs attention conveys very important information such as low battery.
20+
/// An item that needs attention conveys very important information such as low battery.
2121
NeedsAttention = 2,
2222
};
2323
Q_ENUM_NS(Enum);
@@ -29,12 +29,12 @@ Q_NAMESPACE;
2929
QML_ELEMENT;
3030

3131
enum Enum {
32-
// The fallback category for general applications or anything that does
33-
// not fit into a different category.
32+
/// The fallback category for general applications or anything that does
33+
/// not fit into a different category.
3434
ApplicationStatus = 0,
35-
// System services such as IMEs or disk indexing.
35+
/// System services such as IMEs or disk indexing.
3636
SystemServices = 1,
37-
// Hardware controls like battery indicators or volume control.
37+
/// Hardware controls like battery indicators or volume control.
3838
Hardware = 2,
3939
};
4040
Q_ENUM_NS(Enum);
@@ -47,33 +47,36 @@ Q_ENUM_NS(Enum);
4747
///
4848
/// [kde/freedesktop spec]: https://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/StatusNotifierItem/
4949
class SystemTrayItem: public QObject {
50+
using DBusMenuItem = qs::dbus::dbusmenu::DBusMenuItem;
51+
5052
Q_OBJECT;
51-
// A name unique to the application, such as its name.
53+
/// A name unique to the application, such as its name.
5254
Q_PROPERTY(QString id READ id NOTIFY idChanged);
53-
// A name that describes the application
55+
/// Text that describes the application.
5456
Q_PROPERTY(QString title READ title NOTIFY titleChanged);
5557
Q_PROPERTY(SystemTrayStatus::Enum status READ status NOTIFY statusChanged);
5658
Q_PROPERTY(SystemTrayCategory::Enum category READ category NOTIFY categoryChanged);
57-
// Icon source string, usable as an Image source.
59+
/// Icon source string, usable as an Image source.
5860
Q_PROPERTY(QString icon READ icon NOTIFY iconChanged);
5961
Q_PROPERTY(QString tooltipTitle READ tooltipTitle NOTIFY tooltipTitleChanged);
6062
Q_PROPERTY(QString tooltipDescription READ tooltipDescription NOTIFY tooltipDescriptionChanged);
61-
Q_PROPERTY(qs::dbus::dbusmenu::DBusMenuItem* menu READ menu NOTIFY menuChanged);
62-
// If this tray item only offers a menu and no activation action.
63+
// The context menu provided by the application, generally displayed via a right click.
64+
Q_PROPERTY(DBusMenuItem* menu READ menu NOTIFY menuChanged);
65+
/// If this tray item only offers a menu and activation will do nothing.
6366
Q_PROPERTY(bool onlyMenu READ onlyMenu NOTIFY onlyMenuChanged);
6467
QML_ELEMENT;
6568
QML_UNCREATABLE("SystemTrayItems can only be acquired from SystemTray");
6669

6770
public:
6871
explicit SystemTrayItem(qs::service::sni::StatusNotifierItem* item, QObject* parent = nullptr);
6972

70-
// Primary activation action, generally triggered via a left click.
73+
/// Primary activation action, generally triggered via a left click.
7174
Q_INVOKABLE void activate();
7275

73-
// Secondary activation action, generally triggered via a middle click.
76+
/// Secondary activation action, generally triggered via a middle click.
7477
Q_INVOKABLE void secondaryActivate();
7578

76-
// Scroll action, such as changing volume on a mixer.
79+
/// Scroll action, such as changing volume on a mixer.
7780
Q_INVOKABLE void scroll(qint32 delta, bool horizontal);
7881

7982
[[nodiscard]] QString id() const;
@@ -83,7 +86,7 @@ class SystemTrayItem: public QObject {
8386
[[nodiscard]] QString icon() const;
8487
[[nodiscard]] QString tooltipTitle() const;
8588
[[nodiscard]] QString tooltipDescription() const;
86-
[[nodiscard]] qs::dbus::dbusmenu::DBusMenuItem* menu() const;
89+
[[nodiscard]] DBusMenuItem* menu() const;
8790
[[nodiscard]] bool onlyMenu() const;
8891

8992
signals:
@@ -107,8 +110,13 @@ private slots:
107110
friend class SystemTray;
108111
};
109112

113+
///! System tray
114+
/// Referencing the SystemTray singleton will make quickshell start tracking
115+
/// system tray contents, which are updated as the tray changes, and can be
116+
/// accessed via the `items` property.
110117
class SystemTray: public QObject {
111118
Q_OBJECT;
119+
/// List of all system tray icons.
112120
Q_PROPERTY(QQmlListProperty<SystemTrayItem> items READ items NOTIFY itemsChanged);
113121
QML_ELEMENT;
114122
QML_SINGLETON;

0 commit comments

Comments
 (0)