From ab185c058f894ddc556f67b2853de4adad2bb10c Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 11 Sep 2023 09:38:10 +0200 Subject: [PATCH] fix: fullscreen crashing with no roundedCorners and no frame (#39747) --- shell/browser/native_window_mac.mm | 6 ++---- shell/browser/ui/cocoa/electron_ns_window.h | 2 +- shell/browser/ui/cocoa/electron_ns_window.mm | 7 ++++++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index e339366b05a2..49f9dbdd8867 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -683,9 +683,6 @@ void NativeWindowMac::DetachChildren() { } void NativeWindowMac::SetFullScreen(bool fullscreen) { - if (!has_frame() && !HasStyleMask(NSWindowStyleMaskTitled)) - return; - // [NSWindow -toggleFullScreen] is an asynchronous operation, which means // that it's possible to call it while a fullscreen transition is currently // in process. This can create weird behavior (incl. phantom windows), @@ -718,7 +715,8 @@ void NativeWindowMac::SetFullScreen(bool fullscreen) { ? FullScreenTransitionState::kEntering : FullScreenTransitionState::kExiting; - [window_ toggleFullScreenMode:nil]; + if (![window_ toggleFullScreenMode:nil]) + fullscreen_transition_state_ = FullScreenTransitionState::kNone; } bool NativeWindowMac::IsFullscreen() const { diff --git a/shell/browser/ui/cocoa/electron_ns_window.h b/shell/browser/ui/cocoa/electron_ns_window.h index 4256050d7e81..502592313c15 100644 --- a/shell/browser/ui/cocoa/electron_ns_window.h +++ b/shell/browser/ui/cocoa/electron_ns_window.h @@ -44,7 +44,7 @@ class ScopedDisableResize { - (electron::NativeWindowMac*)shell; - (id)accessibilityFocusedUIElement; - (NSRect)originalContentRectForFrameRect:(NSRect)frameRect; -- (void)toggleFullScreenMode:(id)sender; +- (BOOL)toggleFullScreenMode:(id)sender; - (NSImage*)_cornerMask; @end diff --git a/shell/browser/ui/cocoa/electron_ns_window.mm b/shell/browser/ui/cocoa/electron_ns_window.mm index ae4e96859b0e..17adef63de82 100644 --- a/shell/browser/ui/cocoa/electron_ns_window.mm +++ b/shell/browser/ui/cocoa/electron_ns_window.mm @@ -334,7 +334,10 @@ void SwizzleSwipeWithEvent(NSView* view, SEL swiz_selector) { } } -- (void)toggleFullScreenMode:(id)sender { +- (BOOL)toggleFullScreenMode:(id)sender { + if (!shell_->has_frame() && !shell_->HasStyleMask(NSWindowStyleMaskTitled)) + return NO; + bool is_simple_fs = shell_->IsSimpleFullScreen(); bool always_simple_fs = shell_->always_simple_fullscreen(); @@ -363,6 +366,8 @@ void SwizzleSwipeWithEvent(NSView* view, SEL swiz_selector) { bool maximizable = shell_->IsMaximizable(); shell_->SetMaximizable(maximizable); } + + return YES; } - (void)performMiniaturize:(id)sender {