Fix window activation
This commit is contained in:
+9
-20
@@ -499,7 +499,7 @@ type GlobalObservationCallback = Box<dyn FnMut(&mut AppContext)>;
|
|||||||
type FocusObservationCallback = Box<dyn FnMut(bool, &mut WindowContext) -> bool>;
|
type FocusObservationCallback = Box<dyn FnMut(bool, &mut WindowContext) -> bool>;
|
||||||
type ReleaseObservationCallback = Box<dyn FnMut(&dyn Any, &mut AppContext)>;
|
type ReleaseObservationCallback = Box<dyn FnMut(&dyn Any, &mut AppContext)>;
|
||||||
type ActionObservationCallback = Box<dyn FnMut(TypeId, &mut AppContext)>;
|
type ActionObservationCallback = Box<dyn FnMut(TypeId, &mut AppContext)>;
|
||||||
type WindowActivationCallback = Box<dyn FnMut(bool, &mut AppContext) -> bool>;
|
type WindowActivationCallback = Box<dyn FnMut(bool, &mut WindowContext) -> bool>;
|
||||||
type WindowFullscreenCallback = Box<dyn FnMut(bool, &mut AppContext) -> bool>;
|
type WindowFullscreenCallback = Box<dyn FnMut(bool, &mut AppContext) -> bool>;
|
||||||
type WindowBoundsCallback = Box<dyn FnMut(WindowBounds, Uuid, &mut AppContext) -> bool>;
|
type WindowBoundsCallback = Box<dyn FnMut(WindowBounds, Uuid, &mut AppContext) -> bool>;
|
||||||
type KeystrokeCallback =
|
type KeystrokeCallback =
|
||||||
@@ -1110,7 +1110,7 @@ impl AppContext {
|
|||||||
|
|
||||||
fn observe_window_activation<F>(&mut self, window_id: usize, callback: F) -> Subscription
|
fn observe_window_activation<F>(&mut self, window_id: usize, callback: F) -> Subscription
|
||||||
where
|
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);
|
let subscription_id = post_inc(&mut self.next_subscription_id);
|
||||||
self.pending_effects
|
self.pending_effects
|
||||||
@@ -2070,22 +2070,13 @@ impl AppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handle_window_activation_effect(&mut self, window_id: usize, active: bool) {
|
fn handle_window_activation_effect(&mut self, window_id: usize, active: bool) {
|
||||||
//Short circuit evaluation if we're already g2g
|
self.update_window(window_id, |cx| {
|
||||||
if self
|
if cx.window.is_active == active {
|
||||||
.windows
|
return;
|
||||||
.get(&window_id)
|
}
|
||||||
.map(|w| w.is_active == active)
|
cx.window.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;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
if let Some(focused_id) = cx.window.focused_view_id {
|
||||||
for view_id in cx.ancestors(window_id, focused_id).collect::<Vec<_>>() {
|
for view_id in cx.ancestors(window_id, focused_id).collect::<Vec<_>>() {
|
||||||
cx.update_any_view(focused_id, |view, cx| {
|
cx.update_any_view(focused_id, |view, cx| {
|
||||||
if active {
|
if active {
|
||||||
@@ -2095,12 +2086,10 @@ impl AppContext {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
let mut observations = cx.window_activation_observations.clone();
|
let mut observations = cx.window_activation_observations.clone();
|
||||||
observations.emit(window_id, |callback| callback(active, cx));
|
observations.emit(window_id, |callback| callback(active, cx));
|
||||||
|
|
||||||
Some(())
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user