enlightenment/src/modules/everything/e_mod_main.c

604 lines
16 KiB
C
Raw Normal View History

#include "e_mod_main.h"
static void _e_mod_action_cb(E_Object *obj, const char *params);
static void _e_mod_action_cb_edge(E_Object *obj, const char *params, E_Event_Zone_Edge *ev);
static Eina_Bool _e_mod_run_defer_cb(void *data);
static void _e_mod_run_cb(void *data, E_Menu *m, E_Menu_Item *mi);
static void _e_mod_menu_add(void *data, E_Menu *m);
static void _config_init(void);
static void _config_free(void);
static Eina_Bool _cleanup_history(void *data);
static void _evry_type_init(const char *type);
static Eina_List *_evry_types = NULL;
static E_Int_Menu_Augmentation *maug = NULL;
static E_Action *act = NULL;
static Ecore_Timer *cleanup_timer;
static const char *module_icon = NULL;
static E_Config_DD *conf_edd = NULL;
static E_Config_DD *plugin_conf_edd = NULL;
static E_Config_DD *gadget_conf_edd = NULL;
Evry_API *evry = NULL;
Evry_Config *evry_conf = NULL;
int _evry_events[NUM_EVRY_EVENTS];
E_Module *_mod_evry = NULL;
/* module setup */
EAPI E_Module_Api e_modapi =
{
E_MODULE_API_VERSION,
"Everything"
};
EAPI void *
e_modapi_init(E_Module *m)
{
Eina_List *l;
Evry_Module *em;
char buf[4096];
_mod_evry = m;
/* add module supplied action */
act = e_action_add("everything");
if (act)
{
act->func.go = _e_mod_action_cb;
act->func.go_edge = _e_mod_action_cb_edge;
e_action_predef_name_set
(N_("Everything Launcher"),
N_("Show Everything Launcher"),
"everything", "", NULL, 0);
}
maug = e_int_menus_menu_augmentation_add
("main/1", _e_mod_menu_add, NULL, NULL, NULL);
e_configure_registry_category_add
("launcher", 80, _("Launcher"), NULL, "modules-launcher");
snprintf(buf, sizeof(buf), "%s/e-module-everything.edj", e_module_dir_get(m));
module_icon = eina_stringshare_add(buf);
e_configure_registry_item_add
("launcher/run_everything", 40, _("Everything Configuration"),
NULL, module_icon, evry_config_dialog);
evry_init();
_evry_type_init("NONE");
_evry_type_init("FILE");
_evry_type_init("DIRECTORY");
_evry_type_init("APPLICATION");
_evry_type_init("ACTION");
_evry_type_init("PLUGIN");
_evry_type_init("BORDER");
_evry_type_init("TEXT");
_config_init();
_evry_events[EVRY_EVENT_ITEMS_UPDATE] = ecore_event_type_new();
_evry_events[EVRY_EVENT_ITEM_SELECTED] = ecore_event_type_new();
_evry_events[EVRY_EVENT_ITEM_CHANGED] = ecore_event_type_new();
_evry_events[EVRY_EVENT_ACTION_PERFORMED] = ecore_event_type_new();
_evry_events[EVRY_EVENT_PLUGIN_SELECTED] = ecore_event_type_new();
evry = E_NEW(Evry_API, 1);
#define SET(func) (evry->func = &evry_##func);
SET(api_version_check);
SET(item_new);
SET(item_free);
SET(item_ref);
SET(plugin_new);
SET(plugin_free);
SET(plugin_register);
SET(plugin_unregister);
SET(plugin_update);
SET(plugin_find);
SET(action_new);
SET(action_free);
SET(action_register);
SET(action_unregister);
SET(action_find);
SET(api_version_check);
SET(type_register);
SET(icon_theme_get);
SET(fuzzy_match);
SET(util_exec_app);
SET(util_url_escape);
SET(util_url_unescape);
SET(util_file_detail_set);
SET(util_plugin_items_add);
SET(util_md5_sum);
SET(util_icon_get);
SET(item_changed);
SET(file_path_get);
SET(file_url_get);
SET(history_item_add);
SET(history_types_get);
SET(history_item_usage_set);
SET(event_handler_add);
#undef SET
evry_history_init();
evry_plug_actions_init();
evry_plug_apps_init(m);
evry_plug_files_init(m);
evry_plug_windows_init(m);
evry_plug_settings_init(m);
evry_plug_calc_init(m);
e_datastore_set("evry_api", evry);
EINA_LIST_FOREACH (e_datastore_get("evry_modules"), l, em)
em->active = em->init(evry);
evry_plug_collection_init();
evry_plug_clipboard_init();
evry_plug_text_init();
evry_view_init();
evry_view_help_init();
evry_gadget_init();
e_module_priority_set(m, -1000);
e_module_delayed_set(m, 1);
2010-05-01 16:24:14 -07:00
/* cleanup every hour :) */
cleanup_timer = ecore_timer_add(3600, _cleanup_history, NULL);
2010-05-01 16:24:14 -07:00
return m;
}
EAPI int
e_modapi_shutdown(E_Module *m __UNUSED__)
{
E_Config_Dialog *cfd;
const char *t;
Eina_List *l;
Evry_Module *em;
EINA_LIST_FOREACH (e_datastore_get("evry_modules"), l, em)
{
if (em->active)
em->shutdown();
em->active = EINA_FALSE;
}
evry_plug_apps_shutdown();
evry_plug_files_shutdown();
evry_plug_settings_shutdown();
evry_plug_windows_shutdown();
evry_plug_calc_shutdown();
evry_plug_clipboard_shutdown();
evry_plug_text_shutdown();
evry_plug_collection_shutdown();
evry_plug_actions_shutdown();
evry_view_shutdown();
evry_view_help_shutdown();
evry_gadget_shutdown();
evry_shutdown();
e_datastore_del("evry_api");
E_FREE(evry);
evry = NULL;
_config_free();
evry_history_free();
EINA_LIST_FREE (_evry_types, t)
eina_stringshare_del(t);
e_configure_registry_item_del("launcher/run_everything");
e_configure_registry_category_del("launcher");
while ((cfd = e_config_dialog_get("E", "launcher/run_everything")))
e_object_del(E_OBJECT(cfd));
if (act)
{
e_action_predef_name_del("Everything Launcher",
"Show Everything Launcher");
e_action_del("everything");
}
if (maug)
{
e_int_menus_menu_augmentation_del("main/1", maug);
maug = NULL;
}
if (module_icon)
eina_stringshare_del(module_icon);
/* Clean EET */
E_CONFIG_DD_FREE(conf_edd);
E_CONFIG_DD_FREE(plugin_conf_edd);
E_CONFIG_DD_FREE(gadget_conf_edd);
2010-05-01 16:24:14 -07:00
if (cleanup_timer)
ecore_timer_del(cleanup_timer);
#ifdef CHECK_REFS
Evry_Item *it;
EINA_LIST_FREE (_refd, it)
printf("%d %s\n", it->ref, it->label);
#endif
_mod_evry = NULL;
return 1;
}
EAPI int
e_modapi_save(E_Module *m __UNUSED__)
{
e_config_domain_save("module.everything", conf_edd, evry_conf);
evry_plug_apps_save();
evry_plug_files_save();
evry_plug_settings_save();
evry_plug_windows_save();
evry_plug_calc_save();
return 1;
}
/***************************************************************************/
Ecore_Event_Handler *
evry_event_handler_add(int type, Eina_Bool (*func)(void *data, int type, void *event), const void *data)
{
return ecore_event_handler_add(_evry_events[type], func, data);
}
Evry_Type
evry_type_register(const char *type)
{
const char *t = eina_stringshare_add(type);
Evry_Type ret = NUM_EVRY_TYPES;
const char *i;
Eina_List *l;
EINA_LIST_FOREACH (_evry_types, l, i)
{
if (i == t) break;
ret++;
}
if (!l)
{
_evry_types = eina_list_append(_evry_types, t);
return ret;
}
eina_stringshare_del(t);
return ret;
}
static void
_evry_type_init(const char *type)
{
const char *t = eina_stringshare_add(type);
_evry_types = eina_list_append(_evry_types, t);
}
const char *
evry_type_get(Evry_Type type)
{
const char *ret = eina_list_nth(_evry_types, type);
if (!ret)
return eina_stringshare_add("");
return ret;
}
int
evry_api_version_check(int version)
{
if (EVRY_API_VERSION == version)
return 1;
ERR("module API is %d, required is %d", version, EVRY_API_VERSION);
return 0;
}
static int
_evry_cb_view_sort(const void *data1, const void *data2)
{
const Evry_View *v1 = data1;
const Evry_View *v2 = data2;
return v1->priority - v2->priority;
}
void
evry_view_register(Evry_View *view, int priority)
{
view->priority = priority;
evry_conf->views = eina_list_append(evry_conf->views, view);
evry_conf->views = eina_list_sort(evry_conf->views,
eina_list_count(evry_conf->views),
_evry_cb_view_sort);
}
void
evry_view_unregister(Evry_View *view)
{
evry_conf->views = eina_list_remove(evry_conf->views, view);
}
/***************************************************************************/
static Eina_Bool
_cleanup_history(void *data __UNUSED__)
2010-05-01 16:24:14 -07:00
{
/* evrything is active */
if (evry_hist)
return ECORE_CALLBACK_RENEW;
2010-05-01 16:24:14 -07:00
/* cleanup old entries */
evry_history_free();
evry_history_init();
return ECORE_CALLBACK_RENEW;
2010-05-01 16:24:14 -07:00
}
static void
_config_init()
{
Plugin_Config *pc, *pcc;
#undef T
#undef D
#define T Plugin_Config
#define D plugin_conf_edd
plugin_conf_edd = E_CONFIG_DD_NEW("Plugin_Config", Plugin_Config);
E_CONFIG_VAL(D, T, name, STR);
E_CONFIG_VAL(D, T, enabled, INT);
E_CONFIG_VAL(D, T, priority, INT);
E_CONFIG_VAL(D, T, trigger, STR);
E_CONFIG_VAL(D, T, trigger_only, INT);
E_CONFIG_VAL(D, T, view_mode, INT);
E_CONFIG_VAL(D, T, aggregate, INT);
E_CONFIG_VAL(D, T, top_level, INT);
E_CONFIG_VAL(D, T, min_query, INT);
E_CONFIG_LIST(D, T, plugins, plugin_conf_edd);
#undef T
#undef D
#define T Gadget_Config
#define D gadget_conf_edd
gadget_conf_edd = E_CONFIG_DD_NEW("Gadget_Config", Gadget_Config);
E_CONFIG_VAL(D, T, id, STR);
E_CONFIG_VAL(D, T, plugin, STR);
E_CONFIG_VAL(D, T, hide_after_action, INT);
E_CONFIG_VAL(D, T, popup, INT);
#undef T
#undef D
#define T Evry_Config
#define D conf_edd
conf_edd = E_CONFIG_DD_NEW("Config", Evry_Config);
E_CONFIG_VAL(D, T, version, INT);
E_CONFIG_VAL(D, T, width, INT);
E_CONFIG_VAL(D, T, height, INT);
E_CONFIG_VAL(D, T, edge_width, INT);
E_CONFIG_VAL(D, T, edge_height, INT);
E_CONFIG_VAL(D, T, rel_x, DOUBLE);
E_CONFIG_VAL(D, T, rel_y, DOUBLE);
E_CONFIG_VAL(D, T, scroll_animate, INT);
E_CONFIG_VAL(D, T, scroll_speed, DOUBLE);
E_CONFIG_VAL(D, T, hide_input, INT);
E_CONFIG_VAL(D, T, hide_list, INT);
E_CONFIG_VAL(D, T, quick_nav, INT);
E_CONFIG_VAL(D, T, view_mode, INT);
E_CONFIG_VAL(D, T, view_zoom, INT);
E_CONFIG_VAL(D, T, cycle_mode, INT);
E_CONFIG_VAL(D, T, history_sort_mode, INT);
E_CONFIG_LIST(D, T, conf_subjects, plugin_conf_edd);
E_CONFIG_LIST(D, T, conf_actions, plugin_conf_edd);
E_CONFIG_LIST(D, T, conf_objects, plugin_conf_edd);
E_CONFIG_LIST(D, T, conf_views, plugin_conf_edd);
E_CONFIG_LIST(D, T, collections, plugin_conf_edd);
E_CONFIG_LIST(D, T, gadgets, gadget_conf_edd);
E_CONFIG_VAL(D, T, first_run, UCHAR);
#undef T
#undef D
2010-05-26 08:34:31 -07:00
evry_conf = e_config_domain_load("module.everything", conf_edd);
if (evry_conf && !e_util_module_config_check(_("Everything Module"),
evry_conf->version,
MOD_CONFIG_FILE_VERSION))
_config_free();
if (!evry_conf)
{
evry_conf = E_NEW(Evry_Config, 1);
/* setup defaults */
evry_conf->rel_x = 0.5;
evry_conf->rel_y = 0.43;
evry_conf->width = 455;
evry_conf->height = 430;
evry_conf->scroll_animate = 1;
evry_conf->scroll_speed = 10.0;
evry_conf->hide_input = 0;
evry_conf->hide_list = 0;
evry_conf->quick_nav = 1;
evry_conf->view_mode = VIEW_MODE_DETAIL;
evry_conf->view_zoom = 0;
evry_conf->cycle_mode = 0;
evry_conf->history_sort_mode = 0;
evry_conf->edge_width = 340;
evry_conf->edge_height = 385;
evry_conf->first_run = EINA_TRUE;
pcc = E_NEW(Plugin_Config, 1);
pcc->name = eina_stringshare_add("Start");
pcc->enabled = EINA_FALSE;
pcc->aggregate = EINA_FALSE;
pcc->top_level = EINA_TRUE;
pcc->view_mode = VIEW_MODE_THUMB;
evry_conf->collections = eina_list_append(evry_conf->collections, pcc);
pc = E_NEW(Plugin_Config, 1);
pc->name = eina_stringshare_add("Windows");
pc->enabled = EINA_TRUE;
pc->view_mode = VIEW_MODE_NONE;
pcc->plugins = eina_list_append(pcc->plugins, pc);
pc = E_NEW(Plugin_Config, 1);
pc->name = eina_stringshare_add("Settings");
pc->enabled = EINA_TRUE;
pc->view_mode = VIEW_MODE_NONE;
pcc->plugins = eina_list_append(pcc->plugins, pc);
pc = E_NEW(Plugin_Config, 1);
pc->name = eina_stringshare_add("Files");
pc->enabled = EINA_TRUE;
pc->view_mode = VIEW_MODE_NONE;
pcc->plugins = eina_list_append(pcc->plugins, pc);
pc = E_NEW(Plugin_Config, 1);
pc->name = eina_stringshare_add("Applications");
pc->enabled = EINA_TRUE;
pc->view_mode = VIEW_MODE_NONE;
pcc->plugins = eina_list_append(pcc->plugins, pc);
evry_conf->width = 464;
evry_conf->height = 366;
}
evry_conf->version = MOD_CONFIG_FILE_VERSION;
}
static void
_config_free(void)
{
Plugin_Config *pc, *pc2;
Gadget_Config *gc;
EINA_LIST_FREE (evry_conf->collections, pc)
{
EINA_LIST_FREE (pc->plugins, pc2)
{
IF_RELEASE(pc2->name);
IF_RELEASE(pc2->trigger);
E_FREE(pc2);
}
// collections become registered as SUBJECT
// plugin, therefore dont free pc here
}
EINA_LIST_FREE (evry_conf->conf_subjects, pc)
{
IF_RELEASE(pc->name);
IF_RELEASE(pc->trigger);
E_FREE(pc);
}
EINA_LIST_FREE (evry_conf->conf_actions, pc)
{
IF_RELEASE(pc->name);
IF_RELEASE(pc->trigger);
E_FREE(pc);
}
EINA_LIST_FREE (evry_conf->conf_objects, pc)
{
IF_RELEASE(pc->name);
IF_RELEASE(pc->trigger);
E_FREE(pc);
}
EINA_LIST_FREE (evry_conf->conf_views, pc)
{
IF_RELEASE(pc->name);
IF_RELEASE(pc->trigger);
E_FREE(pc);
}
EINA_LIST_FREE (evry_conf->gadgets, gc)
{
IF_RELEASE(gc->id);
IF_RELEASE(gc->plugin);
E_FREE(gc);
}
E_FREE(evry_conf);
}
/***************************************************************************/
/* action callback */
static Ecore_Idle_Enterer *_idler = NULL;
static const char *_params = NULL;
static Eina_Bool
_e_mod_run_defer_cb(void *data)
{
E_Zone *zone;
zone = data;
if (zone) evry_show(zone, E_ZONE_EDGE_NONE, _params, EINA_TRUE);
_idler = NULL;
return ECORE_CALLBACK_CANCEL;
}
static void
_e_mod_action_cb(E_Object *obj, const char *params)
{
E_Zone *zone = NULL;
if (obj)
{
if (obj->type == E_MANAGER_TYPE)
zone = e_util_zone_current_get((E_Manager *)obj);
compositor rewrite / charlie-foxtrot situation huge fustercluck commit because there wasn't really a way to separate out the changes. better to just rip it all out at once. * compositor and window management completely rewritten. this was the goal for E19, but it pretty much required everything existing to be scrapped since it wasn't optimized, streamlined, or sensible. now instead of having the compositor strapped to the window manager like an outboard motor, it's housed more like an automobile engine. ** various comp structs have been merged into other places (eg. E_Comp_Zone is now just part of E_Zone where applicable), leading to a large deduplication of attributes ** awful E_Comp_Win is totally dead, having been replaced with e_comp_object smart objects which work just like normal canvas objects ** protocol-specific window management and compositor functionality is now kept exclusively in backend files ** e_pixmap api provides generic client finding and rendering api ** screen/xinerama screens are now provided directly by compositor on startup and re-set on change ** e_comp_render_update finally replaced with eina_tiler ** wayland compositor no longer creates X windows ** compositor e_layout removed entirely * e_container is gone. this was made unnecessary in E18, but I kept it to avoid having too much code churn in one release. its sole purpose was to catch some events and handle window stacking, both of which are now just done by the compositor infra * e_manager is just for screensaver and keybind stuff now, possibly remove later? * e_border is gone along with a lot of its api. e_client has replaced it, and e_client has been rewritten completely; some parts may be similar, but the design now relies upon having a functional compositor ** window configuration/focus functions are all removed. all windows are now managed solely with evas_object_X functions on the "frame" member of a client, just as any other canvas object can be managed. *** do NOT set interceptors on a client's comp_object. seriously. * startup order rewritten: compositor now starts much earlier, other things just use attrs and members of the compositor * ecore_x_pointer_xy_get usage replaced with ecore_evas_pointer_xy_get * e_popup is totally gone, existing usage replaced by e_comp_object_util_add where applicable, otherwise just placed normally on the canvas * deskmirror is (more) broken for now * illume is totally fucked * Ecore_X_Window replaced with Ecore_Window in most cases * edge binding XWindows replaced with regular canvas objects * some E_Win functionality has changed such that delete callbacks are now correctly called in ALL cases. various dialogs have been updated to not crash as a result comp files and descriptions: e_comp.c - overall compositor functions, rendering/update loop, shape cutting e_comp_x.c - X window management and compositor functionality e_comp_wl.c - Wayland surface management and compositor functionality e_comp_canvas.c - general compositor canvas functions and utilities e_comp_object.c - E_Client->frame member for managing clients as Evas_Objects, utility functions for adding objects to the compositor rendering systems additional authors: ivan.briano@intel.com feature: new compositor removal: e_border, e_container, e_popup
2014-01-14 17:19:12 -08:00
else if (obj->type == E_COMP_TYPE)
zone = e_zone_current_get((E_Comp *)obj);
else if (obj->type == E_ZONE_TYPE)
compositor rewrite / charlie-foxtrot situation huge fustercluck commit because there wasn't really a way to separate out the changes. better to just rip it all out at once. * compositor and window management completely rewritten. this was the goal for E19, but it pretty much required everything existing to be scrapped since it wasn't optimized, streamlined, or sensible. now instead of having the compositor strapped to the window manager like an outboard motor, it's housed more like an automobile engine. ** various comp structs have been merged into other places (eg. E_Comp_Zone is now just part of E_Zone where applicable), leading to a large deduplication of attributes ** awful E_Comp_Win is totally dead, having been replaced with e_comp_object smart objects which work just like normal canvas objects ** protocol-specific window management and compositor functionality is now kept exclusively in backend files ** e_pixmap api provides generic client finding and rendering api ** screen/xinerama screens are now provided directly by compositor on startup and re-set on change ** e_comp_render_update finally replaced with eina_tiler ** wayland compositor no longer creates X windows ** compositor e_layout removed entirely * e_container is gone. this was made unnecessary in E18, but I kept it to avoid having too much code churn in one release. its sole purpose was to catch some events and handle window stacking, both of which are now just done by the compositor infra * e_manager is just for screensaver and keybind stuff now, possibly remove later? * e_border is gone along with a lot of its api. e_client has replaced it, and e_client has been rewritten completely; some parts may be similar, but the design now relies upon having a functional compositor ** window configuration/focus functions are all removed. all windows are now managed solely with evas_object_X functions on the "frame" member of a client, just as any other canvas object can be managed. *** do NOT set interceptors on a client's comp_object. seriously. * startup order rewritten: compositor now starts much earlier, other things just use attrs and members of the compositor * ecore_x_pointer_xy_get usage replaced with ecore_evas_pointer_xy_get * e_popup is totally gone, existing usage replaced by e_comp_object_util_add where applicable, otherwise just placed normally on the canvas * deskmirror is (more) broken for now * illume is totally fucked * Ecore_X_Window replaced with Ecore_Window in most cases * edge binding XWindows replaced with regular canvas objects * some E_Win functionality has changed such that delete callbacks are now correctly called in ALL cases. various dialogs have been updated to not crash as a result comp files and descriptions: e_comp.c - overall compositor functions, rendering/update loop, shape cutting e_comp_x.c - X window management and compositor functionality e_comp_wl.c - Wayland surface management and compositor functionality e_comp_canvas.c - general compositor canvas functions and utilities e_comp_object.c - E_Client->frame member for managing clients as Evas_Objects, utility functions for adding objects to the compositor rendering systems additional authors: ivan.briano@intel.com feature: new compositor removal: e_border, e_container, e_popup
2014-01-14 17:19:12 -08:00
zone = e_zone_current_get(((E_Zone *)obj)->comp);
else
zone = e_util_zone_current_get(e_manager_current_get());
}
if (!zone) zone = e_util_zone_current_get(e_manager_current_get());
if (!zone) return;
IF_RELEASE(_params);
if (params && params[0])
_params = eina_stringshare_add(params);
/* if (zone) evry_show(zone, _params); */
if (_idler) ecore_idle_enterer_del(_idler);
_idler = ecore_idle_enterer_add(_e_mod_run_defer_cb, zone);
}
static void
_e_mod_action_cb_edge(E_Object *obj __UNUSED__, const char *params, E_Event_Zone_Edge *ev)
{
IF_RELEASE(_params);
if (params && params[0])
_params = eina_stringshare_add(params);
if (_idler) ecore_idle_enterer_del(_idler);
evry_show(ev->zone, ev->edge, _params, EINA_TRUE);
}
/* menu item callback(s) */
static void
_e_mod_run_cb(void *data __UNUSED__, E_Menu *m, E_Menu_Item *mi __UNUSED__)
{
IF_RELEASE(_params);
ecore_idle_enterer_add(_e_mod_run_defer_cb, m->zone);
}
/* menu item add hook */
static void
_e_mod_menu_add(void *data __UNUSED__, E_Menu *m)
{
E_Menu_Item *mi;
mi = e_menu_item_new(m);
e_menu_item_label_set(mi, _("Run Everything"));
e_util_menu_item_theme_icon_set(mi, "system-run");
e_menu_item_callback_set(mi, _e_mod_run_cb, NULL);
}