This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efm2.

View the commit online.

commit 85c47e264fa464d8e18b8a3246bb996116be7dfb
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
AuthorDate: Thu Jul 20 17:53:30 2023 +0100

    get dnd with custom position to work better and bounds size too
---
 src/efm/efm.c          | 129 ++++++++++++++++++-------------------------------
 src/efm/efm_back_end.c |   2 +
 src/efm/efm_dnd.c      |  66 +++++++++++++++++--------
 3 files changed, 97 insertions(+), 100 deletions(-)

diff --git a/src/efm/efm.c b/src/efm/efm.c
index cdbf8ad..fe8d389 100644
--- a/src/efm/efm.c
+++ b/src/efm/efm.c
@@ -906,8 +906,10 @@ _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
    sd->geom.h = h;
    evas_object_smart_changed(obj);
    evas_object_resize(sd->o_clip, w, h);
-   // if width changed we have to re-flow (relayout) icons
-   if (width_change) sd->relayout = EINA_TRUE;
+   // if width changed we have to re-flow (relayout) icons - unless it's custom
+   // layout where we have fixed  geom per icon
+   if ((width_change) && (sd->config.view_mode != EFM_VIEW_MODE_ICONS_CUSTOM))
+     sd->relayout = EINA_TRUE;
    if (width_change)
      {
         evas_object_resize(sd->o_list_detailed_dummy,
@@ -925,6 +927,25 @@ _cb_canvas_resize(void *data, Evas *e EINA_UNUSED, void *event_info EINA_UNUSED)
    evas_object_smart_changed(obj);
 }
 
+static void
+_layout_bounds_increase(Eina_Rectangle *bounds, Eina_Rectangle *newrect)
+{
+   int x1, y1, x2, y2;
+
+   x1 = bounds->x;
+   y1 = bounds->y;
+   x2 = x1 + bounds->w;
+   y2 = y1 + bounds->h;
+   if (newrect->x < x1) x1 = newrect->x;
+   if (newrect->y < y1) y1 = newrect->y;
+   if ((newrect->x + newrect->w) > x2) x2 = newrect->x + newrect->w;
+   if ((newrect->y + newrect->h) > y2) y2 = newrect->y + newrect->h;
+   bounds->x = x1;
+   bounds->y = y1;
+   bounds->w = x2 - x1;
+   bounds->h = y2 - y1;
+}
+
 static void
 _relayout_icons(Smart_Data *sd)
 { // wall all blocks and icons in blocks and assign them geometry
@@ -950,28 +971,10 @@ _relayout_icons(Smart_Data *sd)
                   x = 0;
                   y += icon->geom.h;
                }
-             if (block->icons == il)
-               { // first icon in block - block bounds == icon geom
-                  block->bounds.x = icon->geom.x;
-                  block->bounds.y = icon->geom.y;
-                  block->bounds.w = icon->geom.w;
-                  block->bounds.h = icon->geom.h;
-               }
-             else
-               { // expand block bounds based on icon geom if it needs to
-                  if (icon->geom.x < block->bounds.x)
-                    block->bounds.x = icon->geom.x;
-                  if (icon->geom.y < block->bounds.y)
-                    block->bounds.y = icon->geom.y;
-                  if ((icon->geom.x + icon->geom.w) >
-                      (block->bounds.x + block->bounds.w))
-                    block->bounds.w = icon->geom.x +
-                    icon->geom.w - block->bounds.x;
-                  if ((icon->geom.y + icon->geom.h) >
-                      (block->bounds.y + block->bounds.h))
-                    block->bounds.h = icon->geom.y +
-                    icon->geom.h - block->bounds.y;
-               }
+             if (block->icons == il) // first icon in block
+               block->bounds = icon->geom;
+             else // expand block bounds based on icon geom
+               _layout_bounds_increase(&block->bounds, &icon->geom);
           }
         // adjust view minw/h if block expands it
         if ((block->bounds.x + block->bounds.w) > minw)
@@ -983,56 +986,38 @@ _relayout_icons(Smart_Data *sd)
    evas_object_size_hint_min_set(sd->o_smart, sd->icon_min_w, minh);
 }
 
