From fa92eda759c6332ff931913b9123dc575c83a5eb Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Tue, 1 Jun 2010 14:26:09 +0000 Subject: [PATCH] evry start icon gadget, not finished but works SVN revision: 49371 --- src/modules/everything/Makefile.am | 1 + src/modules/everything/e_mod_main.c | 4 +- src/modules/everything/e_mod_main.h | 6 +- src/modules/everything/evry.c | 43 ++++-- src/modules/everything/evry_gadget.c | 217 +++++++++++++++++++++++++++ 5 files changed, 252 insertions(+), 19 deletions(-) create mode 100644 src/modules/everything/evry_gadget.c diff --git a/src/modules/everything/Makefile.am b/src/modules/everything/Makefile.am index 9dafeb703..3d97126e7 100644 --- a/src/modules/everything/Makefile.am +++ b/src/modules/everything/Makefile.am @@ -38,6 +38,7 @@ module_la_SOURCES = $(EVRYHEADERS) \ evry_plug_clipboard.c \ evry_plug_text.c \ evry_plug_collection.c \ + evry_gadget.c \ md5.h \ md5.c diff --git a/src/modules/everything/e_mod_main.c b/src/modules/everything/e_mod_main.c index 4ff0d2cb8..116e74c6f 100644 --- a/src/modules/everything/e_mod_main.c +++ b/src/modules/everything/e_mod_main.c @@ -72,7 +72,7 @@ e_modapi_init(E_Module *m) evry_plug_text_init(); evry_view_init(); evry_view_help_init(); - + evry_gadget_init(); /* add module supplied action */ act = e_action_add("everything"); @@ -173,8 +173,8 @@ e_modapi_shutdown(E_Module *m __UNUSED__) e_datastore_del("everything_loaded"); E_FREE(_api); + evry_gadget_shutdown(); evry_shutdown(); - evry_view_shutdown(); evry_view_help_shutdown(); evry_plug_clipboard_shutdown(); diff --git a/src/modules/everything/e_mod_main.h b/src/modules/everything/e_mod_main.h index e1509d90e..0f9abc62c 100644 --- a/src/modules/everything/e_mod_main.h +++ b/src/modules/everything/e_mod_main.h @@ -299,7 +299,7 @@ void evry_plug_collection_shutdown(void); int evry_init(void); int evry_shutdown(void); -int evry_show(E_Zone *zone, E_Zone_Edge edge, const char *params); +Evry_Window *evry_show(E_Zone *zone, E_Zone_Edge edge, const char *params); void evry_hide(int clear); int evry_plug_actions_init(); @@ -319,6 +319,10 @@ int evry_state_push(Evry_Selector *sel, Eina_List *plugins); int evry_selectors_switch(int dir, int slide); int evry_view_toggle(Evry_State *s, const char *trigger); +int evry_gadget_init(void); +void evry_gadget_shutdown(void); + + Ecore_Event_Handler *evry_event_handler_add(int type, int (*func) (void *data, int type, void *event), const void *data); extern Evry_History *evry_hist; diff --git a/src/modules/everything/evry.c b/src/modules/everything/evry.c index 435b119fb..2a4bf94b6 100644 --- a/src/modules/everything/evry.c +++ b/src/modules/everything/evry.c @@ -168,7 +168,7 @@ _cb_hide_timer(void *data) return 0; } -int +Evry_Window * evry_show(E_Zone *zone, E_Zone_Edge edge, const char *params) { E_OBJECT_CHECK_RETURN(zone, 0); @@ -180,14 +180,14 @@ evry_show(E_Zone *zone, E_Zone_Edge edge, const char *params) Evry_Plugin *p; if (win->level > 0) - return 1; + return win; if (!(params) && (CUR_SEL == OBJ_SEL) && ((CUR_SEL)->state && (CUR_SEL)->state->cur_item)) { _evry_selectors_shift(1); - return 1; + return win; } evry_hide(1); @@ -201,7 +201,7 @@ evry_show(E_Zone *zone, E_Zone_Edge edge, const char *params) _evry_selector_update(CUR_SEL); _evry_view_update((CUR_SEL)->state); } - return 1; + return win; } input_window = ecore_x_window_input_new(zone->container->win, 0, 0, 1, 1); @@ -210,7 +210,7 @@ evry_show(E_Zone *zone, E_Zone_Edge edge, const char *params) /* if (edge == E_ZONE_EDGE_NONE) */ { if (!e_grabinput_get(input_window, 0, input_window)) - return 0; + return NULL; } win = _evry_window_new(zone, edge); @@ -219,7 +219,7 @@ evry_show(E_Zone *zone, E_Zone_Edge edge, const char *params) ecore_x_window_free(input_window); e_grabinput_release(input_window, input_window); input_window = 0; - return 0; + return NULL; } win->visible = EINA_FALSE; @@ -286,7 +286,6 @@ evry_show(E_Zone *zone, E_Zone_Edge edge, const char *params) e_popup_layer_set(win->popup, 255); e_popup_show(win->popup); - ecore_x_window_raise(input_window); _evry_selector_subjects_get(params); _evry_selector_update(SUBJ_SEL); @@ -298,7 +297,7 @@ evry_show(E_Zone *zone, E_Zone_Edge edge, const char *params) else _evry_selector_activate(SUBJ_SEL, 0); - return 1; + return win; } void @@ -877,7 +876,8 @@ _evry_window_new(E_Zone *zone, E_Zone_Edge edge) mh += offset_s*2; } - ecore_x_window_move_resize(input_window, x, y, mw, mh); + /* ecore_x_window_reparent(input_window, popup->evas_win, 0,0); + * ecore_x_window_resize(input_window, mw, mh); */ e_popup_move_resize(popup, x, y, mw, mh); @@ -958,7 +958,10 @@ _evry_cb_mouse(void *data, int type, void *event) if ((win->mouse_button == 3) && (s = (CUR_SEL)->state) && (s->cur_item) && (CHECK_TYPE(s->cur_item, EVRY_TYPE_FILE)) && - (!E_INSIDE(ev->x, ev->y, pop->zone->x, pop->zone->y, pop->w, pop->h))) + (!E_INSIDE(ev->x, ev->y, + pop->x + pop->zone->x, + pop->y + pop->zone->y, + pop->w, pop->h))) { const char *drag_types[] = { "text/uri-list" }; E_Drag *d; @@ -981,12 +984,14 @@ _evry_cb_mouse(void *data, int type, void *event) sel_length += s_len + 2; d = e_drag_new(e_container_current_get(e_manager_current_get()), - ev->x, ev->y, drag_types, 1, sel, sel_length, NULL, + ev->x + pop->x, + ev->y + pop->y, + drag_types, 1, sel, sel_length, NULL, _evry_cb_drag_finished); e_drag_resize(d, 128, 128); o = evry_util_icon_get(s->cur_item, e_drag_evas_get(d)); e_drag_object_set(d, o); - e_drag_xdnd_start(d, ev->x, ev->y); + e_drag_xdnd_start(d, ev->x + pop->x, ev->y + pop->y); evry_hide(0); return 1; @@ -994,8 +999,8 @@ _evry_cb_mouse(void *data, int type, void *event) evas_event_feed_mouse_move (pop->evas, - ev->x - pop->zone->x, - ev->y - pop->zone->y, + ev->x - (pop->x + pop->zone->x), + ev->y - (pop->y + pop->zone->y), ev->timestamp, NULL); } else if (type == ECORE_EVENT_MOUSE_BUTTON_DOWN) @@ -1003,7 +1008,10 @@ _evry_cb_mouse(void *data, int type, void *event) win->mouse_out = 0; /* XXX shift triple click in flags when needed */ - if (!E_INSIDE(ev->x, ev->y, pop->zone->x, pop->zone->y, pop->w, pop->h)) + if (!E_INSIDE(ev->x, ev->y, + pop->x + pop->zone->x, + pop->y + pop->zone->y, + pop->w, pop->h)) { win->mouse_out = 1; return 1; @@ -1021,7 +1029,10 @@ _evry_cb_mouse(void *data, int type, void *event) win->mouse_button = 0; if (win->mouse_out && - !E_INSIDE(ev->x, ev->y, pop->zone->x, pop->zone->y, pop->w, pop->h)) + !E_INSIDE(ev->x, ev->y, + pop->x + pop->zone->x, + pop->y + pop->zone->y, + pop->w, pop->h)) { evry_hide(0); return 1; diff --git a/src/modules/everything/evry_gadget.c b/src/modules/everything/evry_gadget.c new file mode 100644 index 000000000..582470b45 --- /dev/null +++ b/src/modules/everything/evry_gadget.c @@ -0,0 +1,217 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 + */ +#include "e.h" +#include "e_mod_main.h" + +/* gadcon requirements */ +static E_Gadcon_Client *_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style); +static void _gc_shutdown(E_Gadcon_Client *gcc); +static void _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient); +static char *_gc_label(E_Gadcon_Client_Class *client_class); +static Evas_Object *_gc_icon(E_Gadcon_Client_Class *client_class, Evas *evas); +static const char *_gc_id_new(E_Gadcon_Client_Class *client_class); +/* and actually define the gadcon class that this module provides (just 1) */ +static const E_Gadcon_Client_Class _gadcon_class = +{ + GADCON_CLIENT_CLASS_VERSION, + "evry-starter", + { + _gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL, + e_gadcon_site_is_not_toolbar + }, + E_GADCON_CLIENT_STYLE_PLAIN +}; + +typedef struct _Instance Instance; + +struct _Instance +{ + E_Gadcon_Client *gcc; + Evas_Object *o_button; + + E_Object_Delfn *del_fn; + Evry_Window *win; +}; + +static void _button_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info); + +static E_Gadcon_Client * +_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style) +{ + Evas_Object *o; + E_Gadcon_Client *gcc; + Instance *inst; + + inst = E_NEW(Instance, 1); + + o = edje_object_add(gc->evas); + e_theme_edje_object_set(o, "base/theme/modules/start", "e/modules/start/main"); + edje_object_signal_emit(o, "e,state,unfocused", "e"); + + gcc = e_gadcon_client_new(gc, name, id, style, o); + gcc->data = inst; + + inst->gcc = gcc; + inst->o_button = o; + + e_gadcon_client_util_menu_attach(gcc); + + evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, + _button_cb_mouse_down, inst); + return gcc; +} + +static void +_gc_shutdown(E_Gadcon_Client *gcc) +{ + Instance *inst; + + inst = gcc->data; + if (inst->del_fn && inst->win) + e_object_delfn_del(E_OBJECT(inst->win->popup), inst->del_fn); + + evas_object_del(inst->o_button); + free(inst); +} + +static void +_gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient) +{ + Instance *inst; + Evas_Coord mw, mh; + + inst = gcc->data; + mw = 0, mh = 0; + edje_object_size_min_get(inst->o_button, &mw, &mh); + if ((mw < 1) || (mh < 1)) + edje_object_size_min_calc(inst->o_button, &mw, &mh); + if (mw < 4) mw = 4; + if (mh < 4) mh = 4; + e_gadcon_client_aspect_set(gcc, mw, mh); + e_gadcon_client_min_size_set(gcc, mw, mh); +} + +static char * +_gc_label(E_Gadcon_Client_Class *client_class) +{ + return _("Everything Starter"); +} + +static Evas_Object * +_gc_icon(E_Gadcon_Client_Class *client_class, Evas *evas) +{ + Evas_Object *o; + /* char buf[4096]; + * + * o = edje_object_add(evas); + * snprintf(buf, sizeof(buf), "%s/e-module-start.edj", + * e_module_dir_get(start_module)); + * edje_object_file_set(o, buf, "icon"); */ + return NULL; +} + +static const char * +_gc_id_new(E_Gadcon_Client_Class *client_class) +{ + return _gadcon_class.name; +} + +/***************************************************************************/ + + +static void _del_func(void *data, void *obj) +{ + Instance *inst = data; + + e_gadcon_locked_set(inst->gcc->gadcon, 0); + e_object_delfn_del(E_OBJECT(inst->win->popup), inst->del_fn); + inst->del_fn = NULL; + inst->win = NULL; +} + +static void +_button_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + Instance *inst; + Evas_Event_Mouse_Down *ev; + + inst = data; + ev = event_info; + if (ev->button == 1) + { + Evas_Coord x, y, w, h; + int cx, cy, px, py, pw, ph; + Evry_Window *win; + int dir; + + win = evry_show(e_util_zone_current_get(e_manager_current_get()), 0, "Start"); + if (!win) return; + + evas_object_geometry_get(inst->o_button, &x, &y, &w, &h); + e_gadcon_canvas_zone_geometry_get(inst->gcc->gadcon, + &cx, &cy, NULL, NULL); + x += cx; + y += cy; + pw = win->popup->w; + ph = win->popup->h; + + switch (inst->gcc->gadcon->orient) + { + + case E_GADCON_ORIENT_TOP: + case E_GADCON_ORIENT_CORNER_TL: + case E_GADCON_ORIENT_CORNER_TR: + e_popup_move(win->popup, x, y + h); + break; + case E_GADCON_ORIENT_BOTTOM: + case E_GADCON_ORIENT_CORNER_BR: + case E_GADCON_ORIENT_CORNER_BL: + e_popup_move(win->popup, x, y - ph); + break; + case E_GADCON_ORIENT_LEFT: + case E_GADCON_ORIENT_CORNER_LT: + case E_GADCON_ORIENT_CORNER_LB: + e_popup_move(win->popup, x + w, y); + break; + case E_GADCON_ORIENT_RIGHT: + case E_GADCON_ORIENT_CORNER_RT: + case E_GADCON_ORIENT_CORNER_RB: + e_popup_move(win->popup, x - pw, y); + break; + case E_GADCON_ORIENT_FLOAT: + case E_GADCON_ORIENT_HORIZ: + case E_GADCON_ORIENT_VERT: + default: + break; + } + + inst->win = win; + + if (win->popup->x + pw > win->popup->zone->w) + e_popup_move(win->popup, win->popup->zone->w - pw, win->popup->y); + + if (win->popup->y + ph > win->popup->zone->h) + e_popup_move(win->popup, win->popup->x, win->popup->zone->h - ph); + + e_gadcon_locked_set(inst->gcc->gadcon, 1); + + inst->del_fn = e_object_delfn_add(E_OBJECT(win->popup), _del_func, inst); + + edje_object_signal_emit(inst->o_button, "e,state,focused", "e"); + } +} + + +int +evry_gadget_init(void) +{ + e_gadcon_provider_register(&_gadcon_class); + return 1; +} + +void +evry_gadget_shutdown(void) +{ + e_gadcon_provider_unregister(&_gadcon_class); +}