From 87d60beda714c18c9a7b216cfa7216f72cebc561 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Thu, 18 Jan 2024 20:47:29 -0700 Subject: [PATCH] Fix a double borrow error in window.open It seems that sometimes calling toggleFullScreen will cause the display_layer callback of a different window to fire. --- crates/gpui/src/platform/mac/window.rs | 40 ++++++++++++++------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index 134390bb79900b0cc09efba720b373303d8cd26b..ee7411bc4f8aa67e7b6eee9162c415b2b46da0b8 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -516,25 +516,6 @@ impl MacWindow { NSArray::arrayWithObject(nil, NSFilenamesPboardType) ]; - let screen = native_window.screen(); - match options.bounds { - WindowBounds::Fullscreen => { - native_window.toggleFullScreen_(nil); - } - WindowBounds::Maximized => { - native_window.setFrame_display_(screen.visibleFrame(), YES); - } - WindowBounds::Fixed(bounds) => { - let display_bounds = display.bounds(); - let frame = if bounds.intersects(&display_bounds) { - display_bounds_to_native(bounds) - } else { - display_bounds_to_native(display_bounds) - }; - native_window.setFrame_display_(mem::transmute::(frame), YES); - } - } - let native_view: id = msg_send![VIEW_CLASS, alloc]; let native_view = NSView::init(native_view); @@ -656,6 +637,27 @@ impl MacWindow { native_window.orderFront_(nil); } + let screen = native_window.screen(); + match options.bounds { + WindowBounds::Fullscreen => { + // We need to toggle full screen asynchronously as doing so may + // call back into the platform handlers. + window.toggle_full_screen() + } + WindowBounds::Maximized => { + native_window.setFrame_display_(screen.visibleFrame(), YES); + } + WindowBounds::Fixed(bounds) => { + let display_bounds = display.bounds(); + let frame = if bounds.intersects(&display_bounds) { + display_bounds_to_native(bounds) + } else { + display_bounds_to_native(display_bounds) + }; + native_window.setFrame_display_(mem::transmute::(frame), YES); + } + } + window.0.lock().move_traffic_light(); pool.drain();