From 678b641950cbf1ad35da1edbdd351bc6ef979f68 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sun, 24 Jan 2021 23:45:24 +0100 Subject: [PATCH] Fix initial focus problem for hidden windows under Mac Assume that hidden windows do accept focus because, even if this is still wrong, in general, it is less harmful than wrongly returning false from CanFocus() for them. Closes #18987. --- src/osx/cocoa/window.mm | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 7ffe20a338..3336fa0fca 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -3094,12 +3094,11 @@ bool wxWidgetCocoaImpl::CanFocus() const { if ( !IsVisible() ) { - // It's useless to call canBecomeKeyView in this case, it will always - // return false. Try to return something reasonable ourselves, knowing - // that most controls are not focusable when full keyboard access if - // off and wxNSTextViewControl overrides CanFocus() to always return - // true anyhow. - return [NSApp isFullKeyboardAccessEnabled]; + // canBecomeKeyView always returns false for hidden windows, but this + // could be wrong because the window could still accept focus once it + // becomes visible, so we have no choice but to return true here to + // avoid situations in which the expected window doesn't get the focus. + return true; } NSView* targetView = m_osxView;