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