[gtk+] window: Don't invalidate cssnode during get_preferred_width()



commit 55735cee2f05eca385f00c196bad05eb50c06822
Author: Benjamin Otte <otte redhat com>
Date:   Sat Nov 14 18:28:34 2015 +0100

    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.

 gtk/gtkwindow.c |   49 +++++++++++++++++--------------------------------
 1 files changed, 17 insertions(+), 32 deletions(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index b52a2fa..db41f91 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -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,44 +6737,30 @@ 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);
+  s = gtk_style_context_get_state (context);
 
-  /* 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);
-
-      /* Always sum border + padding */
-      gtk_style_context_get_border (context, s, &border);
-      gtk_style_context_get_padding (context, s, &d);
-      sum_borders (&d, &border);
+  /* Always sum border + padding */
+  gtk_style_context_get_border (context, s, &border);
+  gtk_style_context_get_padding (context, s, &d);
+  sum_borders (&d, &border);
 
-      /* Calculate the size of the drop shadows ... */
-      shadows = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BOX_SHADOW);
-      _gtk_css_shadows_value_get_extents (shadows, &border);
+  /* Calculate the size of the drop shadows ... */
+  shadows = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BOX_SHADOW);
+  _gtk_css_shadows_value_get_extents (shadows, &border);
 
-      if (priv->type != GTK_WINDOW_POPUP)
-        {
-          /* ... and compare it to the margin size, which we use for resize grips */
-          gtk_style_context_get_margin (context, s, &margin);
-          max_borders (&border, &margin);
-        }
-
-      sum_borders (&d, &border);
-      max_borders (shadow_width, &d);
+  if (priv->type != GTK_WINDOW_POPUP)
+    {
+      /* ... and compare it to the margin size, which we use for resize grips */
+      gtk_style_context_get_margin (context, s, &margin);
+      max_borders (&border, &margin);
     }
 
+  sum_borders (&d, &border);
+  *shadow_width = d;
+
   gtk_style_context_restore (context);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]