gpui_macos: Fix deadlock during re-entrant key status changes (#51035)

Closes #50151

Before you mark this PR as ready for review, make sure that you have:
- [ ] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [ ] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- Fixed a deadlock that froze the entire app when opening a new window
from a PopUp window or switching focus between multiple windows on
macOS.
This commit is contained in:
João Soares 2026-03-17 05:50:54 -03:00 committed by GitHub
parent f1e7f397d7
commit 97049a76ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2113,10 +2113,12 @@ extern "C" fn window_did_change_key_status(this: &Object, selector: Sel, _: id)
// in theory, we're not supposed to invoke this method manually but it balances out
// the spurious `becomeKeyWindow` event and helps us work around that bug.
if selector == sel!(windowDidBecomeKey:) && !is_active {
let native_window = lock.native_window;
drop(lock);
unsafe {
let _: () = msg_send![lock.native_window, resignKeyWindow];
return;
let _: () = msg_send![native_window, resignKeyWindow];
}
return;
}
let executor = lock.foreground_executor.clone();