During development with Qt I noticed a bug in the Plasma's system tray when using QSystemTrayIcon: If the system tray has a context menu set and is shown after one hide (show->hide->show) the tray doesn't react anymore: * no context menu shown on right click * left click doesn't emit signal Reproducible: Always Steps to Reproduce: 1.Try this code inside a QMainWindow: QSystemTrayIcon *sysTray = new QSystemTrayIcon(this); sysTray->setIcon(style()->standardIcon(QStyle::SP_DesktopIcon)); QMenu *trayMenu = new QMenu(this); sysTray->setContextMenu(trayMenu); connect(sysTray, &QSystemTrayIcon::activated, [=](QSystemTrayIcon::ActivationReason){ qDebug() << "clicked"; }); sysTray->show(); sysTray->hide(); sysTray->show(); 2. compile 3. run:) Actual Results: left click on tray does not do anything ("clicked" not printed) Expected Results: print "clicked" to std output This does not happen in LXQt, so I assume it is related to KF5.
Could you just upload a small demo app as you've clearly written one.
Created attachment 99860 [details] Demo code
Created attachment 99861 [details] Cmake file
You can also use the Qt example: https://doc.qt.io/qt-5/qtwidgets-desktop-systray-example.html Same bug there
confirmed. unset XDG_CURRENT_DESKTOP unset KDE_FULL_SESSION so that it doesn't use our QPT fixes it - so the bug is probably in our plasma-integration lib
it's getting inside the first if() in here: void KStatusNotifierItemDBus::Activate(int x, int y) { if (m_statusNotifierItem->d->associatedWidget == m_statusNotifierItem->d->menu) { ContextMenu(x, y); } else { m_statusNotifierItem->activate(QPoint(x, y)); } } The reason being d->assoociatedWidget is null and d->menu is null hence it matches, but it's not really what that code is trying to do. Doing the obvious fix on that fixes the bug. (plus again in KStatusNotifierItem::activate where the code is repeated for no reason) However, d->menu shouldn't be null - you're clearly setting one. Will investigate that - or maybe just get rid of the plasma SNI integration given that's in Qt now..
Update: We have one menu for the whole tray instance We create and delete KSNI object in init() and cleanup() which are called on show() hide() The SNI takes ownership of the menu so for the the second init, we set the SNI to a now deleted menu. It doesn't crash because it's wrapped in a QWeakpointer + guards as this came up before and someone did a bodge job of fixing it in ee62e7d9d2fe185f00562a74602aa4c19e8a88c7 fixing the symptoms without identifying the root cause.
Ehm, any news here?
Git commit 4b3d3b3ab21cff913a0529fddabe94744f607b95 by Alexander Bikadorov. Committed on 28/10/2016 at 17:14. Pushed by abikadorov into branch 'master'. FIXED: [ 365105 ] Workaround for bug in KF5+QSystemTrayIcon M +15 -0 krusader/krusader.cpp http://commits.kde.org/krusader/4b3d3b3ab21cff913a0529fddabe94744f607b95
sorry, closed the wrong bug.
Confirmed that have the same situation with tray on Archlinux Plasma 5.11.4 Whats the status of bug? Has anybody news? Last comment was 2 month ago.
*** Bug 411851 has been marked as a duplicate of this bug. ***
Git commit aa6bb9b06cfba67c1ba226d053a49e0bc1b69cad by Konrad Materka. Committed on 17/10/2019 at 15:34. Pushed by kmaterka into branch 'master'. [KStatusNotifierItem] Allow left click when menu is null Summary: If associatedWidget and menu are the same then instead of "activate" action context menu is used. When both are null coparition is always true but context menu can't be shown, since it is null. It is partial solution for a problem described in https://bugs.kde.org/show_bug.cgi?id=365105. Test Plan: As described in the bug: * create QSystemTrayIcon * assign QMenu * show, hide and show again Both right click and left click do nothing. After change left click works Reviewers: davidedmundson, broulik, nicolasfella, #frameworks Reviewed By: davidedmundson Subscribers: kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D24667 M +2 -2 src/kstatusnotifieritem.cpp M +1 -5 src/kstatusnotifieritemdbus_p.cpp https://commits.kde.org/knotifications/aa6bb9b06cfba67c1ba226d053a49e0bc1b69cad
Git commit bc1c85144adb9a40ed8a6a38ac84234c738dbc7f by Konrad Materka. Committed on 05/11/2019 at 11:42. Pushed by kmaterka into branch 'master'. [KDEPlatformSystemTrayIcon] Recreate deleted menu Summary: Recreate internal menu when needed. It is possible that internal representation of system tray menu is deleted. This can happen when QSystemTrayIcon is hidden. Test Plan: Unit tests included Reviewers: apol, davidedmundson, #plasma, #frameworks, broulik, nicolasfella Reviewed By: apol Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D24843 M +10 -2 autotests/CMakeLists.txt A +106 -0 autotests/kdeplatformsystemtrayicon_unittest.cpp [License: LGPL (v2/3+eV)] M +40 -21 src/platformtheme/kdeplatformsystemtrayicon.cpp M +8 -1 src/platformtheme/kdeplatformsystemtrayicon.h https://commits.kde.org/plasma-integration/bc1c85144adb9a40ed8a6a38ac84234c738dbc7f