diff --git a/internal/gui/panel_space_darwin_test.go b/internal/gui/panel_space_darwin_test.go index a5ec96519..db588871b 100644 --- a/internal/gui/panel_space_darwin_test.go +++ b/internal/gui/panel_space_darwin_test.go @@ -71,8 +71,19 @@ func init() { 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) { - fail("%s: the panel shown doesn't take the keyboard", how) + 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) diff --git a/internal/gui/space_darwin.go b/internal/gui/space_darwin.go index 9a29eb053..c2ba1a6e8 100644 --- a/internal/gui/space_darwin.go +++ b/internal/gui/space_darwin.go @@ -30,6 +30,29 @@ static int nonActivating(void *win) { return [w isKindOfClass:[NSPanel class]] && (w.styleMask & NSWindowStyleMaskNonactivatingPanel) != 0; } +// Can be made key: a borderless window can't unless its class says so, +// as Wails' panel class does. +static int canBeKey(void *win) { + return ((NSWindow *)win).canBecomeKeyWindow; +} + +// Whether this session lets an app that isn't active make a +// non-activating panel key from code: a plain titled one is shown and +// made key as the quick panel is. With no click or key press behind it, +// macOS 26.2 left even that one not key on a Mac no one was at (#2450). +static int sessionKeysPanels(void) { + NSPanel *p = [[NSPanel alloc] initWithContentRect:NSMakeRect(0, 0, 40, 40) + styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskNonactivatingPanel + backing:NSBackingStoreBuffered defer:NO]; + p.releasedWhenClosed = NO; + [p orderFrontRegardless]; + [p makeKeyWindow]; + int key = p.isKeyWindow; + [p orderOut:nil]; + [p release]; + return key; +} + // 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) { @@ -98,6 +121,19 @@ func joinsFullScreenSpaces(w *application.WebviewWindow) bool { return p != nil && C.joinsFullScreenSpaces(p) != 0 } +// canBeKey says whether w can be made key, take the keyboard; on the +// main thread. +func canBeKey(w *application.WebviewWindow) bool { + p := w.NativeWindow() + return p != nil && C.canBeKey(p) != 0 +} + +// sessionKeysPanels says whether this session makes a non-activating +// panel key when an app that isn't active asks with no input behind it, +// which decides whether a test can see the quick panel take the keyboard +// (#2450); on the main thread. +func sessionKeysPanels() bool { return C.sessionKeysPanels() != 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 {