diff --git a/internal/gui/app.go b/internal/gui/app.go index 0cf1c17db..2e7102fd8 100644 --- a/internal/gui/app.go +++ b/internal/gui/app.go @@ -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}, } diff --git a/internal/gui/panel_options_test.go b/internal/gui/panel_options_test.go index 7ef1186da..50b9e3848 100644 --- a/internal/gui/panel_options_test.go +++ b/internal/gui/panel_options_test.go @@ -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) + } +} diff --git a/internal/gui/panel_space_darwin_test.go b/internal/gui/panel_space_darwin_test.go new file mode 100644 index 000000000..643ae81d5 --- /dev/null +++ b/internal/gui/panel_space_darwin_test.go @@ -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, `
magpie
`) + })}, + }) + 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) +} diff --git a/internal/gui/space_darwin.go b/internal/gui/space_darwin.go index ad1464cfd..294c350d7 100644 --- a/internal/gui/space_darwin.go +++ b/internal/gui/space_darwin.go @@ -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 {