From 15567493bafa88906c3e5bbdd880636852764396 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 25 Sep 2023 11:55:05 -0600 Subject: [PATCH] WIP --- crates/gpui3/src/app.rs | 23 ++++++++++++++++++++--- crates/gpui3/src/window.rs | 4 ++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/crates/gpui3/src/app.rs b/crates/gpui3/src/app.rs index 28bc0b636e841da5e9be3eac39089421c498f737..5752d91261b3fa6c24964a972c3103b9628e1759 100644 --- a/crates/gpui3/src/app.rs +++ b/crates/gpui3/src/app.rs @@ -115,12 +115,12 @@ impl AppContext { pub(crate) fn update_window( &mut self, - handle: AnyWindowHandle, + id: WindowId, update: impl FnOnce(&mut WindowContext) -> R, ) -> Result { let mut window = self .windows - .get_mut(handle.id) + .get_mut(id) .ok_or_else(|| anyhow!("window not found"))? .take() .unwrap(); @@ -129,7 +129,7 @@ impl AppContext { window.dirty = true; self.windows - .get_mut(handle.id) + .get_mut(id) .ok_or_else(|| anyhow!("window not found"))? .replace(window); @@ -152,6 +152,23 @@ impl AppContext { Effect::Notify(entity_id) => self.apply_notify_effect(entity_id), } } + + let dirty_window_ids = self + .windows + .iter() + .filter_map(|(window_id, window)| { + let window = window.as_ref().unwrap(); + if window.dirty { + Some(window_id) + } else { + None + } + }) + .collect::>(); + + for dirty_window_id in dirty_window_ids { + self.update_window(dirty_window_id, |cx| cx.draw()); + } } fn apply_notify_effect(&mut self, updated_entity: EntityId) { diff --git a/crates/gpui3/src/window.rs b/crates/gpui3/src/window.rs index b1e1407aa60a2dda98c5bf3d54779671d264bc4b..ca28928739dcf4b0386f7c551c54184da4730c69 100644 --- a/crates/gpui3/src/window.rs +++ b/crates/gpui3/src/window.rs @@ -133,7 +133,7 @@ impl<'a, 'w> WindowContext<'a, 'w> { if window_handle == self.window.handle { Ok(update(self)) } else { - self.app.update_window(window_handle, update) + self.app.update_window(window_handle.id, update) } } } @@ -258,7 +258,7 @@ impl<'a, 'w, T: Send + Sync + 'static> ViewContext<'a, 'w, T> { .entry(handle.id) .or_default() .push(Arc::new(move |cx| { - cx.update_window(window_handle, |cx| { + cx.update_window(window_handle.id, |cx| { if let Some(handle) = handle.upgrade(cx) { this.update(cx, |this, cx| on_notify(this, handle, cx)) .is_ok()