Files
magpie/internal/gui/trayclick.go
T
yetone 884dbdb201 gui: on KDE a right-click on the tray icon opens its menu and leaves the quick panel shut (#1430, olivezane)
Wails (v3 beta.24, systemtray_linux.go) calls the tray's click handler
both for the icon's click (Activate) and from the dbusmenu "opened" event,
when the tray host opens the icon's menu. KDE Plasma opens the menu on a
right-click, so the right-click also opened the quick panel, which took
the focus, and on Wayland the menu shut at once (it stayed under
GDK_BACKEND=x11, as the reporter saw). On Linux the click handler now
ignores a call whose callers include Wails' (*linuxSystemTray).Event
(menuOpening, trayclick.go); a left-click (Activate) opens the panel as
before. Wails has no public hook for the menu opening.

Run: TestTrayMenuOpeningIsNoClick fails with openedBy broken ("a click
from the menu's opened event was counted a click") and passes;
TestTrayMenuOpenFrameIsWails reads the Wails module's source and fails if
Event stops calling the click handler on "opened" or is renamed.
go test -tags nogui ./internal/gui/ under a temp HOME passes; gofmt -l
clean; go vet (darwin, with the GUI) and GOOS=linux/windows go vet -tags
nogui ./internal/gui/ pass; GOOS=linux go build -tags nogui passes.
Not tried on a real KDE Plasma 6 Wayland session: no KDE machine here.
2026-10-10 17:54:19 +08:00

42 lines
1.1 KiB
Go

package gui
import (
"runtime"
"strings"
)
// menuOpenFrame is the Wails function that tells the tray's click handler
// when Linux's tray host opens the icon's menu (com.canonical.dbusmenu's
// "opened" event). KDE Plasma opens the menu on a right-click, so a click
// counted there opened the quick panel too, which took the focus and shut
// the menu on Wayland at once (#1430).
const menuOpenFrame = "pkg/application.(*linuxSystemTray).Event"
// menuOpening says the click handler was called because the tray's menu is
// opening, not because the icon was clicked: Wails calls the same handler
// for both, and only the call stack tells them apart.
func menuOpening() bool {
pcs := make([]uintptr, 32)
n := runtime.Callers(2, pcs)
frames := runtime.CallersFrames(pcs[:n])
var names []string
for {
f, more := frames.Next()
names = append(names, f.Function)
if !more {
break
}
}
return openedBy(names)
}
// openedBy says one of the callers is the menu's "opened" event.
func openedBy(callers []string) bool {
for _, c := range callers {
if strings.HasSuffix(c, menuOpenFrame) {
return true
}
}
return false
}