diff --git a/internal/gui/app.go b/internal/gui/app.go index 4c3016654..9b57f9b4c 100644 --- a/internal/gui/app.go +++ b/internal/gui/app.go @@ -678,6 +678,14 @@ func panelOptions(goos, theme string) application.WebviewWindowOptions { // out of sight, until the user swiped back (#2141). CollectionBehavior: application.MacWindowCollectionBehaviorCanJoinAllSpaces | application.MacWindowCollectionBehaviorFullScreenAuxiliary, + // and shown without activating magpie, as a menu bar extra's + // panel is: an ordinary window's Focus activated the app, and + // the Mac then took the user to the Space of magpie's other + // windows (the desktop the main window is on), off the + // full-screen app's, panel and all (#2141, witt-bit, on + // v0.1.1246). A non-activating panel still takes the keyboard. + WindowClass: application.MacWindowClassPanel, + PanelPreferences: application.MacPanelPreferences{NonActivating: true}, }, Windows: application.WindowsWindow{HiddenOnTaskbar: true}, } diff --git a/internal/gui/panel_options_test.go b/internal/gui/panel_options_test.go index 50b9e3848..12ff40a1f 100644 --- a/internal/gui/panel_options_test.go +++ b/internal/gui/panel_options_test.go @@ -61,4 +61,10 @@ func TestPanelOnEverySpaceOnMac(t *testing.T) { if b&(application.MacWindowCollectionBehaviorMoveToActiveSpace|application.MacWindowCollectionBehaviorFullScreenPrimary) != 0 { t.Errorf("panel collection behaviour %d moves to the active Space or goes full screen itself", b) } + // shown without activating magpie: activated, the Mac took the user to + // the Space of magpie's other windows, off the full-screen app's + mac := panelOptions("darwin", "").Mac + if mac.WindowClass != application.MacWindowClassPanel || !mac.PanelPreferences.NonActivating { + t.Errorf("the panel is window class %d, non-activating %v; want a non-activating panel", mac.WindowClass, mac.PanelPreferences.NonActivating) + } } diff --git a/internal/gui/panel_space_darwin_test.go b/internal/gui/panel_space_darwin_test.go index 643ae81d5..a5ec96519 100644 --- a/internal/gui/panel_space_darwin_test.go +++ b/internal/gui/panel_space_darwin_test.go @@ -19,7 +19,8 @@ import ( // 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. +// shown and hidden with that set, without activating magpie (activated, +// the Mac took the user to the Space of magpie's other windows). 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") { @@ -57,8 +58,22 @@ func init() { 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() { w.Show().Focus() }) // the icon clicked 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(w.IsFocused) { + fail("%s: the panel shown doesn't take the keyboard", how) + } if !application.InvokeSyncWithResult(func() bool { return joinsFullScreenSpaces(w) }) { fail("%s: showing the panel took it off full-screen Spaces", how) } diff --git a/internal/gui/space_darwin.go b/internal/gui/space_darwin.go index 294c350d7..9a29eb053 100644 --- a/internal/gui/space_darwin.go +++ b/internal/gui/space_darwin.go @@ -23,6 +23,19 @@ static int joinsFullScreenSpaces(void *win) { return (b & NSWindowCollectionBehaviorCanJoinAllSpaces) != 0 && (b & NSWindowCollectionBehaviorFullScreenAuxiliary) != 0; } +// A non-activating panel: shown and focused, it leaves the app that is +// active so, and the Space the user is on with it. +static int nonActivating(void *win) { + NSWindow *w = (NSWindow *)win; + return [w isKindOfClass:[NSPanel class]] && (w.styleMask & NSWindowStyleMaskNonactivatingPanel) != 0; +} + +// Frontmost: the app whose menu bar shows, and whose Space the Mac goes +// to. A non-activating panel made key leaves another app frontmost. +static int appFrontmost(void) { + return [NSWorkspace sharedWorkspace].frontmostApplication.processIdentifier == NSProcessInfo.processInfo.processIdentifier; +} + // 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) { @@ -85,6 +98,17 @@ func joinsFullScreenSpaces(w *application.WebviewWindow) bool { return p != nil && C.joinsFullScreenSpaces(p) != 0 } +// nonActivating says whether w shows and takes the keyboard without +// activating magpie, as the quick panel does (#2141); on the main thread. +func nonActivating(w *application.WebviewWindow) bool { + p := w.NativeWindow() + return p != nil && C.nonActivating(p) != 0 +} + +// appFrontmost says whether magpie is the frontmost app, the one whose +// menu bar shows; on the main thread. +func appFrontmost() bool { return C.appFrontmost() != 0 } + // windowOpen says whether w is open: shown, on any Space, and not // minimised; on the main thread. func windowOpen(w *application.WebviewWindow) bool {