discomfitor pushed a commit to branch master.

http://git.enlightenment.org/core/enlightenment.git/commit/?id=7a8ad8080e3d3f5e9445631a1dfd66be2a81d305

commit 7a8ad8080e3d3f5e9445631a1dfd66be2a81d305
Author: Mike Blumenkrantz <[email protected]>
Date:   Thu Dec 5 12:27:46 2013 -0500

    finally fix bug where gadgets on shelves would randomly reorder during drags
    
    ticket #everydamngadgetticketevercreated
---
 ChangeLog          |  4 +++
 NEWS               |  1 +
 src/bin/e_gadcon.c | 82 +++++++++++++++++++++++++++++++++---------------------
 3 files changed, 56 insertions(+), 31 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 45cab25..88725b3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2013-12-04 Mike Blumenkrantz
 
+        * Fixed cases where gadgets would sometimes reorder randomly on shelves
+
+2013-12-04 Mike Blumenkrantz
+
         * Fixed NoDisplay entries in Everything launcher
         * Removed capabilities to alter gadgets in EFM toolbars
 
diff --git a/NEWS b/NEWS
index 9b1aca9..50bd8c6 100644
--- a/NEWS
+++ b/NEWS
@@ -267,3 +267,4 @@ Fixes:
     * Fix unfocusing of disabled widgets
     * Fix crash when activating e's restart from start gadget triggered menu
     * Further improve initial window placement coordinates
+    * Fixed cases where gadgets would sometimes reorder randomly on shelves
diff --git a/src/bin/e_gadcon.c b/src/bin/e_gadcon.c
index 76838a9..979c3b4 100644
--- a/src/bin/e_gadcon.c
+++ b/src/bin/e_gadcon.c
@@ -2320,7 +2320,7 @@ _e_gadcon_client_inject(E_Gadcon *gc, E_Gadcon_Client 
*gcc, int x, int y)
    Eina_List *l;
    E_Gadcon_Client *gcc2;
    Evas_Coord cx = 0, cy = 0, cw = 0, ch = 0;
-   int seq = 1;
+   int i;
 
    /* Check if the gadcon client is in place */
    if (!gcc->hidden)
@@ -2337,44 +2337,64 @@ _e_gadcon_client_inject(E_Gadcon *gc, E_Gadcon_Client 
*gcc, int x, int y)
    /* If x, y is not inside any gadcon client, seq will be 0 and it's position
     * will later be used for placement. */
    gcc->state_info.seq = 0;
-   EINA_LIST_FOREACH(gc->clients, l, gcc2)
-     {
-        if (gcc == gcc2) continue;
-        if (gcc2->hidden) continue;
-        if (gcc2->o_frame)
-          evas_object_geometry_get(gcc2->o_frame, &cx, &cy, &cw, &ch);
-        else if (gcc2->o_base)
-          evas_object_geometry_get(gcc2->o_base, &cx, &cy, &cw, &ch);
-        else return;  /* make clang happy */
-        if (e_gadcon_layout_orientation_get(gc->o_container))
+   for (i = 0; i < 2; i++)
+     {
+        /* two passes:
+         * - find sequence position to inject
+         * - update other gadget sequences
+         */
+        EINA_LIST_FOREACH(gc->clients, l, gcc2)
           {
-             if (E_INSIDE(x, y, cx, cy, cw / 2, ch))
+             if (gcc == gcc2) continue;
+             if (i == 1)
                {
-                  gcc->state_info.seq = seq++;
-                  gcc2->state_info.seq = seq++;
+                  /* on second pass, increment all sequence numbers which are
+                   * >= the injected gadget's sequence to get ordering right
+                   */
+                  if (gcc2->state_info.seq >= gcc->state_info.seq)
+                    gcc2->state_info.seq++;
+                  continue;
                }
-             else if (E_INSIDE(x, y, cx + cw / 2, cy, cw / 2, ch))
+             if (gcc2->hidden) continue;
+             if (gcc2->o_frame)
+               evas_object_geometry_get(gcc2->o_frame, &cx, &cy, &cw, &ch);
+             else if (gcc2->o_base)
+               evas_object_geometry_get(gcc2->o_base, &cx, &cy, &cw, &ch);
+             else return;  /* make clang happy */
+             if (e_gadcon_layout_orientation_get(gc->o_container))
                {
-                  gcc2->state_info.seq = seq++;
-                  gcc->state_info.seq = seq++;
+                  /* inside left half of gadget */
+                  if (E_INSIDE(x, y, cx, cy, cw / 2, ch))
+                    {
+                       /* place before */
+                       gcc->state_info.seq = gcc2->state_info.seq;
+                       break;
+                    }
+                  /* inside right half of gadget */
+                  else if (E_INSIDE(x, y, cx + cw / 2, cy, cw / 2, ch))
+                    {
+                       /* place after */
+                       gcc->state_info.seq = gcc2->state_info.seq + 1;
+                       break;
+                    }
                }
              else
-               gcc2->state_info.seq = seq++;
-          }
-        else
-          {
-             if (E_INSIDE(x, y, cx, cy, cw, ch / 2))
-               {
-                  gcc->state_info.seq = seq++;
-                  gcc2->state_info.seq = seq++;
-               }
-             else if (E_INSIDE(x, y, cx, cy + ch / 2, cw, ch / 2))
                {
-                  gcc2->state_info.seq = seq++;
-                  gcc->state_info.seq = seq++;
+                  /* top half of gadget */
+                  if (E_INSIDE(x, y, cx, cy, cw, ch / 2))
+                    {
+                       /* place before */
+                       gcc->state_info.seq = gcc2->state_info.seq;
+                       break;
+                    }
+                  /* bottom half of gadget */
+                  else if (E_INSIDE(x, y, cx, cy + ch / 2, cw, ch / 2))
+                    {
+                       /* place after */
+                       gcc->state_info.seq = gcc2->state_info.seq + 1;
+                       break;
+                    }
                }
-             else
-               gcc2->state_info.seq = seq++;
           }
      }
 }

-- 


Reply via email to