'everythin' module:

- added initial version of calculator frontend (only bc for now)
  - return without candidate selected adds current result to the history
  - return on candidate puts result in clipboard
- scrolling for the plugin selector tabs
- fix segv when popping a state without a selected candidate   


SVN revision: 41242
This commit is contained in:
Hannes Janetzek 2009-07-03 13:37:54 +00:00
parent d96d336352
commit e307632c59
12 changed files with 368 additions and 62 deletions

View File

@ -26,6 +26,7 @@ module_la_SOURCES = e_mod_main.c \
evry_plug_dir_browse.c \
evry_plug_apps.c \
evry_plug_tracker.c \
evry_plug_calc.c \
evry_plug_border.c \
evry_plug_border_act.c

View File

@ -76,6 +76,7 @@ e_modapi_init(E_Module *m)
evry_plug_tracker_init();
evry_plug_border_init();
evry_plug_border_act_init();
evry_plug_calc_init();
/* add module supplied action */
act = e_action_add("everything");
@ -116,6 +117,7 @@ e_modapi_shutdown(E_Module *m)
evry_plug_tracker_shutdown();
evry_plug_border_shutdown();
evry_plug_border_act_shutdown();
evry_plug_calc_shutdown();
evry_shutdown();
conf_module = NULL;
@ -151,6 +153,9 @@ _e_mod_action_exebuf_cb(E_Object *obj, const char *params)
zone = e_util_zone_current_get(e_manager_current_get());
}
if (!zone) zone = e_util_zone_current_get(e_manager_current_get());
printf("zone %d %d\n", zone->x, zone->y);
if (zone) evry_show(zone);
}

View File

@ -63,6 +63,9 @@ EAPI int evry_plug_tracker_shutdown(void);
EAPI int evry_plug_dir_browse_init(void);
EAPI int evry_plug_dir_browse_shutdown(void);
EAPI int evry_plug_calc_init(void);
EAPI int evry_plug_calc_shutdown(void);
extern Config *evry_conf;
#endif

View File

