fix: zombie windows when fullscreening and closing (#34393)

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot]
2022-05-31 13:15:31 -04:00
committed by GitHub
parent f3da81cb77
commit 4b793692ea
4 changed files with 46 additions and 5 deletions

View File

@@ -176,6 +176,10 @@ class NativeWindowMac : public NativeWindow,
// Handle fullscreen transitions.
void SetFullScreenTransitionState(FullScreenTransitionState state);
void HandlePendingFullscreenTransitions();
bool HandleDeferredClose();
void SetHasDeferredWindowClose(bool defer_close) {
has_deferred_window_close_ = defer_close;
}
enum class VisualEffectState {
kFollowWindow,
@@ -249,6 +253,12 @@ class NativeWindowMac : public NativeWindow,
FullScreenTransitionState fullscreen_transition_state_ =
FullScreenTransitionState::NONE;
// Trying to close an NSWindow during a fullscreen transition will cause the
// window to lock up. Use this to track if CloseWindow was called during a
// fullscreen transition, to defer the -[NSWindow close] call until the
// transition is complete.
bool has_deferred_window_close_ = false;
NSInteger attention_request_id_ = 0; // identifier from requestUserAttention
// The presentation options before entering kiosk mode.

View File

@@ -474,6 +474,11 @@ void NativeWindowMac::Close() {
return;
}
if (fullscreen_transition_state() != FullScreenTransitionState::NONE) {
SetHasDeferredWindowClose(true);
return;
}
// If a sheet is attached to the window when we call
// [window_ performClose:nil], the window won't close properly
// even after the user has ended the sheet.
@@ -678,6 +683,15 @@ void NativeWindowMac::HandlePendingFullscreenTransitions() {
SetFullScreen(next_transition);
}
bool NativeWindowMac::HandleDeferredClose() {
if (has_deferred_window_close_) {
SetHasDeferredWindowClose(false);
Close();
return true;
}
return false;
}
void NativeWindowMac::SetFullScreen(bool fullscreen) {
// [NSWindow -toggleFullScreen] is an asynchronous operation, which means
// that it's possible to call it while a fullscreen transition is currently

View File

@@ -248,6 +248,9 @@ using FullScreenTransitionState =
shell_->NotifyWindowEnterFullScreen();
if (shell_->HandleDeferredClose())
return;
shell_->HandlePendingFullscreenTransitions();
}
@@ -263,6 +266,9 @@ using FullScreenTransitionState =
shell_->SetResizable(is_resizable_);
shell_->NotifyWindowLeaveFullScreen();
if (shell_->HandleDeferredClose())
return;
shell_->HandlePendingFullscreenTransitions();
}