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.
This commit is contained in:
Antonio Scandurra 2022-09-15 15:57:02 +02:00
parent ea00a00028
commit 66d13cf42c

View file

@ -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();