Bug 383202 - System tray icon's context menu isn't updated properly in plasma/x11
Summary: System tray icon's context menu isn't updated properly in plasma/x11
Status: VERIFIED FIXED
Alias: None
Product: plasmashell
Classification: Plasma
Component: System Tray (show other bugs)
Version: 5.9.5
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: 1.0
Assignee: kdelibs bugs
URL: https://phabricator.kde.org/D7260
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-06 14:11 UTC by i.Dark_Templar
Modified: 2021-09-16 19:28 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.22.0


Attachments
menubugtest.tar.bz2 (2.62 KB, application/x-bzip)
2017-08-06 14:11 UTC, i.Dark_Templar
Details
refresh-menu.patch (3.06 KB, patch)
2017-08-11 19:50 UTC, i.Dark_Templar
Details

Note You need to log in before you can comment on or make changes to this bug.
Description i.Dark_Templar 2017-08-06 14:11:44 UTC
Created attachment 107107 [details]
menubugtest.tar.bz2

When context menu of QSystemTrayIcon is changed in plasma/x11, it behaves weird.

If the structure of menu is same, the text of some nested menu items doesn't correctly update, and if structure of menu changes, menu just shuffles somehow all items, maybe even lose some items.

I'm attaching sources of test application.

If you change menu from "menu 1" to "menu 2" you can see the case when nested menu items aren't updated, i.e. their text is not updated, but assigned actions are changed correctly.

If you change menu from "menu 1" or "menu 2" to "menu 3" you can see the case when menu items are placed incorrectly or even missing.

If you hide and show again system tray icon, regenerated menu shows correctly (until you change menu selection).

I'm using:
Qt 5.7.1
sni-qt 0.2.6-r1
libdbusmenu-qt 0.9.3_pre20160218.

Also, the bug doesn't show up when one of following conditions is true:
1) plasma/x11 isn't used (I used LXQt desktop with openbox to test this).
2) environment variable KSNI_NO_DBUSMENU is set.

Testing this application further, I've noticed that if you compile it against Qt4 and if checkbox "Show system tray icon" is unchecked, tray icon doesn't disappear, and when it's checked again, one more tray icon appears (with separate menu). Setting 'KSNI_NO_DBUSMENU' doesn't help to fix this issue, but it's not reproducible in LXQt.
Comment 1 i.Dark_Templar 2017-08-11 19:49:16 UTC
Changed product and version, it looks like bug is in plasma-workspace.
Comment 2 i.Dark_Templar 2017-08-11 19:50:17 UTC
Created attachment 107217 [details]
refresh-menu.patch

Proposed patch, fixes issue for me.
Comment 3 David Edmundson 2017-08-18 00:58:26 UTC
Could you upload it to our code review place please.

http://phabricator.kde.org
Comment 4 i.Dark_Templar 2017-08-18 05:27:19 UTC
Good day.

I already did (and updated it a bit for modern plasma-workspace code). Please see URL. I'll duplicate it here:
https://phabricator.kde.org/D7260
Comment 5 Konrad Materka 2019-10-17 09:00:06 UTC
The situation happens only when:
* Qt QPA (plasma-integration) is not used
* Tray icon menu is changed to new menu
* New menu is created before change

This is partially (or mostly) a Qt bug. Qt does not send any event when menu is replaced by another menu. In Qt 5.11 (and newer) on menu change Qt sends:
> signal time=1571299503.727968 sender=:1.628 -> destination=(null destination) serial=22 path=/StatusNotifierItem; interface=org.kde.StatusNotifierItem; member=NewMenu
"NewMenu" is not supported by the standard, they admit that:
https://github.com/qt/qtbase/commit/ff169e8859457188f94aed86368876ba5bab2e90
In older Qt (for example 5.9 LTS) nothing is being send!

Possible workarounds (for developers):
* do not replace whole menu, update it (even clear if needed m_tray->contextMenu()->clear()) - good option
* set mew menu, but change anything later (for example, add new action) - good option
* recreate whole System Tray icon - not so great advice
* use plasma-integration - bad advice, developers have no influence on that

Possible workaround on KDE Plasma side:
* for Qt >= 5.11: implement "NewMenu" signal - but it is not part of the standard...
* Qt < 5.11: disable cache entirely - not good, breaks global menu and impacts performance

