zyh6036 on X: the menu bar panel stays so far in front that even
WeChat's screenshot can't cover it, so it's hard to take a picture of.
The panel asked for AlwaysOnTop (NSFloatingWindowLevel, 3), but Wails'
SystemTray.PositionWindow sets the window it places to
NSPopUpMenuWindowLevel (101) every time (systemtray_darwin.m), and magpie
places the panel with it on each open and each resize. The live app's
panel read layer 101 in CGWindowList. Nothing in magpie's history chose
101 (git log -S finds only AlwaysOnTop, from the first commit).
placeByIcon now does PositionWindow and then sets NSStatusWindowLevel
(25), the level of the status bar itself: still over normal windows,
floating ones, the Dock (20) and the menu bar (24), and still on every
Space and over full-screen apps (the collection behavior is unchanged,
#2141), but under pop-up menus and anything a screenshot tool puts up at
25 or above. Both PositionWindow calls (togglePanelNow, sizeOpenPanel)
go through it. Other systems: setPanelLevel is a no-op.
What was run (mica, macOS 27, at 48fffb60c + this change; the panel tests again at the rebased head):
- TestPanelJoinsFullScreenSpaces now has a real SystemTray, places the
panel through placeByIcon and checks the level is
NSStatusWindowLevel. Broken by hand (setPanelLevel call removed): red,
"the panel is at level 101". Restored: green.
- A real build in a sandbox HOME (MAGPIE_ADDR 127.0.0.1:3536),
`magpie panel`, with a tiny AppKit helper: CGWindowList front to back
read the panel (439x521) at layer 25 over a normal titled window
(layer 0); a full-screen borderless overlay at NSScreenSaverWindowLevel
(1000) shown after it was in front of the panel, and so was one at
NSStatusWindowLevel (25) shown after it, as a screenshot overlay is.
Before the change the panel was at 101, over the one at 25.
- go test -count=1 -timeout 45m ./internal/gui: ok (714s). An earlier
run of it had two source guards (panelside_test.go) reading the old
PositionWindow call, updated here, and TestGatewayModeListsNoOwnSessions
red under load ("listing":true, the search asked before the list was
read), green alone: filed as #7064.
- go vet ./internal/gui on darwin, GOOS=windows, and Linux in WSL
(magpie-desktop, -tags gtk3): ok. gofmt -l: clean.
Not tried: the panel over a real full-screen app. mica's and mote's
screens are locked, and a window there doesn't enter full screen; the
full-screen guarantee is the unchanged collection behavior, which the
same test still checks. WeChat itself: not installed on any test Mac,
so its overlay's level isn't known; if it is below 25 this doesn't
reach it, and the reply asks the reporter to say.
114 lines
4.8 KiB
Go
114 lines
4.8 KiB
Go
//go:build darwin && cgo && !nogui
|
|
|
|
package gui
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/wailsapp/wails/v3/pkg/application"
|
|
"github.com/wailsapp/wails/v3/pkg/events"
|
|
)
|
|
|
|
// #2141: with Chrome full screen, a click on the menu bar icon showed the
|
|
// quick panel on the desktop Space it was first shown on, out of sight. A
|
|
// test can't make a full-screen Space, so it checks what decides it on the
|
|
// real window: the panel, made at start and made again after lightweight
|
|
// mode let it go, is on every Space and over a full-screen app's, and is
|
|
// shown and hidden with that set, without activating magpie (activated,
|
|
// the Mac took the user to the Space of magpie's other windows). Placed by
|
|
// the tray icon, it is at a menu bar extra's level, not the pop-up menu
|
|
// level Wails' PositionWindow gives it, where WeChat's screenshot couldn't
|
|
// draw over it (zyh6036 on X).
|
|
func TestPanelJoinsFullScreenSpaces(t *testing.T) {
|
|
out, err := runAppKit(t, 30*time.Second, []string{"MAGPIE_TEST_PANEL_SPACE=1"})
|
|
if err != nil || !strings.Contains(string(out), "panel space: ok") {
|
|
t.Fatalf("panel space: %v\n%s", err, out)
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
if os.Getenv("MAGPIE_TEST_PANEL_SPACE") != "1" {
|
|
return
|
|
}
|
|
app := application.New(application.Options{
|
|
Name: "magpie panel space regression",
|
|
Mac: application.MacOptions{ActivationPolicy: application.ActivationPolicyAccessory},
|
|
Assets: application.AssetOptions{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "text/html")
|
|
fmt.Fprint(w, `<p>magpie</p>`)
|
|
})},
|
|
})
|
|
h := &host{app: app, tray: app.SystemTray.New()}
|
|
fail := func(format string, a ...any) {
|
|
fmt.Printf("panel space: "+format+"\n", a...)
|
|
os.Exit(1)
|
|
}
|
|
waitFor := func(what string, ok func() bool) {
|
|
for deadline := time.Now().Add(5 * time.Second); !ok(); time.Sleep(20 * time.Millisecond) {
|
|
if time.Now().After(deadline) {
|
|
fail("timed out waiting until %s", what)
|
|
}
|
|
}
|
|
}
|
|
check := func(how string) {
|
|
var w *application.WebviewWindow
|
|
application.InvokeSync(func() { w, _ = h.panelWin() })
|
|
if !application.InvokeSyncWithResult(func() bool { return joinsFullScreenSpaces(w) }) {
|
|
fail("%s: the panel isn't on every Space and over full-screen ones", how)
|
|
}
|
|
if !application.InvokeSyncWithResult(func() bool { return nonActivating(w) }) {
|
|
fail("%s: the panel isn't a non-activating panel", how)
|
|
}
|
|
if application.InvokeSyncWithResult(appFrontmost) {
|
|
fail("%s: magpie is frontmost before the icon is clicked; the test can't tell", how)
|
|
}
|
|
application.InvokeSync(func() { h.placeByIcon(w); w.Show().Focus() }) // the icon clicked
|
|
if !application.InvokeSyncWithResult(func() bool { return panelLevelOK(w) }) {
|
|
fail("%s: placed by the icon, the panel is at level %d, not a menu bar extra's (NSStatusWindowLevel), so a screenshot tool's overlay can't cover it", how, application.InvokeSyncWithResult(func() int { return panelLevel(w) }))
|
|
}
|
|
waitFor(how+": the panel shows", func() bool { return application.InvokeSyncWithResult(func() bool { return windowOpen(w) }) })
|
|
// activation is asked for and comes a moment later: give it time
|
|
time.Sleep(500 * time.Millisecond)
|
|
if application.InvokeSyncWithResult(appFrontmost) {
|
|
fail("%s: showing the panel brought magpie to the front, which takes the user to the Space of its other windows", how)
|
|
}
|
|
if !application.InvokeSyncWithResult(func() bool { return canBeKey(w) }) {
|
|
fail("%s: the panel can't be made key, so it never takes the keyboard", how)
|
|
}
|
|
// Whether it is key is up to the session too: on a Mac no one was
|
|
// at, macOS 26.2 made no non-activating panel of an app that isn't
|
|
// active key, a plain titled one either (#2450). A click on the
|
|
// icon is input, which this test can't make, so where a plain one
|
|
// isn't made key the check can't tell.
|
|
if !application.InvokeSyncWithResult(w.IsFocused) {
|
|
if application.InvokeSyncWithResult(sessionKeysPanels) {
|
|
fail("%s: the panel shown doesn't take the keyboard", how)
|
|
}
|
|
fmt.Printf("panel space: %s: not checked that it takes the keyboard: this session makes no non-activating panel key\n", how)
|
|
}
|
|
if !application.InvokeSyncWithResult(func() bool { return joinsFullScreenSpaces(w) }) {
|
|
fail("%s: showing the panel took it off full-screen Spaces", how)
|
|
}
|
|
application.InvokeSync(func() { w.Hide() })
|
|
waitFor(how+": the panel hides", func() bool { return !application.InvokeSyncWithResult(func() bool { return windowOpen(w) }) })
|
|
}
|
|
app.Event.OnApplicationEvent(events.Common.ApplicationStarted, func(*application.ApplicationEvent) {
|
|
go func() {
|
|
check("made at start")
|
|
application.InvokeSync(func() { h.panel = nil }) // lightweight mode let it go
|
|
check("made again")
|
|
fmt.Println("panel space: ok")
|
|
app.Quit()
|
|
}()
|
|
})
|
|
if err := app.Run(); err != nil {
|
|
panic(err)
|
|
}
|
|
os.Exit(0)
|
|
}
|