Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
gpui: Update animated image timing to pause when inactive (#52685)
MostlyK086060558f9c
diff --git a/crates/gpui/src/elements/img.rs b/crates/gpui/src/elements/img.rsindex ccf10d038c2..ccd4123048c 100644--- a/crates/gpui/src/elements/img.rs+++ b/crates/gpui/src/elements/img.rs@@ -315,20 +315,24 @@ impl Element for Img {if let Some(state) = &mut state {let frame_count = data.frame_count();if frame_count > 1 {- let current_time = Instant::now();- if let Some(last_frame_time) = state.last_frame_time {- let elapsed = current_time - last_frame_time;- let frame_duration =- Duration::from(data.delay(state.frame_index));-- if elapsed >= frame_duration {- state.frame_index =- (state.frame_index + 1) % frame_count;- state.last_frame_time =- Some(current_time - (elapsed - frame_duration));+ if window.is_window_active() {+ let current_time = Instant::now();+ if let Some(last_frame_time) = state.last_frame_time {+ let elapsed = current_time - last_frame_time;+ let frame_duration =+ Duration::from(data.delay(state.frame_index));++ if elapsed >= frame_duration {+ state.frame_index =+ (state.frame_index + 1) % frame_count;+ state.last_frame_time =+ Some(current_time - (elapsed - frame_duration));+ }+ } else {+ state.last_frame_time = Some(current_time);}} else {- state.last_frame_time = Some(current_time);+ state.last_frame_time = None;}}state.started_loading = None;@@ -365,7 +369,10 @@ impl Element for Img {};}- if global_id.is_some() && data.frame_count() > 1 {+ if global_id.is_some()+ && data.frame_count() > 1+ && window.is_window_active()+ {window.request_animation_frame();}}