Commit d82b5bb6 authored by Iain Lane's avatar Iain Lane Committed by Carlos Soriano Sánchez

nautilus-canvas: Don't lay down desktop icons if we haven't been allocated size yet

Sometimes we were trying to lay down icons before size_allocate had been
run. When this has happened, gtk_widget_get_allocation returns 1×1 as
our size. This messes up the algorithm and causes icons to be
overlapping on the canvas.

This case happens when using Nautilus as the desktop in early-startup
(e.g. from its XDG autostart file). It can happen that we have read the
desktop files before the allocation has happened.

We fix this by noticing if we're called before size_allocate and then
deferring icon layout until later on, after size_allocate has happened.

This behaviour was introduced in commit
e0081be7, which sorts and freezes the
desktop in early-startup.

https://bugs.launchpad.net/ubuntu/+source/nautilus/+bug/1611955

https://bugzilla.gnome.org/show_bug.cgi?id=765601
parent 47d77924
......@@ -1432,6 +1432,9 @@ lay_down_icons_horizontal (NautilusCanvasContainer *container,
g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
/* We can't get the right allocation if the size hasn't been allocated yet */
g_return_if_fail (container->details->has_been_allocated);
if (icons == NULL)
{
return;
......@@ -1938,6 +1941,9 @@ lay_down_icons_vertical_desktop (NautilusCanvasContainer *container,
EelDRect icon_rect;
GtkAllocation allocation;
/* We can't get the right allocation if the size hasn't been allocated yet */
g_return_if_fail (container->details->has_been_allocated);
/* Get container dimensions */
gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
height = CANVAS_HEIGHT (container, allocation);
......@@ -2126,7 +2132,6 @@ lay_down_icons_vertical_desktop (NautilusCanvasContainer *container,
nautilus_canvas_container_freeze_icon_positions (container);
}
static void
lay_down_icons (NautilusCanvasContainer *container,
GList *icons,
......@@ -2218,7 +2223,13 @@ static void
redo_layout (NautilusCanvasContainer *container)
{
unschedule_redo_layout (container);
redo_layout_internal (container);
/* We can't lay out if the size hasn't been allocated yet; wait for it to
* be and then we will be called again from size_allocate ()
*/
if (container->details->has_been_allocated)
{
redo_layout_internal (container);
}
}
static void
......@@ -7836,6 +7847,18 @@ nautilus_canvas_container_freeze_icon_positions (NautilusCanvasContainer *contai
NautilusCanvasIcon *icon;
NautilusCanvasPosition position;
/* This early-exit avoids freezing the icons before they have been properly
* positioned, since we won't re-layout if auto_layout is FALSE.
*
* The container will freeze the icons after it lays them out once we've
* been allocated (e.g. in lay_out_icons_vertical_desktop).
*/
if (!container->details->has_been_allocated)
{
g_debug ("Not freezing icon positions yet; we haven't been allocated");
return;
}
changed = container->details->auto_layout;
container->details->auto_layout = FALSE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment