diff options
author | Carsten Haitzler <raster@rasterman.com> | 2008-11-25 08:05:58 +0000 |
---|---|---|
committer | Carsten Haitzler <raster@rasterman.com> | 2008-11-25 08:05:58 +0000 |
commit | 5a29e1f6b5f834cea564cc305bb8f856c3f79cbd (patch) | |
tree | 1dca33de9c96d906278cf6b684fa78a201aeb639 /src/modules | |
parent | b9d7bcd3775dece81d8a4bb6ea0640e683126aae (diff) | |
download | enlightenment-5a29e1f6b5f834cea564cc305bb8f856c3f79cbd.tar.gz |
syscon module added - provides a system entry in main menu (build in one gone
now). syscon has a poup with buttons (configurale) that offer all the
logout/reboot etc. stuff. also able to extend with more items or inline them
into the theme too.
not complete. need config for being able to extend the syscon popup (and use
it) and no gui config for configuring what should appear and how it should
look. possibly theme should have custon elements for the ones curently using
button + icon look. also no keyboard control.
SVN revision: 37797
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/Makefile.am | 3 | ||||
-rw-r--r-- | src/modules/illume/e_mod_win.c | 6 | ||||
-rw-r--r-- | src/modules/syscon/.cvsignore | 7 | ||||
-rw-r--r-- | src/modules/syscon/Makefile.am | 31 | ||||
-rw-r--r-- | src/modules/syscon/e-module-syscon.edj | bin | 0 -> 6741 bytes | |||
-rw-r--r-- | src/modules/syscon/e_mod_main.c | 138 | ||||
-rw-r--r-- | src/modules/syscon/e_mod_main.h | 19 | ||||
-rw-r--r-- | src/modules/syscon/e_syscon.c | 406 | ||||
-rw-r--r-- | src/modules/syscon/e_syscon.h | 17 | ||||
-rw-r--r-- | src/modules/syscon/module.desktop.in | 6 |
10 files changed, 631 insertions, 2 deletions
diff --git a/src/modules/Makefile.am b/src/modules/Makefile.am index c91b01949b..d4c1b6c3ef 100644 --- a/src/modules/Makefile.am +++ b/src/modules/Makefile.am @@ -55,7 +55,8 @@ mixer \ conf_window_remembers \ conf_scale \ connman \ -illume +illume \ +syscon if HAVE_TEMPERATURE SUBDIRS += temperature diff --git a/src/modules/illume/e_mod_win.c b/src/modules/illume/e_mod_win.c index 2618d2512e..41cb7c4c47 100644 --- a/src/modules/illume/e_mod_win.c +++ b/src/modules/illume/e_mod_win.c @@ -644,7 +644,11 @@ _cb_slipshelf_close(const void *data, E_Slipshelf *ess, E_Slipshelf_Action actio } else { - e_syswin_show(slipwin); + E_Action *a; + + a = e_action_find("syscon"); + if ((a) && (a->func.go)) a->func.go(NULL, NULL); +// e_syswin_show(slipwin); } } diff --git a/src/modules/syscon/.cvsignore b/src/modules/syscon/.cvsignore new file mode 100644 index 0000000000..06d064a845 --- /dev/null +++ b/src/modules/syscon/.cvsignore @@ -0,0 +1,7 @@ +.deps +.libs +Makefile +Makefile.in +*.lo +module.la +module.desktop diff --git a/src/modules/syscon/Makefile.am b/src/modules/syscon/Makefile.am new file mode 100644 index 0000000000..59995bcef1 --- /dev/null +++ b/src/modules/syscon/Makefile.am @@ -0,0 +1,31 @@ +MAINTAINERCLEANFILES = Makefile.in +MODULE = syscon + +# data files for the module +filesdir = $(libdir)/enlightenment/modules/$(MODULE) +files_DATA = \ +e-module-$(MODULE).edj module.desktop + +EXTRA_DIST = $(files_DATA) + +# the module .so file +INCLUDES = -I. \ + -I$(top_srcdir) \ + -I$(top_srcdir)/src/modules/$(MODULE) \ + -I$(top_srcdir)/src/bin \ + -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/modules \ + @e_cflags@ +pkgdir = $(libdir)/enlightenment/modules/$(MODULE)/$(MODULE_ARCH) +pkg_LTLIBRARIES = module.la +module_la_SOURCES = e_mod_main.c \ + e_mod_main.h \ + e_syscon.c \ + e_syscon.h + +module_la_LIBADD = @e_libs@ @dlopen_libs@ +module_la_LDFLAGS = -module -avoid-version +module_la_DEPENDENCIES = $(top_builddir)/config.h + +uninstall: + rm -rf $(DESTDIR)$(libdir)/enlightenment/modules/$(MODULE) diff --git a/src/modules/syscon/e-module-syscon.edj b/src/modules/syscon/e-module-syscon.edj Binary files differnew file mode 100644 index 0000000000..05da0becf0 --- /dev/null +++ b/src/modules/syscon/e-module-syscon.edj diff --git a/src/modules/syscon/e_mod_main.c b/src/modules/syscon/e_mod_main.c new file mode 100644 index 0000000000..95b59e7eb8 --- /dev/null +++ b/src/modules/syscon/e_mod_main.c @@ -0,0 +1,138 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 + */ +#include "e.h" +#include "e_mod_main.h" + +/***************************************************************************/ +/**/ +/* actual module specifics */ + +static void _e_mod_action_syscon_cb(E_Object *obj, const char *params); +static int _e_mod_syscon_defer_cb(void *data); +static void _e_mod_syscon_cb(void *data, E_Menu *m, E_Menu_Item *mi); +static void _e_mod_menu_add(void *data, E_Menu *m); + +static E_Module *conf_module = NULL; +static E_Action *act = NULL; +static E_Int_Menu_Augmentation *maug = NULL; + +/**/ +/***************************************************************************/ + +/***************************************************************************/ +/**/ + +/**/ +/***************************************************************************/ + +/***************************************************************************/ +/**/ +/* module setup */ +EAPI E_Module_Api e_modapi = +{ + E_MODULE_API_VERSION, + "Syscon" +}; + +EAPI void * +e_modapi_init(E_Module *m) +{ + conf_module = m; + e_syscon_init(); + /* add module supplied action */ + act = e_action_add("syscon"); + if (act) + { + act->func.go = _e_mod_action_syscon_cb; + e_action_predef_name_set(_("System"), _("System Control"), "syscon", + NULL, NULL, 0); + } + maug = e_int_menus_menu_augmentation_add("main/10", _e_mod_menu_add, NULL, NULL, NULL); + e_module_delayed_set(m, 1); + return m; +} + +EAPI int +e_modapi_shutdown(E_Module *m) +{ + /* remove module-supplied menu additions */ + if (maug) + { + e_int_menus_menu_augmentation_del("main/10", maug); + maug = NULL; + } + /* remove module-supplied action */ + if (act) + { + e_action_predef_name_del(_("System"), _("System Controls")); + e_action_del("syscon"); + act = NULL; + } + e_syscon_shutdown(); + conf_module = NULL; + return 1; +} + +EAPI int +e_modapi_save(E_Module *m) +{ + return 1; +} + +/* action callback */ +static void +_e_mod_action_syscon_cb(E_Object *obj, const char *params) +{ + E_Zone *zone = NULL; + + // params = syscon action + now: + // desk_lock + // logout + // halt + // reboot + // suspend + // hibernate + if (obj) + { + if (obj->type == E_MANAGER_TYPE) + zone = e_util_zone_current_get((E_Manager *)obj); + else if (obj->type == E_CONTAINER_TYPE) + zone = e_util_zone_current_get(((E_Container *)obj)->manager); + else if (obj->type == E_ZONE_TYPE) + zone = e_util_zone_current_get(((E_Zone *)obj)->container->manager); + 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) e_syscon_show(zone, params); +} + +/* menu item callback(s) */ +static int +_e_mod_syscon_defer_cb(void *data) +{ + E_Zone *zone; + + zone = data; + if (zone) e_syscon_show(zone, NULL); + return 0; +} + +static void +_e_mod_syscon_cb(void *data, E_Menu *m, E_Menu_Item *mi) +{ + ecore_idle_enterer_add(_e_mod_syscon_defer_cb, m->zone); +} + +/* menu item add hook */ +static void +_e_mod_menu_add(void *data, E_Menu *m) +{ + E_Menu_Item *mi; + + mi = e_menu_item_new(m); + e_menu_item_label_set(mi, _("System")); + e_util_menu_item_edje_icon_set(mi, "enlightenment/system"); + e_menu_item_callback_set(mi, _e_mod_syscon_cb, NULL); +} diff --git a/src/modules/syscon/e_mod_main.h b/src/modules/syscon/e_mod_main.h new file mode 100644 index 0000000000..80737e6f5b --- /dev/null +++ b/src/modules/syscon/e_mod_main.h @@ -0,0 +1,19 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 + */ +#ifndef E_MOD_MAIN_H +#define E_MOD_MAIN_H + +#define E_TYPEDEFS 1 +#include "e_syscon.h" + +#undef E_TYPEDEFS +#include "e_syscon.h" + +EAPI extern E_Module_Api e_modapi; + +EAPI void *e_modapi_init (E_Module *m); +EAPI int e_modapi_shutdown (E_Module *m); +EAPI int e_modapi_save (E_Module *m); + +#endif diff --git a/src/modules/syscon/e_syscon.c b/src/modules/syscon/e_syscon.c new file mode 100644 index 0000000000..787359fc86 --- /dev/null +++ b/src/modules/syscon/e_syscon.c @@ -0,0 +1,406 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 + */ +#include "e.h" +#include "e_mod_main.h" + +/* local subsystem functions */ +static int _cb_key_down(void *data, int type, void *event); +static int _cb_mouse_down(void *data, int type, void *event); +static int _cb_mouse_up(void *data, int type, void *event); +static int _cb_mouse_move(void *data, int type, void *event); +static int _cb_mouse_wheel(void *data, int type, void *event); +static void _cb_signal_close(void *data, Evas_Object *obj, const char *emission, const char *source); +static void _cb_signal_syscon(void *data, Evas_Object *obj, const char *emission, const char *source); +static void _cb_signal_action(void *data, Evas_Object *obj, const char *emission, const char *source); +static int _cb_timeout_defaction(void *data); + +/* local subsystem globals */ +static E_Popup *popup = NULL; +static Ecore_X_Window input_window = 0; +static const char *do_defact = NULL; +static Eina_List *handlers = NULL; +static Evas_Object *o_bg = NULL; +static Evas_Object *o_flow_main = NULL; +static Evas_Object *o_flow_secondary = NULL; +static Evas_Object *o_flow_extra = NULL; +static int inevas = 0; +static Ecore_Timer *deftimer = NULL; + +/* externally accessible functions */ +EAPI int +e_syscon_init(void) +{ + return 1; +} + +EAPI int +e_syscon_shutdown(void) +{ + e_syscon_hide(); + return 1; +} + +EAPI int +e_syscon_show(E_Zone *zone, const char *defact) +{ + Evas_Object *o, *o2; + Evas_Coord mw, mh; + int x, y, w, h; + int iw, ih; + Eina_List *l; + + if (popup) return 0; + + input_window = ecore_x_window_input_new(zone->container->win, zone->x, + zone->y, zone->w, zone->h); + ecore_x_window_show(input_window); + if (!e_grabinput_get(input_window, 1, input_window)) + { + ecore_x_window_del(input_window); + input_window = 0; + return 0; + } + + popup = e_popup_new(zone, 0, 0, 1, 1); + if (!popup) + { + e_grabinput_release(input_window, input_window); + ecore_x_window_del(input_window); + input_window = 0; + return 0; + } + evas_event_freeze(popup->evas); + e_popup_layer_set(popup, 500); + + handlers = eina_list_append + (handlers, ecore_event_handler_add + (ECORE_X_EVENT_KEY_DOWN, _cb_key_down, NULL)); + handlers = eina_list_append + (handlers, ecore_event_handler_add + (ECORE_X_EVENT_MOUSE_BUTTON_DOWN, _cb_mouse_down, NULL)); + handlers = eina_list_append + (handlers, ecore_event_handler_add + (ECORE_X_EVENT_MOUSE_BUTTON_UP, _cb_mouse_up, NULL)); + handlers = eina_list_append + (handlers, ecore_event_handler_add + (ECORE_X_EVENT_MOUSE_MOVE, _cb_mouse_move, NULL)); + handlers = eina_list_append + (handlers, ecore_event_handler_add + (ECORE_X_EVENT_MOUSE_WHEEL, _cb_mouse_wheel, NULL)); + + o = edje_object_add(popup->evas); + o_bg = o; + e_theme_edje_object_set(o, "base/theme/syscon", + "e/widgets/syscon/main"); + edje_object_part_text_set(o, "e.text.label", _("Cancel")); + edje_object_signal_callback_add(o, "e,action,close", "", _cb_signal_close, NULL); + edje_object_signal_callback_add(o, "e,action,syscon", "*", _cb_signal_syscon, NULL); + + // main (default): + // halt | suspend | desk_lock + // secondary (default): + // reboot | hibernate | logout + // extra (example for illume): + // home | close | kill + + iw = 64 * e_scale; + ih = 64 * e_scale; + + o = e_flowlayout_add(popup->evas); + o_flow_main = o; + e_flowlayout_orientation_set(o, 1); + e_flowlayout_flowdirection_set(o, 1, 1); + e_flowlayout_homogenous_set(o, 1); + + o = e_flowlayout_add(popup->evas); + o_flow_secondary = o; + e_flowlayout_orientation_set(o, 1); + e_flowlayout_flowdirection_set(o, 1, 1); + e_flowlayout_homogenous_set(o, 1); + + o = e_flowlayout_add(popup->evas); + o_flow_extra = o; + e_flowlayout_orientation_set(o, 1); + e_flowlayout_flowdirection_set(o, 1, 1); + e_flowlayout_homogenous_set(o, 1); + + for (l = e_config->syscon.actions; l; l = l->next) + { + E_Config_Syscon_Action *sca; + char buf[1024]; + E_Action *a; + int disabled; + + sca = l->data; + if (!sca->action) continue; + a = e_action_find(sca->action); + if (!a) continue; + disabled = 0; + if ((!strcmp(sca->action, "logout")) && + (!e_sys_action_possible_get(E_SYS_LOGOUT))) disabled = 1; + else if ((!strcmp(sca->action, "halt")) && + (!e_sys_action_possible_get(E_SYS_HALT))) disabled = 1; + else if ((!strcmp(sca->action, "halt_now")) && + (!e_sys_action_possible_get(E_SYS_HALT_NOW))) disabled = 1; + else if ((!strcmp(sca->action, "reboot")) && + (!e_sys_action_possible_get(E_SYS_REBOOT))) disabled = 1; + else if ((!strcmp(sca->action, "suspend")) && + (!e_sys_action_possible_get(E_SYS_SUSPEND))) disabled = 1; + else if ((!strcmp(sca->action, "hibernate")) && + (!e_sys_action_possible_get(E_SYS_HIBERNATE))) disabled = 1; + o = edje_object_add(popup->evas); + edje_object_signal_callback_add(o, "e,action,click", "", _cb_signal_action, sca); + if (sca->button) + { + snprintf(buf, sizeof(buf), "e/widgets/syscon/item/%s", + sca->button); + e_theme_edje_object_set(o, "base/theme/widgets", buf); + } + else + e_theme_edje_object_set(o, "base/theme/widgets", + "e/widgets/syscon/item/button"); +// edje_object_part_text_set(o, "e.text.label", sca->action); + if (sca->icon) + { + o2 = edje_object_add(popup->evas); + e_util_edje_icon_set(o2, sca->icon); + edje_object_part_swallow(o, "e.swallow.icon", o2); + evas_object_show(o2); + if (disabled) + edje_object_signal_emit(o2, "e,state,disabled", "e"); + } + if (disabled) + edje_object_signal_emit(o, "e,state,disabled", "e"); + if (sca->is_main) + { + e_flowlayout_pack_end(o_flow_main, o); + iw = ih = e_config->syscon.main.icon_size * e_scale; + } + else + { + e_flowlayout_pack_end(o_flow_secondary, o); + iw = ih = e_config->syscon.secondary.icon_size * e_scale; + } + e_flowlayout_pack_options_set(o, 1, 1, 0, 0, 0.5, 0.5, + iw, ih, iw, ih); + evas_object_show(o); + } + // FIXME: "extra" list needs to be handled + + e_flowlayout_fill_set(o_flow_main, 1); + edje_object_part_swallow(o_bg, "e.swallow.main", o_flow_main); + e_flowlayout_fill_set(o_flow_secondary, 1); + edje_object_part_swallow(o_bg, "e.swallow.secondary", o_flow_secondary); + e_flowlayout_fill_set(o_flow_extra, 1); + edje_object_part_swallow(o_bg, "e.swallow.extra", o_flow_extra); + + evas_object_resize(o_bg, zone->w, zone->h); + edje_object_calc_force(o_bg); + + e_flowlayout_min_size_get(o_flow_main, &mw, &mh); + edje_extern_object_min_size_set(o_flow_main, mw, mh); + edje_object_part_swallow(o_bg, "e.swallow.main", o_flow_main); + e_flowlayout_min_size_get(o_flow_secondary, &mw, &mh); + edje_extern_object_min_size_set(o_flow_secondary, mw, mh); + edje_object_part_swallow(o_bg, "e.swallow.secondary", o_flow_secondary); + e_flowlayout_min_size_get(o_flow_extra, &mw, &mh); + edje_extern_object_min_size_set(o_flow_extra, mw, mh); + edje_object_part_swallow(o_bg, "e.swallow.extra", o_flow_extra); + + edje_object_size_min_calc(o_bg, &mw, &mh); + w = mw; + if (w > zone->w) w = zone->w; + x = (zone->w - w) / 2; + h = mh; + if (h > zone->h) h = zone->h; + y = (zone->h - h) / 2; + + e_popup_move_resize(popup, x, y, w, h); + evas_object_move(o_bg, 0, 0); + evas_object_resize(o_bg, w, h); + evas_object_show(o_bg); + e_popup_edje_bg_object_set(popup, o_bg); + + if (e_config->syscon.do_input) + { + deftimer = ecore_timer_add(e_config->syscon.timeout, _cb_timeout_defaction, NULL); + if (defact) do_defact = eina_stringshare_add(defact); + } + + evas_event_thaw(popup->evas); + inevas = 0; + e_popup_show(popup); + return 1; +} + +EAPI void +e_syscon_hide(void) +{ + if (!popup) return; + + if (deftimer) + { + ecore_timer_del(deftimer); + deftimer = NULL; + } + if (do_defact) eina_stringshare_del(do_defact); + do_defact = NULL; + while (handlers) + { + ecore_event_handler_del(handlers->data); + handlers = eina_list_remove_list(handlers, handlers); + } + e_popup_hide(popup); + e_object_del(E_OBJECT(popup)); + popup = NULL; + e_grabinput_release(input_window, input_window); + ecore_x_window_del(input_window); + input_window = 0; +} + +/* local subsystem functions */ +static int +_cb_key_down(void *data, int type, void *event) +{ + Ecore_X_Event_Key_Down *ev; + + ev = event; + if (ev->event_win != input_window) return 1; + if (!strcmp(ev->keysymbol, "Escape")) + { + e_syscon_hide(); + } + else if (!strcmp(ev->keysymbol, "Up")) + { + // FIXME: implement focus and key control... eventually + } + + return 1; +} + +static int +_cb_mouse_down(void *data, int type, void *event) +{ + Ecore_X_Event_Mouse_Button_Down *ev; + Evas_Button_Flags flags = EVAS_BUTTON_NONE; + + ev = event; + if (ev->event_win != input_window) return 1; + if (ev->double_click) flags |= EVAS_BUTTON_DOUBLE_CLICK; + if (ev->triple_click) flags |= EVAS_BUTTON_TRIPLE_CLICK; + if ((ev->x < popup->x) || (ev->x >= (popup->x + popup->w)) || + (ev->y < popup->y) || (ev->y >= (popup->y + popup->h))) + { + e_syscon_hide(); + return 1; + } + evas_event_feed_mouse_down(popup->evas, + ev->button, flags, + ev->time, NULL); + return 1; +} + +static int +_cb_mouse_up(void *data, int type, void *event) +{ + Ecore_X_Event_Mouse_Button_Up *ev; + + ev = event; + if (ev->event_win != input_window) return 1; + evas_event_feed_mouse_up(popup->evas, + ev->button, EVAS_BUTTON_NONE, + ev->time, NULL); + return 1; +} + +static int +_cb_mouse_move(void *data, int type, void *event) +{ + Ecore_X_Event_Mouse_Move *ev; + + ev = event; + if (ev->event_win != input_window) return 1; + if (!inevas) + { + evas_event_feed_mouse_in(popup->evas, ev->time, NULL); + inevas = 1; + } + evas_event_feed_mouse_move(popup->evas, + ev->x - popup->x, + ev->y - popup->y, + ev->time, NULL); + return 1; +} + +static int +_cb_mouse_wheel(void *data, int type, void *event) +{ + Ecore_X_Event_Mouse_Wheel *ev; + + ev = event; + if (ev->event_win != input_window) return 1; + evas_event_feed_mouse_wheel(popup->evas, + ev->direction, ev->z, + ev->time, NULL); + return 1; +} + +static void +_cb_signal_close(void *data, Evas_Object *obj, const char *emission, const char *source) +{ + e_syscon_hide(); +} + +static void +_do_action_name(const char *action) +{ + Eina_List *l; + + for (l = e_config->syscon.actions; l; l = l->next) + { + E_Config_Syscon_Action *sca; + E_Action *a; + + sca = l->data; + if (!sca->action) continue; + if (!strcmp(sca->action, action)) + { + a = e_action_find(sca->action); + if (!a) break; + if (a) a->func.go(NULL, sca->params); + break; + } + } +} + +static void +_cb_signal_syscon(void *data, Evas_Object *obj, const char *emission, const char *source) +{ + e_syscon_hide(); + _do_action_name(source); +} + +static void +_cb_signal_action(void *data, Evas_Object *obj, const char *emission, const char *source) +{ + E_Config_Syscon_Action *sca; + E_Action *a; + + e_syscon_hide(); + sca = data; + if (!sca) return; + a = e_action_find(sca->action); + if (!a) return; + if (a) a->func.go(NULL, sca->params); +} + +static int +_cb_timeout_defaction(void *data) +{ + deftimer = NULL; + if (!do_defact) return 0; + e_syscon_hide(); + _do_action_name(do_defact); + return 0; +} diff --git a/src/modules/syscon/e_syscon.h b/src/modules/syscon/e_syscon.h new file mode 100644 index 0000000000..2187b0509f --- /dev/null +++ b/src/modules/syscon/e_syscon.h @@ -0,0 +1,17 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 + */ +#ifdef E_TYPEDEFS + +#else +#ifndef E_SYSCON_H +#define E_SYSCON_H + +EAPI int e_syscon_init(void); +EAPI int e_syscon_shutdown(void); + +EAPI int e_syscon_show(E_Zone *zone, const char *defact); +EAPI void e_syscon_hide(void); + +#endif +#endif diff --git a/src/modules/syscon/module.desktop.in b/src/modules/syscon/module.desktop.in new file mode 100644 index 0000000000..243e71e63a --- /dev/null +++ b/src/modules/syscon/module.desktop.in @@ -0,0 +1,6 @@ +[Desktop Entry] +Type=Link +Name=System Controls +Icon=e-module-syscon +Comment=<title>System Controls Module</title><br>This module provides a unified popup<br>dialog for all the system actions<br>in Enlightenment. +X-Enlightenment-ModuleType=system |