1 #include <Elementary.h>
4 static Eina_Bool _ews_used = EINA_FALSE;
5 static Eina_List *_ews_ev_handlers = NULL;
6 static Eina_Hash *_ews_borders = NULL;
7 static Eina_Hash *_ews_borders_geo = NULL;
8 static Evas_Object *_ews_bg = NULL;
9 static Ecore_Animator *_ews_border_mover = NULL;
10 static Evas_Object *_ews_border_mover_obj = NULL;
11 static Evas_Point _ews_border_mover_off = {0, 0};
14 _elm_ews_border_usable_screen_geometry_get(int *x, int *y, int *w, int *h)
16 Ecore_Evas *ee = ecore_evas_ews_ecore_evas_get();
17 ecore_evas_geometry_get(ee, NULL, NULL, w, h);
20 // TODO: when add a shelf for iconified, subtract its area here.
24 _elm_ews_wm_border_del(void *data)
26 Evas_Object *deco = data;
27 evas_object_del(deco);
29 if (_ews_border_mover_obj == deco)
31 if (_ews_border_mover)
33 ecore_animator_del(_ews_border_mover);
34 _ews_border_mover = NULL;
36 _ews_border_mover_obj = NULL;
41 _elm_ews_wm_border_find(const Ecore_Evas *ee)
43 return eina_hash_find(_ews_borders, &ee);
46 static Eina_Rectangle *
47 _elm_ews_wm_border_geo_find(const Ecore_Evas *ee)
49 return eina_hash_find(_ews_borders_geo, &ee);
53 _elm_ews_border_geo_apply(Ecore_Evas *ee, Evas_Object *o)
56 ecore_evas_geometry_get(ee, &x, &y, &w, &h);
57 evas_object_move(o, x, y);
58 evas_object_resize(o, w, h);
62 _elm_ews_border_focus_apply(Ecore_Evas *ee, Evas_Object *o)
65 if (ecore_evas_focus_get(ee))
66 sig = "elm,state,focus,on";
68 sig = "elm,state,focus,off";
69 edje_object_signal_emit(o, sig, "elm");
73 _elm_ews_border_stack_apply(Ecore_Evas *ee, Evas_Object *o)
75 Evas_Object *bs_o = ecore_evas_ews_backing_store_get(ee);
76 evas_object_stack_below(o, bs_o);
80 _elm_ews_border_iconified_apply(Ecore_Evas *ee, Evas_Object *o)
83 if (ecore_evas_iconified_get(ee))
84 sig = "elm,state,iconified,on";
86 sig = "elm,state,iconified,off";
87 edje_object_signal_emit(o, sig, "elm");
89 // TODO: add to some taskbar? and actually hide it?
90 DBG("EWS does not implement iconified yet");
94 _elm_ews_border_maximized_apply(Ecore_Evas *ee, Evas_Object *o)
97 if (ecore_evas_maximized_get(ee))
102 edje_object_signal_emit(o, "elm,state,maximized,on", "elm");
103 edje_object_message_signal_process(o);
104 ecore_evas_geometry_get(ee, &x, &y, &w, &h);
106 r = _elm_ews_wm_border_geo_find(ee);
109 r = malloc(sizeof(Eina_Rectangle));
110 eina_hash_add(_ews_borders_geo, &ee, r);
117 _elm_ews_border_usable_screen_geometry_get(&x, &y, &w, &h);
118 edje_object_parts_extends_calc(o, &ex, &ey, &ew, &eh);
126 Eina_Rectangle *r = _elm_ews_wm_border_geo_find(ee);
127 edje_object_signal_emit(o, "elm,state,maximized,off", "elm");
129 if (!r) ecore_evas_geometry_get(ee, &x, &y, &w, &h);
139 ecore_evas_move_resize(ee, x, y, w, h);
140 _elm_ews_border_geo_apply(ee, o);
144 _elm_ews_border_layer_apply(Ecore_Evas *ee, Evas_Object *o)
146 Evas_Object *bs_o = ecore_evas_ews_backing_store_get(ee);
147 evas_object_layer_set(o, evas_object_layer_get(bs_o));
148 _elm_ews_border_stack_apply(ee, o);
152 _elm_ews_border_fullscreen_apply(Ecore_Evas *ee, Evas_Object *o)
155 if (ecore_evas_fullscreen_get(ee))
156 sig = "elm,state,fullscreen,on";
158 sig = "elm,state,fullscreen,off";
159 edje_object_signal_emit(o, sig, "elm");
160 _elm_ews_border_geo_apply(ee, o);
164 _elm_ews_border_config_apply(Ecore_Evas *ee, Evas_Object *o, Elm_Theme *th)
166 const char *title, *name = NULL, *class = NULL, *style = NULL;
169 if (ecore_evas_borderless_get(ee))
170 style = "borderless";
172 _elm_theme_set(th, o, "ews", "decoration", style ? style : "default");
174 if (ecore_evas_shaped_get(ee) || ecore_evas_alpha_get(ee) ||
175 ecore_evas_transparent_get(ee))
176 sig = "elm,state,alpha,on";
178 sig = "elm,state,alpha,off";
179 edje_object_signal_emit(o, sig, "elm");
181 title = ecore_evas_title_get(ee);
182 ecore_evas_name_class_get(ee, &name, &class);
183 edje_object_part_text_set(o, "elm.text.title", title);
184 edje_object_part_text_set(o, "elm.text.name", name);
185 edje_object_part_text_set(o, "elm.text.class", class);
187 _elm_ews_border_geo_apply(ee, o);
188 _elm_ews_border_focus_apply(ee, o);
189 _elm_ews_border_stack_apply(ee, o);
190 _elm_ews_border_iconified_apply(ee, o);
191 _elm_ews_border_maximized_apply(ee, o);
192 _elm_ews_border_layer_apply(ee, o);
193 _elm_ews_border_fullscreen_apply(ee, o);
197 _elm_ews_wm_border_theme_set(Ecore_Evas *ee, Evas_Object *o, Elm_Theme *th)
199 _elm_ews_border_config_apply(ee, o, th);
204 _elm_ews_border_sig_focus(void *data, Evas_Object *o __UNUSED__, const char *sig __UNUSED__, const char *source __UNUSED__)
206 Ecore_Evas *ee = data;
207 ecore_evas_focus_set(ee, EINA_TRUE);
211 _elm_ews_border_sig_iconify(void *data, Evas_Object *o __UNUSED__, const char *sig __UNUSED__, const char *source __UNUSED__)
213 Ecore_Evas *ee = data;
214 ecore_evas_iconified_set(ee, EINA_TRUE);
218 _elm_ews_border_sig_maximize(void *data, Evas_Object *o __UNUSED__, const char *sig __UNUSED__, const char *source __UNUSED__)
220 Ecore_Evas *ee = data;
221 ecore_evas_maximized_set(ee, EINA_TRUE);
225 _elm_ews_border_sig_fullscreen(void *data, Evas_Object *o __UNUSED__, const char *sig __UNUSED__, const char *source __UNUSED__)
227 Ecore_Evas *ee = data;
228 ecore_evas_fullscreen_set(ee, EINA_TRUE);
232 _elm_ews_border_sig_restore(void *data, Evas_Object *o __UNUSED__, const char *sig __UNUSED__, const char *source __UNUSED__)
234 Ecore_Evas *ee = data;
235 ecore_evas_iconified_set(ee, EINA_FALSE);
236 ecore_evas_maximized_set(ee, EINA_FALSE);
237 ecore_evas_fullscreen_set(ee, EINA_FALSE);
241 _elm_ews_border_sig_close(void *data, Evas_Object *o __UNUSED__, const char *sig __UNUSED__, const char *source __UNUSED__)
243 Ecore_Evas *ee = data;
244 ecore_evas_ews_delete_request(ee);
248 _elm_ews_border_sig_menu(void *data, Evas_Object *o __UNUSED__, const char *sig __UNUSED__, const char *source __UNUSED__)
250 // TODO: show some menu?
251 ERR("EWS does not implement menu yet");
256 _elm_ews_border_mover(void *data)
258 Ecore_Evas *ee = data;
259 Evas_Object *o = _elm_ews_wm_border_find(ee);
262 evas_pointer_output_xy_get(ecore_evas_ews_evas_get(), &x, &y);
263 x -= _ews_border_mover_off.x;
264 y -= _ews_border_mover_off.y;
265 ecore_evas_move(ee, x, y);
266 evas_object_move(o, x, y);
272 _elm_ews_border_sig_move_start(void *data, Evas_Object *o __UNUSED__, const char *sig __UNUSED__, const char *source __UNUSED__)
274 Ecore_Evas *ee = data;
275 Evas_Object *bs_o = ecore_evas_ews_backing_store_get(ee);
278 if (_ews_border_mover) ecore_animator_del(_ews_border_mover);
280 evas_pointer_output_xy_get(evas_object_evas_get(bs_o), &x, &y);
281 evas_object_geometry_get(bs_o, &ox, &oy, NULL, NULL);
282 _ews_border_mover_off.x = x - ox;
283 _ews_border_mover_off.y = y - oy;
284 _ews_border_mover_obj = bs_o;
285 _ews_border_mover = ecore_animator_add(_elm_ews_border_mover, ee);
289 _elm_ews_border_sig_move_stop(void *data __UNUSED__, Evas_Object *o __UNUSED__, const char *sig __UNUSED__, const char *source __UNUSED__)
291 if (!_ews_border_mover) return;
292 ecore_animator_del(_ews_border_mover);
293 _ews_border_mover = NULL;
294 _ews_border_mover_obj = NULL;
298 _elm_ews_wm_add_cb(void *data __UNUSED__, int type __UNUSED__, void *event_info)
300 Ecore_Evas *ee = event_info;
301 Evas_Object *o = edje_object_add(ecore_evas_ews_evas_get());
302 Evas_Coord x, y, w, h, sw, sh;
304 edje_object_signal_callback_add
305 (o, "elm,action,focus", "elm", _elm_ews_border_sig_focus, ee);
306 edje_object_signal_callback_add
307 (o, "elm,action,iconify", "elm", _elm_ews_border_sig_iconify, ee);
308 edje_object_signal_callback_add
309 (o, "elm,action,maximize", "elm", _elm_ews_border_sig_maximize, ee);
310 edje_object_signal_callback_add
311 (o, "elm,action,fullscreen", "elm", _elm_ews_border_sig_fullscreen, ee);
312 edje_object_signal_callback_add
313 (o, "elm,action,restore", "elm", _elm_ews_border_sig_restore, ee);
314 edje_object_signal_callback_add
315 (o, "elm,action,close", "elm", _elm_ews_border_sig_close, ee);
316 edje_object_signal_callback_add
317 (o, "elm,action,menu", "elm", _elm_ews_border_sig_menu, ee);
318 edje_object_signal_callback_add
319 (o, "elm,action,move,start", "elm", _elm_ews_border_sig_move_start, ee);
320 edje_object_signal_callback_add
321 (o, "elm,action,move,stop", "elm", _elm_ews_border_sig_move_stop, ee);
323 eina_hash_add(_ews_borders, &ee, o);
324 _elm_ews_wm_border_theme_set(ee, o, NULL);
326 ecore_evas_screen_geometry_get(ee, NULL, NULL, &sw, &sh);
327 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
330 ecore_evas_move(ee, x, y);
331 ecore_evas_focus_set(ee, EINA_TRUE);
337 _elm_ews_wm_del_cb(void *data __UNUSED__, int type __UNUSED__, void *event_info)
339 Ecore_Evas *ee = event_info;
340 eina_hash_del(_ews_borders, &ee, NULL);
341 eina_hash_del(_ews_borders_geo, &ee, NULL);
346 _elm_ews_wm_geo_cb(void *data __UNUSED__, int type __UNUSED__, void *event_info)
348 Ecore_Evas *ee = event_info;
349 Evas_Object *o = _elm_ews_wm_border_find(ee);
350 _elm_ews_border_geo_apply(ee, o);
355 _elm_ews_wm_show_cb(void *data __UNUSED__, int type __UNUSED__, void *event_info)
357 Ecore_Evas *ee = event_info;
358 Evas_Object *o = _elm_ews_wm_border_find(ee);
364 _elm_ews_wm_hide_cb(void *data __UNUSED__, int type __UNUSED__, void *event_info)
366 Ecore_Evas *ee = event_info;
367 Evas_Object *o = _elm_ews_wm_border_find(ee);
373 _elm_ews_wm_focus_cb(void *data __UNUSED__, int type __UNUSED__, void *event_info)
375 Ecore_Evas *ee = event_info;
376 Evas_Object *o = _elm_ews_wm_border_find(ee);
377 _elm_ews_border_focus_apply(ee, o);
382 _elm_ews_wm_stack_cb(void *data __UNUSED__, int type __UNUSED__, void *event_info)
384 Ecore_Evas *ee = event_info;
385 Evas_Object *o = _elm_ews_wm_border_find(ee);
386 _elm_ews_border_stack_apply(ee, o);
391 _elm_ews_wm_iconified_change_cb(void *data __UNUSED__, int type __UNUSED__, void *event_info)
393 Ecore_Evas *ee = event_info;
394 Evas_Object *o = _elm_ews_wm_border_find(ee);
395 _elm_ews_border_iconified_apply(ee, o);
400 _elm_ews_wm_maximized_change_cb(void *data __UNUSED__, int type __UNUSED__, void *event_info)
402 Ecore_Evas *ee = event_info;
403 Evas_Object *o = _elm_ews_wm_border_find(ee);
404 _elm_ews_border_maximized_apply(ee, o);
409 _elm_ews_wm_layer_change_cb(void *data __UNUSED__, int type __UNUSED__, void *event_info)
411 Ecore_Evas *ee = event_info;
412 Evas_Object *o = _elm_ews_wm_border_find(ee);
413 _elm_ews_border_layer_apply(ee, o);
418 _elm_ews_wm_fullscreen_change_cb(void *data __UNUSED__, int type __UNUSED__, void *event_info)
420 Ecore_Evas *ee = event_info;
421 Evas_Object *o = _elm_ews_wm_border_find(ee);
422 _elm_ews_border_fullscreen_apply(ee, o);
427 _elm_ews_wm_config_change_cb(void *data __UNUSED__, int type __UNUSED__, void *event_info)
429 Ecore_Evas *ee = event_info;
430 Evas_Object *o = _elm_ews_wm_border_find(ee);
431 _elm_ews_border_config_apply(ee, o, NULL);
436 _elm_ews_wm_rescale(Elm_Theme *th, Eina_Bool use_theme)
438 Eina_Iterator *it = eina_hash_iterator_tuple_new(_ews_borders);
439 Eina_Hash_Tuple *tp = NULL;
443 EINA_ITERATOR_FOREACH(it, tp)
444 _elm_ews_wm_border_theme_set((void*)tp->key, tp->data, NULL);
447 _elm_theme_set(NULL, _ews_bg, "ews", "background", "default");
451 EINA_ITERATOR_FOREACH(it, tp)
452 _elm_ews_wm_border_theme_set((void*)tp->key, tp->data, th);
455 _elm_theme_set(th, _ews_bg, "ews", "background", "default");
458 eina_iterator_free(it);
462 _elm_ews_wm_init(void)
467 if (strcmp(_elm_config->engine, ELM_EWS) != 0)
469 _ews_used = EINA_FALSE;
473 e = ecore_evas_ews_evas_get();
474 if (!e) return EINA_FALSE;
475 o = edje_object_add(e);
476 if (!o) return EINA_FALSE;
478 if (!_elm_theme_set(NULL, o, "ews", "background", "default"))
480 ERR("Could not set background theme, fallback to rectangle");
486 ecore_evas_ews_background_set(o);
489 #define ADD_EH(ev, cb) \
490 _ews_ev_handlers = eina_list_append \
491 (_ews_ev_handlers, ecore_event_handler_add(ev, cb, NULL))
492 ADD_EH(ECORE_EVAS_EWS_EVENT_ADD, _elm_ews_wm_add_cb);
493 ADD_EH(ECORE_EVAS_EWS_EVENT_DEL, _elm_ews_wm_del_cb);
494 ADD_EH(ECORE_EVAS_EWS_EVENT_RESIZE, _elm_ews_wm_geo_cb);
495 ADD_EH(ECORE_EVAS_EWS_EVENT_MOVE, _elm_ews_wm_geo_cb);
496 ADD_EH(ECORE_EVAS_EWS_EVENT_SHOW, _elm_ews_wm_show_cb);
497 ADD_EH(ECORE_EVAS_EWS_EVENT_HIDE, _elm_ews_wm_hide_cb);
498 ADD_EH(ECORE_EVAS_EWS_EVENT_FOCUS, _elm_ews_wm_focus_cb);
499 ADD_EH(ECORE_EVAS_EWS_EVENT_UNFOCUS, _elm_ews_wm_focus_cb);
500 ADD_EH(ECORE_EVAS_EWS_EVENT_RAISE, _elm_ews_wm_stack_cb);
501 ADD_EH(ECORE_EVAS_EWS_EVENT_LOWER, _elm_ews_wm_stack_cb);
502 ADD_EH(ECORE_EVAS_EWS_EVENT_ICONIFIED_CHANGE, _elm_ews_wm_iconified_change_cb);
503 ADD_EH(ECORE_EVAS_EWS_EVENT_MAXIMIZED_CHANGE, _elm_ews_wm_maximized_change_cb);
504 ADD_EH(ECORE_EVAS_EWS_EVENT_LAYER_CHANGE, _elm_ews_wm_layer_change_cb);
505 ADD_EH(ECORE_EVAS_EWS_EVENT_FULLSCREEN_CHANGE, _elm_ews_wm_fullscreen_change_cb);
506 ADD_EH(ECORE_EVAS_EWS_EVENT_CONFIG_CHANGE, _elm_ews_wm_config_change_cb);
510 _ews_borders = eina_hash_pointer_new(_elm_ews_wm_border_del);
512 if (!_ews_borders_geo)
513 _ews_borders_geo = eina_hash_pointer_new(free);
515 _ews_used = EINA_TRUE;
520 _elm_ews_wm_shutdown(void)
522 Ecore_Event_Handler *eh;
524 if (_ews_border_mover)
526 ecore_animator_del(_ews_border_mover);
527 _ews_border_mover = NULL;
529 _ews_border_mover_obj = NULL;
531 EINA_LIST_FREE(_ews_ev_handlers, eh) ecore_event_handler_del(eh);
534 eina_hash_free(_ews_borders);
537 if (_ews_borders_geo)
539 eina_hash_free(_ews_borders_geo);
540 _ews_borders_geo = NULL;