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

/* TODO
 * - keybinding configuration
 */

#define DRAG_OFF_WINDOW

#define INPUTLEN          256
#define MATCH_LAG         0.15
#define INITIAL_MATCH_LAG 0.3

#if defined (CHECK_TIME) || defined (CHECK_REFS)
#undef DBG
#define DBG(...) ERR(__VA_ARGS__)
#else
#undef DBG
#define DBG(...)
#endif

static Eina_Bool     _evry_cb_desklock(Evry_Window *win, int type EINA_UNUSED, E_Event_Desklock *ev);
static void           _evry_matches_update(Evry_Selector *sel, int async);
static void           _evry_plugin_action(Evry_Selector *sel, int finished);
static void           _evry_plugin_select(Evry_State *s, Evry_Plugin *p);
static void           _evry_plugin_list_insert(Evry_State *s, Evry_Plugin *p);
static int            _evry_backspace(Evry_Selector *sel);
static void           _evry_update(Evry_Selector *sel, int fetch);
static void           _evry_update_text_label(Evry_State *s);
static int            _evry_clear(Evry_Selector *sel);
static Eina_Bool      _evry_cb_update_timer(void *data);

static Evry_State    *_evry_state_new(Evry_Selector *sel, Eina_List *plugins);
static void           _evry_state_pop(Evry_Selector *sel, int immediate);
static void           _evry_state_clear(Evry_Window *win);
static void           _evry_hide_func(Evry_Window *win, int finished);

static Evry_Selector *_evry_selector_new(Evry_Window *win, int type);
static void           _evry_selector_free(Evry_Selector *sel);
static void           _evry_selector_activate(Evry_Selector *sel, int slide);
static void           _evry_selector_update(Evry_Selector *sel);
static int            _evry_selector_plugins_get(Evry_Selector *sel, Evry_Item *it, const char *plugin_name);
static void           _evry_selector_update_actions(Evry_Selector *sel);
static void           _evry_selector_item_update(Evry_Selector *sel);
static void           _evry_selector_item_clear(Evry_Selector *sel);
static void           _evry_selector_label_set(Evry_Selector *sel, const char *part, const char *label);
static void           _evry_selector_signal_emit(Evry_Selector *sel, const char *msg);
static int            _evry_selectors_shift(Evry_Window *win, int dir);
static int            _evry_selectors_switch(Evry_Window *win, int dir);

static Evry_Window   *_evry_window_new(E_Zone *zone, E_Zone_Edge edge);
static void           _evry_cb_win_delete(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED);
static void           _evry_window_free(Evry_Window *win);
static void           _evry_list_win_show(Evry_Window *win);
static void           _evry_list_win_hide(Evry_Window *win);
static void           _evry_list_win_update(Evry_State *s);

static int            _evry_view_create(Evry_State *s);
static void           _evry_view_clear(Evry_State *s);
static int            _evry_view_update(Evry_Window *win, Evry_State *s);
static int            _evry_view_key_press(Evry_State *s, Ecore_Event_Key *ev);
static void           _evry_view_show(Evry_Window *win, Evry_View *v, int slide);
static void           _evry_view_hide(Evry_Window *win, Evry_View *v, int slide);

static void           _evry_item_desel(Evry_State *s);
static void           _evry_item_sel(Evry_State *s, Evry_Item *it);

static void           _evry_cb_show(Evry_Window *win, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED);
static Eina_Bool      _evry_cb_key_down(void *data, int type, void *event);
static Eina_Bool      _evry_cb_selection_notify(void *data, int type, void *event);
static Eina_Bool      _evry_cb_mouse(void *data, int type, void *event);

static Eina_Bool      _evry_delay_hide_timer(void *data);

static Eina_List *windows = NULL;

#ifdef CHECK_TIME
double _evry_time;
#endif

#ifdef CHECK_REFS
static int _item_cnt = 0;
Eina_List *_refd = NULL;
#endif

#define SUBJ_SEL win->selectors[0]
#define ACTN_SEL win->selectors[1]
#define OBJ_SEL  win->selectors[2]
#define CUR_SEL  win->selector

int
evry_init(void)
{
   return 1;
}

int
evry_shutdown(void)
{
   while (windows)
     evry_hide(windows->data, 0);

   return 1;
}

