window: properly compute desired size
authorBenjamin Otte <otte@redhat.com>
Sun, 21 Nov 2021 00:15:59 +0000 (01:15 +0100)
committerBenjamin Otte <otte@redhat.com>
Sun, 21 Nov 2021 00:31:06 +0000 (01:31 +0100)
Previously, the code did not expand the size properly when a default
size was already set.

Reftest included.

gtk/gtkwindow.c
testsuite/reftests/default-size-too-small.ref.ui [new file with mode: 0644]
testsuite/reftests/default-size-too-small.ui [new file with mode: 0644]
testsuite/reftests/meson.build

index 6ae7cef9fb9b59de590ba93739d2124f6ed7a12d..517306845310ec058f361b69afb1daee41a3442d 100644 (file)
@@ -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 (file)
index 0000000..1eaf937
--- /dev/null
@@ -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 (file)
index 0000000..fc504de
--- /dev/null
@@ -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>
index 1df038aa2280838c00197cdd012c60c77cde2da6..c87eb278dd7514634f8156dbf0453313b2542a1e 100644 (file)
@@ -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',