From c62357db025fcdabacceba0498e41522d1fb0cf8 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 14 Apr 2023 08:24:01 +0200 Subject: [PATCH] Fix window activation --- crates/gpui/src/app.rs | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 692d94a455..aa4ceb075b 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -499,7 +499,7 @@ type GlobalObservationCallback = Box; type FocusObservationCallback = Box bool>; type ReleaseObservationCallback = Box; type ActionObservationCallback = Box; -type WindowActivationCallback = Box bool>; +type WindowActivationCallback = Box bool>; type WindowFullscreenCallback = Box bool>; type WindowBoundsCallback = Box bool>; type KeystrokeCallback = @@ -1110,7 +1110,7 @@ impl AppContext { fn observe_window_activation(&mut self, window_id: usize, callback: F) -> Subscription where - F: 'static + FnMut(bool, &mut AppContext) -> bool, + F: 'static + FnMut(bool, &mut WindowContext) -> bool, { let subscription_id = post_inc(&mut self.next_subscription_id); self.pending_effects @@ -2070,22 +2070,13 @@ impl AppContext { } fn handle_window_activation_effect(&mut self, window_id: usize, active: bool) { - //Short circuit evaluation if we're already g2g - if self - .windows - .get(&window_id) - .map(|w| w.is_active == active) - .unwrap_or(false) - { - return; - } - - self.update(|cx| { - cx.update_window(window_id, |cx| { - let Some(focused_id) = cx.window.focused_view_id else { - return; - }; + self.update_window(window_id, |cx| { + if cx.window.is_active == active { + return; + } + cx.window.is_active = active; + if let Some(focused_id) = cx.window.focused_view_id { for view_id in cx.ancestors(window_id, focused_id).collect::>() { cx.update_any_view(focused_id, |view, cx| { if active { @@ -2095,12 +2086,10 @@ impl AppContext { } }); } - }); + } let mut observations = cx.window_activation_observations.clone(); observations.emit(window_id, |callback| callback(active, cx)); - - Some(()) }); }