[gtk+/gtk-3-8] window: restore size after hide/show properly



commit 38b62e4660a470cdda94480d3ab6da467125998e
Author: Benjamin Otte <otte redhat com>
Date:   Mon Apr 8 16:25:29 2013 +0200

    window: restore size after hide/show properly
    
    Old code assumed the size was stored in widget.allocation. This is no
    longer true as the allocation is cleared upon hide. However, we store
    the last configure request, and that one tracks the last size, so we can
    just use that number.
    
    Sometimes things are so easy - once you figure them out...
    
    https://bugzilla.gnome.org/show_bug.cgi?id=696882

 gtk/gtkwindow.c |   76 ++++++++++++++++++++++++------------------------------
 1 files changed, 34 insertions(+), 42 deletions(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index a8dfd31..9eda8c9 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -141,7 +141,6 @@ struct _GtkWindowPrivate
    * and on unrealize (for size).
    */
   guint    need_default_position     : 1;
-  guint    need_default_size         : 1;
 
   guint    above_initially           : 1;
   guint    accept_focus              : 1;
@@ -1145,7 +1144,6 @@ gtk_window_init (GtkWindow *window)
   priv->resizable = TRUE;
   priv->configure_notify_received = FALSE;
   priv->position = GTK_WIN_POS_NONE;
-  priv->need_default_size = TRUE;
   priv->need_default_position = TRUE;
   priv->modal = FALSE;
   priv->gdk_type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
@@ -4931,7 +4929,6 @@ gtk_window_map (GtkWidget *widget)
     }
 
   /* No longer use the default settings */
-  priv->need_default_size = FALSE;
   priv->need_default_position = FALSE;
 
   if (priv->reset_type_hint)
@@ -5083,10 +5080,12 @@ gtk_window_guess_default_size (GtkWindow *window,
                                gint      *width,
                                gint      *height)
 {
-  GtkWidget *widget = GTK_WIDGET (window);
+  GtkWindowGeometryInfo *info;
+  GtkWidget *widget;
   GdkScreen *screen;
   int minimum, natural;
 
+  widget = GTK_WIDGET (window);
   screen = gtk_widget_get_screen (widget);
 
   *width = gdk_screen_get_width (screen);
@@ -5121,6 +5120,14 @@ gtk_window_guess_default_size (GtkWindow *window,
       gtk_widget_get_preferred_height_for_width (widget, *width, &minimum, &natural);
       *height = MAX (minimum, MIN (*height, natural));
     }
+
+  info = gtk_window_get_geometry_info (window, FALSE);
+  if (info)
+    {
+      /* MAX() works even if the last request is unset with -1 */
+      *width = MAX (*width, info->last.configure_request.width);
+      *height = MAX (*height, info->last.configure_request.height);
+    }
 }
 
 static void
@@ -5322,7 +5329,6 @@ gtk_window_unrealize (GtkWidget *widget)
    *
    * Default positioning is reset on unmap, instead of unrealize.
    */
-  priv->need_default_size = TRUE;
   info = gtk_window_get_geometry_info (window, FALSE);
   if (info)
     {
@@ -6522,7 +6528,6 @@ gtk_window_compute_configure_request_size (GtkWindow   *window,
                                            gint        *width,
                                            gint        *height)
 {
-  GtkWindowPrivate *priv = window->priv;
   GtkWindowGeometryInfo *info;
 
   /* Preconditions:
@@ -6531,42 +6536,29 @@ gtk_window_compute_configure_request_size (GtkWindow   *window,
   
   info = gtk_window_get_geometry_info (window, FALSE);
 
-  if (priv->need_default_size)
-    {
-      gtk_window_guess_default_size (window, width, height);
-
-      /* If window is empty so requests 0, default to random nonzero size */
-       if (*width == 0 && *height == 0)
-         {
-           *width = 200;
-           *height = 200;
-         }
-
-       /* Override with default size */
-
-       if (info)
-        {
-          if (info->default_width > 0)
-            *width = info->default_width;
-          if (info->default_height > 0)
-            *height = info->default_height;
-
-          if (info->default_is_geometry)
-            geometry_size_to_pixels (geometry, flags,
-                                     info->default_width > 0 ? width : NULL,
-                                     info->default_height > 0 ? height : NULL);
-         }
-    }
-  else
-    {
-      GtkAllocation allocation;
-
-      gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
-
-      /* Default to keeping current size */
-      *width = allocation.width;
-      *height = allocation.height;
-    }
+  gtk_window_guess_default_size (window, width, height);
+
+  /* If window is empty so requests 0, default to random nonzero size */
+   if (*width == 0 && *height == 0)
+     {
+       *width = 200;
+       *height = 200;
+     }
+
+   /* Override with default size */
+
+   if (info)
+     {
+       if (info->default_width > 0)
+         *width = info->default_width;
+       if (info->default_height > 0)
+         *height = info->default_height;
+
+       if (info->default_is_geometry)
+         geometry_size_to_pixels (geometry, flags,
+                                  info->default_width > 0 ? width : NULL,
+                                  info->default_height > 0 ? height : NULL);
+     }
 
   /* Override any size with gtk_window_resize() values */
   if (info)


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