diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index 2acea0428068..6889eb6f1873 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -429,7 +429,13 @@ void NativeWindowMac::ShowInactive() { if (parent()) InternalSetParentWindow(parent(), true); + // Triggers `NativeWidgetMacNSWindowHost::OnVisibilityChanged`. + widget()->ShowInactive(); + // `Widget::ShowInactive` is not sufficient to bring window to front. [window_ orderFrontRegardless]; + // Above calls do not trigger `orderWindow: relativeTo:` in which headless + // mode is being disabled. + [window_ disableHeadlessMode]; } void NativeWindowMac::Hide() { diff --git a/shell/browser/ui/cocoa/electron_ns_window.h b/shell/browser/ui/cocoa/electron_ns_window.h index 63ea5355467d..8c026c0b0bdc 100644 --- a/shell/browser/ui/cocoa/electron_ns_window.h +++ b/shell/browser/ui/cocoa/electron_ns_window.h @@ -49,6 +49,7 @@ class ElectronNativeWindowObserver; - (NSRect)originalContentRectForFrameRect:(NSRect)frameRect; - (BOOL)toggleFullScreenMode:(id)sender; - (NSImage*)_cornerMask; +- (void)disableHeadlessMode; @end #endif // ELECTRON_SHELL_BROWSER_UI_COCOA_ELECTRON_NS_WINDOW_H_ diff --git a/shell/browser/ui/cocoa/electron_ns_window.mm b/shell/browser/ui/cocoa/electron_ns_window.mm index 30780277d3a5..6555f47f5bc3 100644 --- a/shell/browser/ui/cocoa/electron_ns_window.mm +++ b/shell/browser/ui/cocoa/electron_ns_window.mm @@ -259,13 +259,7 @@ void SwizzleSwipeWithEvent(NSView* view, SEL swiz_selector) { } - (void)orderWindow:(NSWindowOrderingMode)place relativeTo:(NSInteger)otherWin { - if (shell_) { - // We initialize the window in headless mode to allow painting before it is - // shown, but we don't want the headless behavior of allowing the window to - // be placed unconstrained. - self.isHeadless = false; - shell_->widget()->DisableHeadlessMode(); - } + [self disableHeadlessMode]; [super orderWindow:place relativeTo:otherWin]; } @@ -328,6 +322,16 @@ void SwizzleSwipeWithEvent(NSView* view, SEL swiz_selector) { } } +- (void)disableHeadlessMode { + if (shell_) { + // We initialize the window in headless mode to allow painting before it is + // shown, but we don't want the headless behavior of allowing the window to + // be placed unconstrained. + self.isHeadless = false; + shell_->widget()->DisableHeadlessMode(); + } +} + // Quicklook methods - (BOOL)acceptsPreviewPanelControl:(QLPreviewPanel*)panel {