From 9948e0a564bf2fca94d884963ff4c4055006dc32 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 25 Jun 2024 20:07:20 -0400 Subject: [PATCH] css: Fix animations Determine whether the style needs recomputation, then recompute the style, and then set the values from keyframes, so we don't end up overwriting keyframe changes by recomputing properties from their original values. Fixes: #6807 --- gtk/gtkcssanimation.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/gtk/gtkcssanimation.c b/gtk/gtkcssanimation.c index 7c09a370b0..348a5dd7a1 100644 --- a/gtk/gtkcssanimation.c +++ b/gtk/gtkcssanimation.c @@ -132,6 +132,29 @@ gtk_css_animation_apply_values (GtkStyleAnimation *style_animation, gtk_css_variable_value_unref (value); } + /* Now deal with color */ + for (i = 0; i < _gtk_css_keyframes_get_n_properties (resolved_keyframes); i++) + { + GtkCssValue *value; + guint property_id; + + property_id = _gtk_css_keyframes_get_property_id (resolved_keyframes, i); + if (property_id != GTK_CSS_PROPERTY_COLOR) + continue; + + value = _gtk_css_keyframes_get_value (resolved_keyframes, + i, + progress, + gtk_css_animated_style_get_intrinsic_value (style, property_id)); + gtk_css_animated_style_set_animated_value (style, property_id, value); + + change |= GTK_CSS_ANIMATION_CHANGE_COLOR; + break; + } + + if (change != 0) + gtk_css_animated_style_recompute (style, change); + for (i = 0; i < _gtk_css_keyframes_get_n_properties (resolved_keyframes); i++) { GtkCssValue *value; @@ -144,14 +167,8 @@ gtk_css_animation_apply_values (GtkStyleAnimation *style_animation, progress, gtk_css_animated_style_get_intrinsic_value (style, property_id)); gtk_css_animated_style_set_animated_value (style, property_id, value); - - if (property_id == GTK_CSS_PROPERTY_COLOR) - change |= GTK_CSS_ANIMATION_CHANGE_COLOR; } - if (change != 0) - gtk_css_animated_style_recompute (style, change); - _gtk_css_keyframes_unref (resolved_keyframes); }