diff --git a/gtk/gtkapplicationwindow.c b/gtk/gtkapplicationwindow.c index 271054b109..541baf6a03 100644 --- a/gtk/gtkapplicationwindow.c +++ b/gtk/gtkapplicationwindow.c @@ -703,13 +703,17 @@ gtk_application_window_real_size_allocate (GtkWidget *widget, if (window->priv->menubar != NULL) { - GtkAllocation menubar_allocation = *allocation; + GtkAllocation menubar_allocation; + GtkAllocation child_allocation; gint menubar_height; GtkWidget *child; - _gtk_window_set_allocation (GTK_WINDOW (widget), allocation); + _gtk_window_set_allocation (GTK_WINDOW (widget), allocation, &child_allocation); + menubar_allocation = child_allocation; - gtk_widget_get_preferred_height_for_width (window->priv->menubar, allocation->width, &menubar_height, NULL); + gtk_widget_get_preferred_height_for_width (window->priv->menubar, + menubar_allocation.width, + &menubar_height, NULL); menubar_allocation.height = menubar_height; gtk_widget_size_allocate (window->priv->menubar, &menubar_allocation); @@ -717,7 +721,6 @@ gtk_application_window_real_size_allocate (GtkWidget *widget, child = gtk_bin_get_child (GTK_BIN (window)); if (child != NULL && gtk_widget_get_visible (child)) { - GtkAllocation child_allocation = *allocation; gint border_width; border_width = gtk_container_get_border_width (GTK_CONTAINER (window)); diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index fe24363fd1..9f9a4d59c2 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -5504,7 +5504,9 @@ set_grip_position (GtkWindow *window) /* _gtk_window_set_allocation: * @window: a #GtkWindow - * @allocation: the new allocation + * @allocation: the original allocation for the window + * @allocation_out: @allocation taking decorations into + * consideration * * This function is like gtk_widget_set_allocation() * but does the necessary extra work to update @@ -5513,13 +5515,22 @@ set_grip_position (GtkWindow *window) * Call this instead of gtk_widget_set_allocation() * when overriding ::size_allocate in a GtkWindow * subclass without chaining up. + * + * The @allocation parameter will be adjusted to + * reflect any internal decorations that the window + * may have. That revised allocation will then be + * returned in the @allocation_out parameter. */ void -_gtk_window_set_allocation (GtkWindow *window, - GtkAllocation *allocation) +_gtk_window_set_allocation (GtkWindow *window, + const GtkAllocation *allocation, + GtkAllocation *allocation_out) { GtkWidget *widget = (GtkWidget *)window; + g_assert (allocation != NULL); + g_assert (allocation_out != NULL); + gtk_widget_set_allocation (widget, allocation); if (gtk_widget_get_realized (widget)) @@ -5539,6 +5550,8 @@ _gtk_window_set_allocation (GtkWindow *window, set_grip_position (window); } } + + *allocation_out = *allocation; } static void @@ -5550,16 +5563,16 @@ gtk_window_size_allocate (GtkWidget *widget, GtkWidget *child; guint border_width; - _gtk_window_set_allocation (window, allocation); + _gtk_window_set_allocation (window, allocation, &child_allocation); child = gtk_bin_get_child (&(window->bin)); if (child && gtk_widget_get_visible (child)) { border_width = gtk_container_get_border_width (GTK_CONTAINER (window)); - child_allocation.x = border_width; - child_allocation.y = border_width; - child_allocation.width = MAX (1, allocation->width - border_width * 2); - child_allocation.height = MAX (1, allocation->height - border_width * 2); + child_allocation.x += border_width; + child_allocation.y += border_width; + child_allocation.width = MAX (1, child_allocation.width - border_width * 2); + child_allocation.height = MAX (1, child_allocation.height - border_width * 2); gtk_widget_size_allocate (child, &child_allocation); } diff --git a/gtk/gtkwindowprivate.h b/gtk/gtkwindowprivate.h index 22f8d57705..8891ca4c4f 100644 --- a/gtk/gtkwindowprivate.h +++ b/gtk/gtkwindowprivate.h @@ -66,8 +66,9 @@ void _gtk_window_get_wmclass (GtkWindow *window, gchar **wmclass_name, gchar **wmclass_class); -void _gtk_window_set_allocation (GtkWindow *window, - GtkAllocation *allocation); +void _gtk_window_set_allocation (GtkWindow *window, + const GtkAllocation *allocation, + GtkAllocation *allocation_out); typedef void (*GtkWindowKeysForeachFunc) (GtkWindow *window, guint keyval,