canvas-container: Unconditionally redo layout

The ::size-allocate handler only redoes its layout if the allocation
had changed and if there isn’t an allocation loop. There used to be a
bug, which caused that to happen in certain cases, but the workarounds
break in GTK+ 4, and it doesn’t seem likely that the bug will manifest
itself again.
This commit is contained in:
Ernestas Kulik 2018-07-19 10:26:00 +03:00
parent 7f01de5e44
commit e9e595ca05
2 changed files with 1 additions and 66 deletions

View file

@ -2714,12 +2714,6 @@ destroy (GtkWidget *object)
container->details->selection_changed_id = 0;
}
if (container->details->size_allocation_count_id != 0)
{
g_source_remove (container->details->size_allocation_count_id);
container->details->size_allocation_count_id = 0;
}
GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->destroy (object);
}
@ -2759,78 +2753,22 @@ finalize (GObject *object)
/* GtkWidget methods. */
static gboolean
clear_size_allocation_count (gpointer data)
{
NautilusCanvasContainer *container;
container = NAUTILUS_CANVAS_CONTAINER (data);
container->details->size_allocation_count_id = 0;
container->details->size_allocation_count = 0;
return FALSE;
}
static void
size_allocate (GtkWidget *widget,
const GtkAllocation *allocation,
int baseline)
{
NautilusCanvasContainer *container;
gboolean need_layout_redone;
GtkAllocation wid_allocation;
GtkWidgetClass *widget_class;
container = NAUTILUS_CANVAS_CONTAINER (widget);
need_layout_redone = !container->details->has_been_allocated;
gtk_widget_get_allocation (widget, &wid_allocation);
if (allocation->width != wid_allocation.width)
{
need_layout_redone = TRUE;
}
if (allocation->height != wid_allocation.height)
{
need_layout_redone = TRUE;
}
/* Under some conditions we can end up in a loop when size allocating.
* This happens when the icons don't fit without a scrollbar, but fits
* when a scrollbar is added (bug #129963 for details).
* We keep track of this looping by increasing a counter in size_allocate
* and clearing it in a high-prio idle (the only way to detect the loop is
* done).
* When we've done at more than two iterations (with/without scrollbar)
* we terminate this looping by not redoing the layout when the width
* is wider than the current one (i.e when removing the scrollbar).
*/
if (container->details->size_allocation_count_id == 0)
{
container->details->size_allocation_count_id =
g_idle_add_full (G_PRIORITY_HIGH,
clear_size_allocation_count,
container, NULL);
}
container->details->size_allocation_count++;
if (container->details->size_allocation_count > 2 &&
allocation->width >= wid_allocation.width)
{
need_layout_redone = FALSE;
}
widget_class = GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class);
widget_class->size_allocate (widget, allocation, baseline);
container->details->has_been_allocated = TRUE;
if (need_layout_redone)
{
redo_layout (container);
}
redo_layout (container);
}
static GtkSizeRequestMode

View file

@ -194,9 +194,6 @@ struct NautilusCanvasContainerDetails {
/* Set to TRUE after first allocation has been done */
gboolean has_been_allocated;
int size_allocation_count;
guint size_allocation_count_id;
/* a11y items used by canvas items */
guint a11y_item_action_idle_handler;
GQueue* a11y_item_action_queue;