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;
28 /* externally accessible functions */
36 e_syscon_shutdown(void)
43 e_syscon_show(E_Zone *zone, const char *defact)
47 int x, y, w, h, zx, zy, zw, zh;
53 input_window = ecore_x_window_input_new(zone->container->win, zone->x,
54 zone->y, zone->w, zone->h);
55 ecore_x_window_show(input_window);
56 if (!e_grabinput_get(input_window, 1, input_window))
58 ecore_x_window_free(input_window);
63 popup = e_popup_new(zone, 0, 0, 1, 1);
66 e_grabinput_release(input_window, input_window);
67 ecore_x_window_free(input_window);
71 evas_event_freeze(popup->evas);
72 e_popup_layer_set(popup, 500);
74 handlers = eina_list_append
75 (handlers, ecore_event_handler_add
76 (ECORE_EVENT_KEY_DOWN, _cb_key_down, NULL));
77 handlers = eina_list_append
78 (handlers, ecore_event_handler_add
79 (ECORE_EVENT_MOUSE_BUTTON_DOWN, _cb_mouse_down, NULL));
80 handlers = eina_list_append
81 (handlers, ecore_event_handler_add
82 (ECORE_EVENT_MOUSE_BUTTON_UP, _cb_mouse_up, NULL));
83 handlers = eina_list_append
84 (handlers, ecore_event_handler_add
85 (ECORE_EVENT_MOUSE_MOVE, _cb_mouse_move, NULL));
86 handlers = eina_list_append
87 (handlers, ecore_event_handler_add
88 (ECORE_EVENT_MOUSE_WHEEL, _cb_mouse_wheel, NULL));
90 o = edje_object_add(popup->evas);
92 e_theme_edje_object_set(o, "base/theme/syscon",
93 "e/widgets/syscon/main");
94 edje_object_part_text_set(o, "e.text.label", _("Cancel"));
95 edje_object_signal_callback_add(o, "e,action,close", "",
96 _cb_signal_close, NULL);
97 edje_object_signal_callback_add(o, "e,action,syscon", "*",
98 _cb_signal_syscon, NULL);
101 // halt | suspend | desk_lock
102 // secondary (default):
103 // reboot | hibernate | logout
104 // extra (example for illume):
105 // home | close | kill
110 o = e_flowlayout_add(popup->evas);
112 e_flowlayout_orientation_set(o, 1);
113 e_flowlayout_flowdirection_set(o, 1, 1);
114 e_flowlayout_homogenous_set(o, 1);
116 o = e_flowlayout_add(popup->evas);
117 o_flow_secondary = o;
118 e_flowlayout_orientation_set(o, 1);
119 e_flowlayout_flowdirection_set(o, 1, 1);
120 e_flowlayout_homogenous_set(o, 1);
122 o = e_flowlayout_add(popup->evas);
124 e_flowlayout_orientation_set(o, 1);
125 e_flowlayout_flowdirection_set(o, 1, 1);
126 e_flowlayout_homogenous_set(o, 1);
128 for (l = e_config->syscon.actions; l; l = l->next)
130 E_Config_Syscon_Action *sca;
135 if (!(sca = l->data)) continue;
136 if (!sca->action) continue;
137 a = e_action_find(sca->action);
140 if ((!strcmp(sca->action, "logout")) &&
141 (!e_sys_action_possible_get(E_SYS_LOGOUT))) disabled = 1;
142 else if ((!strcmp(sca->action, "halt")) &&
143 (!e_sys_action_possible_get(E_SYS_HALT))) disabled = 1;
144 else if ((!strcmp(sca->action, "halt_now")) &&
145 (!e_sys_action_possible_get(E_SYS_HALT_NOW))) disabled = 1;
146 else if ((!strcmp(sca->action, "reboot")) &&
147 (!e_sys_action_possible_get(E_SYS_REBOOT))) disabled = 1;
148 else if ((!strcmp(sca->action, "suspend")) &&
149 (!e_sys_action_possible_get(E_SYS_SUSPEND))) disabled = 1;
150 else if ((!strcmp(sca->action, "hibernate")) &&
151 (!e_sys_action_possible_get(E_SYS_HIBERNATE))) disabled = 1;
152 o = edje_object_add(popup->evas);
153 edje_object_signal_callback_add(o, "e,action,click", "",
154 _cb_signal_action, sca);
157 snprintf(buf, sizeof(buf), "e/widgets/syscon/item/%s",
159 e_theme_edje_object_set(o, "base/theme/widgets", buf);
162 e_theme_edje_object_set(o, "base/theme/widgets",
163 "e/widgets/syscon/item/button");
164 edje_object_part_text_set(o, "e.text.label",
165 _(e_action_predef_label_get(sca->action, sca->params)));
168 o2 = e_icon_add(popup->evas);
169 e_util_icon_theme_set(o2, sca->icon);
170 edje_object_part_swallow(o, "e.swallow.icon", o2);
171 evas_object_show(o2);
173 edje_object_signal_emit(o2, "e,state,disabled", "e");
176 edje_object_signal_emit(o, "e,state,disabled", "e");
179 e_flowlayout_pack_end(o_flow_main, o);
180 iw = ih = e_config->syscon.main.icon_size * e_scale;
184 e_flowlayout_pack_end(o_flow_secondary, o);
185 iw = ih = e_config->syscon.secondary.icon_size * e_scale;
187 edje_object_message_signal_process(o);
188 edje_object_size_min_calc(o, &mw, &mh);
189 if (mw > iw) iw = mw;
190 if (mh > ih) ih = mh;
191 e_flowlayout_pack_options_set(o, 1, 1, 0, 0, 0.5, 0.5,
196 for (l = (Eina_List *)e_sys_con_extra_action_list_get(); l; l = l->next)
198 E_Sys_Con_Action *sca;
202 o = edje_object_add(popup->evas);
203 edje_object_signal_callback_add(o, "e,action,click", "", _cb_signal_action_extra, sca);
204 if (sca->button_name)
206 snprintf(buf, sizeof(buf), "e/widgets/syscon/item/%s",
208 e_theme_edje_object_set(o, "base/theme/widgets", buf);
211 e_theme_edje_object_set(o, "base/theme/widgets",
212 "e/widgets/syscon/item/button");
213 edje_object_part_text_set(o, "e.text.label", sca->label);
216 o2 = edje_object_add(popup->evas);
217 e_util_edje_icon_set(o2, sca->icon_group);
218 edje_object_part_swallow(o, "e.swallow.icon", o2);
219 evas_object_show(o2);
221 edje_object_signal_emit(o2, "e,state,disabled", "e");
224 edje_object_signal_emit(o, "e,state,disabled", "e");
225 e_flowlayout_pack_end(o_flow_extra, o);
226 iw = ih = e_config->syscon.extra.icon_size * e_scale;
227 e_flowlayout_pack_options_set(o, 1, 1, 0, 0, 0.5, 0.5,
232 e_flowlayout_fill_set(o_flow_main, 1);
233 edje_object_part_swallow(o_bg, "e.swallow.main", o_flow_main);
234 e_flowlayout_fill_set(o_flow_secondary, 1);
235 edje_object_part_swallow(o_bg, "e.swallow.secondary", o_flow_secondary);
236 e_flowlayout_fill_set(o_flow_extra, 1);
237 edje_object_part_swallow(o_bg, "e.swallow.extra", o_flow_extra);
239 e_zone_useful_geometry_get(zone, &zx, &zy, &zw, &zh);
240 evas_object_resize(o_bg, zw, zh);
241 edje_object_calc_force(o_bg);
243 e_flowlayout_size_min_get(o_flow_main, &mw, &mh);
244 edje_extern_object_min_size_set(o_flow_main, mw, mh);
245 edje_object_part_swallow(o_bg, "e.swallow.main", o_flow_main);
246 e_flowlayout_size_min_get(o_flow_secondary, &mw, &mh);
247 edje_extern_object_min_size_set(o_flow_secondary, mw, mh);
248 edje_object_part_swallow(o_bg, "e.swallow.secondary", o_flow_secondary);
249 e_flowlayout_size_min_get(o_flow_extra, &mw, &mh);
250 edje_extern_object_min_size_set(o_flow_extra, mw, mh);
251 edje_object_part_swallow(o_bg, "e.swallow.extra", o_flow_extra);
253 edje_object_size_min_calc(o_bg, &mw, &mh);
257 x = zx - zone->x + (zw - w) / 2;
260 y = zy - zone->y + (zh - h) / 2;
262 e_popup_move_resize(popup, x, y, w, h);
263 evas_object_move(o_bg, 0, 0);
264 evas_object_resize(o_bg, w, h);
265 evas_object_show(o_bg);
266 e_popup_edje_bg_object_set(popup, o_bg);
268 if (e_config->syscon.do_input)
270 deftimer = ecore_timer_add(e_config->syscon.timeout,
271 _cb_timeout_defaction, NULL);
272 if (defact) do_defact = eina_stringshare_add(defact);
275 evas_event_thaw(popup->evas);
288 ecore_timer_del(deftimer);
291 if (do_defact) eina_stringshare_del(do_defact);
295 ecore_event_handler_del(handlers->data);
296 handlers = eina_list_remove_list(handlers, handlers);
299 e_object_del(E_OBJECT(popup));
301 e_grabinput_release(input_window, input_window);
302 ecore_x_window_free(input_window);
306 /* local subsystem functions */
308 _cb_key_down(__UNUSED__ void *data, __UNUSED__ int type, void *event)
313 if (ev->event_window != input_window) return ECORE_CALLBACK_PASS_ON;
314 if (!strcmp(ev->key, "Escape"))
316 else if (!strcmp(ev->key, "Up"))
318 // FIXME: implement focus and key control... eventually
321 return ECORE_CALLBACK_PASS_ON;
325 _cb_mouse_down(__UNUSED__ void *data, __UNUSED__ int type, void *event)
327 Ecore_Event_Mouse_Button *ev;
328 Evas_Button_Flags flags = EVAS_BUTTON_NONE;
331 if (ev->event_window != input_window) return ECORE_CALLBACK_PASS_ON;
332 if (ev->double_click) flags |= EVAS_BUTTON_DOUBLE_CLICK;
333 if (ev->triple_click) flags |= EVAS_BUTTON_TRIPLE_CLICK;
334 if ((ev->x < popup->x) || (ev->x >= (popup->x + popup->w)) ||
335 (ev->y < popup->y) || (ev->y >= (popup->y + popup->h)))
338 return ECORE_CALLBACK_PASS_ON;
340 evas_event_feed_mouse_down(popup->evas, ev->buttons, flags, ev->timestamp, NULL);
341 return ECORE_CALLBACK_PASS_ON;
345 _cb_mouse_up(__UNUSED__ void *data, __UNUSED__ int type, void *event)
347 Ecore_Event_Mouse_Button *ev;
350 if (ev->event_window != input_window) return ECORE_CALLBACK_PASS_ON;
351 evas_event_feed_mouse_up(popup->evas, ev->buttons, EVAS_BUTTON_NONE,
352 ev->timestamp, NULL);
353 return ECORE_CALLBACK_PASS_ON;
357 _cb_mouse_move(__UNUSED__ void *data, __UNUSED__ int type, void *event)
359 Ecore_Event_Mouse_Move *ev;
362 if (ev->event_window != input_window) return ECORE_CALLBACK_PASS_ON;
365 evas_event_feed_mouse_in(popup->evas, ev->timestamp, NULL);
368 evas_event_feed_mouse_move(popup->evas, ev->x - popup->x, ev->y - popup->y,
369 ev->timestamp, NULL);
370 return ECORE_CALLBACK_PASS_ON;
374 _cb_mouse_wheel(__UNUSED__ void *data, __UNUSED__ int type, void *event)
376 Ecore_Event_Mouse_Wheel *ev;
379 if (ev->event_window != input_window) return ECORE_CALLBACK_PASS_ON;
380 evas_event_feed_mouse_wheel(popup->evas, ev->direction, ev->z,
381 ev->timestamp, NULL);
382 return ECORE_CALLBACK_PASS_ON;
386 _cb_signal_close(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
392 _do_action_name(const char *action)
396 for (l = e_config->syscon.actions; l; l = l->next)
398 E_Config_Syscon_Action *sca;
402 if (!sca->action) continue;
403 if (!strcmp(sca->action, action))
405 a = e_action_find(sca->action);
407 if (a) a->func.go(NULL, sca->params);
414 _cb_signal_syscon(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source)
417 _do_action_name(source);
421 _cb_signal_action(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
423 E_Config_Syscon_Action *sca;
429 a = e_action_find(sca->action);
431 a->func.go(NULL, sca->params);
435 _cb_signal_action_extra(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
437 E_Sys_Con_Action *sca;
442 if (sca->func) sca->func((void *)sca->data);
446 _cb_timeout_defaction(void *data __UNUSED__)
449 if (!do_defact) return ECORE_CALLBACK_CANCEL;
451 _do_action_name(do_defact);
452 return ECORE_CALLBACK_CANCEL;