Possible solution on Qt side:
* send "LayoutUpdated" in addition to "NewMenu" - I will create an issue in Qt Bug tracker
Comment 6 Konrad Materka 2019-10-17 09:25:14 UTC
Qt BUG: https://bugreports.qt.io/browse/QTBUG-79287
Comment 7 i.Dark_Templar 2019-10-17 16:39:55 UTC
I don't think it's a bug in Qt because, as I wrote in original comment, it didn't reproduce with LXQt desktop for me, and LXQt is based on Qt mostly, and my patch for KDE, while it might have downsides or things to improve, fixes this bug.

I'm using KDE with linked patch since reporting this bug and it works fine for me all the time.
Comment 8 Konrad Materka 2019-10-17 19:42:17 UTC
I had to check :) It is not working on "pure" LXDE. LXDE has a QPA plugin, similar one as KDE has. Run your test application with:

XDG_SESSION_DESKTOP=X QT_QPA_PLATFORMTHEME=X ./menubugtest

You will see exactly the same results. You can also remove/move the file:
/usr/lib/x86_64-linux-gnu/qt5/plugins/platformthemes/libqtlxqt.so

On KDE install package "plasma-integration" (at least on *Ubuntu) at will work correctly, the same as in LXDE. It should be installed by default.
Comment 9 Nate Graham 2020-11-09 17:56:30 UTC
Is this still happening for you in Plasma 5.20--or even better, with current git master? A lot of fixes related to this have landed recently.
Comment 10 i.Dark_Templar 2020-11-09 19:09:28 UTC
(In reply to Nate Graham from comment #9)
> Is this still happening for you in Plasma 5.20--or even better, with current
> git master? A lot of fixes related to this have landed recently.

I'll check it when Plasma 5.20.X gets marked stable in Gentoo amd64. Currently 5.19.5 is stable there.

There's also attached test which should reproduce issue.
Comment 11 Konrad Materka 2020-11-09 22:02:06 UTC
I think it is still there - Qt bug is not fixed:
https://bugreports.qt.io/browse/QTBUG-79287

On KDE/Plasma side we can implement non-standard "NewMenu" signal. In addition, we should update freedesktop documentation as well:
https://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/StatusNotifierItem/
Comment 12 Konrad Materka 2020-11-09 22:03:01 UTC
So that I'm changing this to Confirmed. It is not entirely fault of Plasma, but Qt is the foundation of KDE so we can't just close this as upstream bug :)
Comment 13 i.Dark_Templar 2021-01-22 18:31:07 UTC
Updated to plasma-workspace 5.20.5. Bug is still present. Attached application still reproduces issue. Linked patch still fixes issue, although it had to be rebased again.
Comment 14 Bug Janitor Service 2021-01-23 21:27:29 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/594
Comment 15 Konrad Materka 2021-01-25 19:06:24 UTC
Git commit 628c44c1eaec0bd877c6a247a7e2c0d0c5c294d1 by Konrad Materka.
Committed on 23/01/2021 at 22:07.
Pushed by kmaterka into branch 'master'.

Emit NewMenu when new context menu is set.

When new context menu is beeing set we should notify about it.
It is possible that the menu is cached on the client side and the menu items ids are the same.

This signal not part of the official standard but already used by Qt
(starting from Qt 5.11).

M  +1    -0    src/kstatusnotifieritem.cpp
M  +5    -0    src/kstatusnotifieritemdbus_p.h
M  +3    -0    src/org.kde.StatusNotifierItem.xml

https://invent.kde.org/frameworks/knotifications/commit/628c44c1eaec0bd877c6a247a7e2c0d0c5c294d1
Comment 16 Konrad Materka 2021-03-07 11:40:50 UTC
Git commit 7c9021ebbc6277e40e2013bda48962754d6e03a4 by Konrad Materka.
Committed on 07/03/2021 at 11:40.
Pushed by kmaterka into branch 'master'.

[SNI] Handle NewMenu signal

Qt uses NewMenu signal to notify when new context menu is set.
It is not part of the official standard but already used by Qt
(starting from Qt 5.11).
FIXED-IN: 5.22.0

M  +10   -0    dataengines/statusnotifieritem/statusnotifieritemsource.cpp
M  +1    -0    dataengines/statusnotifieritem/statusnotifieritemsource.h

https://invent.kde.org/plasma/plasma-workspace/commit/7c9021ebbc6277e40e2013bda48962754d6e03a4
Comment 17 i.Dark_Templar 2021-09-16 19:28:37 UTC
Looks like it's finally fixed. Tested with plasma-workspace 5.22.5 on Gentoo.