Repository navigation
[v3] refresh systray menus on Menu.Update - #6314
Conversation
|
Caution Review failedThe pull request is closed. No actionable comments were generated in the recent review. ℹ️ Recent review info
WalkthroughLinux menu updates now refresh system-tray menus backed by the updated menu. GTK3 destroy callbacks preserve signal mappings owned by newer native menu items. Tests cover tray item updates and activation-handler cleanup. ChangesLinux system-tray menu updates
Estimated code review effort: 2 (Simple) | ~12 minutes Change: Bug fix Suggested reviewers: Merge Risk:
|
773e65a to
17aacb2
Compare
On Linux a tray shows a dbusmenu layout that linuxSystemTray.setMenu builds from the Menu. linuxMenu.update() only rebuilt the native menu, so after tray.SetMenu(menu) a later menu.Clear(); menu.Add(...); menu.Update() left the tray on the first menu forever. Windows already rebuilds every tray popup built from the menu in update(); do the same on Linux by rebuilding the layout of every tray whose menu is the updated one, under the tray's itemMapLock as setMenu does. The tray rebuild binds item.impl to the tray, so the gtk3 destroy hook no longer saw itself as the owner and kept the activation handler entries of items removed from a tray menu. Release them unless a newer native item has taken the entry over.
17aacb2 to
cc28190
Compare
Description
On Linux,
Menu.Update()does not refresh a system tray menu built from thatMenu.The tray shows a StatusNotifierItem/dbusmenu layout that
linuxSystemTray.setMenubuilds from theMenu(it rebuildsitemMap, binds each item to asystrayMenuItem, and callsrefreshLockedto bump the dbusmenu revision and emitLayoutUpdated).linuxMenu.update()only rebuilt the native GMenu/GtkMenu, so an app that doestray.SetMenu(menu)once and latermenu.Clear(); menu.Add(...); menu.Update()keeps showing the first menu forever. Item setters (SetLabel,SetEnabled, ...) also stop reaching the tray afterUpdate, because the native rebuild rebindsitem.implto the GTK item.#6301 fixed the same gap on Windows by having
windowsMenu.update()defer torefreshSystemTrayMenus(menu), which rebuilds every tray popup built from that menu; Linux was left out. This does the same on Linux:refreshSystemTrayMenus(insystemtray_linux.go, shared by the default andgtk3builds) rebuilds the dbusmenu layout of every tray whose menu is the updated one, via the existingsetMenu, and bothlinuxMenu.update()variants defer to it. A menu attached to no tray, orUpdatebefore the app runs, behave as before.This is the
Updatehalf of #4604 (closed by #4615, which fixedSetMenu).The tray rebuild binds each
item.implto the tray. On thegtk3build, the destroy hook that releases a removed item'sgtkSignalToMenuItementry only did so when the native item still owneditem.impl, so items removed from a tray menu would have leaked on everyUpdate; the hook now releases the entry unless a newer native item has taken it over.Known limits:
Update()on a submenuMenudoes not refresh the tray; call it on the root menu.Menushown by both a tray and a native menu (menubar or context menu) was already unsupported:item.implis one slot, and whichever renderer rebuilt last owns it, so item setters reach only that one and a native checkbox/radio activation panics onitem.impl.(*linuxMenuItem)when the tray owns it. Before, that depended on whether the tray'sRunor the window'sUpdateran last; nowUpdatealways leaves the tray as the owner. For the same reason,Menu.Destroy()on a gtk3 menu the tray owns does not destroy the native widgets until the next rebuild. A tolerant native callback or a tray-side item mapping like the Windows popup would lift this; out of scope here.Type of change
How Has This Been Tested?
Ubuntu 24.04 (container; Go 1.26.9, libgtk-4-dev, libwebkitgtk-6.0-dev, libgtk-3-dev, libwebkit2gtk-4.1-dev).
New test
TestLinuxSystemTrayMenuUpdatebuilds a tray from a menu, then doesClear/Add/Updateand checks the tray'sitemMap, dbusmenu revision, and the item binding. Onmasterit fails:With this branch it passes, and
go test -race ./pkg/application/passes with and without-tags gtk3. The gtk3 integration testTestGTK3MenuRebuild(-tags "gtk3 wailsintegration", underxvfb-run) gained a tray-bound segment: it fails without the destroy-hook change (item removed from a tray menu retains an activation handler) and passes with it.go build ./pkg/application/passes for darwin and windows (cross-compiled) andGOOS=linux -tags server.Not run on a desktop against a live StatusNotifierItem host; the dbusmenu side (
refreshLocked) is the same code pathSetMenualready uses.Test Configuration
wails doctorwas not run in the container (no desktop). Environment: Ubuntu 24.04 x86_64 container, Go 1.26.9 linux/amd64, GTK 4.14.5 / WebKitGTK 6.0 (2.52.6), GTK 3.24.41 / WebKit2GTK 4.1 (2.52.6) from the Ubuntu repos.Checklist:
website/src/pages/changelog.mdxwith details of this PR (v3 changelog entries are added automatically)Summary by CodeRabbit