diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md index 9f2b9208d..1152f0b8d 100644 --- a/docs/subsystems/gui-shell.md +++ b/docs/subsystems/gui-shell.md @@ -121,6 +121,7 @@ axis controls. - The Usage page's cards and the tray panel's Allowances tab share one order, `settings.UsageOrder` (`byUsageOrder`). The panel's *Arrange* (`panelArrange`) moves rows in it and hides subscriptions from that tab alone (`settings.PanelUsageHidden`); both save through `POST /api/usage/arrange`, which changes only the field it is sent, and the Settings save keeps both. Hiding is display only: a menu bar cell's card shows though hidden (`panelPeek`). See `TestUsageArrangePanelHidden` and `panel-arrange.test.cjs`. - The page must work in Chromium (Windows' WebView2) and WebKit (macOS, and WebKitGTK on Linux). GUI tests run in both engines. - On Linux the panel is frameless and the main window has a hidden title bar (`plainTitlebar`). GTK 3 asks KDE's Wayland session (KWin's decoration protocol) for a frame drawn by KWin on any window without client-side decorations, an undecorated one too, so `ownFrame` tells KWin the panel draws its own on each realize (#1283). GTK 4 builds ask for none themselves. +- Wails calls the tray's click handler both for the icon's click (`Activate`) and when the tray host opens the icon's menu (dbusmenu's "opened" event). KDE opens the menu on a right-click, and the panel that click opened took the focus and shut the menu on Wayland. On Linux the handler ignores the call when it comes from the menu opening (`menuOpening` in [`trayclick.go`](../../internal/gui/trayclick.go), which looks for Wails' `(*linuxSystemTray).Event` among its callers; `TestTrayMenuOpenFrameIsWails` fails if Wails renames it or stops calling the handler there) (#1430). - On GTK 3 builds, the app gives GDK a font DPI before the first webview when it has none (`fontDPI`, [`fontdpi_gtk3.h`](../../internal/gui/fontdpi_gtk3.h)). GDK's unset value is -1, and WebKitGTK 2.54's GTK 3 settings reader multiplies it by 1024 unchecked, so every page lays out at a negative width with a 9000000px font (#1371). An unset DPI takes `gtk-xft-dpi`, or 96, times a valid `GDK_DPI_SCALE`; a positive one is left alone. Wails initialises GTK (its GtkApplication) only inside `Run` and makes each window from a default-idle-priority callback on the main loop, so `fontDPI`, called just before `Run`, queues the check as a `G_PRIORITY_HIGH` idle: it runs on the main thread after GTK's own start, before the first window. `TestFontDPIUnset` opens a real WebKitGTK page through `magpie_font_dpi` and needs a display (Xvfb). - Tests never touch a live agent config. The package's `TestMain` runs under `testenv`'s home of its own. A macOS test that shows windows runs them in a process of its own through `runAppKit` ([`appkit_darwin_test.go`](../../internal/gui/appkit_darwin_test.go)). AppKit and WebKit take their home from the account, not from HOME, so `runAppKit` gives them a temporary one with `CFFIXED_USER_HOME`; appearance, contrast and languages still come from the account. The test fails when that process leaves a folder in the real `~/Library/WebKit` or `~/Library/Caches`. Playwright tests serve `assets/` with isolated `/api` fixtures. - `POST /api/settings/codex-auto-review` accepts an empty value (Codex's own choice) or an exact model/group ID in `provider.Served`, including unlisted providers. A known provider with an unknown or empty model name is rejected without changing the saved reviewer or catalog tag. Generic gateway request resolution remains permissive; it is not the validator for this setting. See `Handler` in [`api.go`](../../internal/gui/api.go) and `TestCodexAutoReviewSetting` in [`codex_auto_review_test.go`](../../internal/gui/codex_auto_review_test.go). diff --git a/internal/gui/app.go b/internal/gui/app.go index 68c3c6408..8bc3a8e9a 100644 --- a/internal/gui/app.go +++ b/internal/gui/app.go @@ -463,6 +463,9 @@ func Run(version string, showMain bool, link string) error { if cmdClick() { return // Command-drag moves the icon; the system handles it } + if runtime.GOOS == "linux" && menuOpening() { + return // a right-click opening the menu, not a click (#1430) + } if runtime.GOOS == "darwin" { go h.flap() } diff --git a/internal/gui/trayclick.go b/internal/gui/trayclick.go new file mode 100644 index 000000000..c76adfb7b --- /dev/null +++ b/internal/gui/trayclick.go @@ -0,0 +1,41 @@ +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 +} diff --git a/internal/gui/trayclick_test.go b/internal/gui/trayclick_test.go new file mode 100644 index 000000000..db325c0f7 --- /dev/null +++ b/internal/gui/trayclick_test.go @@ -0,0 +1,61 @@ +package gui + +import ( + "os" + "os/exec" + "path/filepath" + "regexp" + "strings" + "testing" +) + +// A right-click on KDE opens the tray's menu, and Wails calls the click +// handler from the menu's "opened" event; that call must not open the +// panel, while the icon's own click (Activate) still does (#1430). +func TestTrayMenuOpeningIsNoClick(t *testing.T) { + const app = "github.com/wailsapp/wails/v3/pkg/application." + opened := []string{ + "magpie/internal/gui.Run.func12", + app + "(*linuxSystemTray).Event", + "reflect.Value.call", + "github.com/godbus/dbus/v5.(*Conn).handleCall", + } + if !openedBy(opened) { + t.Fatal("a click from the menu's opened event was counted a click") + } + activate := []string{ + "magpie/internal/gui.Run.func12", + app + "(*linuxSystemTray).Activate", + "reflect.Value.call", + } + if openedBy(activate) { + t.Fatal("the icon's click (Activate) was taken for the menu opening") + } + if openedBy([]string{app + "(*linuxSystemTray).EventGroup"}) { + t.Fatal("EventGroup is not Event") + } + if menuOpening() { + t.Fatal("a plain call was taken for the menu opening") + } +} + +// The frame menuOpening looks for is the Wails function that calls the +// click handler on the menu's "opened" event; an upgrade that renames it +// or stops calling the handler there fails here. +func TestTrayMenuOpenFrameIsWails(t *testing.T) { + out, err := exec.Command("go", "list", "-m", "-f", "{{.Dir}}", "github.com/wailsapp/wails/v3").Output() + if err != nil { + t.Skip("go list:", err) + } + src, err := os.ReadFile(filepath.Join(strings.TrimSpace(string(out)), "pkg", "application", "systemtray_linux.go")) + if err != nil { + t.Fatal(err) + } + fn := regexp.MustCompile(`(?s)func \(s \*linuxSystemTray\) Event\(.*?\n}\n`).Find(src) + if fn == nil { + t.Fatalf("Wails has no (*linuxSystemTray).Event; menuOpenFrame %q is stale", menuOpenFrame) + } + if !regexp.MustCompile(`(?s)case "opened":\s*if s\.parent\.clickHandler != nil \{\s*s\.parent\.clickHandler\(\)`).Match(fn) { + t.Fatalf("Wails' Event no longer calls the click handler on \"opened\"; see menuOpening:\n%s", fn) + } +}