<commit_before>#include "e.h"
#include "e_mod_main.h"

// FIXME:
//   need choice after add (file, gradient, online source)
//   need delete select mode
//   need after select on delete an ok/cancel if file or "ok to remove whole online source" if online
//   need to make "exchange" wallpapers have a different look
//   bug: animated wp doesn't workon first show
//   need to be able to "type name to search/filter"

typedef struct _Info Info;
typedef struct _Smart_Data Smart_Data;
typedef struct _Item Item;

struct _Info
{
   E_Win *win;
   Evas_Object *bg, *preview, *mini, *button, *box, *sframe, *span;
   char *bg_file;
   int iw, ih;
   Eina_List *dirs;
   char *curdir;
   Eina_Iterator *dir;
   Ecore_Idler *idler;
   int scans;
   int con_num, zone_num, desk_x, desk_y;
   int use_theme_bg;
   int mode;
};

struct _Smart_Data
{
   Eina_List *items;
   Ecore_Idle_Enterer *idle_enter;
   Ecore_Animator *animator;
   Ecore_Timer *seltimer;
   Info *info;
   Evas_Coord x, y, w, h;
   Evas_Coord cx, cy, cw, ch;
   Evas_Coord sx, sy;
   int id_num;
   int sort_num;
   double seltime;
   double selmove;
   Eina_Bool selin : 1;
   Eina_Bool selout : 1;
   Eina_Bool jump2hi : 1;
};

struct _Item
{
   Evas_Object *obj;
   Evas_Coord x, y, w, h;
   const char *file;
   char *sort_id;
   Evas_Object *frame, *image;
   Eina_Bool selected : 1;
   Eina_Bool have_thumb : 1;
   Eina_Bool do_thumb : 1;
   Eina_Bool remote : 1;
   Eina_Bool theme : 1;
   Eina_Bool visible : 1;
   Eina_Bool hilighted : 1;
};

static Info *global_info = NULL;

static void _e_smart_reconfigure(Evas_Object *obj);
static Eina_Bool _e_smart_reconfigure_do(void *data);
static void _thumb_gen(void *data, Evas_Object *obj, void *event_info);
static void _item_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _item_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
static int _sort_cb(const void *d1, const void *d2);
static void _scan(Info *info);

static void
_pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
{
   Smart_Data *sd = evas_object_smart_data_get(obj);

   if (x > (sd->cw - sd->w)) x = sd->cw - sd->w;
   if (y > (sd->ch - sd->h)) y = sd->ch - sd->h;
   if (x < 0) x = 0;
   if (y < 0) y = 0;
   if ((sd->cx == x) && (sd->cy == y)) return;
   sd->cx = x;
   sd->cy = y;
   _e_smart_reconfigure(obj);
}

static void
_pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
{
   Smart_Data *sd = evas_object_smart_data_get(obj);

   if (x) *x = sd->cx;
   if (y) *y = sd->cy;
}

static void
_pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
{
   Smart_Data *sd = evas_object_smart_data_get(obj);

   if (x)
     {
        if (sd->w < sd->cw) *x = sd->cw - sd->w;
        else *x = 0;
     }
   if (y)
     {
        if (sd->h < sd->ch) *y = sd->ch - sd->h;
        else *y = 0;
     }
}

static void
_pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
{
   Smart_Data *sd = evas_object_smart_data_get(obj);

   if (w) *w = sd->cw;
   if (h) *h = sd->ch;
}

