<commit_before>#include "private.h"

#include <Elementary.h>
#include <stdlib.h>
#include <unistd.h>
#include "sel.h"
#include "config.h"
#include "utils.h"
#include "termio.h"

typedef struct _Sel Sel;
typedef struct _Entry Entry;

struct _Sel
{
   Evas_Object_Smart_Clipped_Data __clipped_data;
   Evas_Object *clip, *o_event;
   Ecore_Animator *anim;
   Ecore_Timer *autozoom_timeout;
   Eina_List *items;
   double t_start, t_total;
   double zoom, zoom0, zoom1;
   double last_cmd;
   double interp;
   double orig_zoom;
   Evas_Coord px, px0, px1;
   Evas_Coord py, py0, py1;
   int w, h;
   struct {
      Evas_Coord x, y;
      Eina_Bool down : 1;
   } down;
   Config *config;
   Eina_Bool select_me : 1;
   Eina_Bool exit_me : 1;
   Eina_Bool exit_on_sel : 1;
   Eina_Bool exit_now : 1;
   Eina_Bool pending_sel : 1;
   Eina_Bool use_px : 1;
};

struct _Entry
{
   Evas_Object *obj, *bg, *termio;
   Eina_Bool selected : 1;
   Eina_Bool selected_before : 1;
   Eina_Bool selected_orig : 1;
   Eina_Bool was_selected : 1;
};

static Evas_Smart *_smart = NULL;
static Evas_Smart_Class _parent_sc = EVAS_SMART_CLASS_INIT_NULL;

static void _smart_calculate(Evas_Object *obj);
static void _transit(Evas_Object *obj, double tim);

static void
_mouse_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
{
   Evas_Event_Mouse_Down *ev = event;
   Sel *sd = evas_object_smart_data_get(data);
   if (!sd) return;
   
   if (sd->down.down) return;
   if (ev->button != 1) return;
   sd->down.x = ev->canvas.x;
   sd->down.y = ev->canvas.y;
   sd->down.down = EINA_TRUE;
}

static void
_mouse_up_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
{
   Evas_Event_Mouse_Down *ev = event;
   Sel *sd = evas_object_smart_data_get(data);
   Evas_Coord dx, dy;
   if (!sd) return;
   
   if (!sd->down.down) return;
   sd->down.down = EINA_FALSE;
   dx = abs(ev->canvas.x - sd->down.x);
   dy = abs(ev->canvas.y - sd->down.y);
   if ((dx <= elm_config_finger_size_get()) &&
       (dy <= elm_config_finger_size_get()))
     {
        Eina_List *l;
        Entry *en;
        Evas_Coord x, y, ox, oy, ow, oh;
        
        x = ev->canvas.x;
        y = ev->canvas.y;
        EINA_LIST_FOREACH(sd->items, l, en)
          {
             evas_object_geometry_get(en->bg, &ox, &oy, &ow, &oh);
             if (ELM_RECTS_INTERSECT(ox, oy, ow, oh, x, y, 1, 1))
               {
                  sel_entry_selected_set(data, en->obj, EINA_FALSE);
                  sd->select_me = EINA_TRUE;
                  sd->exit_me = EINA_FALSE;
                  if (sd->autozoom_timeout)
                    {
                       ecore_timer_del(sd->autozoom_timeout);
                       sd->autozoom_timeout = NULL;
                    }
                  evas_object_smart_callback_call(data, "ending", NULL);
                  sel_zoom(data, 1.0);
                  return;
               }
          }
        evas_object_smart_callback_call(data, "clicked", NULL);
     }
}

