window: Don't invalidate cssnode during get_preferred_width()

Getting the shadow width must not call gtk_style_context_set_state()
because that will invalidate the node and cause a style-updated emission
which can cause gtk_widget_queue_resize() calls.

And calling queue_resize() from get_preferred_size() essentially means
the size is permanently invalid because you invalidate it while
querying it.

This causes flickering of windows when going from/to backdrop state. To
avoid this we either need to fix the theme to not have different shadow
sizes in those cases or we need to ensure the window doesn't flicker in
the first place.
This commit is contained in:
Benjamin Otte 2015-11-14 18:28:34 +01:00
parent 38bfec8ea4
commit 55735cee2f

View File

@ -6717,9 +6717,8 @@ get_shadow_width (GtkWindow *window,
GtkBorder d = { 0 };
GtkBorder margin;
GtkStyleContext *context;
GtkStateFlags state, s;
GtkStateFlags s;
GtkCssValue *shadows;
gint i;
*shadow_width = border;
@ -6738,23 +6737,10 @@ get_shadow_width (GtkWindow *window,
if (!_gtk_widget_is_toplevel (GTK_WIDGET (window)))
return;
state = _gtk_widget_get_state_flags (GTK_WIDGET (window));
context = _gtk_widget_get_style_context (GTK_WIDGET (window));
gtk_style_context_save_to_node (context, priv->decoration_node);
/* We don't want windows to jump as they go to backdrop,
* therefore we use the maximum of the decoration sizes
* for focused and unfocused.
*/
for (i = 0; i < 2; i++)
{
if (i == 0)
s = state & ~GTK_STATE_FLAG_BACKDROP;
else
s = state | GTK_STATE_FLAG_BACKDROP;
gtk_style_context_set_state (context, s);
s = gtk_style_context_get_state (context);
/* Always sum border + padding */
gtk_style_context_get_border (context, s, &border);
@ -6773,8 +6759,7 @@ get_shadow_width (GtkWindow *window,
}
sum_borders (&d, &border);
max_borders (shadow_width, &d);
}
*shadow_width = d;
gtk_style_context_restore (context);
}