diff --git a/crates/gpui2/src/app.rs b/crates/gpui2/src/app.rs index 422654d578..16dc5440bd 100644 --- a/crates/gpui2/src/app.rs +++ b/crates/gpui2/src/app.rs @@ -595,6 +595,14 @@ impl AppContext { break; } } + + for (_, window) in &self.windows { + if let Some(window) = window.as_ref() { + if window.dirty { + window.platform_window.invalidate(); + } + } + } } /// Repeatedly called during `flush_effects` to release any entities whose @@ -713,7 +721,7 @@ impl AppContext { fn apply_refresh_effect(&mut self) { for window in self.windows.values_mut() { if let Some(window) = window.as_mut() { - window.platform_window.invalidate(); + window.dirty = true; } } } diff --git a/crates/gpui2/src/platform/test/platform.rs b/crates/gpui2/src/platform/test/platform.rs index 8997eb4902..2a57842991 100644 --- a/crates/gpui2/src/platform/test/platform.rs +++ b/crates/gpui2/src/platform/test/platform.rs @@ -136,11 +136,12 @@ impl Platform for TestPlatform { &self, handle: AnyWindowHandle, options: WindowOptions, - _draw: Box Result>, + draw: Box Result>, ) -> Box { *self.active_window.lock() = Some(handle); Box::new(TestWindow::new( options, + draw, self.weak.clone(), self.active_display.clone(), )) diff --git a/crates/gpui2/src/platform/test/window.rs b/crates/gpui2/src/platform/test/window.rs index 424b203758..02b3982d12 100644 --- a/crates/gpui2/src/platform/test/window.rs +++ b/crates/gpui2/src/platform/test/window.rs @@ -1,7 +1,7 @@ use crate::{ - px, AtlasKey, AtlasTextureId, AtlasTile, Pixels, PlatformAtlas, PlatformDisplay, - PlatformInputHandler, PlatformWindow, Point, Scene, Size, TestPlatform, TileId, - WindowAppearance, WindowBounds, WindowOptions, + px, AtlasKey, AtlasTextureId, AtlasTile, DrawWindow, Pixels, PlatformAtlas, PlatformDisplay, + PlatformInputHandler, PlatformWindow, Point, Size, TestPlatform, TileId, WindowAppearance, + WindowBounds, WindowOptions, }; use collections::HashMap; use parking_lot::Mutex; @@ -20,7 +20,7 @@ pub(crate) struct TestWindowHandlers { pub struct TestWindow { pub(crate) bounds: WindowBounds, - current_scene: Mutex>, + draw: Mutex, display: Rc, pub(crate) window_title: Option, pub(crate) input_handler: Option>>>, @@ -32,12 +32,13 @@ pub struct TestWindow { impl TestWindow { pub fn new( options: WindowOptions, + draw: DrawWindow, platform: Weak, display: Rc, ) -> Self { Self { bounds: options.bounds, - current_scene: Default::default(), + draw: Mutex::new(draw), display, platform, input_handler: None, @@ -166,7 +167,9 @@ impl PlatformWindow for TestWindow { unimplemented!() } - fn invalidate(&self) {} + fn invalidate(&self) { + (self.draw.lock())().unwrap(); + } fn sprite_atlas(&self) -> sync::Arc { self.sprite_atlas.clone() diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rs index ad583af323..06412889a1 100644 --- a/crates/gpui2/src/window.rs +++ b/crates/gpui2/src/window.rs @@ -223,6 +223,7 @@ pub struct Window { bounds: WindowBounds, bounds_observers: SubscriberSet<(), AnyObserver>, active: bool, + pub(crate) dirty: bool, activation_observers: SubscriberSet<(), AnyObserver>, pub(crate) last_blur: Option>, pub(crate) focus: Option, @@ -355,6 +356,7 @@ impl Window { bounds, bounds_observers: SubscriberSet::new(), active: false, + dirty: false, activation_observers: SubscriberSet::new(), last_blur: None, focus: None, @@ -406,7 +408,7 @@ impl<'a> WindowContext<'a> { /// Mark the window as dirty, scheduling it to be redrawn on the next frame. pub fn notify(&mut self) { - self.window.platform_window.invalidate(); + self.window.dirty = true; } /// Close this window. @@ -1237,6 +1239,7 @@ impl<'a> WindowContext<'a> { .take() .unwrap_or(CursorStyle::Arrow); self.platform.set_cursor_style(cursor_style); + self.window.dirty = false; scene }