enlightenment/src/modules/systray/e_mod_main.c

548 lines
12 KiB
C
Raw Normal View History

#include "e_mod_main.h"
static const char _Name[] = "Systray";
static const char _name[] = "systray";
static const char _group_gadget[] = "e/modules/systray/main";
static const char _sig_source[] = "e";
static E_Module *systray_mod = NULL;
static Systray_Context *ctx = NULL;
EINTERN Instance *instance = NULL; /* only one systray ever possible */
static char tmpbuf[4096]; /* general purpose buffer, just use immediately */
#define SYSTRAY_MIN_W 16
#define SYSTRAY_MIN_H 8
2012-06-20 05:55:44 -07:00
static Eina_Bool
_systray_site_is_safe(E_Gadcon_Site site)
{
/* NB: filter out sites we know are not safe for a systray to sit.
2012-06-20 05:55:44 -07:00
* This was done so that systray could be put into illume indicator
* (or anywhere else really) that is 'safe' for systray to be.
* Pretty much, this is anywhere but toolbars at the moment */
return !e_gadcon_site_is_any_toolbar(site);
}
static const char *
_systray_theme_path(void)
{
#define TF "/e-module-systray.edj"
unsigned int dirlen;
const char *moddir = e_module_dir_get(systray_mod);
dirlen = strlen(moddir);
if (dirlen >= sizeof(tmpbuf) - sizeof(TF))
return NULL;
memcpy(tmpbuf, moddir, dirlen);
memcpy(tmpbuf + dirlen, TF, sizeof(TF));
return tmpbuf;
#undef TF
}
2014-11-25 12:20:11 -08:00
#if 0
static void *
_cfg_data_create(E_Config_Dialog *cfd EINA_UNUSED)
{
E_Config_Dialog_Data *cfdata = calloc(1, sizeof(E_Config_Dialog_Data));
return cfdata;
}
static void
_cfg_data_free(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
{
free(cfdata);
}
static Evas_Object *
_cfg_widgets_create(E_Config_Dialog *cfd EINA_UNUSED, Evas *evas, E_Config_Dialog_Data *cfdata)
{
Evas_Object *o, *of;
o = e_widget_list_add(evas, 0, 0);
return o;
}
static int
_cfg_data_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
{
Instance *inst = cfd->data;
systray_size_updated(inst);
return 1;
}
static void
_cb_menu_cfg(void *data, E_Menu *m EINA_UNUSED, E_Menu_Item *mi EINA_UNUSED)
{
E_Config_Dialog_View *v;
v = calloc(1, sizeof(E_Config_Dialog_View));
v->create_cfdata = _cfg_data_create;
v->free_cfdata = _cfg_data_free;
v->basic.create_widgets = _cfg_widgets_create;
v->basic.apply_cfdata = _cfg_data_apply;
e_config_dialog_new(NULL, _("Systray Settings"), "E",
2013-06-08 13:49:15 -07:00
"_e_mod_systray_config_dialog",
NULL, 0, v, data);
}
2014-11-25 12:20:11 -08:00
#endif
static void
_systray_menu_new(Instance *inst, Evas_Event_Mouse_Down *ev)
{
E_Zone *zone;
E_Menu *m;
2014-11-25 12:20:11 -08:00
//E_Menu_Item *mi;
int x, y;
zone = e_util_zone_current_get(e_manager_current_get());
m = e_menu_new();
2014-11-25 12:20:11 -08:00
//mi = e_menu_item_new(m);
//e_menu_item_label_set(mi, _("Settings"));
//e_util_menu_item_theme_icon_set(mi, "configure");
//e_menu_item_callback_set(mi, _cb_menu_cfg, inst);
m = e_gadcon_client_util_menu_items_append(inst->gcc, m, 0);
e_gadcon_canvas_zone_geometry_get(inst->gcc->gadcon, &x, &y, NULL, NULL);
e_menu_activate_mouse(m, zone, x + ev->output.x, y + ev->output.y,
2012-06-20 05:55:44 -07:00
1, 1, E_MENU_POP_DIRECTION_AUTO, ev->timestamp);
evas_event_feed_mouse_up(inst->gcc->gadcon->evas, ev->button,
EVAS_BUTTON_NONE, ev->timestamp, NULL);
}
static void
_systray_cb_mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
{
Instance *inst = data;
Evas_Event_Mouse_Down *ev = event;
if (ev->button == 3)
_systray_menu_new(inst, ev);
}
static void
_systray_theme(Evas_Object *o, const char *shelf_style, const char *gc_style)
{
const char base_theme[] = "base/theme/modules/systray";
const char *path = _systray_theme_path();
char buf[128], *p;
size_t len, avail;
len = eina_strlcpy(buf, _group_gadget, sizeof(buf));
if (len >= sizeof(buf))
goto fallback;
p = buf + len;
*p = '/';
p++;
avail = sizeof(buf) - len - 2;
if (shelf_style && gc_style)
{
2012-06-20 05:55:44 -07:00
size_t r;
r = snprintf(p, avail, "%s/%s", shelf_style, gc_style);
if (r < avail && e_theme_edje_object_set(o, base_theme, buf))
return;
}
if (shelf_style)
{
2012-06-20 05:55:44 -07:00
size_t r;
r = eina_strlcpy(p, shelf_style, avail);
if (r < avail && e_theme_edje_object_set(o, base_theme, buf))
return;
}
if (gc_style)
{
2012-06-20 05:55:44 -07:00
size_t r;
r = eina_strlcpy(p, gc_style, avail);
if (r < avail && e_theme_edje_object_set(o, base_theme, buf))
return;
}
if (e_theme_edje_object_set(o, base_theme, _group_gadget))
return;
if (shelf_style && gc_style)
{
2012-06-20 05:55:44 -07:00
size_t r;
r = snprintf(p, avail, "%s/%s", shelf_style, gc_style);
if (r < avail && edje_object_file_set(o, path, buf))
return;
}
if (shelf_style)
{
2012-06-20 05:55:44 -07:00
size_t r;
r = eina_strlcpy(p, shelf_style, avail);
if (r < avail && edje_object_file_set(o, path, buf))
return;
}
if (gc_style)
{
2012-06-20 05:55:44 -07:00
size_t r;
r = eina_strlcpy(p, gc_style, avail);
if (r < avail && edje_object_file_set(o, path, buf))
return;
}
2012-06-20 05:55:44 -07:00
fallback:
edje_object_file_set(o, path, _group_gadget);
}
static E_Gadcon_Client *
_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
{
Instance *inst;
// fprintf(stderr, "SYSTRAY: init name=%s, id=%s, style=%s\n", name, id, style);
if (!systray_mod)
return NULL;
if ((!id) || (instance))
{
2012-06-20 05:55:44 -07:00
e_util_dialog_internal
(_("Another systray exists"),
_("There can be only one systray gadget and "
"another one already exists."));
return NULL;
}
inst = E_NEW(Instance, 1);
if (!inst)
return NULL;
inst->evas = gc->evas;
inst->comp = e_comp;
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
if (!inst->comp)
{
2012-06-20 05:55:44 -07:00
E_FREE(inst);
return NULL;
}
inst->ui.gadget = edje_object_add(inst->evas);
_systray_theme(inst->ui.gadget, gc->shelf ? gc->shelf->style : NULL, style);
inst->gcc = e_gadcon_client_new(gc, name, id, style, inst->ui.gadget);
if (!inst->gcc)
{
2012-06-20 05:55:44 -07:00
evas_object_del(inst->ui.gadget);
E_FREE(inst);
return NULL;
}
e_gadcon_client_min_size_set(inst->gcc, SYSTRAY_MIN_W, SYSTRAY_MIN_H);
inst->gcc->data = inst;
evas_object_event_callback_add(inst->ui.gadget, EVAS_CALLBACK_MOUSE_DOWN,
2012-06-20 05:55:44 -07:00
_systray_cb_mouse_down, inst);
inst->notifier = systray_notifier_host_new(inst, inst->gcc->gadcon);
instance = inst;
return inst->gcc;
}
/* Called when Gadget_Container says stop */
static void
_gc_shutdown(E_Gadcon_Client *gcc)
{
Instance *inst = gcc->data;
// fprintf(stderr, "SYSTRAY: shutdown %p, inst=%p\n", gcc, inst);
if (!inst)
return;
systray_notifier_host_free(inst->notifier);
evas_object_del(inst->ui.gadget);
if (instance == inst)
instance = NULL;
if (inst->job.size_apply)
ecore_job_del(inst->job.size_apply);
E_FREE(inst);
gcc->data = NULL;
}
static void
_gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient)
{
Instance *inst = gcc->data;
const char *sig;
if (!inst)
return;
switch (orient)
{
case E_GADCON_ORIENT_FLOAT:
2012-06-20 05:55:44 -07:00
sig = "e,action,orient,float";
break;
case E_GADCON_ORIENT_HORIZ:
2012-06-20 05:55:44 -07:00
sig = "e,action,orient,horiz";
break;
case E_GADCON_ORIENT_VERT:
2012-06-20 05:55:44 -07:00
sig = "e,action,orient,vert";
break;
case E_GADCON_ORIENT_LEFT:
2012-06-20 05:55:44 -07:00
sig = "e,action,orient,left";
break;
case E_GADCON_ORIENT_RIGHT:
2012-06-20 05:55:44 -07:00
sig = "e,action,orient,right";
break;
case E_GADCON_ORIENT_TOP:
2012-06-20 05:55:44 -07:00
sig = "e,action,orient,top";
break;
case E_GADCON_ORIENT_BOTTOM:
2012-06-20 05:55:44 -07:00
sig = "e,action,orient,bottom";
break;
case E_GADCON_ORIENT_CORNER_TL:
2012-06-20 05:55:44 -07:00
sig = "e,action,orient,corner_tl";
break;
case E_GADCON_ORIENT_CORNER_TR:
2012-06-20 05:55:44 -07:00
sig = "e,action,orient,corner_tr";
break;
case E_GADCON_ORIENT_CORNER_BL:
2012-06-20 05:55:44 -07:00
sig = "e,action,orient,corner_bl";
break;
case E_GADCON_ORIENT_CORNER_BR:
2012-06-20 05:55:44 -07:00
sig = "e,action,orient,corner_br";
break;
case E_GADCON_ORIENT_CORNER_LT:
2012-06-20 05:55:44 -07:00
sig = "e,action,orient,corner_lt";
break;
case E_GADCON_ORIENT_CORNER_RT:
2012-06-20 05:55:44 -07:00
sig = "e,action,orient,corner_rt";
break;
case E_GADCON_ORIENT_CORNER_LB:
2012-06-20 05:55:44 -07:00
sig = "e,action,orient,corner_lb";
break;
case E_GADCON_ORIENT_CORNER_RB:
2012-06-20 05:55:44 -07:00
sig = "e,action,orient,corner_rb";
break;
default:
2012-06-20 05:55:44 -07:00
sig = "e,action,orient,horiz";
}
edje_object_signal_emit(inst->ui.gadget, sig, _sig_source);
edje_object_message_signal_process(inst->ui.gadget);
}
static const char *
_gc_label(const E_Gadcon_Client_Class *client_class __UNUSED__)
{
return _("Systray");
}
static Evas_Object *
_gc_icon(const E_Gadcon_Client_Class *client_class __UNUSED__, Evas *evas)
{
Evas_Object *o;
o = edje_object_add(evas);
edje_object_file_set(o, _systray_theme_path(), "icon");
return o;
}
static const char *
_gc_id_new(const E_Gadcon_Client_Class *client_class __UNUSED__)
{
return _name;
}
static const E_Gadcon_Client_Class _gc_class =
{
2012-06-20 05:55:44 -07:00
GADCON_CLIENT_CLASS_VERSION, _name,
{
_gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL,
_systray_site_is_safe
},
E_GADCON_CLIENT_STYLE_PLAIN
};
EAPI E_Module_Api e_modapi = {E_MODULE_API_VERSION, _Name};
EAPI void *
e_modapi_init(E_Module *m)
{
systray_mod = m;
ctx = calloc(1, sizeof(Systray_Context));
ctx->conf_edd = E_CONFIG_DD_NEW("Systray_Config", Systray_Config);
#undef T
#undef D
#define T Systray_Config
#define D ctx->conf_edd
ctx->config = e_config_domain_load(_name, ctx->conf_edd);
if (!ctx->config)
ctx->config = calloc(1, sizeof(Systray_Config));
e_gadcon_provider_register(&_gc_class);
systray_notifier_host_init();
return ctx;
}
EAPI int
e_modapi_shutdown(E_Module *m __UNUSED__)
{
e_gadcon_provider_unregister(&_gc_class);
systray_mod = NULL;
systray_notifier_host_shutdown();
E_CONFIG_DD_FREE(ctx->conf_edd);
free(ctx->config);
free(ctx);
return 1;
}
EAPI int
e_modapi_save(E_Module *m __UNUSED__)
{
e_config_domain_save(_name, ctx->conf_edd, ctx->config);
return 1;
}
2012-06-20 05:55:44 -07:00
E_Gadcon_Orient
systray_orient_get(const Instance *inst)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(inst, E_GADCON_ORIENT_HORIZ);
return inst->gcc->gadcon->orient;
}
const E_Gadcon *
systray_gadcon_get(const Instance *inst)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(inst, NULL);
return inst->gcc->gadcon;
}
E_Gadcon_Client *
systray_gadcon_client_get(const Instance *inst)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(inst, NULL);
return inst->gcc;
}
const char *
systray_style_get(const Instance *inst)
{
const char *style;
EINA_SAFETY_ON_NULL_RETURN_VAL(inst, NULL);
style = inst->gcc->style;
if (!style)
style = "default";
return style;
}
Evas *
systray_evas_get(const Instance *inst)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(inst, NULL);
return inst->evas;
}
Evas_Object *
systray_edje_get(const Instance *inst)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(inst, NULL);
return inst->ui.gadget;
}
const Evas_Object *
systray_box_get(const Instance *inst)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(inst, NULL);
return edje_object_part_object_get(inst->ui.gadget, "box");
}
void
systray_edje_box_append(const Instance *inst, Evas_Object *child)
{
edje_object_part_box_append(inst->ui.gadget, "box", child);
}
void
systray_edje_box_prepend(const Instance *inst, Evas_Object *child)
{
edje_object_part_box_prepend(inst->ui.gadget, "box", child);
}
void
systray_edje_box_remove(const Instance *inst, Evas_Object *child)
{
edje_object_part_box_remove(inst->ui.gadget, "box", child);
}
int
systray_manager_number_get(const Instance *inst)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(inst, 0);
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
return inst->comp->num;
}
Ecore_X_Window
systray_root_get(const Instance *inst)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(inst, 0);
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
return inst->comp->man->root;
}
static void
_systray_size_apply_do(Instance *inst)
{
Evas_Coord w, h;
edje_object_message_signal_process(inst->ui.gadget);
edje_object_size_min_calc(inst->ui.gadget, &w, &h);
e_gadcon_client_min_size_set(inst->gcc, MAX(w, SYSTRAY_MIN_W), MAX(h, SYSTRAY_MIN_H));
}
static void
_systray_size_apply_delayed(void *data)
{
Instance *inst = data;
_systray_size_apply_do(inst);
inst->job.size_apply = NULL;
}
void
systray_size_updated(Instance *inst)
{
EINA_SAFETY_ON_NULL_RETURN(inst);
if (inst->job.size_apply) return;
inst->job.size_apply = ecore_job_add(_systray_size_apply_delayed, inst);
}
EINTERN Systray_Context *
systray_ctx_get(void)
{
return ctx;
}