From 2337d8676dbde6cd10f6112a13e73e3bb18a28e5 Mon Sep 17 00:00:00 2001 From: cptpcrd <31829097+cptpcrd@users.noreply.github.com> Date: Thu, 1 Aug 2024 06:13:13 -0400 Subject: [PATCH] fix: handle failing to enter fullscreen on macOS (#43112) * fix: handle failing to enter/exit fullscreen on macOS On macOS, failing to enter/exit fullscreen can fail. If this happens, properly restore the original window state. * refactor: remove fail to exit fullscreen handlers Seem to be unnecessary since the window exits fullscreen anyway. --- shell/browser/native_window_mac.h | 1 + shell/browser/native_window_mac.mm | 7 +++++++ .../browser/ui/cocoa/electron_ns_window_delegate.mm | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/shell/browser/native_window_mac.h b/shell/browser/native_window_mac.h index d3c541ba688f..cb39aab4843f 100644 --- a/shell/browser/native_window_mac.h +++ b/shell/browser/native_window_mac.h @@ -167,6 +167,7 @@ class NativeWindowMac : public NativeWindow, void DetachChildren() override; void NotifyWindowWillEnterFullScreen(); + void NotifyWindowDidFailToEnterFullScreen(); void NotifyWindowWillLeaveFullScreen(); // Cleanup observers when window is getting closed. Note that the destructor diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index 06b4600245f1..3766e10d31c8 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -1662,6 +1662,13 @@ void NativeWindowMac::NotifyWindowWillEnterFullScreen() { UpdateVibrancyRadii(true); } +void NativeWindowMac::NotifyWindowDidFailToEnterFullScreen() { + UpdateVibrancyRadii(false); + + if (buttons_proxy_) + [buttons_proxy_ redraw]; +} + void NativeWindowMac::NotifyWindowWillLeaveFullScreen() { if (buttons_proxy_) { // Hide window title when leaving fullscreen. diff --git a/shell/browser/ui/cocoa/electron_ns_window_delegate.mm b/shell/browser/ui/cocoa/electron_ns_window_delegate.mm index e15687a942ee..d6af0ac6d9bb 100644 --- a/shell/browser/ui/cocoa/electron_ns_window_delegate.mm +++ b/shell/browser/ui/cocoa/electron_ns_window_delegate.mm @@ -311,6 +311,18 @@ using FullScreenTransitionState = shell_->HandlePendingFullscreenTransitions(); } +- (void)windowDidFailToEnterFullScreen:(NSWindow*)window { + shell_->set_fullscreen_transition_state(FullScreenTransitionState::kNone); + + shell_->SetResizable(is_resizable_); + shell_->NotifyWindowDidFailToEnterFullScreen(); + + if (shell_->HandleDeferredClose()) + return; + + shell_->HandlePendingFullscreenTransitions(); +} + - (void)windowWillExitFullScreen:(NSNotification*)notification { shell_->set_fullscreen_transition_state(FullScreenTransitionState::kExiting);