@ -24,6 +24,12 @@ struct _Evry_State
const char *request_type;
Eina_Bool initial;
/* this is for the case when the current plugin was not selected
manually and a higher priority (async) plugin retrieves
candidates, the higher priority plugin is made current */
Eina_Bool plugin_auto_selected;
};
static int _evry_cb_key_down(void *data, int type, void *event);
@ -46,6 +52,7 @@ static void _evry_item_prev(void);
static void _evry_plugin_next(void);
static void _evry_plugin_prev(void);
static void _evry_scroll_to(int i);
static void _evry_tab_scroll_to(Evry_Plugin *p);
static void _evry_item_desel(Evry_Item *it);
static void _evry_item_sel(Evry_Item *it);
static void _evry_action(int finished);
@ -55,7 +62,7 @@ static int _evry_animator(void *data);
static int _evry_scroll_timer(void *data);
static int _evry_push_state(void);
static int _evry_pop_state(void);
static void _evry_plugin_selector_append(Evry_Plugin *p);
static void _evry_plugin_selector_show(Evry_Plugin *p);
static int _evry_cb_plugin_sort(const void *data1, const void *data2);
static int _evry_plug_act_select_init(void);
@ -282,30 +289,44 @@ evry_hide(void)
EAPI void
evry_plugin_async_update(Evry_Plugin *p, int state)
evry_plugin_async_update(Evry_Plugin *p, int action)
{
Evry_State *s;
if (!popup) return;
s = cur_state;
if (!eina_list_data_find(s->cur_plugins, p))
if (action == 1)
{
s->cur_plugins = eina_list_append(s->cur_plugins, p);
_evry_plugin_selector_append(p);
}
else
{
char buf[64];
snprintf(buf, 64, "%s (%d)", p->name, eina_list_count(p->items));
edje_object_part_text_set(p->tab, "e.text.label", buf);
}
if (!eina_list_data_find(s->cur_plugins, p))
{
s->cur_plugins = eina_list_append(s->cur_plugins, p);
s->cur_plugins = eina_list_sort(s->cur_plugins,
eina_list_count(s->cur_plugins),
_evry_cb_plugin_sort);
_evry_plugin_selector_show(p);
}
else
{
char buf[64];
snprintf(buf, 64, "%s (%d)", p->name, eina_list_count(p->items));
edje_object_part_text_set(p->tab, "e.text.label", buf);
}
if (!s->cur_plugin && s->cur_plugins)
if ((!s->cur_plugin && s->cur_plugins) || (s->cur_plugin == p) ||
(s->plugin_auto_selected && (s->cur_plugin->prio > p->prio)))
{
if (!s->cur_plugin)
s->plugin_auto_selected = 1;
_evry_list_clear();
_evry_show_items(s->cur_plugins->data);
}
}
else if ((action == 0) && (s->cur_plugin == p))
{
_evry_list_clear();
_evry_show_items(s->cur_plugins->data);
}
}
@ -402,6 +423,8 @@ _evry_push_state(void)
s->plugins = list;
s->cur_plugins = NULL;
s->sel_item = NULL;
s->plugin_auto_selected = 1;
if (cur_state)
{
s->request_type = cur_state->request_type;
@ -493,7 +516,7 @@ _evry_pop_state(void)
if (it)
{
_evry_item_desel(s->sel_item);
if (s->sel_item) _evry_item_desel(s->sel_item);
s->sel_item = it;
_evry_item_sel(s->sel_item);
_evry_scroll_to(i);
@ -791,6 +814,7 @@ _evry_action(int finished)
}
else if (s->cur_action)
{
/* */
if (s->sel_item && (!strcmp(s->cur_plugin->type_out, s->request_type)))
{
s->cur_action->thing2 = s->sel_item;
@ -799,12 +823,20 @@ _evry_action(int finished)
}
else if (s->cur_plugin && (s->sel_item || s->input))
{
if (!s->cur_plugin->action ||
!s->cur_plugin->action(s->sel_item, s->input))
/* XXX use flags for return values */
int ret = 0;
if (s->cur_plugin->action)
{
ret = s->cur_plugin->action(s->sel_item, s->input);
}
if (ret == EVRY_ACTION_OTHER)
{
_evry_push_state();
finished = 0;
}
else if (ret == EVRY_ACTION_CONTINUE)
finished = 0;
}
else if (s->initial)
e_exec(popup->zone, NULL, s->input, NULL, NULL /* "everything" */);
@ -872,14 +904,16 @@ _evry_show_items(Evry_Plugin *p)
/* TODO add option */
if (!s->sel_item && p->items)
{
s->sel_item = p->items->data;
_evry_item_sel(s->sel_item);
_evry_scroll_to(0);
}
/* if (!s->sel_item && p->items)
* {
* s->sel_item = p->items->data;
* _evry_item_sel(s->sel_item);
* _evry_scroll_to(0);
* } */
evas_event_thaw(popup->evas);
_evry_tab_scroll_to(p);
}
static void
@ -911,7 +945,7 @@ _evry_matches_update(void)
if (!s->initial || (items && eina_list_count(p->items) > 0))
{
s->cur_plugins = eina_list_append(s->cur_plugins, p);
_evry_plugin_selector_append(p);
_evry_plugin_selector_show(p);
}
}
@ -983,6 +1017,43 @@ _evry_scroll_to(int i)
e_box_align_set(o_list, 0.5, 1.0);
}
static void
_evry_tab_scroll_to(Evry_Plugin *p)
{
int n, w, mw, i;
double align;
Eina_List *l;
for(i = 0, l = cur_state->cur_plugins; l; l = l->next, i++)
if (l->data == p) break;
n = eina_list_count(cur_state->cur_plugins);
e_box_min_size_get(o_selector, &mw, NULL);
evas_object_geometry_get(o_selector, NULL, NULL, &w, NULL);
if (mw <= w) return;
if (n > 1)
{
align = (double)i / (double)(n - 1);
/* if (evry_conf->scroll_animate)
* {
* if (!scroll_timer)
* scroll_timer = ecore_timer_add(0.01, _evry_scroll_timer, NULL);
* if (!scroll_animator)
* scroll_animator = ecore_animator_add(_evry_animator, NULL);
* }
* else */
{
e_box_align_set(o_selector, 1.0 - align, 0.5);
}
}
else
e_box_align_set(o_selector, 1.0, 0.5);
}
static void
_evry_item_desel(Evry_Item *it)
{
@ -1005,6 +1076,8 @@ _evry_item_next(void)
Eina_List *l;
int i;
Evry_State *s = cur_state;
s->plugin_auto_selected = 0;
if (s->sel_item)
{
@ -1040,9 +1113,11 @@ _evry_item_prev(void)
Eina_List *l;
int i;
Evry_State *s = cur_state;
s->plugin_auto_selected = 0;
if (s->sel_item)
{
{
_evry_item_desel(s->sel_item);
for (i = 0, l = s->cur_plugin->items; l; l = l->next, i++)
@ -1071,20 +1146,21 @@ static void
_evry_plugin_next(void)
{
Eina_List *l;
Evry_Plugin *plugin;
Evry_State *s = cur_state;
if (!s->cur_plugin) return;
l = eina_list_data_find_list(s->cur_plugins, s->cur_plugin);
if (l && l->next)
{
s->plugin_auto_selected = 0;
_evry_list_clear();
_evry_show_items(l->next->data);
}
else if (s->cur_plugin != s->cur_plugins->data)
{
s->plugin_auto_selected = 0;
_evry_list_clear();
_evry_show_items(s->cur_plugins->data);
}
@ -1104,15 +1180,17 @@ _evry_plugin_prev(void)
if (l && l->prev)
{
s->plugin_auto_selected = 0;
_evry_list_clear();
_evry_show_items(l->prev->data);
}
else
{
{
l = eina_list_last(s->cur_plugins);
if (s->cur_plugin != l->data)
{
s->plugin_auto_selected = 0;
_evry_list_clear();
_evry_show_items(l->data);
}
@ -1154,12 +1232,14 @@ _evry_animator(void *data)
}
static void
_evry_plugin_selector_append(Evry_Plugin *p)
_evry_plugin_selector_show(Evry_Plugin *p)
{
Evas_Object *o;
Evas_Coord mw = 0, mh = 0;
char buf[64];
Eina_List *l;
Evry_State *s = cur_state;
o = edje_object_add(popup->evas);
/* TODO move this to everything theme group !*/
e_theme_edje_object_set(o, "base/theme/widgets",
@ -1171,8 +1251,16 @@ _evry_plugin_selector_append(Evry_Plugin *p)
edje_object_size_min_calc(o, &mw, &mh);
e_box_freeze(o_selector);
e_box_pack_end(o_selector, o);
l = eina_list_data_find_list(s->cur_plugins, p);
if (l && l->next)
{
Evry_Plugin *p2 = l->next->data;
e_box_pack_before(o_selector, o, p2->tab);
}
else
e_box_pack_end(o_selector, o);
evas_object_show(o);
e_box_pack_options_set(o, 1, 1, 0, 0, 0.5, 0.5, mw, mh, 9999, 9999);
e_box_thaw(o_selector);

View File

@ -9,6 +9,7 @@ typedef struct _Evry_Action Evry_Action;
typedef struct _Evry_Config Evry_Config;
typedef struct _Evry_App Evry_App;
/* typedef enum _Evry_Plugin_Type
* {
* EVRY_SYNC,
@ -22,6 +23,12 @@ typedef struct _Evry_App Evry_App;
* EVRY_STATE_FINISHED,
* } Evry_Plugin_State; */
#define EVRY_ACTION_OTHER 0
#define EVRY_ACTION_FINISHED 1
#define EVRY_ACTION_CONTINUE 2
#else
#ifndef EVRY_H
#define EVRY_H
@ -55,12 +62,12 @@ struct _Evry_Plugin
int prio;
/* sync/async ?*/
unsigned char async_query : 1;
Eina_Bool async_query;
/* whether candidates can be shown without input
* e.g. borders, app history */
unsigned char need_query : 1;
Eina_Bool need_query;
/* run when plugin is activated. */
int (*begin) (Evry_Item *item);
@ -84,7 +91,6 @@ struct _Evry_Plugin
void (*config_apply) (void);
/* for internal use by plugin */
Eina_List *states;
void *priv;
/* not to be set by plugin! */

View File

@ -146,10 +146,10 @@ _action(Evry_Item *it, const char *input)
eina_list_free(files);
return 1;
return EVRY_ACTION_FINISHED;
}
return 0;
return EVRY_ACTION_CONTINUE;
}
@ -163,8 +163,8 @@ _list_free(void)
{
if (it->label) eina_stringshare_del(it->label);
app = it->data[0];
free(app);
free(it);
E_FREE(app);
E_FREE(it);
}
}
@ -343,8 +343,8 @@ _item_add(Efreet_Desktop *desktop, char *file, int prio)
file = NULL;
}
it = calloc(1, sizeof(Evry_Item));
app = calloc(1, sizeof(Evry_App));
it = E_NEW(Evry_Item, 1);
app = E_NEW(Evry_App, 1);
app->desktop = desktop;
app->file = file;
it->data[0] = app;

View File

@ -50,7 +50,7 @@ _action(Evry_Item *it, const char *input)
E_Border *bd;
E_Zone *zone;
if (!it) return 0;
if (!it) return EVRY_ACTION_CONTINUE;
bd = (E_Border *)it->data[0];
zone = e_util_zone_current_get(e_manager_current_get());
@ -69,7 +69,7 @@ _action(Evry_Item *it, const char *input)
/* e_border_focus_set(bd, 1, 1); */
e_border_focus_set_with_pointer(bd);
return 1;
return EVRY_ACTION_FINISHED;
}
static void
@ -81,7 +81,7 @@ _cleanup()
{
/* if (it->data[0]) e_object_unref(E_OBJECT(it->data[0])); */
if (it->label) eina_stringshare_del(it->label);
free(it);
E_FREE(it);
}
}
@ -149,7 +149,7 @@ _item_add(E_Border *bd, int prio)
{
Evry_Item *it;
it = calloc(1, sizeof(Evry_Item));
it = E_NEW(Evry_Item, 1);
/* e_object_ref(E_OBJECT(bd)); */
it->data[0] = bd;
it->priority = prio;

View File

@ -94,7 +94,8 @@ _action(Evry_Item *item, const char *input)
void (*border_action) (E_Border *bd);
border_action = item->data[0];
border_action(inst->border);
return 1;
return EVRY_ACTION_FINISHED;
}
static void
@ -106,7 +107,7 @@ _cleanup(void)
{
if (it->data[1]) eina_stringshare_del(it->data[1]);
if (it->label) eina_stringshare_del(it->label);
free(it);
E_FREE(it);
}
}
@ -115,7 +116,7 @@ _item_add(const char *label, void (*action_cb) (E_Border *bd), const char *icon)
{
Evry_Item *it;
it = calloc(1, sizeof(Evry_Item));
it = E_NEW(Evry_Item, 1);
it->data[0] = action_cb;
it->data[1] = (void *) eina_stringshare_add(icon);
it->label = eina_stringshare_add(label);

View File

@ -0,0 +1,201 @@
/* TODO
* - dc support?
*/
#include "e.h"
#include "e_mod_main.h"
static int _begin(Evry_Item *it);
static int _fetch(const char *input);
static int _action(Evry_Item *item, const char *input);
static void _cleanup(void);
static void _item_add(char *output, int prio);
static int _cb_sort(const void *data1, const void *data2);
static void _item_icon_get(Evry_Item *it, Evas *e);
static int _cb_data(void *data, int type, void *event);
static Evry_Plugin *p;
static Ecore_Exe *exe = NULL;
static Eina_List *history = NULL;
static Ecore_Event_Handler *data_handler = NULL;
static Ecore_Event_Handler *error_handler = NULL;
EAPI int
evry_plug_calc_init(void)
{
p = E_NEW(Evry_Plugin, 1);
p->name = "Calculator";
p->type_in = "NONE";
p->type_out = "NONE";
p->need_query = 0;
p->prio = 6;
p->async_query = 1;
p->begin = &_begin;
p->fetch = &_fetch;
p->action = &_action;
p->cleanup = &_cleanup;
p->icon_get = &_item_icon_get;
evry_plugin_register(p);
return 1;
}
EAPI int
evry_plug_calc_shutdown(void)
{
Evry_Item *it;
EINA_LIST_FREE(p->items, it)
{
if (it->label) eina_stringshare_del(it->label);
free(it);
}
evry_plugin_unregister(p);
E_FREE(p);
return 1;
}
static int
_begin(Evry_Item *it)
{
data_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DATA, _cb_data, p);
exe = ecore_exe_pipe_run("bc",
ECORE_EXE_PIPE_READ |
ECORE_EXE_PIPE_READ_LINE_BUFFERED |
ECORE_EXE_PIPE_WRITE,
NULL);
}
static void
_cleanup()
{
Evry_Item *it;
int i = 0;
EINA_LIST_FREE(p->items, it)
{
if (i < 10)
{
history = eina_list_append(history, it);
}
else
{
if (it->label) eina_stringshare_del(it->label);
free(it);
}
}
ecore_event_handler_del(data_handler);
data_handler = NULL;
ecore_exe_quit(exe);
exe = NULL;
}
static int
_send_input(const char *input)
{
char buf[1024];
snprintf(buf, 1024, "%s\n", input);
return ecore_exe_send(exe, buf, strlen(buf));
}
static int
_action(Evry_Item *it, const char *input)
{
if (!it)
{
if (p->items)
{
Evry_Item *it2 = p->items->data;
_item_add((char *) it2->label, 1);
evry_plugin_async_update(p, 1);
}
return EVRY_ACTION_CONTINUE;
}
else
{
/* XXX on which windows must the selection be set? */
ecore_x_selection_primary_set(e_manager_current_get()->win,
it->label, strlen(it->label));
if (p->items->data == it)
{
Evry_Item *it2 = p->items->data;
_item_add((char *) it2->label, 1);
}
}
return EVRY_ACTION_FINISHED;
}
static int
_fetch(const char *input)
{
if (history)
{
p->items = history;
history = NULL;
}
_send_input(input);
return 1;
}
static void
_item_icon_get(Evry_Item *it, Evas *e)
{
it->o_icon = NULL;
}
static void
_item_add(char *output, int prio)
{
Evry_Item *it;
it = E_NEW(Evry_Item, 1);
it->priority = prio;
it->label = eina_stringshare_add(output);
p->items = eina_list_prepend(p->items, it);
}
static int
_cb_data(void *data, int type, void *event)
{
Ecore_Exe_Event_Data *ev = event;
Ecore_Exe_Event_Data_Line *l;
if (data != p) return 1;
evry_plugin_async_update(p, 0);
for (l = ev->lines; l && l->line; l++)
{
if (p->items)
{
Evry_Item *it = p->items->data;
if (it->label)
eina_stringshare_del(it->label);
it->label = eina_stringshare_add(l->line);
}
else
_item_add(l->line, 1);
}
evry_plugin_async_update(p, 1);
return 1;
}

View File

@ -46,7 +46,7 @@ _action(Evry_Item *it, const char *input)
char buf[1024];
int found = 0;
if (!it) return 0;
if (!it) return EVRY_ACTION_CONTINUE;
eci = it->data[0];
con = e_container_current_get(e_manager_current_get());
@ -70,7 +70,7 @@ _action(Evry_Item *it, const char *input)
if (found)
e_configure_registry_call(buf, con, NULL);
return 1;
return EVRY_ACTION_FINISHED;
}
static void
@ -81,7 +81,7 @@ _cleanup(void)
EINA_LIST_FREE(p->items, it)
{
if (it->label) eina_stringshare_del(it->label);
free(it);
E_FREE(it);
}
}
@ -158,7 +158,7 @@ _item_add(E_Configure_It *eci, int prio)
{
Evry_Item *it;
it = calloc(1, sizeof(Evry_Item));
it = E_NEW(Evry_Item, 1);
it->data[0] = eci;
it->priority = prio;
it->label = eina_stringshare_add(eci->label);

View File

@ -19,6 +19,7 @@ static void _list_free(void);
static Evry_Item *_item_fill(const char *directory, const char *file);
static Evry_Plugin *p;
static Eina_List *stack = NULL;
EAPI int
evry_plug_dir_browse_init(void)
@ -67,7 +68,7 @@ _begin(Evry_Item *it)
s->directory = eina_stringshare_add(e_user_homedir_get());
}
p->states = eina_list_prepend(p->states, s);
stack = eina_list_prepend(stack, s);
p->items = NULL;
return 1;
@ -76,7 +77,7 @@ _begin(Evry_Item *it)
static int
_action(Evry_Item *it, const char *input)
{
return 0;
return EVRY_ACTION_OTHER;
}
static void
@ -100,9 +101,9 @@ _cleanup()
{
State *s;
if (!p->states) return;
if (!stack) return;
s = p->states->data;
s = stack->data;
_list_free();
@ -110,11 +111,11 @@ _cleanup()
E_FREE(s);
p->states = eina_list_remove_list(p->states, p->states);
stack = eina_list_remove_list(stack, stack);
if (p->states)
if (stack)
{
s = p->states->data;
s = stack->data;
p->items = s->items;
}
}
@ -128,7 +129,7 @@ _fetch(const char *input)
Evry_Item *it;
char match1[4096];
char match2[4096];
State *s = p->states->data;
State *s = stack->data;
_list_free();

View File

@ -66,7 +66,7 @@ evry_plug_tracker_shutdown(void)
static int
_action(Evry_Item *it, const char *input)
{
return 0;
return EVRY_ACTION_OTHER;
}
static void