Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

perf(desktop-gpui): repaint the target picker only when what it draws changes

Richie McIlroya0d25c6de33e
diff --git a/apps/desktop-gpui/src/target_overlay.rs b/apps/desktop-gpui/src/target_overlay.rs
index feb0e2a44..18b4924cc 100644
--- a/apps/desktop-gpui/src/target_overlay.rs
+++ b/apps/desktop-gpui/src/target_overlay.rs
@@ -367,11 +367,14 @@ impl TargetSelect {
})
.await;
- let Ok((icon_wanted, active)) = this.update(cx, |this: &mut Self, cx| {
+ let Ok((icon_wanted, active, changed)) = this.update(cx, |this: &mut Self, cx| {
let (display, window) = probe;
- this.microphone_fill =
+ let microphone_fill =
crate::ui::MicrophoneLevel::fill(crate::feeds::Feeds::global(cx).read(cx));
- let changed = this.cursor_display != display || this.hovered_window != window;
+ let changed = this.cursor_display != display
+ || this.hovered_window != window
+ || this.microphone_fill != microphone_fill;
+ this.microphone_fill = microphone_fill;
this.cursor_display = display;
this.hovered_window = window;
if changed {
@@ -383,10 +386,12 @@ impl TargetSelect {
.map(|window| window.id.clone())
.filter(|id| !this.icons.contains_key(&id.to_string())),
this.active_window().cloned(),
+ changed,
)
}) else {
return;
};
+ let fetched_icon = icon_wanted.is_some();
if let Some(id) = icon_wanted {
Self::fetch_icon(id, &this, cx).await;
}
@@ -399,8 +404,11 @@ impl TargetSelect {
// Repaint the overlays explicitly: none of them is the active
// window while the user hovers another app, and an inactive
- // window only repaints when asked (the unit-2 finding).
- cx.update(app_windows::refresh_target_overlays);
+ // window only repaints when asked (the unit-2 finding). A tick
+ // that changed nothing they draw has nothing to repaint.
+ if changed || fetched_icon {
+ cx.update(app_windows::refresh_target_overlays);
+ }
cx.background_executor().timer(POLL_INTERVAL).await;
}
}));
@@ -642,6 +650,16 @@ impl OverlayWindow {
crate::theme::bind_window(window, cx);
let theme = Theme::for_window(window, cx, false);
cx.observe(&select, |_, _, cx| cx.notify()).detach();
+ let session = crate::session::RecordingSession::global(cx);
+ let mut drawn_phase = session.read(cx).phase;
+ cx.observe(&session, move |_, session, cx| {
+ let phase = session.read(cx).phase;
+ if phase != drawn_phase {
+ drawn_phase = phase;
+ cx.notify();
+ }
+ })
+ .detach();
let main = cx.global::<app_windows::AppWindows>().main;
let main_subscription = main
.update(cx, |_, _, cx| cx.entity())