static Eina_Bool
_e_smart_reconfigure_do(void *data)
{
   Evas_Object *obj = data;
   Smart_Data *sd = evas_object_smart_data_get(obj);
   Eina_List *l;
   Item *it;
   int iw, redo = 0, changed = 0;
   static int recursion = 0;
   Evas_Coord x, y, xx, yy, ww, hh, mw, mh, ox, oy, dd;
   Evas *evas;

   if (!sd) return ECORE_CALLBACK_CANCEL;
   if (sd->cx > (sd->cw - sd->w)) sd->cx = sd->cw - sd->w;
   if (sd->cy > (sd->ch - sd->h)) sd->cy = sd->ch - sd->h;
   if (sd->cx < 0) sd->cx = 0;
   if (sd->cy < 0) sd->cy = 0;

   iw = sd->w / 4;
   if (iw > (120 * e_scale)) iw = (120 * e_scale);
   else
     {
        if (iw < (60 * e_scale)) iw = (sd->w / 3);
        if (iw < (60 * e_scale)) iw = (sd->w / 2);
        if (iw < (60 * e_scale)) iw = sd->w;
     }
   x = 0;
   y = 0;
   ww = iw;
   hh = (sd->info->ih * iw) / (sd->info->iw);
   mw = mh = 0;

   evas = evas_object_evas_get(obj);
   EINA_LIST_FOREACH(sd->items, l, it)
     {
        if (x > (sd->w - ww))
          {
             x = 0;
             y += hh;
          }
        it->x = x;
        it->y = y;
        it->w = ww;
        it->h = hh;
        if (it->selected)
          {
             sd->sx = it->x + (it->w / 2);
             sd->sy = it->y + (it->h / 2);
          }
        if ((x + ww) > mw) mw = x + ww;
        if ((y + hh) > mh) mh = y + hh;
        x += ww;
     }
   if ((mw != sd->cw) || (mh != sd->ch))
     {
        sd->cw = mw;
        sd->ch = mh;
        if (sd->cx > (sd->cw - sd->w))
          {
             sd->cx = sd->cw - sd->w;
             redo = 1;
          }
        if (sd->cy > (sd->ch - sd->h))
          {
             sd->cy = sd->ch - sd->h;
             redo = 1;
          }
        if (sd->cx < 0)
          {
             sd->cx = 0;
             redo = 1;
          }
        if (sd->cy < 0)
          {
             sd->cy = 0;
             redo = 1;
          }
        if (redo)
	  {
	     recursion = 1;
	     _e_smart_reconfigure_do(obj);
	     recursion = 0;
	  }
        changed = 1;
     }

   ox = 0;
   if (sd->w > sd->cw) ox = (sd->w - sd->cw) / 2;
   oy = 0;
   if (sd->h > sd->ch) oy = (sd->h - sd->ch) / 2;

   EINA_LIST_FOREACH(sd->items, l, it)
     { 
        Evas_Coord dx, dy, vw, vh;

        dx = dy = 0;
        if ((sd->sx >= 0) && (sd->selmove > 0.0)
            
/*            &&
            ((it->x + it->w) > sd->cx) &&
            ((it->x) < (sd->cx + sd->w)) &&
            ((it->y + it->h) > sd->cy) &&
            ((it->y) < (sd->cy + sd->h))
 */
            )
          {
             double a, d;
             int sum = 0;
             char *p;

             // -----0X0+++++
             dx = (it->x + (it->w / 2)) - sd->sx;
             dy = (it->y + (it->h / 2)) - sd->sy;
             if (dx > 0)
               {
                  // |/
                  // +--
                  if (dy < 0)
                    a = -atan(-(double)dy / (double)dx);
                  // +--
                  /* |\ */
                  else
                    a = atan((double)dy / (double)dx);
               }
             else if (dx == 0)
               {
                  //   |
                  //   +
                  if (dy < 0) a = -M_PI / 2;
                  //   +
                  //   |
                  else a = M_PI / 2;
               }
             else
               {
                  //  \|
                  // --+
                  if (dy < 0)
                    a = -M_PI + atan((double)dy / (double)dx);
                  // --+
                  //  /|
                  else
                    a = M_PI - atan(-(double)dy / (double)dx);
               }
             d = sqrt((double)(dx * dx) + (double)(dy * dy));

             sum = 0;
             if (it->file)
               {
                  for (p = (char *)it->file; *p; p++) sum += (int)(*p);
               }
             sum = (sum & 0xff) - 128;
             a = a + ((double)sum / 1024.0);
             xx = sd->sx - sd->cx + ox;
             yy = sd->sy - sd->cy + oy;
             if (xx < (sd->w / 2)) dx = sd->w - xx;
             else dx = xx;
             if (yy < (sd->h / 2)) dy = sd->h - yy;
             else dy = yy;
             dd = dx - d;
             if (dy > dx) dd = dy - d;
             if (dd < 0) dd = 0;
             dy = sin(a) * sd->selmove * (dd * 0.9);
             dx = cos(a) * sd->selmove * (dd * 0.9);
          }
        xx = sd->x - sd->cx + it->x + ox;
        yy = sd->y - sd->cy + it->y + oy;
        evas_output_viewport_get(evas, NULL, NULL, &vw, &vh);
        if (E_INTERSECTS(xx, yy, it->w, it->h, 0, 0, vw, vh))
          {
             if (!it->have_thumb)
               {
                  if (!it->do_thumb)
                    {
                       e_thumb_icon_begin(it->image);
                       it->do_thumb = EINA_TRUE;
                    }
               }
             else
               {
                  if (!it->frame)
                    {
                       it->frame = edje_object_add(evas);
                       if (it->theme)
                         e_theme_edje_object_set(it->frame, "base/theme/widgets",
                                                 "e/conf/wallpaper/main/mini-theme");
                       else if (it->remote)
                         e_theme_edje_object_set(it->frame, "base/theme/widgets",
                                                 "e/conf/wallpaper/main/mini-remote");
                       else
                         e_theme_edje_object_set(it->frame, "base/theme/widgets",
                                                 "e/conf/wallpaper/main/mini");
                       if (it->hilighted)
                         {
                            edje_object_signal_emit(it->frame, "e,state,selected", "e");
                            evas_object_raise(it->frame);
                         }
                       evas_object_event_callback_add(it->frame, EVAS_CALLBACK_MOUSE_DOWN,
                                                      _item_down, it);<commit_msg>E (wallpaper2): No need to fetch viewport size every time we iterate here. Previously, the viewport w/h was being fetched for Every object...silly ;)<commit_after>#include "e.h"
#include "e_mod_main.h"

// FIXME:
//   need choice after add (file, gradient, online source)
//   need delete select mode
//   need after select on delete an ok/cancel if file or "ok to remove whole online source" if online
//   need to make "exchange" wallpapers have a different look
//   bug: animated wp doesn't workon first show
//   need to be able to "type name to search/filter"

typedef struct _Info Info;
typedef struct _Smart_Data Smart_Data;
typedef struct _Item Item;

struct _Info
{
   E_Win *win;
   Evas_Object *bg, *preview, *mini, *button, *box, *sframe, *span;
   char *bg_file;
   int iw, ih;
   Eina_List *dirs;
   char *curdir;
   Eina_Iterator *dir;
   Ecore_Idler *idler;
   int scans;
   int con_num, zone_num, desk_x, desk_y;
   int use_theme_bg;
   int mode;
};

struct _Smart_Data
{
   Eina_List *items;
   Ecore_Idle_Enterer *idle_enter;
   Ecore_Animator *animator;
   Ecore_Timer *seltimer;
   Info *info;
   Evas_Coord x, y, w, h;
   Evas_Coord cx, cy, cw, ch;
   Evas_Coord sx, sy;
   int id_num;
   int sort_num;
   double seltime;
   double selmove;
   Eina_Bool selin : 1;
   Eina_Bool selout : 1;
   Eina_Bool jump2hi : 1;
};

struct _Item
{
   Evas_Object *obj;
   Evas_Coord x, y, w, h;
   const char *file;
   char *sort_id;
   Evas_Object *frame, *image;
   Eina_Bool selected : 1;
   Eina_Bool have_thumb : 1;
   Eina_Bool do_thumb : 1;
   Eina_Bool remote : 1;
   Eina_Bool theme : 1;
   Eina_Bool visible : 1;
   Eina_Bool hilighted : 1;
};

static Info *global_info = NULL;

static void _e_smart_reconfigure(Evas_Object *obj);
static Eina_Bool _e_smart_reconfigure_do(void *data);
static void _thumb_gen(void *data, Evas_Object *obj, void *event_info);
static void _item_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _item_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
static int _sort_cb(const void *d1, const void *d2);
static void _scan(Info *info);

static void
_pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
{
   Smart_Data *sd = evas_object_smart_data_get(obj);

   if (x > (sd->cw - sd->w)) x = sd->cw - sd->w;
   if (y > (sd->ch - sd->h)) y = sd->ch - sd->h;
   if (x < 0) x = 0;
   if (y < 0) y = 0;
   if ((sd->cx == x) && (sd->cy == y)) return;
   sd->cx = x;
   sd->cy = y;
   _e_smart_reconfigure(obj);
}

static void
_pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
{
   Smart_Data *sd = evas_object_smart_data_get(obj);

   if (x) *x = sd->cx;
   if (y) *y = sd->cy;
}

static void
_pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
{
   Smart_Data *sd = evas_object_smart_data_get(obj);

   if (x)
     {
        if (sd->w < sd->cw) *x = sd->cw - sd->w;
        else *x = 0;
     }
   if (y)
     {
        if (sd->h < sd->ch) *y = sd->ch - sd->h;
        else *y = 0;
     }
}

static void
_pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
{
   Smart_Data *sd = evas_object_smart_data_get(obj);

   if (w) *w = sd->cw;
   if (h) *h = sd->ch;
}

static Eina_Bool
_e_smart_reconfigure_do(void *data)
{
   Evas_Object *obj = data;
   Smart_Data *sd = evas_object_smart_data_get(obj);
   Eina_List *l;
   Item *it;
   int iw, redo = 0, changed = 0;
   static int recursion = 0;
   Evas_Coord x, y, xx, yy, ww, hh, mw, mh, ox, oy, dd;
   Evas_Coord vw, vh;
   Evas *evas;

   if (!sd) return ECORE_CALLBACK_CANCEL;
   if (sd->cx > (sd->cw - sd->w)) sd->cx = sd->cw - sd->w;
   if (sd->cy > (sd->ch - sd->h)) sd->cy = sd->ch - sd->h;
   if (sd->cx < 0) sd->cx = 0;
   if (sd->cy < 0) sd->cy = 0;

   iw = sd->w / 4;
   if (iw > (120 * e_scale)) iw = (120 * e_scale);
   else
     {
        if (iw < (60 * e_scale)) iw = (sd->w / 3);
        if (iw < (60 * e_scale)) iw = (sd->w / 2);
        if (iw < (60 * e_scale)) iw = sd->w;
     }
   x = 0;
   y = 0;
   ww = iw;
   hh = (sd->info->ih * iw) / (sd->info->iw);
   mw = mh = 0;

   evas = evas_object_evas_get(obj);
   evas_output_viewport_get(evas, NULL, NULL, &vw, &vh);

   EINA_LIST_FOREACH(sd->items, l, it)
     {
        if (x > (sd->w - ww))
          {
             x = 0;
             y += hh;
          }
        it->x = x;
        it->y = y;
        it->w = ww;
        it->h = hh;
        if (it->selected)
          {
             sd->sx = it->x + (it->w / 2);
             sd->sy = it->y + (it->h / 2);
          }
        if ((x + ww) > mw) mw = x + ww;
        if ((y + hh) > mh) mh = y + hh;
        x += ww;
     }
   if ((mw != sd->cw) || (mh != sd->ch))
     {
        sd->cw = mw;
        sd->ch = mh;
        if (sd->cx > (sd->cw - sd->w))
          {
             sd->cx = sd->cw - sd->w;
             redo = 1;
          }
        if (sd->cy > (sd->ch - sd->h))
          {
             sd->cy = sd->ch - sd->h;
             redo = 1;
          }
        if (sd->cx < 0)
          {
             sd->cx = 0;
             redo = 1;
          }
        if (sd->cy < 0)
          {
             sd->cy = 0;
             redo = 1;
          }
        if (redo)
	  {
	     recursion = 1;
	     _e_smart_reconfigure_do(obj);
	     recursion = 0;
	  }
        changed = 1;
     }

   ox = 0;
   if (sd->w > sd->cw) ox = (sd->w - sd->cw) / 2;
   oy = 0;
   if (sd->h > sd->ch) oy = (sd->h - sd->ch) / 2;

   EINA_LIST_FOREACH(sd->items, l, it)
     { 
        Evas_Coord dx, dy;

        dx = dy = 0;
        if ((sd->sx >= 0) && (sd->selmove > 0.0)
            
/*            &&
            ((it->x + it->w) > sd->cx) &&
            ((it->x) < (sd->cx + sd->w)) &&
            ((it->y + it->h) > sd->cy) &&
            ((it->y) < (sd->cy + sd->h))
 */
            )
          {
             double a, d;
             int sum = 0;
             char *p;

             // -----0X0+++++
             dx = (it->x + (it->w / 2)) - sd->sx;
             dy = (it->y + (it->h / 2)) - sd->sy;
             if (dx > 0)
               {
                  // |/
                  // +--
                  if (dy < 0)
                    a = -atan(-(double)dy / (double)dx);
                  // +--
                  /* |\ */
                  else
                    a = atan((double)dy / (double)dx);
               }
             else if (dx == 0)
               {
                  //   |
                  //   +
                  if (dy < 0) a = -M_PI / 2;
                  //   +
                  //   |
                  else a = M_PI / 2;
               }
             else
               {
                  //  \|
                  // --+
                  if (dy < 0)
                    a = -M_PI + atan((double)dy / (double)dx);
                  // --+
                  //  /|
                  else
                    a = M_PI - atan(-(double)dy / (double)dx);
               }
             d = sqrt((double)(dx * dx) + (double)(dy * dy));

             sum = 0;
             if (it->file)
               {
                  for (p = (char *)it->file; *p; p++) sum += (int)(*p);
               }
             sum = (sum & 0xff) - 128;
             a = a + ((double)sum / 1024.0);
             xx = sd->sx - sd->cx + ox;
             yy = sd->sy - sd->cy + oy;
             if (xx < (sd->w / 2)) dx = sd->w - xx;
             else dx = xx;
             if (yy < (sd->h / 2)) dy = sd->h - yy;
             else dy = yy;
             dd = dx - d;
             if (dy > dx) dd = dy - d;
             if (dd < 0) dd = 0;
             dy = sin(a) * sd->selmove * (dd * 0.9);
             dx = cos(a) * sd->selmove * (dd * 0.9);
          }
        xx = sd->x - sd->cx + it->x + ox;
        yy = sd->y - sd->cy + it->y + oy;
        if (E_INTERSECTS(xx, yy, it->w, it->h, 0, 0, vw, vh))
          {
             if (!it->have_thumb)
               {
                  if (!it->do_thumb)
                    {
                       e_thumb_icon_begin(it->image);
                       it->do_thumb = EINA_TRUE;
                    }
               }
             else
               {
                  if (!it->frame)
                    {
                       it->frame = edje_object_add(evas);
                       if (it->theme)
                         e_theme_edje_object_set(it->frame, "base/theme/widgets",
                                                 "e/conf/wallpaper/main/mini-theme");
                       else if (it->remote)
                         e_theme_edje_object_set(it->frame, "base/theme/widgets",
                                                 "e/conf/wallpaper/main/mini-remote");
                       else
                         e_theme_edje_object_set(it->frame, "base/theme/widgets",
                                                 "e/conf/wallpaper/main/mini");
                       if (it->hilighted)
                         {
                            edje_object_signal_emit(it->frame, "e,state,selected", "e");
                            evas_object_raise(it->frame);
                         }
                       evas_object_event_callback_add(it->frame, EVAS_CALLBACK_MOUSE_DOWN,
                                                      _item_down, it);
{'fraction_non_alphanumeric': 0.15409459163564704, 'fraction_numerical': 0.010783884388000875, 'mean_word_length': 1.2462805852698882, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 329, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6883989', 'n_tokens_mistral': 6984, 'n_tokens_neox': 6613, 'n_words': 1637}