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



commit d82b5bb6e06b6761bd5d5f3dc9a0762ce55517b4
Author: Iain Lane <iain orangesquash org uk>
Date:   Fri Oct 7 12:24:18 2016 +0100

    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
    e0081be7cd65de6422529d831f7882009ce00a9d, 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

 src/nautilus-canvas-container.c |   27 +++++++++++++++++++++++++--
 1 files changed, 25 insertions(+), 2 deletions(-)
---
diff --git a/src/nautilus-canvas-container.c b/src/nautilus-canvas-container.c
index 26b21e7..67196f4 100644
--- a/src/nautilus-canvas-container.c
+++ b/src/nautilus-canvas-container.c
@@ -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;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]