[SF#1028] Fix endless loop in desktop items placement in some corner cases.
authorAndriy Grytsenko <andrej@rep.kiev.ua>
Fri, 9 Dec 2016 22:29:21 +0000 (00:29 +0200)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Fri, 9 Dec 2016 22:37:06 +0000 (00:37 +0200)
Calculations of next item position were wrong and test
if free space is enough for item was wrong too.

NEWS
src/desktop.c

diff --git a/NEWS b/NEWS
index 808e72f..22e6258 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,8 @@
 
 * Fixed unwanted unselection of items when right-clicked the desktop.
 
+* Fixed endless loop in desktop items placement in some corner cases.
+
 
 Changes on 1.2.4 since 1.2.3:
 
index 2458330..4ec77b9 100644 (file)
@@ -1739,17 +1739,18 @@ _next_position:
                 item->area.x = self->working_area.x + x;
                 item->area.y = self->working_area.y + y;
                 calc_item_size(self, item, icon);
-                while (self->working_area.y + y < item->area.y + item->area.height)
-                    y += self->cell_h;
-                if(y > bottom)
+                /* check if item does not fit into space that left */
+                if (item->area.y + item->area.height > bottom && y > self->ymargin)
                 {
                     x += self->cell_w;
                     y = self->ymargin;
+                    goto _next_position;
                 }
+                /* prepare position for next item */
+                while (self->working_area.y + y < item->area.y + item->area.height)
+                    y += self->cell_h;
                 /* check if this position is occupied by a fixed item */
-                /* or its height does not fit into space that left */
-                if(item->area.y + item->area.height > bottom ||
-                   is_pos_occupied(self, item))
+                if(is_pos_occupied(self, item))
                     goto _next_position;
             }
             if(icon)
@@ -1773,17 +1774,18 @@ _next_position_rtl:
                 item->area.x = self->working_area.x + x;
                 item->area.y = self->working_area.y + y;
                 calc_item_size(self, item, icon);
-                while (self->working_area.y + y < item->area.y + item->area.height)
-                    y += self->cell_h;
-                if(y > bottom)
+                /* check if item does not fit into space that left */
+                if (item->area.y + item->area.height > bottom && y > self->ymargin)
                 {
                     x -= self->cell_w;
                     y = self->ymargin;
+                    goto _next_position_rtl;
                 }
+                /* prepare position for next item */
+                while (self->working_area.y + y < item->area.y + item->area.height)
+                    y += self->cell_h;
                 /* check if this position is occupied by a fixed item */
-                /* or its height does not fit into space that left */
-                if(item->area.y + item->area.height > bottom ||
-                   is_pos_occupied(self, item))
+                if(is_pos_occupied(self, item))
                     goto _next_position_rtl;
             }
             if(icon)