Skip to content

fix(tray): register the tray icon again when the panel forgets it - #125

Merged
shakaran merged 2 commits into
shakaran:mainfrom
gbmaizol:fix/tray-reregister
Oct 21, 2026
Merged

shakaran merged 2 commits into
shakaran:mainfrom
gbmaizol:fix/tray-reregister

Conversation

@gbmaizol

Copy link
Copy Markdown
Contributor

On Linux Mint (Cinnamon) the tray icon can disappear from the panel while Whatly keeps running. When the window is hidden, that also takes away the only way back to it, or to Quit.

Cause. The icon is still served. Qt's StatusNotifierItem was alive on its own bus connection, answering with the right tooltip and unread count, but it was missing from the watcher's RegisteredStatusNotifierItems. Cinnamon's xapp-sn-watcher removes items in handle_sn_item_name_owner_lost with g_str_has_prefix (key, name), so when a client named :1.51 exits, the item registered as :1.519/StatusNotifierItem is removed with it. That is fixed upstream in linuxmint/xapp#211 (2026-09-04), but the xapp 3.2.3 Mint ships today still calls g_str_has_prefix there, so it will be around for a while. Calling RegisterStatusNotifierItem for the live item by hand brought the icon straight back.

Qt registers its item once, and again only when the watcher service itself restarts (QDBusTrayIcon::watcherServiceRegistered), so nothing in Qt notices.

What this does. On Linux, every 30 seconds Whatly reads the watcher's RegisteredStatusNotifierItems asynchronously, and if its own item is not listed it calls RegisterStatusNotifierItem again. Qt serves the item on a private connection named org.kde.StatusNotifierItem-<pid>-<n>, where n also counts the throwaway tray objects isSystemTrayAvailable() creates. So the check does not guess n: it takes the connection that has an object at /StatusNotifierItem. If the icon is hidden, Qt has no such connection, or there is no watcher, it does nothing.

Tested against a stand-in watcher on a private session bus, which drops every item 15 seconds after the first registration. Whatly registered at 1.9s, the watcher dropped it at 16.9s, and Whatly registered it again at 31.4s. Also running on the Flatpak build on Cinnamon, where the icon is present with the unread count.

@coderabbitai ignore

Cinnamon's xapp-sn-watcher before linuxmint/xapp#211 removes every
status notifier item whose key starts with the bus name of a client
that exits, so when ":1.51" quits, ":1.519/StatusNotifierItem" goes too.
Qt registers its item once and again only when the watcher restarts, so
the icon stayed off the panel while Whatly ran.

Every 30 seconds, find the private connection Qt serves the item on and,
if the watcher's RegisteredStatusNotifierItems lacks it, call
RegisterStatusNotifierItem again. Linux only; does nothing when the icon
is hidden or there is no watcher.

@shakaran shakaran left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Checked against Qt's qdbusmenuconnection.cpp: it registers the item with the connection's baseService(), so comparing against that is right. I pushed b8abbe4 to move your function above the menu-state comment, which had ended up documenting it instead of checkWindowState().

@shakaran
shakaran merged commit f094d02 into shakaran:main Oct 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants