input: Add e_input_thread_client
[platform/upstream/enlightenment.git] / src / bin / e_client.c
1 #include "e_client_intern.h"
2 #include "e_actions_intern.h"
3 #include "e_appinfo_intern.h"
4 #include "e_bindings_intern.h"
5 #include "e_uuid_store_intern.h"
6 #include "e_utils_intern.h"
7 #include "e_comp_canvas_intern.h"
8 #include "e_comp_wl_intern.h"
9 #include "e_comp_wl_subsurface_intern.h"
10 #include "e_comp_intern.h"
11 #include "e_input_intern.h"
12 #include "e_policy_intern.h"
13 #include "e_map_intern.h"
14 #include "e_policy_visibility_intern.h"
15 #include "e_comp_object_intern.h"
16 #include "e_desk_area_intern.h"
17 #include "e_desk_intern.h"
18 #include "e_zone_intern.h"
19 #include "e_config_intern.h"
20 #include "e_input_thread_client_intern.h"
21
22 #define PRI(ec) ((E_Client_Private *)e_object_data_get(E_OBJECT(ec)))
23
24 #define API_ENTRY \
25    EINA_SAFETY_ON_NULL_RETURN(ec); \
26    E_Client_Private *priv = PRI(ec); \
27    EINA_SAFETY_ON_NULL_RETURN(priv);
28
29 #define API_ENTRY_VAL(ret) \
30    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, ret); \
31    E_Client_Private *priv = PRI(ec); \
32    EINA_SAFETY_ON_NULL_RETURN_VAL(priv, ret);
33
34 typedef struct _E_Client_Private E_Client_Private;
35
36 struct _E_Client_Private
37 {
38    struct
39      {
40         struct wl_signal eval_pre_fetch;
41         struct wl_signal eval_fetch;
42         struct wl_signal eval_pre_post_fetch;
43         struct wl_signal eval_post_fetch;
44         struct wl_signal eval_pre_frame_assign;
45         struct wl_signal eval_post_frame_assign;
46         struct wl_signal eval_pre_new_client;
47         struct wl_signal eval_post_new_client;
48         struct wl_signal eval_visibility;
49         struct wl_signal eval_visibility_end;
50         struct wl_signal eval_end;
51
52         struct wl_signal move_begin;
53         struct wl_signal move_update;
54         struct wl_signal move_end;
55         struct wl_signal move_resize_begin;
56         struct wl_signal move_resize_update;
57         struct wl_signal move_resize_end;
58
59         struct wl_signal destroy;
60         struct wl_signal new_client;
61         struct wl_signal new_client_post;
62
63         struct wl_signal unredirect;
64         struct wl_signal redirect;
65
66         struct wl_signal aux_hint_change;
67         struct wl_signal window_role_change;
68         struct wl_signal transform_change;
69         struct wl_signal activate_done;
70
71         struct wl_signal mouse_in;
72         struct wl_signal mouse_out;
73         struct wl_signal mouse_down;
74
75         struct wl_signal focus_set;
76         struct wl_signal focus_unset;
77         struct wl_signal focus_defer_set;
78         struct wl_signal focus_latest_set;
79
80         struct wl_signal iconify;
81         struct wl_signal uniconify;
82         struct wl_signal maximize;
83         struct wl_signal unmaximize;
84         struct wl_signal fullscreen_pre;
85         struct wl_signal fullscreen;
86         struct wl_signal unfullscreen;
87
88         struct wl_signal move;
89
90         struct wl_signal set_layer;
91         struct wl_signal raise;
92         struct wl_signal lower;
93         struct wl_signal stack_below;
94         struct wl_signal stack_above;
95         struct wl_signal stack_transient_for_done;
96
97         struct wl_signal stick;
98         struct wl_signal unstick;
99
100 #ifdef REFACTOR_DESK_AREA
101         struct wl_signal get_above;
102         struct wl_signal get_below;
103         struct wl_signal get_visible_above;
104         struct wl_signal get_visible_below;
105         struct wl_signal subsurface_stack_update;
106 #endif
107      } events;
108
109    Eina_Bool hide_by_request;
110    Eina_Bool focus_check;
111 };
112
113 static int _e_client_hooks_delete = 0;
114 static int _e_client_hooks_walking = 0;
115
116 static int _e_client_intercept_hooks_delete = 0;
117 static int _e_client_intercept_hooks_walking = 0;
118
119 E_API int E_EVENT_CLIENT_ADD = -1;
120 E_API int E_EVENT_CLIENT_REMOVE = -1;
121 E_API int E_EVENT_CLIENT_ZONE_SET = -1;
122 E_API int E_EVENT_CLIENT_DESK_SET = -1;
123 E_API int E_EVENT_CLIENT_RESIZE = -1;
124 E_API int E_EVENT_CLIENT_MOVE = -1;
125 E_API int E_EVENT_CLIENT_SHOW = -1;
126 E_API int E_EVENT_CLIENT_HIDE = -1;
127 E_API int E_EVENT_CLIENT_ICONIFY = -1;
128 E_API int E_EVENT_CLIENT_UNICONIFY = -1;
129 E_API int E_EVENT_CLIENT_STACK = -1;
130 E_API int E_EVENT_CLIENT_FOCUS_IN = -1;
131 E_API int E_EVENT_CLIENT_FOCUS_OUT = -1;
132 E_API int E_EVENT_CLIENT_PROPERTY = -1;
133 E_API int E_EVENT_CLIENT_FULLSCREEN = -1;
134 E_API int E_EVENT_CLIENT_UNFULLSCREEN = -1;
135 #ifdef _F_ZONE_WINDOW_ROTATION_
136 E_API int E_EVENT_CLIENT_ROTATION_CHANGE_BEGIN = -1;
137 E_API int E_EVENT_CLIENT_ROTATION_CHANGE_CANCEL = -1;
138 E_API int E_EVENT_CLIENT_ROTATION_CHANGE_END = -1;
139 E_API int E_EVENT_CLIENT_ROTATION_GEOMETRY_SET = -1;
140 #endif
141 E_API int E_EVENT_CLIENT_VISIBILITY_CHANGE = -1;
142 E_API int E_EVENT_CLIENT_BUFFER_CHANGE = -1;
143 E_API int E_EVENT_CLIENT_FOCUS_SKIP_SET = -1;
144 E_API int E_EVENT_CLIENT_FOCUS_SKIP_UNSET = -1;
145
146 static Eina_Hash *clients_hash[E_PIXMAP_TYPE_MAX] = {NULL}; // pixmap->client
147
148 static E_Client *ecmove = NULL;
149 static E_Client *ecresize = NULL;
150 static E_Client *action_client = NULL;
151
152 static Eina_Bool comp_grabbed = EINA_FALSE;
153
154 static Eina_List *handlers = NULL;
155 static Eina_List *hooks = NULL;
156 static Eina_List *comp_hooks = NULL;
157
158 static Ecore_Event_Handler *action_handler_mouse = NULL;
159 static Ecore_Timer *action_timer = NULL;
160 static Eina_Rectangle action_orig = {0, 0, 0, 0};
161
162 static E_Client_Resize_Object_Create_Cb _e_client_resize_object_create_cb = NULL;
163
164 EINTERN void e_client_focused_set(E_Client *ec);
165 static void _e_client_transient_for_group_make(E_Client *ec, Eina_List **list);
166 static Evas_Object *_e_client_resize_object_create(E_Client *ec);
167 static void _e_client_resize_object_del(E_Client *ec);
168 static void _e_client_stay_within_canvas(E_Client *ec, int x, int y, int *new_x, int *new_y);
169 static void _e_client_stay_within_canvas_margin(E_Client *ec, int x, int y, int *new_x, int *new_y);
170
171 static Eina_Inlist *_e_client_hooks[] =
172 {
173    [E_CLIENT_HOOK_EVAL_PRE_FETCH] = NULL,
174    [E_CLIENT_HOOK_EVAL_FETCH] = NULL,
175    [E_CLIENT_HOOK_EVAL_PRE_POST_FETCH] = NULL,
176    [E_CLIENT_HOOK_EVAL_POST_FETCH] = NULL,
177    [E_CLIENT_HOOK_EVAL_PRE_FRAME_ASSIGN] = NULL,
178    [E_CLIENT_HOOK_EVAL_POST_FRAME_ASSIGN] = NULL,
179    [E_CLIENT_HOOK_EVAL_PRE_NEW_CLIENT] = NULL,
180    [E_CLIENT_HOOK_EVAL_POST_NEW_CLIENT] = NULL,
181    [E_CLIENT_HOOK_EVAL_END] = NULL,
182    [E_CLIENT_HOOK_FOCUS_SET] = NULL,
183    [E_CLIENT_HOOK_FOCUS_UNSET] = NULL,
184    [E_CLIENT_HOOK_NEW_CLIENT] = NULL,
185    [E_CLIENT_HOOK_MOVE_BEGIN] = NULL,
186    [E_CLIENT_HOOK_MOVE_UPDATE] = NULL,
187    [E_CLIENT_HOOK_MOVE_END] = NULL,
188    [E_CLIENT_HOOK_RESIZE_BEGIN] = NULL,
189    [E_CLIENT_HOOK_RESIZE_UPDATE] = NULL,
190    [E_CLIENT_HOOK_RESIZE_END] = NULL,
191    [E_CLIENT_HOOK_FULLSCREEN_PRE] = NULL,
192    [E_CLIENT_HOOK_DEL] = NULL,
193    [E_CLIENT_HOOK_UNREDIRECT] = NULL,
194    [E_CLIENT_HOOK_REDIRECT] = NULL,
195 #ifdef _F_E_CLIENT_NEW_CLIENT_POST_HOOK_
196    [E_CLIENT_HOOK_NEW_CLIENT_POST] = NULL,
197 #endif
198    [E_CLIENT_HOOK_EVAL_VISIBILITY] = NULL,
199    [E_CLIENT_HOOK_ICONIFY] = NULL,
200    [E_CLIENT_HOOK_UNICONIFY] = NULL,
201    [E_CLIENT_HOOK_AUX_HINT_CHANGE] = NULL,
202    [E_CLIENT_HOOK_WINDOW_ROLE_CHANGE] = NULL,
203    [E_CLIENT_HOOK_TRANSFORM_CHANGE] = NULL,
204    [E_CLIENT_HOOK_ACTIVATE_DONE] = NULL,
205    [E_CLIENT_HOOK_EVAL_VISIBILITY_END] = NULL,
206 };
207
208 static Eina_Inlist *_e_client_intercept_hooks[] =
209 {
210    [E_CLIENT_INTERCEPT_HOOK_FOCUS_REVERT] = NULL,
211    [E_CLIENT_INTERCEPT_HOOK_AUTO_PLACEMENT] = NULL,
212 };
213
214 ///////////////////////////////////////////
215
216 static void
217 _e_client_hooks_clean(void)
218 {
219    Eina_Inlist *l;
220    E_Client_Hook *ch;
221    unsigned int x;
222
223    for (x = 0; x < E_CLIENT_HOOK_LAST; x++)
224      EINA_INLIST_FOREACH_SAFE(_e_client_hooks[x], l, ch)
225        {
226           if (!ch->delete_me) continue;
227           _e_client_hooks[x] = eina_inlist_remove(_e_client_hooks[x], EINA_INLIST_GET(ch));
228           free(ch);
229        }
230 }
231
232 static Eina_Bool
233 _e_client_hook_call(E_Client_Hook_Point hookpoint, E_Client *ec)
234 {
235    E_Client_Hook *ch;
236
237    e_object_ref(E_OBJECT(ec));
238    _e_client_hooks_walking++;
239    EINA_INLIST_FOREACH(_e_client_hooks[hookpoint], ch)
240      {
241         if (ch->delete_me) continue;
242         ch->func(ch->data, ec);
243         if ((hookpoint != E_CLIENT_HOOK_DEL) &&
244           (hookpoint != E_CLIENT_HOOK_MOVE_END) &&
245           (hookpoint != E_CLIENT_HOOK_RESIZE_END) &&
246           (hookpoint != E_CLIENT_HOOK_FOCUS_UNSET) &&
247           e_object_is_del(E_OBJECT(ec)))
248           break;
249      }
250    _e_client_hooks_walking--;
251    if ((_e_client_hooks_walking == 0) && (_e_client_hooks_delete > 0))
252      _e_client_hooks_clean();
253    return !!e_object_unref(E_OBJECT(ec));
254 }
255
256 ///////////////////////////////////////////
257
258 static void
259 _e_client_intercept_hooks_clean(void)
260 {
261    Eina_Inlist *l;
262    E_Client_Intercept_Hook *ch;
263    unsigned int x;
264
265    for (x = 0; x < E_CLIENT_INTERCEPT_HOOK_LAST; x++)
266      EINA_INLIST_FOREACH_SAFE(_e_client_intercept_hooks[x], l, ch)
267        {
268           if (!ch->delete_me) continue;
269           _e_client_intercept_hooks[x] =
270              eina_inlist_remove(_e_client_intercept_hooks[x], EINA_INLIST_GET(ch));
271           free(ch);
272        }
273 }
274
275 static Eina_Bool
276 _e_client_intercept_hook_call(E_Client_Intercept_Hook_Point hookpoint, E_Client *ec)
277 {
278    E_Client_Intercept_Hook *ch;
279    Eina_Bool ret = EINA_TRUE;
280
281    if (e_object_is_del(E_OBJECT(ec)))
282      {
283         if (hookpoint != E_CLIENT_INTERCEPT_HOOK_FOCUS_REVERT)
284           {
285              return ret;
286           }
287      }
288
289    e_object_ref(E_OBJECT(ec));
290    _e_client_intercept_hooks_walking++;
291    EINA_INLIST_FOREACH(_e_client_intercept_hooks[hookpoint], ch)
292      {
293         if (ch->delete_me) continue;
294         if (!(ch->func(ch->data, ec)))
295           {
296              ret = EINA_FALSE;
297              break;
298           }
299      }
300    _e_client_intercept_hooks_walking--;
301    if ((_e_client_intercept_hooks_walking == 0) &&
302        (_e_client_intercept_hooks_delete > 0))
303      _e_client_intercept_hooks_clean();
304
305    e_object_unref(E_OBJECT(ec));
306    return ret;
307 }
308
309 static void
310 _e_client_event_simple_free(void *d EINA_UNUSED, E_Event_Client *ev)
311 {
312    UNREFD(ev->ec, 3);
313    e_object_unref(E_OBJECT(ev->ec));
314    free(ev);
315 }
316
317 static void
318 _e_client_event_simple(E_Client *ec, int type)
319 {
320    E_Event_Client *ev;
321
322    ev = E_NEW(E_Event_Client, 1);
323    if (!ev) return;
324    ev->ec = ec;
325    REFD(ec, 3);
326    e_object_ref(E_OBJECT(ec));
327    ecore_event_add(type, ev, (Ecore_End_Cb)_e_client_event_simple_free, NULL);
328 }
329
330 static void
331 _e_client_event_add(E_Client *ec)
332 {
333    if (ec->reg_ev.add)
334      return;
335
336    ec->reg_ev.add = EINA_TRUE;
337    ELOGF("COMP", "SEND E_EVENT_CLIENT_ADD event", ec);
338    _e_client_event_simple(ec, E_EVENT_CLIENT_ADD);
339 }
340
341 static void
342 _e_client_event_remove(E_Client *ec)
343 {
344    if (!ec->reg_ev.add)
345      return;
346
347    ec->reg_ev.add = EINA_FALSE;
348    ELOGF("COMP", "SEND E_EVENT_CLIENT_REMOVE event", ec);
349    _e_client_event_simple(ec, E_EVENT_CLIENT_REMOVE);
350 }
351
352 static void
353 _e_client_event_show(E_Client *ec)
354 {
355    if (ec->reg_ev.show)
356      return;
357
358    ec->reg_ev.show = EINA_TRUE;
359    _e_client_event_simple(ec, E_EVENT_CLIENT_SHOW);
360 }
361
362 static void
363 _e_client_event_hide(E_Client *ec)
364 {
365    if (!ec->reg_ev.show)
366      return;
367
368    ec->reg_ev.show = EINA_FALSE;
369    _e_client_event_simple(ec, E_EVENT_CLIENT_HIDE);
370 }
371
372 static void
373 _e_client_event_property(E_Client *ec, int prop)
374 {
375    E_Event_Client_Property *ev;
376
377    ev = E_NEW(E_Event_Client_Property, 1);
378    if (!ev) return;
379    ev->ec = ec;
380    ev->property = prop;
381    REFD(ec, 33);
382    e_object_ref(E_OBJECT(ec));
383    ecore_event_add(E_EVENT_CLIENT_PROPERTY, ev, (Ecore_End_Cb)_e_client_event_simple_free, NULL);
384 }
385
386 ////////////////////////////////////////////////
387
388 static int
389 _e_client_action_input_win_del(void)
390 {
391    if (!comp_grabbed) return 0;
392
393    e_comp_ungrab_input(1, 1);
394    comp_grabbed = 0;
395    return 1;
396 }
397
398 static void
399 _e_client_action_finish(void)
400 {
401    if (comp_grabbed)
402      _e_client_action_input_win_del();
403
404    E_FREE_FUNC(action_timer, ecore_timer_del);
405    E_FREE_FUNC(action_handler_mouse, ecore_event_handler_del);
406    if (action_client)
407      {
408         action_client->keyboard_resizing = 0;
409      }
410    action_client = NULL;
411 }
412
413 static void
414 _e_client_transform_point_transform(int cx, int cy, double angle, int x, int y, int *tx, int *ty)
415 {
416    double s = sin(angle * M_PI / 180);
417    double c = cos(angle * M_PI / 180);
418    int rx, ry;
419
420    x -= cx;
421    y -= cy;
422
423    rx = x * c + y * s;
424    ry = - x * s + y * c;
425
426    rx += cx;
427    ry += cy;
428
429    *tx = rx;
430    *ty = ry;
431 }
432
433 static void
434 _e_client_transform_geometry_save(E_Client *ec, E_Map *map)
435 {
436    int i;
437
438    if (!map) return;
439
440    for (i = 0; i < 4; i ++)
441      {
442         e_map_point_precise_coord_get(map, i,
443                                       &ec->transform.saved[i].x,
444                                       &ec->transform.saved[i].y,
445                                       &ec->transform.saved[i].z);
446      }
447 }
448
449 static void
450 _e_client_transform_resize(E_Client *ec)
451 {
452    E_Map *map;
453    int cx, cy;
454    double dx = 0, dy = 0;
455    double px[4], py[4];
456    int pw, ph;
457    int i;
458
459    if (!ec->transformed) return;
460
461    if (!e_pixmap_size_get(ec->pixmap, &pw, &ph))
462      {
463         pw = ec->client.w;
464         ph = ec->client.h;
465      }
466
467    cx = ec->client.x + pw / 2;
468    cy = ec->client.y + ph / 2;
469
470    /* step 1: Rotate resized object and get map points */
471    map = e_map_new_with_direct_render(ec->transform_core.direct_render);
472    e_map_util_points_populate_from_geometry(map,
473                                             ec->client.x, ec->client.y,
474                                             pw, ph,
475                                             0);
476    e_map_util_rotate(map, ec->transform.angle, cx, cy);
477    e_map_util_zoom(map, ec->transform.zoom, ec->transform.zoom, cx, cy);
478
479    for (i = 0; i < 4; i++)
480      e_map_point_precise_coord_get(map, i, &px[i], &py[i], NULL);
481
482    e_map_free(map);
483
484    /* step 2: get adjusted values to keep up fixed position according
485     * to resize mode */
486    switch (ec->resize_mode)
487      {
488       case E_POINTER_RESIZE_R:
489       case E_POINTER_RESIZE_BR:
490          dx = ec->transform.saved[0].x - px[0];
491          dy = ec->transform.saved[0].y - py[0];
492          break;
493       case E_POINTER_RESIZE_BL:
494       case E_POINTER_RESIZE_B:
495          dx = ec->transform.saved[1].x - px[1];
496          dy = ec->transform.saved[1].y - py[1];
497          break;
498       case E_POINTER_RESIZE_TL:
499       case E_POINTER_RESIZE_L:
500          dx = ec->transform.saved[2].x - px[2];
501          dy = ec->transform.saved[2].y - py[2];
502          break;
503       case E_POINTER_RESIZE_T:
504       case E_POINTER_RESIZE_TR:
505          dx = ec->transform.saved[3].x - px[3];
506          dy = ec->transform.saved[3].y - py[3];
507          break;
508       default:
509          break;
510      }
511
512    ec->transform.adjusted.x = dx;
513    ec->transform.adjusted.y = dy;
514
515    /* step 3: set each points of the quadrangle */
516    map = e_map_new_with_direct_render(ec->transform_core.direct_render);
517    e_map_util_points_populate_from_object_full(map, ec->frame, 0);
518
519    for (i = 0; i < 4; i++)
520       e_map_point_precise_coord_set(map, i, px[i] + dx, py[i] + dy, 0);
521
522    e_client_map_set(ec, map);
523    e_client_map_enable_set(ec, EINA_TRUE);
524    e_map_free(map);
525 }
526
527 static void
528 _e_client_transform_resize_handle(E_Client *ec)
529 {
530
531    int new_x, new_y, new_w, new_h;
532    int org_w, org_h;
533    int button_id;
534    int cx, cy;
535    Evas_Point current, moveinfo;
536    E_Zone *zone;
537
538    if (e_object_is_del(E_OBJECT(ec))) return;
539    if (e_client_util_ignored_get(ec)) return;
540    if (!ec->transformed) return;
541
542    zone = e_comp_zone_find_by_ec(ec);
543    if (!zone) return;
544
545    button_id = ec->moveinfo.down.button;
546
547    org_w = ec->mouse.last_down[button_id - 1].w;
548    org_h = ec->mouse.last_down[button_id - 1].h;
549
550    new_w = ec->client.w;
551    new_h = ec->client.h;
552    new_x = ec->client.x;
553    new_y = ec->client.y;
554
555    /* step 1: get center coordinate its' based on original object geometry*/
556    cx = ec->client.x + org_w / 2;
557    cy = ec->client.y + org_h / 2;
558
559    /* step 2: transform coordinates of mouse position
560     * subtract adjusted value from mouse position is needed */
561    current.x = ec->mouse.current.mx - ec->transform.adjusted.x;
562    current.y = ec->mouse.current.my - ec->transform.adjusted.y;
563    moveinfo.x = ec->moveinfo.down.mx - ec->transform.adjusted.x;
564    moveinfo.y = ec->moveinfo.down.my - ec->transform.adjusted.y;
565
566    _e_client_transform_point_transform(cx, cy, ec->transform.angle,
567                                        current.x, current.y,
568                                        &current.x, &current.y);
569    _e_client_transform_point_transform(cx, cy, ec->transform.angle,
570                                        moveinfo.x, moveinfo.y,
571                                        &moveinfo.x, &moveinfo.y);
572
573    /* step 3: calculate new size */
574    if ((ec->resize_mode == E_POINTER_RESIZE_TR) ||
575        (ec->resize_mode == E_POINTER_RESIZE_R) ||
576        (ec->resize_mode == E_POINTER_RESIZE_BR))
577      {
578         if ((button_id >= 1) && (button_id <= 3))
579           new_w = org_w + (current.x - moveinfo.x);
580         else
581           new_w = ec->moveinfo.down.w + (current.x - moveinfo.x);
582      }
583    else if ((ec->resize_mode == E_POINTER_RESIZE_TL) ||
584             (ec->resize_mode == E_POINTER_RESIZE_L) ||
585             (ec->resize_mode == E_POINTER_RESIZE_BL))
586      {
587         if ((button_id >= 1) && (button_id <= 3))
588           new_w = org_w - (current.x - moveinfo.x);
589         else
590           new_w = ec->moveinfo.down.w - (current.x - moveinfo.x);
591      }
592
593    if ((ec->resize_mode == E_POINTER_RESIZE_TL) ||
594        (ec->resize_mode == E_POINTER_RESIZE_T) ||
595        (ec->resize_mode == E_POINTER_RESIZE_TR))
596      {
597         if ((button_id >= 1) && (button_id <= 3))
598           new_h = org_h - (current.y - moveinfo.y);
599         else
600           new_h = ec->moveinfo.down.h - (current.y - moveinfo.y);
601      }
602    else if ((ec->resize_mode == E_POINTER_RESIZE_BL) ||
603             (ec->resize_mode == E_POINTER_RESIZE_B) ||
604             (ec->resize_mode == E_POINTER_RESIZE_BR))
605      {
606         if ((button_id >= 1) && (button_id <= 3))
607           new_h = org_h + (current.y - moveinfo.y);
608         else
609           new_h = ec->moveinfo.down.h + (current.y - moveinfo.y);
610      }
611
612    new_w = MIN(new_w, zone->w);
613    new_h = MIN(new_h, zone->h);
614
615    /* step 4: move to new position */
616    if ((ec->resize_mode == E_POINTER_RESIZE_TL) ||
617        (ec->resize_mode == E_POINTER_RESIZE_L) ||
618        (ec->resize_mode == E_POINTER_RESIZE_BL))
619      new_x += (new_w - org_w);
620    if ((ec->resize_mode == E_POINTER_RESIZE_TL) ||
621        (ec->resize_mode == E_POINTER_RESIZE_T) ||
622        (ec->resize_mode == E_POINTER_RESIZE_TR))
623      new_y += (new_h - org_h);
624
625    /* step 5: set geometry to new value */
626    evas_object_geometry_set(ec->frame, new_x, new_y, new_w, new_h);
627 }
628
629 void
630 _e_client_transform_resize_begin(E_Client *ec)
631 {
632    E_Map *map;
633    if (!ec->transformed) return;
634
635    map = e_client_map_get(ec);
636    _e_client_transform_geometry_save(ec, map);
637    e_map_free(map);
638 }
639
640 void
641 _e_client_transform_resize_end(E_Client *ec)
642 {
643    E_Map *map;
644    int new_x = 0, new_y = 0;
645    int cx, cy, pw, ph;
646
647    if (!ec->transformed) return;
648
649    map = e_client_map_get(ec);
650    if (!map) return;
651
652    if (!e_pixmap_size_get(ec->pixmap, &pw, &ph))
653      {
654         pw = ec->client.w;
655         ph = ec->client.h;
656      }
657
658    cx = ec->client.x + pw / 2 + ec->transform.adjusted.x;
659    cy = ec->client.y + ph / 2 + ec->transform.adjusted.y;
660
661    if (ec->transform.zoom != 1.0)
662      {
663         E_Map *tmp_map;
664
665         tmp_map = e_map_dup(map);
666         e_map_util_zoom(tmp_map,
667                            1 / ec->transform.zoom,
668                            1 / ec->transform.zoom,
669                            cx, cy);
670
671         _e_client_transform_geometry_save(ec, tmp_map);
672         e_map_free(tmp_map);
673      }
674    else
675      {
676         _e_client_transform_geometry_save(ec, map);
677      }
678
679    /* move original object to adjusted position after resizing */
680    _e_client_transform_point_transform(cx, cy,
681                                        ec->transform.angle,
682                                        ec->transform.saved[0].x,
683                                        ec->transform.saved[0].y,
684                                        &new_x, &new_y);
685    e_client_util_move_without_frame(ec, new_x, new_y);
686    e_map_util_object_move_sync_set(map, EINA_TRUE);
687    e_map_free(map);
688 }
689
690 static void
691 _e_client_transform_move_end(E_Client *ec)
692 {
693
694    int i;
695    double dx, dy, px, py;
696    E_Map *map;
697
698    if (!ec->transformed) return;
699
700    map = e_client_map_get(ec);
701    if (!map) return;
702
703    if (ec->transform.zoom != 1.0)
704      {
705         e_map_point_precise_coord_get(map, 0, &px, &py, NULL);
706
707         dx = px - ec->transform.saved[0].x;
708         dy = py - ec->transform.saved[0].y;
709
710         for (i = 0; i < 4; i++)
711           {
712              ec->transform.saved[i].x += dx;
713              ec->transform.saved[i].y += dy;
714           }
715      }
716    else
717      _e_client_transform_geometry_save(ec, map);
718    e_map_free(map);
719 }
720
721 EINTERN Eina_Bool
722 e_client_intercept_hook_focus_revert_call(E_Client *ec)
723 {
724   // no need to call the intercept hook if ec is NULL.
725   if (!ec) return EINA_FALSE;
726
727   if (!_e_client_intercept_hook_call(E_CLIENT_INTERCEPT_HOOK_FOCUS_REVERT, ec))
728     {
729        ELOGF("FOCUS", "E_CLIENT_INTERCEPT_HOOK_FOCUS_REVERT Intercepted.", ec);
730        return EINA_TRUE;
731     }
732
733   return EINA_FALSE;
734 }
735
736 EINTERN E_Client *
737 e_client_check_fully_contain_by_above(E_Client *ec, Eina_Bool check_layer)
738 {
739    E_Client *above = NULL;
740    E_Zone *zone = NULL;
741    int x = 0, y = 0, w = 0, h = 0;
742    int ax = 0, ay = 0, aw = 0, ah = 0;
743
744    if (!ec) return NULL;
745
746    e_client_geometry_get(ec, &x, &y, &w, &h);
747
748    zone = e_comp_zone_find_by_ec(ec);
749    if (zone)
750      E_RECTS_CLIP_TO_RECT(x, y, w, h, zone->x, zone->y, zone->w, zone->h);
751
752    above = e_client_above_get(ec);
753    while (above)
754      {
755         if ((check_layer) &&
756             (above->layer <= ec->layer))
757           {
758              above = e_client_above_get(above);
759              continue;
760           }
761
762         if ((!e_object_is_del(E_OBJECT(above))) &&
763             (!e_client_util_ignored_get(above)) &&
764             (above->visible) &&
765             (!above->iconic || e_policy_visibility_client_is_uniconic(above)) &&
766             (!above->bg_state) &&
767             (!above->argb) &&
768             (!above->visibility.force_obscured) &&
769             (above->frame))
770           {
771              e_client_geometry_get(above, &ax, &ay, &aw, &ah);
772              if (E_CONTAINS(ax, ay, aw, ah, x, y, w, h))
773                break;
774           }
775         above = e_client_above_get(above);
776      }
777
778    return above;
779 }
780
781 EINTERN E_Client *
782 e_client_check_obscured_by_children_group(E_Client *ec)
783 {
784    E_Client *cec = NULL;
785    Eina_List *transients = NULL, *l = NULL;
786
787    _e_client_transient_for_group_make(ec, &transients);
788    if (!transients) return NULL;
789
790    EINA_LIST_FOREACH(transients, l, cec)
791      {
792         if (E_CONTAINS(cec->x, cec->y, cec->w, cec->h, ec->x, ec->y, ec->w, ec->h))
793           {
794             if (!cec->argb) break;
795             if (cec->visibility.opaque > 0) break;
796           }
797      }
798
799    eina_list_free(transients);
800
801    return cec;
802 }
803
804 EINTERN Eina_Bool
805 e_client_check_really_iconified(E_Client *ec)
806 {
807    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
808
809    if (!ec->iconic) return EINA_FALSE;
810
811    return ((!e_policy_visibility_client_is_uniconic(ec) &&
812             !e_policy_visibility_client_is_uniconify_render_running(ec)) ||
813            (e_client_is_iconified_by_client(ec)));
814 }
815
816 static void
817 _e_client_event_focus_skip_set(E_Client *ec, Eina_Bool by_client)
818 {
819    E_Event_Client_Focus_Skip_Set *ev;
820
821    ev = E_NEW(E_Event_Client_Focus_Skip_Set, 1);
822    if (!ev) return;
823
824    ev->ec = ec;
825    ev->by_client = by_client;
826    e_object_ref(E_OBJECT(ec));
827
828    ecore_event_add(E_EVENT_CLIENT_FOCUS_SKIP_SET, ev, (Ecore_End_Cb)_e_client_event_simple_free, NULL);
829 }
830
831 static void
832 _e_client_event_focus_skip_unset(E_Client *ec, Eina_Bool by_client)
833 {
834    E_Event_Client_Focus_Skip_Unset *ev;
835
836    ev = E_NEW(E_Event_Client_Focus_Skip_Unset, 1);
837    if (!ev) return;
838
839    ev->ec = ec;
840    ev->by_client = by_client;
841    e_object_ref(E_OBJECT(ec));
842
843    ecore_event_add(E_EVENT_CLIENT_FOCUS_SKIP_UNSET, ev, (Ecore_End_Cb)_e_client_event_simple_free, NULL);
844 }
845
846 E_API void
847 e_client_focus_skip_set(E_Client *ec, Eina_Bool skip, Eina_Bool by_client)
848 {
849    if (!ec) return;
850
851    if (skip)
852      {
853         if (ec->icccm.accepts_focus)
854           {
855              ELOGF("TZPOL", "FOCUS|SKIP SET (by_client:%d)", ec, by_client);
856              ec->icccm.accepts_focus = ec->icccm.take_focus = 0;
857              ec->changes.accepts_focus = 1;
858              EC_CHANGED(ec);
859
860              _e_client_event_focus_skip_set(ec, by_client);
861           }
862      }
863    else
864      {
865         if (!ec->icccm.accepts_focus)
866           {
867              ELOGF("TZPOL", "FOCUS|SKIP UNSET (by_client:%d)", ec, by_client);
868              ec->icccm.accepts_focus = ec->icccm.take_focus = 1;
869              ec->changes.accepts_focus = 1;
870              EC_CHANGED(ec);
871
872              _e_client_event_focus_skip_unset(ec, by_client);
873           }
874      }
875 }
876
877 EINTERN Eina_Bool
878 e_client_check_above_focused(E_Client *ec)
879 {
880    E_Client *focus = NULL;
881    E_Client *above = NULL;
882
883    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
884
885    focus = e_client_focused_get();
886    if (!focus) return EINA_FALSE;
887
888    above = e_client_above_get(ec);
889    while (above)
890      {
891         if (above == focus)
892           return EINA_TRUE;
893
894         above = e_client_above_get(above);
895      }
896
897    return EINA_FALSE;
898 }
899
900 static Eina_Bool
901 _e_client_private_init(E_Client *ec)
902 {
903    E_Client_Private *priv;
904
905    priv = E_NEW(E_Client_Private, 1);
906    if (!priv)
907      return EINA_FALSE;
908
909    wl_signal_init(&priv->events.eval_pre_fetch);
910    wl_signal_init(&priv->events.eval_fetch);
911    wl_signal_init(&priv->events.eval_pre_post_fetch);
912    wl_signal_init(&priv->events.eval_post_fetch);
913    wl_signal_init(&priv->events.eval_pre_frame_assign);
914    wl_signal_init(&priv->events.eval_post_frame_assign);
915    wl_signal_init(&priv->events.eval_pre_new_client);
916    wl_signal_init(&priv->events.eval_post_new_client);
917    wl_signal_init(&priv->events.eval_visibility);
918    wl_signal_init(&priv->events.eval_visibility_end);
919    wl_signal_init(&priv->events.eval_end);
920    wl_signal_init(&priv->events.move_begin);
921    wl_signal_init(&priv->events.move_update);
922    wl_signal_init(&priv->events.move_end);
923    wl_signal_init(&priv->events.move_resize_begin);
924    wl_signal_init(&priv->events.move_resize_update);
925    wl_signal_init(&priv->events.move_resize_end);
926    wl_signal_init(&priv->events.destroy);
927    wl_signal_init(&priv->events.new_client);
928    wl_signal_init(&priv->events.new_client_post);
929    wl_signal_init(&priv->events.unredirect);
930    wl_signal_init(&priv->events.redirect);
931    wl_signal_init(&priv->events.aux_hint_change);
932    wl_signal_init(&priv->events.window_role_change);
933    wl_signal_init(&priv->events.transform_change);
934    wl_signal_init(&priv->events.activate_done);
935    wl_signal_init(&priv->events.mouse_in);
936    wl_signal_init(&priv->events.mouse_out);
937    wl_signal_init(&priv->events.mouse_down);
938    wl_signal_init(&priv->events.focus_set);
939    wl_signal_init(&priv->events.focus_unset);
940    wl_signal_init(&priv->events.focus_defer_set);
941    wl_signal_init(&priv->events.focus_latest_set);
942    wl_signal_init(&priv->events.iconify);
943    wl_signal_init(&priv->events.uniconify);
944    wl_signal_init(&priv->events.maximize);
945    wl_signal_init(&priv->events.unmaximize);
946    wl_signal_init(&priv->events.fullscreen_pre);
947    wl_signal_init(&priv->events.fullscreen);
948    wl_signal_init(&priv->events.unfullscreen);
949    wl_signal_init(&priv->events.move);
950    wl_signal_init(&priv->events.set_layer);
951    wl_signal_init(&priv->events.raise);
952    wl_signal_init(&priv->events.lower);
953    wl_signal_init(&priv->events.stack_below);
954    wl_signal_init(&priv->events.stack_above);
955    wl_signal_init(&priv->events.stack_transient_for_done);
956    wl_signal_init(&priv->events.stick);
957    wl_signal_init(&priv->events.unstick);
958 #ifdef REFACTOR_DESK_AREA
959    wl_signal_init(&priv->events.get_above);
960    wl_signal_init(&priv->events.get_below);
961    wl_signal_init(&priv->events.get_visible_above);
962    wl_signal_init(&priv->events.get_visible_below);
963    wl_signal_init(&priv->events.subsurface_stack_update);
964 #endif
965
966    e_object_data_set(E_OBJECT(ec), priv);
967
968    return EINA_TRUE;
969 }
970
971 static void
972 _e_client_private_finish(E_Client *ec)
973 {
974    E_Client_Private *priv;
975
976    priv = PRI(ec);
977    e_object_data_set(E_OBJECT(ec), NULL);
978
979    free(priv);
980 }
981
982 static void
983 _e_client_free(E_Client *ec)
984 {
985    g_rec_mutex_lock(&e_comp->ec_list_mutex);
986
987    e_comp_object_redirected_set(ec->frame, 0);
988    e_comp_object_render_update_del(ec->frame);
989
990    E_OBJECT(ec)->references++;
991
992    if (ec->new_client)
993      e_comp->new_clients--;
994
995    if (ec->e.state.video_parent && ec->e.state.video_parent_client)
996      {
997         ec->e.state.video_parent_client->e.state.video_child =
998           eina_list_remove(ec->e.state.video_parent_client->e.state.video_child, ec);
999      }
1000    if (ec->e.state.video_child)
1001      {
1002         E_Client *tmp;
1003
1004         EINA_LIST_FREE(ec->e.state.video_child, tmp)
1005           tmp->e.state.video_parent_client = NULL;
1006      }
1007    E_FREE_FUNC(ec->kill_timer, ecore_timer_del);
1008
1009    E_FREE_FUNC(ec->map_timer, ecore_timer_del);
1010
1011    ec->transients = eina_list_free(ec->transients);
1012    eina_stringshare_replace(&ec->border.name, NULL);
1013    eina_stringshare_replace(&ec->bordername, NULL);
1014    eina_stringshare_replace(&ec->icccm.name, NULL);
1015 #if defined(__cplusplus) || defined(c_plusplus)
1016    eina_stringshare_replace(&ec->icccm.cpp_class, NULL);
1017 #else
1018    eina_stringshare_replace(&ec->icccm.class, NULL);
1019 #endif
1020    e_client_icccm_title_set(ec, NULL);
1021    eina_stringshare_replace(&ec->icccm.window_role, NULL);
1022    e_client_netwm_name_set(ec, NULL);
1023
1024    E_FREE_FUNC(ec->frame, evas_object_del);
1025
1026    E_OBJECT(ec)->references--;
1027    ELOGF("COMP", "CLIENT FREE", ec);
1028
1029    e_uuid_store_entry_del(ec->uuid);
1030
1031    _e_client_private_finish(ec);
1032    free(ec);
1033
1034    g_rec_mutex_unlock(&e_comp->ec_list_mutex);
1035 }
1036
1037 static void
1038 _e_client_del(E_Client *ec)
1039 {
1040    E_Client *child;
1041    E_Pixmap_Type type;
1042
1043    g_rec_mutex_lock(&e_comp->ec_list_mutex);
1044
1045    ec->changed = 0;
1046
1047    if (ec == e_comp_object_dim_client_get())
1048      {
1049         INF("[DIM] client deleted\n");
1050         e_comp_object_dim_client_set(NULL);
1051      }
1052
1053    if (ec->cur_mouse_action)
1054      {
1055         if (ec->cur_mouse_action->func.end)
1056           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
1057      }
1058    if (action_client == ec) _e_client_action_finish();
1059
1060    if (!stopping)
1061      {
1062         e_client_comp_hidden_set(ec, 1);
1063         evas_object_pass_events_set(ec->frame, 1);
1064      }
1065
1066    E_FREE_FUNC(ec->ping_poller, ecore_poller_del);
1067
1068    wl_signal_emit_mutable(&PRI(ec)->events.destroy, NULL);
1069
1070    /* must be called before parent/child clear */
1071    _e_client_hook_call(E_CLIENT_HOOK_DEL, ec);
1072
1073    _e_client_event_remove(ec);
1074
1075    ELOGF("COMP", "CLIENT DEL", ec);
1076
1077    if (ec->parent)
1078      {
1079         ec->parent->transients = eina_list_remove(ec->parent->transients, ec);
1080         ec->parent = NULL;
1081      }
1082    EINA_LIST_FREE(ec->transients, child)
1083      child->parent = NULL;
1084
1085    type = e_pixmap_type_get(ec->pixmap);
1086    if (type < E_PIXMAP_TYPE_MAX)
1087      eina_hash_del_by_key(clients_hash[type], &ec->pixmap);
1088    e_comp->clients = eina_list_remove(e_comp->clients, ec);
1089    e_comp_object_render_update_del(ec->frame);
1090    e_comp_post_update_purge(ec);
1091    if (e_pixmap_free(ec->pixmap))
1092      e_pixmap_client_set(ec->pixmap, NULL);
1093    ec->pixmap = NULL;
1094
1095    // base_output_resolution
1096    e_util_transform_del(ec->base_output_resolution.transform);
1097    ec->base_output_resolution.transform = NULL;
1098    E_FREE_FUNC(ec->base_output_resolution.hook_subsurf_create, e_comp_wl_hook_del);
1099
1100    if (ec->transform_core.transform_list)
1101      {
1102         E_Util_Transform *transform;
1103
1104         EINA_LIST_FREE(ec->transform_core.transform_list, transform)
1105           {
1106              e_util_transform_unref(transform);
1107           }
1108      }
1109
1110    ec->transform_core.result.enable = EINA_FALSE;
1111
1112    _e_client_resize_object_del(ec);
1113
1114    e_comp_visibility_calculation_set(EINA_TRUE);
1115
1116    g_rec_mutex_unlock(&e_comp->ec_list_mutex);
1117 }
1118
1119 ///////////////////////////////////////////
1120
1121 static Eina_Bool
1122 _e_client_cb_kill_timer(void *data)
1123 {
1124    E_Client *ec = data;
1125
1126 // dont wait until it's hung -
1127 //   if (ec->hung)
1128 //     {
1129    if (ec->netwm.pid > 1)
1130      kill(ec->netwm.pid, SIGKILL);
1131 //     }
1132    ec->kill_timer = NULL;
1133    return ECORE_CALLBACK_CANCEL;
1134 }
1135
1136 static Eina_Bool
1137 _e_client_cb_ping_poller(void *data)
1138 {
1139    E_Client *ec;
1140
1141    ec = data;
1142    if (e_object_is_del(E_OBJECT(ec)))
1143      {
1144         ec->ping_poller = NULL;
1145         return ECORE_CALLBACK_CANCEL;
1146      }
1147
1148    if (ec->ping_ok)
1149      {
1150         if (ec->hung)
1151           {
1152              ec->hung = 0;
1153              evas_object_smart_callback_call(ec->frame, "unhung", NULL);
1154              E_FREE_FUNC(ec->kill_timer, ecore_timer_del);
1155           }
1156      }
1157    else
1158      {
1159         /* if time between last ping and now is greater
1160          * than half the ping interval... */
1161         if ((ecore_loop_time_get() - ec->ping) >
1162             ((e_config->ping_clients_interval *
1163               ecore_poller_poll_interval_get(ECORE_POLLER_CORE)) / 2.0))
1164           {
1165              if (!ec->hung)
1166                {
1167                   ec->hung = 1;
1168                   evas_object_smart_callback_call(ec->frame, "hung", NULL);
1169                   /* FIXME: if below dialog is up - hide it now */
1170                }
1171              if (ec->delete_requested)
1172                {
1173                   /* FIXME: pop up dialog saying app is hung - kill client, or pid */
1174                   e_client_act_kill_begin(ec);
1175                }
1176           }
1177      }
1178    ec->ping_poller = NULL;
1179    e_client_ping(ec);
1180    return ECORE_CALLBACK_CANCEL;
1181 }
1182
1183 ///////////////////////////////////////////
1184
1185 static int
1186 _e_client_action_input_win_new(void)
1187 {
1188    if (comp_grabbed)
1189      {
1190         CRI("DOUBLE COMP GRAB! ACK!!!!");
1191         return 1;
1192      }
1193    comp_grabbed = e_comp_grab_input(1, 1);
1194    if (!comp_grabbed) _e_client_action_input_win_del();
1195    return comp_grabbed;
1196 }
1197
1198 static void
1199 _e_client_action_init(E_Client *ec)
1200 {
1201    action_orig.x = ec->x;
1202    action_orig.y = ec->y;
1203    action_orig.w = ec->w;
1204    action_orig.h = ec->h;
1205
1206    if (action_client)
1207      {
1208         action_client->keyboard_resizing = 0;
1209      }
1210    action_client = ec;
1211 }
1212
1213 static int
1214 _e_client_move_begin(E_Client *ec)
1215 {
1216    if ((ec->fullscreen) || (ec->lock_user_location))
1217      return 0;
1218
1219    if (!_e_client_action_input_win_new()) return 0;
1220    ec->moving = 1;
1221    ecmove = ec;
1222
1223    wl_signal_emit(&PRI(ec)->events.move_begin, NULL);
1224    _e_client_hook_call(E_CLIENT_HOOK_MOVE_BEGIN, ec);
1225    if (!ec->moving)
1226      {
1227         if (ecmove == ec) ecmove = NULL;
1228         _e_client_action_input_win_del();
1229         return 0;
1230      }
1231    if (!ec->lock_user_stacking)
1232      {
1233         if (e_config->border_raise_on_mouse_action)
1234           e_client_raise(ec);
1235      }
1236
1237    if (e_comp->hwc)
1238      e_comp_client_override_add(ec);
1239
1240    return 1;
1241 }
1242
1243 static int
1244 _e_client_move_end(E_Client *ec)
1245 {
1246    ec->moving = 0;
1247    _e_client_action_input_win_del();
1248
1249    wl_signal_emit(&PRI(ec)->events.move_end, NULL);
1250    _e_client_hook_call(E_CLIENT_HOOK_MOVE_END, ec);
1251
1252    if (ec->transformed)
1253      _e_client_transform_move_end(ec);
1254
1255    if (e_comp->hwc)
1256      e_comp_client_override_del(ec);
1257
1258    ecmove = NULL;
1259    return 1;
1260 }
1261
1262 static Eina_Bool
1263 _e_client_action_move_timeout(void *data EINA_UNUSED)
1264 {
1265    _e_client_move_end(action_client);
1266    _e_client_action_finish();
1267    return ECORE_CALLBACK_CANCEL;
1268 }
1269
1270 static void
1271 _e_client_action_move_timeout_add(void)
1272 {
1273    E_FREE_FUNC(action_timer, ecore_timer_del);
1274    if (e_config->border_keyboard.timeout)
1275      action_timer = ecore_timer_add(e_config->border_keyboard.timeout, _e_client_action_move_timeout, NULL);
1276 }
1277
1278 static Eina_Bool
1279 _e_client_move_mouse_down(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
1280 {
1281    if (!comp_grabbed) return ECORE_CALLBACK_RENEW;
1282
1283    if (!action_client)
1284      ERR("no action_client!");
1285
1286    if (action_client) _e_client_move_end(action_client);
1287    _e_client_action_finish();
1288    return ECORE_CALLBACK_DONE;
1289 }
1290
1291 static void
1292 _e_client_moveinfo_gather(E_Client *ec, const char *source)
1293 {
1294    if (e_util_glob_match(source, "mouse,*,1"))
1295      ec->moveinfo.down.button = 1;
1296    else if (e_util_glob_match(source, "mouse,*,2"))
1297      ec->moveinfo.down.button = 2;
1298    else if (e_util_glob_match(source, "mouse,*,3"))
1299      ec->moveinfo.down.button = 3;
1300    else
1301      ec->moveinfo.down.button = 0;
1302    if ((ec->moveinfo.down.button >= 1) && (ec->moveinfo.down.button <= 3))
1303      {
1304         ec->moveinfo.down.mx = ec->mouse.last_down[ec->moveinfo.down.button - 1].mx;
1305         ec->moveinfo.down.my = ec->mouse.last_down[ec->moveinfo.down.button - 1].my;
1306      }
1307    else
1308      {
1309         ec->moveinfo.down.mx = ec->mouse.current.mx;
1310         ec->moveinfo.down.my = ec->mouse.current.my;
1311      }
1312 }
1313
1314 static void
1315 _e_client_move_handle(E_Client *ec)
1316 {
1317    int x, y;
1318
1319    if ((ec->moveinfo.down.button >= 1) && (ec->moveinfo.down.button <= 3))
1320      {
1321         x = ec->mouse.last_down[ec->moveinfo.down.button - 1].x +
1322            (ec->mouse.current.mx - ec->moveinfo.down.mx);
1323         y = ec->mouse.last_down[ec->moveinfo.down.button - 1].y +
1324            (ec->mouse.current.my - ec->moveinfo.down.my);
1325      }
1326    else
1327      {
1328         x = ec->moveinfo.down.x +
1329            (ec->mouse.current.mx - ec->moveinfo.down.mx);
1330         y = ec->moveinfo.down.y +
1331            (ec->mouse.current.my - ec->moveinfo.down.my);
1332      }
1333
1334    if (e_config->screen_limits == E_CLIENT_OFFSCREEN_LIMIT_ALLOW_NONE)
1335      _e_client_stay_within_canvas(ec, x, y, &x, &y);
1336
1337    if (ec->floating)
1338      _e_client_stay_within_canvas_margin(ec, x, y, &x, &y);
1339
1340    evas_object_move(ec->frame, x, y);
1341
1342    if (e_client_transform_core_enable_get(ec))
1343      {
1344         e_client_transform_core_update(ec);
1345      }
1346 }
1347
1348 static Evas_Object *
1349 _e_client_resize_object_rectangle_get(E_Client *ec)
1350 {
1351    Evas_Object *resize_obj = NULL;
1352
1353    resize_obj = evas_object_rectangle_add(evas_object_evas_get(ec->frame));
1354    EINA_SAFETY_ON_NULL_RETURN_VAL(resize_obj, NULL);
1355
1356    if (e_config->resize_object.customize)
1357      {
1358         evas_object_color_set(resize_obj,
1359                               e_config->resize_object.r,
1360                               e_config->resize_object.g,
1361                               e_config->resize_object.b,
1362                               e_config->resize_object.a);
1363      }
1364    else
1365      evas_object_color_set(resize_obj, 128, 128, 128, 100);
1366
1367    return resize_obj;
1368 }
1369
1370 static Evas_Object *
1371 _e_client_resize_object_image_get(E_Client *ec)
1372 {
1373    int err;
1374    Evas_Object *resize_obj = NULL;
1375
1376    if (!e_config->resize_object.image_path)
1377      {
1378         ELOGF("COMP", "NO resize_object image! Make default resize_object", ec);
1379         goto get_rectangle;
1380      }
1381
1382    resize_obj = evas_object_image_add(evas_object_evas_get(ec->frame));
1383    EINA_SAFETY_ON_NULL_RETURN_VAL(resize_obj, NULL);
1384
1385    evas_object_image_file_set(resize_obj, e_config->resize_object.image_path, NULL);
1386    err = evas_object_image_load_error_get(resize_obj);
1387    if (err != EVAS_LOAD_ERROR_NONE)
1388      {
1389         ELOGF("COMP", "Image load error. path:%s, errno:%d. Make default resize_object",
1390               ec, e_config->resize_object.image_path, err);
1391         evas_object_del(resize_obj);
1392         resize_obj = NULL;
1393         goto get_rectangle;
1394      }
1395
1396    evas_object_image_fill_set(resize_obj, 0, 0, ec->w, ec->h);
1397    evas_object_image_filled_set(resize_obj, EINA_TRUE);
1398
1399    evas_object_image_border_set(resize_obj,
1400                                 e_config->resize_object.border_width.l,
1401                                 e_config->resize_object.border_width.r,
1402                                 e_config->resize_object.border_width.t,
1403                                 e_config->resize_object.border_width.b);
1404
1405    return resize_obj;
1406
1407 get_rectangle:
1408    return _e_client_resize_object_rectangle_get(ec);
1409 }
1410
1411 static Evas_Object *
1412 _e_client_resize_object_create(E_Client *ec)
1413 {
1414    EINA_SAFETY_ON_NULL_RETURN_VAL(ec->frame, NULL);
1415
1416    Evas_Object *resize_obj = NULL;
1417
1418    if (_e_client_resize_object_create_cb)
1419      resize_obj = _e_client_resize_object_create_cb(ec);
1420    else
1421      {
1422         if (e_config->resize_object.type == 1) // image object
1423           {
1424              resize_obj = _e_client_resize_object_image_get(ec);
1425           }
1426         else // rectangle
1427           {
1428              resize_obj = _e_client_resize_object_rectangle_get(ec);
1429           }
1430      }
1431    EINA_SAFETY_ON_NULL_RETURN_VAL(resize_obj, NULL);
1432
1433    evas_object_pass_events_set(resize_obj, EINA_TRUE);
1434    evas_object_layer_set(resize_obj, evas_object_layer_get(ec->frame));
1435    evas_object_stack_above(resize_obj, ec->frame);
1436    evas_object_name_set(resize_obj, "resize_object");
1437
1438    return resize_obj;
1439 }
1440
1441 static void
1442 _e_client_resize_object_del(E_Client *ec)
1443 {
1444    if (ec == NULL) return;
1445    if (ec->manage_resize.resize_obj == NULL) return;
1446
1447    evas_object_hide(ec->manage_resize.resize_obj);
1448    evas_object_del(ec->manage_resize.resize_obj);
1449    ec->manage_resize.resize_obj = NULL;
1450 }
1451
1452 static void
1453 _e_client_resize_handle(E_Client *ec)
1454 {
1455    int x, y, w, h;
1456    int new_x, new_y, new_w, new_h;
1457    int tw, th;
1458    int trans_x = 0, trans_y = 0;
1459    int trans_w = 0, trans_h = 0;
1460
1461    if (ec->transformed)
1462      {
1463         _e_client_transform_resize_handle(ec);
1464         return;
1465      }
1466
1467    x = ec->x;
1468    y = ec->y;
1469    w = ec->w;
1470    h = ec->h;
1471
1472    if ((ec->resize_mode == E_POINTER_RESIZE_TR) ||
1473        (ec->resize_mode == E_POINTER_RESIZE_R) ||
1474        (ec->resize_mode == E_POINTER_RESIZE_BR))
1475      {
1476         if ((ec->moveinfo.down.button >= 1) &&
1477             (ec->moveinfo.down.button <= 3))
1478           w = ec->mouse.last_down[ec->moveinfo.down.button - 1].w +
1479             (ec->mouse.current.mx - ec->moveinfo.down.mx);
1480         else
1481           w = ec->moveinfo.down.w + (ec->mouse.current.mx - ec->moveinfo.down.mx);
1482      }
1483    else if ((ec->resize_mode == E_POINTER_RESIZE_TL) ||
1484             (ec->resize_mode == E_POINTER_RESIZE_L) ||
1485             (ec->resize_mode == E_POINTER_RESIZE_BL))
1486      {
1487         if ((ec->moveinfo.down.button >= 1) &&
1488             (ec->moveinfo.down.button <= 3))
1489           w = ec->mouse.last_down[ec->moveinfo.down.button - 1].w -
1490             (ec->mouse.current.mx - ec->moveinfo.down.mx);
1491         else
1492           w = ec->moveinfo.down.w - (ec->mouse.current.mx - ec->moveinfo.down.mx);
1493      }
1494
1495    if ((ec->resize_mode == E_POINTER_RESIZE_TL) ||
1496        (ec->resize_mode == E_POINTER_RESIZE_T) ||
1497        (ec->resize_mode == E_POINTER_RESIZE_TR))
1498      {
1499         if ((ec->moveinfo.down.button >= 1) &&
1500             (ec->moveinfo.down.button <= 3))
1501           h = ec->mouse.last_down[ec->moveinfo.down.button - 1].h -
1502             (ec->mouse.current.my - ec->moveinfo.down.my);
1503         else
1504           h = ec->moveinfo.down.h - (ec->mouse.current.my - ec->moveinfo.down.my);
1505      }
1506    else if ((ec->resize_mode == E_POINTER_RESIZE_BL) ||
1507             (ec->resize_mode == E_POINTER_RESIZE_B) ||
1508             (ec->resize_mode == E_POINTER_RESIZE_BR))
1509      {
1510         if ((ec->moveinfo.down.button >= 1) &&
1511             (ec->moveinfo.down.button <= 3))
1512           h = ec->mouse.last_down[ec->moveinfo.down.button - 1].h +
1513             (ec->mouse.current.my - ec->moveinfo.down.my);
1514         else
1515           h = ec->moveinfo.down.h + (ec->mouse.current.my - ec->moveinfo.down.my);
1516      }
1517    tw = ec->w;
1518    th = ec->h;
1519
1520    if ((ec->resize_mode == E_POINTER_RESIZE_T) ||
1521        (ec->resize_mode == E_POINTER_RESIZE_TL) ||
1522        (ec->resize_mode == E_POINTER_RESIZE_L) ||
1523        (ec->resize_mode == E_POINTER_RESIZE_BL))
1524      x += (tw - w);
1525    if ((ec->resize_mode == E_POINTER_RESIZE_L) ||
1526        (ec->resize_mode == E_POINTER_RESIZE_TL) ||
1527        (ec->resize_mode == E_POINTER_RESIZE_T) ||
1528        (ec->resize_mode == E_POINTER_RESIZE_TR))
1529      y += (th - h);
1530
1531    new_x = x;
1532    new_y = y;
1533    new_w = w;
1534    new_h = h;
1535    if (e_config->screen_limits == E_CLIENT_OFFSCREEN_LIMIT_ALLOW_NONE)
1536      {
1537         E_Zone *zone;
1538         zone = e_comp_zone_find_by_ec(ec);
1539         if (zone)
1540           {
1541              w = MIN(w, zone->w);
1542              h = MIN(h, zone->h);
1543           }
1544      }
1545    e_client_resize_limit(ec, &new_w, &new_h);
1546
1547    if (ec->manage_resize.enable_aspect_ratio)
1548      {
1549         if ((ec->resize_mode == E_POINTER_RESIZE_TL) ||
1550             (ec->resize_mode == E_POINTER_RESIZE_L) ||
1551             (ec->resize_mode == E_POINTER_RESIZE_BL) ||
1552             (ec->resize_mode == E_POINTER_RESIZE_TR) ||
1553             (ec->resize_mode == E_POINTER_RESIZE_R) ||
1554             (ec->resize_mode == E_POINTER_RESIZE_BR))
1555           {
1556              new_h = (int) ec->manage_resize.ah / ec->manage_resize.aw * new_w;
1557           }
1558         else if ((ec->resize_mode == E_POINTER_RESIZE_T) ||
1559                  (ec->resize_mode == E_POINTER_RESIZE_B))
1560           {
1561              new_w = (int) ec->manage_resize.aw / ec->manage_resize.ah * new_h;
1562           }
1563           new_h += ec->manage_resize.header_h;
1564           new_h += ec->manage_resize.footer_h;
1565      }
1566
1567    if ((ec->resize_mode == E_POINTER_RESIZE_T) ||
1568        (ec->resize_mode == E_POINTER_RESIZE_TL) ||
1569        (ec->resize_mode == E_POINTER_RESIZE_L) ||
1570        (ec->resize_mode == E_POINTER_RESIZE_BL))
1571      new_x += (w - new_w);
1572    if ((ec->resize_mode == E_POINTER_RESIZE_L) ||
1573        (ec->resize_mode == E_POINTER_RESIZE_TL) ||
1574        (ec->resize_mode == E_POINTER_RESIZE_T) ||
1575        (ec->resize_mode == E_POINTER_RESIZE_TR))
1576      new_y += (h - new_h);
1577
1578    if (e_config->interactive_resize)
1579      {
1580         evas_object_geometry_set(ec->frame, new_x, new_y, new_w, new_h);
1581      }
1582    else
1583      {
1584         if (ec->manage_resize.resize_obj == NULL)
1585           {
1586              ec->manage_resize.resize_obj = _e_client_resize_object_create(ec);
1587              EINA_SAFETY_ON_NULL_RETURN(ec->manage_resize.resize_obj);
1588           }
1589
1590         if (e_client_transform_core_enable_get(ec))
1591           {
1592              e_client_transform_core_input_inv_transform(ec, new_x, new_y, &trans_x, &trans_y);
1593              e_client_transform_core_input_inv_transform(ec, new_w, new_h, &trans_w, &trans_h);
1594              evas_object_geometry_set(ec->manage_resize.resize_obj, trans_x, trans_y, trans_w, trans_h);
1595           }
1596         else
1597           evas_object_geometry_set(ec->manage_resize.resize_obj, new_x, new_y, new_w, new_h);
1598         evas_object_show(ec->manage_resize.resize_obj);
1599
1600         ec->manage_resize.x = new_x;
1601         ec->manage_resize.y = new_y;
1602         ec->manage_resize.w = new_w;
1603         ec->manage_resize.h = new_h;
1604      }
1605 }
1606
1607 static int
1608 _e_client_adjust_size_by_ppu(int size, int start_size, unsigned int ppu)
1609 {
1610    if (ppu <= 1) return size;
1611
1612    unsigned int remainder = size % ppu;
1613    if (remainder == 0) return size;
1614
1615    int gap = size - start_size;
1616    int new_size = size;
1617    if (gap > 0)
1618      new_size = size + (ppu - remainder);
1619    else
1620      new_size = size - remainder;
1621
1622    return new_size;
1623 }
1624
1625 static int
1626 _e_client_adjust_position_by_ppu(int pos, int size, int prev_pos, int prev_size)
1627 {
1628    int new_pos = 0;
1629
1630    if (prev_pos == pos)
1631      new_pos = pos;
1632    else
1633      new_pos = (prev_pos + prev_size) - size;
1634
1635    return new_pos;
1636 }
1637
1638 static void
1639 _e_client_adjust_geometry_by_resize_ppu(E_Client *ec)
1640 {
1641    if (ec->manage_resize.unit_size <= 1) return;
1642
1643    ec->manage_resize.w = _e_client_adjust_size_by_ppu(ec->manage_resize.w, ec->w, ec->manage_resize.unit_size);
1644    ec->manage_resize.h = _e_client_adjust_size_by_ppu(ec->manage_resize.h, ec->h, ec->manage_resize.unit_size);
1645
1646    ec->manage_resize.x = _e_client_adjust_position_by_ppu(ec->manage_resize.x, ec->manage_resize.w, ec->x, ec->w);
1647    ec->manage_resize.y = _e_client_adjust_position_by_ppu(ec->manage_resize.y, ec->manage_resize.h, ec->y, ec->h);
1648 }
1649
1650 static int
1651 _e_client_resize_end(E_Client *ec)
1652 {
1653    ec->resize_mode = E_POINTER_RESIZE_NONE;
1654    _e_client_action_input_win_del();
1655
1656    wl_signal_emit(&PRI(ec)->events.move_resize_end, NULL);
1657    _e_client_hook_call(E_CLIENT_HOOK_RESIZE_END, ec);
1658
1659    if (ec->transformed)
1660      _e_client_transform_resize_end(ec);
1661
1662    if (e_comp->hwc)
1663      e_comp_client_override_del(ec);
1664
1665    ecresize = NULL;
1666
1667    if (!e_config->interactive_resize)
1668      {
1669         if (ec->manage_resize.resize_obj)
1670           {
1671              if (ec->manage_resize.unit_size > 1)
1672                _e_client_adjust_geometry_by_resize_ppu(ec);
1673
1674              e_client_frame_geometry_set(ec,
1675                                          ec->manage_resize.x,
1676                                          ec->manage_resize.y,
1677                                          ec->manage_resize.w,
1678                                          ec->manage_resize.h);
1679              _e_client_resize_object_del(ec);
1680           }
1681      }
1682
1683    return 1;
1684 }
1685
1686 static Eina_Bool
1687 _e_client_action_resize_timeout(void *data EINA_UNUSED)
1688 {
1689    _e_client_resize_end(action_client);
1690    _e_client_action_finish();
1691    return ECORE_CALLBACK_CANCEL;
1692 }
1693
1694 static void
1695 _e_client_action_resize_timeout_add(void)
1696 {
1697    E_FREE_FUNC(action_timer, ecore_timer_del);
1698    if (e_config->border_keyboard.timeout)
1699      action_timer = ecore_timer_add(e_config->border_keyboard.timeout, _e_client_action_resize_timeout, NULL);
1700 }
1701
1702 static Eina_Bool
1703 _e_client_resize_mouse_down(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
1704 {
1705    if (!comp_grabbed) return ECORE_CALLBACK_RENEW;
1706
1707    if (!action_client)
1708      ERR("no action_client!");
1709
1710    if (action_client) _e_client_resize_end(action_client);
1711    _e_client_action_finish();
1712    return ECORE_CALLBACK_DONE;
1713 }
1714
1715 ////////////////////////////////////////////////
1716
1717 static Eina_Bool
1718 _e_client_position_inside_input_rect(E_Client *ec, int tx, int ty)
1719 {
1720    int x, y, w, h;
1721    Eina_Bool res = EINA_FALSE;
1722    Eina_List *list = NULL, *l;
1723    Eina_Rectangle *data;
1724
1725    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
1726
1727    e_client_geometry_get(ec, &x, &y, &w, &h);
1728    e_comp_object_input_rect_get(ec->frame, &list);
1729    if (list)
1730      {
1731         EINA_LIST_FOREACH(list, l, data)
1732           {
1733              if ((tx >= x + data->x) && (tx <= x + data->x + data->w) &&
1734                  (ty >= y + data->y) && (ty <= y + data->y + data->h))
1735                {
1736                   res = EINA_TRUE;
1737                   break;
1738                }
1739           }
1740         list = eina_list_free(list);
1741      }
1742    else
1743      {
1744         if ((tx >= x) && (tx <= x + w) &&
1745             (ty >= y) && (ty <= y + h))
1746           {
1747              res = EINA_TRUE;
1748           }
1749      }
1750
1751    return res;
1752 }
1753
1754 static Eina_Bool
1755 _e_client_under_pointer_helper_ignore_client(E_Desk *desk, E_Client *client)
1756 {
1757    /* If a border was specified which should be excluded from the list
1758     * (because it will be closed shortly for example), skip */
1759    if (e_client_util_ignored_get(client) || (!e_desk_has_ec(desk, client))) return EINA_TRUE;
1760    if (!evas_object_visible_get(client->frame)) return EINA_TRUE;
1761    if (e_policy_client_is_cursor(client)) return EINA_TRUE;
1762    if (e_comp_wl->drag_client == client) return EINA_TRUE;
1763
1764    return EINA_FALSE;
1765 }
1766
1767 static E_Client *
1768 _e_client_under_pointer_helper(E_Desk *desk, E_Client *exclude, int x, int y)
1769 {
1770    E_Client *ec = NULL, *cec;
1771
1772    E_CLIENT_REVERSE_FOREACH(cec)
1773      {
1774         if (_e_client_under_pointer_helper_ignore_client(desk, cec)) continue;
1775         if ((exclude) && (cec == exclude)) continue;
1776         if (!E_INSIDE(x, y, cec->x, cec->y, cec->w, cec->h))
1777           continue;
1778         /* If the layer is higher, the position of the window is higher
1779          * (always on top vs always below) */
1780         if (!ec || (cec->layer > ec->layer))
1781           ec = cec;
1782      }
1783    return ec;
1784 }
1785
1786 static E_Client *
1787 _e_client_under_pointer_input_helper(E_Desk *desk, int x, int y)
1788 {
1789    E_Client *ec = NULL, *cec;
1790
1791    E_CLIENT_REVERSE_FOREACH(cec)
1792      {
1793         if (_e_client_under_pointer_helper_ignore_client(desk, cec)) continue;
1794
1795         Eina_List *list = NULL;
1796         Eina_Rectangle *rect;
1797         Eina_Bool inside = EINA_FALSE;
1798         e_comp_object_input_rect_get(cec->frame, &list);
1799         if (list)
1800           {
1801              EINA_LIST_FREE(list, rect)
1802                {
1803                   if (E_INSIDE(x, y, rect->x, rect->y, rect->w, rect->h))
1804                     inside = EINA_TRUE;
1805                }
1806           }
1807         else if (E_INSIDE(x, y, cec->x, cec->y, cec->w, cec->h))
1808           {
1809              inside = EINA_TRUE;
1810           }
1811
1812         if (!inside) continue;
1813         /* If the layer is higher, the position of the window is higher
1814          * (always on top vs always below) */
1815         if (!ec || (cec->layer > ec->layer))
1816           ec = cec;
1817      }
1818
1819    return ec;
1820 }
1821
1822 ////////////////////////////////////////////////
1823
1824 static void
1825 _e_client_zones_layout_calc(E_Client *ec, int *zx, int *zy, int *zw, int *zh)
1826 {
1827    int x, y, w, h;
1828    E_Zone *zone_above, *zone_below, *zone_left, *zone_right;
1829    E_Zone *zone;
1830
1831    zone = e_comp_zone_find_by_ec(ec);
1832    if (!zone) return;
1833    x = zone->x;
1834    y = zone->y;
1835    w = zone->w;
1836    h = zone->h;
1837
1838    if (eina_list_count(e_comp->zones) == 1)
1839      {
1840         if (zx) *zx = x;
1841         if (zy) *zy = y;
1842         if (zw) *zw = w;
1843         if (zh) *zh = h;
1844         return;
1845      }
1846
1847    zone_left = e_comp_zone_xy_get((x - w + 5), y);
1848    zone_right = e_comp_zone_xy_get((x + w + 5), y);
1849    zone_above = e_comp_zone_xy_get(x, (y - h + 5));
1850    zone_below = e_comp_zone_xy_get(x, (y + h + 5));
1851
1852    if (!(zone_above) && (y))
1853      zone_above = e_comp_zone_xy_get(x, (h - 5));
1854
1855    if (!(zone_left) && (x))
1856      zone_left = e_comp_zone_xy_get((x - 5), y);
1857
1858    if (zone_right)
1859      w = zone_right->x + zone_right->w;
1860
1861    if (zone_left)
1862      w = zone->x + zone->w;
1863
1864    if (zone_below)
1865      h = zone_below->y + zone_below->h;
1866
1867    if (zone_above)
1868      h = zone->y + zone->h;
1869
1870    if ((zone_left) && (zone_right))
1871      w = zone->w + zone_right->x;
1872
1873    if ((zone_above) && (zone_below))
1874      h = zone->h + zone_below->y;
1875
1876    if (x) x -= zone->w;
1877    if (y) y -= zone->h;
1878
1879    if (zx) *zx = x > 0 ? x : 0;
1880    if (zy) *zy = y > 0 ? y : 0;
1881    if (zw) *zw = w;
1882    if (zh) *zh = h;
1883 }
1884
1885 static void
1886 _e_client_stay_within_canvas(E_Client *ec, int x, int y, int *new_x, int *new_y)
1887 {
1888    int new_x_max, new_y_max;
1889    int zw, zh;
1890    Eina_Bool lw, lh;
1891    E_Zone *zone;
1892
1893    zone = e_comp_zone_find_by_ec(ec);
1894    if (!zone)
1895      {
1896         if (new_x) *new_x = x;
1897         if (new_y) *new_y = y;
1898         return;
1899      }
1900
1901    _e_client_zones_layout_calc(ec, NULL, NULL, &zw, &zh);
1902
1903    new_x_max = zw - ec->w;
1904    new_y_max = zh - ec->h;
1905    lw = ec->w > zw ? EINA_TRUE : EINA_FALSE;
1906    lh = ec->h > zh ? EINA_TRUE : EINA_FALSE;
1907
1908    if (lw)
1909      {
1910         if (x <= new_x_max)
1911           *new_x = new_x_max;
1912         else if (x >= 0)
1913           *new_x = 0;
1914      }
1915    else
1916      {
1917         if (x >= new_x_max)
1918           *new_x = new_x_max;
1919         else if (x <= 0)
1920           *new_x = 0;
1921      }
1922
1923    if (lh)
1924      {
1925         if (y <= new_y_max)
1926           *new_y = new_y_max;
1927         else if (y >= 0)
1928           *new_y = 0;
1929      }
1930    else
1931      {
1932         if (y >= new_y_max)
1933           *new_y = new_y_max;
1934         else if (y <= 0)
1935           *new_y = 0;
1936      }
1937 }
1938
1939 static void
1940 _e_client_stay_within_canvas_margin(E_Client *ec, int x, int y, int *new_x, int *new_y)
1941 {
1942    int new_x_max, new_y_max, new_x_min, new_y_min;
1943    int margin_w, margin_h;
1944    int zw, zh;
1945    int cw, ch;
1946    E_Zone *zone;
1947
1948    zone = e_comp_zone_find_by_ec(ec);
1949    if (!zone)
1950      {
1951         if (new_x) *new_x = x;
1952         if (new_y) *new_y = y;
1953         return;
1954      }
1955
1956    cw = ec->w;
1957    ch = ec->h;
1958
1959    _e_client_zones_layout_calc(ec, NULL, NULL, &zw, &zh);
1960
1961    margin_w = zw/3;
1962    margin_h = zh/10;
1963
1964    new_x_min = (margin_w > cw) ? 0 : -(cw - margin_w);
1965    new_x_max = (margin_w > cw) ? (zw - cw) : (zw - margin_w);
1966    new_y_min = (margin_h > ch) ? 0 : -(ch - margin_h);
1967    new_y_max = (margin_h > ch) ? (zh - ch) : (zh - margin_h);
1968
1969    if (x >= new_x_max)
1970      *new_x = new_x_max;
1971    else if (x <= new_x_min)
1972      *new_x = new_x_min;
1973
1974    if (y >= new_y_max)
1975      *new_y = new_y_max;
1976    else if (y <= new_y_min)
1977      *new_y = new_y_min;
1978
1979 }
1980
1981 ////////////////////////////////////////////////
1982
1983 static void
1984 _e_client_transform_core_activate_set(E_Client *ec, Eina_Bool set)
1985 {
1986    if (ec->transform_core.activate == set) return;
1987
1988    ec->transform_core.activate = set;
1989
1990    if (set)
1991      {
1992         if (ec->transform_core.result.enable)
1993           e_client_map_enable_set(ec, EINA_TRUE);
1994      }
1995    else
1996      {
1997         e_client_map_enable_set(ec, EINA_FALSE);
1998      }
1999 }
2000
2001 static void
2002 _e_client_cb_evas_hide(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
2003 {
2004    E_Client *ec = data;
2005
2006    if (stopping) return; //ignore all of this if we're shutting down!
2007    if (e_object_is_del(data)) return; //client is about to die
2008    if (ec->cur_mouse_action)
2009      {
2010         if (ec->cur_mouse_action->func.end_mouse)
2011           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", NULL);
2012         else if (ec->cur_mouse_action->func.end)
2013           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
2014         E_FREE_FUNC(ec->cur_mouse_action, e_object_unref);
2015      }
2016    if (action_client == ec) _e_client_action_finish();
2017
2018    ec->want_focus = ec->take_focus = 0;
2019
2020    _e_client_transform_core_activate_set(ec, EINA_FALSE);
2021
2022    if (ec->new_client) return;
2023    _e_client_event_hide(ec);
2024
2025    e_client_focus_check_set(ec, EINA_TRUE);
2026    EC_CHANGED(ec);
2027 }
2028
2029 static void
2030 _e_client_cb_evas_move(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
2031 {
2032    E_Client *ec = data;
2033    E_Map *map;
2034    Evas_Coord x, y;
2035
2036    if (e_object_is_del(data)) return;
2037
2038    ec->pre_res_change.valid = 0;
2039
2040    _e_client_event_simple(ec, E_EVENT_CLIENT_MOVE);
2041
2042    evas_object_geometry_get(ec->frame, &x, &y, NULL, NULL);
2043    if ((e_config->transient.move) && (ec->transients))
2044      {
2045         Eina_List *list = eina_list_clone(ec->transients);
2046         E_Client *child;
2047
2048         EINA_LIST_FREE(list, child)
2049           {
2050              if (child->vkbd.vkbd) continue;
2051
2052              evas_object_move(child->frame,
2053                               child->x + x - ec->pre_cb.x,
2054                               child->y + y - ec->pre_cb.y);
2055           }
2056      }
2057    if (ec->moving || (ecmove == ec))
2058      {
2059         wl_signal_emit(&PRI(ec)->events.move_resize_update, NULL);
2060         _e_client_hook_call(E_CLIENT_HOOK_MOVE_UPDATE, ec);
2061      }
2062
2063    if ((!ec->moving) && (ec->transformed))
2064      {
2065         map = e_client_map_get(ec);
2066         _e_client_transform_geometry_save(ec, map);
2067         e_map_free(map);
2068      }
2069
2070    ec->pre_cb.x = x; ec->pre_cb.y = y;
2071
2072    wl_signal_emit(&PRI(ec)->events.move, NULL);
2073
2074    e_comp_visibility_calculation_set(EINA_TRUE);
2075 }
2076
2077 static void
2078 _e_client_cb_evas_resize(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
2079 {
2080    E_Client *ec = data;
2081    Evas_Coord x, y, w, h;
2082
2083    if (e_object_is_del(data)) return;
2084
2085    ec->pre_res_change.valid = 0;
2086
2087    _e_client_event_simple(ec, E_EVENT_CLIENT_RESIZE);
2088
2089    evas_object_geometry_get(ec->frame, &x, &y, &w, &h);
2090    if ((e_config->transient.resize) && (ec->transients))
2091      {
2092         Eina_List *list = eina_list_clone(ec->transients);
2093         E_Client *child;
2094
2095         EINA_LIST_FREE(list, child)
2096           {
2097              Evas_Coord nx, ny, nw, nh;
2098
2099              if ((ec->pre_cb.w > 0) && (ec->pre_cb.h > 0))
2100                {
2101                   nx = x + (((child->x - x) * w) / ec->pre_cb.w);
2102                   ny = y + (((child->y - y) * h) / ec->pre_cb.h);
2103                   nw = (child->w * w) / ec->pre_cb.w;
2104                   nh = (child->h * h) / ec->pre_cb.h;
2105                   nx += ((nw - child->w) / 2);
2106                   ny += ((nh - child->h) / 2);
2107                   evas_object_move(child->frame, nx, ny);
2108                }
2109           }
2110      }
2111
2112    if (e_client_util_resizing_get(ec) || (ecresize == ec))
2113      {
2114          wl_signal_emit(&PRI(ec)->events.move_resize_update, NULL);
2115         _e_client_hook_call(E_CLIENT_HOOK_RESIZE_UPDATE, ec);
2116      }
2117    ec->pre_cb.w = w; ec->pre_cb.h = h;
2118
2119    e_client_transform_core_update(ec);
2120    e_comp_visibility_calculation_set(EINA_TRUE);
2121 }
2122
2123 static void
2124 _e_client_cb_evas_show(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
2125 {
2126    E_Client *ec = data;
2127
2128    if (e_object_is_del(data)) return;
2129
2130    _e_client_transform_core_activate_set(ec, EINA_TRUE);
2131
2132    _e_client_event_show(ec);
2133
2134    e_client_focus_check_set(ec, EINA_TRUE);
2135    EC_CHANGED(ec);
2136 }
2137
2138 static void
2139 _e_client_cb_evas_restack(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
2140 {
2141    E_Client *ec = data;
2142    E_Comp_Wl_Client_Data *child_cdata = NULL;
2143
2144    if (e_object_is_del(data)) return;
2145    if (ec->layer_block) return;
2146    if (ec->layer_pending) return;
2147    if (e_config->transient.raise && ec->transients)
2148      {
2149         Eina_List *list = eina_list_clone(ec->transients);
2150         E_Client *child, *below = NULL, *above = NULL;
2151         E_Transient transient_policy;
2152
2153         E_LIST_REVERSE_FREE(list, child)
2154           {
2155              child_cdata = e_client_cdata_get(child);
2156              if (child_cdata && !child_cdata->mapped)
2157                {
2158                   ELOGF("COMP", "STACK CHANGE CHILD. BUT not mapped. skip. child(ec:%p, win:0x%08zx)", ec, child, e_client_util_win_get(child));
2159                   continue;
2160                }
2161
2162              /* Don't stack iconic transients. If the user wants these shown,
2163               * that's another option.
2164               */
2165              if (child->iconic && e_client_is_iconified_by_client(child)) continue;
2166
2167              transient_policy = e_client_transient_policy_get(child);
2168              if (transient_policy == E_TRANSIENT_ABOVE)
2169                {
2170                   if (below)
2171                     e_client_stack_below(child, below);
2172                   else
2173                     e_client_stack_above(child, ec);
2174                   below = child;
2175                }
2176              else if (transient_policy == E_TRANSIENT_BELOW)
2177                {
2178                   if (above)
2179                     e_client_stack_below(child, above);
2180                   else
2181                     e_client_stack_below(child, ec);
2182                   above = child;
2183                }
2184
2185           }
2186      }
2187
2188    _e_client_event_simple(ec, E_EVENT_CLIENT_STACK);
2189
2190    e_client_focus_check_set(ec, EINA_TRUE);
2191    EC_CHANGED(ec);
2192
2193    e_comp_visibility_calculation_set(EINA_TRUE);
2194 }
2195
2196 ////////////////////////////////////////////////
2197 static void
2198 _e_client_aux_hint_eval(E_Client *ec)
2199 {
2200    if (!ec) return;
2201
2202    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
2203    Eina_List *l, *ll;
2204    E_Comp_Wl_Aux_Hint *hint;
2205
2206    if (cdata && cdata->aux_hint.changed)
2207      {
2208         wl_signal_emit(&PRI(ec)->events.aux_hint_change, NULL);
2209         _e_client_hook_call(E_CLIENT_HOOK_AUX_HINT_CHANGE, ec);
2210
2211         EINA_LIST_FOREACH_SAFE(cdata->aux_hint.hints, l, ll, hint)
2212           {
2213              hint->changed = EINA_FALSE;
2214              if (hint->deleted)
2215                {
2216                   ELOGF("COMP", "AUX_HINT |Del [%d:%s:%s]", ec, hint->id, hint->hint, hint->val);
2217                   if (hint->hint) eina_stringshare_del(hint->hint);
2218                   if (hint->val) eina_stringshare_del(hint->val);
2219                   cdata->aux_hint.hints = eina_list_remove_list(cdata->aux_hint.hints, l);
2220                   E_FREE(hint);
2221                }
2222           }
2223         cdata->aux_hint.changed = 0;
2224      }
2225 }
2226
2227 static void
2228 _e_client_eval(E_Client *ec)
2229 {
2230    int send_event = 1;
2231    unsigned int prop = 0;
2232    int tx, ty;
2233
2234    if (e_object_is_del(E_OBJECT(ec)))
2235      {
2236         CRI("_e_client_eval(%p) with deleted border! - %d\n", ec, ec->new_client);
2237         ec->changed = 0;
2238         return;
2239      }
2240
2241    TRACE_DS_BEGIN(CLIENT:EVAL);
2242
2243    wl_signal_emit(&PRI(ec)->events.eval_pre_new_client, NULL);
2244    if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_PRE_NEW_CLIENT, ec))
2245      {
2246         TRACE_DS_END();
2247         return;
2248      }
2249
2250    if ((ec->new_client) && (!e_client_util_ignored_get(ec)))
2251      {
2252         wl_signal_emit(&PRI(ec)->events.eval_post_new_client, NULL);
2253         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_POST_NEW_CLIENT, ec))
2254           {
2255              TRACE_DS_END();
2256              return;
2257           }
2258      }
2259
2260    if (ec->changes.size)
2261      {
2262         ec->changes.size = 0;
2263         evas_object_resize(ec->frame, ec->w, ec->h);
2264
2265         prop |= E_CLIENT_PROPERTY_SIZE;
2266      }
2267    if (ec->changes.pos)
2268      {
2269         ec->changes.tz_position = 0;
2270         ec->changes.pos = 0;
2271         evas_object_move(ec->frame, ec->x, ec->y);
2272         prop |= E_CLIENT_PROPERTY_POS;
2273      }
2274
2275    if (ec->changes.reset_gravity)
2276      {
2277         ec->changes.reset_gravity = 0;
2278         prop |= E_CLIENT_PROPERTY_GRAVITY;
2279      }
2280
2281    if (ec->changes.title)
2282      {
2283         ec->changes.title = 0;
2284         prop |= E_CLIENT_PROPERTY_TITLE;
2285      }
2286
2287    if ((ec->changes.visible) && (ec->visible) && (ec->new_client) && (!ec->iconic))
2288      {
2289         int x, y;
2290
2291         e_input_device_pointer_xy_get(NULL, &x, &y);
2292         if ((!ec->placed) && (!ec->re_manage) &&
2293             (e_config->window_placement_policy == E_WINDOW_PLACEMENT_MANUAL) &&
2294             (!((ec->icccm.transient_for != 0) ||
2295                (ec->dialog))) &&
2296             (!ecmove) && (!ecresize))
2297           {
2298              /* Set this window into moving state */
2299
2300              ec->cur_mouse_action = e_action_find("window_move");
2301              if (ec->cur_mouse_action)
2302                {
2303                   if ((!ec->cur_mouse_action->func.end_mouse) &&
2304                       (!ec->cur_mouse_action->func.end))
2305                     ec->cur_mouse_action = NULL;
2306                   if (ec->cur_mouse_action)
2307                     {
2308                        int t;
2309                        tx = x - (ec->w >> 1);
2310                        e_comp_object_frame_geometry_get(ec->frame, NULL, NULL, &t, NULL);
2311                        ty = y - (t >> 1);
2312                        e_client_pos_set(ec, tx, ty);
2313                        EC_CHANGED(ec);
2314                        ec->changes.pos = 1;
2315                     }
2316                }
2317           }
2318
2319         evas_object_show(ec->frame);
2320         if (evas_object_visible_get(ec->frame))
2321           {
2322              ec->changes.visible = 0;
2323              _e_client_event_show(ec);
2324           }
2325      }
2326    else if ((ec->changes.visible) && (ec->new_client))
2327      {
2328         ec->changes.visible = 0;
2329         if (!ec->iconic)
2330           _e_client_event_hide(ec);
2331      }
2332
2333    if (ec->changes.icon)
2334      {
2335         ec->changes.icon = 0;
2336      }
2337
2338    if (ec->new_client)
2339      e_comp->new_clients--;
2340    ec->new_client = 0;
2341    ec->changed = ec->changes.pos || ec->changes.size ||
2342                  ec->changes.stack || ec->changes.prop || ec->changes.border ||
2343                  ec->changes.reset_gravity ||
2344                  ec->changes.shape || ec->changes.shape_input || ec->changes.icon ||
2345                  ec->changes.internal_state ||
2346                  ec->changes.need_maximize || ec->changes.need_unmaximize ||
2347                  e_client_focus_check_get(ec);
2348    ec->changes.stack = 0;
2349
2350    if (ec->changes.need_maximize)
2351      {
2352         E_Maximize max = ec->maximized;
2353         ec->maximized = E_MAXIMIZE_NONE;
2354         e_client_maximize(ec, max);
2355         ec->changes.need_maximize = 0;
2356      }
2357    else if (ec->changes.need_unmaximize)
2358      {
2359         e_client_unmaximize(ec, ec->maximized);
2360         ec->changes.need_unmaximize = 0;
2361      }
2362
2363    if (ec->need_fullscreen)
2364      {
2365         e_client_fullscreen(ec, e_config->fullscreen_policy);
2366         ec->need_fullscreen = 0;
2367      }
2368
2369    if (ec->changes.accepts_focus)
2370      {
2371         if ((!ec->icccm.accepts_focus) && (!ec->icccm.take_focus))
2372           {
2373              if (!ec->focused)
2374                ec->changes.accepts_focus = 0;
2375           }
2376      }
2377
2378    if (send_event && prop)
2379      {
2380         _e_client_event_property(ec, prop);
2381      }
2382
2383    _e_client_aux_hint_eval(ec);
2384
2385    e_client_transform_core_update(ec);
2386
2387    wl_signal_emit(&PRI(ec)->events.eval_end, NULL);
2388    _e_client_hook_call(E_CLIENT_HOOK_EVAL_END, ec);
2389
2390    TRACE_DS_END();
2391 }
2392
2393 EINTERN void
2394 e_client_frame_update(E_Client *ec)
2395 {
2396    const char *bordername;
2397
2398    EINA_SAFETY_ON_NULL_RETURN(ec);
2399    if (e_object_is_del(E_OBJECT(ec))) return;
2400
2401    ec->border.changed = 0;
2402    if (!e_comp_object_frame_allowed(ec->frame)) return;
2403    if (ec->fullscreen || ec->borderless)
2404      bordername = "borderless";
2405    else if (ec->bordername)
2406      bordername = ec->bordername;
2407    else if (((ec->icccm.transient_for != 0) || (ec->dialog)) &&
2408             (ec->icccm.min_w == ec->icccm.max_w) &&
2409             (ec->icccm.min_h == ec->icccm.max_h))
2410      bordername = "noresize_dialog";
2411    else if ((ec->icccm.min_w == ec->icccm.max_w) &&
2412             (ec->icccm.min_h == ec->icccm.max_h))
2413      bordername = "noresize";
2414    else if (ec->shaped)
2415      bordername = "shaped";
2416    else if ((ec->netwm.state.skip_taskbar) ||
2417             (ec->netwm.state.skip_pager))
2418      bordername = "skipped";
2419   /*
2420    else if ((ec->internal) && (ec->icccm.class) &&
2421             (!strncmp(ec->icccm.class, "e_fwin", 6)))
2422      bordername = "internal_fileman";
2423   */
2424    else
2425      bordername = e_config->theme_default_border_style;
2426    if (!bordername) bordername = "default";
2427 }
2428
2429 static Eina_Bool
2430 _e_client_type_match(E_Client *ec, E_Config_Client_Type *m)
2431 {
2432    if (!ec || !m) return EINA_FALSE;
2433    if (e_object_is_del(E_OBJECT(ec))) return EINA_FALSE;
2434
2435    if ((int)ec->netwm.type != m->window_type)
2436      return EINA_FALSE;
2437
2438 #if defined(__cplusplus) || defined(c_plusplus)
2439    if (m->clas)
2440      {
2441         if (!ec->icccm.cpp_class)
2442           return EINA_FALSE;
2443
2444         if (!e_util_glob_match(ec->icccm.cpp_class, m->clas))
2445           return EINA_FALSE;
2446      }
2447 #else
2448    if (m->clas)
2449      {
2450         if (!ec->icccm.class)
2451           return EINA_FALSE;
2452
2453         if (!e_util_glob_match(ec->icccm.class, m->clas))
2454           return EINA_FALSE;
2455      }
2456 #endif
2457
2458    if (m->name)
2459      {
2460         if (ec->icccm.name && e_util_glob_match(ec->icccm.name, m->name))
2461           return EINA_TRUE;
2462
2463         if (ec->icccm.title && e_util_glob_match(ec->icccm.title, m->name))
2464           return EINA_TRUE;
2465
2466         if (ec->netwm.name && e_util_glob_match(ec->netwm.name, m->name))
2467           return EINA_TRUE;
2468      }
2469
2470    return EINA_FALSE;
2471 }
2472
2473 EINTERN int
2474 e_client_type_update(E_Client *ec)
2475 {
2476    E_Config_Client_Type *m;
2477    Eina_List *l;
2478    int type = 0;
2479
2480    if (!e_config->client_types) return 0;
2481
2482    EINA_LIST_FOREACH(e_config->client_types, l, m)
2483      {
2484         if (!_e_client_type_match(ec, m)) continue;
2485         else
2486           {
2487              type = m->client_type;
2488              break;
2489           }
2490      }
2491
2492    if (ec->client_type != type)
2493      {
2494         ec->client_type = type;
2495         _e_client_event_property(ec, E_CLIENT_PROPERTY_CLIENT_TYPE);
2496      }
2497
2498    return ec->client_type;
2499 }
2500
2501 static void
2502 _e_client_transform_sub_apply(E_Client *ec, E_Client *epc, double zoom)
2503 {
2504    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
2505    E_Client *subc;
2506    Eina_List *l;
2507    int px = 0, py = 0;
2508    int ox = 0, oy = 0, ow, oh;
2509    int mx, my, mw, mh;
2510    E_Map *map;
2511
2512    EINA_SAFETY_ON_FALSE_RETURN(e_comp_wl_subsurface_check(ec));
2513
2514    e_comp_wl_subsurface_position_get(ec, &ox, &oy);
2515    ow = cdata->width_from_viewport;
2516    oh = cdata->height_from_viewport;
2517
2518    map = e_client_map_get(epc);
2519    e_map_point_coord_get(map, 0, &px, &py, 0);
2520    e_map_free(map);
2521
2522    mx = ox * zoom + px;
2523    my = oy * zoom + py;
2524    mw = ow * zoom;
2525    mh = oh * zoom;
2526
2527    map = e_map_new_with_direct_render(ec->transform_core.direct_render);
2528    e_map_util_points_populate_from_geometry(map, mx, my, mw, mh, 0);
2529    e_map_util_object_move_sync_set(map, EINA_TRUE);
2530    e_client_map_set(ec, map);
2531    e_client_map_enable_set(ec, EINA_TRUE);
2532
2533    EINA_LIST_FOREACH(cdata->sub.list, l, subc)
2534      _e_client_transform_sub_apply(subc, ec, zoom);
2535    EINA_LIST_REVERSE_FOREACH(cdata->sub.below_list, l, subc)
2536      _e_client_transform_sub_apply(subc, ec, zoom);
2537
2538    e_map_free(map);
2539 }
2540
2541 static void
2542 _e_client_transient_for_group_make(E_Client *ec, Eina_List **list)
2543 {
2544    E_Client *child;
2545    Eina_List *l;
2546
2547    if (!ec) return;
2548    if (!e_config->transient.raise) return;
2549
2550    EINA_LIST_FOREACH(ec->transients, l, child)
2551      {
2552         if (!child) continue;
2553         if (child->iconic) continue;
2554         if (e_client_transient_policy_get(child) == E_TRANSIENT_ABOVE)
2555           {
2556              *list = eina_list_prepend(*list, child);
2557              _e_client_transient_for_group_make(child, list);
2558           }
2559      }
2560 }
2561
2562 EINTERN E_Client *
2563 e_client_transient_child_top_get(E_Client *ec, Eina_Bool consider_focus)
2564 {
2565    E_Client *top_ec = NULL;
2566    Eina_List *transient_list = NULL;
2567
2568    _e_client_transient_for_group_make(ec, &transient_list);
2569
2570    if (transient_list)
2571      {
2572         Eina_List *l = NULL;
2573         E_Client *temp_ec = NULL;
2574         E_Client *temp_ec2 = NULL;
2575
2576         E_CLIENT_REVERSE_FOREACH(temp_ec)
2577           {
2578              if (top_ec) break;
2579              if (temp_ec == ec)
2580                {
2581                   top_ec = ec;
2582                   break;
2583                }
2584
2585              EINA_LIST_FOREACH(transient_list, l, temp_ec2)
2586                {
2587                   if (temp_ec == temp_ec2)
2588                     {
2589                        if (consider_focus)
2590                          {
2591                             if ((temp_ec2->icccm.accepts_focus) ||
2592                                 (temp_ec2->icccm.take_focus))
2593                               {
2594                                  top_ec = temp_ec2;
2595                               }
2596                          }
2597                        else
2598                          {
2599                             top_ec = temp_ec2;
2600                          }
2601                        break;
2602                     }
2603                }
2604           }
2605         eina_list_free(transient_list);
2606      }
2607    return top_ec;
2608 }
2609
2610 #ifdef EC_IS_NOT_VISIBLE
2611 # undef EC_IS_NOT_VISIBLE
2612 #endif
2613 #define EC_IS_NOT_VISIBLE if (e_client_visibility_get(ec) != E_VISIBILITY_UNOBSCURED)
2614
2615 EINTERN Eina_Bool
2616 e_client_visibility_touched_check(E_Client *ec)
2617 {
2618    int tx, ty;
2619
2620    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
2621
2622    tx = wl_fixed_to_int(e_comp->wl_comp_data->ptr.x);
2623    ty = wl_fixed_to_int(e_comp->wl_comp_data->ptr.y);
2624
2625    return _e_client_position_inside_input_rect(ec, tx, ty);
2626 }
2627
2628 EINTERN void
2629 e_client_visibility_change_notify(E_Client *ec)
2630 {
2631    EINA_SAFETY_ON_NULL_RETURN(ec);
2632
2633    if (ec->visibility.changed)
2634      _e_client_event_simple(ec, E_EVENT_CLIENT_VISIBILITY_CHANGE);
2635
2636    wl_signal_emit(&PRI(ec)->events.eval_visibility, NULL);
2637    _e_client_hook_call(E_CLIENT_HOOK_EVAL_VISIBILITY, ec);
2638 }
2639
2640 EINTERN void
2641 e_client_visibility_end_notify(void)
2642 {
2643    // FIXME: This hook means that the visiblitiy calculation of a zone is done
2644    //        at this idle handler.This is a hook for a zone, not for a client.
2645    //        Therefore, this hook may be defined as a zone hook,
2646    //        ex) E_ZONE_HOOK_EVAL_VISIBILITY_END or E_ZONE_HOOK_EVAL_VISIBILITY_DONE.
2647    _e_client_hook_call(E_CLIENT_HOOK_EVAL_VISIBILITY_END, NULL);
2648 }
2649
2650 EINTERN E_Visibility
2651 e_client_visibility_get(E_Client *ec)
2652 {
2653    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, E_VISIBILITY_UNKNOWN);
2654
2655    return ec->visibility.obscured;
2656 }
2657
2658 static void
2659 _e_input_thread_client_visible_set(void *data)
2660 {
2661    E_Input_Thread_Request_EClient_Data ec_data;
2662    memcpy(&ec_data, data, sizeof(E_Input_Thread_Request_EClient_Data));
2663
2664    INF("[input thread|%s] ec(%p), visible(%d)\n", __func__, ec_data.ec, ec_data.visible);
2665    e_input_thread_client_visible_set(e_input_thread_client_get(ec_data.ec), ec_data.visible);
2666 }
2667
2668 EINTERN void
2669 e_client_visibility_set(E_Client *ec, E_Visibility visibility)
2670 {
2671    E_Input_Thread_Request_EClient_Data ec_data;
2672    memset(&ec_data, 0, sizeof(E_Input_Thread_Request_EClient_Data));
2673
2674    EINA_SAFETY_ON_NULL_RETURN(ec);
2675
2676    if (e_client_visibility_get(ec) == visibility) return;
2677
2678    ec->visibility.obscured = visibility;
2679
2680    ec_data.ec = ec;
2681    ec_data.visible = ec->visibility.obscured;
2682
2683    INF("[%s] ec(%p), visible(%d)\n", __func__, ec, ec->visibility.obscured);
2684    e_input_thread_safe_call(_e_input_thread_client_visible_set, &ec_data, sizeof(E_Input_Thread_Request_EClient_Data));
2685 }
2686
2687 static Eina_Bool
2688 _e_client_transform_core_check_change(E_Client *ec)
2689 {
2690    int w = 0;
2691    int h = 0;
2692    Eina_Bool check = EINA_FALSE;
2693    if (!ec) return EINA_FALSE;
2694
2695    if (ec->frame)
2696      evas_object_geometry_get(ec->frame, 0, 0, &w, &h);
2697
2698    // check client position or size change
2699    if (ec->x != ec->transform_core.backup.client_x ||
2700        ec->y != ec->transform_core.backup.client_y ||
2701        ec->w != ec->transform_core.backup.client_w ||
2702        ec->h != ec->transform_core.backup.client_h ||
2703        w     != ec->transform_core.backup.frame_w ||
2704        h     != ec->transform_core.backup.frame_h ||
2705        ec->argb != ec->transform_core.backup.argb)
2706      {
2707         check = EINA_TRUE;
2708         ec->transform_core.backup.client_x = ec->x;
2709         ec->transform_core.backup.client_y = ec->y;
2710         ec->transform_core.backup.client_w = ec->w;
2711         ec->transform_core.backup.client_h = ec->h;
2712         ec->transform_core.backup.frame_w = w;
2713         ec->transform_core.backup.frame_h = h;
2714         ec->transform_core.backup.argb = ec->argb;
2715      }
2716
2717    // check new transform or del transform
2718    if (ec->transform_core.changed)
2719      {
2720         check = EINA_TRUE;
2721         ec->transform_core.changed = EINA_FALSE;
2722      }
2723
2724    // check each transform change
2725    if (ec->transform_core.transform_list)
2726      {
2727         Eina_List *l;
2728         Eina_List *l_next;
2729         E_Util_Transform *transform;
2730
2731         EINA_LIST_FOREACH_SAFE(ec->transform_core.transform_list, l, l_next, transform)
2732           {
2733              // del transform check
2734              if (e_util_transform_ref_count_get(transform) <= 1)
2735                {
2736                   ec->transform_core.transform_list = eina_list_remove(ec->transform_core.transform_list, transform);
2737                   e_util_transform_unref(transform);
2738                   check = EINA_TRUE;
2739                   continue;
2740                }
2741
2742              // transform change test
2743              if (e_util_transform_change_get(transform))
2744                {
2745                   check = EINA_TRUE;
2746                   e_util_transform_change_unset(transform);
2747                }
2748           }
2749      }
2750
2751    if (e_comp_wl_subsurface_check(ec))
2752      {
2753         // check parent matrix change
2754         E_Client *parent = e_comp_wl_subsurface_parent_get(ec);
2755         if (parent && parent->transform_core.result.enable)
2756           {
2757              ec->transform_core.parent.enable = EINA_TRUE;
2758
2759              if (!e_util_transform_matrix_equal_check(&ec->transform_core.parent.matrix,
2760                                                       &parent->transform_core.result.matrix))
2761                {
2762                   check = EINA_TRUE;
2763                   ec->transform_core.parent.matrix = parent->transform_core.result.matrix;
2764                }
2765              if (memcmp(&ec->transform_core.parent.zoom, &parent->transform_core.result.transform.zoom, sizeof(E_Util_Transform_Zoom)) != 0)
2766                {
2767                   check = EINA_TRUE;
2768                   ec->transform_core.parent.zoom = parent->transform_core.result.transform.zoom;
2769                }
2770           }
2771         else if (ec->transform_core.parent.enable)
2772           {
2773              ec->transform_core.parent.enable = EINA_FALSE;
2774              e_util_transform_matrix_load_identity(&ec->transform_core.parent.matrix);
2775              ec->transform_core.parent.zoom.zoom_x = 1.0;
2776              ec->transform_core.parent.zoom.zoom_y = 1.0;
2777              ec->transform_core.parent.zoom.cx = 0;
2778              ec->transform_core.parent.zoom.cy = 0;
2779              check = EINA_TRUE;
2780           }
2781      }
2782
2783    return check;
2784 }
2785
2786 static void
2787 _e_client_transform_core_boundary_update(E_Client *ec, E_Util_Transform_Rect_Vertex *vertices)
2788 {
2789    int minx = 99999, miny = 99999;
2790    int maxx = -99999, maxy = -99999;
2791    int x, y;
2792    int i;
2793
2794    if (!ec) return;
2795    if (!ec->frame) return;
2796    if (!ec->transform_core.result.enable) return;
2797    if (!vertices) return;
2798
2799    for (i = 0; i < 4; ++i)
2800      {
2801         x = 0;
2802         y = 0;
2803
2804         e_util_transform_vertices_pos_round_get(vertices, i, &x, &y, 0, 0);
2805
2806         if (x < minx) minx = x;
2807         if (y < miny) miny = y;
2808         if (x > maxx) maxx = x;
2809         if (y > maxy) maxy = y;
2810      }
2811
2812    ec->transform_core.result.boundary.x = minx;
2813    ec->transform_core.result.boundary.y = miny;
2814    ec->transform_core.result.boundary.w = maxx - minx;
2815    ec->transform_core.result.boundary.h = maxy - miny;
2816
2817    ELOGF("COMP", "[Transform][boundary][%d %d %d %d]",
2818          ec,
2819          ec->transform_core.result.boundary.x,
2820          ec->transform_core.result.boundary.y,
2821          ec->transform_core.result.boundary.w,
2822          ec->transform_core.result.boundary.h);
2823 }
2824
2825 static E_Map *
2826 _e_client_transform_core_map_new(Evas_Object *obj,
2827                                  E_Util_Transform_Rect_Vertex *vertices,
2828                                  E_Util_Transform *transform,
2829                                  Eina_Bool direct_render)
2830 {
2831    E_Map *map;
2832    int i;
2833    int x, y;
2834    double u, v;
2835
2836    map = e_map_new_with_direct_render(direct_render);
2837    EINA_SAFETY_ON_NULL_RETURN_VAL(map, NULL);
2838
2839    e_map_util_points_populate_from_object_full(map, obj, 0);
2840    e_map_util_points_color_set(map, 255, 255, 255, 255);
2841
2842    for (i = 0 ; i < 4 ; ++i)
2843      {
2844         x = 0;
2845         y = 0;
2846
2847         e_util_transform_vertices_pos_round_get(vertices, i, &x, &y, 0, 0);
2848         e_map_point_coord_set(map, i, x, y, 1.0);
2849
2850         if (transform && e_util_transform_texcoord_flag_get(transform))
2851           {
2852              u = 0.0;
2853              v = 0.0;
2854
2855              e_util_transform_texcoord_get(transform, i, &u, &v);
2856              e_map_point_image_uv_set(map, i, u, v);
2857           }
2858      }
2859
2860    return map;
2861 }
2862
2863 static void
2864 _e_client_transform_core_vertices_apply_with_zoom(E_Client *ec,
2865                                         Evas_Object *obj,
2866                                         E_Util_Transform_Rect_Vertex *vertices,
2867                                         E_Util_Transform *transform,
2868                                         E_Util_Transform_Zoom zoom)
2869 {
2870    E_Map *map = NULL, *current_map = NULL;
2871
2872    if (!obj) return;
2873
2874    if (vertices)
2875      {
2876         if (!ec->transform_core.update_lock)
2877           {
2878              map = _e_client_transform_core_map_new(obj, vertices, transform,
2879                                                     ec->transform_core.direct_render);
2880              EINA_SAFETY_ON_NULL_RETURN(map);
2881
2882              e_map_util_zoom(map, zoom.zoom_x, zoom.zoom_y, zoom.cx, zoom.cy);
2883
2884              e_comp_object_map_set(obj, map);
2885           }
2886
2887         current_map = e_comp_object_map_get(obj);
2888
2889         if ((ec->transform_core.activate) && (current_map))
2890           e_comp_object_map_enable_set(obj, EINA_TRUE);
2891         else
2892           e_comp_object_map_enable_set(obj, EINA_FALSE);
2893
2894         if (map) e_map_free(map);
2895         if (current_map) e_map_free(current_map);
2896      }
2897    else
2898      evas_object_map_enable_set(obj, EINA_FALSE);
2899 }
2900
2901 static void
2902 _e_client_transform_core_vertices_apply(E_Client *ec,
2903                                         Evas_Object *obj,
2904                                         E_Util_Transform_Rect_Vertex *vertices,
2905                                         E_Util_Transform *transform)
2906 {
2907    E_Map *map = NULL, *current_map = NULL;
2908
2909    if (!obj) return;
2910
2911    if (vertices)
2912      {
2913         if (!ec->transform_core.update_lock)
2914           {
2915               map = _e_client_transform_core_map_new(obj, vertices, transform,
2916                                                      ec->transform_core.direct_render);
2917               EINA_SAFETY_ON_NULL_RETURN(map);
2918
2919               e_comp_object_map_set(obj, map);
2920           }
2921
2922         current_map = e_comp_object_map_get(obj);
2923
2924         if ((ec->transform_core.activate) && (current_map))
2925           e_comp_object_map_enable_set(obj, EINA_TRUE);
2926         else
2927           e_comp_object_map_enable_set(obj, EINA_FALSE);
2928
2929         if (map) e_map_free(map);
2930         if (current_map) e_map_free(current_map);
2931      }
2932    else
2933      evas_object_map_enable_set(obj, EINA_FALSE);
2934 }
2935
2936 static void
2937 _e_client_transform_core_sub_update(E_Client *ec, E_Util_Transform_Rect_Vertex *vertices)
2938 {
2939    Eina_List *l;
2940    E_Client *subc;
2941    E_Comp_Wl_Client_Data *cdata;
2942
2943    if (!ec) return;
2944
2945    cdata = e_client_cdata_get(ec);
2946    if (!cdata) return;
2947
2948    EINA_LIST_FOREACH(cdata->sub.list, l, subc)
2949       e_client_transform_core_update(subc);
2950
2951    EINA_LIST_FOREACH(cdata->sub.below_list, l, subc)
2952       e_client_transform_core_update(subc);
2953 }
2954
2955 static void
2956 _e_client_cb_hook_shell_surface_ready(void *data EINA_UNUSED, E_Client *ec)
2957 {
2958    if (EINA_UNLIKELY(!ec))
2959      return;
2960
2961    _e_client_aux_hint_eval(ec);
2962 }
2963
2964 // FIXME: This function has to be deleted and it remains for the backward compatibility.
2965 //        Please find and fix to use e_comp_visibility_calculation_set(EINA_TRUE)
2966 //        instead of e_client_visibility_calculate() call at e20 modules.
2967 E_API void
2968 e_client_visibility_calculate(void)
2969 {
2970    e_comp_visibility_calculation_set(EINA_TRUE);
2971 }
2972
2973 E_API void
2974 e_client_visibility_skip_set(E_Client *ec, Eina_Bool skip)
2975 {
2976    if (!ec) return;
2977
2978    ELOGF("POL_VIS", "visibility skip set to %d", ec, skip);
2979    ec->visibility.skip = skip;
2980 }
2981
2982 E_API void
2983 e_client_post_raise_lower_set(E_Client *ec, Eina_Bool raise_set, Eina_Bool lower_set)
2984 {
2985    if (!ec) return;
2986
2987    ec->post_raise = raise_set;
2988    ec->post_lower = lower_set;
2989 }
2990
2991 E_API Eina_Bool
2992 e_client_first_mapped_get(E_Client *ec)
2993 {
2994    if (!ec) return EINA_FALSE;
2995
2996    return ec->first_mapped;
2997 }
2998
2999 EINTERN Eina_Bool e_client_mapped_get(E_Client *ec)
3000 {
3001    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
3002    EINA_SAFETY_ON_NULL_RETURN_VAL(cdata, EINA_FALSE);
3003
3004   return cdata->mapped;
3005 }
3006
3007 EINTERN void
3008 e_client_mapped_set(E_Client *ec, Eina_Bool set)
3009 {
3010    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
3011    EINA_SAFETY_ON_NULL_RETURN(cdata);
3012
3013    cdata->mapped = set;
3014 }
3015
3016
3017 ////////////////////////////////////////////////
3018 EINTERN Eina_Bool
3019 e_client_clients_hash_exist()
3020 {
3021   int pix_id;
3022
3023   for (pix_id = 0; pix_id < E_PIXMAP_TYPE_MAX; pix_id++)
3024     {
3025       if (eina_hash_population(clients_hash[pix_id]))
3026         return EINA_TRUE;
3027     }
3028
3029   return EINA_FALSE;
3030 }
3031
3032 EINTERN void
3033 e_client_idler_before(Eina_Bool *check_focus)
3034 {
3035    const Eina_List *l;
3036    E_Client *ec;
3037
3038    *check_focus = EINA_FALSE;
3039
3040    if (!e_client_clients_hash_exist()) return;
3041
3042    TRACE_DS_BEGIN(CLIENT:IDLE BEFORE);
3043
3044    EINA_LIST_FOREACH(e_comp->clients, l, ec)
3045      {
3046         // pass 1 - eval0. fetch properties on new or on change and
3047         // call hooks to decide what to do - maybe move/resize
3048         if (ec->ignored || (!ec->changed)) continue;
3049
3050         wl_signal_emit(&PRI(ec)->events.eval_pre_fetch, NULL);
3051         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_PRE_FETCH, ec)) continue;
3052
3053
3054         /* FETCH is hooked by the compositor to get client hints */
3055         wl_signal_emit(&PRI(ec)->events.eval_fetch, NULL);
3056         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_FETCH, ec)) continue;
3057
3058         if (ec->new_client)
3059           {
3060              e_client_type_update(ec);
3061           }
3062
3063         /* PRE_POST_FETCH calls e_remember apply for new client */
3064         wl_signal_emit(&PRI(ec)->events.eval_pre_post_fetch, NULL);
3065         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_PRE_POST_FETCH, ec)) continue;
3066         wl_signal_emit(&PRI(ec)->events.eval_post_fetch, NULL);
3067         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_POST_FETCH, ec)) continue;
3068         wl_signal_emit(&PRI(ec)->events.eval_pre_frame_assign, NULL);
3069         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_PRE_FRAME_ASSIGN, ec)) continue;
3070
3071         wl_signal_emit(&PRI(ec)->events.eval_post_frame_assign, NULL);
3072         _e_client_hook_call(E_CLIENT_HOOK_EVAL_POST_FRAME_ASSIGN, ec);
3073      }
3074    // pass 2 - show and hide windows needing hide and eval (main eval)
3075    E_CLIENT_FOREACH(ec)
3076      {
3077         if (e_object_is_del(E_OBJECT(ec))) continue;
3078         if (ec->ignored)
3079           {
3080              // ignored client but needing eval (aux hint) such as remote surfaces
3081              if (ec->changed)
3082                {
3083                   E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
3084                   if (cdata && cdata->first_commit)
3085                     _e_client_aux_hint_eval(ec);
3086                }
3087              continue;
3088           }
3089
3090         if (ec->changes.visible)
3091           {
3092              if (ec->visible)
3093                {
3094                   if ((!ec->new_client) &&
3095                       (!ec->changes.pos) &&
3096                       (!ec->changes.size))
3097                     {
3098                        evas_object_show(ec->frame);
3099                        ec->changes.visible = !evas_object_visible_get(ec->frame);
3100                     }
3101                }
3102              else
3103                {
3104                   evas_object_hide(ec->frame);
3105                   ec->changes.visible = 0;
3106                }
3107           }
3108
3109         if (ec->changed)
3110           {
3111              _e_client_eval(ec);
3112              e_comp_visibility_calculation_set(EINA_TRUE);
3113              if (ec->changes.accepts_focus)
3114                *check_focus = EINA_TRUE;
3115              ec->changes.accepts_focus = 0;
3116
3117              if (e_client_focus_check_get(ec))
3118                {
3119                   *check_focus = EINA_TRUE;
3120                   e_client_focus_check_set(ec, EINA_FALSE);
3121                }
3122           }
3123
3124         if ((ec->changes.visible) && (ec->visible) && (!ec->changed))
3125           {
3126              evas_object_show(ec->frame);
3127              ec->changes.visible = !evas_object_visible_get(ec->frame);
3128              ec->changed = ec->changes.visible;
3129              e_comp_visibility_calculation_set(EINA_TRUE);
3130           }
3131      }
3132
3133    TRACE_DS_END();
3134 }
3135
3136 static Eina_Bool
3137 _e_client_cb_hook_comp_render_update_lock_set(void *data, E_Client *ec)
3138 {
3139    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_TRUE);
3140
3141    ec->transform_core.update_lock = EINA_TRUE;
3142
3143    return EINA_TRUE;
3144 }
3145
3146 static Eina_Bool
3147 _e_client_cb_hook_comp_render_update_lock_unset(void *data, E_Client *ec)
3148 {
3149    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_TRUE);
3150
3151    ec->transform_core.update_lock = EINA_FALSE;
3152    ec->transform_core.changed = EINA_TRUE;
3153
3154    e_client_transform_core_update(ec);
3155
3156    return EINA_TRUE;
3157 }
3158
3159 EINTERN Eina_Bool
3160 e_client_init(void)
3161 {
3162    int pix_id;
3163    for (pix_id = 0; pix_id < E_PIXMAP_TYPE_MAX; pix_id++)
3164      clients_hash[pix_id] = eina_hash_pointer_new(NULL);
3165
3166    E_COMP_WL_HOOK_APPEND(hooks, E_COMP_WL_HOOK_SHELL_SURFACE_READY, _e_client_cb_hook_shell_surface_ready, NULL);
3167    E_COMP_COMP_HOOK_APPEND(comp_hooks, E_COMP_OBJECT_HOOK_RENDER_UPDATE_LOCK_SET, _e_client_cb_hook_comp_render_update_lock_set, NULL);
3168    E_COMP_COMP_HOOK_APPEND(comp_hooks, E_COMP_OBJECT_HOOK_RENDER_UPDATE_LOCK_UNSET, _e_client_cb_hook_comp_render_update_lock_unset, NULL);
3169
3170    E_EVENT_CLIENT_ADD = ecore_event_type_new();
3171    E_EVENT_CLIENT_REMOVE = ecore_event_type_new();
3172    E_EVENT_CLIENT_DESK_SET = ecore_event_type_new();
3173    E_EVENT_CLIENT_ZONE_SET = ecore_event_type_new();
3174    E_EVENT_CLIENT_RESIZE = ecore_event_type_new();
3175    E_EVENT_CLIENT_MOVE = ecore_event_type_new();
3176    E_EVENT_CLIENT_SHOW = ecore_event_type_new();
3177    E_EVENT_CLIENT_HIDE = ecore_event_type_new();
3178    E_EVENT_CLIENT_ICONIFY = ecore_event_type_new();
3179    E_EVENT_CLIENT_UNICONIFY = ecore_event_type_new();
3180    E_EVENT_CLIENT_STACK = ecore_event_type_new();
3181    E_EVENT_CLIENT_FOCUS_IN = ecore_event_type_new();
3182    E_EVENT_CLIENT_FOCUS_OUT = ecore_event_type_new();
3183    E_EVENT_CLIENT_PROPERTY = ecore_event_type_new();
3184    E_EVENT_CLIENT_FULLSCREEN = ecore_event_type_new();
3185    E_EVENT_CLIENT_UNFULLSCREEN = ecore_event_type_new();
3186 #ifdef _F_ZONE_WINDOW_ROTATION_
3187    E_EVENT_CLIENT_ROTATION_CHANGE_BEGIN = ecore_event_type_new();
3188    E_EVENT_CLIENT_ROTATION_CHANGE_CANCEL = ecore_event_type_new();
3189    E_EVENT_CLIENT_ROTATION_CHANGE_END = ecore_event_type_new();
3190    E_EVENT_CLIENT_ROTATION_GEOMETRY_SET = ecore_event_type_new();
3191 #endif
3192    E_EVENT_CLIENT_VISIBILITY_CHANGE = ecore_event_type_new();
3193    E_EVENT_CLIENT_BUFFER_CHANGE = ecore_event_type_new();
3194    E_EVENT_CLIENT_FOCUS_SKIP_SET = ecore_event_type_new();;
3195    E_EVENT_CLIENT_FOCUS_SKIP_UNSET = ecore_event_type_new();;
3196
3197    return (!!clients_hash[1]);
3198 }
3199
3200 EINTERN void
3201 e_client_shutdown(void)
3202 {
3203    int pix_id;
3204    for (pix_id = 0; pix_id < E_PIXMAP_TYPE_MAX; pix_id++)
3205      E_FREE_FUNC(clients_hash[pix_id], eina_hash_free);
3206
3207    E_FREE_LIST(comp_hooks, e_comp_object_hook_del);
3208    E_FREE_LIST(hooks, e_comp_wl_hook_del);
3209    E_FREE_LIST(handlers, ecore_event_handler_del);
3210
3211 }
3212
3213 E_API void
3214 e_client_unignore(E_Client *ec)
3215 {
3216    E_OBJECT_CHECK(ec);
3217    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3218    if (!ec->ignored) return;
3219
3220    ec->ignored = 0;
3221    _e_client_event_add(ec);
3222 }
3223
3224 static E_Layer
3225 _e_client_convert_fullscreen_layer(int layer)
3226 {
3227    if (layer <= E_LAYER_CLIENT_NORMAL)
3228      return E_LAYER_CLIENT_NORMAL;
3229    else if (layer <= E_LAYER_CLIENT_ABOVE)
3230      return E_LAYER_CLIENT_ABOVE;
3231    else if (layer <= E_LAYER_CLIENT_EDGE)
3232      return E_LAYER_CLIENT_EDGE;
3233    else
3234      return E_LAYER_CLIENT_FULLSCREEN;
3235 }
3236
3237 static void
3238 _e_input_thread_client_new(void *data)
3239 {
3240    E_Input_Thread_Request_EClient_Data ec_new_data;
3241    memcpy(&ec_new_data, data, sizeof(E_Input_Thread_Request_EClient_Data));
3242
3243    INF("[input thread|%s] ec(%p), surface(%p)\n", __func__, ec_new_data.ec, ec_new_data.wl_surface);
3244    e_input_thread_client_new(ec_new_data.ec, ec_new_data.wl_surface);
3245 }
3246
3247 E_API E_Client *
3248 e_client_new(E_Pixmap *cp, int first_map, int internal)
3249 {
3250    E_Client *ec;
3251    E_Pixmap_Type type;
3252
3253    type = e_pixmap_type_get(cp);
3254    if (type >= E_PIXMAP_TYPE_MAX) return NULL;
3255    if (eina_hash_find(clients_hash[type], &cp)) return NULL;
3256
3257    ec = E_OBJECT_ALLOC(E_Client, E_CLIENT_TYPE, _e_client_free);
3258    if (!ec) return NULL;
3259    e_object_del_func_set(E_OBJECT(ec), E_OBJECT_CLEANUP_FUNC(_e_client_del));
3260
3261    if (!_e_client_private_init(ec))
3262      {
3263         e_object_del(E_OBJECT(ec));
3264         return NULL;
3265      }
3266
3267    uuid_generate(ec->uuid);
3268
3269    ec->focus_policy_override = E_FOCUS_LAST;
3270    e_client_size_set(ec, 1, 1);
3271    ec->internal = internal;
3272
3273    ec->pixmap = cp;
3274    e_pixmap_client_set(cp, ec);
3275    ec->resize_mode = E_POINTER_RESIZE_NONE;
3276    ec->layer = E_LAYER_CLIENT_NORMAL;
3277    ec->first_mapped = EINA_FALSE;
3278    ec->post_raise = EINA_TRUE;
3279    ec->post_lower = EINA_FALSE;
3280    ec->animatable = EINA_TRUE;
3281    ec->maximize_type = e_config->maximize_policy & E_MAXIMIZE_TYPE;
3282    ec->fullscreen_layer = _e_client_convert_fullscreen_layer(e_config->fullscreen_layer);
3283
3284    /* FIXME: if first_map is 1 then we should ignore the first hide event
3285     * or ensure the window is already hidden and events flushed before we
3286     * create a border for it */
3287    if (first_map)
3288      {
3289         ec->changes.pos = 1;
3290         ec->re_manage = 1;
3291      }
3292    ec->new_client = 1;
3293    e_comp->new_clients++;
3294
3295    ec->exp_iconify.by_client = 0;
3296    ec->exp_iconify.not_raise = 0;
3297    ec->exp_iconify.skip_iconify = 0;
3298    ec->exp_iconify.skip_by_remote = 0;
3299    if (e_config->deiconify_approve)
3300      ec->exp_iconify.deiconify_update= 1;
3301    else
3302      ec->exp_iconify.deiconify_update= 0;
3303    if (e_config->use_buffer_flush)
3304      ec->exp_iconify.buffer_flush = 1;
3305    else
3306      ec->exp_iconify.buffer_flush = 0;
3307
3308    e_client_iconified_type_set(ec, E_ICONIFIED_TYPE_NONE);
3309
3310    wl_signal_emit(&PRI(ec)->events.new_client, NULL);
3311    if (!_e_client_hook_call(E_CLIENT_HOOK_NEW_CLIENT, ec))
3312      {
3313         /* delete the above allocated object */
3314         //e_object_del(E_OBJECT(ec));
3315         return NULL;
3316      }
3317
3318    _e_client_aux_hint_eval(ec);
3319
3320    ec->icccm.title = NULL;
3321    ec->icccm.name = NULL;
3322 #if defined(__cplusplus) || defined(c_plusplus)
3323    ec->icccm.cpp_class = NULL;
3324 #else
3325    ec->icccm.class = NULL;
3326 #endif
3327    ec->icccm.min_w = 1;
3328    ec->icccm.min_h = 1;
3329    ec->icccm.max_w = 32767;
3330    ec->icccm.max_h = 32767;
3331
3332    ec->netwm.pid = 0;
3333    ec->netwm.name = NULL;
3334    ec->netwm.state.skip_taskbar = 0;
3335    ec->netwm.state.skip_pager = 0;
3336    ec->netwm.opacity = 255;
3337
3338    ec->visibility.obscured = E_VISIBILITY_UNKNOWN;
3339    ec->visibility.opaque = -1;
3340    ec->visibility.changed = 0;
3341    ec->visibility.skip = 0;
3342    ec->visibility.last_sent_type = E_VISIBILITY_UNKNOWN;
3343
3344    ec->transform.zoom = 1.0;
3345    ec->transform.angle = 0.0;
3346    ec->transform_core.direct_render = EINA_TRUE;
3347    ec->transform_core.activate = EINA_TRUE;
3348
3349    ec->pointer_enter_sent = EINA_FALSE;
3350
3351    ec->acquire_fence_fd = -1;
3352
3353    EC_CHANGED(ec);
3354
3355    e_comp->clients = eina_list_append(e_comp->clients, ec);
3356    eina_hash_add(clients_hash[type], &ec->pixmap, ec);
3357
3358    ELOGF("COMP", "CLIENT ADD. cp:%p, argb:%d, internal:%d, ignored:%d", ec, cp, ec->argb, internal, ec->ignored);
3359    if (!ec->ignored)
3360      _e_client_event_add(ec);
3361    e_comp_object_client_add(ec);
3362    if (ec->frame)
3363      {
3364         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_SHOW, _e_client_cb_evas_show, ec);
3365         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_HIDE, _e_client_cb_evas_hide, ec);
3366         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_MOVE, _e_client_cb_evas_move, ec);
3367         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_RESIZE, _e_client_cb_evas_resize, ec);
3368         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_RESTACK, _e_client_cb_evas_restack, ec);
3369      }
3370
3371    wl_signal_emit(&PRI(ec)->events.new_client_post, NULL);
3372
3373 #ifdef _F_E_CLIENT_NEW_CLIENT_POST_HOOK_
3374    _e_client_hook_call(E_CLIENT_HOOK_NEW_CLIENT_POST, ec);
3375 #endif
3376
3377    ec->manage_resize.resize_obj = NULL;
3378    ec->manage_resize.x = ec->manage_resize.y = ec->manage_resize.w = ec->manage_resize.h = 0;
3379    ec->manage_resize.enable_aspect_ratio = EINA_FALSE;
3380    ec->manage_resize.aw = ec->manage_resize.ah = 0;
3381    ec->manage_resize.header_h = 0;
3382    ec->manage_resize.footer_h = 0;
3383
3384    ec->visibility.ignore_geometry = e_config->calc_vis_ignore_geometry;
3385
3386    E_Input_Thread_Request_EClient_Data ec_new_data;
3387    memset(&ec_new_data, 0, sizeof(E_Input_Thread_Request_EClient_Data));
3388
3389    ec_new_data.ec = ec;
3390    ec_new_data.wl_surface = ec->comp_data ? ec->comp_data->wl_surface : NULL;
3391    INF("[%s] ec(%p), surface(%p)\n", __func__, ec, ec_new_data.wl_surface);
3392    e_input_thread_safe_call(_e_input_thread_client_new, &ec_new_data, sizeof(E_Input_Thread_Request_EClient_Data));
3393
3394    return ec;
3395 }
3396
3397 E_API Eina_Bool e_client_is_internal(E_Client *ec)
3398 {
3399    E_OBJECT_CHECK_RETURN(ec, EINA_TRUE);
3400    return ec->internal;
3401 }
3402
3403 EINTERN void
3404 e_client_desk_iconify_skip_set(E_Client *ec, Eina_Bool skip)
3405 {
3406    if (!ec) return;
3407    ec->user_skip_winlist = skip;
3408 }
3409
3410 EINTERN Eina_Bool
3411 e_client_desk_iconify_skip_get(E_Client *ec)
3412 {
3413    if (!ec) return EINA_FALSE;
3414    return ec->user_skip_winlist;
3415 }
3416
3417 EINTERN Eina_Bool
3418 e_client_comp_grabbed_get(void)
3419 {
3420    return comp_grabbed;
3421 }
3422
3423 EINTERN E_Client *
3424 e_client_action_get(void)
3425 {
3426    return action_client;
3427 }
3428
3429
3430 //////////////////////////////////////////////////////////
3431
3432 EINTERN void
3433 e_client_mouse_in(E_Client *ec, int x, int y)
3434 {
3435    E_Desk *desk;
3436
3437    if (comp_grabbed) return;
3438    if (e_object_is_del(E_OBJECT(ec))) return;
3439    desk = e_comp_desk_find_by_ec(ec);
3440    if (desk && desk->animate_count) return;
3441    ec->mouse.current.mx = x;
3442    ec->mouse.current.my = y;
3443    ec->mouse.in = 1;
3444
3445    wl_signal_emit(&PRI(ec)->events.mouse_in, NULL);
3446 }
3447
3448 EINTERN void
3449 e_client_mouse_out(E_Client *ec, int x, int y)
3450 {
3451    E_Desk *desk;
3452
3453    if (comp_grabbed) return;
3454    if (ec->fullscreen) return;
3455    if (e_object_is_del(E_OBJECT(ec))) return;
3456    desk = e_comp_desk_find_by_ec(ec);
3457    if (desk && desk->animate_count) return;
3458
3459    ec->mouse.current.mx = x;
3460    ec->mouse.current.my = y;
3461    ec->mouse.in = 0;
3462
3463    wl_signal_emit(&PRI(ec)->events.mouse_out, NULL);
3464 }
3465
3466 EINTERN void
3467 e_client_mouse_wheel(E_Client *ec, Evas_Point *output, E_Binding_Event_Wheel *ev)
3468 {
3469    EINA_SAFETY_ON_NULL_RETURN(ec);
3470    if (action_client) return;
3471    ec->mouse.current.mx = output->x;
3472    ec->mouse.current.my = output->y;
3473 }
3474
3475 EINTERN void
3476 e_client_mouse_down(E_Client *ec, int button, Evas_Point *output, E_Binding_Event_Mouse_Button *ev)
3477 {
3478    EINA_SAFETY_ON_NULL_RETURN(ec);
3479
3480    if (action_client || ec->iconic || e_client_util_ignored_get(ec)) return;
3481    if ((button >= 1) && (button <= 3))
3482      {
3483         ec->mouse.last_down[button - 1].mx = output->x;
3484         ec->mouse.last_down[button - 1].my = output->y;
3485         ec->mouse.last_down[button - 1].x = ec->x;
3486         ec->mouse.last_down[button - 1].y = ec->y;
3487         ec->mouse.last_down[button - 1].w = ec->w;
3488         ec->mouse.last_down[button - 1].h = ec->h;
3489      }
3490    else
3491      {
3492         ec->moveinfo.down.x = ec->x;
3493         ec->moveinfo.down.y = ec->y;
3494         ec->moveinfo.down.w = ec->w;
3495         ec->moveinfo.down.h = ec->h;
3496      }
3497    ec->mouse.current.mx = output->x;
3498    ec->mouse.current.my = output->y;
3499    if ((button >= 1) && (button <= 3))
3500      {
3501         ec->mouse.last_down[button - 1].mx = output->x;
3502         ec->mouse.last_down[button - 1].my = output->y;
3503         ec->mouse.last_down[button - 1].x = ec->x;
3504         ec->mouse.last_down[button - 1].y = ec->y;
3505         ec->mouse.last_down[button - 1].w = ec->w;
3506         ec->mouse.last_down[button - 1].h = ec->h;
3507      }
3508    else
3509      {
3510         ec->moveinfo.down.x = ec->x;
3511         ec->moveinfo.down.y = ec->y;
3512         ec->moveinfo.down.w = ec->w;
3513         ec->moveinfo.down.h = ec->h;
3514      }
3515    ec->mouse.current.mx = output->x;
3516    ec->mouse.current.my = output->y;
3517
3518    wl_signal_emit(&PRI(ec)->events.mouse_down, NULL);
3519 }
3520
3521 EINTERN void
3522 e_client_mouse_up(E_Client *ec, int button, Evas_Point *output, E_Binding_Event_Mouse_Button* ev)
3523 {
3524    EINA_SAFETY_ON_NULL_RETURN(ec);
3525    if (ec->iconic || e_client_util_ignored_get(ec)) return;
3526    if ((button >= 1) && (button <= 3))
3527      {
3528         ec->mouse.last_up[button - 1].mx = output->x;
3529         ec->mouse.last_up[button - 1].my = output->y;
3530         ec->mouse.last_up[button - 1].x = ec->x;
3531         ec->mouse.last_up[button - 1].y = ec->y;
3532      }
3533    ec->mouse.current.mx = output->x;
3534    ec->mouse.current.my = output->y;
3535    /* also we don't pass the same params that went in - then again that */
3536    /* should be ok as we are just ending the action if it has an end */
3537    if (ec->cur_mouse_action)
3538      {
3539         if (ec->cur_mouse_action->func.end_mouse)
3540           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", ev);
3541         else if (ec->cur_mouse_action->func.end)
3542           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
3543         e_object_unref(E_OBJECT(ec->cur_mouse_action));
3544         ec->cur_mouse_action = NULL;
3545      }
3546
3547    if ((button >= 1) && (button <= 3))
3548      {
3549         ec->mouse.last_up[button - 1].mx = output->x;
3550         ec->mouse.last_up[button - 1].my = output->y;
3551         ec->mouse.last_up[button - 1].x = ec->x;
3552         ec->mouse.last_up[button - 1].y = ec->y;
3553      }
3554 }
3555
3556 E_API void
3557 e_client_stay_within_canvas_margin(E_Client *ec)
3558 {
3559    int new_x = ec->x;
3560    int new_y = ec->y;
3561
3562    if (ec->floating)
3563      {
3564         _e_client_stay_within_canvas_margin(ec, ec->x, ec->y, &new_x, &new_y);
3565
3566         if ((ec->x != new_x) || (ec->y != new_y))
3567           evas_object_move(ec->frame, new_x, new_y);
3568      }
3569 }
3570
3571 EINTERN void
3572 e_client_mouse_move(E_Client *ec, Evas_Point *output)
3573 {
3574    EINA_SAFETY_ON_NULL_RETURN(ec);
3575    if (ec->iconic || e_client_util_ignored_get(ec)) return;
3576    ec->mouse.current.mx = output->x;
3577    ec->mouse.current.my = output->y;
3578    if (e_client_util_moving_get(ec))
3579      {
3580         _e_client_move_handle(ec);
3581      }
3582    else if (e_client_util_resizing_get(ec))
3583      {
3584         _e_client_resize_handle(ec);
3585      }
3586 }
3587 ///////////////////////////////////////////////////////
3588
3589 EINTERN void
3590 e_client_res_change_geometry_save(E_Client *ec)
3591 {
3592    E_OBJECT_CHECK(ec);
3593    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3594
3595    if (ec->pre_res_change.valid) return;
3596    ec->pre_res_change.valid = 1;
3597    ec->pre_res_change.x = ec->x;
3598    ec->pre_res_change.y = ec->y;
3599    ec->pre_res_change.w = ec->w;
3600    ec->pre_res_change.h = ec->h;
3601    ec->pre_res_change.saved.x = ec->saved.x;
3602    ec->pre_res_change.saved.y = ec->saved.y;
3603    ec->pre_res_change.saved.w = ec->saved.w;
3604    ec->pre_res_change.saved.h = ec->saved.h;
3605 }
3606
3607 EINTERN void
3608 e_client_res_change_geometry_restore(E_Client *ec)
3609 {
3610    E_Zone *zone;
3611
3612    struct
3613    {
3614       unsigned char valid : 1;
3615       int           x, y, w, h;
3616       struct
3617       {
3618          int x, y, w, h;
3619       } saved;
3620    } pre_res_change;
3621
3622    E_OBJECT_CHECK(ec);
3623    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3624    if (!ec->pre_res_change.valid) return;
3625    if (ec->new_client) return;
3626
3627    zone = e_comp_zone_find_by_ec(ec);
3628    if (!zone) return;
3629
3630    memcpy(&pre_res_change, &ec->pre_res_change, sizeof(pre_res_change));
3631
3632    if (ec->fullscreen)
3633      {
3634         e_client_unfullscreen(ec);
3635         e_client_fullscreen(ec, e_config->fullscreen_policy);
3636      }
3637    else if (ec->maximized != E_MAXIMIZE_NONE)
3638      {
3639         E_Maximize max;
3640
3641         max = ec->maximized;
3642         e_client_unmaximize(ec, E_MAXIMIZE_BOTH);
3643         e_client_maximize(ec, max);
3644      }
3645    else
3646      {
3647         int x, y, w, h, zx, zy, zw, zh;
3648
3649         ec->saved.x = ec->pre_res_change.saved.x;
3650         ec->saved.y = ec->pre_res_change.saved.y;
3651         ec->saved.w = ec->pre_res_change.saved.w;
3652         ec->saved.h = ec->pre_res_change.saved.h;
3653
3654         e_zone_useful_geometry_get(zone, &zx, &zy, &zw, &zh);
3655
3656         if (ec->saved.w > zw)
3657           ec->saved.w = zw;
3658         if ((ec->saved.x + ec->saved.w) > (zx + zw))
3659           ec->saved.x = zx + zw - ec->saved.w;
3660
3661         if (ec->saved.h > zh)
3662           ec->saved.h = zh;
3663         if ((ec->saved.y + ec->saved.h) > (zy + zh))
3664           ec->saved.y = zy + zh - ec->saved.h;
3665
3666         x = ec->pre_res_change.x;
3667         y = ec->pre_res_change.y;
3668         w = ec->pre_res_change.w;
3669         h = ec->pre_res_change.h;
3670         if (w > zw)
3671           w = zw;
3672         if (h > zh)
3673           h = zh;
3674         if ((x + w) > (zx + zw))
3675           x = zx + zw - w;
3676         if ((y + h) > (zy + zh))
3677           y = zy + zh - h;
3678         evas_object_geometry_set(ec->frame, x, y, w, h);
3679      }
3680    memcpy(&ec->pre_res_change, &pre_res_change, sizeof(pre_res_change));
3681 }
3682
3683 EINTERN void
3684 e_client_pos_set(E_Client *ec, int x, int y)
3685 {
3686    if (!ec) return;
3687    ec->x = x;
3688    ec->y = y;
3689 }
3690
3691 EINTERN void
3692 e_client_pos_get(E_Client *ec, int *x, int *y)
3693 {
3694    int ex = 0;
3695    int ey = 0;
3696
3697    if (ec)
3698      {
3699         ex = ec->x;
3700         ey = ec->y;
3701      }
3702
3703    if (x) *x = ex;
3704    if (y) *y = ey;
3705 }
3706
3707 E_API void
3708 e_client_size_set(E_Client *ec, int w, int h)
3709 {
3710    if (!ec) return;
3711    ec->w = w;
3712    ec->h = h;
3713 }
3714
3715 E_API void
3716 e_client_size_get(E_Client *ec, int *w, int *h)
3717 {
3718    int ew = 0;
3719    int eh = 0;
3720
3721    if (ec)
3722      {
3723         ew = ec->w;
3724         eh = ec->h;
3725      }
3726
3727    if (w) *w = ew;
3728    if (h) *h = eh;
3729 }
3730
3731 E_API void
3732 e_client_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
3733 {
3734    int gx = 0;
3735    int gy = 0;
3736    int gw = 0;
3737    int gh = 0;
3738
3739    E_OBJECT_CHECK(ec);
3740    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3741
3742    if (e_client_transform_core_enable_get(ec))
3743      {
3744         gx = ec->transform_core.result.boundary.x;
3745         gy = ec->transform_core.result.boundary.y;
3746         gw = ec->transform_core.result.boundary.w;
3747         gh = ec->transform_core.result.boundary.h;
3748      }
3749    else
3750      {
3751         if (ec->frame)
3752           {
3753              evas_object_geometry_get(ec->frame, &gx, &gy, &gw, &gh);
3754              if (gw == 0 && gh == 0)
3755                {
3756                   /* In this case, there is no image buffer in e_comp_object, thus it
3757                    * should return geometry value of ec itself. It usually happens if
3758                    * new ec is not mapped yet.
3759                    */
3760                   gw = ec->w;
3761                   gh = ec->h;
3762                   gx = ec->x;
3763                   gy = ec->y;
3764                }
3765           }
3766         else
3767           {
3768              gx = ec->x;
3769              gy = ec->y;
3770              gw = ec->w;
3771              gh = ec->h;
3772           }
3773      }
3774
3775    if (x) *x = gx;
3776    if (y) *y = gy;
3777    if (w) *w = gw;
3778    if (h) *h = gh;
3779 }
3780
3781 E_API E_Client *
3782 e_client_above_get(const E_Client *ec)
3783 {
3784 #ifdef REFACTOR_DESK_AREA
3785    API_ENTRY_VAL(NULL);
3786
3787    E_Client_Data_Get_Above data;
3788
3789    data.above_ec = NULL;
3790
3791    wl_signal_emit(&priv->events.get_above, &data);
3792
3793    return data.above_ec;
3794 #else
3795    unsigned int x;
3796    E_Client *ec2;
3797
3798    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
3799    if (EINA_INLIST_GET(ec)->next) //check current layer
3800      {
3801         EINA_INLIST_FOREACH(EINA_INLIST_GET(ec)->next, ec2)
3802           {
3803              if (ec == ec2)
3804                {
3805                   ELOGF("FATAL", "CHECK the ec inlist next", ec);
3806                   continue;
3807                }
3808              if (!e_object_is_del(E_OBJECT(ec2)))
3809                return ec2;
3810           }
3811      }
3812    if (ec->layer == E_LAYER_CLIENT_CURSOR) return NULL;
3813    if (e_comp_canvas_client_layer_map(ec->layer) == 9999) return NULL;
3814
3815    g_rec_mutex_lock(&e_comp->ec_list_mutex);
3816    /* go up the layers until we find one */
3817    for (x = e_comp_canvas_layer_map(ec->layer) + 1; x <= e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x++)
3818      {
3819         if (!e_comp->layers[x].clients) continue;
3820         EINA_INLIST_FOREACH(e_comp->layers[x].clients, ec2)
3821           {
3822              if (ec == ec2)
3823                {
3824                   ELOGF("FATAL", "EC exist above layer. ec layer_map:%d, cur layer_map:%d",
3825                         ec, e_comp_canvas_layer_map(ec->layer), x);
3826                   continue;
3827                }
3828              if (!e_object_is_del(E_OBJECT(ec2)))
3829                {
3830                   g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3831                   return ec2;
3832                }
3833           }
3834      }
3835    g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3836
3837    return NULL;
3838 #endif
3839 }
3840
3841 E_API E_Client *
3842 e_client_below_get(const E_Client *ec)
3843 {
3844 #ifdef REFACTOR_DESK_AREA
3845    API_ENTRY_VAL(NULL);
3846
3847    E_Client_Data_Get_Below data;
3848
3849    data.below_ec = NULL;
3850
3851    wl_signal_emit(&priv->events.get_below, &data);
3852
3853    return data.below_ec;
3854 #else
3855    unsigned int x;
3856    E_Client *ec2;
3857    Eina_Inlist *l;
3858    E_Layer ec_layer, ec_layer_cw;
3859    int cw_layer;
3860
3861    E_OBJECT_CHECK_RETURN(ec, NULL);
3862    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, NULL);
3863
3864    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
3865    if (EINA_INLIST_GET(ec)->prev) //check current layer
3866      {
3867         for (l = EINA_INLIST_GET(ec)->prev; l; l = l->prev)
3868           {
3869              ec2 = EINA_INLIST_CONTAINER_GET(l, E_Client);
3870              if (ec == ec2)
3871                {
3872                   ELOGF("FATAL", "CHECK the ec inlist prev", ec);
3873                   continue;
3874                }
3875              if (!e_object_is_del(E_OBJECT(ec2)))
3876                return ec2;
3877           }
3878      }
3879
3880    // check layer validation
3881    ec_layer = ec->layer;
3882    if (ec->layer_block || ec->layer_pending)
3883      {
3884         cw_layer = e_comp_object_layer_get(ec->frame);
3885         if (cw_layer >= 0)
3886           {
3887              ec_layer_cw = e_comp_canvas_layer_map_to(cw_layer);
3888              if (ec_layer != ec_layer_cw)
3889                {
3890                   ELOGF("COMP", "LAYER is not same. USE obj layer! (ec->layer:%d, obj:%d). block:%d, pending:%d)", ec, ec_layer, ec_layer_cw, ec->layer_block, ec->layer_pending);
3891                   ec_layer = ec_layer_cw;
3892                }
3893           }
3894      }
3895
3896    if (ec_layer == E_LAYER_CLIENT_DESKTOP) return NULL;
3897    if (e_comp_canvas_client_layer_map(ec_layer) == 9999) return NULL;
3898
3899    /* go down the layers until we find one */
3900    x = e_comp_canvas_layer_map(ec_layer);
3901    if (x > 0) x--;
3902
3903    g_rec_mutex_lock(&e_comp->ec_list_mutex);
3904    for (; x >= e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x--)
3905      {
3906         if (!e_comp->layers[x].clients) continue;
3907         EINA_INLIST_REVERSE_FOREACH(e_comp->layers[x].clients, ec2)
3908           {
3909              if (ec == ec2)
3910                {
3911                   ELOGF("FATAL", "EC exist below layer. ec layer_map:%d, cur layer_map:%d",
3912                         ec, e_comp_canvas_layer_map(ec_layer), x);
3913                   continue;
3914                }
3915              if (!e_object_is_del(E_OBJECT(ec2)))
3916                {
3917                   g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3918                   return ec2;
3919                }
3920           }
3921      }
3922    g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3923
3924    return NULL;
3925 #endif
3926 }
3927
3928 EINTERN E_Client *
3929 e_client_visible_above_get(E_Client *ec)
3930 {
3931 #ifdef REFACTOR_DESK_AREA
3932    API_ENTRY_VAL(NULL);
3933
3934    E_Client_Data_Get_Visible_Above data;
3935
3936    data.above_ec = NULL;
3937
3938    wl_signal_emit(&priv->events.get_visible_above, &data);
3939
3940    return data.above_ec;
3941 #else
3942    unsigned int x;
3943    E_Client *ec2;
3944
3945    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
3946    if (EINA_INLIST_GET(ec)->next) //check current layer
3947      {
3948         EINA_INLIST_FOREACH(EINA_INLIST_GET(ec)->next, ec2)
3949           {
3950              if (ec == ec2) continue;
3951              if ((!e_object_is_del(E_OBJECT(ec2))) &&
3952                  (!e_client_util_ignored_get(ec2)) &&
3953                  (ec2->visible) &&
3954                  (ec2->frame))
3955                return ec2;
3956           }
3957      }
3958
3959    if (ec->layer == E_LAYER_CLIENT_CURSOR) return NULL;
3960    if (e_comp_canvas_client_layer_map(ec->layer) == 9999) return NULL;
3961
3962    /* go up the layers until we find one */
3963    for (x = e_comp_canvas_layer_map(ec->layer) + 1; x <= e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x++)
3964      {
3965         if (!e_comp->layers[x].clients) continue;
3966         EINA_INLIST_FOREACH(e_comp->layers[x].clients, ec2)
3967           {
3968              if (ec == ec2) continue;
3969              if ((!e_object_is_del(E_OBJECT(ec2))) &&
3970                  (!e_client_util_ignored_get(ec2)) &&
3971                  (ec2->visible) &&
3972                  (ec2->frame))
3973                return ec2;
3974           }
3975      }
3976
3977    return NULL;
3978 #endif
3979 }
3980
3981 EINTERN E_Client *
3982 e_client_visible_below_get(E_Client *ec)
3983 {
3984 #ifdef REFACTOR_DESK_AREA
3985    API_ENTRY_VAL(NULL);
3986
3987    E_Client_Data_Get_Visible_Below data;
3988
3989    data.below_ec = NULL;
3990
3991    wl_signal_emit(&priv->events.get_visible_below, &data);
3992
3993    return data.below_ec;
3994 #else
3995    unsigned int x;
3996    E_Client *ec2;
3997    Eina_Inlist *l;
3998    E_Layer ec_layer, ec_layer_cw;
3999    int cw_layer;
4000
4001    E_OBJECT_CHECK_RETURN(ec, NULL);
4002    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, NULL);
4003
4004    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
4005    if (EINA_INLIST_GET(ec)->prev) //check current layer
4006      {
4007         for (l = EINA_INLIST_GET(ec)->prev; l; l = l->prev)
4008           {
4009              ec2 = EINA_INLIST_CONTAINER_GET(l, E_Client);
4010              if (ec == ec2) continue;
4011              if ((!e_object_is_del(E_OBJECT(ec2))) &&
4012                  (!e_client_util_ignored_get(ec2)) &&
4013                  (ec2->visible) &&
4014                  (ec2->frame))
4015                return ec2;
4016           }
4017      }
4018
4019    // check layer validation
4020    ec_layer = ec->layer;
4021    if (ec->layer_block || ec->layer_pending)
4022      {
4023         cw_layer = e_comp_object_layer_get(ec->frame);
4024         if (cw_layer >= 0)
4025           {
4026              ec_layer_cw = e_comp_canvas_layer_map_to(cw_layer);
4027              if (ec_layer != ec_layer_cw)
4028                {
4029                   ELOGF("COMP", "LAYER is not same. USE obj layer! (ec->layer:%d, obj:%d). block:%d, pending:%d)", ec, ec_layer, ec_layer_cw, ec->layer_block, ec->layer_pending);
4030                   ec_layer = ec_layer_cw;
4031                }
4032           }
4033      }
4034
4035    /* go down the layers until we find one */
4036    if (e_comp_canvas_layer_map(ec->layer) > e_comp_canvas_layer_map(E_LAYER_MAX)) return NULL;
4037    x = e_comp_canvas_layer_map(ec->layer);
4038    if (x > 0) x--;
4039
4040    for (; x >= e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x--)
4041      {
4042         if (!e_comp->layers[x].clients) continue;
4043         EINA_INLIST_REVERSE_FOREACH(e_comp->layers[x].clients, ec2)
4044           {
4045              if (ec == ec2) continue;
4046              if ((!e_object_is_del(E_OBJECT(ec2))) &&
4047                  (!e_client_util_ignored_get(ec2)) &&
4048                  (ec2->visible) &&
4049                  (ec2->frame))
4050                return ec2;
4051           }
4052      }
4053
4054    return NULL;
4055 #endif
4056 }
4057
4058 E_API E_Client *
4059 e_client_bottom_get(void)
4060 {
4061 #ifdef REFACTOR_DESK_AREA
4062    E_Zone *zone;
4063    E_Desk *desk;
4064
4065    // get the bottom ec from current desk at current zone
4066    zone = e_zone_current_get();
4067    desk = e_desk_current_get(zone);
4068
4069    return e_desk_bottom_ec_get(desk);
4070 #else
4071    unsigned int x;
4072    g_rec_mutex_lock(&e_comp->ec_list_mutex);
4073    for (x = e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x <= e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x++)
4074      {
4075         E_Client *ec2;
4076
4077         if (!e_comp->layers[x].clients) continue;
4078         EINA_INLIST_FOREACH(e_comp->layers[x].clients, ec2)
4079           if (!e_object_is_del(E_OBJECT(ec2)))
4080             {
4081                g_rec_mutex_unlock(&e_comp->ec_list_mutex);
4082                return ec2;
4083             }
4084      }
4085    g_rec_mutex_unlock(&e_comp->ec_list_mutex);
4086
4087    return NULL;
4088 #endif
4089 }
4090
4091 E_API E_Client *
4092 e_client_top_get(void)
4093 {
4094 #ifdef REFACTOR_DESK_AREA
4095    E_Zone *zone;
4096    E_Desk *desk;
4097
4098    // get the top ec from current desk at current zone
4099    zone = e_zone_current_get();
4100    desk = e_desk_current_get(zone);
4101
4102    return e_desk_top_ec_get(desk);
4103 #else
4104    unsigned int x;
4105    g_rec_mutex_lock(&e_comp->ec_list_mutex);
4106    for (x = e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x >= e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x--)
4107      {
4108         E_Client *ec2;
4109
4110         if (!e_comp->layers[x].clients) continue;
4111         EINA_INLIST_REVERSE_FOREACH(e_comp->layers[x].clients, ec2)
4112           if (!e_object_is_del(E_OBJECT(ec2)))
4113             {
4114                g_rec_mutex_unlock(&e_comp->ec_list_mutex);
4115                return ec2;
4116             }
4117      }
4118    g_rec_mutex_unlock(&e_comp->ec_list_mutex);
4119
4120    return NULL;
4121 #endif
4122 }
4123
4124 EINTERN unsigned int
4125 e_clients_count(void)
4126 {
4127    return eina_list_count(e_comp->clients);
4128 }
4129
4130
4131 /**
4132  * Set a callback which will be called just prior to updating the
4133  * move coordinates for a border
4134  */
4135 EINTERN void
4136 e_client_move_intercept_cb_set(E_Client *ec, E_Client_Move_Intercept_Cb cb)
4137 {
4138    ec->move_intercept_cb = cb;
4139 }
4140
4141 ///////////////////////////////////////
4142
4143 E_API E_Client_Hook *
4144 e_client_hook_add(E_Client_Hook_Point hookpoint, E_Client_Hook_Cb func, const void *data)
4145 {
4146    E_Client_Hook *ch;
4147
4148    EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_CLIENT_HOOK_LAST, NULL);
4149    ch = E_NEW(E_Client_Hook, 1);
4150    if (!ch) return NULL;
4151    ch->hookpoint = hookpoint;
4152    ch->func = func;
4153    ch->data = (void*)data;
4154    _e_client_hooks[hookpoint] = eina_inlist_append(_e_client_hooks[hookpoint], EINA_INLIST_GET(ch));
4155    return ch;
4156 }
4157
4158 E_API void
4159 e_client_hook_del(E_Client_Hook *ch)
4160 {
4161    ch->delete_me = 1;
4162    if (_e_client_hooks_walking == 0)
4163      {
4164         _e_client_hooks[ch->hookpoint] = eina_inlist_remove(_e_client_hooks[ch->hookpoint], EINA_INLIST_GET(ch));
4165         free(ch);
4166      }
4167    else
4168      _e_client_hooks_delete++;
4169 }
4170
4171 ///////////////////////////////////////
4172
4173 E_API E_Client_Intercept_Hook *
4174 e_client_intercept_hook_add(E_Client_Intercept_Hook_Point hookpoint, E_Client_Intercept_Hook_Cb func, const void *data)
4175 {
4176    E_Client_Intercept_Hook *ch;
4177
4178    EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_CLIENT_INTERCEPT_HOOK_LAST, NULL);
4179    ch = E_NEW(E_Client_Intercept_Hook, 1);
4180    if (!ch) return NULL;
4181    ch->hookpoint = hookpoint;
4182    ch->func = func;
4183    ch->data = (void*)data;
4184    _e_client_intercept_hooks[hookpoint] = eina_inlist_append(_e_client_intercept_hooks[hookpoint], EINA_INLIST_GET(ch));
4185    return ch;
4186 }
4187
4188 E_API void
4189 e_client_intercept_hook_del(E_Client_Intercept_Hook *ch)
4190 {
4191    if (!ch) return;
4192
4193    ch->delete_me = 1;
4194    if (_e_client_intercept_hooks_walking == 0)
4195      {
4196         _e_client_intercept_hooks[ch->hookpoint] =
4197            eina_inlist_remove(_e_client_intercept_hooks[ch->hookpoint], EINA_INLIST_GET(ch));
4198         free(ch);
4199      }
4200    else
4201      _e_client_intercept_hooks_delete++;
4202 }
4203
4204 E_API void
4205 e_client_focus_latest_set(E_Client *ec)
4206 {
4207    EINA_SAFETY_ON_NULL_RETURN(ec);
4208
4209    wl_signal_emit(&PRI(ec)->events.focus_latest_set, NULL);
4210 }
4211
4212 E_API void
4213 e_client_focus_defer_set(E_Client *ec)
4214 {
4215    EINA_SAFETY_ON_NULL_RETURN(ec);
4216
4217    wl_signal_emit(&PRI(ec)->events.focus_defer_set, NULL);
4218 }
4219
4220 EINTERN void
4221 e_client_focused_set(E_Client *ec)
4222 {
4223    E_Client *focused_ec;
4224    E_Zone *zone;
4225
4226    if (ec)
4227      ELOGF("FOCUS", "CLIENT FOCUSED_SET : SET", ec);
4228    else
4229      ELOGF("FOCUS", "CLIENT FOCUSED_SET : UNSET", NULL);
4230
4231   focused_ec = e_comp_focused_ec_get();
4232   if (ec == focused_ec) return;
4233
4234    TRACE_DS_BEGIN(CLIENT:FOCUSED SET);
4235
4236    // unset the current focused_ec if focused_ec is not being deleted
4237    if (focused_ec)
4238      {
4239        if (!e_object_is_del(E_OBJECT(focused_ec)))
4240          {
4241             // FIXME: Remove focus_unset event of client.
4242             //        Instead, make zone focus_unset event and use it.
4243             wl_signal_emit(&PRI(focused_ec)->events.focus_unset, NULL);
4244             _e_client_hook_call(E_CLIENT_HOOK_FOCUS_UNSET, focused_ec);
4245
4246             if (e_object_ref_get(E_OBJECT(focused_ec)) > 0)
4247               {
4248                  _e_client_event_simple(focused_ec, E_EVENT_CLIENT_FOCUS_OUT);
4249               }
4250          }
4251      }
4252
4253    // clear the current focused_ec when ec is NULL
4254    if (!ec)
4255      {
4256         zone = e_comp_zone_find_by_ec(focused_ec);
4257         e_zone_focus_clear(zone);
4258         TRACE_DS_END();
4259         return;
4260      }
4261
4262    // FIXME: Remove focus_set event of client.
4263    //        Instead, make zone focus_set event and use it.
4264    // set the new current focused_ec
4265    wl_signal_emit(&PRI(ec)->events.focus_set, NULL);
4266    _e_client_hook_call(E_CLIENT_HOOK_FOCUS_SET, ec);
4267
4268    // send the client_focuse_in event
4269    _e_client_event_simple(ec, E_EVENT_CLIENT_FOCUS_IN);
4270
4271    TRACE_DS_END();
4272 }
4273
4274 EINTERN void
4275 e_client_activate(E_Client *ec)
4276 {
4277    E_OBJECT_CHECK(ec);
4278    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4279
4280    TRACE_DS_BEGIN(CLIENT:ACTIVATE);
4281
4282    ELOGF("COMP", "Set launching flag..", ec);
4283    ec->launching = EINA_TRUE;
4284
4285    ec->exp_iconify.not_raise = 0;
4286
4287    if (ec->iconic)
4288      {
4289          if (!ec->lock_user_iconify)
4290            e_client_uniconify(ec);
4291      }
4292    ELOGF("COMP", "Un-Set ICONIFY BY CLIENT", ec);
4293    ec->exp_iconify.by_client = 0;
4294    e_client_iconified_type_set(ec, E_ICONIFIED_TYPE_NONE);
4295
4296    wl_signal_emit(&PRI(ec)->events.activate_done, NULL);
4297    _e_client_hook_call(E_CLIENT_HOOK_ACTIVATE_DONE, ec);
4298
4299    TRACE_DS_END();
4300 }
4301
4302 E_API E_Client *
4303 e_client_focused_get(void)
4304 {
4305    return e_comp_focused_ec_get();
4306 }
4307
4308 EINTERN Eina_List *
4309 e_client_lost_windows_get(E_Zone *zone)
4310 {
4311    Eina_List *list = NULL;
4312    const Eina_List *l;
4313    E_Client *ec;
4314    int loss_overlap = 5;
4315
4316    E_OBJECT_CHECK_RETURN(zone, NULL);
4317    E_OBJECT_TYPE_CHECK_RETURN(zone, E_ZONE_TYPE, NULL);
4318    EINA_LIST_FOREACH(e_comp->clients, l, ec)
4319      {
4320         if (!e_zone_has_ec(zone, ec)) continue;
4321         if (e_client_util_ignored_get(ec)) continue;
4322
4323         if (!E_INTERSECTS(zone->x + loss_overlap,
4324                           zone->y + loss_overlap,
4325                           zone->w - (2 * loss_overlap),
4326                           zone->h - (2 * loss_overlap),
4327                           ec->x, ec->y, ec->w, ec->h))
4328           {
4329              list = eina_list_append(list, ec);
4330           }
4331      }
4332    return list;
4333 }
4334
4335 ///////////////////////////////////////
4336
4337 EINTERN void
4338 e_client_maximized_geometry_set(E_Client *ec, int x, int y, int w, int h)
4339 {
4340    if (!ec) return;
4341
4342    ec->maximized_info.x = x;
4343    ec->maximized_info.y = y;
4344    ec->maximized_info.w = w;
4345    ec->maximized_info.h = h;
4346
4347    e_client_frame_geometry_set(ec, x, y, w, h);
4348 }
4349
4350 EINTERN void
4351 e_client_maximized_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
4352 {
4353    if (!ec) return;
4354
4355    if (x) *x = ec->maximized_info.x;
4356    if (y) *y = ec->maximized_info.y;
4357    if (w) *w = ec->maximized_info.w;
4358    if (h) *h = ec->maximized_info.h;
4359 }
4360
4361 EINTERN void
4362 e_client_maximize_update(E_Client *ec)
4363 {
4364    E_Maximize max;
4365
4366    E_OBJECT_CHECK(ec);
4367    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4368
4369    if (ec->maximized)
4370      {
4371         max = ec->maximized;
4372         ec->maximized = 0;
4373         e_client_maximize(ec, max);
4374      }
4375 }
4376
4377 E_API void
4378 e_client_maximize(E_Client *ec, E_Maximize max)
4379 {
4380    E_OBJECT_CHECK(ec);
4381    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4382
4383    if (!(max & E_MAXIMIZE_DIRECTION)) max |= E_MAXIMIZE_BOTH;
4384
4385    if ((ec->maximized & E_MAXIMIZE_DIRECTION) == (max & E_MAXIMIZE_DIRECTION))
4386      {
4387         if ((ec->maximized & E_MAXIMIZE_TYPE) == (max & E_MAXIMIZE_TYPE))
4388           return;
4389      }
4390
4391    if (ec->new_client)
4392      {
4393         ec->changes.need_maximize = 1;
4394         ec->maximized &= ~E_MAXIMIZE_TYPE;
4395         ec->maximized |= max;
4396         EC_CHANGED(ec);
4397         return;
4398      }
4399
4400    if (!ec->fullscreen)
4401      {
4402         // call the maximize hook of a client
4403         wl_signal_emit(&PRI(ec)->events.maximize, &max);
4404
4405         // store the E_Maximize value
4406         ec->maximized = max;
4407         ec->changes.need_unmaximize = 0;
4408
4409         evas_object_smart_callback_call(ec->frame, "maximize_done", NULL);
4410      }
4411    else
4412      {
4413         // store the E_Maximize value
4414         ec->maximized = max;
4415         ec->changes.need_unmaximize = 0;
4416      }
4417 }
4418
4419 E_API void
4420 e_client_unmaximize(E_Client *ec, E_Maximize max)
4421 {
4422    E_OBJECT_CHECK(ec);
4423    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4424
4425    if (!(max & E_MAXIMIZE_DIRECTION))
4426      {
4427         CRI("BUG: Unmaximize call without direction!");
4428         return;
4429      }
4430    if (ec->new_client)
4431      {
4432         ec->changes.need_unmaximize = 1;
4433         EC_CHANGED(ec);
4434         return;
4435      }
4436
4437    /* Remove directions not used */
4438    max &= (ec->maximized & E_MAXIMIZE_DIRECTION);
4439    /* Can only remove existing maximization directions */
4440    if (!max) return;
4441
4442    if (!ec->fullscreen)
4443      {
4444         evas_object_smart_callback_call(ec->frame, "unmaximize_pre", NULL);
4445
4446         // call the unmaximize hook of a client
4447         wl_signal_emit(&PRI(ec)->events.unmaximize, &max);
4448
4449         evas_object_smart_callback_call(ec->frame, "unmaximize_done", NULL);
4450      }
4451
4452    ec->maximized = E_MAXIMIZE_NONE;
4453    ec->changes.need_unmaximize = 0;
4454 }
4455
4456 EINTERN void
4457 e_client_fullscreen(E_Client *ec, E_Fullscreen policy)
4458 {
4459    E_OBJECT_CHECK(ec);
4460    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4461
4462    if (ec->fullscreen) return;
4463
4464    // call the fullscreen_pre hook of a client
4465    wl_signal_emit(&PRI(ec)->events.fullscreen_pre, NULL);
4466    _e_client_hook_call(E_CLIENT_HOOK_FULLSCREEN_PRE, ec);
4467
4468    if (ec->skip_fullscreen) return;
4469    if (ec->new_client)
4470      {
4471         ec->need_fullscreen = 1;
4472         return;
4473      }
4474
4475    ec->saved.layer = ec->layer;
4476    e_client_layer_set(ec, ec->fullscreen_layer);
4477
4478    ec->fullscreen = 1;
4479
4480    // call the fullscreen hook of a client
4481    wl_signal_emit(&PRI(ec)->events.fullscreen, &policy);
4482
4483    ec->fullscreen_policy = policy;
4484
4485    _e_client_event_simple(ec, E_EVENT_CLIENT_FULLSCREEN);
4486 }
4487
4488 EINTERN void
4489 e_client_unfullscreen(E_Client *ec)
4490 {
4491    E_OBJECT_CHECK(ec);
4492    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4493
4494    ec->need_fullscreen = 0;
4495
4496    if (!ec->fullscreen) return;
4497
4498    ec->fullscreen = 0;
4499
4500    E_Fullscreen policy = ec->fullscreen_policy;
4501
4502    // call the unfullscreen hook of a client
4503    wl_signal_emit(&PRI(ec)->events.unfullscreen, &policy);
4504
4505    e_client_layer_set(ec, ec->saved.layer);
4506
4507    ec->fullscreen_policy = E_FULLSCREEN_RESIZE;
4508
4509    _e_client_event_simple(ec, E_EVENT_CLIENT_UNFULLSCREEN);
4510 }
4511
4512 ///////////////////////////////////////
4513 EINTERN Eina_Bool
4514 e_client_is_parent_iconify_by_client(E_Client *ec)
4515 {
4516    E_Client *parent = ec->parent;
4517    if (!parent) return EINA_FALSE;
4518
4519    if ((parent->exp_iconify.type == E_ICONIFIED_TYPE_ICONIFY_BY_CLIENT) ||
4520        (parent->exp_iconify.type == E_ICONIFIED_TYPE_PARENT_ICONIFY_BY_CLIENT))
4521      return EINA_TRUE;
4522
4523    return EINA_FALSE;
4524 }
4525
4526 E_API void
4527 e_client_iconify(E_Client *ec)
4528 {
4529    E_OBJECT_CHECK(ec);
4530    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4531
4532    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
4533    Eina_Bool iconified_by_client = e_client_is_iconified_by_client(ec);
4534
4535    ELOGF("TZVIS", "ICONIFY  |iconic:%d  |argb:%d       |not_raise:%d   |by_client:%d, type:%d",
4536          ec, ec->iconic, ec->argb, (unsigned int)ec->exp_iconify.not_raise,
4537          ec->exp_iconify.by_client, ec->exp_iconify.type);
4538
4539    if (ec->iconic) return;
4540    if (ec->exp_iconify.skip_iconify && !iconified_by_client) return;
4541    if (ec->exp_iconify.skip_by_remote) return;
4542    if (!cdata || !cdata->mapped)
4543      {
4544         if (!iconified_by_client)
4545           {
4546              ELOGF("TZVIS", "Not mapped.. So, don't iconify", ec);
4547              return;
4548           }
4549         else
4550           {
4551              ELOGF("TZVIS", "Not mapped.. But, iconify by user request", ec);
4552           }
4553      }
4554
4555    TRACE_DS_BEGIN(CLIENT:ICONIFY);
4556
4557    wl_signal_emit(&PRI(ec)->events.iconify, NULL);
4558    _e_client_hook_call(E_CLIENT_HOOK_ICONIFY, ec);
4559
4560    TRACE_DS_END();
4561 }
4562
4563 E_API void
4564 e_client_uniconify(E_Client *ec)
4565 {
4566    E_Comp_Wl_Client_Data *cdata;
4567
4568    E_OBJECT_CHECK(ec);
4569    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4570
4571    cdata = e_client_cdata_get(ec);
4572
4573    ELOGF("TZVIS", "UNICONIFY|iconic:%d  |argb:%d       |not_raise:%d  |by_client:%d, type:%d |mapped:%d",
4574          ec, ec->iconic, ec->argb, (unsigned int)ec->exp_iconify.not_raise,
4575          ec->exp_iconify.by_client, ec->exp_iconify.type,
4576          cdata ? cdata->mapped : 0);
4577
4578    if (!ec->iconic) return;
4579
4580    TRACE_DS_BEGIN(CLIENT:UNICONIFY);
4581
4582     // call the uniconify hook of a client
4583    wl_signal_emit(&PRI(ec)->events.uniconify, NULL);
4584    _e_client_hook_call(E_CLIENT_HOOK_UNICONIFY, ec);
4585
4586    TRACE_DS_END();
4587 }
4588
4589 E_API void
4590 e_client_iconified_type_set(E_Client *ec, E_Iconified_Type type)
4591 {
4592    if (!ec) return;
4593    ec->exp_iconify.type = type;
4594 }
4595
4596 EINTERN E_Iconified_Type
4597 e_client_iconified_type_get(E_Client *ec)
4598 {
4599    if (!ec) return E_ICONIFIED_TYPE_NONE;
4600    return ec->exp_iconify.type;
4601 }
4602
4603 E_API Eina_Bool e_client_is_iconified_by_client(E_Client *ec)
4604 {
4605    if (!ec) return EINA_FALSE;
4606
4607    if (ec->exp_iconify.type == E_ICONIFIED_TYPE_ICONIFY_BY_CLIENT)
4608      return EINA_TRUE;
4609
4610    if (ec->exp_iconify.type == E_ICONIFIED_TYPE_DESK_ICONIFY_BY_CLIENT)
4611      return EINA_TRUE;
4612
4613    if (ec->exp_iconify.type == E_ICONIFIED_TYPE_PARENT_ICONIFY_BY_CLIENT)
4614      return EINA_TRUE;
4615
4616    if (ec->exp_iconify.by_client)
4617      {
4618         ELOGF("POL", "CHECK. mismatch value. by_client:%d, type:%d", ec, ec->exp_iconify.by_client, ec->exp_iconify.type);
4619         return EINA_TRUE;
4620      }
4621
4622    return EINA_FALSE;
4623 }
4624
4625 ///////////////////////////////////////
4626
4627 EINTERN void e_client_hide_by_request_set(E_Client *ec, Eina_Bool set)
4628 {
4629    API_ENTRY;
4630    priv->hide_by_request = set;
4631 }
4632
4633 EINTERN Eina_Bool e_client_hide_by_request_get(E_Client *ec)
4634 {
4635    API_ENTRY_VAL(EINA_FALSE);
4636    return priv->hide_by_request;
4637 }
4638
4639 EINTERN void e_client_focus_check_set(E_Client *ec, Eina_Bool set)
4640 {
4641    API_ENTRY;
4642    priv->focus_check = set;
4643 }
4644
4645 EINTERN Eina_Bool e_client_focus_check_get(E_Client *ec)
4646 {
4647    API_ENTRY_VAL(EINA_FALSE);
4648    return priv->focus_check;
4649 }
4650
4651 ///////////////////////////////////////
4652
4653 EINTERN void
4654 e_client_stick(E_Client *ec)
4655 {
4656    E_OBJECT_CHECK(ec);
4657    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4658    if (ec->sticky) return;
4659
4660    // call the stick hook of a client
4661    wl_signal_emit(&PRI(ec)->events.stick, NULL);
4662
4663    // send the sticky property event of a client
4664    _e_client_event_property(ec, E_CLIENT_PROPERTY_STICKY);
4665 }
4666
4667 EINTERN void
4668 e_client_unstick(E_Client *ec)
4669 {
4670    E_OBJECT_CHECK(ec);
4671    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4672
4673    if (!ec->sticky) return;
4674
4675    // call the unstick hook of a client
4676    wl_signal_emit(&PRI(ec)->events.unstick, NULL);
4677
4678   // send the sticky property event of a client
4679    _e_client_event_property(ec, E_CLIENT_PROPERTY_STICKY);
4680 }
4681
4682 EINTERN void
4683 e_client_pinned_set(E_Client *ec, Eina_Bool set)
4684 {
4685    E_Layer layer;
4686
4687    EINA_SAFETY_ON_NULL_RETURN(ec);
4688    if (set)
4689      layer = E_LAYER_CLIENT_ABOVE;
4690    else
4691      layer = E_LAYER_CLIENT_NORMAL;
4692
4693    e_client_layer_set(ec, layer);
4694
4695    EC_CHANGED(ec);
4696 }
4697
4698 ///////////////////////////////////////
4699
4700 ///////////////////////////////////////
4701
4702 EINTERN void
4703 e_client_comp_hidden_set(E_Client *ec, Eina_Bool hidden)
4704 {
4705    E_OBJECT_CHECK(ec);
4706    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4707
4708    hidden = !!hidden;
4709    if (ec->comp_hidden == hidden) return;
4710    ec->comp_hidden = hidden;
4711    evas_object_smart_callback_call(ec->frame, "comp_hidden", NULL);
4712 }
4713
4714 ///////////////////////////////////////
4715
4716 EINTERN void
4717 e_client_act_move_keyboard(E_Client *ec)
4718 {
4719    EINA_SAFETY_ON_NULL_RETURN(ec);
4720
4721    if (!_e_client_move_begin(ec))
4722      return;
4723
4724    _e_client_action_init(ec);
4725    _e_client_action_move_timeout_add();
4726
4727    wl_signal_emit(&PRI(ec)->events.move_update, NULL);
4728    if (!_e_client_hook_call(E_CLIENT_HOOK_MOVE_UPDATE, ec)) return;
4729    evas_object_freeze_events_set(ec->frame, 1);
4730
4731    if (!action_handler_mouse)
4732      action_handler_mouse = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, _e_client_move_mouse_down, NULL);
4733 }
4734
4735 EINTERN void
4736 e_client_act_resize_keyboard(E_Client *ec)
4737 {
4738    EINA_SAFETY_ON_NULL_RETURN(ec);
4739
4740    ec->resize_mode = E_POINTER_RESIZE_TL;
4741    ec->keyboard_resizing = 1;
4742    if (!e_client_resize_begin(ec))
4743      {
4744         ec->keyboard_resizing = 0;
4745         return;
4746      }
4747
4748    _e_client_action_init(ec);
4749    _e_client_action_resize_timeout_add();
4750    evas_object_freeze_events_set(ec->frame, 1);
4751
4752    if (!action_handler_mouse)
4753      action_handler_mouse = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, _e_client_resize_mouse_down, NULL);
4754 }
4755
4756 EINTERN void
4757 e_client_act_move_begin(E_Client *ec, E_Binding_Event_Mouse_Button *ev)
4758 {
4759    E_OBJECT_CHECK(ec);
4760    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4761    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4762    if (ev)
4763      {
4764         char source[256];
4765
4766         snprintf(source, sizeof(source) - 1, "mouse,down,%i", ev->button);
4767         _e_client_moveinfo_gather(ec, source);
4768      }
4769    if (!_e_client_move_begin(ec))
4770      return;
4771
4772    _e_client_action_init(ec);
4773 }
4774
4775 E_API void
4776 e_client_act_move_end(E_Client *ec, E_Binding_Event_Mouse_Button *ev EINA_UNUSED)
4777 {
4778    E_OBJECT_CHECK(ec);
4779    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4780    if (!ec->moving) return;
4781    _e_client_move_end(ec);
4782    _e_client_action_finish();
4783 }
4784
4785 EINTERN void
4786 e_client_act_resize_begin(E_Client *ec, E_Binding_Event_Mouse_Button *ev, E_Pointer_Mode resize_mode)
4787 {
4788    E_OBJECT_CHECK(ec);
4789    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4790    if (ec->lock_user_size) return;
4791    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4792    if (ev)
4793      {
4794         char source[256];
4795         snprintf(source, sizeof(source) - 1, "mouse,down,%i", ev->button);
4796         _e_client_moveinfo_gather(ec, source);
4797
4798         if (resize_mode != E_POINTER_RESIZE_NONE)
4799           {
4800              ec->resize_mode = resize_mode;
4801           }
4802         else
4803           {
4804              /* Use canvas.x, canvas.y of event.
4805               * Transformed coordinates has to be considered for accurate resize_mode
4806               * rather than absolute coordinates. */
4807              if ((ev->canvas.x > (ec->x + ec->w / 5)) &&
4808                  (ev->canvas.x < (ec->x + ec->w * 4 / 5)))
4809                {
4810                   if (ev->canvas.y < (ec->y + ec->h / 2)) ec->resize_mode = E_POINTER_RESIZE_T;
4811                   else ec->resize_mode = E_POINTER_RESIZE_B;
4812                }
4813              else if (ev->canvas.x < (ec->x + ec->w / 2))
4814                {
4815                   if ((ev->canvas.y > (ec->y + ec->h / 5)) && (ev->canvas.y < (ec->y + ec->h * 4 / 5))) ec->resize_mode = E_POINTER_RESIZE_L;
4816                   else if (ev->canvas.y < (ec->y + ec->h / 2)) ec->resize_mode = E_POINTER_RESIZE_TL;
4817                   else ec->resize_mode = E_POINTER_RESIZE_BL;
4818                }
4819              else
4820                {
4821                   if ((ev->canvas.y > (ec->y + ec->h / 5)) && (ev->canvas.y < (ec->y + ec->h * 4 / 5))) ec->resize_mode = E_POINTER_RESIZE_R;
4822                   else if (ev->canvas.y < (ec->y + ec->h / 2)) ec->resize_mode = E_POINTER_RESIZE_TR;
4823                   else ec->resize_mode = E_POINTER_RESIZE_BR;
4824                }
4825           }
4826      }
4827    if (!e_client_resize_begin(ec))
4828      return;
4829    _e_client_action_init(ec);
4830 }
4831
4832 EINTERN void
4833 e_client_act_resize_end(E_Client *ec, E_Binding_Event_Mouse_Button *ev EINA_UNUSED)
4834 {
4835    E_OBJECT_CHECK(ec);
4836    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4837    if (e_client_util_resizing_get(ec))
4838      {
4839         _e_client_resize_end(ec);
4840         ec->changes.reset_gravity = 1;
4841         if (!e_object_is_del(E_OBJECT(ec)))
4842           EC_CHANGED(ec);
4843      }
4844    _e_client_action_finish();
4845 }
4846
4847 EINTERN void
4848 e_client_act_menu_begin(E_Client *ec, E_Binding_Event_Mouse_Button *ev, int key)
4849 {
4850    E_OBJECT_CHECK(ec);
4851    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4852 }
4853
4854 EINTERN void
4855 e_client_act_close_begin(E_Client *ec)
4856 {
4857    E_OBJECT_CHECK(ec);
4858    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4859    if (ec->lock_close) return;
4860    if (ec->icccm.delete_request)
4861      {
4862         ec->delete_requested = 1;
4863         evas_object_smart_callback_call(ec->frame, "delete_request", NULL);
4864      }
4865    else if (e_config->kill_if_close_not_possible)
4866      {
4867         e_client_act_kill_begin(ec);
4868      }
4869 }
4870
4871 EINTERN void
4872 e_client_act_kill_begin(E_Client *ec)
4873 {
4874    E_OBJECT_CHECK(ec);
4875    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4876    if (ec->internal) return;
4877    if (ec->lock_close) return;
4878    if ((ec->netwm.pid > 1) && (e_config->kill_process))
4879      {
4880         kill(ec->netwm.pid, SIGINT);
4881         ec->kill_timer = ecore_timer_add(e_config->kill_timer_wait,
4882                                          _e_client_cb_kill_timer, ec);
4883      }
4884    else
4885      evas_object_smart_callback_call(ec->frame, "kill_request", NULL);
4886 }
4887
4888 ////////////////////////////////////////////
4889
4890 EINTERN void
4891 e_client_ping(E_Client *ec)
4892 {
4893    E_OBJECT_CHECK(ec);
4894    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4895
4896    if (!e_config->ping_clients) return;
4897
4898    EINA_SAFETY_ON_TRUE_RETURN(e_object_is_del(E_OBJECT(ec)));
4899
4900    ec->ping_ok = 0;
4901    evas_object_smart_callback_call(ec->frame, "ping", NULL);
4902    ec->ping = ecore_loop_time_get();
4903    if (ec->ping_poller) ecore_poller_del(ec->ping_poller);
4904    ec->ping_poller = ecore_poller_add(ECORE_POLLER_CORE,
4905                                       e_config->ping_clients_interval,
4906                                       _e_client_cb_ping_poller, ec);
4907 }
4908
4909 ////////////////////////////////////////////
4910 E_API void
4911 e_client_cursor_map_apply(E_Client *ec, int rotation, int x, int y)
4912 {
4913    // TODO: remove(deprecate) this e_client_cursor_map_apply.
4914 }
4915
4916 EINTERN void
4917 e_client_move_cancel(void)
4918 {
4919    if (!ecmove) return;
4920    if (ecmove->cur_mouse_action)
4921      {
4922         E_Client *ec;
4923
4924         ec = ecmove;
4925         e_object_ref(E_OBJECT(ec));
4926         if (ec->cur_mouse_action->func.end_mouse)
4927           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", NULL);
4928         else if (ec->cur_mouse_action->func.end)
4929           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
4930         e_object_unref(E_OBJECT(ec->cur_mouse_action));
4931         ec->cur_mouse_action = NULL;
4932         e_object_unref(E_OBJECT(ec));
4933      }
4934    else
4935      _e_client_move_end(ecmove);
4936 }
4937
4938 EINTERN void
4939 e_client_resize_cancel(void)
4940 {
4941    if (!ecresize) return;
4942    if (ecresize->cur_mouse_action)
4943      {
4944         E_Client *ec;
4945
4946         ec = ecresize;
4947         e_object_ref(E_OBJECT(ec));
4948         if (ec->cur_mouse_action->func.end_mouse)
4949           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", NULL);
4950         else if (ec->cur_mouse_action->func.end)
4951           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
4952         e_object_unref(E_OBJECT(ec->cur_mouse_action));
4953         ec->cur_mouse_action = NULL;
4954         e_object_unref(E_OBJECT(ec));
4955      }
4956    else
4957      _e_client_resize_end(ecresize);
4958 }
4959
4960 EINTERN Eina_Bool
4961 e_client_resize_begin(E_Client *ec)
4962 {
4963    if ((ec->fullscreen) || (ec->lock_user_size))
4964      goto error;
4965    if (!_e_client_action_input_win_new()) goto error;
4966    ecresize = ec;
4967    if (ec->manage_resize.enable_aspect_ratio)
4968      {
4969         ELOGF("RESIZE", "Set resize aspect ratio.. ratio(%dx%d)", ec, ec->w, ec->h);
4970         ec->manage_resize.aw = ec->w;
4971         ec->manage_resize.ah = ec->h - ec->manage_resize.header_h - ec->manage_resize.footer_h;
4972      }
4973
4974    wl_signal_emit(&PRI(ec)->events.move_begin, NULL);
4975    _e_client_hook_call(E_CLIENT_HOOK_RESIZE_BEGIN, ec);
4976    if (ec->transformed)
4977      _e_client_transform_resize_begin(ec);
4978    if (!e_client_util_resizing_get(ec))
4979      {
4980         if (ecresize == ec) ecresize = NULL;
4981         _e_client_action_input_win_del();
4982         return EINA_FALSE;
4983      }
4984    if (!ec->lock_user_stacking)
4985      {
4986         if (e_config->border_raise_on_mouse_action)
4987           e_client_raise(ec);
4988      }
4989
4990    if (e_comp->hwc)
4991      e_comp_client_override_add(ec);
4992
4993    return EINA_TRUE;
4994 error:
4995    ec->resize_mode = E_POINTER_RESIZE_NONE;
4996    return EINA_FALSE;
4997 }
4998
4999
5000 ////////////////////////////////////////////
5001
5002 EINTERN void
5003 e_client_frame_recalc(E_Client *ec)
5004 {
5005    EINA_SAFETY_ON_NULL_RETURN(ec);
5006    if (!ec->frame) return;
5007    evas_object_smart_callback_call(ec->frame, "frame_recalc", NULL);
5008 }
5009
5010 ////////////////////////////////////////////
5011
5012 EINTERN void
5013 e_client_signal_move_begin(E_Client *ec, const char *sig, const char *src EINA_UNUSED)
5014 {
5015    E_OBJECT_CHECK(ec);
5016    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
5017
5018    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
5019    _e_client_moveinfo_gather(ec, sig);
5020    if (!_e_client_move_begin(ec)) return;
5021 }
5022
5023 EINTERN void
5024 e_client_signal_move_end(E_Client *ec, const char *sig EINA_UNUSED, const char *src EINA_UNUSED)
5025 {
5026    E_OBJECT_CHECK(ec);
5027    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
5028    if (!ec->moving) return;
5029    _e_client_move_end(ec);
5030 }
5031
5032 EINTERN void
5033 e_client_signal_resize_begin(E_Client *ec, const char *dir, const char *sig, const char *src EINA_UNUSED)
5034 {
5035    int resize_mode = E_POINTER_RESIZE_BR;
5036
5037    E_OBJECT_CHECK(ec);
5038    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
5039
5040    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
5041    if (!strcmp(dir, "tl"))
5042      {
5043         resize_mode = E_POINTER_RESIZE_TL;
5044      }
5045    else if (!strcmp(dir, "t"))
5046      {
5047         resize_mode = E_POINTER_RESIZE_T;
5048      }
5049    else if (!strcmp(dir, "tr"))
5050      {
5051         resize_mode = E_POINTER_RESIZE_TR;
5052      }
5053    else if (!strcmp(dir, "r"))
5054      {
5055         resize_mode = E_POINTER_RESIZE_R;
5056      }
5057    else if (!strcmp(dir, "br"))
5058      {
5059         resize_mode = E_POINTER_RESIZE_BR;
5060      }
5061    else if (!strcmp(dir, "b"))
5062      {
5063         resize_mode = E_POINTER_RESIZE_B;
5064      }
5065    else if (!strcmp(dir, "bl"))
5066      {
5067         resize_mode = E_POINTER_RESIZE_BL;
5068      }
5069    else if (!strcmp(dir, "l"))
5070      {
5071         resize_mode = E_POINTER_RESIZE_L;
5072      }
5073    ec->resize_mode = resize_mode;
5074    _e_client_moveinfo_gather(ec, sig);
5075    if (!e_client_resize_begin(ec))
5076      return;
5077 }
5078
5079 EINTERN void
5080 e_client_signal_resize_end(E_Client *ec, const char *dir EINA_UNUSED, const char *sig EINA_UNUSED, const char *src EINA_UNUSED)
5081 {
5082    E_OBJECT_CHECK(ec);
5083    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
5084    if (!e_client_util_resizing_get(ec)) return;
5085    _e_client_resize_handle(ec);
5086    _e_client_resize_end(ec);
5087    ec->changes.reset_gravity = 1;
5088    EC_CHANGED(ec);
5089 }
5090
5091 ////////////////////////////////////////////
5092
5093 EINTERN void
5094 e_client_resize_limit(E_Client *ec, int *w, int *h)
5095 {
5096    E_OBJECT_CHECK(ec);
5097    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
5098
5099    if (ec->frame)
5100      e_comp_object_frame_wh_unadjust(ec->frame, *w, *h, w, h);
5101    if (*h < 1) *h = 1;
5102    if (*w < 1) *w = 1;
5103
5104    if ((ec->icccm.max_w > 0) && (*w > ec->icccm.max_w)) *w = ec->icccm.max_w;
5105    else if (*w < ec->icccm.min_w)
5106      *w = ec->icccm.min_w;
5107    if ((ec->icccm.max_h > 0) && (*h > ec->icccm.max_h)) *h = ec->icccm.max_h;
5108    else if (*h < ec->icccm.min_h)
5109      *h = ec->icccm.min_h;
5110
5111    if (ec->frame)
5112      e_comp_object_frame_wh_adjust(ec->frame, *w, *h, w, h);
5113 }
5114
5115 ////////////////////////////////////////////
5116
5117
5118
5119 EINTERN E_Client *
5120 e_client_under_pointer_get(E_Desk *desk, E_Client *exclude)
5121 {
5122    int x, y;
5123
5124    /* We need to ensure that we can get the comp window for the
5125     * zone of either the given desk or the desk of the excluded
5126     * window, so return if neither is given */
5127    if (desk)
5128      e_input_device_pointer_xy_get(NULL, &x, &y);
5129    else if (exclude)
5130      e_input_device_pointer_xy_get(NULL, &x, &y);
5131    else
5132      return NULL;
5133
5134    if (!desk)
5135      {
5136         desk = exclude->desk;
5137         if (!desk)
5138           {
5139              if (exclude->zone)
5140                desk = e_desk_current_get(exclude->zone);
5141              else
5142                desk = e_desk_current_get(e_zone_current_get());
5143           }
5144      }
5145
5146    return desk ? _e_client_under_pointer_helper(desk, exclude, x, y) : NULL;
5147 }
5148
5149 E_API E_Client *e_client_under_position_get(E_Desk *desk, int x, int y, E_Client *exclude)
5150 {
5151    if (!desk) return NULL;
5152
5153    return _e_client_under_pointer_helper(desk, exclude, x, y);
5154 }
5155
5156 E_API E_Client *e_client_under_position_input_get(E_Desk *desk, int x, int y)
5157 {
5158    if (!desk) return NULL;
5159
5160    return _e_client_under_pointer_input_helper(desk, x, y);
5161 }
5162
5163 ////////////////////////////////////////////
5164
5165 ////////////////////////////////////////////
5166
5167 E_API void
5168 e_client_redirected_set(E_Client *ec, Eina_Bool set)
5169 {
5170    EINA_SAFETY_ON_NULL_RETURN(ec);
5171    if (ec->input_only) return;
5172    set = !!set;
5173    if (ec->redirected == set) return;
5174    if (set)
5175      {
5176         e_client_frame_recalc(ec);
5177
5178         wl_signal_emit(&PRI(ec)->events.redirect, NULL);
5179         if (!_e_client_hook_call(E_CLIENT_HOOK_REDIRECT, ec)) return;
5180      }
5181    else
5182      {
5183         wl_signal_emit(&PRI(ec)->events.unredirect, NULL);
5184         if (!_e_client_hook_call(E_CLIENT_HOOK_UNREDIRECT, ec)) return;
5185      }
5186    e_comp_object_redirected_set(ec->frame, set);
5187    ec->redirected = !!set;
5188 }
5189
5190 ////////////////////////////////////////////
5191
5192 E_API void
5193 e_client_transform_update(E_Client *ec)
5194 {
5195    if (e_client_util_resizing_get(ec))
5196      _e_client_transform_resize(ec);
5197 }
5198
5199 ////////////////////////////////////////////
5200
5201 EINTERN void
5202 e_client_transform_apply(E_Client *ec, double angle, double zoom, int cx, int cy)
5203 {
5204    E_Map *map;
5205    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
5206    E_Client *subc;
5207    Eina_List *l;
5208
5209    if (e_comp_wl_subsurface_check(ec))
5210      return;
5211
5212    /* check if it's different with current state */
5213    if ((ec->transform.angle == angle) &&
5214        (ec->transform.zoom == zoom) &&
5215        (ec->transform.center.x == cx) &&
5216        (ec->transform.center.y == cy))
5217      return;
5218
5219    /* use previous value if any required value is invalid */
5220    if (angle == -1.0)
5221      angle = ec->transform.angle;
5222    if (zoom == -1.0)
5223      zoom = ec->transform.zoom;
5224    if (!E_INSIDE(cx, cy,
5225                  ec->client.x, ec->client.y,
5226                  ec->client.w, ec->client.h))
5227      {
5228         cx = ec->transform.center.x;
5229         cy = ec->transform.center.y;
5230      }
5231
5232    if ((angle == 0) && (zoom == 1.0))
5233      {
5234         e_client_transform_clear(ec);
5235         return;
5236      }
5237
5238    map = e_map_new_with_direct_render(ec->transform_core.direct_render);
5239    e_map_util_points_populate_from_object_full(map, ec->frame, 0);
5240
5241    e_map_util_rotate(map, angle, cx, cy);
5242    _e_client_transform_geometry_save(ec, map);
5243
5244    e_map_util_zoom(map, zoom, zoom, cx, cy);
5245
5246    e_map_util_object_move_sync_set(map, EINA_TRUE);
5247    e_client_map_set(ec, map);
5248    e_client_map_enable_set(ec, EINA_TRUE);
5249
5250    EINA_LIST_FOREACH(cdata->sub.list, l, subc)
5251      _e_client_transform_sub_apply(subc, ec, zoom);
5252    EINA_LIST_REVERSE_FOREACH(cdata->sub.below_list, l, subc)
5253      _e_client_transform_sub_apply(subc, ec, zoom);
5254
5255    e_map_free(map);
5256
5257    ec->transform.zoom = zoom;
5258    ec->transform.angle = angle;
5259    ec->transform.center.x = cx;
5260    ec->transform.center.y = cy;
5261    ec->transformed = EINA_TRUE;
5262 }
5263
5264 ////////////////////////////////////////////
5265
5266 EINTERN void
5267 e_client_transform_clear(E_Client *ec)
5268 {
5269    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
5270    E_Client *subc;
5271    Eina_List *l;
5272
5273    e_client_map_enable_set(ec, EINA_FALSE);
5274    e_client_map_set(ec, NULL);
5275
5276    EINA_LIST_FOREACH(cdata->sub.list, l, subc)
5277      _e_client_transform_sub_apply(subc, ec, 1.0);
5278    EINA_LIST_REVERSE_FOREACH(cdata->sub.below_list, l, subc)
5279      _e_client_transform_sub_apply(subc, ec, 1.0);
5280
5281    ec->transform.zoom = 1.0;
5282    ec->transform.angle = 0.0;
5283    ec->transformed = EINA_FALSE;
5284 }
5285
5286 E_API Eina_Bool
5287 e_client_transform_core_enable_get(E_Client *ec)
5288 {
5289    if (!ec) return EINA_FALSE;
5290    return ec->transform_core.result.enable;
5291 }
5292
5293 E_API void
5294 e_client_transform_core_add(E_Client *ec, E_Util_Transform *transform)
5295 {
5296    if (!ec) return;
5297    if (!transform) return;
5298
5299    // duplication check
5300    if (ec->transform_core.transform_list &&
5301        eina_list_data_find(ec->transform_core.transform_list, transform) == transform)
5302      {
5303         return;
5304      }
5305
5306    ec->transform_core.transform_list = eina_list_append(ec->transform_core.transform_list, transform);
5307    ec->transform_core.changed = EINA_TRUE;
5308    e_util_transform_ref(transform);
5309   // e_client_transform_core_update(ec);
5310 }
5311
5312 E_API void
5313 e_client_transform_core_remove(E_Client *ec, E_Util_Transform *transform)
5314 {
5315    if (!ec) return;
5316    if (!transform) return;
5317
5318    if (ec->transform_core.transform_list &&
5319        eina_list_data_find(ec->transform_core.transform_list, transform) == transform)
5320      {
5321         ec->transform_core.transform_list = eina_list_remove(ec->transform_core.transform_list, transform);
5322         e_util_transform_unref(transform);
5323         ec->transform_core.changed = EINA_TRUE;
5324      }
5325
5326    e_client_transform_core_update(ec);
5327 }
5328
5329 E_API void
5330 e_client_transform_core_update(E_Client *ec)
5331 {
5332    if (!ec) return;
5333    if (ec->new_client) return;
5334    if (!_e_client_transform_core_check_change(ec)) return;
5335
5336    if (ec->transform_core.transform_list || ec->transform_core.parent.enable)
5337      {
5338         E_Util_Transform_Rect source_rect;
5339         E_Util_Transform_Matrix matrix, boundary_matrix;
5340         E_Util_Transform_Zoom zoom;
5341         Eina_List *l;
5342         Eina_Bool background;
5343         E_Util_Transform *temp_trans;
5344
5345         // 1. init state
5346         ec->transform_core.result.enable = EINA_TRUE;
5347         e_util_transform_rect_client_rect_get(&source_rect, ec);
5348         e_util_transform_init(&ec->transform_core.result.transform);
5349
5350         // 2. merge transform
5351         EINA_LIST_FOREACH(ec->transform_core.transform_list, l, temp_trans)
5352           {
5353              e_util_transform_merge(&ec->transform_core.result.transform, temp_trans);
5354           }
5355         zoom = ec->transform_core.result.transform.zoom;
5356
5357         // 2.5 check viewport
5358         if (e_util_transform_viewport_flag_get(&ec->transform_core.result.transform))
5359           {
5360              int vx = 0, vy = 0, vw = 0, vh = 0;
5361              e_util_transform_viewport_get(&ec->transform_core.result.transform, &vx, &vy, &vw, &vh);
5362              e_util_transform_rect_init(&source_rect, vx, vy, vw, vh);
5363           }
5364
5365         // 3. apply background transform
5366         matrix = e_util_transform_convert_to_matrix(&ec->transform_core.result.transform, &source_rect);
5367
5368         if (e_util_transform_bg_transform_flag_get(&ec->transform_core.result.transform))
5369           {
5370              boundary_matrix = e_util_transform_bg_convert_to_matrix(&ec->transform_core.result.transform, &source_rect);
5371              background = EINA_TRUE;
5372           }
5373         else
5374           {
5375              background = EINA_FALSE;
5376              boundary_matrix = matrix;
5377           }
5378
5379         if (background != ec->transform_core.background)
5380           {
5381              if (background)
5382                {
5383                   e_comp_object_transform_bg_set(ec->frame, EINA_TRUE);
5384                }
5385              else
5386                {
5387                   e_comp_object_transform_bg_set(ec->frame, EINA_FALSE);
5388                }
5389
5390              ec->transform_core.background = background;
5391           }
5392
5393         // 3.1 if 24bit window then set transp rect
5394         if (!ec->argb)
5395           {
5396              int angle = 0;
5397
5398              e_util_transform_rotation_round_get(&ec->transform_core.result.transform, 0, 0, &angle);
5399              angle %= 90;
5400
5401              if (angle == 0) // when transform angle is 0, 90, 180, 270, 360. then set transp rect
5402                e_comp_object_transform_transp_set(ec->frame, EINA_TRUE);
5403              else
5404                e_comp_object_transform_transp_set(ec->frame, EINA_FALSE);
5405           }
5406         else
5407           e_comp_object_transform_transp_set(ec->frame, EINA_FALSE);
5408
5409         // 3.5 parent matrix multiply
5410         if (ec->transform_core.parent.enable)
5411           {
5412              matrix = e_util_transform_matrix_multiply(&ec->transform_core.parent.matrix,
5413                                                        &matrix);
5414              boundary_matrix = e_util_transform_matrix_multiply(&ec->transform_core.parent.matrix,
5415                                                                 &boundary_matrix);
5416
5417              ec->transform_core.result.transform.use_zoom = EINA_TRUE;
5418              zoom.zoom_x *= ec->transform_core.parent.zoom.zoom_x;
5419              zoom.zoom_y *= ec->transform_core.parent.zoom.zoom_y;
5420              zoom.cx += ec->transform_core.parent.zoom.cx;
5421              zoom.cy += ec->transform_core.parent.zoom.cy;
5422           }
5423
5424         // 4. apply matrix to vertices
5425         ec->transform_core.result.matrix = matrix;
5426         ec->transform_core.result.inv_matrix = e_util_transform_matrix_inverse_get(&matrix);
5427         ec->transform_core.result.vertices = e_util_transform_rect_to_vertices(&source_rect);
5428         ec->transform_core.result.boundary.vertices = e_util_transform_rect_to_vertices(&source_rect);
5429         ec->transform_core.result.vertices = e_util_transform_matrix_multiply_rect_vertex(&matrix,
5430                                                                                           &ec->transform_core.result.vertices);
5431         ec->transform_core.result.boundary.vertices = e_util_transform_matrix_multiply_rect_vertex(&boundary_matrix,
5432                                                                                                    &ec->transform_core.result.boundary.vertices);
5433         ec->transform_core.result.transform.zoom = zoom;
5434
5435         // 5. apply vertices
5436         if (ec->transform_core.result.transform.use_zoom)
5437           {
5438              // TODO: apply zoom values to vertices
5439              e_comp_object_transform_transp_vertices_set_with_zoom(ec->frame, &ec->transform_core.result.vertices,
5440                                                                    ec->transform_core.result.transform.zoom);
5441              e_comp_object_transform_bg_vertices_set_with_zoom(ec->frame, &ec->transform_core.result.boundary.vertices,
5442                                                                ec->transform_core.result.transform.zoom);
5443              _e_client_transform_core_boundary_update(ec, &ec->transform_core.result.boundary.vertices);
5444              _e_client_transform_core_vertices_apply_with_zoom(ec, ec->frame, &ec->transform_core.result.vertices, &ec->transform_core.result.transform,
5445                                                                ec->transform_core.result.transform.zoom);
5446           }
5447         else
5448           {
5449              e_comp_object_transform_transp_vertices_set(ec->frame, &ec->transform_core.result.vertices);
5450              e_comp_object_transform_bg_vertices_set(ec->frame, &ec->transform_core.result.boundary.vertices);
5451              _e_client_transform_core_boundary_update(ec, &ec->transform_core.result.boundary.vertices);
5452              _e_client_transform_core_vertices_apply(ec, ec->frame, &ec->transform_core.result.vertices, &ec->transform_core.result.transform);
5453           }
5454
5455         // 6. subsurface update
5456         _e_client_transform_core_sub_update(ec, &ec->transform_core.result.vertices);
5457
5458         if (!e_object_is_del(E_OBJECT(ec)))
5459           {
5460              wl_signal_emit(&PRI(ec)->events.transform_change, NULL);
5461              _e_client_hook_call(E_CLIENT_HOOK_TRANSFORM_CHANGE, ec);
5462           }
5463      }
5464    else
5465      {
5466         if (ec->transform_core.result.enable)
5467           {
5468              ec->transform_core.result.enable = EINA_FALSE;
5469              _e_client_transform_core_vertices_apply(ec, ec->frame, NULL, NULL);
5470              e_comp_object_transform_bg_set(ec->frame, EINA_FALSE);
5471              ec->transform_core.background = EINA_FALSE;
5472              e_comp_object_transform_transp_set(ec->frame, EINA_FALSE);
5473              _e_client_transform_core_sub_update(ec, NULL);
5474
5475              if (!e_object_is_del(E_OBJECT(ec)))
5476                {
5477                   wl_signal_emit(&PRI(ec)->events.transform_change, NULL);
5478                   _e_client_hook_call(E_CLIENT_HOOK_TRANSFORM_CHANGE, ec);
5479                }
5480           }
5481      }
5482
5483    e_comp_visibility_calculation_set(EINA_TRUE);
5484 }
5485
5486 E_API int
5487 e_client_transform_core_transform_count_get(E_Client *ec)
5488 {
5489    if (!ec) return 0;
5490    if (!ec->transform_core.transform_list) return 0;
5491    return eina_list_count(ec->transform_core.transform_list);
5492 }
5493
5494 E_API E_Util_Transform*
5495 e_client_transform_core_transform_get(E_Client *ec, int index)
5496 {
5497    if (!ec) return NULL;
5498    if (!ec->transform_core.transform_list) return NULL;
5499    if (index < 0 || index >= e_client_transform_core_transform_count_get(ec))
5500       return NULL;
5501
5502    return (E_Util_Transform*)eina_list_nth(ec->transform_core.transform_list, index);
5503 }
5504
5505 E_API void
5506 e_client_transform_core_input_transform(E_Client *ec, int x, int y, int *out_x, int *out_y)
5507 {
5508    E_Util_Transform_Vertex vertex, result_vertex;
5509
5510    if (!ec) return;
5511    if (!e_client_transform_core_enable_get(ec)) return;
5512
5513    e_util_transform_vertex_init(&vertex, x, y, 0.0, 1.0);
5514
5515    result_vertex = e_util_transform_matrix_multiply_vertex(&ec->transform_core.result.inv_matrix, &vertex);
5516    e_util_transform_vertex_pos_round_get(&result_vertex, out_x, out_y, NULL, NULL);
5517 }
5518
5519 E_API void
5520 e_client_transform_core_input_inv_transform(E_Client *ec, int x, int y, int *out_x, int *out_y)
5521 {
5522    E_Util_Transform_Vertex vertex, result_vertex;
5523
5524    if (!ec) return;
5525    if (!e_client_transform_core_enable_get(ec)) return;
5526
5527    e_util_transform_vertex_init(&vertex, x, y, 0.0, 1.0);
5528
5529    result_vertex = e_util_transform_matrix_multiply_vertex(&ec->transform_core.result.matrix, &vertex);
5530    e_util_transform_vertex_pos_round_get(&result_vertex, out_x, out_y, NULL, NULL);
5531 }
5532
5533 EINTERN void
5534 e_client_transform_core_input_inv_rect_transform(E_Client *ec, int x, int y, int *out_x, int *out_y)
5535 {
5536    int gw = 0, gh = 0;
5537    if (!ec) return;
5538    if (!e_client_transform_core_enable_get(ec)) return;
5539    e_client_geometry_get(ec, NULL, NULL, &gw, &gh);
5540
5541    e_util_transform_matrix_inv_rect_coords_get(&ec->transform_core.result.transform,
5542                                                &ec->transform_core.result.vertices,
5543                                                gw, gh,
5544                                                x, y, out_x, out_y);
5545 }
5546
5547 E_API void
5548 e_client_transform_core_direct_render_set(E_Client *ec, Eina_Bool set)
5549 {
5550    EINA_SAFETY_ON_NULL_RETURN(ec);
5551
5552    if (ec->transform_core.direct_render == set) return;
5553
5554    ec->transform_core.direct_render = set;
5555    ec->transform_core.changed = EINA_TRUE;
5556
5557    e_client_transform_core_update(ec);
5558 }
5559
5560 EINTERN E_Pixmap *
5561 e_client_pixmap_change(E_Client *ec, E_Pixmap *newcp)
5562 {
5563    E_Pixmap_Type oldtype, newtype;
5564    E_Pixmap *oldcp;
5565
5566    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
5567    EINA_SAFETY_ON_NULL_RETURN_VAL(ec->pixmap, NULL);
5568    EINA_SAFETY_ON_NULL_RETURN_VAL(newcp, NULL);
5569
5570    oldcp = ec->pixmap;
5571
5572    oldtype = e_pixmap_type_get(oldcp);
5573    if (oldtype >= E_PIXMAP_TYPE_MAX) return NULL;
5574
5575    newtype = e_pixmap_type_get(newcp);
5576    if (newtype >= E_PIXMAP_TYPE_MAX) return NULL;
5577
5578    if (eina_hash_find(clients_hash[oldtype], &oldcp))
5579      eina_hash_del_by_key(clients_hash[oldtype], &oldcp);
5580    e_pixmap_client_set(oldcp, NULL);
5581
5582    ec->pixmap = newcp;
5583    e_pixmap_client_set(newcp, ec);
5584
5585    eina_hash_add(clients_hash[newtype], &newcp, ec);
5586
5587    return oldcp;
5588 }
5589
5590 E_API void
5591 e_client_window_role_set(E_Client *ec, const char *role)
5592 {
5593    EINA_SAFETY_ON_NULL_RETURN(ec);
5594
5595    if (eina_stringshare_replace(&ec->icccm.window_role, role))
5596      {
5597         wl_signal_emit(&PRI(ec)->events.window_role_change, NULL);
5598         _e_client_hook_call(E_CLIENT_HOOK_WINDOW_ROLE_CHANGE, ec);
5599      }
5600 }
5601
5602 EINTERN Eina_Bool
5603 e_client_key_send(E_Client *ec, int keycode, Eina_Bool pressed, Ecore_Device *dev, unsigned int time)
5604 {
5605    Eina_Bool res;
5606
5607    res = e_comp_wl_key_send(ec, keycode, pressed, dev, time);
5608
5609    return res;
5610 }
5611
5612 EINTERN Eina_Bool
5613 e_client_key_cancel(E_Client *ec, int keycode, Ecore_Device *dev, unsigned int time)
5614 {
5615    Eina_Bool res;
5616
5617    res = e_comp_wl_key_cancel(ec, keycode, dev, time);
5618
5619    return res;
5620 }
5621
5622 EINTERN Eina_Bool
5623 e_client_touch_send(E_Client *ec, int idx, int x, int y, Eina_Bool pressed, Ecore_Device *dev, double radius_x, double radius_y, double pressure, double angle, unsigned int time)
5624 {
5625    Eina_Bool res;
5626
5627    res = e_comp_wl_touch_send(ec, idx, x, y, pressed, dev, radius_x, radius_y, pressure, angle, time);
5628
5629    return res;
5630 }
5631
5632 EINTERN Eina_Bool
5633 e_client_touch_update_send(E_Client *ec, int idx, int x, int y, Ecore_Device *dev, double radius_x, double radius_y, double pressure, double angle, unsigned int time)
5634 {
5635    Eina_Bool res;
5636
5637    res = e_comp_wl_touch_update_send(ec, idx, x, y, dev, radius_x, radius_y, pressure, angle, time);
5638
5639    return res;
5640 }
5641
5642 EINTERN Eina_Bool
5643 e_client_touch_cancel_send(E_Client *ec)
5644 {
5645    Eina_Bool res;
5646
5647    res = e_comp_wl_touch_cancel_send(ec);
5648
5649    return res;
5650 }
5651
5652 EINTERN Eina_Bool
5653 e_client_mouse_button_send(E_Client *ec, int buttons, Eina_Bool pressed, Ecore_Device *dev, unsigned int time)
5654 {
5655    Eina_Bool res;
5656
5657    res = e_comp_wl_mouse_button_send(ec, buttons, pressed, dev, time);
5658
5659    return res;
5660 }
5661
5662 EINTERN Eina_Bool
5663 e_client_mouse_move_send(E_Client *ec, int x, int y, Ecore_Device *dev, unsigned int time)
5664 {
5665    Eina_Bool res;
5666
5667    res = e_comp_wl_mouse_move_send(ec, x, y, dev, time);
5668
5669    return res;
5670 }
5671
5672 EINTERN Eina_Bool
5673 e_client_mouse_wheel_send(E_Client *ec, int direction, int z, Ecore_Device *dev, unsigned int time)
5674 {
5675    Eina_Bool res;
5676
5677    res = e_comp_wl_mouse_wheel_send(ec, direction, z, dev, time);
5678
5679    return res;
5680 }
5681
5682 EINTERN Eina_Bool
5683 e_client_mouse_in_send(E_Client *ec, int x, int y, Ecore_Device *dev, unsigned int time)
5684 {
5685    Eina_Bool res;
5686
5687    res = e_comp_wl_mouse_in_send(ec, x, y, dev, time);
5688
5689    return res;
5690 }
5691
5692 EINTERN Eina_Bool
5693 e_client_mouse_out_send(E_Client *ec, Ecore_Device *dev, unsigned int time)
5694 {
5695    Eina_Bool res;
5696
5697    res = e_comp_wl_mouse_out_send(ec, dev, time);
5698
5699    return res;
5700 }
5701
5702 E_API Eina_Bool
5703 e_client_video_client_has(E_Client *ec)
5704 {
5705    return e_comp_wl_video_subsurface_has(ec);
5706 }
5707
5708 E_API Eina_Bool
5709 e_client_normal_client_has(E_Client *ec)
5710 {
5711    return e_comp_wl_normal_subsurface_has(ec);
5712 }
5713
5714 E_API Eina_Bool
5715 e_client_cursor_hide(E_Client *ec)
5716 {
5717    return e_comp_wl_cursor_hide(ec);
5718 }
5719
5720 E_API void
5721 e_client_visibility_force_obscured_set(E_Client *ec, Eina_Bool set)
5722 {
5723    if (!ec) return;
5724
5725    ELOGF("TZVIS", "VIS_FORCE_OBSCURED :%d", ec, set);
5726
5727    ec->visibility.force_obscured = set;
5728    e_comp_visibility_calculation_set(EINA_TRUE);
5729 }
5730
5731 EINTERN E_Capture_Save_State
5732 e_client_image_save(E_Client *ec, const char *dir, const char *name, E_Capture_Client_Save_End_Cb func_end, void *data, Eina_Bool skip_child)
5733 {
5734    return e_comp_wl_capture_client_image_save(ec, dir, name, func_end, data, skip_child);
5735 }
5736
5737 static void
5738 _e_client_base_output_resolution_hook_subsurf_create(void *data, E_Client *subc)
5739 {
5740    E_Client *ec, *parent;
5741
5742    ec = data;
5743    if (ec != subc)
5744      return;
5745
5746    ec->base_output_resolution.use = 0;
5747    ec->base_output_resolution.w = 0;
5748    ec->base_output_resolution.h = 0;
5749    if (ec->base_output_resolution.transform)
5750      {
5751         e_client_transform_core_remove(ec, ec->base_output_resolution.transform);
5752         E_FREE_FUNC(ec->base_output_resolution.transform, e_util_transform_del);
5753         ELOGF("POL_APPINFO", "Cancel TRANSFORM for subsurface", ec);
5754      }
5755
5756    /* Update transform for toplevel surface.
5757     * The transform of subsurface will be updated by its parent accordingly. */
5758    parent = e_comp_wl_topmost_parent_get(ec);
5759    if (parent)
5760      {
5761         parent->transform_core.changed = EINA_TRUE;
5762         e_client_transform_core_update(parent);
5763      }
5764
5765    /* TODO: Do we need to apply it again if subsurface is destroyed? */
5766 }
5767
5768 static void
5769 _e_client_base_output_resolution_set(E_Client *ec, int width, int height)
5770 {
5771    if (!ec) return;
5772    ec->base_output_resolution.use = 1;
5773    ec->base_output_resolution.w = width;
5774    ec->base_output_resolution.h = height;
5775    ec->base_output_resolution.transform = e_util_transform_new();
5776    e_util_transform_role_set(ec->base_output_resolution.transform, "base_output_resolution");
5777    e_client_transform_core_add(ec, ec->base_output_resolution.transform);
5778
5779    if (!ec->base_output_resolution.hook_subsurf_create)
5780      {
5781         ec->base_output_resolution.hook_subsurf_create =
5782            e_comp_wl_hook_add(E_COMP_WL_HOOK_SUBSURFACE_CREATE,
5783                               _e_client_base_output_resolution_hook_subsurf_create,
5784                               ec);
5785      }
5786 }
5787
5788 E_API void
5789 e_client_base_output_resolution_transform_adjust(E_Client *ec)
5790 {
5791    E_Desk *desk;
5792
5793    EINA_SAFETY_ON_NULL_RETURN(ec);
5794    if (!ec->base_output_resolution.use) return;
5795    if (!ec->base_output_resolution.transform) return;
5796
5797    desk = e_comp_desk_find_by_ec(ec);
5798    EINA_SAFETY_ON_NULL_RETURN(desk);
5799
5800    ELOGF("POL_APPINFO", "Apply TRANSFORM... desk:(%dx%d), ec:(%dx%d)",
5801          ec, desk->geom.w, desk->geom.h, ec->w, ec->h);
5802
5803    e_util_transform_scale(ec->base_output_resolution.transform,
5804                           (double)desk->geom.w /(double)ec->base_output_resolution.w,
5805                           (double)desk->geom.h /(double)ec->base_output_resolution.h,
5806                           1.0);
5807    e_client_transform_core_update(ec);
5808 }
5809
5810 E_API Eina_Bool
5811 e_client_base_output_resolution_update(E_Client *ec)
5812 {
5813    E_Appinfo *eai = NULL;
5814    int configured_width, configured_height;
5815    int width, height;
5816    E_Desk *desk;
5817
5818    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
5819
5820   if (!e_config->configured_output_resolution.use) return EINA_TRUE;
5821   if (ec->base_output_resolution.use) return EINA_TRUE;
5822
5823   /* Check whether it's subsurface or not
5824    * The resolution of subsurface will follow the resolution of its toplevel surface.
5825    * Transform for subsurface will be applied when toplevel surface does by
5826    * implementation of e_client_transform_core.
5827    */
5828   if (e_comp_wl_subsurface_check(ec))
5829     return EINA_FALSE;
5830
5831    desk = e_comp_desk_find_by_ec(ec);
5832    EINA_SAFETY_ON_NULL_RETURN_VAL(desk, EINA_FALSE);
5833
5834   configured_width = e_config->configured_output_resolution.w;
5835   configured_height = e_config->configured_output_resolution.h;
5836
5837   if (!ec->netwm.pid)
5838     {
5839        ELOGF("POL_APPINFO", "NO PID... USE configured_output_resolution(%d,%d) pid:%d", ec,
5840              configured_width, configured_height, ec->netwm.pid);
5841        goto use_configured;
5842     }
5843
5844    eai = e_appinfo_find_with_pid(ec->netwm.pid);
5845    if (!eai)
5846      {
5847         ELOGF("POL_APPINFO", "NO APPINFO... USE configured_output_resolution(%d,%d) pid:%d", ec,
5848               configured_width, configured_height, ec->netwm.pid);
5849         goto use_configured;
5850      }
5851
5852    if (!e_appinfo_base_output_resolution_available_get(eai))
5853      {
5854         ELOGF("POL_APPINFO", "NO AVAILABLE BASE SCREEN RESOLUTION... QUERY base_output_resolution", ec);
5855         e_policy_base_output_resolution_info_update(ec->netwm.pid);
5856      }
5857
5858    if (!e_appinfo_base_output_resolution_get(eai, &width, &height))
5859      {
5860         ELOGF("POL_APPINFO", "NO BASE SCREEN RESOLUTION... USE configured_output_resolution(%d,%d) pid:%d", ec,
5861               configured_width, configured_height, ec->netwm.pid);
5862         goto use_configured;
5863       }
5864
5865    if ((width == 0) && (height == 0))
5866      {
5867         ELOGF("POL_APPINFO", "SKIP SET BASE SCREEN RESOLUTION... base_output_resolution size:(%d,%d) pid:%d", ec, width, height, ec->netwm.pid);
5868         return EINA_TRUE;
5869      }
5870
5871    if ((desk->geom.w == width) && (desk->geom.h == height))
5872      {
5873         ELOGF("POL_APPINFO", "SKIP SET BASE SCREEN RESOLUTION... base_output_resolution is same with desk size:(%d,%d), pid:%d", ec, width, height, ec->netwm.pid);
5874         return EINA_TRUE;
5875      }
5876
5877    /* set the base_output_resolution of the e_client */
5878    _e_client_base_output_resolution_set(ec, width, height);
5879
5880    ELOGF("POL_APPINFO", "USE base_output_resolution(%d,%d) pid:%d", ec, width, height, ec->netwm.pid);
5881
5882    return EINA_TRUE;
5883
5884 use_configured:
5885
5886    if ((desk->geom.w == configured_width) && (desk->geom.h == configured_height))
5887      {
5888         ELOGF("POL_APPINFO", "SKIP use configured_output_resolution (same with desk size:(%d,%d), pid:%d)", ec, configured_width, configured_height, ec->netwm.pid);
5889      }
5890    else
5891      {
5892         /* set the base_output_resolution of the e_client as a default */
5893         _e_client_base_output_resolution_set(ec, configured_width, configured_height);
5894      }
5895
5896    return EINA_TRUE;
5897 }
5898
5899 E_API Eina_Bool
5900 e_client_base_output_resolution_useful_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
5901 {
5902    int zx, zy, zw, zh;
5903    E_Zone *zone;
5904
5905    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
5906
5907    zone = e_comp_zone_find_by_ec(ec);
5908    EINA_SAFETY_ON_NULL_RETURN_VAL(zone, EINA_FALSE);
5909
5910    e_zone_useful_geometry_get(zone, &zx, &zy, &zw, &zh);
5911
5912    if (x) *x = zx;
5913    if (y) *y = zy;
5914    if (w) *w = zw;
5915    if (h) *h = zh;
5916
5917    if (ec->base_output_resolution.use)
5918      {
5919         if (w) *w = ec->base_output_resolution.w;
5920         if (h) *h = ec->base_output_resolution.h;
5921      }
5922
5923    return EINA_TRUE;
5924 }
5925
5926 E_API Eina_Bool
5927 e_client_base_output_resolution_desk_useful_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h, Eina_Bool consider_obstacle_area)
5928 {
5929    int zx, zy, zw, zh;
5930    E_Zone *zone;
5931
5932    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
5933
5934    zone = e_comp_zone_find_by_ec(ec);
5935    EINA_SAFETY_ON_NULL_RETURN_VAL(zone, EINA_FALSE);
5936
5937    e_zone_desk_useful_geometry_get(zone, ec->desk, &zx, &zy, &zw, &zh, consider_obstacle_area);
5938
5939    if (x) *x = zx;
5940    if (y) *y = zy;
5941    if (w) *w = zw;
5942    if (h) *h = zh;
5943
5944    if (ec->base_output_resolution.use)
5945      {
5946         // TODO: Consider obstacle area
5947         if (w) *w = ec->base_output_resolution.w;
5948         if (h) *h = ec->base_output_resolution.h;
5949      }
5950
5951    return EINA_TRUE;
5952 }
5953
5954 /* change the base_output_resolution of the bind_ec by checking the base_output_resolution of provider_ec's appinfo */
5955 EINTERN Eina_Bool
5956 e_client_base_output_resolution_rsm_update(E_Client *bind_ec, E_Client *provider_ec)
5957 {
5958    E_Appinfo *epai = NULL;
5959    int configured_width, configured_height;
5960    int width, height;
5961    E_Desk *bind_ec_desk;
5962
5963    EINA_SAFETY_ON_NULL_RETURN_VAL(bind_ec, EINA_FALSE);
5964    EINA_SAFETY_ON_NULL_RETURN_VAL(provider_ec, EINA_FALSE);
5965
5966    bind_ec_desk = e_comp_desk_find_by_ec(bind_ec);
5967    EINA_SAFETY_ON_NULL_RETURN_VAL(bind_ec_desk, EINA_FALSE);
5968
5969   if (!e_config->configured_output_resolution.use) return EINA_TRUE;
5970
5971   configured_width = e_config->configured_output_resolution.w;
5972   configured_height = e_config->configured_output_resolution.h;
5973
5974   if (bind_ec->base_output_resolution.use)
5975     {
5976        ELOGF("POL_APPINFO", "DELETE EXISTED BINDER BASE SCREEN RESOLUTION... base_output_resolution is same with desk size:(%d,%d), bind_pid:%d", bind_ec,
5977              bind_ec->base_output_resolution.w, bind_ec->base_output_resolution.h, bind_ec->netwm.pid);
5978
5979        bind_ec->base_output_resolution.use = 0;
5980        bind_ec->base_output_resolution.w = 0;
5981        bind_ec->base_output_resolution.h = 0;
5982        e_client_transform_core_remove(bind_ec, bind_ec->base_output_resolution.transform);
5983        E_FREE_FUNC(bind_ec->base_output_resolution.transform, e_util_transform_del);
5984     }
5985
5986   if (!provider_ec->netwm.pid)
5987     {
5988        ELOGF("POL_APPINFO", "NO PROVIDER PID... USE configured_output_resolution(%d,%d) provider_pid:%d", provider_ec,
5989              configured_width, configured_height, provider_ec->netwm.pid);
5990        goto use_configured;
5991     }
5992
5993    epai = e_appinfo_find_with_pid(provider_ec->netwm.pid);
5994    if (!epai)
5995      {
5996         ELOGF("POL_APPINFO", "NO PROVIDER APPINFO... USE configured_output_resolution(%d,%d) provider_pid:%d", provider_ec,
5997               configured_width, configured_height, provider_ec->netwm.pid);
5998         goto use_configured;
5999      }
6000
6001    if (!e_appinfo_base_output_resolution_get(epai, &width, &height))
6002      {
6003         ELOGF("POL_APPINFO", "NO PROVIDER APPINFO BASE SCREEN RESOLUTION... USE configured_output_resolution(%d,%d) provider_pid:%d", provider_ec,
6004               configured_width, configured_height, provider_ec->netwm.pid);
6005         goto use_configured;
6006       }
6007
6008    if ((width == 0) && (height == 0))
6009      {
6010         ELOGF("POL_APPINFO", "NO PROVIDER WIDTH and HEIGHT... SKIP base_output_resolution due to size:(%d,%d) provider_pid:%d", provider_ec,
6011              width, height, provider_ec->netwm.pid);
6012         return EINA_TRUE;
6013      }
6014
6015    if ((bind_ec_desk->geom.w == width) && (bind_ec_desk->geom.h == height))
6016      {
6017         ELOGF("POL_APPINFO", "SKIP SET BINDER BASE SCREEN RESOLUTION... base_output_resolution is same with desk size:(%d,%d), bind_pid:%d", bind_ec,
6018             width, height, bind_ec->netwm.pid);
6019         return EINA_TRUE;
6020      }
6021
6022    /* set the base_output_resolution of the e_client */
6023    _e_client_base_output_resolution_set(bind_ec, width, height);
6024    e_client_base_output_resolution_transform_adjust(bind_ec);
6025
6026    ELOGF("POL_APPINFO", "USE BINDER base_output_resolution(%d,%d) bind_pid:%d", bind_ec, width, height, bind_ec->netwm.pid);
6027
6028    return EINA_TRUE;
6029
6030 use_configured:
6031
6032    if ((bind_ec_desk->geom.w == configured_width) && (bind_ec_desk->geom.h == configured_height))
6033      {
6034         ELOGF("POL_APPINFO", "SKIP BINDER use configured_output_resolution (same with desk size:(%d,%d), bind_pid:%d)", bind_ec,
6035              configured_width, configured_height, bind_ec->netwm.pid);
6036      }
6037    else
6038      {
6039         /* set the base_output_resolution of the e_client as a default */
6040         _e_client_base_output_resolution_set(bind_ec, configured_width, configured_height);
6041      }
6042
6043    return EINA_TRUE;
6044 }
6045
6046 /* tizen_move_resize */
6047 EINTERN Eina_Bool
6048 e_client_pending_geometry_has(E_Client *ec)
6049 {
6050    if (!eina_list_count(ec->surface_sync.pending_geometry))
6051      return EINA_FALSE;
6052
6053    return ec->surface_sync.wait_commit;
6054 }
6055
6056 EINTERN void
6057 e_client_pending_geometry_flush(E_Client *ec)
6058 {
6059    E_Client_Pending_Geometry *geo;
6060
6061    if (!eina_list_count(ec->surface_sync.pending_geometry))
6062      {
6063         EINA_LIST_FREE(ec->surface_sync.pending_geometry, geo)
6064           {
6065              E_FREE(geo);
6066           }
6067         ec->surface_sync.wait_commit = EINA_FALSE;
6068         ELOGF("POSSIZE", "pending geometry has flushed", ec);
6069      }
6070 }
6071
6072 EINTERN void
6073 e_client_pending_geometry_last_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
6074 {
6075    Eina_List *l;
6076    E_Client_Pending_Geometry *geo;
6077    int gx = 0;
6078    int gy = 0;
6079    int gw = 0;
6080    int gh = 0;
6081
6082    EINA_LIST_REVERSE_FOREACH(ec->surface_sync.pending_geometry, l, geo)
6083      {
6084         gx = geo->x;
6085         gy = geo->y;
6086         gw = geo->w;
6087         gh = geo->h;
6088         break;
6089      }
6090
6091    if (x) *x = gx;
6092    if (y) *y = gy;
6093    if (w) *w = gw;
6094    if (h) *h = gh;
6095 }
6096
6097 E_API void
6098 e_client_frame_focus_set(E_Client *ec, Eina_Bool focus)
6099 {
6100    if (!ec) return;
6101    evas_object_focus_set(ec->frame, focus);
6102 }
6103
6104 EINTERN void
6105 e_client_frame_geometry_set(E_Client *ec, int x, int y, int w, int h)
6106 {
6107    if (!ec) return;
6108
6109    if (ec->internal || ec->input_only)
6110      {
6111         evas_object_geometry_set(ec->frame, x, y, w, h);
6112      }
6113    else
6114      {
6115         if ((ec->w != w) || (ec->h != h))
6116           {
6117              ELOGF("POSSIZE", "Set move_after_resize. old(%d,%d,%dx%d), new(%d,%d,%dx%d)", ec, ec->x, ec->y, ec->w, ec->h, x, y, w, h);
6118              ec->move_after_resize = EINA_TRUE;
6119
6120              e_client_pos_set(ec, x, y);
6121              evas_object_resize(ec->frame, w, h);
6122           }
6123         else
6124           evas_object_geometry_set(ec->frame, x, y, w, h);
6125      }
6126 }
6127
6128 EAPI void
6129 e_client_util_move_resize_without_frame(E_Client *ec, int x, int y, int w, int h)
6130 {
6131    if (!ec) return;
6132
6133    if (ec->internal || ec->input_only)
6134      {
6135         e_client_util_move_without_frame(ec, x, y);
6136         e_client_util_resize_without_frame(ec, w, h);
6137      }
6138    else
6139      {
6140         if ((ec->w != w) || (ec->h != h))
6141           {
6142              ELOGF("POSSIZE", "Set move_after_resize. old(%d,%d,%dx%d), new(%d,%d,%dx%d)", ec, ec->x, ec->y, ec->w, ec->h, x, y, w, h);
6143              ec->move_after_resize = EINA_TRUE;
6144
6145              e_comp_object_frame_xy_adjust(ec->frame, x, y, &x, &y);
6146              e_client_pos_set(ec, x, y);
6147              e_client_util_resize_without_frame(ec, w, h);
6148           }
6149         else
6150           {
6151              e_client_util_move_without_frame(ec, x, y);
6152              e_client_util_resize_without_frame(ec, w, h);
6153           }
6154      }
6155 }
6156
6157 E_API Eina_Bool
6158 e_client_layer_set(E_Client *ec,
6159                    E_Layer layer)
6160 {
6161    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
6162    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, EINA_FALSE);
6163    if (!ec->frame) return EINA_FALSE;
6164
6165    if (e_comp_canvas_client_layer_map(layer) == 9999)
6166      return EINA_FALSE; //invalid layer is not allowed
6167
6168 #ifdef REFACTOR_DESK_AREA
6169 #else
6170    if (ec->desk_area.enable)
6171      {
6172         if (e_client_layer_set_by_desk_area(ec, layer))
6173           {
6174              // restack according to desk group rule
6175              e_desk_area_ec_rearrange(ec->desk_area.desk_area, ec);
6176              return EINA_TRUE;
6177           }
6178      }
6179    ec->desk_area.layer_backup = layer;
6180 #endif
6181
6182    evas_object_layer_set(ec->frame, layer);
6183    if (ec->layer != layer)
6184      {
6185         /* check exceptional case */
6186         if ((ec->fullscreen) &&
6187             (ec->saved.layer != layer))
6188           {
6189              ELOGF("LAYER", "(%d) fail to backup at saved.layer for fullscreen", ec, layer);
6190              return EINA_FALSE;
6191           }
6192         // if e_comp_object fail to change ec->layer due to ec->layer_pending or block
6193         // leave log and apply ec->layer according to set
6194         // as a result it restores back to given layer when pending or block is free
6195         ELOGF("LAYER", "change layer from %d to %d if in case layer pending(%d) or block(%d)",
6196               ec, ec->layer, layer, ec->layer_pending, ec->layer_block);
6197         if (ec->layer_pending || ec->layer_block)
6198           {
6199              ec->layer = layer;
6200              return EINA_TRUE;
6201           }
6202      }
6203
6204    wl_signal_emit(&PRI(ec)->events.set_layer, NULL);
6205
6206    return EINA_TRUE;
6207 }
6208
6209 E_API E_Layer
6210 e_client_layer_get(E_Client *ec)
6211 {
6212    short layer;
6213
6214    E_OBJECT_CHECK_RETURN(ec, E_LAYER_BOTTOM);
6215    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, E_LAYER_BOTTOM);
6216    if (!ec->frame) return E_LAYER_BOTTOM;
6217
6218    layer = evas_object_layer_get(ec->frame);
6219    if (ec->layer != layer)
6220      {
6221         /* client could be on temperory layer while pending or block,
6222          * in that case, client restores back to ec->layer after pending/block finish */
6223         if (ec->layer_block || ec->layer_pending)
6224           return ec->layer;
6225
6226         /* otherwise, client is on unexpected layer */
6227         ELOGF("LAYER", "layer dismatch ec->layer %d | evas obj layer %d ",
6228               ec, ec->layer, layer);
6229
6230         if (e_comp_canvas_client_layer_map(layer) == 9999)
6231           return E_LAYER_BOTTOM; //not on E_LAYER_CLIENT
6232      }
6233
6234    return ec->layer;
6235 }
6236
6237 #ifdef REFACTOR_DESK_AREA
6238 #else
6239 static void
6240 _e_client_desk_area_original_layer_save(E_Client *ec, E_Layer layer)
6241 {
6242    E_OBJECT_CHECK(ec);
6243    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
6244    ec->desk_area.layer_backup = layer;
6245 }
6246
6247 EINTERN Eina_Bool
6248 e_client_layer_set_by_desk_area(E_Client *ec, E_Layer layer)
6249 {
6250    E_Desk_Area *eda;
6251    E_Layer edg_layer;
6252    E_Layer org_layer;
6253
6254    if (!ec) return EINA_FALSE;
6255    if (!ec->frame) return EINA_FALSE;
6256    if (!ec->desk_area.enable) return EINA_FALSE;
6257    if (!ec->desk_area.desk_area) return EINA_FALSE;
6258
6259    eda = ec->desk_area.desk_area;
6260
6261    // save original layer
6262    _e_client_desk_area_original_layer_save(ec, layer);
6263
6264    // get desk_area layer
6265    edg_layer = (E_Layer)e_desk_area_layer_get(eda);
6266    org_layer = e_client_desk_area_original_layer_get(ec);
6267
6268    ELOGF("EDG", "layer_set by desk_area... layer:%d, org_layer:%d, new_layer:%d", ec, layer, org_layer, edg_layer);
6269    if (org_layer == edg_layer)
6270      {
6271         e_client_raise(ec);
6272      }
6273    else
6274      {
6275         evas_object_layer_set(ec->frame, edg_layer);
6276         if (edg_layer == ec->layer)
6277           e_client_raise(ec);
6278      }
6279
6280    return EINA_TRUE;
6281 }
6282
6283 EINTERN void
6284 e_client_desk_area_original_layer_restore(E_Client *ec)
6285 {
6286    if (!ec) return;
6287
6288    // Do we need to check ec->desk_area.enable?
6289    // if ec->desk_area.enable is true, then e_client_layer_set calls
6290    // e_desk_area_ec_edg_layer_set(). that's too bad. :(
6291    // so, we MUST make a policy for ordering of the desk group layer restore
6292    // and the desk group enable.
6293    if (ec->desk_area.enable) return;
6294    e_client_layer_set(ec, ec->desk_area.layer_backup);
6295 }
6296
6297 EINTERN E_Layer
6298 e_client_desk_area_original_layer_get(E_Client *ec)
6299 {
6300    if (!ec) return E_LAYER_DESKTOP;
6301
6302    if (ec->desk_area.enable)
6303      return ec->desk_area.layer_backup;
6304    else
6305      return ec->layer;
6306 }
6307
6308 EINTERN Eina_Bool
6309 e_client_desk_area_client_layer_set(E_Client *ec, E_Desk_Area_Client_Layer edgc_layer)
6310 {
6311    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
6312    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, EINA_FALSE);
6313    if ((edgc_layer < E_DESK_AREA_CLIENT_LAYER_DESKTOP) ||
6314        (edgc_layer >= E_DESK_AREA_CLIENT_LAYER_MAX))
6315      return EINA_FALSE;
6316
6317    ec->desk_area.edgc_layer = edgc_layer;
6318    return EINA_TRUE;
6319 }
6320
6321 EINTERN E_Desk_Area_Client_Layer
6322 e_client_desk_area_client_layer_get(E_Client *ec)
6323 {
6324    E_OBJECT_CHECK_RETURN(ec, E_DESK_AREA_CLIENT_LAYER_DESKTOP);
6325
6326    return ec->desk_area.edgc_layer;
6327 }
6328
6329 //FIXME: use e_desk_area_ec_reassign(eda, ec) instead of this api
6330 E_API Eina_Bool
6331 e_client_desk_area_set(E_Client *ec, E_Desk_Area *eda)
6332 {
6333    E_Desk_Area *old_edg;
6334
6335    if (!ec) return EINA_FALSE;
6336
6337 #if 0 // if this is removed.. then below if (eda != old_edg) is removed also...
6338    if (ec->desk_area.desk_area == eda)
6339      return EINA_TRUE;
6340 #endif
6341
6342    ELOGF("EDG", "Desk Group Set (new:%p, old:%p)", ec, eda, ec->desk_area.desk_area);
6343    old_edg = ec->desk_area.desk_area;
6344    if (old_edg)
6345      e_desk_area_ec_remove(old_edg, ec);
6346
6347    ec->desk_area.desk_area = eda;
6348    e_desk_area_ec_add(eda, ec);
6349
6350 #if 0 // if this is removed.. then above if (ec->desk_area.desk_area == eda) is removed also...
6351    if (eda != old_edg)
6352 #endif
6353      {
6354         e_desk_area_ec_update(eda, ec);
6355         e_desk_area_ec_rearrange(ec->desk_area.desk_area, ec);
6356      }
6357
6358    return EINA_TRUE;
6359 }
6360 #endif
6361
6362 static void
6363 _raise_between_sibling_under_parent(E_Client *ec)
6364 {
6365    ELOGF("POL", "RAISE child window between sibling. So, stack below under the parent (win:%zx, ec:%p)", ec, e_client_util_win_get(ec->parent), ec->parent);
6366    e_client_stack_below(ec, ec->parent);
6367 }
6368
6369 static void
6370 _raise_between_sibling_on_parent(E_Client *ec)
6371 {
6372    E_Client *top_child = NULL;
6373    top_child = e_client_transient_child_top_get(ec->parent, EINA_FALSE);
6374    if (!top_child)
6375      {
6376         ELOGF("POL", "RAISE child window... Stack above on the parent (win:%zx, ec:%p)", ec, e_client_util_win_get(ec->parent), ec->parent);
6377         e_client_stack_above(ec, ec->parent);
6378      }
6379    else
6380      {
6381         if (top_child != ec)
6382           {
6383              ELOGF("POL", "RAISE child window between sibling... Stack above on the top child (win:%zx, ec:%p)", ec, e_client_util_win_get(top_child), top_child);
6384              e_client_stack_above(ec, top_child);
6385           }
6386         else
6387           ELOGF("POL", "RAISE child window between sibling... already on the top. STAY", ec);
6388      }
6389 }
6390
6391 static void
6392 _raise_belong_to_parent(E_Client *ec)
6393 {
6394    if (e_client_transient_policy_get(ec) == E_TRANSIENT_BELOW)
6395      _raise_between_sibling_under_parent(ec);
6396    else
6397      _raise_between_sibling_on_parent(ec);
6398 }
6399
6400 E_API void
6401 e_client_raise(E_Client *ec)
6402 {
6403    if (!ec) return;
6404
6405 #ifdef REFACTOR_DESK_AREA
6406 #else
6407    if (ec->desk_area.enable)
6408      {
6409         E_Desk_Area *eda;
6410         eda = ec->desk_area.desk_area;
6411         if (eda)
6412           {
6413              e_desk_area_ec_raise(eda, ec);
6414              return;
6415           }
6416      }
6417 #endif
6418
6419    if (ec->parent && e_client_is_belong_to_parent(ec))
6420      _raise_belong_to_parent(ec);
6421    else
6422      evas_object_raise(ec->frame);
6423
6424    wl_signal_emit(&PRI(ec)->events.raise, NULL);
6425 }
6426
6427 static void
6428 _e_client_transient_for_below_group_make(E_Client *ec, Eina_List **list)
6429 {
6430    // list : Head is the bottommost child
6431    E_Client *child;
6432    Eina_List *l;
6433
6434    if (!ec) return;
6435
6436    EINA_LIST_REVERSE_FOREACH(ec->transients, l, child)
6437      {
6438         if (!child) continue;
6439         if (e_client_transient_policy_get(child) != E_TRANSIENT_BELOW) continue;
6440         if (!e_client_is_belong_to_parent(child)) continue;
6441
6442         *list = eina_list_prepend(*list, child);
6443         _e_client_transient_for_group_make(child, list);
6444      }
6445 }
6446
6447 E_API E_Client *
6448 e_client_transient_child_bottom_get(E_Client *ec)
6449 {
6450    E_Client *bottom_ec = NULL;
6451    Eina_List *transient_below_list = NULL;
6452    Eina_List *l = NULL;
6453
6454    _e_client_transient_for_below_group_make(ec, &transient_below_list);
6455
6456    if (transient_below_list)
6457      {
6458         E_Client *temp_ec = NULL;
6459         E_Client *temp_ec2 = NULL;
6460
6461         E_CLIENT_FOREACH(temp_ec)
6462           {
6463              if (bottom_ec) break;
6464
6465              if (temp_ec == ec)
6466                {
6467                   bottom_ec = ec;
6468                   break;
6469                }
6470
6471              EINA_LIST_FOREACH(transient_below_list, l, temp_ec2)
6472                {
6473                   if (temp_ec == temp_ec2)
6474                     {
6475                        bottom_ec = temp_ec2;
6476                        break;
6477                     }
6478                }
6479           }
6480         eina_list_free(transient_below_list);
6481      }
6482    return bottom_ec;
6483 }
6484
6485 static void
6486 _lower_between_sibling_under_parent(E_Client *ec)
6487 {
6488    E_Client *bottom_child = NULL;
6489    bottom_child = e_client_transient_child_bottom_get(ec->parent);
6490    if (!bottom_child)
6491      {
6492         ELOGF("POL", "LOWER child window between sibling... Stack below under the parent (win:%zx, ec:%p)", ec, e_client_util_win_get(ec->parent), ec->parent);
6493         e_client_stack_below(ec, ec->parent);
6494      }
6495    else
6496      {
6497         if (bottom_child != ec)
6498           {
6499              ELOGF("POL", "LOWER child window between sibling... Stack below under the bottom child (win:%zx, ec:%p)", ec, e_client_util_win_get(bottom_child), bottom_child);
6500              e_client_stack_below(ec, bottom_child);
6501           }
6502         else
6503           ELOGF("POL", "LOWER child window between sibling... already under the bottom. STAY", ec);
6504      }
6505 }
6506
6507 static void
6508 _lower_between_sibling_on_parent(E_Client *ec)
6509 {
6510    ELOGF("POL", "LOWER child window between sibling... So, stack above on the parent (win:%zx, ec:%p)", ec, e_client_util_win_get(ec->parent), ec->parent);
6511    e_client_stack_above(ec, ec->parent);
6512 }
6513
6514 static void
6515 _lower_belong_to_parent(E_Client *ec)
6516 {
6517    if (e_client_transient_policy_get(ec) == E_TRANSIENT_BELOW)
6518      _lower_between_sibling_under_parent(ec);
6519    else
6520      _lower_between_sibling_on_parent(ec);
6521 }
6522
6523 E_API void
6524 e_client_lower(E_Client *ec)
6525 {
6526    if (!ec) return;
6527
6528 #ifdef REFACTOR_DESK_AREA
6529 #else
6530    if (ec->desk_area.enable)
6531      {
6532         E_Desk_Area *eda;
6533         eda = ec->desk_area.desk_area;
6534         if (eda)
6535           {
6536              e_desk_area_ec_lower(eda, ec);
6537
6538              wl_signal_emit(&PRI(ec)->events.lower, NULL);
6539              return;
6540           }
6541      }
6542 #endif
6543
6544    if (ec->parent && e_client_is_belong_to_parent(ec))
6545      _lower_belong_to_parent(ec);
6546    else
6547      evas_object_lower(ec->frame);
6548
6549    wl_signal_emit(&PRI(ec)->events.lower, NULL);
6550 }
6551
6552 E_API void
6553 e_client_stack_above(E_Client *ec, E_Client *above)
6554 {
6555    if (!ec) return;
6556    if (!ec->frame) return;
6557    if (!above) return;
6558    if (!above->frame) return;
6559
6560 #ifdef REFACTOR_DESK_AREA
6561 #else
6562    if (ec->desk_area.enable)
6563      {
6564         E_Desk_Area *eda;
6565         eda = ec->desk_area.desk_area;
6566         if (eda)
6567           {
6568              e_desk_area_ec_stack_above(eda, ec, above);
6569              return;
6570           }
6571      }
6572 #endif
6573
6574    evas_object_stack_above(ec->frame, above->frame);
6575
6576    wl_signal_emit(&PRI(ec)->events.stack_above, NULL);
6577 }
6578
6579 E_API void
6580 e_client_stack_below(E_Client *ec, E_Client *below)
6581 {
6582    if (!ec) return;
6583    if (!ec->frame) return;
6584    if (!below) return;
6585    if (!below->frame) return;
6586
6587 #ifdef REFACTOR_DESK_AREA
6588 #else
6589    if (ec->desk_area.enable)
6590      {
6591         E_Desk_Area *eda;
6592         eda = ec->desk_area.desk_area;
6593         if (eda)
6594           {
6595              e_desk_area_ec_stack_below(eda, ec, below);
6596              return;
6597           }
6598      }
6599 #endif
6600
6601    evas_object_stack_below(ec->frame, below->frame);
6602
6603    wl_signal_emit(&PRI(ec)->events.stack_below, NULL);
6604 }
6605
6606 E_API int
6607 e_client_show_pending_set(E_Client *ec)
6608 {
6609    if (!ec) return 0;
6610
6611    ec->show_pending.count++;
6612    ELOGF("E_CLIENT", "SET show_pending. (count:%d, run:%d)", ec, ec->show_pending.count, ec->show_pending.running);
6613    return ec->show_pending.count;
6614 }
6615
6616 E_API int
6617 e_client_show_pending_unset(E_Client *ec)
6618 {
6619    if (!ec) return 0;
6620    if (ec->show_pending.count <= 0) return 0;
6621
6622    ec->show_pending.count--;
6623    ELOGF("E_CLIENT", "UNSET show_pending. (count:%d, run:%d)", ec, ec->show_pending.count, ec->show_pending.running);
6624    if (ec->show_pending.count == 0 && ec->show_pending.running)
6625      {
6626         ec->show_pending.running = EINA_FALSE;
6627         if (ec->frame)
6628           {
6629              ELOGF("E_CLIENT", "evas_object_show by unset show_pending", ec);
6630              evas_object_show(ec->frame);
6631              //e_comp_object_damage(ec->frame, 0, 0, ec->w, ec->h);
6632              EC_CHANGED(ec);
6633           }
6634      }
6635
6636    return ec->show_pending.count;
6637 }
6638
6639 static Eina_Bool
6640 _e_client_surface_tree_foreach_helper(E_Client *ec, E_Client_Surface_Tree_Foreach func, void *data)
6641 {
6642    E_Client *subc;
6643    Eina_List *l, *ll;
6644    Eina_Bool res = EINA_TRUE;
6645    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
6646
6647    if (!cdata)
6648      return res;
6649
6650    EINA_LIST_FOREACH_SAFE(cdata->sub.below_list, l, ll, subc)
6651      {
6652         res = _e_client_surface_tree_foreach_helper(subc, func, data);
6653         if (!res)
6654           break;
6655      }
6656
6657    if (res)
6658      {
6659         res = func(data, ec);
6660         if (res)
6661           {
6662              EINA_LIST_FOREACH_SAFE(cdata->sub.list, l, ll, subc)
6663                {
6664                   res = _e_client_surface_tree_foreach_helper(subc,
6665                                                               func,
6666                                                               data);
6667                   if (!res)
6668                     break;
6669                }
6670           }
6671      }
6672
6673    return res;
6674 }
6675
6676 E_API void
6677 e_client_surface_tree_foreach(E_Client *ec, E_Client_Surface_Tree_Foreach func, void *data)
6678 {
6679    EINA_SAFETY_ON_NULL_RETURN(ec);
6680    EINA_SAFETY_ON_NULL_RETURN(func);
6681
6682    _e_client_surface_tree_foreach_helper(ec, func, data);
6683 }
6684
6685 EINTERN E_Comp_Wl_Client_Data *
6686 e_client_cdata_new(E_Client *ec)
6687 {
6688    E_Comp_Wl_Client_Data *cdata;
6689
6690    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
6691
6692    if (!(cdata = E_NEW(E_Comp_Wl_Client_Data, 1)))
6693      {
6694         ERR("Could not allocate new E_Comp_Wl_Client_Data structure");
6695         return NULL;
6696      }
6697    ec->comp_data = cdata;
6698
6699    return cdata;
6700 }
6701
6702 EINTERN void
6703 e_client_cdata_free(E_Client *ec)
6704 {
6705   EINA_SAFETY_ON_NULL_RETURN(ec);
6706   if (!ec->comp_data) return;
6707
6708   E_FREE(ec->comp_data);
6709 }
6710
6711 EINTERN E_Comp_Wl_Client_Data *
6712 e_client_cdata_get(E_Client *ec)
6713 {
6714    if (!ec) return NULL;
6715
6716    return ec->comp_data;
6717 }
6718
6719 EINTERN Eina_Bool
6720 e_client_map_set(E_Client *ec, E_Map *em)
6721 {
6722    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6723
6724    return e_map_set_to_comp_object(em, ec->frame);
6725 }
6726
6727 E_API E_Map *
6728 e_client_map_get(const E_Client *ec)
6729 {
6730    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
6731
6732    return e_map_get_from_comp_object(ec->frame);
6733 }
6734
6735 EINTERN Eina_Bool
6736 e_client_map_enable_set(E_Client *ec, Eina_Bool enable)
6737 {
6738    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6739    EINA_SAFETY_ON_NULL_RETURN_VAL(ec->frame, EINA_FALSE);
6740
6741    evas_object_map_enable_set(ec->frame, enable);
6742
6743    return EINA_TRUE;
6744 }
6745
6746 EINTERN void
6747 e_client_belong_to_parent_set(E_Client *ec, Eina_Bool set)
6748 {
6749    if (!ec) return;
6750    ec->belong_to_parent = set;
6751 }
6752
6753 EINTERN Eina_Bool
6754 e_client_is_belong_to_parent(E_Client *ec)
6755 {
6756    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6757    return ec->belong_to_parent;
6758 }
6759
6760 EINTERN void
6761 e_client_transient_policy_set(E_Client *ec, E_Transient policy)
6762 {
6763    if (!ec) return;
6764    ec->transient_policy = policy;
6765 }
6766
6767 E_API E_Transient
6768 e_client_transient_policy_get(E_Client *ec)
6769 {
6770    if (!ec) return E_TRANSIENT_ABOVE;
6771    return ec->transient_policy;
6772 }
6773
6774 EINTERN void
6775 e_client_resize_object_create_cb_set(E_Client_Resize_Object_Create_Cb cb)
6776 {
6777    if (_e_client_resize_object_create_cb && cb)
6778      CRI("ATTEMPTING TO OVERWRITE EXISTING CLIENT RESIZE OBJECT CREATE HOOK!!!");
6779    _e_client_resize_object_create_cb = cb;
6780 }
6781
6782 EINTERN void
6783 e_client_resize_unit_size_set(E_Client *ec, unsigned int unit_size)
6784 {
6785    if (!ec) return;
6786
6787    // FYI, we consider 0 and 1 to be the same value as a default unit size.
6788    ec->manage_resize.unit_size = unit_size;
6789 }
6790
6791 EINTERN void
6792 e_client_desk_zoom_enable_set(E_Client *ec, Eina_Bool enable)
6793 {
6794    if (!ec) return;
6795    ec->desk_zoom.enable = enable;
6796 }
6797
6798 EINTERN Eina_Bool
6799 e_client_desk_zoom_enable_get(E_Client *ec)
6800 {
6801    if (!ec) return EINA_FALSE;
6802    return ec->desk_zoom.enable;
6803 }
6804
6805 EINTERN void
6806 e_client_layout_apply(E_Client *ec, Eina_Bool apply)
6807 {
6808    if (!ec) return;
6809    ec->apply_layout = apply;
6810 }
6811
6812 EINTERN Eina_Bool
6813 e_client_is_layout_apply(E_Client *ec)
6814 {
6815    if (!ec) return EINA_FALSE;
6816    return ec->apply_layout;
6817 }
6818
6819 E_API E_Client *
6820 e_client_from_surface_resource(struct wl_resource *surface_resource)
6821 {
6822    EINA_SAFETY_ON_NULL_RETURN_VAL(surface_resource, NULL);
6823
6824    return e_comp_wl_util_client_from_surface_resource(surface_resource);
6825 }
6826
6827 EINTERN void
6828 e_client_fps_update(E_Client *ec)
6829 {
6830    double dt;
6831    double tim;
6832
6833    EINA_SAFETY_ON_NULL_RETURN(ec);
6834
6835    if (!ec->fps.enabled) return;
6836
6837    tim = ecore_time_get();
6838
6839    dt = tim - ec->fps.frametimes[0];
6840
6841    ec->fps.frametimes[0] = tim;
6842    ec->fps.time += dt;
6843    ec->fps.cframes++;
6844
6845    if (ec->fps.lapse == 0.0)
6846      {
6847         ec->fps.lapse = tim;
6848         ec->fps.flapse = ec->fps.cframes;
6849      }
6850    else if ((tim - ec->fps.lapse) >= 0.5)
6851      {
6852         ec->fps.fps = (ec->fps.cframes - ec->fps.flapse) /
6853                       (tim - ec->fps.lapse);
6854         ec->fps.lapse = tim;
6855         ec->fps.flapse = ec->fps.cframes;
6856         ec->fps.time = 0.0;
6857      }
6858 }
6859
6860 EINTERN Eina_Bool
6861 e_client_fps_get(E_Client *ec, double *fps)
6862 {
6863    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6864
6865    if (ec->fps.old_fps == ec->fps.fps)
6866      return EINA_FALSE;
6867
6868    if (ec->fps.fps > 0.0)
6869      {
6870         *fps = ec->fps.fps;
6871         ec->fps.old_fps = ec->fps.fps;
6872         return EINA_TRUE;
6873      }
6874
6875    return EINA_FALSE;
6876 }
6877
6878 EINTERN void
6879 e_client_fps_enable(E_Client *ec, Eina_Bool enable)
6880 {
6881    EINA_SAFETY_ON_NULL_RETURN(ec);
6882
6883    ec->fps.enabled = enable;
6884 }
6885
6886 EINTERN Eina_Bool
6887 e_client_explicit_sync_get(E_Client *ec)
6888 {
6889    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6890
6891    return ec->explicit_sync;
6892 }
6893
6894 EINTERN Eina_Bool
6895 e_client_explicit_sync_set(E_Client *ec, Eina_Bool enable)
6896 {
6897    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6898
6899    ec->explicit_sync = enable;
6900
6901    return EINA_TRUE;
6902 }
6903
6904 EINTERN int
6905 e_client_explicit_sync_acquire_fence_fd_get(E_Client *ec)
6906 {
6907    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, -1);
6908
6909    return ec->acquire_fence_fd;
6910 }
6911
6912 EINTERN Eina_Bool
6913 e_client_explicit_sync_acquire_fence_fd_set(E_Client *ec, int fd)
6914 {
6915   EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6916
6917   ec->acquire_fence_fd = fd;
6918
6919   return EINA_TRUE;
6920 }
6921
6922 EINTERN Eina_Bool
6923 e_client_intercept_hook_auto_placement_call(E_Client *ec)
6924 {
6925   // no need to call the intercept hook if ec is NULL.
6926   if (!ec) return EINA_FALSE;
6927
6928   if (!_e_client_intercept_hook_call(E_CLIENT_INTERCEPT_HOOK_AUTO_PLACEMENT, ec))
6929     {
6930        ELOGF("FOCUS", "E_CLIENT_INTERCEPT_HOOK_AUTO_PLACEMENT Intercepted.", ec);
6931        return EINA_TRUE;
6932     }
6933
6934   return EINA_FALSE;
6935 }
6936
6937 EINTERN void
6938 e_client_iconify_event_send(E_Client *ec)
6939 {
6940    EINA_SAFETY_ON_NULL_RETURN(ec);
6941
6942    _e_client_event_simple(ec, E_EVENT_CLIENT_ICONIFY);
6943 }
6944
6945 EINTERN void
6946 e_client_uniconify_event_send(E_Client *ec)
6947 {
6948    EINA_SAFETY_ON_NULL_RETURN(ec);
6949
6950    _e_client_event_simple(ec, E_EVENT_CLIENT_UNICONIFY);
6951 }
6952
6953 EINTERN void
6954 e_client_stack_transient_for_done_notify(E_Client *ec)
6955 {
6956    EINA_SAFETY_ON_NULL_RETURN(ec);
6957
6958    wl_signal_emit(&PRI(ec)->events.stack_transient_for_done, NULL);
6959 }
6960
6961 #ifdef REFACTOR_DESK_AREA
6962 EINTERN void
6963 e_client_subsurface_stack_update(E_Client *ec)
6964 {
6965    EINA_SAFETY_ON_NULL_RETURN(ec);
6966
6967    wl_signal_emit(&PRI(ec)->events.subsurface_stack_update, ec);
6968 }
6969 #endif
6970
6971 EINTERN void
6972 e_client_eval_pre_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
6973 {
6974    API_ENTRY;
6975    wl_signal_add(&priv->events.eval_pre_fetch, listener);
6976 }
6977
6978 EINTERN void
6979 e_client_eval_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
6980 {
6981    API_ENTRY;
6982    wl_signal_add(&priv->events.eval_fetch, listener);
6983 }
6984
6985 EINTERN void
6986 e_client_eval_pre_post_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
6987 {
6988    API_ENTRY;
6989    wl_signal_add(&priv->events.eval_pre_post_fetch, listener);
6990 }
6991
6992 EINTERN void
6993 e_client_eval_post_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
6994 {
6995    API_ENTRY;
6996    wl_signal_add(&priv->events.eval_post_fetch, listener);
6997 }
6998
6999 EINTERN void
7000 e_client_eval_pre_frame_assign_listener_add(E_Client *ec, struct wl_listener *listener)
7001 {
7002    API_ENTRY;
7003    wl_signal_add(&priv->events.eval_pre_frame_assign, listener);
7004 }
7005
7006 EINTERN void
7007 e_client_eval_post_frame_assign_listener_add(E_Client *ec, struct wl_listener *listener)
7008 {
7009    API_ENTRY;
7010    wl_signal_add(&priv->events.eval_post_frame_assign, listener);
7011 }
7012
7013 EINTERN void
7014 e_client_eval_pre_new_client_listener_add(E_Client *ec, struct wl_listener *listener)
7015 {
7016    API_ENTRY;
7017    wl_signal_add(&priv->events.eval_pre_new_client, listener);
7018 }
7019
7020 EINTERN void
7021 e_client_eval_post_new_client_listener_add(E_Client *ec, struct wl_listener *listener)
7022 {
7023    API_ENTRY;
7024    wl_signal_add(&priv->events.eval_post_new_client, listener);
7025 }
7026
7027 EINTERN void
7028 e_client_eval_visibility_listener_add(E_Client *ec, struct wl_listener *listener)
7029 {
7030    API_ENTRY;
7031    wl_signal_add(&priv->events.eval_visibility, listener);
7032 }
7033
7034 EINTERN void
7035 e_client_eval_visibility_end_listener_add(E_Client *ec, struct wl_listener *listener)
7036 {
7037    API_ENTRY;
7038    wl_signal_add(&priv->events.eval_visibility_end, listener);
7039 }
7040
7041 EINTERN void
7042 e_client_eval_end_listener_add(E_Client *ec, struct wl_listener *listener)
7043 {
7044    API_ENTRY;
7045    wl_signal_add(&priv->events.eval_end, listener);
7046 }
7047
7048 EINTERN void
7049 e_client_move_begin_listener_add(E_Client *ec, struct wl_listener *listener)
7050 {
7051    API_ENTRY;
7052    wl_signal_add(&priv->events.move_begin, listener);
7053 }
7054
7055 EINTERN void
7056 e_client_move_update_listener_add(E_Client *ec, struct wl_listener *listener)
7057 {
7058    API_ENTRY;
7059    wl_signal_add(&priv->events.move_update, listener);
7060 }
7061
7062 EINTERN void
7063 e_client_move_end_listener_add(E_Client *ec, struct wl_listener *listener)
7064 {
7065    API_ENTRY;
7066    wl_signal_add(&priv->events.move_end, listener);
7067 }
7068
7069 EINTERN void
7070 e_client_move_resize_begin_listener_add(E_Client *ec, struct wl_listener *listener)
7071 {
7072    API_ENTRY;
7073    wl_signal_add(&priv->events.move_resize_begin, listener);
7074 }
7075
7076 EINTERN void
7077 e_client_move_resize_update_listener_add(E_Client *ec, struct wl_listener *listener)
7078 {
7079    API_ENTRY;
7080    wl_signal_add(&priv->events.move_resize_update, listener);
7081 }
7082
7083 EINTERN void
7084 e_client_move_resize_end_listener_add(E_Client *ec, struct wl_listener *listener)
7085 {
7086    API_ENTRY;
7087    wl_signal_add(&priv->events.move_resize_end, listener);
7088 }
7089
7090 EINTERN void
7091 e_client_destroy_listener_add(E_Client *ec, struct wl_listener *listener)
7092 {
7093    API_ENTRY;
7094    wl_signal_add(&priv->events.destroy, listener);
7095 }
7096
7097 EINTERN void
7098 e_client_new_client_listener_add(E_Client *ec, struct wl_listener *listener)
7099 {
7100    API_ENTRY;
7101    wl_signal_add(&priv->events.new_client, listener);
7102 }
7103
7104 EINTERN void
7105 e_client_new_client_post_listener_add(E_Client *ec, struct wl_listener *listener)
7106 {
7107    API_ENTRY;
7108    wl_signal_add(&priv->events.new_client_post, listener);
7109 }
7110
7111 EINTERN void
7112 e_client_unredirect_listener_add(E_Client *ec, struct wl_listener *listener)
7113 {
7114    API_ENTRY;
7115    wl_signal_add(&priv->events.unredirect, listener);
7116 }
7117
7118 EINTERN void
7119 e_client_redirect_listener_add(E_Client *ec, struct wl_listener *listener)
7120 {
7121    API_ENTRY;
7122    wl_signal_add(&priv->events.redirect, listener);
7123 }
7124
7125 EINTERN void
7126 e_client_aux_hint_change_listener_add(E_Client *ec, struct wl_listener *listener)
7127 {
7128    API_ENTRY;
7129    wl_signal_add(&priv->events.aux_hint_change, listener);
7130 }
7131
7132 EINTERN void
7133 e_client_window_role_change_listener_add(E_Client *ec, struct wl_listener *listener)
7134 {
7135    API_ENTRY;
7136    wl_signal_add(&priv->events.window_role_change, listener);
7137 }
7138
7139 EINTERN void
7140 e_client_transform_change_listener_add(E_Client *ec, struct wl_listener *listener)
7141 {
7142    API_ENTRY;
7143    wl_signal_add(&priv->events.transform_change, listener);
7144 }
7145
7146 EINTERN void
7147 e_client_activate_done_listener_add(E_Client *ec, struct wl_listener *listener)
7148 {
7149    API_ENTRY;
7150    wl_signal_add(&priv->events.activate_done, listener);
7151 }
7152
7153 EINTERN void
7154 e_client_mouse_in_listener_add(E_Client *ec, struct wl_listener *listener)
7155 {
7156    API_ENTRY;
7157    wl_signal_add(&priv->events.mouse_in, listener);
7158 }
7159
7160 EINTERN void
7161 e_client_mouse_out_listener_add(E_Client *ec, struct wl_listener *listener)
7162 {
7163    API_ENTRY;
7164    wl_signal_add(&priv->events.mouse_out, listener);
7165 }
7166
7167 EINTERN void
7168 e_client_mouse_down_listener_add(E_Client *ec, struct wl_listener *listener)
7169 {
7170    API_ENTRY;
7171    wl_signal_add(&priv->events.mouse_down, listener);
7172 }
7173
7174 EINTERN void
7175 e_client_focus_set_listener_add(E_Client *ec, struct wl_listener *listener)
7176 {
7177    API_ENTRY;
7178    wl_signal_add(&priv->events.focus_set, listener);
7179 }
7180
7181 EINTERN void
7182 e_client_focus_unset_listener_add(E_Client *ec, struct wl_listener *listener)
7183 {
7184    API_ENTRY;
7185    wl_signal_add(&priv->events.focus_unset, listener);
7186 }
7187
7188 EINTERN void
7189 e_client_focus_defer_set_listener_add(E_Client *ec, struct wl_listener *listener)
7190 {
7191    API_ENTRY;
7192    wl_signal_add(&priv->events.focus_defer_set, listener);
7193 }
7194
7195 EINTERN void
7196 e_client_focus_latest_set_listener_add(E_Client *ec, struct wl_listener *listener)
7197 {
7198    API_ENTRY;
7199    wl_signal_add(&priv->events.focus_latest_set, listener);
7200 }
7201
7202 EINTERN void
7203 e_client_iconify_listener_add(E_Client *ec, struct wl_listener *listener)
7204 {
7205    API_ENTRY;
7206    wl_signal_add(&priv->events.iconify, listener);
7207 }
7208
7209 EINTERN void
7210 e_client_uniconify_listener_add(E_Client *ec, struct wl_listener *listener)
7211 {
7212    API_ENTRY;
7213    wl_signal_add(&priv->events.uniconify, listener);
7214 }
7215
7216 EINTERN void
7217 e_client_maximize_listener_add(E_Client *ec, struct wl_listener *listener)
7218 {
7219    API_ENTRY;
7220    wl_signal_add(&priv->events.maximize, listener);
7221 }
7222
7223 EINTERN void
7224 e_client_unmaximize_listener_add(E_Client *ec, struct wl_listener *listener)
7225 {
7226    API_ENTRY;
7227    wl_signal_add(&priv->events.unmaximize, listener);
7228 }
7229
7230 EINTERN void
7231 e_client_fullscreen_pre_listener_add(E_Client *ec, struct wl_listener *listener)
7232 {
7233    API_ENTRY;
7234    wl_signal_add(&priv->events.fullscreen_pre, listener);
7235 }
7236
7237 EINTERN void
7238 e_client_fullscreen_listener_add(E_Client *ec, struct wl_listener *listener)
7239 {
7240    API_ENTRY;
7241    wl_signal_add(&priv->events.fullscreen, listener);
7242 }
7243
7244 EINTERN void
7245 e_client_unfullscreen_listener_add(E_Client *ec, struct wl_listener *listener)
7246 {
7247    API_ENTRY;
7248    wl_signal_add(&priv->events.unfullscreen, listener);
7249 }
7250
7251 EINTERN void
7252 e_client_move_listener_add(E_Client *ec, struct wl_listener *listener)
7253 {
7254    API_ENTRY;
7255    wl_signal_add(&priv->events.move, listener);
7256 }
7257
7258 EINTERN void
7259 e_client_raise_listener_add(E_Client *ec, struct wl_listener *listener)
7260 {
7261    API_ENTRY;
7262    wl_signal_add(&priv->events.raise, listener);
7263 }
7264
7265 EINTERN void
7266 e_client_lower_listener_add(E_Client *ec, struct wl_listener *listener)
7267 {
7268    API_ENTRY;
7269    wl_signal_add(&priv->events.lower, listener);
7270 }
7271
7272 EINTERN void
7273 e_client_stack_below_listener_add(E_Client *ec, struct wl_listener *listener)
7274 {
7275    API_ENTRY;
7276    wl_signal_add(&priv->events.stack_below, listener);
7277 }
7278
7279 EINTERN void
7280 e_client_stack_above_listener_add(E_Client *ec, struct wl_listener *listener)
7281 {
7282    API_ENTRY;
7283    wl_signal_add(&priv->events.stack_above, listener);
7284 }
7285
7286 EINTERN void
7287 e_client_set_layer_listener_add(E_Client *ec, struct wl_listener *listener)
7288 {
7289    API_ENTRY;
7290    wl_signal_add(&priv->events.set_layer, listener);
7291 }
7292
7293 EINTERN void
7294 e_client_stack_transient_for_done_listener_add(E_Client *ec, struct wl_listener *listener)
7295 {
7296    API_ENTRY;
7297    wl_signal_add(&priv->events.stack_transient_for_done, listener);
7298 }
7299
7300 EINTERN void
7301 e_client_stick_listener_add(E_Client *ec, struct wl_listener *listener)
7302 {
7303    API_ENTRY;
7304    wl_signal_add(&priv->events.stick, listener);
7305 }
7306
7307 EINTERN void
7308 e_client_unstick_listener_add(E_Client *ec, struct wl_listener *listener)
7309 {
7310    API_ENTRY;
7311    wl_signal_add(&priv->events.unstick, listener);
7312 }
7313
7314 EINTERN struct wl_listener *
7315 e_client_destroy_listener_get(E_Client *ec, wl_notify_func_t notify)
7316 {
7317    API_ENTRY_VAL(NULL);
7318    return wl_signal_get(&priv->events.destroy, notify);
7319 }
7320
7321 #ifdef REFACTOR_DESK_AREA
7322 EINTERN void
7323 e_client_get_above_listener_add(E_Client *ec, struct wl_listener *listener)
7324 {
7325    API_ENTRY;
7326    wl_signal_add(&priv->events.get_above, listener);
7327 }
7328
7329 EINTERN void
7330 e_client_get_below_listener_add(E_Client *ec, struct wl_listener *listener)
7331 {
7332    API_ENTRY;
7333    wl_signal_add(&priv->events.get_below, listener);
7334 }
7335
7336 EINTERN void
7337 e_client_get_visible_above_listener_add(E_Client *ec, struct wl_listener *listener)
7338 {
7339    API_ENTRY;
7340    wl_signal_add(&priv->events.get_visible_above, listener);
7341 }
7342
7343 EINTERN void
7344 e_client_get_visible_below_listener_add(E_Client *ec, struct wl_listener *listener)
7345 {
7346    API_ENTRY;
7347    wl_signal_add(&priv->events.get_visible_below, listener);
7348 }
7349
7350 EINTERN void
7351 e_client_subsurface_stack_update_listener_add(E_Client *ec, struct wl_listener *listener)
7352 {
7353    API_ENTRY;
7354    wl_signal_add(&priv->events.subsurface_stack_update, listener);
7355 }
7356 #endif
7357
7358 EINTERN void
7359 e_client_shell_configure_send(E_Client *ec, uint32_t edges, int32_t width, int32_t height)
7360 {
7361    EINA_SAFETY_ON_NULL_RETURN(ec);
7362    EINA_SAFETY_ON_NULL_RETURN(ec->comp_data);
7363
7364    if ((!ec->comp_data->shell.surface) ||
7365        (!ec->comp_data->shell.configure_send))
7366      return;
7367
7368    ec->comp_data->shell.configure_send(ec->comp_data->shell.surface, edges, width, height);
7369 }
7370
7371 EINTERN void
7372 e_client_shell_configure(E_Client *ec, Evas_Coord x, Evas_Coord y, Evas_Coord width, Evas_Coord height)
7373 {
7374    EINA_SAFETY_ON_NULL_RETURN(ec);
7375    EINA_SAFETY_ON_NULL_RETURN(ec->comp_data);
7376
7377    if ((!ec->comp_data->shell.surface) ||
7378        (!ec->comp_data->shell.configure))
7379      return;
7380
7381    ec->comp_data->shell.configure(ec->comp_data->shell.surface, x, y, width, height);
7382 }
7383
7384 EINTERN void
7385 e_client_shell_ping(E_Client *ec)
7386 {
7387    EINA_SAFETY_ON_NULL_RETURN(ec);
7388    EINA_SAFETY_ON_NULL_RETURN(ec->comp_data);
7389
7390    if ((!ec->comp_data->shell.surface) ||
7391        (!ec->comp_data->shell.ping))
7392      return;
7393
7394    ec->comp_data->shell.ping(ec->comp_data->shell.surface);
7395 }
7396
7397 static void
7398 _e_input_thread_client_icccm_name_set(void *data)
7399 {
7400    E_Input_Thread_Request_EClient_Data ec_data;
7401    memcpy(&ec_data, data, sizeof(E_Input_Thread_Request_EClient_Data));
7402
7403    INF("[input thread|%s] ec(%p), name(%s)\n", __func__, ec_data.ec, ec_data.icccm_name);
7404    e_input_thread_client_icccm_name_set(e_input_thread_client_get(ec_data.ec), ec_data.icccm_name);
7405 }
7406
7407 EINTERN void
7408 e_client_icccm_name_set(E_Client *ec, const char *name)
7409 {
7410    E_Input_Thread_Request_EClient_Data ec_data;
7411    memset(&ec_data, 0, sizeof(E_Input_Thread_Request_EClient_Data));
7412
7413    EINA_SAFETY_ON_NULL_RETURN(ec);
7414
7415    if (eina_stringshare_replace(&ec->icccm.name, name))
7416      {
7417         ec->changes.title = EINA_TRUE;
7418
7419         ec_data.ec = ec;
7420         ec_data.wl_surface = ec->comp_data ? ec->comp_data->wl_surface : NULL;
7421         ec_data.visible = ec->visible;
7422         ec_data.is_video = EINA_FALSE;
7423
7424         if (name)
7425           strncpy(ec_data.icccm_name, name, sizeof(ec_data.icccm_name)-1);
7426
7427         INF("[%s] ec(%p), surface(%p), name(%s)\n", __func__, ec, ec_data.wl_surface, name);
7428         e_input_thread_safe_call(_e_input_thread_client_icccm_name_set, &ec_data, sizeof(E_Input_Thread_Request_EClient_Data));
7429      }
7430 }
7431
7432 E_API Eina_Stringshare *
7433 e_client_icccm_name_get(E_Client *ec)
7434 {
7435    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
7436
7437    return ec->icccm.name;
7438 }
7439
7440 static void
7441 _e_input_thread_client_netwm_name_set(void *data)
7442 {
7443    E_Input_Thread_Request_EClient_Data ec_data;
7444    memcpy(&ec_data, data, sizeof(E_Input_Thread_Request_EClient_Data));
7445
7446    INF("[input thread|%s] ec(%p), name(%p)\n", __func__, ec_data.ec, ec_data.netwm_name);
7447    e_input_thread_client_netwm_name_set(e_input_thread_client_get(ec_data.ec), ec_data.netwm_name);
7448 }
7449
7450 EINTERN void
7451 e_client_netwm_name_set(E_Client *ec, const char *name)
7452 {
7453    E_Input_Thread_Request_EClient_Data ec_data = { NULL, NULL, EINA_FALSE, EINA_FALSE };
7454    memset(&ec_data, 0, sizeof(E_Input_Thread_Request_EClient_Data));
7455
7456    EINA_SAFETY_ON_NULL_RETURN(ec);
7457
7458    eina_stringshare_replace(&ec->netwm.name, name);
7459
7460    ec_data.ec = ec;
7461    ec_data.wl_surface = ec->comp_data ? ec->comp_data->wl_surface : NULL;
7462    ec_data.visible = EINA_FALSE;
7463
7464    if (name)
7465      strncpy(ec_data.netwm_name, name, sizeof(ec_data.netwm_name)-1);
7466
7467    INF("[%s] ec(%p), surface(%p), name(%s)\n", __func__, ec, ec_data.wl_surface, ec_data.netwm_name);
7468    e_input_thread_safe_call(_e_input_thread_client_netwm_name_set, &ec_data, sizeof(E_Input_Thread_Request_EClient_Data));
7469 }
7470
7471 E_API Eina_Stringshare *
7472 e_client_netwm_name_get(E_Client *ec)
7473 {
7474    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
7475
7476    return ec->netwm.name;
7477 }
7478
7479 static void
7480 _e_input_thread_client_icccm_title_set(void *data)
7481 {
7482    E_Input_Thread_Request_EClient_Data ec_data;
7483    memcpy(&ec_data, data, sizeof(E_Input_Thread_Request_EClient_Data));
7484
7485    INF("[input thread|%s] ec(%p), title(%s)\n", __func__, ec_data.ec, ec_data.icccm_title);
7486    e_input_thread_client_icccm_title_set(e_input_thread_client_get(ec_data.ec), ec_data.icccm_title);
7487 }
7488
7489 EINTERN void
7490 e_client_icccm_title_set(E_Client *ec, const char *title)
7491 {
7492    E_Input_Thread_Request_EClient_Data ec_data;
7493    memset(&ec_data, 0, sizeof(E_Input_Thread_Request_EClient_Data));
7494
7495    EINA_SAFETY_ON_NULL_RETURN(ec);
7496
7497    if (eina_stringshare_replace(&ec->icccm.title, title))
7498      {
7499         ec->changes.title = EINA_TRUE;
7500
7501         ec_data.ec = ec;
7502         ec_data.wl_surface = ec->comp_data ? ec->comp_data->wl_surface : NULL;
7503         if (title)
7504           strncpy(ec_data.icccm_title, title, sizeof(ec_data.icccm_title)-1);
7505
7506         INF("[%s] ec(%p), surface(%p)\n", __func__, ec, ec_data.wl_surface);
7507         e_input_thread_safe_call(_e_input_thread_client_icccm_title_set, &ec_data, sizeof(E_Input_Thread_Request_EClient_Data));
7508      }
7509 }
7510
7511 E_API Eina_Stringshare *
7512 e_client_icccm_title_get(E_Client *ec)
7513 {
7514    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
7515
7516    return ec->icccm.title;
7517 }
7518
7519 static void
7520 _e_client_shell_map(E_Client *ec)
7521 {
7522    EINA_SAFETY_ON_NULL_RETURN(ec);
7523    EINA_SAFETY_ON_NULL_RETURN(ec->comp_data);
7524
7525    if ((!ec->comp_data->shell.surface) ||
7526        (!ec->comp_data->shell.map))
7527      return;
7528
7529    ec->comp_data->shell.map(ec->comp_data->shell.surface);
7530 }
7531
7532 EINTERN void
7533 e_client_shell_unmap(E_Client *ec)
7534 {
7535    EINA_SAFETY_ON_NULL_RETURN(ec);
7536    EINA_SAFETY_ON_NULL_RETURN(ec->comp_data);
7537
7538    if ((!ec->comp_data->shell.surface) ||
7539        (!ec->comp_data->shell.unmap))
7540      return;
7541
7542    ec->comp_data->shell.unmap(ec->comp_data->shell.surface);
7543 }
7544
7545 EINTERN void
7546 e_client_show(E_Client *ec)
7547 {
7548    EINA_SAFETY_ON_NULL_RETURN(ec);
7549    EINA_SAFETY_ON_NULL_RETURN(ec->comp_data);
7550
7551    if (ec->comp_data->mapped)
7552      return;
7553
7554    if ((ec->comp_data->shell.surface) && (ec->comp_data->shell.map) &&
7555        (!ec->ignored))
7556      {
7557         ELOGF("E_CLIENT", "Map.", ec);
7558         _e_client_shell_map(ec);
7559      }
7560    else if (ec->internal || e_comp_wl_subsurface_can_show(ec) ||
7561             (ec == e_comp_wl->drag_client))
7562      {
7563         ELOGF("E_CLIENT", "Map. internal:%d, drag:%d",
7564               ec, ec->internal, (ec == e_comp_wl->drag_client));
7565         ec->visible = EINA_TRUE;
7566         ec->ignored = 0;
7567         evas_object_show(ec->frame);
7568         ec->comp_data->mapped = 1;
7569      }
7570 }
7571
7572 EINTERN void
7573 e_client_hide(E_Client *ec)
7574 {
7575    API_ENTRY;
7576
7577    EINA_SAFETY_ON_NULL_RETURN(ec->comp_data);
7578
7579    if (!ec->comp_data->mapped)
7580      return;
7581
7582    if ((ec->comp_data->shell.surface) && (ec->comp_data->shell.unmap))
7583      {
7584         ELOGF("E_CLIENT", "Unmap", ec);
7585
7586         if (priv->hide_by_request)
7587           ELOGF("COMP", "Currenlty hide_by_request state.", ec);
7588
7589         if (ec->show_pending.count > 0)
7590           {
7591              ELOGF("E_CLIENT", "Reset show_pending!!! (count:%d, run:%d)", ec, ec->show_pending.count, ec->show_pending.running);
7592              ec->show_pending.count = 0;
7593              if (ec->show_pending.running)
7594                {
7595                   // need to send visibility false;
7596                   e_client_visibility_set(ec, E_VISIBILITY_UNOBSCURED);
7597                   ELOGF("POL_VIS", "CLIENT VIS ON (fake).  argb:%d, opaque:%2d", ec, ec->argb, ec->visibility.opaque);
7598                   EC_CHANGED(ec);
7599                }
7600              ec->show_pending.running = EINA_FALSE;
7601           }
7602         e_client_shell_unmap(ec);
7603      }
7604    else if ((ec->internal) || (e_comp_wl_subsurface_check(ec)) ||
7605             (ec == e_comp_wl->drag_client))
7606      {
7607         ELOGF("E_CLIENT", "Unmap. internal:%d, sub:%p, drag:%d",
7608               ec, ec->internal, ec->comp_data->sub.data, (ec == e_comp_wl->drag_client));
7609         ec->visible = EINA_FALSE;
7610         evas_object_hide(ec->frame);
7611         ec->comp_data->mapped = 0;
7612      }
7613 }
7614
7615 static void
7616 _e_input_thread_client_video_mode_set(void *data)
7617 {
7618    E_Input_Thread_Request_EClient_Data ec_data;
7619    memcpy(&ec_data, data, sizeof(E_Input_Thread_Request_EClient_Data));
7620
7621    INF("[input thread|%s] ec(%p), is_video(%d)\n", __func__, ec_data.ec, ec_data.is_video);
7622    e_input_thread_client_video_set(e_input_thread_client_get(ec_data.ec), ec_data.is_video);
7623 }
7624
7625 EINTERN void
7626 e_client_video_mode_set(E_Client *ec, Eina_Bool is_video)
7627 {
7628    E_Input_Thread_Request_EClient_Data ec_data;
7629    memset(&ec_data, 0, sizeof(E_Input_Thread_Request_EClient_Data));
7630
7631    EINA_SAFETY_ON_NULL_RETURN(ec);
7632    EINA_SAFETY_ON_NULL_RETURN(ec->hwc_window);
7633
7634    ec->hwc_window->is_video = is_video;
7635
7636    ec_data.ec = ec;
7637    ec_data.is_video = is_video;
7638
7639    INF("[%s] ec(%p), is_video(%d)\n", __func__, ec, is_video);
7640    e_input_thread_safe_call(_e_input_thread_client_video_mode_set, &ec_data, sizeof(E_Input_Thread_Request_EClient_Data));
7641 }