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