[gtk/wip/otte/for-master: 2/4] window: properly compute desired size




commit 170bc0a8de8fc344cb21b0be2f5230e370131304
Author: Benjamin Otte <otte redhat com>
Date:   Sun Nov 21 01:15:59 2021 +0100

    window: properly compute desired size
    
    Previously, the code did not expand the size properly when a default
    size was already set.
    
    Reftest included.

 gtk/gtkwindow.c                                  | 41 ++++++++++++++----------
 testsuite/reftests/default-size-too-small.ref.ui | 12 +++++++
 testsuite/reftests/default-size-too-small.ui     | 13 ++++++++
 testsuite/reftests/meson.build                   |  2 ++
 4 files changed, 51 insertions(+), 17 deletions(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 6ae7cef9fb..5173068453 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -4165,12 +4165,14 @@ update_realized_window_properties (GtkWindow *window)
 
 static void
 gtk_window_compute_default_size (GtkWindow *window,
+                                 int        cur_width,
+                                 int        cur_height,
                                  int        max_width,
                                  int        max_height,
                                  int       *min_width,
                                  int       *min_height,
-                                 int       *nat_width,
-                                 int       *nat_height)
+                                 int       *width,
+                                 int       *height)
 {
   GtkWidget *widget = GTK_WIDGET (window);
 
@@ -4182,14 +4184,20 @@ gtk_window_compute_default_size (GtkWindow *window,
                           &minimum, &natural,
                           NULL, NULL);
       *min_height = minimum;
-      *nat_height = MAX (minimum, MIN (max_height, natural));
+      if (cur_height > 0)
+        *height = MAX (cur_height, minimum);
+      else
+        *height = MAX (minimum, MIN (max_height, natural));
 
       gtk_widget_measure (widget, GTK_ORIENTATION_HORIZONTAL,
-                          *nat_height,
+                          *height,
                           &minimum, &natural,
                           NULL, NULL);
       *min_width = minimum;
-      *nat_width = MAX (minimum, MIN (max_width, natural));
+      if (cur_width > 0)
+        *width = MAX (cur_width, minimum);
+      else
+        *width = MAX (minimum, MIN (max_width, natural));
     }
   else /* GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH or CONSTANT_SIZE */
     {
@@ -4199,14 +4207,20 @@ gtk_window_compute_default_size (GtkWindow *window,
                           &minimum, &natural,
                           NULL, NULL);
       *min_width = minimum;
-      *nat_width = MAX (minimum, MIN (max_width, natural));
+      if (cur_width > 0)
+        *width = MAX (cur_width, minimum);
+      else
+        *width = MAX (minimum, MIN (max_width, natural));
 
       gtk_widget_measure (widget, GTK_ORIENTATION_VERTICAL,
-                          *nat_width,
+                          *width,
                           &minimum, &natural,
                           NULL, NULL);
       *min_height = minimum;
-      *nat_height = MAX (minimum, MIN (max_height, natural));
+      if (cur_height > 0)
+        *height = MAX (cur_height, minimum);
+      else
+        *height = MAX (minimum, MIN (max_height, natural));
     }
 }
 
@@ -4239,22 +4253,15 @@ toplevel_compute_size (GdkToplevel     *toplevel,
   GtkBorder shadow;
   int bounds_width, bounds_height;
   int min_width, min_height;
-  int nat_width, nat_height;
 
   gdk_toplevel_size_get_bounds (size, &bounds_width, &bounds_height);
 
   gtk_window_compute_default_size (window,
+                                   priv->default_width, priv->default_height,
                                    bounds_width, bounds_height,
                                    &min_width, &min_height,
-                                   &nat_width, &nat_height);
-
-  width = priv->default_width;
-  height = priv->default_height;
+                                   &width, &height);
 
-  if (width <= 0)
-    width = nat_width;
-  if (height <= 0)
-    height = nat_height;
 
   if (width < min_width)
     width = min_width;
diff --git a/testsuite/reftests/default-size-too-small.ref.ui 
b/testsuite/reftests/default-size-too-small.ref.ui
new file mode 100644
index 0000000000..1eaf937c72
--- /dev/null
+++ b/testsuite/reftests/default-size-too-small.ref.ui
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk40">
+  <object class="GtkWindow">
+    <property name="decorated">0</property>
+    <child>
+      <object class="GtkLabel">
+        <property name="label">Hello
+World</property>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/testsuite/reftests/default-size-too-small.ui b/testsuite/reftests/default-size-too-small.ui
new file mode 100644
index 0000000000..fc504de50e
--- /dev/null
+++ b/testsuite/reftests/default-size-too-small.ui
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk40">
+  <object class="GtkWindow">
+    <property name="default-width">4</property>
+    <property name="decorated">0</property>
+    <child>
+      <object class="GtkLabel">
+        <property name="label">Hello World</property>
+        <property name="wrap">True</property>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/testsuite/reftests/meson.build b/testsuite/reftests/meson.build
index 1df038aa22..c87eb278dd 100644
--- a/testsuite/reftests/meson.build
+++ b/testsuite/reftests/meson.build
@@ -266,6 +266,8 @@ testdata = [
   'data-url.css',
   'data-url.ref.ui',
   'data-url.ui',
+  'default-size-too-small.ref.ui',
+  'default-size-too-small.ui',
   'default-size-undecorated.ui',
   'default-size-undecorated.ref.ui',
   'default-size-with-titlebar.ui',


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