|
19 | 19 | #include <QGuiApplication> |
20 | 20 | #include <QIcon> |
21 | 21 | #include <QMenu> |
| 22 | +#include <QPixmap> |
22 | 23 | #include <QScreen> |
23 | 24 | #include <QSystemTrayIcon> |
24 | 25 | #include <QTimer> |
@@ -266,17 +267,16 @@ extern "C" { |
266 | 267 | // event-loop iteration via QTimer::singleShot(0). Deferring allows any |
267 | 268 | // platform pointer grab from the tray click to be released before the menu |
268 | 269 | // establishes its own grab. |
269 | | - // QApplication::setActiveWindow gives the menu window X11 focus so that the |
270 | | - // subsequent XGrabPointer inside popup() succeeds, enabling click-outside |
271 | | - // dismissal on Xorg. |
| 270 | + // activateWindow() gives the menu window X11 focus so that the subsequent |
| 271 | + // XGrabPointer inside popup() succeeds, enabling click-outside dismissal on Xorg. |
272 | 272 | QObject::connect(g_tray_icon, &QSystemTrayIcon::activated, [](QSystemTrayIcon::ActivationReason reason) { |
273 | 273 | if (reason == QSystemTrayIcon::Trigger) { |
274 | 274 | const QPoint pos = calculateMenuPosition(); |
275 | 275 | QTimer::singleShot(0, g_tray_icon, [pos]() { |
276 | 276 | if (g_tray_icon != nullptr) { |
277 | 277 | QMenu *menu = g_tray_icon->contextMenu(); |
278 | 278 | if (menu != nullptr && !menu->isVisible()) { |
279 | | - QApplication::setActiveWindow(menu); |
| 279 | + menu->activateWindow(); |
280 | 280 | menu->popup(pos); |
281 | 281 | } |
282 | 282 | } |
@@ -337,7 +337,20 @@ extern "C" { |
337 | 337 | } |
338 | 338 |
|
339 | 339 | const QString icon_str = QString::fromUtf8(tray->icon); |
340 | | - const QIcon icon = QFileInfo(icon_str).exists() ? QIcon(icon_str) : QIcon::fromTheme(icon_str); |
| 340 | + QIcon icon; |
| 341 | + const QFileInfo icon_fi(icon_str); |
| 342 | + if (icon_fi.exists()) { |
| 343 | + // Explicitly load via QPixmap so that the icon engine has pixmap data and |
| 344 | + // availableSizes() is populated immediately. QIcon(filename) lazy-loads the |
| 345 | + // pixmap, which leaves availableSizes() empty; Qt6's SNI tray backend then |
| 346 | + // sees no sizes and sends no icon data, causing the tray icon to be blank. |
| 347 | + const QPixmap pixmap(icon_fi.absoluteFilePath()); |
| 348 | + if (!pixmap.isNull()) { |
| 349 | + icon.addPixmap(pixmap); |
| 350 | + } |
| 351 | + } else { |
| 352 | + icon = QIcon::fromTheme(icon_str); |
| 353 | + } |
341 | 354 | // Only update the icon when the resolved icon is valid. Setting a null icon |
342 | 355 | // clears the tray icon and triggers "No Icon set" warnings (Qt6 is stricter |
343 | 356 | // about QIcon::fromTheme when the name is not found in the active theme). |
|
0 commit comments