static void
_mouse_move_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
{
   Evas_Event_Mouse_Move *ev = event;
   Sel *sd = evas_object_smart_data_get(data);
   if (!sd) return;
   Evas_Coord x = 0, y = 0, w = 0, h = 0, sw, sh;
   int iw, ih;
   
   if ((sd->exit_me) || (sd->exit_now) || (sd->select_me)) return;
   iw = sqrt(eina_list_count(sd->items));
   if (iw < 1) iw = 1;
   ih = (eina_list_count(sd->items) + (iw - 1)) / iw;
   if (ih < 1) ih = 1;
   evas_object_geometry_get(data, &x, &y, &w, &h);
   sw = w * sd->zoom;
   sh = h * sd->zoom;
   if (!sd->down.down)
     {
        if ((w > 0) && (h > 0))
          {
             _transit(data, 0.5);
             sd->px1 = ((ev->cur.canvas.x - x) * ((iw - 1) * sw)) / w;
             sd->py1 = ((ev->cur.canvas.y - y) * ((ih - 1) * sh)) / h;
             sd->use_px = EINA_TRUE;
          }
     }
   else
     {
        // XXX: drag to scroll
     }
}

static Eina_Bool
_autozoom_reset(void *data)
{
   Sel *sd = evas_object_smart_data_get(data);
   if (!sd) return EINA_FALSE;
   sd->autozoom_timeout = NULL;
   sel_zoom(data, sd->orig_zoom);
   return EINA_FALSE;
}

static void
_autozoom(Evas_Object *obj)
{
   Sel *sd = evas_object_smart_data_get(obj);
   double t = ecore_loop_time_get();
   if (!sd) return;
   if ((t - sd->last_cmd) < 0.5)
     {
        sel_zoom(obj, sd->zoom * 0.9);
     }
   sd->last_cmd = t;
   if (sd->autozoom_timeout) ecore_timer_del(sd->autozoom_timeout);
   sd->autozoom_timeout = ecore_timer_add(0.5, _autozoom_reset, obj);
}

