From 358893aa841c42017160bbe74e74e40c8abc3eb6 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 21 Nov 2021 05:32:20 +0100 Subject: [PATCH 1/3] window: Always clamp to max size When computing the window size, always try to clamp to the max size. This will shrink a window down into a sane size if it was too big before. --- gtk/gtkwindow.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 5173068453..32c9798476 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -4184,20 +4184,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 +4205,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 +4259,6 @@ toplevel_compute_size (GdkToplevel *toplevel, &min_width, &min_height, &width, &height); - if (width < min_width) width = min_width; if (height < min_height) From 822508f33e46947db178ca58a7ec6dcfe29f1dee Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 21 Nov 2021 06:08:06 +0100 Subject: [PATCH 2/3] widget: Clear size request cache on queue_resize() ... and not later. Otherwise future calls to sizing fucntions will reuse an outdated cache and compute wrong values. --- gtk/gtkwidget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 192cc62de3..d6ad33626f 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -3591,6 +3591,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) @@ -10602,7 +10603,6 @@ gtk_widget_ensure_resize (GtkWidget *widget) return; priv->resize_needed = FALSE; - _gtk_size_request_cache_clear (&priv->requests); } void From c990134e49564c8d8a34f1871237227c0fe2e4ef Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 21 Nov 2021 06:10:11 +0100 Subject: [PATCH 3/3] window: Properly distribute size between title and child Otherwise we can end up with a window that's too small in certain corner cases after resizing. --- gtk/gtkwindow.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 32c9798476..9d360a6d4a 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -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);