gui: on the Mac the quick panel opens over a full-screen app, on the Space the user is on, not on the desktop it was first shown on (#2141)

With Chrome full screen and Settings > Click the tray icon set to the
quick panel, a click on the menu bar icon flashed the icon and showed the
panel on the non-full-screen desktop instead, out of sight until the user
swiped back (witt-bit, macOS 27.0.1, v0.1.1230). The panel's window had no
collection behaviour of its own, so Wails gave it FullScreenPrimary alone:
an ordinary window, kept on the Space it was first ordered in on, and not
allowed on a full-screen app's Space. It now has CanJoinAllSpaces |
FullScreenAuxiliary, as a menu bar extra's panel (and Wails' own notch
window) does, so it is on every Space, full-screen ones too. It never
moves to the active Space as well (AppKit refuses that pair), and nothing
calls setMovesToActiveSpace on it (showHere is the main window's only).
The panel lightweight mode makes again takes the same options.

Tests:
- TestPanelOnEverySpaceOnMac (panel_options_test.go) checks the options.
- TestPanelJoinsFullScreenSpaces (AppKit, runAppKit) makes the real panel
  through panelWin, at start and again after lightweight mode let it go,
  shows and hides it, and reads NSWindow.collectionBehavior
  (joinsFullScreenSpaces).
- Without the change both fail: "panel collection behaviour 0 is not on
  every Space and over full-screen ones" and "made at start: the panel
  isn't on every Space and over full-screen ones".

Run: gofmt -l (clean); go vet ./internal/gui/ (darwin),
GOOS=linux go vet -tags nogui, GOOS=windows go vet; go build,
GOOS=linux go build -tags nogui, GOOS=windows go build; go test
./internal/gui/ under a sandbox HOME with pinned caches. In the package
run, at load average ~300-420 from other sessions, two tests unrelated to
the panel failed: TestMainWindowCorners (40s deadline killed; fails the
same on clean origin/main c4c3cafa2, filed as #1936) and
TestSetAnswersWhileDevinAndProvidersHang (filed as #1375; passed on clean
c4c3cafa2 right after). Panel, dock and Space tests pass.

Not tried: a real full-screen Space. A test can't make one, and doing it
by hand would take over the owner's screen; the reporter is asked to
confirm on the next release.
This commit is contained in:
yetone
2026-10-14 16:12:44 +08:00
parent 644ad1ed7a
commit b2d558db97
4 changed files with 116 additions and 0 deletions
+7
View File
@@ -665,6 +665,13 @@ func panelOptions(goos, theme string) application.WebviewWindowOptions {
Mac: application.MacWindow{
Backdrop: application.MacBackdropTranslucent,
CornerRadius: 12,
// On every Space, a full-screen app's among them, as a menu
// bar extra's panel is: by default (FullScreenPrimary alone)
// it stayed on the desktop Space it was first shown on, and a
// click on the icon over a full-screen Chrome showed it there,
// out of sight, until the user swiped back (#2141).
CollectionBehavior: application.MacWindowCollectionBehaviorCanJoinAllSpaces |
application.MacWindowCollectionBehaviorFullScreenAuxiliary,
},
Windows: application.WindowsWindow{HiddenOnTaskbar: true},
}
+15
View File
@@ -47,3 +47,18 @@ func TestPanelSolidOnLinux(t *testing.T) {
}
}
}
// #2141: over a full-screen app the menu bar icon showed the quick panel on
// the desktop Space it was first shown on. On the Mac the panel is on every
// Space, full-screen ones among them, as a menu bar extra's panel is, and
// doesn't also move to the active Space (AppKit refuses the two together).
func TestPanelOnEverySpaceOnMac(t *testing.T) {
b := panelOptions("darwin", "").Mac.CollectionBehavior
want := application.MacWindowCollectionBehaviorCanJoinAllSpaces | application.MacWindowCollectionBehaviorFullScreenAuxiliary
if b&want != want {
t.Errorf("panel collection behaviour %d is not on every Space and over full-screen ones", b)
}
if b&(application.MacWindowCollectionBehaviorMoveToActiveSpace|application.MacWindowCollectionBehaviorFullScreenPrimary) != 0 {
t.Errorf("panel collection behaviour %d moves to the active Space or goes full screen itself", b)
}
}
+81
View File
@@ -0,0 +1,81 @@
//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.
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}
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)
}
application.InvokeSync(func() { w.Show().Focus() }) // the icon clicked
waitFor(how+": the panel shows", func() bool { return application.InvokeSyncWithResult(func() bool { return windowOpen(w) }) })
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)
}
+13
View File
@@ -17,6 +17,12 @@ static int movesToActiveSpace(void *win) {
return (((NSWindow *)win).collectionBehavior & NSWindowCollectionBehaviorMoveToActiveSpace) != 0;
}
// On every Space and over a full-screen app's.
static int joinsFullScreenSpaces(void *win) {
NSWindowCollectionBehavior b = ((NSWindow *)win).collectionBehavior;
return (b & NSWindowCollectionBehaviorCanJoinAllSpaces) != 0 && (b & NSWindowCollectionBehaviorFullScreenAuxiliary) != 0;
}
// Ordered in and not in the Dock: on a Space of its own, or covered, it is
// still open, where Wails' IsVisible (its occlusion state) says it isn't.
static int windowOpen(void *win) {
@@ -72,6 +78,13 @@ func movesToActiveSpace(w *application.WebviewWindow) bool {
return p != nil && C.movesToActiveSpace(p) != 0
}
// joinsFullScreenSpaces says whether w is on every Space, a full-screen
// app's too, as the quick panel is (#2141); on the main thread.
func joinsFullScreenSpaces(w *application.WebviewWindow) bool {
p := w.NativeWindow()
return p != nil && C.joinsFullScreenSpaces(p) != 0
}
// windowOpen says whether w is open: shown, on any Space, and not
// minimised; on the main thread.
func windowOpen(w *application.WebviewWindow) bool {