static int
_evry_aggregator_fetch(Evry_State *s)
{
   Eina_List *l;

   if (!s)
     {
        ERR("no state");
        return 0;
     }

   if (s->aggregator->fetch(s->aggregator, s->input))
     {
        l = eina_list_data_find_list(s->cur_plugins, s->aggregator);

        if (!l)
          s->cur_plugins = eina_list_prepend(s->cur_plugins, s->aggregator);
        else
          s->cur_plugins = eina_list_promote_list(s->cur_plugins, l);

        return 1;
     }

   s->cur_plugins = eina_list_remove(s->cur_plugins, s->aggregator);

   return 1;
}

static Eina_Bool
_evry_cb_item_changed(EINA_UNUSED void *data, EINA_UNUSED int type, void *event)
{
   Evry_Event_Item_Changed *ev = event;
   Evry_Selector *sel;
   Evry_Item *it = ev->item;

   if (!it || !it->plugin || !it->plugin->state)
     return ECORE_CALLBACK_PASS_ON;

   sel = it->plugin->state->selector;

   if (sel->state && sel->state->cur_item == it)
     {
        _evry_selector_update(sel);
     }

   return ECORE_CALLBACK_PASS_ON;
}

Evry_Window *
evry_show(E_Zone *zone, E_Zone_Edge edge, const char *params, Eina_Bool popup)
{
   Evry_Window *win;
   Evry_Selector *sel;

#ifdef CHECK_TIME
   _evry_time = ecore_time_get();
   DBG("_____evry_show______");
#endif

   E_OBJECT_CHECK_RETURN(zone, 0);
   E_OBJECT_TYPE_CHECK_RETURN(zone, E_ZONE_TYPE, 0);

   if (popup)
     {
        // only one popup please
        Eina_List *l;
        EINA_LIST_FOREACH(windows, l, win)
          if (win->grab)
            return NULL;
     }
   
   if (!(win = _evry_window_new(zone, edge)))
     return NULL;

   if (popup)
     {
        E_Client *ec;

        ecore_evas_name_class_set(e_win_ee_get(win->ewin), "E", "everything");

        evas_object_show(win->ewin);
        ec = e_win_client_get(win->ewin);
        if (ec)
          {
#ifndef HAVE_WAYLAND_ONLY
             if (e_comp->comp_type == E_PIXMAP_TYPE_X)
               ecore_x_netwm_window_type_set(elm_win_window_id_get(win->ewin),
                                             ECORE_X_WINDOW_TYPE_UTILITY);
#endif
             ec->netwm.state.skip_taskbar = 1;
             EC_CHANGED(ec);
          }

        win->grab = 1;
     }

   evry_history_load();

   if (params)
     win->plugin_dedicated = EINA_TRUE;

   win->sel_list = E_NEW(Evry_Selector *, 4);
   win->sel_list[3] = NULL;
   win->selectors = win->sel_list;
   _evry_selector_new(win, EVRY_PLUGIN_SUBJECT);
   _evry_selector_new(win, EVRY_PLUGIN_ACTION);
   _evry_selector_new(win, EVRY_PLUGIN_OBJECT);

   E_LIST_HANDLER_APPEND(win->handlers, ECORE_EVENT_KEY_DOWN, _evry_cb_key_down, win);
#ifndef HAVE_WAYLAND_ONLY
   if (e_comp->comp_type == E_PIXMAP_TYPE_X)
     E_LIST_HANDLER_APPEND(win->handlers, ECORE_X_EVENT_SELECTION_NOTIFY, _evry_cb_selection_notify, win);
#endif
   evas_object_event_callback_add(e_win_client_get(win->ewin)->frame, EVAS_CALLBACK_SHOW, (Evas_Object_Event_Cb)_evry_cb_show, win);

   E_LIST_HANDLER_APPEND(win->handlers, EVRY_EVENT_ITEM_CHANGED, _evry_cb_item_changed, win);
<commit_msg>hide evry on focus-out<commit_after>#include "e.h"
#include "e_mod_main.h"

/* TODO
 * - keybinding configuration
 */

#define DRAG_OFF_WINDOW

#define INPUTLEN          256
#define MATCH_LAG         0.15
#define INITIAL_MATCH_LAG 0.3

#if defined (CHECK_TIME) || defined (CHECK_REFS)
#undef DBG
#define DBG(...) ERR(__VA_ARGS__)
#else
#undef DBG
#define DBG(...)
#endif

static Eina_Bool     _evry_cb_desklock(Evry_Window *win, int type EINA_UNUSED, E_Event_Desklock *ev);
static void           _evry_matches_update(Evry_Selector *sel, int async);
static void           _evry_plugin_action(Evry_Selector *sel, int finished);
static void           _evry_plugin_select(Evry_State *s, Evry_Plugin *p);
static void           _evry_plugin_list_insert(Evry_State *s, Evry_Plugin *p);
static int            _evry_backspace(Evry_Selector *sel);
static void           _evry_update(Evry_Selector *sel, int fetch);
static void           _evry_update_text_label(Evry_State *s);
static int            _evry_clear(Evry_Selector *sel);
static Eina_Bool      _evry_cb_update_timer(void *data);

static Evry_State    *_evry_state_new(Evry_Selector *sel, Eina_List *plugins);
static void           _evry_state_pop(Evry_Selector *sel, int immediate);
static void           _evry_state_clear(Evry_Window *win);
static void           _evry_hide_func(Evry_Window *win, int finished);

static Evry_Selector *_evry_selector_new(Evry_Window *win, int type);
static void           _evry_selector_free(Evry_Selector *sel);
static void           _evry_selector_activate(Evry_Selector *sel, int slide);
static void           _evry_selector_update(Evry_Selector *sel);
static int            _evry_selector_plugins_get(Evry_Selector *sel, Evry_Item *it, const char *plugin_name);
static void           _evry_selector_update_actions(Evry_Selector *sel);
static void           _evry_selector_item_update(Evry_Selector *sel);
static void           _evry_selector_item_clear(Evry_Selector *sel);
static void           _evry_selector_label_set(Evry_Selector *sel, const char *part, const char *label);
static void           _evry_selector_signal_emit(Evry_Selector *sel, const char *msg);
static int            _evry_selectors_shift(Evry_Window *win, int dir);
static int            _evry_selectors_switch(Evry_Window *win, int dir);

static Evry_Window   *_evry_window_new(E_Zone *zone, E_Zone_Edge edge);
static void           _evry_cb_win_delete(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED);
static void           _evry_window_free(Evry_Window *win);
static void           _evry_list_win_show(Evry_Window *win);
static void           _evry_list_win_hide(Evry_Window *win);
static void           _evry_list_win_update(Evry_State *s);

static int            _evry_view_create(Evry_State *s);
static void           _evry_view_clear(Evry_State *s);
static int            _evry_view_update(Evry_Window *win, Evry_State *s);
static int            _evry_view_key_press(Evry_State *s, Ecore_Event_Key *ev);
static void           _evry_view_show(Evry_Window *win, Evry_View *v, int slide);
static void           _evry_view_hide(Evry_Window *win, Evry_View *v, int slide);

static void           _evry_item_desel(Evry_State *s);
static void           _evry_item_sel(Evry_State *s, Evry_Item *it);

static void           _evry_cb_show(Evry_Window *win, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED);
static Eina_Bool      _evry_cb_key_down(void *data, int type, void *event);
static Eina_Bool      _evry_cb_selection_notify(void *data, int type, void *event);
static Eina_Bool      _evry_cb_mouse(void *data, int type, void *event);

static Eina_Bool      _evry_delay_hide_timer(void *data);

static Eina_List *windows = NULL;

#ifdef CHECK_TIME
double _evry_time;
#endif

#ifdef CHECK_REFS
static int _item_cnt = 0;
Eina_List *_refd = NULL;
#endif

#define SUBJ_SEL win->selectors[0]
#define ACTN_SEL win->selectors[1]
#define OBJ_SEL  win->selectors[2]
#define CUR_SEL  win->selector

int
evry_init(void)
{
   return 1;
}

int
evry_shutdown(void)
{
   while (windows)
     evry_hide(windows->data, 0);

   return 1;
}

static int
_evry_aggregator_fetch(Evry_State *s)
{
   Eina_List *l;

   if (!s)
     {
        ERR("no state");
        return 0;
     }

   if (s->aggregator->fetch(s->aggregator, s->input))
     {
        l = eina_list_data_find_list(s->cur_plugins, s->aggregator);

        if (!l)
          s->cur_plugins = eina_list_prepend(s->cur_plugins, s->aggregator);
        else
          s->cur_plugins = eina_list_promote_list(s->cur_plugins, l);

        return 1;
     }

   s->cur_plugins = eina_list_remove(s->cur_plugins, s->aggregator);

   return 1;
}

static Eina_Bool
_evry_cb_item_changed(EINA_UNUSED void *data, EINA_UNUSED int type, void *event)
{
   Evry_Event_Item_Changed *ev = event;
   Evry_Selector *sel;
   Evry_Item *it = ev->item;

   if (!it || !it->plugin || !it->plugin->state)
     return ECORE_CALLBACK_PASS_ON;

   sel = it->plugin->state->selector;

   if (sel->state && sel->state->cur_item == it)
     {
        _evry_selector_update(sel);
     }

   return ECORE_CALLBACK_PASS_ON;
}

static void
_evry_focus_out(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Evry_Window *win = data;
   E_Client *ec;

   if (!win->grab) return;

   ec = e_win_client_get(win->ewin);
   if (ec && (!e_object_is_del(E_OBJECT(ec))))
     evry_hide(win, 0);
}

Evry_Window *
evry_show(E_Zone *zone, E_Zone_Edge edge, const char *params, Eina_Bool popup)
{
   Evry_Window *win;
   Evry_Selector *sel;

#ifdef CHECK_TIME
   _evry_time = ecore_time_get();
   DBG("_____evry_show______");
#endif

   E_OBJECT_CHECK_RETURN(zone, 0);
   E_OBJECT_TYPE_CHECK_RETURN(zone, E_ZONE_TYPE, 0);

   if (popup)
     {
        // only one popup please
        Eina_List *l;
        EINA_LIST_FOREACH(windows, l, win)
          if (win->grab)
            return NULL;
     }
   
   if (!(win = _evry_window_new(zone, edge)))
     return NULL;

   if (popup)
     {
        E_Client *ec;

        ecore_evas_name_class_set(e_win_ee_get(win->ewin), "E", "everything");

        evas_object_show(win->ewin);
        ec = e_win_client_get(win->ewin);
        if (ec)
          {
#ifndef HAVE_WAYLAND_ONLY
             if (e_comp->comp_type == E_PIXMAP_TYPE_X)
               ecore_x_netwm_window_type_set(elm_win_window_id_get(win->ewin),
                                             ECORE_X_WINDOW_TYPE_UTILITY);
#endif
             ec->netwm.state.skip_taskbar = 1;
             EC_CHANGED(ec);
          }

        win->grab = 1;
        evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_FOCUS_OUT, _evry_focus_out, win);
     }

   evry_history_load();

   if (params)
     win->plugin_dedicated = EINA_TRUE;

   win->sel_list = E_NEW(Evry_Selector *, 4);
   win->sel_list[3] = NULL;
   win->selectors = win->sel_list;
   _evry_selector_new(win, EVRY_PLUGIN_SUBJECT);
   _evry_selector_new(win, EVRY_PLUGIN_ACTION);
   _evry_selector_new(win, EVRY_PLUGIN_OBJECT);

   E_LIST_HANDLER_APPEND(win->handlers, ECORE_EVENT_KEY_DOWN, _evry_cb_key_down, win);
#ifndef HAVE_WAYLAND_ONLY
   if (e_comp->comp_type == E_PIXMAP_TYPE_X)
     E_LIST_HANDLER_APPEND(win->handlers, ECORE_X_EVENT_SELECTION_NOTIFY, _evry_cb_selection_notify, win);
#endif
   evas_object_event_callback_add(e_win_client_get(win->ewin)->frame, EVAS_CALLBACK_SHOW, (Evas_Object_Event_Cb)_evry_cb_show, win);

   E_LIST_HANDLER_APPEND(win->handlers, EVRY_EVENT_ITEM_CHANGED, _evry_cb_item_changed, win);

{'fraction_non_alphanumeric': 0.09718357651849338, 'fraction_numerical': 0.00332541567695962, 'mean_word_length': 3.5369458128078817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 102, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5370099', 'n_tokens_mistral': 5526, 'n_tokens_neox': 5406, 'n_words': 1083}