void
_key_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
{
   Evas_Event_Key_Down *ev = event;
   Sel *sd = evas_object_smart_data_get(data);<commit_msg>Remove EINA_UNUSED from parameter that is actually used.<commit_after>#include "private.h"

#include <Elementary.h>
#include <stdlib.h>
#include <unistd.h>
#include "sel.h"
#include "config.h"
#include "utils.h"
#include "termio.h"

typedef struct _Sel Sel;
typedef struct _Entry Entry;

struct _Sel
{
   Evas_Object_Smart_Clipped_Data __clipped_data;
   Evas_Object *clip, *o_event;
   Ecore_Animator *anim;
   Ecore_Timer *autozoom_timeout;
   Eina_List *items;
   double t_start, t_total;
   double zoom, zoom0, zoom1;
   double last_cmd;
   double interp;
   double orig_zoom;
   Evas_Coord px, px0, px1;
   Evas_Coord py, py0, py1;
   int w, h;
   struct {
      Evas_Coord x, y;
      Eina_Bool down : 1;
   } down;
   Config *config;
   Eina_Bool select_me : 1;
   Eina_Bool exit_me : 1;
   Eina_Bool exit_on_sel : 1;
   Eina_Bool exit_now : 1;
   Eina_Bool pending_sel : 1;
   Eina_Bool use_px : 1;
};

struct _Entry
{
   Evas_Object *obj, *bg, *termio;
   Eina_Bool selected : 1;
   Eina_Bool selected_before : 1;
   Eina_Bool selected_orig : 1;
   Eina_Bool was_selected : 1;
};

static Evas_Smart *_smart = NULL;
static Evas_Smart_Class _parent_sc = EVAS_SMART_CLASS_INIT_NULL;

static void _smart_calculate(Evas_Object *obj);
static void _transit(Evas_Object *obj, double tim);

static void
_mouse_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
{
   Evas_Event_Mouse_Down *ev = event;
   Sel *sd = evas_object_smart_data_get(data);
   if (!sd) return;
   
   if (sd->down.down) return;
   if (ev->button != 1) return;
   sd->down.x = ev->canvas.x;
   sd->down.y = ev->canvas.y;
   sd->down.down = EINA_TRUE;
}

static void
_mouse_up_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
{
   Evas_Event_Mouse_Down *ev = event;
   Sel *sd = evas_object_smart_data_get(data);
   Evas_Coord dx, dy;
   if (!sd) return;
   
   if (!sd->down.down) return;
   sd->down.down = EINA_FALSE;
   dx = abs(ev->canvas.x - sd->down.x);
   dy = abs(ev->canvas.y - sd->down.y);
   if ((dx <= elm_config_finger_size_get()) &&
       (dy <= elm_config_finger_size_get()))
     {
        Eina_List *l;
        Entry *en;
        Evas_Coord x, y, ox, oy, ow, oh;
        
        x = ev->canvas.x;
        y = ev->canvas.y;
        EINA_LIST_FOREACH(sd->items, l, en)
          {
             evas_object_geometry_get(en->bg, &ox, &oy, &ow, &oh);
             if (ELM_RECTS_INTERSECT(ox, oy, ow, oh, x, y, 1, 1))
               {
                  sel_entry_selected_set(data, en->obj, EINA_FALSE);
                  sd->select_me = EINA_TRUE;
                  sd->exit_me = EINA_FALSE;
                  if (sd->autozoom_timeout)
                    {
                       ecore_timer_del(sd->autozoom_timeout);
                       sd->autozoom_timeout = NULL;
                    }
                  evas_object_smart_callback_call(data, "ending", NULL);
                  sel_zoom(data, 1.0);
                  return;
               }
          }
        evas_object_smart_callback_call(data, "clicked", NULL);
     }
}

static void
_mouse_move_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
{
   Evas_Event_Mouse_Move *ev = event;
   Sel *sd = evas_object_smart_data_get(data);
   if (!sd) return;
   Evas_Coord x = 0, y = 0, w = 0, h = 0, sw, sh;
   int iw, ih;
   
   if ((sd->exit_me) || (sd->exit_now) || (sd->select_me)) return;
   iw = sqrt(eina_list_count(sd->items));
   if (iw < 1) iw = 1;
   ih = (eina_list_count(sd->items) + (iw - 1)) / iw;
   if (ih < 1) ih = 1;
   evas_object_geometry_get(data, &x, &y, &w, &h);
   sw = w * sd->zoom;
   sh = h * sd->zoom;
   if (!sd->down.down)
     {
        if ((w > 0) && (h > 0))
          {
             _transit(data, 0.5);
             sd->px1 = ((ev->cur.canvas.x - x) * ((iw - 1) * sw)) / w;
             sd->py1 = ((ev->cur.canvas.y - y) * ((ih - 1) * sh)) / h;
             sd->use_px = EINA_TRUE;
          }
     }
   else
     {
        // XXX: drag to scroll
     }
}

static Eina_Bool
_autozoom_reset(void *data)
{
   Sel *sd = evas_object_smart_data_get(data);
   if (!sd) return EINA_FALSE;
   sd->autozoom_timeout = NULL;
   sel_zoom(data, sd->orig_zoom);
   return EINA_FALSE;
}

static void
_autozoom(Evas_Object *obj)
{
   Sel *sd = evas_object_smart_data_get(obj);
   double t = ecore_loop_time_get();
   if (!sd) return;
   if ((t - sd->last_cmd) < 0.5)
     {
        sel_zoom(obj, sd->zoom * 0.9);
     }
   sd->last_cmd = t;
   if (sd->autozoom_timeout) ecore_timer_del(sd->autozoom_timeout);
   sd->autozoom_timeout = ecore_timer_add(0.5, _autozoom_reset, obj);
}

void
_key_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event)
{
   Evas_Event_Key_Down *ev = event;
   Sel *sd = evas_object_smart_data_get(data);
{'fraction_non_alphanumeric': 0.13393882451195324, 'fraction_numerical': 0.009395552771688067, 'mean_word_length': 2.491253644314869, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '292770', 'n_tokens_mistral': 3903, 'n_tokens_neox': 3772, 'n_words': 831}