Skip to content

Commit 2b7b7f6

Browse files
Add icon format docs and use lookupIcon
Add an "Icon formats" section to README describing how `icon` and `notification_icon` can be file paths or theme names, listing supported formats per backend and recommending SVG/PNG for cross-platform use (noting libnotify limitations). Replace direct QIcon construction with lookupIcon(trayStruct->icon) in QtTrayMenu to properly resolve theme icon names and paths when setting the tray icon, aligning runtime behavior with the documented expectations.
1 parent 64a3ef2 commit 2b7b7f6

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ Execute the `tests` application:
127127
./build/tests/test_tray
128128
```
129129

130+
## Icon formats
131+
132+
The `icon` and `notification_icon` fields can be a path to an image file or an icon theme name. Relative file paths
133+
are resolved from the process working directory, so applications should copy or install icon files where the running
134+
process can find them.
135+
136+
| Component | Backend | Supported inputs | Notes |
137+
|----------------------------------------------------------------------------------------|-------------------------------------------------------|------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
138+
| Tray icon (`icon`) | Qt `QSystemTrayIcon` / `QIcon` on all platforms | SVG, ICO, PNG, Qt theme icon names | Loaded through Qt's `QIcon` path; SVG, ICO, and PNG are tested. Theme icon names are resolved by Qt when the platform/theme supports them. |
139+
| Notification icon (`notification_icon`) on Windows, macOS, and Linux without libnotify | Qt `QSystemTrayIcon::showMessage` / `QIcon` | SVG, ICO, PNG, Qt theme icon names | Loaded through Qt's `QIcon` path; SVG, ICO, and PNG are tested. Theme icon names are resolved by Qt when the platform/theme supports them. |
140+
| Notification icon (`notification_icon`) on Linux with libnotify | libnotify / freedesktop notification server | SVG, PNG, or icon theme name | libnotify accepts an icon theme name or filename, but the notification server and installed image loaders decide which file formats render. Do not rely on ICO for libnotify notifications. |
141+
142+
For the most predictable cross-platform behavior, use SVG or PNG files for both tray and notification icons. ICO is
143+
supported by the Qt-backed paths tested by this project, but it is not portable for libnotify notifications.
144+
Qt theme icons should be passed as icon name strings, such as `mail-message-new`.
145+
130146
## API
131147

132148
Tray structure defines an icon and a menu.

src/QtTrayMenu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void QtTrayMenu::onUpdate(struct tray *tray, const bool notify) {
101101
return;
102102
}
103103
this->trayStruct = tray;
104-
if (const auto newIcon = QIcon(trayStruct->icon); !newIcon.isNull()) {
104+
if (const auto newIcon = lookupIcon(trayStruct->icon); !newIcon.isNull()) {
105105
trayIcon->setIcon(newIcon);
106106
}
107107
trayIcon->setToolTip(QString::fromUtf8(trayStruct->tooltip));

0 commit comments

Comments
 (0)