2 #include "e_mod_main.h"
4 /* local subsystem functions */
5 static Eina_Bool _cb_key_down(void *data, int type, void *event);
6 static Eina_Bool _cb_mouse_down(void *data, int type, void *event);
7 static Eina_Bool _cb_mouse_up(void *data, int type, void *event);
8 static Eina_Bool _cb_mouse_move(void *data, int type, void *event);
9 static Eina_Bool _cb_mouse_wheel(void *data, int type, void *event);
10 static void _cb_signal_close(void *data, Evas_Object *obj, const char *emission, const char *source);
11 static void _cb_signal_syscon(void *data, Evas_Object *obj, const char *emission, const char *source);
12 static void _cb_signal_action(void *data, Evas_Object *obj, const char *emission, const char *source);
13 static void _cb_signal_action_extra(void *data, Evas_Object *obj, const char *emission, const char *source);
14 static Eina_Bool _cb_timeout_defaction(void *data);
16 /* local subsystem globals */
17 static E_Popup *popup = NULL;
18 static Ecore_X_Window input_window = 0;
19 static const char *do_defact = NULL;
20 static Eina_List *handlers = NULL;
21 static Evas_Object *o_bg = NULL;
22 static Evas_Object *o_flow_main = NULL;
23 static Evas_Object *o_flow_secondary = NULL;
24 static Evas_Object *o_flow_extra = NULL;
25 static int inevas = 0;
26 static Ecore_Timer *deftimer = NULL;
27 static double show_time = 0.0;
28 static int act_count = 0;
30 /* externally accessible functions */
38 e_syscon_shutdown(void)
45 e_syscon_show(E_Zone *zone, const char *defact)
49 int x, y, w, h, zx, zy, zw, zh;
54 t = ecore_loop_time_get();
57 if ((t - show_time) > 0.5)
59 for (l = e_config->syscon.actions; l; l = l->next)
61 E_Config_Syscon_Action *sca;
64 if (!(sca = l->data)) continue;
65 if (!sca->action) continue;
66 a = e_action_find(sca->action);
68 if (sca->is_main == 2)
70 a->func.go(NULL, sca->params);
79 input_window = ecore_x_window_input_new(zone->container->win, zone->x,
80 zone->y, zone->w, zone->h);
81 ecore_x_window_show(input_window);
82 if (!e_grabinput_get(input_window, 1, input_window))
84 ecore_x_window_free(input_window);
89 popup = e_popup_new(zone, 0, 0, 1, 1);
92 e_grabinput_release(input_window, input_window);
93 ecore_x_window_free(input_window);
97 evas_event_freeze(popup->evas);
98 e_popup_layer_set(popup, 500);
100 handlers = eina_list_append
101 (handlers, ecore_event_handler_add
102 (ECORE_EVENT_KEY_DOWN, _cb_key_down, NULL));
103 handlers = eina_list_append
104 (handlers, ecore_event_handler_add
105 (ECORE_EVENT_MOUSE_BUTTON_DOWN, _cb_mouse_down, NULL));
106 handlers = eina_list_append
107 (handlers, ecore_event_handler_add
108 (ECORE_EVENT_MOUSE_BUTTON_UP, _cb_mouse_up, NULL));
109 handlers = eina_list_append
110 (handlers, ecore_event_handler_add
111 (ECORE_EVENT_MOUSE_MOVE, _cb_mouse_move, NULL));
112 handlers = eina_list_append
113 (handlers, ecore_event_handler_add
114 (ECORE_EVENT_MOUSE_WHEEL, _cb_mouse_wheel, NULL));
116 o = edje_object_add(popup->evas);
118 e_theme_edje_object_set(o, "base/theme/syscon",
119 "e/widgets/syscon/main");
120 edje_object_part_text_set(o, "e.text.label", _("Cancel"));
121 edje_object_signal_callback_add(o, "e,action,close", "",
122 _cb_signal_close, NULL);
123 edje_object_signal_callback_add(o, "e,action,syscon", "*",
124 _cb_signal_syscon, NULL);
130 // halt | suspend | desk_lock
131 // secondary (default):
132 // reboot | hibernate | logout
133 // extra (example for illume):
134 // home | close | kill
137 o = e_flowlayout_add(popup->evas);
139 e_flowlayout_orientation_set(o, 1);
140 e_flowlayout_flowdirection_set(o, 1, 1);
141 e_flowlayout_homogenous_set(o, 1);
143 o = e_flowlayout_add(popup->evas);
144 o_flow_secondary = o;
145 e_flowlayout_orientation_set(o, 1);
146 e_flowlayout_flowdirection_set(o, 1, 1);
147 e_flowlayout_homogenous_set(o, 1);
149 o = e_flowlayout_add(popup->evas);
151 e_flowlayout_orientation_set(o, 1);
152 e_flowlayout_flowdirection_set(o, 1, 1);
153 e_flowlayout_homogenous_set(o, 1);
155 for (l = e_config->syscon.actions; l; l = l->next)
157 E_Config_Syscon_Action *sca;
162 if (!(sca = l->data)) continue;
163 if (!sca->action) continue;
164 a = e_action_find(sca->action);
167 if ((!strcmp(sca->action, "logout")) &&
168 (!e_sys_action_possible_get(E_SYS_LOGOUT))) disabled = 1;
169 else if ((!strcmp(sca->action, "halt")) &&
170 (!e_sys_action_possible_get(E_SYS_HALT))) disabled = 1;
171 else if ((!strcmp(sca->action, "halt_now")) &&
172 (!e_sys_action_possible_get(E_SYS_HALT_NOW))) disabled = 1;
173 else if ((!strcmp(sca->action, "reboot")) &&
174 (!e_sys_action_possible_get(E_SYS_REBOOT))) disabled = 1;
175 else if ((!strcmp(sca->action, "suspend")) &&
176 (!e_sys_action_possible_get(E_SYS_SUSPEND))) disabled = 1;
177 else if ((!strcmp(sca->action, "hibernate")) &&
178 (!e_sys_action_possible_get(E_SYS_HIBERNATE))) disabled = 1;
179 o = edje_object_add(popup->evas);
180 edje_object_signal_callback_add(o, "e,action,click", "",
181 _cb_signal_action, sca);
184 snprintf(buf, sizeof(buf), "e/widgets/syscon/item/%s",
186 e_theme_edje_object_set(o, "base/theme/widgets", buf);
189 e_theme_edje_object_set(o, "base/theme/widgets",
190 "e/widgets/syscon/item/button");
191 edje_object_part_text_set(o, "e.text.label",
192 _(e_action_predef_label_get(sca->action, sca->params)));
195 o2 = e_icon_add(popup->evas);
196 e_util_icon_theme_set(o2, sca->icon);
197 edje_object_part_swallow(o, "e.swallow.icon", o2);
198 evas_object_show(o2);
200 edje_object_signal_emit(o2, "e,state,disabled", "e");
203 edje_object_signal_emit(o, "e,state,disabled", "e");
206 e_flowlayout_pack_end(o_flow_main, o);
207 iw = ih = e_config->syscon.main.icon_size * e_scale;
211 e_flowlayout_pack_end(o_flow_secondary, o);
212 iw = ih = e_config->syscon.secondary.icon_size * e_scale;
214 edje_object_message_signal_process(o);
215 edje_object_size_min_calc(o, &mw, &mh);
216 if (mw > iw) iw = mw;
217 if (mh > ih) ih = mh;
218 e_flowlayout_pack_options_set(o, 1, 1, 0, 0, 0.5, 0.5,
223 for (l = (Eina_List *)e_sys_con_extra_action_list_get(); l; l = l->next)
225 E_Sys_Con_Action *sca;
229 o = edje_object_add(popup->evas);
230 edje_object_signal_callback_add(o, "e,action,click", "", _cb_signal_action_extra, sca);
231 if (sca->button_name)
233 snprintf(buf, sizeof(buf), "e/widgets/syscon/item/%s",
235 e_theme_edje_object_set(o, "base/theme/widgets", buf);
238 e_theme_edje_object_set(o, "base/theme/widgets",
239 "e/widgets/syscon/item/button");
240 edje_object_part_text_set(o, "e.text.label", sca->label);
243 o2 = edje_object_add(popup->evas);
244 e_util_edje_icon_set(o2, sca->icon_group);
245 edje_object_part_swallow(o, "e.swallow.icon", o2);
246 evas_object_show(o2);
248 edje_object_signal_emit(o2, "e,state,disabled", "e");
251 edje_object_signal_emit(o, "e,state,disabled", "e");
252 e_flowlayout_pack_end(o_flow_extra, o);
253 iw = ih = e_config->syscon.extra.icon_size * e_scale;
254 e_flowlayout_pack_options_set(o, 1, 1, 0, 0, 0.5, 0.5,
259 e_flowlayout_fill_set(o_flow_main, 1);
260 edje_object_part_swallow(o_bg, "e.swallow.main", o_flow_main);
261 e_flowlayout_fill_set(o_flow_secondary, 1);
262 edje_object_part_swallow(o_bg, "e.swallow.secondary", o_flow_secondary);
263 e_flowlayout_fill_set(o_flow_extra, 1);
264 edje_object_part_swallow(o_bg, "e.swallow.extra", o_flow_extra);
266 e_zone_useful_geometry_get(zone, &zx, &zy, &zw, &zh);
267 evas_object_resize(o_bg, zw, zh);
268 edje_object_calc_force(o_bg);
270 e_flowlayout_size_min_get(o_flow_main, &mw, &mh);
271 edje_extern_object_min_size_set(o_flow_main, mw, mh);
272 edje_object_part_swallow(o_bg, "e.swallow.main", o_flow_main);
273 e_flowlayout_size_min_get(o_flow_secondary, &mw, &mh);
274 edje_extern_object_min_size_set(o_flow_secondary, mw, mh);
275 edje_object_part_swallow(o_bg, "e.swallow.secondary", o_flow_secondary);
276 e_flowlayout_size_min_get(o_flow_extra, &mw, &mh);
277 edje_extern_object_min_size_set(o_flow_extra, mw, mh);
278 edje_object_part_swallow(o_bg, "e.swallow.extra", o_flow_extra);
280 edje_object_size_min_calc(o_bg, &mw, &mh);
284 x = zx - zone->x + (zw - w) / 2;
287 y = zy - zone->y + (zh - h) / 2;
289 e_popup_move_resize(popup, x, y, w, h);
290 evas_object_move(o_bg, 0, 0);
291 evas_object_resize(o_bg, w, h);
292 evas_object_show(o_bg);
293 e_popup_edje_bg_object_set(popup, o_bg);
295 if (e_config->syscon.do_input)
297 deftimer = ecore_timer_add(e_config->syscon.timeout,
298 _cb_timeout_defaction, NULL);
299 if (defact) do_defact = eina_stringshare_add(defact);
302 evas_event_thaw(popup->evas);
315 ecore_timer_del(deftimer);
318 if (do_defact) eina_stringshare_del(do_defact);
322 ecore_event_handler_del(handlers->data);
323 handlers = eina_list_remove_list(handlers, handlers);
326 e_object_del(E_OBJECT(popup));
328 e_grabinput_release(input_window, input_window);
329 ecore_x_window_free(input_window);
333 /* local subsystem functions */
335 _cb_key_down(__UNUSED__ void *data, __UNUSED__ int type, void *event)
340 if (ev->event_window != input_window) return ECORE_CALLBACK_PASS_ON;
341 if (!strcmp(ev->key, "Escape"))
343 else if (!strcmp(ev->key, "Up"))
345 // FIXME: implement focus and key control... eventually
347 else if (!strcmp(ev->key, "Down"))
349 // FIXME: implement focus and key control... eventually
351 else if (!strcmp(ev->key, "Left"))
353 // FIXME: implement focus and key control... eventually
355 else if (!strcmp(ev->key, "Right"))
357 // FIXME: implement focus and key control... eventually
359 else if (!strcmp(ev->key, "Tab"))
361 // FIXME: implement focus and key control... eventually
363 else if (!strcmp(ev->key, "Enter"))
365 // FIXME: implement focus and key control... eventually
372 t = ecore_loop_time_get();
373 if (t - show_time > 0.5)
375 act = e_bindings_key_down_event_find(E_BINDING_CONTEXT_ANY, ev);
376 if ((act) && (act->name))
378 if (!strcmp(act->name, "syscon"))
382 e_syscon_show(popup->zone, do_defact);
389 for (l = e_config->syscon.actions; l; l = l->next)
391 E_Config_Syscon_Action *sca;
393 if (!(sca = l->data)) continue;
394 if (!sca->action) continue;
395 if (!strcmp(sca->action, act->name))
400 act->func.go(NULL, sca->params);
411 return ECORE_CALLBACK_PASS_ON;
415 _cb_mouse_down(__UNUSED__ void *data, __UNUSED__ int type, void *event)
417 Ecore_Event_Mouse_Button *ev;
418 Evas_Button_Flags flags = EVAS_BUTTON_NONE;
421 if (ev->event_window != input_window) return ECORE_CALLBACK_PASS_ON;
422 if (ev->double_click) flags |= EVAS_BUTTON_DOUBLE_CLICK;
423 if (ev->triple_click) flags |= EVAS_BUTTON_TRIPLE_CLICK;
424 if ((ev->x < popup->x) || (ev->x >= (popup->x + popup->w)) ||
425 (ev->y < popup->y) || (ev->y >= (popup->y + popup->h)))
428 return ECORE_CALLBACK_PASS_ON;
430 evas_event_feed_mouse_down(popup->evas, ev->buttons, flags, ev->timestamp, NULL);
431 return ECORE_CALLBACK_PASS_ON;
435 _cb_mouse_up(__UNUSED__ void *data, __UNUSED__ int type, void *event)
437 Ecore_Event_Mouse_Button *ev;
440 if (ev->event_window != input_window) return ECORE_CALLBACK_PASS_ON;
441 evas_event_feed_mouse_up(popup->evas, ev->buttons, EVAS_BUTTON_NONE,
442 ev->timestamp, NULL);
443 return ECORE_CALLBACK_PASS_ON;
447 _cb_mouse_move(__UNUSED__ void *data, __UNUSED__ int type, void *event)
449 Ecore_Event_Mouse_Move *ev;
452 if (ev->event_window != input_window) return ECORE_CALLBACK_PASS_ON;
455 evas_event_feed_mouse_in(popup->evas, ev->timestamp, NULL);
458 evas_event_feed_mouse_move(popup->evas, ev->x - popup->x, ev->y - popup->y,
459 ev->timestamp, NULL);
460 return ECORE_CALLBACK_PASS_ON;
464 _cb_mouse_wheel(__UNUSED__ void *data, __UNUSED__ int type, void *event)
466 Ecore_Event_Mouse_Wheel *ev;
469 if (ev->event_window != input_window) return ECORE_CALLBACK_PASS_ON;
470 evas_event_feed_mouse_wheel(popup->evas, ev->direction, ev->z,
471 ev->timestamp, NULL);
472 return ECORE_CALLBACK_PASS_ON;
476 _cb_signal_close(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
482 _do_action_name(const char *action)
486 for (l = e_config->syscon.actions; l; l = l->next)
488 E_Config_Syscon_Action *sca;
492 if (!sca->action) continue;
493 if (!strcmp(sca->action, action))
495 a = e_action_find(sca->action);
497 if (a) a->func.go(NULL, sca->params);
504 _cb_signal_syscon(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source)
507 _do_action_name(source);
511 _cb_signal_action(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
513 E_Config_Syscon_Action *sca;
519 a = e_action_find(sca->action);
521 a->func.go(NULL, sca->params);
525 _cb_signal_action_extra(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
527 E_Sys_Con_Action *sca;
532 if (sca->func) sca->func((void *)sca->data);
536 _cb_timeout_defaction(void *data __UNUSED__)
538 const char *defact = NULL;
540 if (!do_defact) return ECORE_CALLBACK_CANCEL;
541 defact = eina_stringshare_add(do_defact);
545 _do_action_name(defact);
546 eina_stringshare_del(defact);
548 return ECORE_CALLBACK_CANCEL;