+static void
+_icon_custom_position_find(Icon *icon)
+{ // allocate a spot for this icon as we don't have it stored
+   icon->geom.x = rand() % 1000;
+   icon->geom.y = rand() % 1000;
+}
+
 static void
 _relayout_icons_custom(Smart_Data *sd)
 { // wall all blocks and icons in blocks and assign them geometry
    Eina_List *bl, *il;
    Block *block;
    Icon *icon;
-   Evas_Coord x, y, minw, minh;
+   Evas_Coord minw, minh;
 
    // this is a row by row top-left to bottom-right layout
-   x = y = 0;
    minw = minh = 0;
    EINA_LIST_FOREACH(sd->blocks, bl, block)
      {
         EINA_LIST_FOREACH(block->icons, il, icon)
           { // icon is at urrent x,y
-             if (icon->geom.x == -9999)
+             if (icon->geom.w == -9999)
                {
-                  icon->geom.x = rand() % 1000;
-                  icon->geom.y = rand() % 1000;
-               }
-             icon->geom.w = sd->icon_min_w;
-             icon->geom.h = sd->icon_min_h;
-             x += icon->geom.w;
-             if ((x + icon->geom.w) > sd->geom.w)
-               { // if next icon over end of row, start a new row
-                  x = 0;
-                  y += icon->geom.h;
-               }
-             if (block->icons == il)
-               { // first icon in block - block bounds == icon geom
-                  block->bounds.x = icon->geom.x;
-                  block->bounds.y = icon->geom.y;
-                  block->bounds.w = icon->geom.w;
-                  block->bounds.h = icon->geom.h;
-               }
-             else
-               { // expand block bounds based on icon geom if it needs to
-                  if (icon->geom.x < block->bounds.x)
-                    block->bounds.x = icon->geom.x;
-                  if (icon->geom.y < block->bounds.y)
-                    block->bounds.y = icon->geom.y;
-                  if ((icon->geom.x + icon->geom.w) >
-                      (block->bounds.x + block->bounds.w))
-                    block->bounds.w = icon->geom.x +
-                    icon->geom.w - block->bounds.x;
-                  if ((icon->geom.y + icon->geom.h) >
-                      (block->bounds.y + block->bounds.h))
-                    block->bounds.h = icon->geom.y +
-                    icon->geom.h - block->bounds.y;
+                  icon->geom.w = sd->icon_min_w;
+                  icon->geom.h = sd->icon_min_h;
                }
+             if (icon->geom.x == -9999)
+               _icon_custom_position_find(icon);
+             if (block->icons == il) // first icon in block
+               block->bounds = icon->geom;
+             else // expand block bounds based on icon geom
+               _layout_bounds_increase(&block->bounds, &icon->geom);
           }
         // adjust view minw/h if block expands it
         if ((block->bounds.x + block->bounds.w) > minw)
@@ -1067,28 +1052,10 @@ _relayout_list(Smart_Data *sd)
              else
                icon->geom.h = sd->list_min_h;
              y += icon->geom.h;
-             if (block->icons == il)
-               { // first icon in block - block bounds == icon geom
-                  block->bounds.x = icon->geom.x;
-                  block->bounds.y = icon->geom.y;
-                  block->bounds.w = icon->geom.w;
-                  block->bounds.h = icon->geom.h;
-               }
-             else
-               { // expand block bounds based on icon geom if it needs to
-                  if (icon->geom.x < block->bounds.x)
-                    block->bounds.x = icon->geom.x;
-                  if (icon->geom.y < block->bounds.y)
-                    block->bounds.y = icon->geom.y;
-                  if ((icon->geom.x + icon->geom.w) >
-                      (block->bounds.x + block->bounds.w))
-                    block->bounds.w = icon->geom.x +
-                    icon->geom.w - block->bounds.x;
-                  if ((icon->geom.y + icon->geom.h) >
-                      (block->bounds.y + block->bounds.h))
-                    block->bounds.h = icon->geom.y +
-                    icon->geom.h - block->bounds.y;
-               }
+             if (block->icons == il) // first icon in block
+               block->bounds = icon->geom;
+             else // expand block bounds based on icon geom
+               _layout_bounds_increase(&block->bounds, &icon->geom);
           }
         // adjust view minw/h if block expands it
         if (sd->config.view_mode == EFM_VIEW_MODE_LIST_DETAILED)
diff --git a/src/efm/efm_back_end.c b/src/efm/efm_back_end.c
index 992350c..dcb76f5 100644
--- a/src/efm/efm_back_end.c
+++ b/src/efm/efm_back_end.c
@@ -343,6 +343,8 @@ _cb_thread_notify(void *data, Ecore_Thread *th EINA_UNUSED, void *msg)
              // initial "invalid" xy for custom location - meta overrides
              icon->geom.x = -9999;
              icon->geom.y = -9999;
+             icon->geom.w = -9999;
+             icon->geom.h = -9999;
              icon->sd = sd;
              icon->cmd = c;
              icon->changed = EINA_TRUE;
diff --git a/src/efm/efm_dnd.c b/src/efm/efm_dnd.c
index a251689..35ffef1 100644
--- a/src/efm/efm_dnd.c
+++ b/src/efm/efm_dnd.c
@@ -126,8 +126,9 @@ _cb_drop(void *data, Evas_Object *o EINA_UNUSED, Elm_Selection_Data *ev)
 {
    Smart_Data *sd = data;
    char **plist, **p, *esc, *tmp;
-   Eina_List *dropicons;
+   Eina_List *dropicons, *l;
    Icon *icon;
+   int delta_x = 0, delta_y = 0;
 
    if (sd->drop_over) printf("XXX: DND DROP OVER [%s]\n", sd->drop_over->info.file);
    else printf("XXX: DND DROP ...\n");
@@ -136,6 +137,32 @@ _cb_drop(void *data, Evas_Object *o EINA_UNUSED, Elm_Selection_Data *ev)
    memcpy(tmp, ev->data, ev->len);
    tmp[ev->len] = 0;
    plist = eina_str_split(tmp, "\n", -1);
+   for (p = plist; *p != NULL; ++p)
+     {
+        if (**p)
+          {
+             esc = _escape_parse(*p);
+             if (!esc) continue;
+             dropicons = _icons_path_find(esc);
+             free(esc);
+             EINA_LIST_FOREACH(dropicons, l, icon)
+               {
+                  printf("XXX: DROPICON: [%s]\n", icon->info.file);
+                  if (icon->selected)
+                    {
+                       if ((icon->sd == sd) && (icon->drag))
+                         {
+                            printf("    dropicon is %s/%s\n", icon->sd->path, icon->info.file);
+                            delta_x = icon->sd->dnd_x - icon->down_rel_x - icon->geom.x;
+                            delta_y = icon->sd->dnd_y - icon->down_rel_y - icon->geom.y;
+                            icon->drag = EINA_FALSE;
+                            break;
+                         }
+                    }
+               }
+             EINA_LIST_FREE(dropicons, icon);
+          }
+     }
    for (p = plist; *p != NULL; ++p)
      {
         if (**p)
@@ -150,34 +177,35 @@ _cb_drop(void *data, Evas_Object *o EINA_UNUSED, Elm_Selection_Data *ev)
                     {
                        if (icon->selected)
                          {
-                            if ((icon->sd == sd) && (icon->drag))
-                              {
-                                 Eina_Strbuf *buf;
-                                 char str[PATH_MAX];
+                            Eina_Strbuf *buf;
+                            char str[PATH_MAX];
 
-                                 printf("   offset: [%i] - %i %i\n", icon->drag, icon->down_rel_x, icon->down_rel_y);
-                                 // XXX: fix position of all icons correctly based on dnd_x/y
-                                 icon->geom.x = icon->sd->dnd_x - icon->down_rel_x;
-                                 icon->geom.y = icon->sd->dnd_y - icon->down_rel_y;
-                                 buf = cmd_strbuf_new("meta-set");
-                                 // XXX: use strbuf for str
-                                 snprintf(str, sizeof(str), "%s/%s", icon->sd->path, icon->info.file);
-                                 cmd_strbuf_append(buf, "path", str);
-                                 snprintf(str, sizeof(str), "%i,%i", icon->geom.x, icon->geom.y);
-                                 cmd_strbuf_append(buf, "xy", str);
-                                 cmd_strbuf_exe_consume(buf, icon->sd->exe_open);
+                            if ((icon->sd == sd)/*(icon->drag)*/)
+                              {
+                                 icon->geom.x += delta_x;
+                                 icon->geom.y += delta_y;
                               }
                             else
                               {
-                                 icon->geom.x = icon->sd->dnd_x;
-                                 icon->geom.y = icon->sd->dnd_y;
+                                 icon->geom.x = icon->sd->dnd_x - (icon->geom.w / 2);
+                                 icon->geom.y = icon->sd->dnd_y - (icon->geom.h / 2);
                               }
+                            printf("XXX: ->     DROPICON: [%s]  %i   %i\n", icon->info.file, icon->geom.x, icon->geom.y);
+                            buf = cmd_strbuf_new("meta-set");
+                            // XXX: use strbuf for str
+                            snprintf(str, sizeof(str), "%s/%s", icon->sd->path, icon->info.file);
+                            cmd_strbuf_append(buf, "path", str);
+                            snprintf(str, sizeof(str), "%i,%i", icon->geom.x, icon->geom.y);
+                            cmd_strbuf_append(buf, "xy", str);
+                            cmd_strbuf_exe_consume(buf, icon->sd->exe_open);
                          }
                     }
                }
+             free(esc);
           }
      }
-        evas_object_smart_calculate(sd->o_smart);
+   sd->relayout = EINA_TRUE;
+   evas_object_smart_calculate(sd->o_smart);
    free(*plist);
    free(plist);
    free(tmp);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to