From 66d13cf42c0178b30e2d0d28de4cf19b6e079c84 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 15 Sep 2022 15:57:02 +0200 Subject: [PATCH] Query `isKeyWindow` on `windowDidBecomeKey` or `windowDidResignKey` Before we were assuming that receiving a callback meant that the window was in that "key" state accordingly, but with popups that's not always the case. In particular, there was a bug that caused an unrelated window to receive `windowDidBecomeKey` when making an `NSPanel` the key window. --- crates/gpui/src/platform/mac/window.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index a8e9853be6..b0002709e0 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -1070,17 +1070,12 @@ fn window_fullscreen_changed(this: &Object, is_fullscreen: bool) { } } -extern "C" fn window_did_change_key_status(this: &Object, selector: Sel, _: id) { - let is_active = if selector == sel!(windowDidBecomeKey:) { - true - } else if selector == sel!(windowDidResignKey:) { - false - } else { - unreachable!(); - }; - +extern "C" fn window_did_change_key_status(this: &Object, _: Sel, _: id) { let window_state = unsafe { get_window_state(this) }; - let executor = window_state.as_ref().borrow().executor.clone(); + let window_state_borrow = window_state.borrow(); + let is_active = unsafe { window_state_borrow.native_window.isKeyWindow() }; + let executor = window_state_borrow.executor.clone(); + drop(window_state_borrow); executor .spawn(async move { let mut window_state_borrow = window_state.as_ref().borrow_mut();