Merge branch 'wip/otte/for-master' into 'master'

window: Always clamp to max size

See merge request GNOME/gtk!4185
This commit is contained in:
Benjamin Otte
2021-11-21 18:44:26 +00:00
2 changed files with 39 additions and 27 deletions

View File

@@ -3606,6 +3606,7 @@ gtk_widget_queue_resize_internal (GtkWidget *widget)
return;
priv->resize_needed = TRUE;
_gtk_size_request_cache_clear (&priv->requests);
gtk_widget_set_alloc_needed (widget);
if (priv->resize_func)
@@ -10617,7 +10618,6 @@ gtk_widget_ensure_resize (GtkWidget *widget)
return;
priv->resize_needed = FALSE;
_gtk_size_request_cache_clear (&priv->requests);
}
void

View File

@@ -57,6 +57,7 @@
#include "gtkshortcutcontrollerprivate.h"
#include "gtkshortcutmanager.h"
#include "gtkshortcuttrigger.h"
#include "gtksizerequest.h"
#include "gtksnapshot.h"
#include "gtktypebuiltins.h"
#include "gtkwidgetprivate.h"
@@ -618,8 +619,10 @@ gtk_window_measure (GtkWidget *widget,
GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
GtkWidget *child = priv->child;
gboolean has_size_request = gtk_widget_has_size_request (widget);
int title_for_size = for_size;
int title_min_size = 0;
int title_nat_size = 0;
int child_for_size = for_size;
int child_min_size = 0;
int child_nat_size = 0;
@@ -629,17 +632,30 @@ gtk_window_measure (GtkWidget *widget,
gtk_widget_get_visible (priv->title_box) &&
gtk_widget_get_child_visible (priv->title_box))
{
int size = for_size;
if (orientation == GTK_ORIENTATION_HORIZONTAL && for_size >= 0)
gtk_widget_measure (priv->title_box,
GTK_ORIENTATION_VERTICAL,
-1,
NULL, &size,
NULL, NULL);
if (orientation == GTK_ORIENTATION_HORIZONTAL && for_size >= 0 &&
child != NULL && gtk_widget_get_visible (child))
{
GtkRequestedSize sizes[2];
gtk_widget_measure (priv->title_box,
GTK_ORIENTATION_VERTICAL,
-1,
&sizes[0].minimum_size, &sizes[0].natural_size,
NULL, NULL);
gtk_widget_measure (child,
GTK_ORIENTATION_VERTICAL,
-1,
&sizes[1].minimum_size, &sizes[1].natural_size,
NULL, NULL);
for_size -= sizes[0].minimum_size + sizes[1].minimum_size;
for_size = gtk_distribute_natural_allocation (for_size, 2, sizes);
title_for_size = sizes[0].minimum_size;
child_for_size = sizes[1].minimum_size + for_size;
}
gtk_widget_measure (priv->title_box,
orientation,
MAX (size, -1),
title_for_size,
&title_min_size, &title_nat_size,
NULL, NULL);
}
@@ -649,7 +665,7 @@ gtk_window_measure (GtkWidget *widget,
{
gtk_widget_measure (child,
orientation,
MAX (for_size, -1),
child_for_size,
&child_min_size, &child_nat_size,
NULL, NULL);
@@ -4184,20 +4200,18 @@ gtk_window_compute_default_size (GtkWindow *window,
&minimum, &natural,
NULL, NULL);
*min_height = minimum;
if (cur_height > 0)
*height = MAX (cur_height, minimum);
else
*height = MAX (minimum, MIN (max_height, natural));
if (cur_height <= 0)
cur_height = natural;
*height = MAX (minimum, MIN (max_height, cur_height));
gtk_widget_measure (widget, GTK_ORIENTATION_HORIZONTAL,
*height,
&minimum, &natural,
NULL, NULL);
*min_width = minimum;
if (cur_width > 0)
*width = MAX (cur_width, minimum);
else
*width = MAX (minimum, MIN (max_width, natural));
if (cur_width <= 0)
cur_width = natural;
*width = MAX (minimum, MIN (max_width, cur_width));
}
else /* GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH or CONSTANT_SIZE */
{
@@ -4207,20 +4221,19 @@ gtk_window_compute_default_size (GtkWindow *window,
&minimum, &natural,
NULL, NULL);
*min_width = minimum;
if (cur_width > 0)
*width = MAX (cur_width, minimum);
else
*width = MAX (minimum, MIN (max_width, natural));
if (cur_width <= 0)
cur_width = natural;
*width = MAX (minimum, MIN (max_width, cur_width));
gtk_widget_measure (widget, GTK_ORIENTATION_VERTICAL,
*width,
&minimum, &natural,
NULL, NULL);
*min_height = minimum;
if (cur_height > 0)
*height = MAX (cur_height, minimum);
else
*height = MAX (minimum, MIN (max_height, natural));
if (cur_height <= 0)
cur_height = natural;
*height = MAX (minimum, MIN (max_height, cur_height));
}
}
@@ -4262,7 +4275,6 @@ toplevel_compute_size (GdkToplevel *toplevel,
&min_width, &min_height,
&width, &height);
if (width < min_width)
width = min_width;
if (height < min_height)