remove code related with ec->changes.shading/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    if (ec->changes.size)
2240      {
2241         ec->changes.size = 0;
2242         evas_object_resize(ec->frame, ec->w, ec->h);
2243
2244         prop |= E_CLIENT_PROPERTY_SIZE;
2245      }
2246    if (ec->changes.pos)
2247      {
2248         ec->changes.tz_position = 0;
2249         ec->changes.pos = 0;
2250         evas_object_move(ec->frame, ec->x, ec->y);
2251         prop |= E_CLIENT_PROPERTY_POS;
2252      }
2253
2254    if (ec->changes.reset_gravity)
2255      {
2256         ec->changes.reset_gravity = 0;
2257         prop |= E_CLIENT_PROPERTY_GRAVITY;
2258      }
2259
2260    if (ec->changes.title)
2261      {
2262         ec->changes.title = 0;
2263         prop |= E_CLIENT_PROPERTY_TITLE;
2264      }
2265
2266    if ((ec->changes.visible) && (ec->visible) && (ec->new_client) && (!ec->iconic))
2267      {
2268         int x, y;
2269
2270         e_input_device_pointer_xy_get(NULL, &x, &y);
2271         if ((!ec->placed) && (!ec->re_manage) &&
2272             (e_config->window_placement_policy == E_WINDOW_PLACEMENT_MANUAL) &&
2273             (!((ec->icccm.transient_for != 0) ||
2274                (ec->dialog))) &&
2275             (!ecmove) && (!ecresize))
2276           {
2277              /* Set this window into moving state */
2278
2279              ec->cur_mouse_action = e_action_find("window_move");
2280              if (ec->cur_mouse_action)
2281                {
2282                   if ((!ec->cur_mouse_action->func.end_mouse) &&
2283                       (!ec->cur_mouse_action->func.end))
2284                     ec->cur_mouse_action = NULL;
2285                   if (ec->cur_mouse_action)
2286                     {
2287                        int t;
2288                        tx = x - (ec->w >> 1);
2289                        e_comp_object_frame_geometry_get(ec->frame, NULL, NULL, &t, NULL);
2290                        ty = y - (t >> 1);
2291                        e_client_pos_set(ec, tx, ty);
2292                        EC_CHANGED(ec);
2293                        ec->changes.pos = 1;
2294                     }
2295                }
2296           }
2297
2298         evas_object_show(ec->frame);
2299         if (evas_object_visible_get(ec->frame))
2300           {
2301              ec->changes.visible = 0;
2302              _e_client_event_show(ec);
2303           }
2304      }
2305    else if ((ec->changes.visible) && (ec->new_client))
2306      {
2307         ec->changes.visible = 0;
2308         if (!ec->iconic)
2309           _e_client_event_hide(ec);
2310      }
2311
2312    if (ec->changes.icon)
2313      {
2314         ec->changes.icon = 0;
2315      }
2316
2317    if (ec->new_client)
2318      e_comp->new_clients--;
2319    ec->new_client = 0;
2320    ec->changed = ec->changes.pos || ec->changes.size ||
2321                  ec->changes.stack || ec->changes.prop || ec->changes.border ||
2322                  ec->changes.reset_gravity ||
2323                  ec->changes.shape || ec->changes.shape_input || ec->changes.icon ||
2324                  ec->changes.internal_state ||
2325                  ec->changes.need_maximize || ec->changes.need_unmaximize;
2326    ec->changes.stack = 0;
2327
2328    if (ec->changes.need_maximize)
2329      {
2330         E_Maximize max = ec->maximized;
2331         ec->maximized = E_MAXIMIZE_NONE;
2332         e_client_maximize(ec, max);
2333         ec->changes.need_maximize = 0;
2334      }
2335    else if (ec->changes.need_unmaximize)
2336      {
2337         e_client_unmaximize(ec, ec->maximized);
2338         ec->changes.need_unmaximize = 0;
2339      }
2340
2341    if (ec->need_fullscreen)
2342      {
2343         e_client_fullscreen(ec, e_config->fullscreen_policy);
2344         ec->need_fullscreen = 0;
2345      }
2346
2347    if (ec->changes.accepts_focus)
2348      {
2349         if ((!ec->icccm.accepts_focus) && (!ec->icccm.take_focus))
2350           {
2351              if (!ec->focused)
2352                ec->changes.accepts_focus = 0;
2353           }
2354      }
2355
2356    if (send_event && prop)
2357      {
2358         _e_client_event_property(ec, prop);
2359      }
2360
2361    _e_client_aux_hint_eval(ec);
2362
2363    e_client_transform_core_update(ec);
2364
2365    wl_signal_emit_mutable(&PRI(ec)->events.eval_end, NULL);
2366    _e_client_hook_call(E_CLIENT_HOOK_EVAL_END, ec);
2367
2368    TRACE_DS_END();
2369 }
2370
2371 EINTERN void
2372 e_client_frame_update(E_Client *ec)
2373 {
2374    const char *bordername;
2375
2376    EINA_SAFETY_ON_NULL_RETURN(ec);
2377    if (e_object_is_del(E_OBJECT(ec))) return;
2378
2379    ec->border.changed = 0;
2380    if (!e_comp_object_frame_allowed(ec->frame)) return;
2381    if (ec->fullscreen || ec->borderless)
2382      bordername = "borderless";
2383    else if (ec->bordername)
2384      bordername = ec->bordername;
2385    else if (ec->mwm.borderless)
2386      bordername = "borderless";
2387    else if (((ec->icccm.transient_for != 0) || (ec->dialog)) &&
2388             (ec->icccm.min_w == ec->icccm.max_w) &&
2389             (ec->icccm.min_h == ec->icccm.max_h))
2390      bordername = "noresize_dialog";
2391    else if ((ec->icccm.min_w == ec->icccm.max_w) &&
2392             (ec->icccm.min_h == ec->icccm.max_h))
2393      bordername = "noresize";
2394    else if (ec->shaped)
2395      bordername = "shaped";
2396    else if (ec->urgent)
2397      bordername = "urgent";
2398    else if (ec->netwm.state.modal)
2399      bordername = "modal";
2400    else if ((ec->netwm.state.skip_taskbar) ||
2401             (ec->netwm.state.skip_pager))
2402      bordername = "skipped";
2403   /*
2404    else if ((ec->internal) && (ec->icccm.class) &&
2405             (!strncmp(ec->icccm.class, "e_fwin", 6)))
2406      bordername = "internal_fileman";
2407   */
2408    else
2409      bordername = e_config->theme_default_border_style;
2410    if (!bordername) bordername = "default";
2411
2412    e_client_border_set(ec, bordername);
2413 }
2414
2415 static Eina_Bool
2416 _e_client_type_match(E_Client *ec, E_Config_Client_Type *m)
2417 {
2418    if (!ec || !m) return EINA_FALSE;
2419    if (e_object_is_del(E_OBJECT(ec))) return EINA_FALSE;
2420
2421    if ((int)ec->netwm.type != m->window_type)
2422      return EINA_FALSE;
2423
2424 #if defined(__cplusplus) || defined(c_plusplus)
2425    if (m->clas)
2426      {
2427         if (!ec->icccm.cpp_class)
2428           return EINA_FALSE;
2429
2430         if (!e_util_glob_match(ec->icccm.cpp_class, m->clas))
2431           return EINA_FALSE;
2432      }
2433 #else
2434    if (m->clas)
2435      {
2436         if (!ec->icccm.class)
2437           return EINA_FALSE;
2438
2439         if (!e_util_glob_match(ec->icccm.class, m->clas))
2440           return EINA_FALSE;
2441      }
2442 #endif
2443
2444    if (m->name)
2445      {
2446         if (ec->icccm.name && e_util_glob_match(ec->icccm.name, m->name))
2447           return EINA_TRUE;
2448
2449         if (ec->icccm.title && e_util_glob_match(ec->icccm.title, m->name))
2450           return EINA_TRUE;
2451
2452         if (ec->netwm.name && e_util_glob_match(ec->netwm.name, m->name))
2453           return EINA_TRUE;
2454      }
2455
2456    return EINA_FALSE;
2457 }
2458
2459 EINTERN int
2460 e_client_type_update(E_Client *ec)
2461 {
2462    E_Config_Client_Type *m;
2463    Eina_List *l;
2464    int type = 0;
2465
2466    if (!e_config->client_types) return 0;
2467
2468    EINA_LIST_FOREACH(e_config->client_types, l, m)
2469      {
2470         if (!_e_client_type_match(ec, m)) continue;
2471         else
2472           {
2473              type = m->client_type;
2474              break;
2475           }
2476      }
2477
2478    if (ec->client_type != type)
2479      {
2480         ec->client_type = type;
2481         _e_client_event_property(ec, E_CLIENT_PROPERTY_CLIENT_TYPE);
2482      }
2483
2484    return ec->client_type;
2485 }
2486
2487 static void
2488 _e_client_transform_sub_apply(E_Client *ec, E_Client *epc, double zoom)
2489 {
2490    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
2491    E_Client *subc;
2492    Eina_List *l;
2493    int px = 0, py = 0;
2494    int ox = 0, oy = 0, ow, oh;
2495    int mx, my, mw, mh;
2496    E_Map *map;
2497
2498    EINA_SAFETY_ON_FALSE_RETURN(e_comp_wl_subsurface_check(ec));
2499
2500    e_comp_wl_subsurface_position_get(ec, &ox, &oy);
2501    ow = cdata->width_from_viewport;
2502    oh = cdata->height_from_viewport;
2503
2504    map = e_client_map_get(epc);
2505    e_map_point_coord_get(map, 0, &px, &py, 0);
2506    e_map_free(map);
2507
2508    mx = ox * zoom + px;
2509    my = oy * zoom + py;
2510    mw = ow * zoom;
2511    mh = oh * zoom;
2512
2513    map = e_map_new_with_direct_render(ec->transform_core.direct_render);
2514    e_map_util_points_populate_from_geometry(map, mx, my, mw, mh, 0);
2515    e_map_util_object_move_sync_set(map, EINA_TRUE);
2516    e_client_map_set(ec, map);
2517    e_client_map_enable_set(ec, EINA_TRUE);
2518
2519    EINA_LIST_FOREACH(cdata->sub.list, l, subc)
2520      _e_client_transform_sub_apply(subc, ec, zoom);
2521    EINA_LIST_REVERSE_FOREACH(cdata->sub.below_list, l, subc)
2522      _e_client_transform_sub_apply(subc, ec, zoom);
2523
2524    e_map_free(map);
2525 }
2526
2527 static void
2528 _e_client_transient_for_group_make(E_Client *ec, Eina_List **list)
2529 {
2530    E_Client *child;
2531    Eina_List *l;
2532
2533    if (!ec) return;
2534    if (!e_config->transient.raise) return;
2535
2536    EINA_LIST_FOREACH(ec->transients, l, child)
2537      {
2538         if (!child) continue;
2539         if (child->iconic) continue;
2540         if (e_client_transient_policy_get(child) == E_TRANSIENT_ABOVE)
2541           {
2542              *list = eina_list_prepend(*list, child);
2543              _e_client_transient_for_group_make(child, list);
2544           }
2545      }
2546 }
2547
2548 EINTERN E_Client *
2549 e_client_transient_child_top_get(E_Client *ec, Eina_Bool consider_focus)
2550 {
2551    E_Client *top_ec = NULL;
2552    Eina_List *transient_list = NULL;
2553
2554    _e_client_transient_for_group_make(ec, &transient_list);
2555
2556    if (transient_list)
2557      {
2558         Eina_List *l = NULL;
2559         E_Client *temp_ec = NULL;
2560         E_Client *temp_ec2 = NULL;
2561
2562         E_CLIENT_REVERSE_FOREACH(temp_ec)
2563           {
2564              if (top_ec) break;
2565              if (temp_ec == ec)
2566                {
2567                   top_ec = ec;
2568                   break;
2569                }
2570
2571              EINA_LIST_FOREACH(transient_list, l, temp_ec2)
2572                {
2573                   if (temp_ec == temp_ec2)
2574                     {
2575                        if (consider_focus)
2576                          {
2577                             if ((temp_ec2->icccm.accepts_focus) ||
2578                                 (temp_ec2->icccm.take_focus))
2579                               {
2580                                  top_ec = temp_ec2;
2581                               }
2582                          }
2583                        else
2584                          {
2585                             top_ec = temp_ec2;
2586                          }
2587                        break;
2588                     }
2589                }
2590           }
2591         eina_list_free(transient_list);
2592      }
2593    return top_ec;
2594 }
2595
2596 #ifdef EC_IS_NOT_VISIBLE
2597 # undef EC_IS_NOT_VISIBLE
2598 #endif
2599 #define EC_IS_NOT_VISIBLE if (ec->visibility.obscured != E_VISIBILITY_UNOBSCURED)
2600
2601 EINTERN Eina_Bool
2602 e_client_visibility_touched_check(E_Client *ec)
2603 {
2604    int tx, ty;
2605
2606    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
2607
2608    tx = wl_fixed_to_int(e_comp->wl_comp_data->ptr.x);
2609    ty = wl_fixed_to_int(e_comp->wl_comp_data->ptr.y);
2610
2611    return _e_client_position_inside_input_rect(ec, tx, ty);
2612 }
2613
2614 EINTERN void
2615 e_client_visibility_change_notify(E_Client *ec)
2616 {
2617    EINA_SAFETY_ON_NULL_RETURN(ec);
2618
2619    if (ec->visibility.changed)
2620      _e_client_event_simple(ec, E_EVENT_CLIENT_VISIBILITY_CHANGE);
2621
2622    wl_signal_emit_mutable(&PRI(ec)->events.eval_visibility, NULL);
2623    _e_client_hook_call(E_CLIENT_HOOK_EVAL_VISIBILITY, ec);
2624 }
2625
2626 EINTERN void
2627 e_client_visibility_end_notify(void)
2628 {
2629    // FIXME: This hook means that the visiblitiy calculation of a zone is done
2630    //        at this idle handler.This is a hook for a zone, not for a client.
2631    //        Therefore, this hook may be defined as a zone hook,
2632    //        ex) E_ZONE_HOOK_EVAL_VISIBILITY_END or E_ZONE_HOOK_EVAL_VISIBILITY_DONE.
2633    _e_client_hook_call(E_CLIENT_HOOK_EVAL_VISIBILITY_END, NULL);
2634 }
2635
2636 static Eina_Bool
2637 _e_client_transform_core_check_change(E_Client *ec)
2638 {
2639    int w = 0;
2640    int h = 0;
2641    Eina_Bool check = EINA_FALSE;
2642    if (!ec) return EINA_FALSE;
2643
2644    if (ec->frame)
2645      evas_object_geometry_get(ec->frame, 0, 0, &w, &h);
2646
2647    // check client position or size change
2648    if (ec->x != ec->transform_core.backup.client_x ||
2649        ec->y != ec->transform_core.backup.client_y ||
2650        ec->w != ec->transform_core.backup.client_w ||
2651        ec->h != ec->transform_core.backup.client_h ||
2652        w     != ec->transform_core.backup.frame_w ||
2653        h     != ec->transform_core.backup.frame_h ||
2654        ec->argb != ec->transform_core.backup.argb)
2655      {
2656         check = EINA_TRUE;
2657         ec->transform_core.backup.client_x = ec->x;
2658         ec->transform_core.backup.client_y = ec->y;
2659         ec->transform_core.backup.client_w = ec->w;
2660         ec->transform_core.backup.client_h = ec->h;
2661         ec->transform_core.backup.frame_w = w;
2662         ec->transform_core.backup.frame_h = h;
2663         ec->transform_core.backup.argb = ec->argb;
2664      }
2665
2666    // check new transform or del transform
2667    if (ec->transform_core.changed)
2668      {
2669         check = EINA_TRUE;
2670         ec->transform_core.changed = EINA_FALSE;
2671      }
2672
2673    // check each transform change
2674    if (ec->transform_core.transform_list)
2675      {
2676         Eina_List *l;
2677         Eina_List *l_next;
2678         E_Util_Transform *transform;
2679
2680         EINA_LIST_FOREACH_SAFE(ec->transform_core.transform_list, l, l_next, transform)
2681           {
2682              // del transform check
2683              if (e_util_transform_ref_count_get(transform) <= 1)
2684                {
2685                   ec->transform_core.transform_list = eina_list_remove(ec->transform_core.transform_list, transform);
2686                   e_util_transform_unref(transform);
2687                   check = EINA_TRUE;
2688                   continue;
2689                }
2690
2691              // transform change test
2692              if (e_util_transform_change_get(transform))
2693                {
2694                   check = EINA_TRUE;
2695                   e_util_transform_change_unset(transform);
2696                }
2697           }
2698      }
2699
2700    if (e_comp_wl_subsurface_check(ec))
2701      {
2702         // check parent matrix change
2703         E_Client *parent = e_comp_wl_subsurface_parent_get(ec);
2704         if (parent && parent->transform_core.result.enable)
2705           {
2706              ec->transform_core.parent.enable = EINA_TRUE;
2707
2708              if (!e_util_transform_matrix_equal_check(&ec->transform_core.parent.matrix,
2709                                                       &parent->transform_core.result.matrix))
2710                {
2711                   check = EINA_TRUE;
2712                   ec->transform_core.parent.matrix = parent->transform_core.result.matrix;
2713                }
2714              if (memcmp(&ec->transform_core.parent.zoom, &parent->transform_core.result.transform.zoom, sizeof(E_Util_Transform_Zoom)) != 0)
2715                {
2716                   check = EINA_TRUE;
2717                   ec->transform_core.parent.zoom = parent->transform_core.result.transform.zoom;
2718                }
2719           }
2720         else if (ec->transform_core.parent.enable)
2721           {
2722              ec->transform_core.parent.enable = EINA_FALSE;
2723              e_util_transform_matrix_load_identity(&ec->transform_core.parent.matrix);
2724              ec->transform_core.parent.zoom.zoom_x = 1.0;
2725              ec->transform_core.parent.zoom.zoom_y = 1.0;
2726              ec->transform_core.parent.zoom.cx = 0;
2727              ec->transform_core.parent.zoom.cy = 0;
2728              check = EINA_TRUE;
2729           }
2730      }
2731
2732    return check;
2733 }
2734
2735 static void
2736 _e_client_transform_core_boundary_update(E_Client *ec, E_Util_Transform_Rect_Vertex *vertices)
2737 {
2738    int minx = 99999, miny = 99999;
2739    int maxx = -99999, maxy = -99999;
2740    int x, y;
2741    int i;
2742
2743    if (!ec) return;
2744    if (!ec->frame) return;
2745    if (!ec->transform_core.result.enable) return;
2746    if (!vertices) return;
2747
2748    for (i = 0; i < 4; ++i)
2749      {
2750         x = 0;
2751         y = 0;
2752
2753         e_util_transform_vertices_pos_round_get(vertices, i, &x, &y, 0, 0);
2754
2755         if (x < minx) minx = x;
2756         if (y < miny) miny = y;
2757         if (x > maxx) maxx = x;
2758         if (y > maxy) maxy = y;
2759      }
2760
2761    ec->transform_core.result.boundary.x = minx;
2762    ec->transform_core.result.boundary.y = miny;
2763    ec->transform_core.result.boundary.w = maxx - minx;
2764    ec->transform_core.result.boundary.h = maxy - miny;
2765
2766    ELOGF("COMP", "[Transform][boundary][%d %d %d %d]",
2767          ec,
2768          ec->transform_core.result.boundary.x,
2769          ec->transform_core.result.boundary.y,
2770          ec->transform_core.result.boundary.w,
2771          ec->transform_core.result.boundary.h);
2772 }
2773
2774 static E_Map *
2775 _e_client_transform_core_map_new(Evas_Object *obj,
2776                                  E_Util_Transform_Rect_Vertex *vertices,
2777                                  E_Util_Transform *transform,
2778                                  Eina_Bool direct_render)
2779 {
2780    E_Map *map;
2781    int i;
2782    int x, y;
2783    double u, v;
2784
2785    map = e_map_new_with_direct_render(direct_render);
2786    EINA_SAFETY_ON_NULL_RETURN_VAL(map, NULL);
2787
2788    e_map_util_points_populate_from_object_full(map, obj, 0);
2789    e_map_util_points_color_set(map, 255, 255, 255, 255);
2790
2791    for (i = 0 ; i < 4 ; ++i)
2792      {
2793         x = 0;
2794         y = 0;
2795
2796         e_util_transform_vertices_pos_round_get(vertices, i, &x, &y, 0, 0);
2797         e_map_point_coord_set(map, i, x, y, 1.0);
2798
2799         if (transform && e_util_transform_texcoord_flag_get(transform))
2800           {
2801              u = 0.0;
2802              v = 0.0;
2803
2804              e_util_transform_texcoord_get(transform, i, &u, &v);
2805              e_map_point_image_uv_set(map, i, u, v);
2806           }
2807      }
2808
2809    return map;
2810 }
2811
2812 static void
2813 _e_client_transform_core_vertices_apply_with_zoom(E_Client *ec,
2814                                         Evas_Object *obj,
2815                                         E_Util_Transform_Rect_Vertex *vertices,
2816                                         E_Util_Transform *transform,
2817                                         E_Util_Transform_Zoom zoom)
2818 {
2819    E_Map *map = NULL;
2820
2821    if (!obj) return;
2822
2823    if (vertices)
2824      {
2825         map = _e_client_transform_core_map_new(obj, vertices, transform,
2826                                                ec->transform_core.direct_render);
2827         EINA_SAFETY_ON_NULL_RETURN(map);
2828
2829         e_map_util_zoom(map, zoom.zoom_x, zoom.zoom_y, zoom.cx, zoom.cy);
2830
2831         e_comp_object_map_set(obj, map);
2832
2833         if (ec->transform_core.activate)
2834           e_comp_object_map_enable_set(obj, EINA_TRUE);
2835         else
2836           e_comp_object_map_enable_set(obj, EINA_FALSE);
2837
2838         e_map_free(map);
2839      }
2840    else
2841      evas_object_map_enable_set(obj, EINA_FALSE);
2842 }
2843
2844 static void
2845 _e_client_transform_core_vertices_apply(E_Client *ec,
2846                                         Evas_Object *obj,
2847                                         E_Util_Transform_Rect_Vertex *vertices,
2848                                         E_Util_Transform *transform)
2849 {
2850    E_Map *map = NULL;
2851
2852    if (!obj) return;
2853
2854    if (vertices)
2855      {
2856         map = _e_client_transform_core_map_new(obj, vertices, transform,
2857                                                ec->transform_core.direct_render);
2858         EINA_SAFETY_ON_NULL_RETURN(map);
2859
2860         e_comp_object_map_set(obj, map);
2861
2862         if (ec->transform_core.activate)
2863           e_comp_object_map_enable_set(obj, EINA_TRUE);
2864         else
2865           e_comp_object_map_enable_set(obj, EINA_FALSE);
2866
2867         e_map_free(map);
2868      }
2869    else
2870      evas_object_map_enable_set(obj, EINA_FALSE);
2871 }
2872
2873 static void
2874 _e_client_transform_core_sub_update(E_Client *ec, E_Util_Transform_Rect_Vertex *vertices)
2875 {
2876    Eina_List *l;
2877    E_Client *subc;
2878    E_Comp_Wl_Client_Data *cdata;
2879
2880    if (!ec) return;
2881
2882    cdata = e_client_cdata_get(ec);
2883    if (!cdata) return;
2884
2885    EINA_LIST_FOREACH(cdata->sub.list, l, subc)
2886       e_client_transform_core_update(subc);
2887
2888    EINA_LIST_FOREACH(cdata->sub.below_list, l, subc)
2889       e_client_transform_core_update(subc);
2890 }
2891
2892 static void
2893 _e_client_cb_hook_shell_surface_ready(void *data EINA_UNUSED, E_Client *ec)
2894 {
2895    if (EINA_UNLIKELY(!ec))
2896      return;
2897
2898    _e_client_aux_hint_eval(ec);
2899 }
2900
2901 // FIXME: This function has to be deleted and it remains for the backward compatibility.
2902 //        Please find and fix to use e_comp_visibility_calculation_set(EINA_TRUE)
2903 //        instead of e_client_visibility_calculate() call at e20 modules.
2904 E_API void
2905 e_client_visibility_calculate(void)
2906 {
2907    e_comp_visibility_calculation_set(EINA_TRUE);
2908 }
2909
2910 E_API void
2911 e_client_visibility_skip_set(E_Client *ec, Eina_Bool skip)
2912 {
2913    if (!ec) return;
2914
2915    ELOGF("POL_VIS", "visibility skip set to %d", ec, skip);
2916    ec->visibility.skip = skip;
2917 }
2918
2919 E_API void
2920 e_client_post_raise_lower_set(E_Client *ec, Eina_Bool raise_set, Eina_Bool lower_set)
2921 {
2922    if (!ec) return;
2923
2924    ec->post_raise = raise_set;
2925    ec->post_lower = lower_set;
2926 }
2927
2928 E_API Eina_Bool
2929 e_client_first_mapped_get(E_Client *ec)
2930 {
2931    if (!ec) return EINA_FALSE;
2932
2933    return ec->first_mapped;
2934 }
2935
2936 EINTERN Eina_Bool e_client_mapped_get(E_Client *ec)
2937 {
2938    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
2939    EINA_SAFETY_ON_NULL_RETURN_VAL(cdata, EINA_FALSE);
2940
2941   return cdata->mapped;
2942 }
2943
2944 EINTERN void
2945 e_client_mapped_set(E_Client *ec, Eina_Bool set)
2946 {
2947    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
2948    EINA_SAFETY_ON_NULL_RETURN(cdata);
2949
2950    cdata->mapped = set;
2951 }
2952
2953
2954 ////////////////////////////////////////////////
2955 EINTERN Eina_Bool
2956 e_client_clients_hash_exist()
2957 {
2958   int pix_id;
2959
2960   for (pix_id = 0; pix_id < E_PIXMAP_TYPE_MAX; pix_id++)
2961     {
2962       if (eina_hash_population(clients_hash[pix_id]))
2963         return EINA_TRUE;
2964     }
2965
2966   return EINA_FALSE;
2967 }
2968
2969 EINTERN void
2970 e_client_idler_before(Eina_Bool *check_focus)
2971 {
2972    const Eina_List *l;
2973    E_Client *ec;
2974
2975    *check_focus = EINA_FALSE;
2976
2977    if (!e_client_clients_hash_exist()) return;
2978
2979    TRACE_DS_BEGIN(CLIENT:IDLE BEFORE);
2980
2981    EINA_LIST_FOREACH(e_comp->clients, l, ec)
2982      {
2983         // pass 1 - eval0. fetch properties on new or on change and
2984         // call hooks to decide what to do - maybe move/resize
2985         if (ec->ignored || (!ec->changed)) continue;
2986
2987         wl_signal_emit_mutable(&PRI(ec)->events.eval_pre_fetch, NULL);
2988         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_PRE_FETCH, ec)) continue;
2989
2990
2991         /* FETCH is hooked by the compositor to get client hints */
2992         wl_signal_emit_mutable(&PRI(ec)->events.eval_fetch, NULL);
2993         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_FETCH, ec)) continue;
2994
2995         if (ec->new_client)
2996           {
2997              e_client_type_update(ec);
2998           }
2999
3000         /* PRE_POST_FETCH calls e_remember apply for new client */
3001         wl_signal_emit_mutable(&PRI(ec)->events.eval_pre_post_fetch, NULL);
3002         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_PRE_POST_FETCH, ec)) continue;
3003         wl_signal_emit_mutable(&PRI(ec)->events.eval_post_fetch, NULL);
3004         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_POST_FETCH, ec)) continue;
3005         wl_signal_emit_mutable(&PRI(ec)->events.eval_pre_frame_assign, NULL);
3006         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_PRE_FRAME_ASSIGN, ec)) continue;
3007
3008         wl_signal_emit_mutable(&PRI(ec)->events.eval_post_frame_assign, NULL);
3009         _e_client_hook_call(E_CLIENT_HOOK_EVAL_POST_FRAME_ASSIGN, ec);
3010      }
3011    // pass 2 - show and hide windows needing hide and eval (main eval)
3012    E_CLIENT_FOREACH(ec)
3013      {
3014         if (e_object_is_del(E_OBJECT(ec))) continue;
3015         if (ec->ignored)
3016           {
3017              // ignored client but needing eval (aux hint) such as remote surfaces
3018              if (ec->changed)
3019                {
3020                   E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
3021                   if (cdata && cdata->first_commit)
3022                     _e_client_aux_hint_eval(ec);
3023                }
3024              continue;
3025           }
3026
3027         if (ec->changes.visible)
3028           {
3029              if (ec->visible)
3030                {
3031                   if ((!ec->new_client) &&
3032                       (!ec->changes.pos) &&
3033                       (!ec->changes.size))
3034                     {
3035                        evas_object_show(ec->frame);
3036                        ec->changes.visible = !evas_object_visible_get(ec->frame);
3037                     }
3038                }
3039              else
3040                {
3041                   evas_object_hide(ec->frame);
3042                   ec->changes.visible = 0;
3043                }
3044           }
3045
3046         if (ec->changed)
3047           {
3048              _e_client_eval(ec);
3049              e_comp_visibility_calculation_set(EINA_TRUE);
3050              if (ec->changes.accepts_focus)
3051                *check_focus = EINA_TRUE;
3052              ec->changes.accepts_focus = 0;
3053           }
3054
3055         if ((ec->changes.visible) && (ec->visible) && (!ec->changed))
3056           {
3057              evas_object_show(ec->frame);
3058              ec->changes.visible = !evas_object_visible_get(ec->frame);
3059              ec->changed = ec->changes.visible;
3060              e_comp_visibility_calculation_set(EINA_TRUE);
3061           }
3062      }
3063
3064    TRACE_DS_END();
3065 }
3066
3067
3068 EINTERN Eina_Bool
3069 e_client_init(void)
3070 {
3071    int pix_id;
3072    for (pix_id = 0; pix_id < E_PIXMAP_TYPE_MAX; pix_id++)
3073      clients_hash[pix_id] = eina_hash_pointer_new(NULL);
3074
3075    E_COMP_WL_HOOK_APPEND(hooks, E_COMP_WL_HOOK_SHELL_SURFACE_READY, _e_client_cb_hook_shell_surface_ready, NULL);
3076
3077    E_EVENT_CLIENT_ADD = ecore_event_type_new();
3078    E_EVENT_CLIENT_REMOVE = ecore_event_type_new();
3079    E_EVENT_CLIENT_DESK_SET = ecore_event_type_new();
3080    E_EVENT_CLIENT_ZONE_SET = ecore_event_type_new();
3081    E_EVENT_CLIENT_RESIZE = ecore_event_type_new();
3082    E_EVENT_CLIENT_MOVE = ecore_event_type_new();
3083    E_EVENT_CLIENT_SHOW = ecore_event_type_new();
3084    E_EVENT_CLIENT_HIDE = ecore_event_type_new();
3085    E_EVENT_CLIENT_ICONIFY = ecore_event_type_new();
3086    E_EVENT_CLIENT_UNICONIFY = ecore_event_type_new();
3087    E_EVENT_CLIENT_STACK = ecore_event_type_new();
3088    E_EVENT_CLIENT_FOCUS_IN = ecore_event_type_new();
3089    E_EVENT_CLIENT_FOCUS_OUT = ecore_event_type_new();
3090    E_EVENT_CLIENT_PROPERTY = ecore_event_type_new();
3091    E_EVENT_CLIENT_FULLSCREEN = ecore_event_type_new();
3092    E_EVENT_CLIENT_UNFULLSCREEN = ecore_event_type_new();
3093 #ifdef _F_ZONE_WINDOW_ROTATION_
3094    E_EVENT_CLIENT_ROTATION_CHANGE_BEGIN = ecore_event_type_new();
3095    E_EVENT_CLIENT_ROTATION_CHANGE_CANCEL = ecore_event_type_new();
3096    E_EVENT_CLIENT_ROTATION_CHANGE_END = ecore_event_type_new();
3097    E_EVENT_CLIENT_ROTATION_GEOMETRY_SET = ecore_event_type_new();
3098 #endif
3099    E_EVENT_CLIENT_VISIBILITY_CHANGE = ecore_event_type_new();
3100    E_EVENT_CLIENT_BUFFER_CHANGE = ecore_event_type_new();
3101    E_EVENT_CLIENT_FOCUS_SKIP_SET = ecore_event_type_new();;
3102    E_EVENT_CLIENT_FOCUS_SKIP_UNSET = ecore_event_type_new();;
3103
3104    return (!!clients_hash[1]);
3105 }
3106
3107 EINTERN void
3108 e_client_shutdown(void)
3109 {
3110    int pix_id;
3111    for (pix_id = 0; pix_id < E_PIXMAP_TYPE_MAX; pix_id++)
3112      E_FREE_FUNC(clients_hash[pix_id], eina_hash_free);
3113
3114    E_FREE_LIST(hooks, e_comp_wl_hook_del);
3115    E_FREE_LIST(handlers, ecore_event_handler_del);
3116
3117 }
3118
3119 E_API void
3120 e_client_unignore(E_Client *ec)
3121 {
3122    E_OBJECT_CHECK(ec);
3123    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3124    if (!ec->ignored) return;
3125
3126    ec->ignored = 0;
3127    _e_client_event_add(ec);
3128 }
3129
3130 static E_Layer
3131 _e_client_convert_fullscreen_layer(int layer)
3132 {
3133    if (layer <= E_LAYER_CLIENT_NORMAL)
3134      return E_LAYER_CLIENT_NORMAL;
3135    else if (layer <= E_LAYER_CLIENT_ABOVE)
3136      return E_LAYER_CLIENT_ABOVE;
3137    else if (layer <= E_LAYER_CLIENT_EDGE)
3138      return E_LAYER_CLIENT_EDGE;
3139    else
3140      return E_LAYER_CLIENT_FULLSCREEN;
3141 }
3142
3143 E_API E_Client *
3144 e_client_new(E_Pixmap *cp, int first_map, int internal)
3145 {
3146    E_Client *ec;
3147    E_Pixmap_Type type;
3148
3149    type = e_pixmap_type_get(cp);
3150    if (type >= E_PIXMAP_TYPE_MAX) return NULL;
3151    if (eina_hash_find(clients_hash[type], &cp)) return NULL;
3152
3153    ec = E_OBJECT_ALLOC(E_Client, E_CLIENT_TYPE, _e_client_free);
3154    if (!ec) return NULL;
3155    e_object_del_func_set(E_OBJECT(ec), E_OBJECT_CLEANUP_FUNC(_e_client_del));
3156
3157    if (!_e_client_private_init(ec))
3158      {
3159         e_object_del(E_OBJECT(ec));
3160         return NULL;
3161      }
3162
3163    uuid_generate(ec->uuid);
3164
3165    ec->focus_policy_override = E_FOCUS_LAST;
3166    e_client_size_set(ec, 1, 1);
3167    ec->internal = internal;
3168
3169    ec->pixmap = cp;
3170    e_pixmap_client_set(cp, ec);
3171    ec->resize_mode = E_POINTER_RESIZE_NONE;
3172    ec->layer = E_LAYER_CLIENT_NORMAL;
3173    ec->first_mapped = EINA_FALSE;
3174    ec->post_raise = EINA_TRUE;
3175    ec->post_lower = EINA_FALSE;
3176    ec->animatable = EINA_TRUE;
3177    ec->maximize_type = e_config->maximize_policy & E_MAXIMIZE_TYPE;
3178    ec->fullscreen_layer = _e_client_convert_fullscreen_layer(e_config->fullscreen_layer);
3179
3180    /* FIXME: if first_map is 1 then we should ignore the first hide event
3181     * or ensure the window is already hidden and events flushed before we
3182     * create a border for it */
3183    if (first_map)
3184      {
3185         ec->changes.pos = 1;
3186         ec->re_manage = 1;
3187         // needed to be 1 for internal windw and on restart.
3188         // ec->ignore_first_unmap = 2;
3189      }
3190    ec->offer_resistance = 1;
3191    ec->new_client = 1;
3192    e_comp->new_clients++;
3193
3194    ec->exp_iconify.by_client = 0;
3195    ec->exp_iconify.not_raise = 0;
3196    ec->exp_iconify.skip_iconify = 0;
3197    ec->exp_iconify.skip_by_remote = 0;
3198    if (e_config->deiconify_approve)
3199      ec->exp_iconify.deiconify_update= 1;
3200    else
3201      ec->exp_iconify.deiconify_update= 0;
3202    if (e_config->use_buffer_flush)
3203      ec->exp_iconify.buffer_flush = 1;
3204    else
3205      ec->exp_iconify.buffer_flush = 0;
3206
3207    e_client_iconified_type_set(ec, E_ICONIFIED_TYPE_NONE);
3208
3209    wl_signal_emit_mutable(&PRI(ec)->events.new_client, NULL);
3210    if (!_e_client_hook_call(E_CLIENT_HOOK_NEW_CLIENT, ec))
3211      {
3212         /* delete the above allocated object */
3213         //e_object_del(E_OBJECT(ec));
3214         return NULL;
3215      }
3216
3217    _e_client_aux_hint_eval(ec);
3218
3219    ec->icccm.title = NULL;
3220    ec->icccm.name = NULL;
3221 #if defined(__cplusplus) || defined(c_plusplus)
3222    ec->icccm.cpp_class = NULL;
3223 #else
3224    ec->icccm.class = NULL;
3225 #endif
3226    ec->icccm.icon_name = NULL;
3227    ec->icccm.machine = NULL;
3228    ec->icccm.min_w = 1;
3229    ec->icccm.min_h = 1;
3230    ec->icccm.max_w = 32767;
3231    ec->icccm.max_h = 32767;
3232    ec->icccm.base_w = 0;
3233    ec->icccm.base_h = 0;
3234    ec->icccm.step_w = -1;
3235    ec->icccm.step_h = -1;
3236    ec->icccm.min_aspect = 0.0;
3237    ec->icccm.max_aspect = 0.0;
3238
3239    ec->netwm.pid = 0;
3240    ec->netwm.name = NULL;
3241    ec->netwm.icon_name = NULL;
3242    ec->netwm.desktop = 0;
3243    ec->netwm.state.modal = 0;
3244    ec->netwm.state.sticky = 0;
3245    ec->netwm.state.shaded = 0;
3246    ec->netwm.state.hidden = 0;
3247    ec->netwm.state.maximized_v = 0;
3248    ec->netwm.state.maximized_h = 0;
3249    ec->netwm.state.skip_taskbar = 0;
3250    ec->netwm.state.skip_pager = 0;
3251    ec->netwm.state.fullscreen = 0;
3252    ec->netwm.state.stacking = E_STACKING_NONE;
3253    ec->netwm.action.move = 0;
3254    ec->netwm.action.resize = 0;
3255    ec->netwm.action.minimize = 0;
3256    ec->netwm.action.shade = 0;
3257    ec->netwm.action.stick = 0;
3258    ec->netwm.action.maximized_h = 0;
3259    ec->netwm.action.maximized_v = 0;
3260    ec->netwm.action.fullscreen = 0;
3261    ec->netwm.action.change_desktop = 0;
3262    ec->netwm.action.close = 0;
3263    ec->netwm.opacity = 255;
3264
3265    ec->visibility.obscured = E_VISIBILITY_UNKNOWN;
3266    ec->visibility.opaque = -1;
3267    ec->visibility.changed = 0;
3268    ec->visibility.skip = 0;
3269    ec->visibility.last_sent_type = E_VISIBILITY_UNKNOWN;
3270
3271    ec->transform.zoom = 1.0;
3272    ec->transform.angle = 0.0;
3273    ec->transform_core.direct_render = EINA_TRUE;
3274    ec->transform_core.activate = EINA_TRUE;
3275
3276    ec->pointer_enter_sent = EINA_FALSE;
3277
3278    ec->acquire_fence_fd = -1;
3279
3280    EC_CHANGED(ec);
3281
3282    e_comp->clients = eina_list_append(e_comp->clients, ec);
3283    eina_hash_add(clients_hash[type], &ec->pixmap, ec);
3284
3285    ELOGF("COMP", "CLIENT ADD. cp:%p, argb:%d, internal:%d, ignored:%d", ec, cp, ec->argb, internal, ec->ignored);
3286    if (!ec->ignored)
3287      _e_client_event_add(ec);
3288    e_comp_object_client_add(ec);
3289    if (ec->frame)
3290      {
3291         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_SHOW, _e_client_cb_evas_show, ec);
3292         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_HIDE, _e_client_cb_evas_hide, ec);
3293         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_MOVE, _e_client_cb_evas_move, ec);
3294         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_RESIZE, _e_client_cb_evas_resize, ec);
3295         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_RESTACK, _e_client_cb_evas_restack, ec);
3296      }
3297
3298    wl_signal_emit_mutable(&PRI(ec)->events.new_client_post, NULL);
3299
3300 #ifdef _F_E_CLIENT_NEW_CLIENT_POST_HOOK_
3301    _e_client_hook_call(E_CLIENT_HOOK_NEW_CLIENT_POST, ec);
3302 #endif
3303
3304    ec->manage_resize.resize_obj = NULL;
3305    ec->manage_resize.x = ec->manage_resize.y = ec->manage_resize.w = ec->manage_resize.h = 0;
3306    ec->manage_resize.enable_aspect_ratio = EINA_FALSE;
3307    ec->manage_resize.aw = ec->manage_resize.ah = 0;
3308    ec->manage_resize.header_h = 0;
3309    ec->manage_resize.footer_h = 0;
3310
3311    ec->visibility.ignore_geometry = e_config->calc_vis_ignore_geometry;
3312
3313    return ec;
3314 }
3315
3316 E_API Eina_Bool e_client_is_internal(E_Client *ec)
3317 {
3318    E_OBJECT_CHECK_RETURN(ec, EINA_TRUE);
3319    return ec->internal;
3320 }
3321
3322 EINTERN void
3323 e_client_desk_iconify_skip_set(E_Client *ec, Eina_Bool skip)
3324 {
3325    if (!ec) return;
3326    ec->user_skip_winlist = skip;
3327 }
3328
3329 EINTERN Eina_Bool
3330 e_client_desk_iconify_skip_get(E_Client *ec)
3331 {
3332    if (!ec) return EINA_FALSE;
3333    return ec->user_skip_winlist;
3334 }
3335
3336 EINTERN Eina_Bool
3337 e_client_comp_grabbed_get(void)
3338 {
3339    return comp_grabbed;
3340 }
3341
3342 EINTERN E_Client *
3343 e_client_action_get(void)
3344 {
3345    return action_client;
3346 }
3347
3348
3349 //////////////////////////////////////////////////////////
3350
3351 EINTERN void
3352 e_client_mouse_in(E_Client *ec, int x, int y)
3353 {
3354    E_Desk *desk;
3355
3356    if (comp_grabbed) return;
3357    if (e_object_is_del(E_OBJECT(ec))) return;
3358    desk = e_comp_desk_find_by_ec(ec);
3359    if (desk && desk->animate_count) return;
3360    ec->mouse.current.mx = x;
3361    ec->mouse.current.my = y;
3362    ec->mouse.in = 1;
3363
3364    wl_signal_emit_mutable(&PRI(ec)->events.mouse_in, NULL);
3365 }
3366
3367 EINTERN void
3368 e_client_mouse_out(E_Client *ec, int x, int y)
3369 {
3370    E_Desk *desk;
3371
3372    if (comp_grabbed) return;
3373    if (ec->fullscreen) return;
3374    if (e_object_is_del(E_OBJECT(ec))) return;
3375    desk = e_comp_desk_find_by_ec(ec);
3376    if (desk && desk->animate_count) return;
3377
3378    ec->mouse.current.mx = x;
3379    ec->mouse.current.my = y;
3380    ec->mouse.in = 0;
3381
3382    wl_signal_emit_mutable(&PRI(ec)->events.mouse_out, NULL);
3383 }
3384
3385 EINTERN void
3386 e_client_mouse_wheel(E_Client *ec, Evas_Point *output, E_Binding_Event_Wheel *ev)
3387 {
3388    EINA_SAFETY_ON_NULL_RETURN(ec);
3389    if (action_client) return;
3390    ec->mouse.current.mx = output->x;
3391    ec->mouse.current.my = output->y;
3392 }
3393
3394 EINTERN void
3395 e_client_mouse_down(E_Client *ec, int button, Evas_Point *output, E_Binding_Event_Mouse_Button *ev)
3396 {
3397    EINA_SAFETY_ON_NULL_RETURN(ec);
3398
3399    if (action_client || ec->iconic || e_client_util_ignored_get(ec)) return;
3400    if ((button >= 1) && (button <= 3))
3401      {
3402         ec->mouse.last_down[button - 1].mx = output->x;
3403         ec->mouse.last_down[button - 1].my = output->y;
3404         ec->mouse.last_down[button - 1].x = ec->x;
3405         ec->mouse.last_down[button - 1].y = ec->y;
3406         ec->mouse.last_down[button - 1].w = ec->w;
3407         ec->mouse.last_down[button - 1].h = ec->h;
3408      }
3409    else
3410      {
3411         ec->moveinfo.down.x = ec->x;
3412         ec->moveinfo.down.y = ec->y;
3413         ec->moveinfo.down.w = ec->w;
3414         ec->moveinfo.down.h = ec->h;
3415      }
3416    ec->mouse.current.mx = output->x;
3417    ec->mouse.current.my = output->y;
3418    if ((button >= 1) && (button <= 3))
3419      {
3420         ec->mouse.last_down[button - 1].mx = output->x;
3421         ec->mouse.last_down[button - 1].my = output->y;
3422         ec->mouse.last_down[button - 1].x = ec->x;
3423         ec->mouse.last_down[button - 1].y = ec->y;
3424         ec->mouse.last_down[button - 1].w = ec->w;
3425         ec->mouse.last_down[button - 1].h = ec->h;
3426      }
3427    else
3428      {
3429         ec->moveinfo.down.x = ec->x;
3430         ec->moveinfo.down.y = ec->y;
3431         ec->moveinfo.down.w = ec->w;
3432         ec->moveinfo.down.h = ec->h;
3433      }
3434    ec->mouse.current.mx = output->x;
3435    ec->mouse.current.my = output->y;
3436
3437    wl_signal_emit_mutable(&PRI(ec)->events.mouse_down, NULL);
3438 }
3439
3440 EINTERN void
3441 e_client_mouse_up(E_Client *ec, int button, Evas_Point *output, E_Binding_Event_Mouse_Button* ev)
3442 {
3443    EINA_SAFETY_ON_NULL_RETURN(ec);
3444    if (ec->iconic || e_client_util_ignored_get(ec)) return;
3445    if ((button >= 1) && (button <= 3))
3446      {
3447         ec->mouse.last_up[button - 1].mx = output->x;
3448         ec->mouse.last_up[button - 1].my = output->y;
3449         ec->mouse.last_up[button - 1].x = ec->x;
3450         ec->mouse.last_up[button - 1].y = ec->y;
3451      }
3452    ec->mouse.current.mx = output->x;
3453    ec->mouse.current.my = output->y;
3454    /* also we don't pass the same params that went in - then again that */
3455    /* should be ok as we are just ending the action if it has an end */
3456    if (ec->cur_mouse_action)
3457      {
3458         if (ec->cur_mouse_action->func.end_mouse)
3459           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", ev);
3460         else if (ec->cur_mouse_action->func.end)
3461           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
3462         e_object_unref(E_OBJECT(ec->cur_mouse_action));
3463         ec->cur_mouse_action = NULL;
3464      }
3465
3466    if ((button >= 1) && (button <= 3))
3467      {
3468         ec->mouse.last_up[button - 1].mx = output->x;
3469         ec->mouse.last_up[button - 1].my = output->y;
3470         ec->mouse.last_up[button - 1].x = ec->x;
3471         ec->mouse.last_up[button - 1].y = ec->y;
3472      }
3473 }
3474
3475 E_API void
3476 e_client_stay_within_canvas_margin(E_Client *ec)
3477 {
3478    int new_x = ec->x;
3479    int new_y = ec->y;
3480
3481    if (ec->floating)
3482      {
3483         _e_client_stay_within_canvas_margin(ec, ec->x, ec->y, &new_x, &new_y);
3484
3485         if ((ec->x != new_x) || (ec->y != new_y))
3486           evas_object_move(ec->frame, new_x, new_y);
3487      }
3488 }
3489
3490 EINTERN void
3491 e_client_mouse_move(E_Client *ec, Evas_Point *output)
3492 {
3493    EINA_SAFETY_ON_NULL_RETURN(ec);
3494    if (ec->iconic || e_client_util_ignored_get(ec)) return;
3495    ec->mouse.current.mx = output->x;
3496    ec->mouse.current.my = output->y;
3497    if (e_client_util_moving_get(ec))
3498      {
3499         _e_client_move_handle(ec);
3500      }
3501    else if (e_client_util_resizing_get(ec))
3502      {
3503         _e_client_resize_handle(ec);
3504      }
3505 }
3506 ///////////////////////////////////////////////////////
3507
3508 EINTERN void
3509 e_client_res_change_geometry_save(E_Client *ec)
3510 {
3511    E_OBJECT_CHECK(ec);
3512    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3513
3514    if (ec->pre_res_change.valid) return;
3515    ec->pre_res_change.valid = 1;
3516    ec->pre_res_change.x = ec->x;
3517    ec->pre_res_change.y = ec->y;
3518    ec->pre_res_change.w = ec->w;
3519    ec->pre_res_change.h = ec->h;
3520    ec->pre_res_change.saved.x = ec->saved.x;
3521    ec->pre_res_change.saved.y = ec->saved.y;
3522    ec->pre_res_change.saved.w = ec->saved.w;
3523    ec->pre_res_change.saved.h = ec->saved.h;
3524 }
3525
3526 EINTERN void
3527 e_client_res_change_geometry_restore(E_Client *ec)
3528 {
3529    E_Zone *zone;
3530
3531    struct
3532    {
3533       unsigned char valid : 1;
3534       int           x, y, w, h;
3535       struct
3536       {
3537          int x, y, w, h;
3538       } saved;
3539    } pre_res_change;
3540
3541    E_OBJECT_CHECK(ec);
3542    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3543    if (!ec->pre_res_change.valid) return;
3544    if (ec->new_client) return;
3545
3546    zone = e_comp_zone_find_by_ec(ec);
3547    if (!zone) return;
3548
3549    memcpy(&pre_res_change, &ec->pre_res_change, sizeof(pre_res_change));
3550
3551    if (ec->fullscreen)
3552      {
3553         e_client_unfullscreen(ec);
3554         e_client_fullscreen(ec, e_config->fullscreen_policy);
3555      }
3556    else if (ec->maximized != E_MAXIMIZE_NONE)
3557      {
3558         E_Maximize max;
3559
3560         max = ec->maximized;
3561         e_client_unmaximize(ec, E_MAXIMIZE_BOTH);
3562         e_client_maximize(ec, max);
3563      }
3564    else
3565      {
3566         int x, y, w, h, zx, zy, zw, zh;
3567
3568         ec->saved.x = ec->pre_res_change.saved.x;
3569         ec->saved.y = ec->pre_res_change.saved.y;
3570         ec->saved.w = ec->pre_res_change.saved.w;
3571         ec->saved.h = ec->pre_res_change.saved.h;
3572
3573         e_zone_useful_geometry_get(zone, &zx, &zy, &zw, &zh);
3574
3575         if (ec->saved.w > zw)
3576           ec->saved.w = zw;
3577         if ((ec->saved.x + ec->saved.w) > (zx + zw))
3578           ec->saved.x = zx + zw - ec->saved.w;
3579
3580         if (ec->saved.h > zh)
3581           ec->saved.h = zh;
3582         if ((ec->saved.y + ec->saved.h) > (zy + zh))
3583           ec->saved.y = zy + zh - ec->saved.h;
3584
3585         x = ec->pre_res_change.x;
3586         y = ec->pre_res_change.y;
3587         w = ec->pre_res_change.w;
3588         h = ec->pre_res_change.h;
3589         if (w > zw)
3590           w = zw;
3591         if (h > zh)
3592           h = zh;
3593         if ((x + w) > (zx + zw))
3594           x = zx + zw - w;
3595         if ((y + h) > (zy + zh))
3596           y = zy + zh - h;
3597         evas_object_geometry_set(ec->frame, x, y, w, h);
3598      }
3599    memcpy(&ec->pre_res_change, &pre_res_change, sizeof(pre_res_change));
3600 }
3601
3602 EINTERN void
3603 e_client_pos_set(E_Client *ec, int x, int y)
3604 {
3605    if (!ec) return;
3606    ec->x = x;
3607    ec->y = y;
3608 }
3609
3610 EINTERN void
3611 e_client_pos_get(E_Client *ec, int *x, int *y)
3612 {
3613    int ex = 0;
3614    int ey = 0;
3615
3616    if (ec)
3617      {
3618         ex = ec->x;
3619         ey = ec->y;
3620      }
3621
3622    if (x) *x = ex;
3623    if (y) *y = ey;
3624 }
3625
3626 E_API void
3627 e_client_size_set(E_Client *ec, int w, int h)
3628 {
3629    if (!ec) return;
3630    ec->w = w;
3631    ec->h = h;
3632 }
3633
3634 E_API void
3635 e_client_size_get(E_Client *ec, int *w, int *h)
3636 {
3637    int ew = 0;
3638    int eh = 0;
3639
3640    if (ec)
3641      {
3642         ew = ec->w;
3643         eh = ec->h;
3644      }
3645
3646    if (w) *w = ew;
3647    if (h) *h = eh;
3648 }
3649
3650 E_API void
3651 e_client_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
3652 {
3653    int gx = 0;
3654    int gy = 0;
3655    int gw = 0;
3656    int gh = 0;
3657
3658    E_OBJECT_CHECK(ec);
3659    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3660
3661    if (e_client_transform_core_enable_get(ec))
3662      {
3663         gx = ec->transform_core.result.boundary.x;
3664         gy = ec->transform_core.result.boundary.y;
3665         gw = ec->transform_core.result.boundary.w;
3666         gh = ec->transform_core.result.boundary.h;
3667      }
3668    else
3669      {
3670         if (ec->frame)
3671           {
3672              evas_object_geometry_get(ec->frame, &gx, &gy, &gw, &gh);
3673              if (gw == 0 && gh == 0)
3674                {
3675                   /* In this case, there is no image buffer in e_comp_object, thus it
3676                    * should return geometry value of ec itself. It usually happens if
3677                    * new ec is not mapped yet.
3678                    */
3679                   gw = ec->w;
3680                   gh = ec->h;
3681                   gx = ec->x;
3682                   gy = ec->y;
3683                }
3684           }
3685         else
3686           {
3687              gx = ec->x;
3688              gy = ec->y;
3689              gw = ec->w;
3690              gh = ec->h;
3691           }
3692      }
3693
3694    if (x) *x = gx;
3695    if (y) *y = gy;
3696    if (w) *w = gw;
3697    if (h) *h = gh;
3698 }
3699
3700 E_API E_Client *
3701 e_client_above_get(const E_Client *ec)
3702 {
3703    unsigned int x;
3704    E_Client *ec2;
3705
3706    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
3707    if (EINA_INLIST_GET(ec)->next) //check current layer
3708      {
3709         EINA_INLIST_FOREACH(EINA_INLIST_GET(ec)->next, ec2)
3710           {
3711              if (ec == ec2)
3712                {
3713                   ELOGF("FATAL", "CHECK the ec inlist next", ec);
3714                   continue;
3715                }
3716              if (!e_object_is_del(E_OBJECT(ec2)))
3717                return ec2;
3718           }
3719      }
3720    if (ec->layer == E_LAYER_CLIENT_CURSOR) return NULL;
3721    if (e_comp_canvas_client_layer_map(ec->layer) == 9999) return NULL;
3722
3723    g_rec_mutex_lock(&e_comp->ec_list_mutex);
3724    /* go up the layers until we find one */
3725    for (x = e_comp_canvas_layer_map(ec->layer) + 1; x <= e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x++)
3726      {
3727         if (!e_comp->layers[x].clients) continue;
3728         EINA_INLIST_FOREACH(e_comp->layers[x].clients, ec2)
3729           {
3730              if (ec == ec2)
3731                {
3732                   ELOGF("FATAL", "EC exist above layer. ec layer_map:%d, cur layer_map:%d",
3733                         ec, e_comp_canvas_layer_map(ec->layer), x);
3734                   continue;
3735                }
3736              if (!e_object_is_del(E_OBJECT(ec2)))
3737                {
3738                   g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3739                   return ec2;
3740                }
3741           }
3742      }
3743    g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3744
3745    return NULL;
3746 }
3747
3748 E_API E_Client *
3749 e_client_below_get(const E_Client *ec)
3750 {
3751    unsigned int x;
3752    E_Client *ec2;
3753    Eina_Inlist *l;
3754    E_Layer ec_layer, ec_layer_cw;
3755    int cw_layer;
3756
3757    E_OBJECT_CHECK_RETURN(ec, NULL);
3758    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, NULL);
3759
3760    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
3761    if (EINA_INLIST_GET(ec)->prev) //check current layer
3762      {
3763         for (l = EINA_INLIST_GET(ec)->prev; l; l = l->prev)
3764           {
3765              ec2 = EINA_INLIST_CONTAINER_GET(l, E_Client);
3766              if (ec == ec2)
3767                {
3768                   ELOGF("FATAL", "CHECK the ec inlist prev", ec);
3769                   continue;
3770                }
3771              if (!e_object_is_del(E_OBJECT(ec2)))
3772                return ec2;
3773           }
3774      }
3775
3776    // check layer validation
3777    ec_layer = ec->layer;
3778    if (ec->layer_block || ec->layer_pending)
3779      {
3780         cw_layer = e_comp_object_layer_get(ec->frame);
3781         if (cw_layer >= 0)
3782           {
3783              ec_layer_cw = e_comp_canvas_layer_map_to(cw_layer);
3784              if (ec_layer != ec_layer_cw)
3785                {
3786                   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);
3787                   ec_layer = ec_layer_cw;
3788                }
3789           }
3790      }
3791
3792    if (ec_layer == E_LAYER_CLIENT_DESKTOP) return NULL;
3793    if (e_comp_canvas_client_layer_map(ec_layer) == 9999) return NULL;
3794
3795    /* go down the layers until we find one */
3796    x = e_comp_canvas_layer_map(ec_layer);
3797    if (x > 0) x--;
3798
3799    g_rec_mutex_lock(&e_comp->ec_list_mutex);
3800    for (; x >= e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x--)
3801      {
3802         if (!e_comp->layers[x].clients) continue;
3803         EINA_INLIST_REVERSE_FOREACH(e_comp->layers[x].clients, ec2)
3804           {
3805              if (ec == ec2)
3806                {
3807                   ELOGF("FATAL", "EC exist below layer. ec layer_map:%d, cur layer_map:%d",
3808                         ec, e_comp_canvas_layer_map(ec_layer), x);
3809                   continue;
3810                }
3811              if (!e_object_is_del(E_OBJECT(ec2)))
3812                {
3813                   g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3814                   return ec2;
3815                }
3816           }
3817      }
3818    g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3819
3820    return NULL;
3821 }
3822
3823 EINTERN E_Client *
3824 e_client_visible_above_get(E_Client *ec)
3825 {
3826    unsigned int x;
3827    E_Client *ec2;
3828
3829    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
3830    if (EINA_INLIST_GET(ec)->next) //check current layer
3831      {
3832         EINA_INLIST_FOREACH(EINA_INLIST_GET(ec)->next, ec2)
3833           {
3834              if (ec == ec2) continue;
3835              if ((!e_object_is_del(E_OBJECT(ec2))) &&
3836                  (!e_client_util_ignored_get(ec2)) &&
3837                  (ec2->visible) &&
3838                  (ec2->frame))
3839                return ec2;
3840           }
3841      }
3842
3843    if (ec->layer == E_LAYER_CLIENT_CURSOR) return NULL;
3844    if (e_comp_canvas_client_layer_map(ec->layer) == 9999) return NULL;
3845
3846    /* go up the layers until we find one */
3847    for (x = e_comp_canvas_layer_map(ec->layer) + 1; x <= e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x++)
3848      {
3849         if (!e_comp->layers[x].clients) continue;
3850         EINA_INLIST_FOREACH(e_comp->layers[x].clients, ec2)
3851           {
3852              if (ec == ec2) continue;
3853              if ((!e_object_is_del(E_OBJECT(ec2))) &&
3854                  (!e_client_util_ignored_get(ec2)) &&
3855                  (ec2->visible) &&
3856                  (ec2->frame))
3857                return ec2;
3858           }
3859      }
3860
3861    return NULL;
3862 }
3863
3864 EINTERN E_Client *
3865 e_client_visible_below_get(E_Client *ec)
3866 {
3867    unsigned int x;
3868    E_Client *ec2;
3869    Eina_Inlist *l;
3870    E_Layer ec_layer, ec_layer_cw;
3871    int cw_layer;
3872
3873    E_OBJECT_CHECK_RETURN(ec, NULL);
3874    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, NULL);
3875
3876    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
3877    if (EINA_INLIST_GET(ec)->prev) //check current layer
3878      {
3879         for (l = EINA_INLIST_GET(ec)->prev; l; l = l->prev)
3880           {
3881              ec2 = EINA_INLIST_CONTAINER_GET(l, E_Client);
3882              if (ec == ec2) continue;
3883              if ((!e_object_is_del(E_OBJECT(ec2))) &&
3884                  (!e_client_util_ignored_get(ec2)) &&
3885                  (ec2->visible) &&
3886                  (ec2->frame))
3887                return ec2;
3888           }
3889      }
3890
3891    // check layer validation
3892    ec_layer = ec->layer;
3893    if (ec->layer_block || ec->layer_pending)
3894      {
3895         cw_layer = e_comp_object_layer_get(ec->frame);
3896         if (cw_layer >= 0)
3897           {
3898              ec_layer_cw = e_comp_canvas_layer_map_to(cw_layer);
3899              if (ec_layer != ec_layer_cw)
3900                {
3901                   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);
3902                   ec_layer = ec_layer_cw;
3903                }
3904           }
3905      }
3906
3907    /* go down the layers until we find one */
3908    if (e_comp_canvas_layer_map(ec->layer) > e_comp_canvas_layer_map(E_LAYER_MAX)) return NULL;
3909    x = e_comp_canvas_layer_map(ec->layer);
3910    if (x > 0) x--;
3911
3912    for (; x >= e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x--)
3913      {
3914         if (!e_comp->layers[x].clients) continue;
3915         EINA_INLIST_REVERSE_FOREACH(e_comp->layers[x].clients, ec2)
3916           {
3917              if (ec == ec2) continue;
3918              if ((!e_object_is_del(E_OBJECT(ec2))) &&
3919                  (!e_client_util_ignored_get(ec2)) &&
3920                  (ec2->visible) &&
3921                  (ec2->frame))
3922                return ec2;
3923           }
3924      }
3925
3926    return NULL;
3927 }
3928
3929 E_API E_Client *
3930 e_client_bottom_get(void)
3931 {
3932    unsigned int x;
3933    g_rec_mutex_lock(&e_comp->ec_list_mutex);
3934    for (x = e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x <= e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x++)
3935      {
3936         E_Client *ec2;
3937
3938         if (!e_comp->layers[x].clients) continue;
3939         EINA_INLIST_FOREACH(e_comp->layers[x].clients, ec2)
3940           if (!e_object_is_del(E_OBJECT(ec2)))
3941             {
3942                g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3943                return ec2;
3944             }
3945      }
3946    g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3947
3948    return NULL;
3949 }
3950
3951 E_API E_Client *
3952 e_client_top_get(void)
3953 {
3954    unsigned int x;
3955    g_rec_mutex_lock(&e_comp->ec_list_mutex);
3956    for (x = e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x >= e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x--)
3957      {
3958         E_Client *ec2;
3959
3960         if (!e_comp->layers[x].clients) continue;
3961         EINA_INLIST_REVERSE_FOREACH(e_comp->layers[x].clients, ec2)
3962           if (!e_object_is_del(E_OBJECT(ec2)))
3963             {
3964                g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3965                return ec2;
3966             }
3967      }
3968    g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3969
3970    return NULL;
3971 }
3972
3973 EINTERN unsigned int
3974 e_clients_count(void)
3975 {
3976    return eina_list_count(e_comp->clients);
3977 }
3978
3979
3980 /**
3981  * Set a callback which will be called just prior to updating the
3982  * move coordinates for a border
3983  */
3984 EINTERN void
3985 e_client_move_intercept_cb_set(E_Client *ec, E_Client_Move_Intercept_Cb cb)
3986 {
3987    ec->move_intercept_cb = cb;
3988 }
3989
3990 ///////////////////////////////////////
3991
3992 E_API E_Client_Hook *
3993 e_client_hook_add(E_Client_Hook_Point hookpoint, E_Client_Hook_Cb func, const void *data)
3994 {
3995    E_Client_Hook *ch;
3996
3997    EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_CLIENT_HOOK_LAST, NULL);
3998    ch = E_NEW(E_Client_Hook, 1);
3999    if (!ch) return NULL;
4000    ch->hookpoint = hookpoint;
4001    ch->func = func;
4002    ch->data = (void*)data;
4003    _e_client_hooks[hookpoint] = eina_inlist_append(_e_client_hooks[hookpoint], EINA_INLIST_GET(ch));
4004    return ch;
4005 }
4006
4007 E_API void
4008 e_client_hook_del(E_Client_Hook *ch)
4009 {
4010    ch->delete_me = 1;
4011    if (_e_client_hooks_walking == 0)
4012      {
4013         _e_client_hooks[ch->hookpoint] = eina_inlist_remove(_e_client_hooks[ch->hookpoint], EINA_INLIST_GET(ch));
4014         free(ch);
4015      }
4016    else
4017      _e_client_hooks_delete++;
4018 }
4019
4020 ///////////////////////////////////////
4021
4022 E_API E_Client_Intercept_Hook *
4023 e_client_intercept_hook_add(E_Client_Intercept_Hook_Point hookpoint, E_Client_Intercept_Hook_Cb func, const void *data)
4024 {
4025    E_Client_Intercept_Hook *ch;
4026
4027    EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_CLIENT_INTERCEPT_HOOK_LAST, NULL);
4028    ch = E_NEW(E_Client_Intercept_Hook, 1);
4029    if (!ch) return NULL;
4030    ch->hookpoint = hookpoint;
4031    ch->func = func;
4032    ch->data = (void*)data;
4033    _e_client_intercept_hooks[hookpoint] = eina_inlist_append(_e_client_intercept_hooks[hookpoint], EINA_INLIST_GET(ch));
4034    return ch;
4035 }
4036
4037 E_API void
4038 e_client_intercept_hook_del(E_Client_Intercept_Hook *ch)
4039 {
4040    if (!ch) return;
4041
4042    ch->delete_me = 1;
4043    if (_e_client_intercept_hooks_walking == 0)
4044      {
4045         _e_client_intercept_hooks[ch->hookpoint] =
4046            eina_inlist_remove(_e_client_intercept_hooks[ch->hookpoint], EINA_INLIST_GET(ch));
4047         free(ch);
4048      }
4049    else
4050      _e_client_intercept_hooks_delete++;
4051 }
4052
4053 E_API void
4054 e_client_focus_latest_set(E_Client *ec)
4055 {
4056    EINA_SAFETY_ON_NULL_RETURN(ec);
4057
4058    wl_signal_emit_mutable(&PRI(ec)->events.focus_latest_set, NULL);
4059 }
4060
4061 E_API void
4062 e_client_focus_defer_set(E_Client *ec)
4063 {
4064    EINA_SAFETY_ON_NULL_RETURN(ec);
4065
4066    wl_signal_emit_mutable(&PRI(ec)->events.focus_defer_set, NULL);
4067 }
4068
4069 EINTERN void
4070 e_client_focused_set(E_Client *ec)
4071 {
4072    E_Client *focused_ec;
4073    E_Zone *zone;
4074
4075    if (ec)
4076      ELOGF("FOCUS", "CLIENT FOCUSED_SET : SET", ec);
4077    else
4078      ELOGF("FOCUS", "CLIENT FOCUSED_SET : UNSET", NULL);
4079
4080   focused_ec = e_comp_focused_ec_get();
4081   if (ec == focused_ec) return;
4082
4083    TRACE_DS_BEGIN(CLIENT:FOCUSED SET);
4084
4085    // unset the current focused_ec if focused_ec is not being deleted
4086    if (focused_ec)
4087      {
4088        if (!e_object_is_del(E_OBJECT(focused_ec)))
4089          {
4090             // FIXME: Remove focus_unset event of client.
4091             //        Instead, make zone focus_unset event and use it.
4092             wl_signal_emit_mutable(&PRI(focused_ec)->events.focus_unset, NULL);
4093             _e_client_hook_call(E_CLIENT_HOOK_FOCUS_UNSET, focused_ec);
4094
4095             if (e_object_ref_get(E_OBJECT(focused_ec)) > 0)
4096               {
4097                  _e_client_event_simple(focused_ec, E_EVENT_CLIENT_FOCUS_OUT);
4098                  e_client_urgent_set(focused_ec, focused_ec->icccm.urgent);
4099               }
4100          }
4101      }
4102
4103    // clear the current focused_ec when ec is NULL
4104    if (!ec)
4105      {
4106         zone = e_comp_zone_find_by_ec(focused_ec);
4107         e_zone_focus_clear(zone);
4108         TRACE_DS_END();
4109         return;
4110      }
4111
4112    // FIXME: Remove focus_set event of client.
4113    //        Instead, make zone focus_set event and use it.
4114    // set the new current focused_ec
4115    wl_signal_emit_mutable(&PRI(ec)->events.focus_set, NULL);
4116    _e_client_hook_call(E_CLIENT_HOOK_FOCUS_SET, ec);
4117
4118    // send the client_focuse_in event
4119    _e_client_event_simple(ec, E_EVENT_CLIENT_FOCUS_IN);
4120
4121    TRACE_DS_END();
4122 }
4123
4124 EINTERN void
4125 e_client_activate(E_Client *ec)
4126 {
4127    E_OBJECT_CHECK(ec);
4128    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4129
4130    TRACE_DS_BEGIN(CLIENT:ACTIVATE);
4131
4132    ELOGF("COMP", "Set launching flag..", ec);
4133    ec->launching = EINA_TRUE;
4134
4135    ec->exp_iconify.not_raise = 0;
4136
4137    if (ec->iconic)
4138      {
4139          if (!ec->lock_user_iconify)
4140            e_client_uniconify(ec);
4141      }
4142    ELOGF("COMP", "Un-Set ICONIFY BY CLIENT", ec);
4143    ec->exp_iconify.by_client = 0;
4144    e_client_iconified_type_set(ec, E_ICONIFIED_TYPE_NONE);
4145
4146    wl_signal_emit_mutable(&PRI(ec)->events.activate_done, NULL);
4147    _e_client_hook_call(E_CLIENT_HOOK_ACTIVATE_DONE, ec);
4148
4149    TRACE_DS_END();
4150 }
4151
4152 E_API E_Client *
4153 e_client_focused_get(void)
4154 {
4155    return e_comp_focused_ec_get();
4156 }
4157
4158 EINTERN Eina_List *
4159 e_client_lost_windows_get(E_Zone *zone)
4160 {
4161    Eina_List *list = NULL;
4162    const Eina_List *l;
4163    E_Client *ec;
4164    int loss_overlap = 5;
4165
4166    E_OBJECT_CHECK_RETURN(zone, NULL);
4167    E_OBJECT_TYPE_CHECK_RETURN(zone, E_ZONE_TYPE, NULL);
4168    EINA_LIST_FOREACH(e_comp->clients, l, ec)
4169      {
4170         if (!e_zone_has_ec(zone, ec)) continue;
4171         if (e_client_util_ignored_get(ec)) continue;
4172
4173         if (!E_INTERSECTS(zone->x + loss_overlap,
4174                           zone->y + loss_overlap,
4175                           zone->w - (2 * loss_overlap),
4176                           zone->h - (2 * loss_overlap),
4177                           ec->x, ec->y, ec->w, ec->h))
4178           {
4179              list = eina_list_append(list, ec);
4180           }
4181      }
4182    return list;
4183 }
4184
4185 ///////////////////////////////////////
4186
4187 EINTERN void
4188 e_client_maximized_geometry_set(E_Client *ec, int x, int y, int w, int h)
4189 {
4190    if (!ec) return;
4191
4192    ec->maximized_info.x = x;
4193    ec->maximized_info.y = y;
4194    ec->maximized_info.w = w;
4195    ec->maximized_info.h = h;
4196
4197    e_client_frame_geometry_set(ec, x, y, w, h);
4198 }
4199
4200 EINTERN void
4201 e_client_maximized_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
4202 {
4203    if (!ec) return;
4204
4205    if (x) *x = ec->maximized_info.x;
4206    if (y) *y = ec->maximized_info.y;
4207    if (w) *w = ec->maximized_info.w;
4208    if (h) *h = ec->maximized_info.h;
4209 }
4210
4211 EINTERN void
4212 e_client_maximize_update(E_Client *ec)
4213 {
4214    E_Maximize max;
4215
4216    E_OBJECT_CHECK(ec);
4217    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4218
4219    if (ec->maximized)
4220      {
4221         max = ec->maximized;
4222         ec->maximized = 0;
4223         e_client_maximize(ec, max);
4224      }
4225 }
4226
4227 E_API void
4228 e_client_maximize(E_Client *ec, E_Maximize max)
4229 {
4230    E_OBJECT_CHECK(ec);
4231    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4232
4233    if (!(max & E_MAXIMIZE_DIRECTION)) max |= E_MAXIMIZE_BOTH;
4234
4235    if ((ec->maximized & E_MAXIMIZE_DIRECTION) == (max & E_MAXIMIZE_DIRECTION))
4236      {
4237         if ((ec->maximized & E_MAXIMIZE_TYPE) == (max & E_MAXIMIZE_TYPE))
4238           return;
4239      }
4240
4241    if (ec->new_client)
4242      {
4243         ec->changes.need_maximize = 1;
4244         ec->maximized &= ~E_MAXIMIZE_TYPE;
4245         ec->maximized |= max;
4246         EC_CHANGED(ec);
4247         return;
4248      }
4249
4250    if (!ec->fullscreen)
4251      {
4252         // call the maximize hook of a client
4253         wl_signal_emit_mutable(&PRI(ec)->events.maximize, &max);
4254
4255         // store the E_Maximize value
4256         ec->maximized = max;
4257         ec->changes.need_unmaximize = 0;
4258
4259         evas_object_smart_callback_call(ec->frame, "maximize_done", NULL);
4260      }
4261    else
4262      {
4263         // store the E_Maximize value
4264         ec->maximized = max;
4265         ec->changes.need_unmaximize = 0;
4266      }
4267 }
4268
4269 E_API void
4270 e_client_unmaximize(E_Client *ec, E_Maximize max)
4271 {
4272    E_OBJECT_CHECK(ec);
4273    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4274
4275    if (!(max & E_MAXIMIZE_DIRECTION))
4276      {
4277         CRI("BUG: Unmaximize call without direction!");
4278         return;
4279      }
4280    if (ec->new_client)
4281      {
4282         ec->changes.need_unmaximize = 1;
4283         EC_CHANGED(ec);
4284         return;
4285      }
4286
4287    /* Remove directions not used */
4288    max &= (ec->maximized & E_MAXIMIZE_DIRECTION);
4289    /* Can only remove existing maximization directions */
4290    if (!max) return;
4291
4292    if (!ec->fullscreen)
4293      {
4294         evas_object_smart_callback_call(ec->frame, "unmaximize_pre", NULL);
4295
4296         // call the unmaximize hook of a client
4297         wl_signal_emit_mutable(&PRI(ec)->events.unmaximize, &max);
4298
4299         evas_object_smart_callback_call(ec->frame, "unmaximize_done", NULL);
4300      }
4301
4302    ec->maximized = E_MAXIMIZE_NONE;
4303    ec->changes.need_unmaximize = 0;
4304 }
4305
4306 EINTERN void
4307 e_client_fullscreen(E_Client *ec, E_Fullscreen policy)
4308 {
4309    E_OBJECT_CHECK(ec);
4310    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4311
4312    if (ec->fullscreen) return;
4313
4314    // call the fullscreen_pre hook of a client
4315    wl_signal_emit_mutable(&PRI(ec)->events.fullscreen_pre, NULL);
4316    _e_client_hook_call(E_CLIENT_HOOK_FULLSCREEN_PRE, ec);
4317
4318    if (ec->skip_fullscreen) return;
4319    if (ec->new_client)
4320      {
4321         ec->need_fullscreen = 1;
4322         return;
4323      }
4324
4325    ec->saved.layer = ec->layer;
4326    e_client_layer_set(ec, ec->fullscreen_layer);
4327
4328    ec->fullscreen = 1;
4329
4330    // call the fullscreen hook of a client
4331    wl_signal_emit_mutable(&PRI(ec)->events.fullscreen, &policy);
4332
4333    ec->fullscreen_policy = policy;
4334
4335    _e_client_event_simple(ec, E_EVENT_CLIENT_FULLSCREEN);
4336 }
4337
4338 EINTERN void
4339 e_client_unfullscreen(E_Client *ec)
4340 {
4341    E_OBJECT_CHECK(ec);
4342    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4343
4344    ec->need_fullscreen = 0;
4345
4346    if (!ec->fullscreen) return;
4347
4348    ec->fullscreen = 0;
4349
4350    E_Fullscreen policy = ec->fullscreen_policy;
4351
4352    // call the unfullscreen hook of a client
4353    wl_signal_emit_mutable(&PRI(ec)->events.unfullscreen, &policy);
4354
4355    e_client_layer_set(ec, ec->saved.layer);
4356
4357    ec->fullscreen_policy = E_FULLSCREEN_RESIZE;
4358
4359    _e_client_event_simple(ec, E_EVENT_CLIENT_UNFULLSCREEN);
4360 }
4361
4362 ///////////////////////////////////////
4363 EINTERN Eina_Bool
4364 e_client_is_parent_iconify_by_client(E_Client *ec)
4365 {
4366    E_Client *parent = ec->parent;
4367    if (!parent) return EINA_FALSE;
4368
4369    if ((parent->exp_iconify.type == E_ICONIFIED_TYPE_ICONIFY_BY_CLIENT) ||
4370        (parent->exp_iconify.type == E_ICONIFIED_TYPE_PARENT_ICONIFY_BY_CLIENT))
4371      return EINA_TRUE;
4372
4373    return EINA_FALSE;
4374 }
4375
4376 E_API void
4377 e_client_iconify(E_Client *ec)
4378 {
4379    E_OBJECT_CHECK(ec);
4380    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4381
4382    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
4383    Eina_Bool iconified_by_client = e_client_is_iconified_by_client(ec);
4384
4385    ELOGF("TZVIS", "ICONIFY  |iconic:%d  |argb:%d       |not_raise:%d   |by_client:%d, type:%d",
4386          ec, ec->iconic, ec->argb, (unsigned int)ec->exp_iconify.not_raise,
4387          ec->exp_iconify.by_client, ec->exp_iconify.type);
4388
4389    if (ec->iconic) return;
4390    if (ec->exp_iconify.skip_iconify && !iconified_by_client) return;
4391    if (ec->exp_iconify.skip_by_remote) return;
4392    if (!cdata || !cdata->mapped)
4393      {
4394         if (!iconified_by_client)
4395           {
4396              ELOGF("TZVIS", "Not mapped.. So, don't iconify", ec);
4397              return;
4398           }
4399         else
4400           {
4401              ELOGF("TZVIS", "Not mapped.. But, iconify by user request", ec);
4402           }
4403      }
4404
4405    TRACE_DS_BEGIN(CLIENT:ICONIFY);
4406
4407    wl_signal_emit_mutable(&PRI(ec)->events.iconify, NULL);
4408    _e_client_hook_call(E_CLIENT_HOOK_ICONIFY, ec);
4409
4410    TRACE_DS_END();
4411 }
4412
4413 E_API void
4414 e_client_uniconify(E_Client *ec)
4415 {
4416    E_Comp_Wl_Client_Data *cdata;
4417
4418    E_OBJECT_CHECK(ec);
4419    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4420
4421    cdata = e_client_cdata_get(ec);
4422
4423    ELOGF("TZVIS", "UNICONIFY|iconic:%d  |argb:%d       |not_raise:%d  |by_client:%d, type:%d |mapped:%d",
4424          ec, ec->iconic, ec->argb, (unsigned int)ec->exp_iconify.not_raise,
4425          ec->exp_iconify.by_client, ec->exp_iconify.type,
4426          cdata ? cdata->mapped : 0);
4427
4428    if (!ec->iconic) return;
4429
4430    TRACE_DS_BEGIN(CLIENT:UNICONIFY);
4431
4432     // call the uniconify hook of a client
4433    wl_signal_emit_mutable(&PRI(ec)->events.uniconify, NULL);
4434    _e_client_hook_call(E_CLIENT_HOOK_UNICONIFY, ec);
4435
4436    TRACE_DS_END();
4437 }
4438
4439 E_API void
4440 e_client_iconified_type_set(E_Client *ec, E_Iconified_Type type)
4441 {
4442    if (!ec) return;
4443    ec->exp_iconify.type = type;
4444 }
4445
4446 EINTERN E_Iconified_Type
4447 e_client_iconified_type_get(E_Client *ec)
4448 {
4449    if (!ec) return E_ICONIFIED_TYPE_NONE;
4450    return ec->exp_iconify.type;
4451 }
4452
4453 E_API Eina_Bool e_client_is_iconified_by_client(E_Client *ec)
4454 {
4455    if (!ec) return EINA_FALSE;
4456
4457    if (ec->exp_iconify.type == E_ICONIFIED_TYPE_ICONIFY_BY_CLIENT)
4458      return EINA_TRUE;
4459
4460    if (ec->exp_iconify.type == E_ICONIFIED_TYPE_DESK_ICONIFY_BY_CLIENT)
4461      return EINA_TRUE;
4462
4463    if (ec->exp_iconify.type == E_ICONIFIED_TYPE_PARENT_ICONIFY_BY_CLIENT)
4464      return EINA_TRUE;
4465
4466    if (ec->exp_iconify.by_client)
4467      {
4468         ELOGF("POL", "CHECK. mismatch value. by_client:%d, type:%d", ec, ec->exp_iconify.by_client, ec->exp_iconify.type);
4469         return EINA_TRUE;
4470      }
4471
4472    return EINA_FALSE;
4473 }
4474
4475 ///////////////////////////////////////
4476
4477 EINTERN void e_client_hide_by_request_set(E_Client *ec, Eina_Bool set)
4478 {
4479    API_ENTRY;
4480    priv->hide_by_request = set;
4481 }
4482
4483 EINTERN Eina_Bool e_client_hide_by_request_get(E_Client *ec)
4484 {
4485    API_ENTRY_VAL(EINA_FALSE);
4486    return priv->hide_by_request;
4487 }
4488
4489 EINTERN void
4490 e_client_urgent_set(E_Client *ec, Eina_Bool urgent)
4491 {
4492    E_OBJECT_CHECK(ec);
4493    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4494
4495    urgent = !!urgent;
4496    if (urgent == ec->urgent) return;
4497    _e_client_event_property(ec, E_CLIENT_PROPERTY_URGENCY);
4498    if (urgent && (!ec->focused) && (!ec->want_focus))
4499      {
4500         e_comp_object_signal_emit(ec->frame, "e,state,urgent", "e");
4501         ec->urgent = urgent;
4502      }
4503    else
4504      {
4505         e_comp_object_signal_emit(ec->frame, "e,state,not_urgent", "e");
4506         ec->urgent = 0;
4507      }
4508 }
4509
4510 ///////////////////////////////////////
4511
4512 EINTERN void
4513 e_client_stick(E_Client *ec)
4514 {
4515    E_OBJECT_CHECK(ec);
4516    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4517    if (ec->sticky) return;
4518
4519    // call the stick hook of a client
4520    wl_signal_emit_mutable(&PRI(ec)->events.stick, NULL);
4521
4522    // send the sticky property event of a client
4523    _e_client_event_property(ec, E_CLIENT_PROPERTY_STICKY);
4524 }
4525
4526 EINTERN void
4527 e_client_unstick(E_Client *ec)
4528 {
4529    E_OBJECT_CHECK(ec);
4530    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4531
4532    if (!ec->sticky) return;
4533
4534    // call the unstick hook of a client
4535    wl_signal_emit_mutable(&PRI(ec)->events.unstick, NULL);
4536
4537   // send the sticky property event of a client
4538    _e_client_event_property(ec, E_CLIENT_PROPERTY_STICKY);
4539 }
4540
4541 EINTERN void
4542 e_client_pinned_set(E_Client *ec, Eina_Bool set)
4543 {
4544    E_Layer layer;
4545
4546    EINA_SAFETY_ON_NULL_RETURN(ec);
4547    if (set)
4548      layer = E_LAYER_CLIENT_ABOVE;
4549    else
4550      layer = E_LAYER_CLIENT_NORMAL;
4551
4552    e_client_layer_set(ec, layer);
4553
4554    EC_CHANGED(ec);
4555 }
4556
4557 ///////////////////////////////////////
4558
4559 EINTERN Eina_Bool
4560 e_client_border_set(E_Client *ec, const char *name)
4561 {
4562    Eina_Stringshare *pborder;
4563
4564    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
4565    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, EINA_FALSE);
4566    if (!e_comp_object_frame_allowed(ec->frame)) return EINA_FALSE;
4567    if (ec->border.changed)
4568      CRI("CALLING WHEN border.changed SET!");
4569
4570    if (!e_util_strcmp(ec->border.name, name)) return EINA_TRUE;
4571    if (ec->mwm.borderless && name && strcmp(name, "borderless"))
4572      {
4573         CRI("border change attempted for MWM borderless client!");
4574      }
4575    pborder = ec->border.name;
4576    ec->border.name = eina_stringshare_add(name);
4577    if (e_comp_object_frame_theme_set(ec->frame, name))
4578      {
4579         eina_stringshare_del(pborder);
4580         return EINA_TRUE;
4581      }
4582    eina_stringshare_del(ec->border.name);
4583    ec->border.name = pborder;
4584    return EINA_FALSE;
4585 }
4586
4587 ///////////////////////////////////////
4588
4589 EINTERN void
4590 e_client_comp_hidden_set(E_Client *ec, Eina_Bool hidden)
4591 {
4592    E_OBJECT_CHECK(ec);
4593    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4594
4595    hidden = !!hidden;
4596    if (ec->comp_hidden == hidden) return;
4597    ec->comp_hidden = hidden;
4598    evas_object_smart_callback_call(ec->frame, "comp_hidden", NULL);
4599 }
4600
4601 ///////////////////////////////////////
4602
4603 EINTERN void
4604 e_client_act_move_keyboard(E_Client *ec)
4605 {
4606    EINA_SAFETY_ON_NULL_RETURN(ec);
4607
4608    if (!_e_client_move_begin(ec))
4609      return;
4610
4611    _e_client_action_init(ec);
4612    _e_client_action_move_timeout_add();
4613
4614    wl_signal_emit_mutable(&PRI(ec)->events.move_update, NULL);
4615    if (!_e_client_hook_call(E_CLIENT_HOOK_MOVE_UPDATE, ec)) return;
4616    evas_object_freeze_events_set(ec->frame, 1);
4617
4618    if (!action_handler_mouse)
4619      action_handler_mouse = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, _e_client_move_mouse_down, NULL);
4620 }
4621
4622 EINTERN void
4623 e_client_act_resize_keyboard(E_Client *ec)
4624 {
4625    EINA_SAFETY_ON_NULL_RETURN(ec);
4626
4627    ec->resize_mode = E_POINTER_RESIZE_TL;
4628    ec->keyboard_resizing = 1;
4629    if (!e_client_resize_begin(ec))
4630      {
4631         ec->keyboard_resizing = 0;
4632         return;
4633      }
4634
4635    _e_client_action_init(ec);
4636    _e_client_action_resize_timeout_add();
4637    evas_object_freeze_events_set(ec->frame, 1);
4638
4639    if (!action_handler_mouse)
4640      action_handler_mouse = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, _e_client_resize_mouse_down, NULL);
4641 }
4642
4643 EINTERN void
4644 e_client_act_move_begin(E_Client *ec, E_Binding_Event_Mouse_Button *ev)
4645 {
4646    E_OBJECT_CHECK(ec);
4647    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4648    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4649    if (ev)
4650      {
4651         char source[256];
4652
4653         snprintf(source, sizeof(source) - 1, "mouse,down,%i", ev->button);
4654         _e_client_moveinfo_gather(ec, source);
4655      }
4656    if (!_e_client_move_begin(ec))
4657      return;
4658
4659    _e_client_action_init(ec);
4660 }
4661
4662 E_API void
4663 e_client_act_move_end(E_Client *ec, E_Binding_Event_Mouse_Button *ev EINA_UNUSED)
4664 {
4665    E_OBJECT_CHECK(ec);
4666    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4667    if (!ec->moving) return;
4668    _e_client_move_end(ec);
4669    _e_client_action_finish();
4670 }
4671
4672 EINTERN void
4673 e_client_act_resize_begin(E_Client *ec, E_Binding_Event_Mouse_Button *ev, E_Pointer_Mode resize_mode)
4674 {
4675    E_OBJECT_CHECK(ec);
4676    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4677    if (ec->lock_user_size) return;
4678    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4679    if (ev)
4680      {
4681         char source[256];
4682         snprintf(source, sizeof(source) - 1, "mouse,down,%i", ev->button);
4683         _e_client_moveinfo_gather(ec, source);
4684
4685         if (resize_mode != E_POINTER_RESIZE_NONE)
4686           {
4687              ec->resize_mode = resize_mode;
4688           }
4689         else
4690           {
4691              /* Use canvas.x, canvas.y of event.
4692               * Transformed coordinates has to be considered for accurate resize_mode
4693               * rather than absolute coordinates. */
4694              if ((ev->canvas.x > (ec->x + ec->w / 5)) &&
4695                  (ev->canvas.x < (ec->x + ec->w * 4 / 5)))
4696                {
4697                   if (ev->canvas.y < (ec->y + ec->h / 2)) ec->resize_mode = E_POINTER_RESIZE_T;
4698                   else ec->resize_mode = E_POINTER_RESIZE_B;
4699                }
4700              else if (ev->canvas.x < (ec->x + ec->w / 2))
4701                {
4702                   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;
4703                   else if (ev->canvas.y < (ec->y + ec->h / 2)) ec->resize_mode = E_POINTER_RESIZE_TL;
4704                   else ec->resize_mode = E_POINTER_RESIZE_BL;
4705                }
4706              else
4707                {
4708                   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;
4709                   else if (ev->canvas.y < (ec->y + ec->h / 2)) ec->resize_mode = E_POINTER_RESIZE_TR;
4710                   else ec->resize_mode = E_POINTER_RESIZE_BR;
4711                }
4712           }
4713      }
4714    if (!e_client_resize_begin(ec))
4715      return;
4716    _e_client_action_init(ec);
4717 }
4718
4719 EINTERN void
4720 e_client_act_resize_end(E_Client *ec, E_Binding_Event_Mouse_Button *ev EINA_UNUSED)
4721 {
4722    E_OBJECT_CHECK(ec);
4723    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4724    if (e_client_util_resizing_get(ec))
4725      {
4726         _e_client_resize_end(ec);
4727         ec->changes.reset_gravity = 1;
4728         if (!e_object_is_del(E_OBJECT(ec)))
4729           EC_CHANGED(ec);
4730      }
4731    _e_client_action_finish();
4732 }
4733
4734 EINTERN void
4735 e_client_act_menu_begin(E_Client *ec, E_Binding_Event_Mouse_Button *ev, int key)
4736 {
4737    E_OBJECT_CHECK(ec);
4738    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4739 }
4740
4741 EINTERN void
4742 e_client_act_close_begin(E_Client *ec)
4743 {
4744    E_OBJECT_CHECK(ec);
4745    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4746    if (ec->lock_close) return;
4747    if (ec->icccm.delete_request)
4748      {
4749         ec->delete_requested = 1;
4750         evas_object_smart_callback_call(ec->frame, "delete_request", NULL);
4751      }
4752    else if (e_config->kill_if_close_not_possible)
4753      {
4754         e_client_act_kill_begin(ec);
4755      }
4756 }
4757
4758 EINTERN void
4759 e_client_act_kill_begin(E_Client *ec)
4760 {
4761    E_OBJECT_CHECK(ec);
4762    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4763    if (ec->internal) return;
4764    if (ec->lock_close) return;
4765    if ((ec->netwm.pid > 1) && (e_config->kill_process))
4766      {
4767         kill(ec->netwm.pid, SIGINT);
4768         ec->kill_timer = ecore_timer_add(e_config->kill_timer_wait,
4769                                          _e_client_cb_kill_timer, ec);
4770      }
4771    else
4772      evas_object_smart_callback_call(ec->frame, "kill_request", NULL);
4773 }
4774
4775 ////////////////////////////////////////////
4776
4777 EINTERN void
4778 e_client_ping(E_Client *ec)
4779 {
4780    E_OBJECT_CHECK(ec);
4781    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4782
4783    if (!e_config->ping_clients) return;
4784
4785    EINA_SAFETY_ON_TRUE_RETURN(e_object_is_del(E_OBJECT(ec)));
4786
4787    ec->ping_ok = 0;
4788    evas_object_smart_callback_call(ec->frame, "ping", NULL);
4789    ec->ping = ecore_loop_time_get();
4790    if (ec->ping_poller) ecore_poller_del(ec->ping_poller);
4791    ec->ping_poller = ecore_poller_add(ECORE_POLLER_CORE,
4792                                       e_config->ping_clients_interval,
4793                                       _e_client_cb_ping_poller, ec);
4794 }
4795
4796 ////////////////////////////////////////////
4797 E_API void
4798 e_client_cursor_map_apply(E_Client *ec, int rotation, int x, int y)
4799 {
4800    // TODO: remove(deprecate) this e_client_cursor_map_apply.
4801 }
4802
4803 EINTERN void
4804 e_client_move_cancel(void)
4805 {
4806    if (!ecmove) return;
4807    if (ecmove->cur_mouse_action)
4808      {
4809         E_Client *ec;
4810
4811         ec = ecmove;
4812         e_object_ref(E_OBJECT(ec));
4813         if (ec->cur_mouse_action->func.end_mouse)
4814           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", NULL);
4815         else if (ec->cur_mouse_action->func.end)
4816           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
4817         e_object_unref(E_OBJECT(ec->cur_mouse_action));
4818         ec->cur_mouse_action = NULL;
4819         e_object_unref(E_OBJECT(ec));
4820      }
4821    else
4822      _e_client_move_end(ecmove);
4823 }
4824
4825 EINTERN void
4826 e_client_resize_cancel(void)
4827 {
4828    if (!ecresize) return;
4829    if (ecresize->cur_mouse_action)
4830      {
4831         E_Client *ec;
4832
4833         ec = ecresize;
4834         e_object_ref(E_OBJECT(ec));
4835         if (ec->cur_mouse_action->func.end_mouse)
4836           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", NULL);
4837         else if (ec->cur_mouse_action->func.end)
4838           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
4839         e_object_unref(E_OBJECT(ec->cur_mouse_action));
4840         ec->cur_mouse_action = NULL;
4841         e_object_unref(E_OBJECT(ec));
4842      }
4843    else
4844      _e_client_resize_end(ecresize);
4845 }
4846
4847 EINTERN Eina_Bool
4848 e_client_resize_begin(E_Client *ec)
4849 {
4850    if ((ec->fullscreen) || (ec->lock_user_size))
4851      goto error;
4852    if (!_e_client_action_input_win_new()) goto error;
4853    ecresize = ec;
4854    if (ec->manage_resize.enable_aspect_ratio)
4855      {
4856         ELOGF("RESIZE", "Set resize aspect ratio.. ratio(%dx%d)", ec, ec->w, ec->h);
4857         ec->manage_resize.aw = ec->w;
4858         ec->manage_resize.ah = ec->h - ec->manage_resize.header_h - ec->manage_resize.footer_h;
4859      }
4860
4861    wl_signal_emit_mutable(&PRI(ec)->events.move_begin, NULL);
4862    _e_client_hook_call(E_CLIENT_HOOK_RESIZE_BEGIN, ec);
4863    if (ec->transformed)
4864      _e_client_transform_resize_begin(ec);
4865    if (!e_client_util_resizing_get(ec))
4866      {
4867         if (ecresize == ec) ecresize = NULL;
4868         _e_client_action_input_win_del();
4869         return EINA_FALSE;
4870      }
4871    if (!ec->lock_user_stacking)
4872      {
4873         if (e_config->border_raise_on_mouse_action)
4874           e_client_raise(ec);
4875      }
4876
4877    if (e_comp->hwc)
4878      e_comp_client_override_add(ec);
4879
4880    return EINA_TRUE;
4881 error:
4882    ec->resize_mode = E_POINTER_RESIZE_NONE;
4883    return EINA_FALSE;
4884 }
4885
4886
4887 ////////////////////////////////////////////
4888
4889 EINTERN void
4890 e_client_frame_recalc(E_Client *ec)
4891 {
4892    EINA_SAFETY_ON_NULL_RETURN(ec);
4893    if (!ec->frame) return;
4894    evas_object_smart_callback_call(ec->frame, "frame_recalc", NULL);
4895 }
4896
4897 ////////////////////////////////////////////
4898
4899 EINTERN void
4900 e_client_signal_move_begin(E_Client *ec, const char *sig, const char *src EINA_UNUSED)
4901 {
4902    E_OBJECT_CHECK(ec);
4903    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4904
4905    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4906    _e_client_moveinfo_gather(ec, sig);
4907    if (!_e_client_move_begin(ec)) return;
4908 }
4909
4910 EINTERN void
4911 e_client_signal_move_end(E_Client *ec, const char *sig EINA_UNUSED, const char *src EINA_UNUSED)
4912 {
4913    E_OBJECT_CHECK(ec);
4914    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4915    if (!ec->moving) return;
4916    _e_client_move_end(ec);
4917 }
4918
4919 EINTERN void
4920 e_client_signal_resize_begin(E_Client *ec, const char *dir, const char *sig, const char *src EINA_UNUSED)
4921 {
4922    int resize_mode = E_POINTER_RESIZE_BR;
4923
4924    E_OBJECT_CHECK(ec);
4925    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4926
4927    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4928    if (!strcmp(dir, "tl"))
4929      {
4930         resize_mode = E_POINTER_RESIZE_TL;
4931      }
4932    else if (!strcmp(dir, "t"))
4933      {
4934         resize_mode = E_POINTER_RESIZE_T;
4935      }
4936    else if (!strcmp(dir, "tr"))
4937      {
4938         resize_mode = E_POINTER_RESIZE_TR;
4939      }
4940    else if (!strcmp(dir, "r"))
4941      {
4942         resize_mode = E_POINTER_RESIZE_R;
4943      }
4944    else if (!strcmp(dir, "br"))
4945      {
4946         resize_mode = E_POINTER_RESIZE_BR;
4947      }
4948    else if (!strcmp(dir, "b"))
4949      {
4950         resize_mode = E_POINTER_RESIZE_B;
4951      }
4952    else if (!strcmp(dir, "bl"))
4953      {
4954         resize_mode = E_POINTER_RESIZE_BL;
4955      }
4956    else if (!strcmp(dir, "l"))
4957      {
4958         resize_mode = E_POINTER_RESIZE_L;
4959      }
4960    ec->resize_mode = resize_mode;
4961    _e_client_moveinfo_gather(ec, sig);
4962    if (!e_client_resize_begin(ec))
4963      return;
4964 }
4965
4966 EINTERN void
4967 e_client_signal_resize_end(E_Client *ec, const char *dir EINA_UNUSED, const char *sig EINA_UNUSED, const char *src EINA_UNUSED)
4968 {
4969    E_OBJECT_CHECK(ec);
4970    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4971    if (!e_client_util_resizing_get(ec)) return;
4972    _e_client_resize_handle(ec);
4973    _e_client_resize_end(ec);
4974    ec->changes.reset_gravity = 1;
4975    EC_CHANGED(ec);
4976 }
4977
4978 ////////////////////////////////////////////
4979
4980 EINTERN void
4981 e_client_resize_limit(E_Client *ec, int *w, int *h)
4982 {
4983    double a;
4984    Eina_Bool inc_h;
4985
4986    E_OBJECT_CHECK(ec);
4987    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4988
4989    inc_h = (*h - ec->h > 0);
4990    if (ec->frame)
4991      e_comp_object_frame_wh_unadjust(ec->frame, *w, *h, w, h);
4992    if (*h < 1) *h = 1;
4993    if (*w < 1) *w = 1;
4994    if ((ec->icccm.base_w >= 0) &&
4995        (ec->icccm.base_h >= 0))
4996      {
4997         int tw, th;
4998
4999         tw = *w - ec->icccm.base_w;
5000         th = *h - ec->icccm.base_h;
5001         if (tw < 1) tw = 1;
5002         if (th < 1) th = 1;
5003         a = (double)(tw) / (double)(th);
5004         if ((ec->icccm.min_aspect != 0.0) &&
5005             (a < ec->icccm.min_aspect))
5006           {
5007              if (inc_h)
5008                tw = th * ec->icccm.min_aspect;
5009              else
5010                th = tw / ec->icccm.max_aspect;
5011              *w = tw + ec->icccm.base_w;
5012              *h = th + ec->icccm.base_h;
5013           }
5014         else if ((ec->icccm.max_aspect != 0.0) &&
5015                  (a > ec->icccm.max_aspect))
5016           {
5017              tw = th * ec->icccm.max_aspect;
5018              *w = tw + ec->icccm.base_w;
5019           }
5020      }
5021    else
5022      {
5023         a = (double)*w / (double)*h;
5024         if ((ec->icccm.min_aspect != 0.0) &&
5025             (a < ec->icccm.min_aspect))
5026           {
5027              if (inc_h)
5028                *w = *h * ec->icccm.min_aspect;
5029              else
5030                *h = *w / ec->icccm.min_aspect;
5031           }
5032         else if ((ec->icccm.max_aspect != 0.0) &&
5033                  (a > ec->icccm.max_aspect))
5034           *w = *h * ec->icccm.max_aspect;
5035      }
5036    if (ec->icccm.step_w > 0)
5037      {
5038         if (ec->icccm.base_w >= 0)
5039           *w = ec->icccm.base_w +
5040             (((*w - ec->icccm.base_w) / ec->icccm.step_w) *
5041              ec->icccm.step_w);
5042         else
5043           *w = ec->icccm.min_w +
5044             (((*w - ec->icccm.min_w) / ec->icccm.step_w) *
5045              ec->icccm.step_w);
5046      }
5047    if (ec->icccm.step_h > 0)
5048      {
5049         if (ec->icccm.base_h >= 0)
5050           *h = ec->icccm.base_h +
5051             (((*h - ec->icccm.base_h) / ec->icccm.step_h) *
5052              ec->icccm.step_h);
5053         else
5054           *h = ec->icccm.min_h +
5055             (((*h - ec->icccm.min_h) / ec->icccm.step_h) *
5056              ec->icccm.step_h);
5057      }
5058
5059    if (*h < 1) *h = 1;
5060    if (*w < 1) *w = 1;
5061
5062    if ((ec->icccm.max_w > 0) && (*w > ec->icccm.max_w)) *w = ec->icccm.max_w;
5063    else if (*w < ec->icccm.min_w)
5064      *w = ec->icccm.min_w;
5065    if ((ec->icccm.max_h > 0) && (*h > ec->icccm.max_h)) *h = ec->icccm.max_h;
5066    else if (*h < ec->icccm.min_h)
5067      *h = ec->icccm.min_h;
5068
5069    if (ec->frame)
5070      e_comp_object_frame_wh_adjust(ec->frame, *w, *h, w, h);
5071 }
5072
5073 ////////////////////////////////////////////
5074
5075
5076
5077 EINTERN E_Client *
5078 e_client_under_pointer_get(E_Desk *desk, E_Client *exclude)
5079 {
5080    int x, y;
5081
5082    /* We need to ensure that we can get the comp window for the
5083     * zone of either the given desk or the desk of the excluded
5084     * window, so return if neither is given */
5085    if (desk)
5086      e_input_device_pointer_xy_get(NULL, &x, &y);
5087    else if (exclude)
5088      e_input_device_pointer_xy_get(NULL, &x, &y);
5089    else
5090      return NULL;
5091
5092    if (!desk)
5093      {
5094         desk = exclude->desk;
5095         if (!desk)
5096           {
5097              if (exclude->zone)
5098                desk = e_desk_current_get(exclude->zone);
5099              else
5100                desk = e_desk_current_get(e_zone_current_get());
5101           }
5102      }
5103
5104    return desk ? _e_client_under_pointer_helper(desk, exclude, x, y) : NULL;
5105 }
5106
5107 E_API E_Client *e_client_under_position_get(E_Desk *desk, int x, int y, E_Client *exclude)
5108 {
5109    if (!desk) return NULL;
5110
5111    return _e_client_under_pointer_helper(desk, exclude, x, y);
5112 }
5113
5114 E_API E_Client *e_client_under_position_input_get(E_Desk *desk, int x, int y)
5115 {
5116    if (!desk) return NULL;
5117
5118    return _e_client_under_pointer_input_helper(desk, x, y);
5119 }
5120
5121 ////////////////////////////////////////////
5122
5123 ////////////////////////////////////////////
5124
5125 E_API void
5126 e_client_redirected_set(E_Client *ec, Eina_Bool set)
5127 {
5128    EINA_SAFETY_ON_NULL_RETURN(ec);
5129    if (ec->input_only) return;
5130    set = !!set;
5131    if (ec->redirected == set) return;
5132    if (set)
5133      {
5134         e_client_frame_recalc(ec);
5135
5136         wl_signal_emit_mutable(&PRI(ec)->events.redirect, NULL);
5137         if (!_e_client_hook_call(E_CLIENT_HOOK_REDIRECT, ec)) return;
5138      }
5139    else
5140      {
5141         wl_signal_emit_mutable(&PRI(ec)->events.unredirect, NULL);
5142         if (!_e_client_hook_call(E_CLIENT_HOOK_UNREDIRECT, ec)) return;
5143      }
5144    e_comp_object_redirected_set(ec->frame, set);
5145    ec->redirected = !!set;
5146 }
5147
5148 ////////////////////////////////////////////
5149
5150 E_API void
5151 e_client_transform_update(E_Client *ec)
5152 {
5153    if (e_client_util_resizing_get(ec))
5154      _e_client_transform_resize(ec);
5155 }
5156
5157 ////////////////////////////////////////////
5158
5159 EINTERN void
5160 e_client_transform_apply(E_Client *ec, double angle, double zoom, int cx, int cy)
5161 {
5162    E_Map *map;
5163    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
5164    E_Client *subc;
5165    Eina_List *l;
5166
5167    if (e_comp_wl_subsurface_check(ec))
5168      return;
5169
5170    /* check if it's different with current state */
5171    if ((ec->transform.angle == angle) &&
5172        (ec->transform.zoom == zoom) &&
5173        (ec->transform.center.x == cx) &&
5174        (ec->transform.center.y == cy))
5175      return;
5176
5177    /* use previous value if any required value is invalid */
5178    if (angle == -1.0)
5179      angle = ec->transform.angle;
5180    if (zoom == -1.0)
5181      zoom = ec->transform.zoom;
5182    if (!E_INSIDE(cx, cy,
5183                  ec->client.x, ec->client.y,
5184                  ec->client.w, ec->client.h))
5185      {
5186         cx = ec->transform.center.x;
5187         cy = ec->transform.center.y;
5188      }
5189
5190    if ((angle == 0) && (zoom == 1.0))
5191      {
5192         e_client_transform_clear(ec);
5193         return;
5194      }
5195
5196    map = e_map_new_with_direct_render(ec->transform_core.direct_render);
5197    e_map_util_points_populate_from_object_full(map, ec->frame, 0);
5198
5199    e_map_util_rotate(map, angle, cx, cy);
5200    _e_client_transform_geometry_save(ec, map);
5201
5202    e_map_util_zoom(map, zoom, zoom, cx, cy);
5203
5204    e_map_util_object_move_sync_set(map, EINA_TRUE);
5205    e_client_map_set(ec, map);
5206    e_client_map_enable_set(ec, EINA_TRUE);
5207
5208    EINA_LIST_FOREACH(cdata->sub.list, l, subc)
5209      _e_client_transform_sub_apply(subc, ec, zoom);
5210    EINA_LIST_REVERSE_FOREACH(cdata->sub.below_list, l, subc)
5211      _e_client_transform_sub_apply(subc, ec, zoom);
5212
5213    e_map_free(map);
5214
5215    ec->transform.zoom = zoom;
5216    ec->transform.angle = angle;
5217    ec->transform.center.x = cx;
5218    ec->transform.center.y = cy;
5219    ec->transformed = EINA_TRUE;
5220 }
5221
5222 ////////////////////////////////////////////
5223
5224 EINTERN void
5225 e_client_transform_clear(E_Client *ec)
5226 {
5227    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
5228    E_Client *subc;
5229    Eina_List *l;
5230
5231    e_client_map_enable_set(ec, EINA_FALSE);
5232    e_client_map_set(ec, NULL);
5233
5234    EINA_LIST_FOREACH(cdata->sub.list, l, subc)
5235      _e_client_transform_sub_apply(subc, ec, 1.0);
5236    EINA_LIST_REVERSE_FOREACH(cdata->sub.below_list, l, subc)
5237      _e_client_transform_sub_apply(subc, ec, 1.0);
5238
5239    ec->transform.zoom = 1.0;
5240    ec->transform.angle = 0.0;
5241    ec->transformed = EINA_FALSE;
5242 }
5243
5244 E_API Eina_Bool
5245 e_client_transform_core_enable_get(E_Client *ec)
5246 {
5247    if (!ec) return EINA_FALSE;
5248    return ec->transform_core.result.enable;
5249 }
5250
5251 E_API void
5252 e_client_transform_core_add(E_Client *ec, E_Util_Transform *transform)
5253 {
5254    if (!ec) return;
5255    if (!transform) return;
5256
5257    // duplication check
5258    if (ec->transform_core.transform_list &&
5259        eina_list_data_find(ec->transform_core.transform_list, transform) == transform)
5260      {
5261         return;
5262      }
5263
5264    ec->transform_core.transform_list = eina_list_append(ec->transform_core.transform_list, transform);
5265    ec->transform_core.changed = EINA_TRUE;
5266    e_util_transform_ref(transform);
5267   // e_client_transform_core_update(ec);
5268 }
5269
5270 E_API void
5271 e_client_transform_core_remove(E_Client *ec, E_Util_Transform *transform)
5272 {
5273    if (!ec) return;
5274    if (!transform) return;
5275
5276    if (ec->transform_core.transform_list &&
5277        eina_list_data_find(ec->transform_core.transform_list, transform) == transform)
5278      {
5279         ec->transform_core.transform_list = eina_list_remove(ec->transform_core.transform_list, transform);
5280         e_util_transform_unref(transform);
5281         ec->transform_core.changed = EINA_TRUE;
5282      }
5283
5284    e_client_transform_core_update(ec);
5285 }
5286
5287 E_API void
5288 e_client_transform_core_update(E_Client *ec)
5289 {
5290    if (!ec) return;
5291    if (ec->new_client) return;
5292    if (!_e_client_transform_core_check_change(ec)) return;
5293
5294    if (ec->transform_core.transform_list || ec->transform_core.parent.enable)
5295      {
5296         E_Util_Transform_Rect source_rect;
5297         E_Util_Transform_Matrix matrix, boundary_matrix;
5298         E_Util_Transform_Zoom zoom;
5299         Eina_List *l;
5300         Eina_Bool background;
5301         E_Util_Transform *temp_trans;
5302
5303         // 1. init state
5304         ec->transform_core.result.enable = EINA_TRUE;
5305         e_util_transform_rect_client_rect_get(&source_rect, ec);
5306         e_util_transform_init(&ec->transform_core.result.transform);
5307
5308         // 2. merge transform
5309         EINA_LIST_FOREACH(ec->transform_core.transform_list, l, temp_trans)
5310           {
5311              e_util_transform_merge(&ec->transform_core.result.transform, temp_trans);
5312           }
5313         zoom = ec->transform_core.result.transform.zoom;
5314
5315         // 2.5 check viewport
5316         if (e_util_transform_viewport_flag_get(&ec->transform_core.result.transform))
5317           {
5318              int vx = 0, vy = 0, vw = 0, vh = 0;
5319              e_util_transform_viewport_get(&ec->transform_core.result.transform, &vx, &vy, &vw, &vh);
5320              e_util_transform_rect_init(&source_rect, vx, vy, vw, vh);
5321           }
5322
5323         // 3. apply background transform
5324         matrix = e_util_transform_convert_to_matrix(&ec->transform_core.result.transform, &source_rect);
5325
5326         if (e_util_transform_bg_transform_flag_get(&ec->transform_core.result.transform))
5327           {
5328              boundary_matrix = e_util_transform_bg_convert_to_matrix(&ec->transform_core.result.transform, &source_rect);
5329              background = EINA_TRUE;
5330           }
5331         else
5332           {
5333              background = EINA_FALSE;
5334              boundary_matrix = matrix;
5335           }
5336
5337         if (background != ec->transform_core.background)
5338           {
5339              if (background)
5340                {
5341                   e_comp_object_transform_bg_set(ec->frame, EINA_TRUE);
5342                }
5343              else
5344                {
5345                   e_comp_object_transform_bg_set(ec->frame, EINA_FALSE);
5346                }
5347
5348              ec->transform_core.background = background;
5349           }
5350
5351         // 3.1 if 24bit window then set transp rect
5352         if (!ec->argb)
5353           {
5354              int angle = 0;
5355
5356              e_util_transform_rotation_round_get(&ec->transform_core.result.transform, 0, 0, &angle);
5357              angle %= 90;
5358
5359              if (angle == 0) // when transform angle is 0, 90, 180, 270, 360. then set transp rect
5360                e_comp_object_transform_transp_set(ec->frame, EINA_TRUE);
5361              else
5362                e_comp_object_transform_transp_set(ec->frame, EINA_FALSE);
5363           }
5364         else
5365           e_comp_object_transform_transp_set(ec->frame, EINA_FALSE);
5366
5367         // 3.5 parent matrix multiply
5368         if (ec->transform_core.parent.enable)
5369           {
5370              matrix = e_util_transform_matrix_multiply(&ec->transform_core.parent.matrix,
5371                                                        &matrix);
5372              boundary_matrix = e_util_transform_matrix_multiply(&ec->transform_core.parent.matrix,
5373                                                                 &boundary_matrix);
5374
5375              ec->transform_core.result.transform.use_zoom = EINA_TRUE;
5376              zoom.zoom_x *= ec->transform_core.parent.zoom.zoom_x;
5377              zoom.zoom_y *= ec->transform_core.parent.zoom.zoom_y;
5378              zoom.cx += ec->transform_core.parent.zoom.cx;
5379              zoom.cy += ec->transform_core.parent.zoom.cy;
5380           }
5381
5382         // 4. apply matrix to vertices
5383         ec->transform_core.result.matrix = matrix;
5384         ec->transform_core.result.inv_matrix = e_util_transform_matrix_inverse_get(&matrix);
5385         ec->transform_core.result.vertices = e_util_transform_rect_to_vertices(&source_rect);
5386         ec->transform_core.result.boundary.vertices = e_util_transform_rect_to_vertices(&source_rect);
5387         ec->transform_core.result.vertices = e_util_transform_matrix_multiply_rect_vertex(&matrix,
5388                                                                                           &ec->transform_core.result.vertices);
5389         ec->transform_core.result.boundary.vertices = e_util_transform_matrix_multiply_rect_vertex(&boundary_matrix,
5390                                                                                                    &ec->transform_core.result.boundary.vertices);
5391         ec->transform_core.result.transform.zoom = zoom;
5392
5393         // 5. apply vertices
5394         if (ec->transform_core.result.transform.use_zoom)
5395           {
5396              // TODO: apply zoom values to vertices
5397              e_comp_object_transform_transp_vertices_set_with_zoom(ec->frame, &ec->transform_core.result.vertices,
5398                                                                    ec->transform_core.result.transform.zoom);
5399              e_comp_object_transform_bg_vertices_set_with_zoom(ec->frame, &ec->transform_core.result.boundary.vertices,
5400                                                                ec->transform_core.result.transform.zoom);
5401              _e_client_transform_core_boundary_update(ec, &ec->transform_core.result.boundary.vertices);
5402              _e_client_transform_core_vertices_apply_with_zoom(ec, ec->frame, &ec->transform_core.result.vertices, &ec->transform_core.result.transform,
5403                                                                ec->transform_core.result.transform.zoom);
5404           }
5405         else
5406           {
5407              e_comp_object_transform_transp_vertices_set(ec->frame, &ec->transform_core.result.vertices);
5408              e_comp_object_transform_bg_vertices_set(ec->frame, &ec->transform_core.result.boundary.vertices);
5409              _e_client_transform_core_boundary_update(ec, &ec->transform_core.result.boundary.vertices);
5410              _e_client_transform_core_vertices_apply(ec, ec->frame, &ec->transform_core.result.vertices, &ec->transform_core.result.transform);
5411           }
5412
5413         // 6. subsurface update
5414         _e_client_transform_core_sub_update(ec, &ec->transform_core.result.vertices);
5415
5416         if (!e_object_is_del(E_OBJECT(ec)))
5417           {
5418              wl_signal_emit_mutable(&PRI(ec)->events.transform_change, NULL);
5419              _e_client_hook_call(E_CLIENT_HOOK_TRANSFORM_CHANGE, ec);
5420           }
5421      }
5422    else
5423      {
5424         if (ec->transform_core.result.enable)
5425           {
5426              ec->transform_core.result.enable = EINA_FALSE;
5427              _e_client_transform_core_vertices_apply(ec, ec->frame, NULL, NULL);
5428              e_comp_object_transform_bg_set(ec->frame, EINA_FALSE);
5429              ec->transform_core.background = EINA_FALSE;
5430              e_comp_object_transform_transp_set(ec->frame, EINA_FALSE);
5431              _e_client_transform_core_sub_update(ec, NULL);
5432
5433              if (!e_object_is_del(E_OBJECT(ec)))
5434                {
5435                   wl_signal_emit_mutable(&PRI(ec)->events.transform_change, NULL);
5436                   _e_client_hook_call(E_CLIENT_HOOK_TRANSFORM_CHANGE, ec);
5437                }
5438           }
5439      }
5440
5441    e_comp_visibility_calculation_set(EINA_TRUE);
5442 }
5443
5444 E_API int
5445 e_client_transform_core_transform_count_get(E_Client *ec)
5446 {
5447    if (!ec) return 0;
5448    if (!ec->transform_core.transform_list) return 0;
5449    return eina_list_count(ec->transform_core.transform_list);
5450 }
5451
5452 E_API E_Util_Transform*
5453 e_client_transform_core_transform_get(E_Client *ec, int index)
5454 {
5455    if (!ec) return NULL;
5456    if (!ec->transform_core.transform_list) return NULL;
5457    if (index < 0 || index >= e_client_transform_core_transform_count_get(ec))
5458       return NULL;
5459
5460    return (E_Util_Transform*)eina_list_nth(ec->transform_core.transform_list, index);
5461 }
5462
5463 E_API void
5464 e_client_transform_core_input_transform(E_Client *ec, int x, int y, int *out_x, int *out_y)
5465 {
5466    E_Util_Transform_Vertex vertex, result_vertex;
5467
5468    if (!ec) return;
5469    if (!e_client_transform_core_enable_get(ec)) return;
5470
5471    e_util_transform_vertex_init(&vertex, x, y, 0.0, 1.0);
5472
5473    result_vertex = e_util_transform_matrix_multiply_vertex(&ec->transform_core.result.inv_matrix, &vertex);
5474    e_util_transform_vertex_pos_round_get(&result_vertex, out_x, out_y, NULL, NULL);
5475 }
5476
5477 E_API void
5478 e_client_transform_core_input_inv_transform(E_Client *ec, int x, int y, int *out_x, int *out_y)
5479 {
5480    E_Util_Transform_Vertex vertex, result_vertex;
5481
5482    if (!ec) return;
5483    if (!e_client_transform_core_enable_get(ec)) return;
5484
5485    e_util_transform_vertex_init(&vertex, x, y, 0.0, 1.0);
5486
5487    result_vertex = e_util_transform_matrix_multiply_vertex(&ec->transform_core.result.matrix, &vertex);
5488    e_util_transform_vertex_pos_round_get(&result_vertex, out_x, out_y, NULL, NULL);
5489 }
5490
5491 EINTERN void
5492 e_client_transform_core_input_inv_rect_transform(E_Client *ec, int x, int y, int *out_x, int *out_y)
5493 {
5494    int gw = 0, gh = 0;
5495    if (!ec) return;
5496    if (!e_client_transform_core_enable_get(ec)) return;
5497    e_client_geometry_get(ec, NULL, NULL, &gw, &gh);
5498
5499    e_util_transform_matrix_inv_rect_coords_get(&ec->transform_core.result.transform,
5500                                                &ec->transform_core.result.vertices,
5501                                                gw, gh,
5502                                                x, y, out_x, out_y);
5503 }
5504
5505 E_API void
5506 e_client_transform_core_direct_render_set(E_Client *ec, Eina_Bool set)
5507 {
5508    EINA_SAFETY_ON_NULL_RETURN(ec);
5509
5510    if (ec->transform_core.direct_render == set) return;
5511
5512    ec->transform_core.direct_render = set;
5513    ec->transform_core.changed = EINA_TRUE;
5514
5515    e_client_transform_core_update(ec);
5516 }
5517
5518 EINTERN E_Pixmap *
5519 e_client_pixmap_change(E_Client *ec, E_Pixmap *newcp)
5520 {
5521    E_Pixmap_Type oldtype, newtype;
5522    E_Pixmap *oldcp;
5523
5524    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
5525    EINA_SAFETY_ON_NULL_RETURN_VAL(ec->pixmap, NULL);
5526    EINA_SAFETY_ON_NULL_RETURN_VAL(newcp, NULL);
5527
5528    oldcp = ec->pixmap;
5529
5530    oldtype = e_pixmap_type_get(oldcp);
5531    if (oldtype >= E_PIXMAP_TYPE_MAX) return NULL;
5532
5533    newtype = e_pixmap_type_get(newcp);
5534    if (newtype >= E_PIXMAP_TYPE_MAX) return NULL;
5535
5536    if (eina_hash_find(clients_hash[oldtype], &oldcp))
5537      eina_hash_del_by_key(clients_hash[oldtype], &oldcp);
5538    e_pixmap_client_set(oldcp, NULL);
5539
5540    ec->pixmap = newcp;
5541    e_pixmap_client_set(newcp, ec);
5542
5543    eina_hash_add(clients_hash[newtype], &newcp, ec);
5544
5545    return oldcp;
5546 }
5547
5548 E_API void
5549 e_client_window_role_set(E_Client *ec, const char *role)
5550 {
5551    EINA_SAFETY_ON_NULL_RETURN(ec);
5552
5553    if (eina_stringshare_replace(&ec->icccm.window_role, role))
5554      {
5555         wl_signal_emit_mutable(&PRI(ec)->events.window_role_change, NULL);
5556         _e_client_hook_call(E_CLIENT_HOOK_WINDOW_ROLE_CHANGE, ec);
5557      }
5558 }
5559
5560 EINTERN Eina_Bool
5561 e_client_key_send(E_Client *ec, int keycode, Eina_Bool pressed, Ecore_Device *dev, unsigned int time)
5562 {
5563    Eina_Bool res;
5564
5565    res = e_comp_wl_key_send(ec, keycode, pressed, dev, time);
5566
5567    return res;
5568 }
5569
5570 EINTERN Eina_Bool
5571 e_client_key_cancel(E_Client *ec, int keycode, Ecore_Device *dev, unsigned int time)
5572 {
5573    Eina_Bool res;
5574
5575    res = e_comp_wl_key_cancel(ec, keycode, dev, time);
5576
5577    return res;
5578 }
5579
5580 EINTERN Eina_Bool
5581 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)
5582 {
5583    Eina_Bool res;
5584
5585    res = e_comp_wl_touch_send(ec, idx, x, y, pressed, dev, radius_x, radius_y, pressure, angle, time);
5586
5587    return res;
5588 }
5589
5590 EINTERN Eina_Bool
5591 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)
5592 {
5593    Eina_Bool res;
5594
5595    res = e_comp_wl_touch_update_send(ec, idx, x, y, dev, radius_x, radius_y, pressure, angle, time);
5596
5597    return res;
5598 }
5599
5600 EINTERN Eina_Bool
5601 e_client_touch_cancel_send(E_Client *ec)
5602 {
5603    Eina_Bool res;
5604
5605    res = e_comp_wl_touch_cancel_send(ec);
5606
5607    return res;
5608 }
5609
5610 EINTERN Eina_Bool
5611 e_client_mouse_button_send(E_Client *ec, int buttons, Eina_Bool pressed, Ecore_Device *dev, unsigned int time)
5612 {
5613    Eina_Bool res;
5614
5615    res = e_comp_wl_mouse_button_send(ec, buttons, pressed, dev, time);
5616
5617    return res;
5618 }
5619
5620 EINTERN Eina_Bool
5621 e_client_mouse_move_send(E_Client *ec, int x, int y, Ecore_Device *dev, unsigned int time)
5622 {
5623    Eina_Bool res;
5624
5625    res = e_comp_wl_mouse_move_send(ec, x, y, dev, time);
5626
5627    return res;
5628 }
5629
5630 EINTERN Eina_Bool
5631 e_client_mouse_wheel_send(E_Client *ec, int direction, int z, Ecore_Device *dev, unsigned int time)
5632 {
5633    Eina_Bool res;
5634
5635    res = e_comp_wl_mouse_wheel_send(ec, direction, z, dev, time);
5636
5637    return res;
5638 }
5639
5640 EINTERN Eina_Bool
5641 e_client_mouse_in_send(E_Client *ec, int x, int y, Ecore_Device *dev, unsigned int time)
5642 {
5643    Eina_Bool res;
5644
5645    res = e_comp_wl_mouse_in_send(ec, x, y, dev, time);
5646
5647    return res;
5648 }
5649
5650 EINTERN Eina_Bool
5651 e_client_mouse_out_send(E_Client *ec, Ecore_Device *dev, unsigned int time)
5652 {
5653    Eina_Bool res;
5654
5655    res = e_comp_wl_mouse_out_send(ec, dev, time);
5656
5657    return res;
5658 }
5659
5660 E_API Eina_Bool
5661 e_client_video_client_has(E_Client *ec)
5662 {
5663    return e_comp_wl_video_subsurface_has(ec);
5664 }
5665
5666 E_API Eina_Bool
5667 e_client_normal_client_has(E_Client *ec)
5668 {
5669    return e_comp_wl_normal_subsurface_has(ec);
5670 }
5671
5672 E_API Eina_Bool
5673 e_client_cursor_hide(E_Client *ec)
5674 {
5675    return e_comp_wl_cursor_hide(ec);
5676 }
5677
5678 E_API void
5679 e_client_visibility_force_obscured_set(E_Client *ec, Eina_Bool set)
5680 {
5681    if (!ec) return;
5682
5683    ELOGF("TZVIS", "VIS_FORCE_OBSCURED :%d", ec, set);
5684
5685    ec->visibility.force_obscured = set;
5686    e_comp_visibility_calculation_set(EINA_TRUE);
5687 }
5688
5689 EINTERN E_Capture_Save_State
5690 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)
5691 {
5692    return e_comp_wl_capture_client_image_save(ec, dir, name, func_end, data, skip_child);
5693 }
5694
5695 static void
5696 _e_client_base_output_resolution_hook_subsurf_create(void *data, E_Client *subc)
5697 {
5698    E_Client *ec, *parent;
5699
5700    ec = data;
5701    if (ec != subc)
5702      return;
5703
5704    ec->base_output_resolution.use = 0;
5705    ec->base_output_resolution.w = 0;
5706    ec->base_output_resolution.h = 0;
5707    if (ec->base_output_resolution.transform)
5708      {
5709         e_client_transform_core_remove(ec, ec->base_output_resolution.transform);
5710         E_FREE_FUNC(ec->base_output_resolution.transform, e_util_transform_del);
5711         ELOGF("POL_APPINFO", "Cancel TRANSFORM for subsurface", ec);
5712      }
5713
5714    /* Update transform for toplevel surface.
5715     * The transform of subsurface will be updated by its parent accordingly. */
5716    parent = e_comp_wl_topmost_parent_get(ec);
5717    if (parent)
5718      {
5719         parent->transform_core.changed = EINA_TRUE;
5720         e_client_transform_core_update(parent);
5721      }
5722
5723    /* TODO: Do we need to apply it again if subsurface is destroyed? */
5724 }
5725
5726 static void
5727 _e_client_base_output_resolution_set(E_Client *ec, int width, int height)
5728 {
5729    if (!ec) return;
5730    ec->base_output_resolution.use = 1;
5731    ec->base_output_resolution.w = width;
5732    ec->base_output_resolution.h = height;
5733    ec->base_output_resolution.transform = e_util_transform_new();
5734    e_util_transform_role_set(ec->base_output_resolution.transform, "base_output_resolution");
5735    e_client_transform_core_add(ec, ec->base_output_resolution.transform);
5736
5737    if (!ec->base_output_resolution.hook_subsurf_create)
5738      {
5739         ec->base_output_resolution.hook_subsurf_create =
5740            e_comp_wl_hook_add(E_COMP_WL_HOOK_SUBSURFACE_CREATE,
5741                               _e_client_base_output_resolution_hook_subsurf_create,
5742                               ec);
5743      }
5744 }
5745
5746 E_API void
5747 e_client_base_output_resolution_transform_adjust(E_Client *ec)
5748 {
5749    E_Desk *desk;
5750
5751    EINA_SAFETY_ON_NULL_RETURN(ec);
5752    if (!ec->base_output_resolution.use) return;
5753    if (!ec->base_output_resolution.transform) return;
5754
5755    desk = e_comp_desk_find_by_ec(ec);
5756    EINA_SAFETY_ON_NULL_RETURN(desk);
5757
5758    ELOGF("POL_APPINFO", "Apply TRANSFORM... desk:(%dx%d), ec:(%dx%d)",
5759          ec, desk->geom.w, desk->geom.h, ec->w, ec->h);
5760
5761    e_util_transform_scale(ec->base_output_resolution.transform,
5762                           (double)desk->geom.w /(double)ec->base_output_resolution.w,
5763                           (double)desk->geom.h /(double)ec->base_output_resolution.h,
5764                           1.0);
5765    e_client_transform_core_update(ec);
5766 }
5767
5768 E_API Eina_Bool
5769 e_client_base_output_resolution_update(E_Client *ec)
5770 {
5771    E_Appinfo *eai = NULL;
5772    int configured_width, configured_height;
5773    int width, height;
5774    E_Desk *desk;
5775
5776    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
5777
5778   if (!e_config->configured_output_resolution.use) return EINA_TRUE;
5779   if (ec->base_output_resolution.use) return EINA_TRUE;
5780
5781   /* Check whether it's subsurface or not
5782    * The resolution of subsurface will follow the resolution of its toplevel surface.
5783    * Transform for subsurface will be applied when toplevel surface does by
5784    * implementation of e_client_transform_core.
5785    */
5786   if (e_comp_wl_subsurface_check(ec))
5787     return EINA_FALSE;
5788
5789    desk = e_comp_desk_find_by_ec(ec);
5790    EINA_SAFETY_ON_NULL_RETURN_VAL(desk, EINA_FALSE);
5791
5792   configured_width = e_config->configured_output_resolution.w;
5793   configured_height = e_config->configured_output_resolution.h;
5794
5795   if (!ec->netwm.pid)
5796     {
5797        ELOGF("POL_APPINFO", "NO PID... USE configured_output_resolution(%d,%d) pid:%d", ec,
5798              configured_width, configured_height, ec->netwm.pid);
5799        goto use_configured;
5800     }
5801
5802    eai = e_appinfo_find_with_pid(ec->netwm.pid);
5803    if (!eai)
5804      {
5805         ELOGF("POL_APPINFO", "NO APPINFO... USE configured_output_resolution(%d,%d) pid:%d", ec,
5806               configured_width, configured_height, ec->netwm.pid);
5807         goto use_configured;
5808      }
5809
5810    if (!e_appinfo_base_output_resolution_available_get(eai))
5811      {
5812         ELOGF("POL_APPINFO", "NO AVAILABLE BASE SCREEN RESOLUTION... QUERY base_output_resolution", ec);
5813         e_policy_base_output_resolution_info_update(ec->netwm.pid);
5814      }
5815
5816    if (!e_appinfo_base_output_resolution_get(eai, &width, &height))
5817      {
5818         ELOGF("POL_APPINFO", "NO BASE SCREEN RESOLUTION... USE configured_output_resolution(%d,%d) pid:%d", ec,
5819               configured_width, configured_height, ec->netwm.pid);
5820         goto use_configured;
5821       }
5822
5823    if ((width == 0) && (height == 0))
5824      {
5825         ELOGF("POL_APPINFO", "SKIP SET BASE SCREEN RESOLUTION... base_output_resolution size:(%d,%d) pid:%d", ec, width, height, ec->netwm.pid);
5826         return EINA_TRUE;
5827      }
5828
5829    if ((desk->geom.w == width) && (desk->geom.h == height))
5830      {
5831         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);
5832         return EINA_TRUE;
5833      }
5834
5835    /* set the base_output_resolution of the e_client */
5836    _e_client_base_output_resolution_set(ec, width, height);
5837
5838    ELOGF("POL_APPINFO", "USE base_output_resolution(%d,%d) pid:%d", ec, width, height, ec->netwm.pid);
5839
5840    return EINA_TRUE;
5841
5842 use_configured:
5843
5844    if ((desk->geom.w == configured_width) && (desk->geom.h == configured_height))
5845      {
5846         ELOGF("POL_APPINFO", "SKIP use configured_output_resolution (same with desk size:(%d,%d), pid:%d)", ec, configured_width, configured_height, ec->netwm.pid);
5847      }
5848    else
5849      {
5850         /* set the base_output_resolution of the e_client as a default */
5851         _e_client_base_output_resolution_set(ec, configured_width, configured_height);
5852      }
5853
5854    return EINA_TRUE;
5855 }
5856
5857 E_API Eina_Bool
5858 e_client_base_output_resolution_useful_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
5859 {
5860    int zx, zy, zw, zh;
5861    E_Zone *zone;
5862
5863    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
5864
5865    zone = e_comp_zone_find_by_ec(ec);
5866    EINA_SAFETY_ON_NULL_RETURN_VAL(zone, EINA_FALSE);
5867
5868    e_zone_useful_geometry_get(zone, &zx, &zy, &zw, &zh);
5869
5870    if (x) *x = zx;
5871    if (y) *y = zy;
5872    if (w) *w = zw;
5873    if (h) *h = zh;
5874
5875    if (ec->base_output_resolution.use)
5876      {
5877         if (w) *w = ec->base_output_resolution.w;
5878         if (h) *h = ec->base_output_resolution.h;
5879      }
5880
5881    return EINA_TRUE;
5882 }
5883
5884 E_API Eina_Bool
5885 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)
5886 {
5887    int zx, zy, zw, zh;
5888    E_Zone *zone;
5889
5890    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
5891
5892    zone = e_comp_zone_find_by_ec(ec);
5893    EINA_SAFETY_ON_NULL_RETURN_VAL(zone, EINA_FALSE);
5894
5895    e_zone_desk_useful_geometry_get(zone, ec->desk, &zx, &zy, &zw, &zh, consider_obstacle_area);
5896
5897    if (x) *x = zx;
5898    if (y) *y = zy;
5899    if (w) *w = zw;
5900    if (h) *h = zh;
5901
5902    if (ec->base_output_resolution.use)
5903      {
5904         // TODO: Consider obstacle area
5905         if (w) *w = ec->base_output_resolution.w;
5906         if (h) *h = ec->base_output_resolution.h;
5907      }
5908
5909    return EINA_TRUE;
5910 }
5911
5912 /* change the base_output_resolution of the bind_ec by checking the base_output_resolution of provider_ec's appinfo */
5913 EINTERN Eina_Bool
5914 e_client_base_output_resolution_rsm_update(E_Client *bind_ec, E_Client *provider_ec)
5915 {
5916    E_Appinfo *epai = NULL;
5917    int configured_width, configured_height;
5918    int width, height;
5919    E_Desk *bind_ec_desk;
5920
5921    EINA_SAFETY_ON_NULL_RETURN_VAL(bind_ec, EINA_FALSE);
5922    EINA_SAFETY_ON_NULL_RETURN_VAL(provider_ec, EINA_FALSE);
5923
5924    bind_ec_desk = e_comp_desk_find_by_ec(bind_ec);
5925    EINA_SAFETY_ON_NULL_RETURN_VAL(bind_ec_desk, EINA_FALSE);
5926
5927   if (!e_config->configured_output_resolution.use) return EINA_TRUE;
5928
5929   configured_width = e_config->configured_output_resolution.w;
5930   configured_height = e_config->configured_output_resolution.h;
5931
5932   if (bind_ec->base_output_resolution.use)
5933     {
5934        ELOGF("POL_APPINFO", "DELETE EXISTED BINDER BASE SCREEN RESOLUTION... base_output_resolution is same with desk size:(%d,%d), bind_pid:%d", bind_ec,
5935              bind_ec->base_output_resolution.w, bind_ec->base_output_resolution.h, bind_ec->netwm.pid);
5936
5937        bind_ec->base_output_resolution.use = 0;
5938        bind_ec->base_output_resolution.w = 0;
5939        bind_ec->base_output_resolution.h = 0;
5940        e_client_transform_core_remove(bind_ec, bind_ec->base_output_resolution.transform);
5941        E_FREE_FUNC(bind_ec->base_output_resolution.transform, e_util_transform_del);
5942     }
5943
5944   if (!provider_ec->netwm.pid)
5945     {
5946        ELOGF("POL_APPINFO", "NO PROVIDER PID... USE configured_output_resolution(%d,%d) provider_pid:%d", provider_ec,
5947              configured_width, configured_height, provider_ec->netwm.pid);
5948        goto use_configured;
5949     }
5950
5951    epai = e_appinfo_find_with_pid(provider_ec->netwm.pid);
5952    if (!epai)
5953      {
5954         ELOGF("POL_APPINFO", "NO PROVIDER APPINFO... USE configured_output_resolution(%d,%d) provider_pid:%d", provider_ec,
5955               configured_width, configured_height, provider_ec->netwm.pid);
5956         goto use_configured;
5957      }
5958
5959    if (!e_appinfo_base_output_resolution_get(epai, &width, &height))
5960      {
5961         ELOGF("POL_APPINFO", "NO PROVIDER APPINFO BASE SCREEN RESOLUTION... USE configured_output_resolution(%d,%d) provider_pid:%d", provider_ec,
5962               configured_width, configured_height, provider_ec->netwm.pid);
5963         goto use_configured;
5964       }
5965
5966    if ((width == 0) && (height == 0))
5967      {
5968         ELOGF("POL_APPINFO", "NO PROVIDER WIDTH and HEIGHT... SKIP base_output_resolution due to size:(%d,%d) provider_pid:%d", provider_ec,
5969              width, height, provider_ec->netwm.pid);
5970         return EINA_TRUE;
5971      }
5972
5973    if ((bind_ec_desk->geom.w == width) && (bind_ec_desk->geom.h == height))
5974      {
5975         ELOGF("POL_APPINFO", "SKIP SET BINDER BASE SCREEN RESOLUTION... base_output_resolution is same with desk size:(%d,%d), bind_pid:%d", bind_ec,
5976             width, height, bind_ec->netwm.pid);
5977         return EINA_TRUE;
5978      }
5979
5980    /* set the base_output_resolution of the e_client */
5981    _e_client_base_output_resolution_set(bind_ec, width, height);
5982    e_client_base_output_resolution_transform_adjust(bind_ec);
5983
5984    ELOGF("POL_APPINFO", "USE BINDER base_output_resolution(%d,%d) bind_pid:%d", bind_ec, width, height, bind_ec->netwm.pid);
5985
5986    return EINA_TRUE;
5987
5988 use_configured:
5989
5990    if ((bind_ec_desk->geom.w == configured_width) && (bind_ec_desk->geom.h == configured_height))
5991      {
5992         ELOGF("POL_APPINFO", "SKIP BINDER use configured_output_resolution (same with desk size:(%d,%d), bind_pid:%d)", bind_ec,
5993              configured_width, configured_height, bind_ec->netwm.pid);
5994      }
5995    else
5996      {
5997         /* set the base_output_resolution of the e_client as a default */
5998         _e_client_base_output_resolution_set(bind_ec, configured_width, configured_height);
5999      }
6000
6001    return EINA_TRUE;
6002 }
6003
6004 /* tizen_move_resize */
6005 EINTERN Eina_Bool
6006 e_client_pending_geometry_has(E_Client *ec)
6007 {
6008    if (!eina_list_count(ec->surface_sync.pending_geometry))
6009      return EINA_FALSE;
6010
6011    return ec->surface_sync.wait_commit;
6012 }
6013
6014 EINTERN void
6015 e_client_pending_geometry_flush(E_Client *ec)
6016 {
6017    E_Client_Pending_Geometry *geo;
6018
6019    if (!eina_list_count(ec->surface_sync.pending_geometry))
6020      {
6021         EINA_LIST_FREE(ec->surface_sync.pending_geometry, geo)
6022           {
6023              E_FREE(geo);
6024           }
6025         ec->surface_sync.wait_commit = EINA_FALSE;
6026         ELOGF("POSSIZE", "pending geometry has flushed", ec);
6027      }
6028 }
6029
6030 EINTERN void
6031 e_client_pending_geometry_last_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
6032 {
6033    Eina_List *l;
6034    E_Client_Pending_Geometry *geo;
6035    int gx = 0;
6036    int gy = 0;
6037    int gw = 0;
6038    int gh = 0;
6039
6040    EINA_LIST_REVERSE_FOREACH(ec->surface_sync.pending_geometry, l, geo)
6041      {
6042         gx = geo->x;
6043         gy = geo->y;
6044         gw = geo->w;
6045         gh = geo->h;
6046         break;
6047      }
6048
6049    if (x) *x = gx;
6050    if (y) *y = gy;
6051    if (w) *w = gw;
6052    if (h) *h = gh;
6053 }
6054
6055 E_API void
6056 e_client_frame_focus_set(E_Client *ec, Eina_Bool focus)
6057 {
6058    if (!ec) return;
6059    evas_object_focus_set(ec->frame, focus);
6060 }
6061
6062 EINTERN void
6063 e_client_frame_geometry_set(E_Client *ec, int x, int y, int w, int h)
6064 {
6065    if (!ec) return;
6066
6067    if (ec->internal || ec->input_only)
6068      {
6069         evas_object_geometry_set(ec->frame, x, y, w, h);
6070      }
6071    else
6072      {
6073         if ((ec->w != w) || (ec->h != h))
6074           {
6075              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);
6076              ec->move_after_resize = EINA_TRUE;
6077
6078              e_client_pos_set(ec, x, y);
6079              evas_object_resize(ec->frame, w, h);
6080           }
6081         else
6082           evas_object_geometry_set(ec->frame, x, y, w, h);
6083      }
6084 }
6085
6086 EAPI void
6087 e_client_util_move_resize_without_frame(E_Client *ec, int x, int y, int w, int h)
6088 {
6089    if (!ec) return;
6090
6091    if (ec->internal || ec->input_only)
6092      {
6093         e_client_util_move_without_frame(ec, x, y);
6094         e_client_util_resize_without_frame(ec, w, h);
6095      }
6096    else
6097      {
6098         if ((ec->w != w) || (ec->h != h))
6099           {
6100              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);
6101              ec->move_after_resize = EINA_TRUE;
6102
6103              e_comp_object_frame_xy_adjust(ec->frame, x, y, &x, &y);
6104              e_client_pos_set(ec, x, y);
6105              e_client_util_resize_without_frame(ec, w, h);
6106           }
6107         else
6108           {
6109              e_client_util_move_without_frame(ec, x, y);
6110              e_client_util_resize_without_frame(ec, w, h);
6111           }
6112      }
6113 }
6114
6115 E_API Eina_Bool
6116 e_client_layer_set(E_Client *ec,
6117                    E_Layer layer)
6118 {
6119    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
6120    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, EINA_FALSE);
6121    if (!ec->frame) return EINA_FALSE;
6122
6123    if (e_comp_canvas_client_layer_map(layer) == 9999)
6124      return EINA_FALSE; //invalid layer is not allowed
6125
6126    if (ec->desk_area.enable)
6127      {
6128         if (e_client_layer_set_by_desk_area(ec, layer))
6129           {
6130              // restack according to desk group rule
6131              e_desk_area_ec_rearrange(ec->desk_area.desk_area, ec);
6132              return EINA_TRUE;
6133           }
6134      }
6135    ec->desk_area.layer_backup = layer;
6136
6137    evas_object_layer_set(ec->frame, layer);
6138    if (ec->layer != layer)
6139      {
6140         /* check exceptional case */
6141         if ((ec->fullscreen) &&
6142             (ec->saved.layer != layer))
6143           {
6144              ELOGF("LAYER", "(%d) fail to backup at saved.layer for fullscreen", ec, layer);
6145              return EINA_FALSE;
6146           }
6147         // if e_comp_object fail to change ec->layer due to ec->layer_pending or block
6148         // leave log and apply ec->layer according to set
6149         // as a result it restores back to given layer when pending or block is free
6150         ELOGF("LAYER", "change layer from %d to %d if in case layer pending(%d) or block(%d)",
6151               ec, ec->layer, layer, ec->layer_pending, ec->layer_block);
6152         if (ec->layer_pending || ec->layer_block)
6153           {
6154              ec->layer = layer;
6155              return EINA_TRUE;
6156           }
6157      }
6158
6159    wl_signal_emit_mutable(&PRI(ec)->events.layer_set, NULL);
6160
6161    return EINA_TRUE;
6162 }
6163
6164 E_API E_Layer
6165 e_client_layer_get(E_Client *ec)
6166 {
6167    short layer;
6168
6169    E_OBJECT_CHECK_RETURN(ec, E_LAYER_BOTTOM);
6170    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, E_LAYER_BOTTOM);
6171    if (!ec->frame) return E_LAYER_BOTTOM;
6172
6173    layer = evas_object_layer_get(ec->frame);
6174    if (ec->layer != layer)
6175      {
6176         /* client could be on temperory layer while pending or block,
6177          * in that case, client restores back to ec->layer after pending/block finish */
6178         if (ec->layer_block || ec->layer_pending)
6179           return ec->layer;
6180
6181         /* otherwise, client is on unexpected layer */
6182         ELOGF("LAYER", "layer dismatch ec->layer %d | evas obj layer %d ",
6183               ec, ec->layer, layer);
6184
6185         if (e_comp_canvas_client_layer_map(layer) == 9999)
6186           return E_LAYER_BOTTOM; //not on E_LAYER_CLIENT
6187      }
6188
6189    return ec->layer;
6190 }
6191
6192 static void
6193 _e_client_desk_area_original_layer_save(E_Client *ec, E_Layer layer)
6194 {
6195    E_OBJECT_CHECK(ec);
6196    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
6197    ec->desk_area.layer_backup = layer;
6198 }
6199
6200 EINTERN Eina_Bool
6201 e_client_layer_set_by_desk_area(E_Client *ec, E_Layer layer)
6202 {
6203    E_Desk_Area *eda;
6204    E_Layer edg_layer;
6205    E_Layer org_layer;
6206
6207    if (!ec) return EINA_FALSE;
6208    if (!ec->frame) return EINA_FALSE;
6209    if (!ec->desk_area.enable) return EINA_FALSE;
6210    if (!ec->desk_area.desk_area) return EINA_FALSE;
6211
6212    eda = ec->desk_area.desk_area;
6213
6214    // save original layer
6215    _e_client_desk_area_original_layer_save(ec, layer);
6216
6217    // get desk_area layer
6218    edg_layer = (E_Layer)e_desk_area_layer_get(eda);
6219    org_layer = e_client_desk_area_original_layer_get(ec);
6220
6221    ELOGF("EDG", "layer_set by desk_area... layer:%d, org_layer:%d, new_layer:%d", ec, layer, org_layer, edg_layer);
6222    if (org_layer == edg_layer)
6223      {
6224         e_client_raise(ec);
6225      }
6226    else
6227      {
6228         evas_object_layer_set(ec->frame, edg_layer);
6229         if (edg_layer == ec->layer)
6230           e_client_raise(ec);
6231      }
6232
6233    return EINA_TRUE;
6234 }
6235
6236 EINTERN void
6237 e_client_desk_area_original_layer_restore(E_Client *ec)
6238 {
6239    if (!ec) return;
6240
6241    // Do we need to check ec->desk_area.enable?
6242    // if ec->desk_area.enable is true, then e_client_layer_set calls
6243    // e_desk_area_ec_edg_layer_set(). that's too bad. :(
6244    // so, we MUST make a policy for ordering of the desk group layer restore
6245    // and the desk group enable.
6246    if (ec->desk_area.enable) return;
6247    e_client_layer_set(ec, ec->desk_area.layer_backup);
6248 }
6249
6250 EINTERN E_Layer
6251 e_client_desk_area_original_layer_get(E_Client *ec)
6252 {
6253    if (!ec) return E_LAYER_DESKTOP;
6254
6255    if (ec->desk_area.enable)
6256      return ec->desk_area.layer_backup;
6257    else
6258      return ec->layer;
6259 }
6260
6261 EINTERN Eina_Bool
6262 e_client_desk_area_client_layer_set(E_Client *ec, E_Desk_Area_Client_Layer edgc_layer)
6263 {
6264    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
6265    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, EINA_FALSE);
6266    if ((edgc_layer < E_DESK_AREA_CLIENT_LAYER_DESKTOP) ||
6267        (edgc_layer >= E_DESK_AREA_CLIENT_LAYER_MAX))
6268      return EINA_FALSE;
6269
6270    ec->desk_area.edgc_layer = edgc_layer;
6271    return EINA_TRUE;
6272 }
6273
6274 EINTERN E_Desk_Area_Client_Layer
6275 e_client_desk_area_client_layer_get(E_Client *ec)
6276 {
6277    E_OBJECT_CHECK_RETURN(ec, E_DESK_AREA_CLIENT_LAYER_DESKTOP);
6278
6279    return ec->desk_area.edgc_layer;
6280 }
6281
6282 //FIXME: use e_desk_area_ec_reassign(eda, ec) instead of this api
6283 E_API Eina_Bool
6284 e_client_desk_area_set(E_Client *ec, E_Desk_Area *eda)
6285 {
6286    E_Desk_Area *old_edg;
6287
6288    if (!ec) return EINA_FALSE;
6289
6290 #if 0 // if this is removed.. then below if (eda != old_edg) is removed also...
6291    if (ec->desk_area.desk_area == eda)
6292      return EINA_TRUE;
6293 #endif
6294
6295    ELOGF("EDG", "Desk Group Set (new:%p, old:%p)", ec, eda, ec->desk_area.desk_area);
6296    old_edg = ec->desk_area.desk_area;
6297    if (old_edg)
6298      e_desk_area_ec_remove(old_edg, ec);
6299
6300    ec->desk_area.desk_area = eda;
6301    e_desk_area_ec_add(eda, ec);
6302
6303 #if 0 // if this is removed.. then above if (ec->desk_area.desk_area == eda) is removed also...
6304    if (eda != old_edg)
6305 #endif
6306      {
6307         e_desk_area_ec_update(eda, ec);
6308         e_desk_area_ec_rearrange(ec->desk_area.desk_area, ec);
6309      }
6310
6311    return EINA_TRUE;
6312 }
6313
6314 static void
6315 _raise_between_sibling_under_parent(E_Client *ec)
6316 {
6317    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);
6318    e_client_stack_below(ec, ec->parent);
6319 }
6320
6321 static void
6322 _raise_between_sibling_on_parent(E_Client *ec)
6323 {
6324    E_Client *top_child = NULL;
6325    top_child = e_client_transient_child_top_get(ec->parent, EINA_FALSE);
6326    if (!top_child)
6327      {
6328         ELOGF("POL", "RAISE child window... Stack above on the parent (win:%zx, ec:%p)", ec, e_client_util_win_get(ec->parent), ec->parent);
6329         e_client_stack_above(ec, ec->parent);
6330      }
6331    else
6332      {
6333         if (top_child != ec)
6334           {
6335              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);
6336              e_client_stack_above(ec, top_child);
6337           }
6338         else
6339           ELOGF("POL", "RAISE child window between sibling... already on the top. STAY", ec);
6340      }
6341 }
6342
6343 static void
6344 _raise_belong_to_parent(E_Client *ec)
6345 {
6346    if (e_client_transient_policy_get(ec) == E_TRANSIENT_BELOW)
6347      _raise_between_sibling_under_parent(ec);
6348    else
6349      _raise_between_sibling_on_parent(ec);
6350 }
6351
6352 E_API void
6353 e_client_raise(E_Client *ec)
6354 {
6355    if (!ec) return;
6356
6357    if (ec->desk_area.enable)
6358      {
6359         E_Desk_Area *eda;
6360         eda = ec->desk_area.desk_area;
6361         if (eda)
6362           {
6363              e_desk_area_ec_raise(eda, ec);
6364              return;
6365           }
6366      }
6367
6368    if (ec->parent && e_client_is_belong_to_parent(ec))
6369      _raise_belong_to_parent(ec);
6370    else
6371      evas_object_raise(ec->frame);
6372
6373    wl_signal_emit_mutable(&PRI(ec)->events.raise, NULL);
6374 }
6375
6376 static void
6377 _e_client_transient_for_below_group_make(E_Client *ec, Eina_List **list)
6378 {
6379    // list : Head is the bottommost child
6380    E_Client *child;
6381    Eina_List *l;
6382
6383    if (!ec) return;
6384
6385    EINA_LIST_REVERSE_FOREACH(ec->transients, l, child)
6386      {
6387         if (!child) continue;
6388         if (e_client_transient_policy_get(child) != E_TRANSIENT_BELOW) continue;
6389         if (!e_client_is_belong_to_parent(child)) continue;
6390
6391         *list = eina_list_prepend(*list, child);
6392         _e_client_transient_for_group_make(child, list);
6393      }
6394 }
6395
6396 E_API E_Client *
6397 e_client_transient_child_bottom_get(E_Client *ec)
6398 {
6399    E_Client *bottom_ec = NULL;
6400    Eina_List *transient_below_list = NULL;
6401    Eina_List *l = NULL;
6402
6403    _e_client_transient_for_below_group_make(ec, &transient_below_list);
6404
6405    if (transient_below_list)
6406      {
6407         E_Client *temp_ec = NULL;
6408         E_Client *temp_ec2 = NULL;
6409
6410         E_CLIENT_FOREACH(temp_ec)
6411           {
6412              if (bottom_ec) break;
6413
6414              if (temp_ec == ec)
6415                {
6416                   bottom_ec = ec;
6417                   break;
6418                }
6419
6420              EINA_LIST_FOREACH(transient_below_list, l, temp_ec2)
6421                {
6422                   if (temp_ec == temp_ec2)
6423                     {
6424                        bottom_ec = temp_ec2;
6425                        break;
6426                     }
6427                }
6428           }
6429         eina_list_free(transient_below_list);
6430      }
6431    return bottom_ec;
6432 }
6433
6434 static void
6435 _lower_between_sibling_under_parent(E_Client *ec)
6436 {
6437    E_Client *bottom_child = NULL;
6438    bottom_child = e_client_transient_child_bottom_get(ec->parent);
6439    if (!bottom_child)
6440      {
6441         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);
6442         e_client_stack_below(ec, ec->parent);
6443      }
6444    else
6445      {
6446         if (bottom_child != ec)
6447           {
6448              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);
6449              e_client_stack_below(ec, bottom_child);
6450           }
6451         else
6452           ELOGF("POL", "LOWER child window between sibling... already under the bottom. STAY", ec);
6453      }
6454 }
6455
6456 static void
6457 _lower_between_sibling_on_parent(E_Client *ec)
6458 {
6459    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);
6460    e_client_stack_above(ec, ec->parent);
6461 }
6462
6463 static void
6464 _lower_belong_to_parent(E_Client *ec)
6465 {
6466    if (e_client_transient_policy_get(ec) == E_TRANSIENT_BELOW)
6467      _lower_between_sibling_under_parent(ec);
6468    else
6469      _lower_between_sibling_on_parent(ec);
6470 }
6471
6472 E_API void
6473 e_client_lower(E_Client *ec)
6474 {
6475    if (!ec) return;
6476
6477    if (ec->desk_area.enable)
6478      {
6479         E_Desk_Area *eda;
6480         eda = ec->desk_area.desk_area;
6481         if (eda)
6482           {
6483              e_desk_area_ec_lower(eda, ec);
6484
6485              wl_signal_emit_mutable(&PRI(ec)->events.lower, NULL);
6486              return;
6487           }
6488      }
6489
6490    if (ec->parent && e_client_is_belong_to_parent(ec))
6491      _lower_belong_to_parent(ec);
6492    else
6493      evas_object_lower(ec->frame);
6494
6495    wl_signal_emit_mutable(&PRI(ec)->events.lower, NULL);
6496 }
6497
6498 E_API void
6499 e_client_stack_above(E_Client *ec, E_Client *above)
6500 {
6501    if (!ec) return;
6502    if (!ec->frame) return;
6503    if (!above) return;
6504    if (!above->frame) return;
6505
6506    if (ec->desk_area.enable)
6507      {
6508         E_Desk_Area *eda;
6509         eda = ec->desk_area.desk_area;
6510         if (eda)
6511           {
6512              e_desk_area_ec_stack_above(eda, ec, above);
6513              return;
6514           }
6515      }
6516
6517    evas_object_stack_above(ec->frame, above->frame);
6518
6519    wl_signal_emit_mutable(&PRI(ec)->events.stack_above, NULL);
6520 }
6521
6522 E_API void
6523 e_client_stack_below(E_Client *ec, E_Client *below)
6524 {
6525    if (!ec) return;
6526    if (!ec->frame) return;
6527    if (!below) return;
6528    if (!below->frame) return;
6529
6530    if (ec->desk_area.enable)
6531      {
6532         E_Desk_Area *eda;
6533         eda = ec->desk_area.desk_area;
6534         if (eda)
6535           {
6536              e_desk_area_ec_stack_below(eda, ec, below);
6537              return;
6538           }
6539      }
6540
6541    evas_object_stack_below(ec->frame, below->frame);
6542
6543    wl_signal_emit_mutable(&PRI(ec)->events.stack_below, NULL);
6544 }
6545
6546 E_API int
6547 e_client_show_pending_set(E_Client *ec)
6548 {
6549    if (!ec) return 0;
6550
6551    ec->show_pending.count++;
6552    ELOGF("E_CLIENT", "SET show_pending. (count:%d, run:%d)", ec, ec->show_pending.count, ec->show_pending.running);
6553    return ec->show_pending.count;
6554 }
6555
6556 E_API int
6557 e_client_show_pending_unset(E_Client *ec)
6558 {
6559    if (!ec) return 0;
6560    if (ec->show_pending.count <= 0) return 0;
6561
6562    ec->show_pending.count--;
6563    ELOGF("E_CLIENT", "UNSET show_pending. (count:%d, run:%d)", ec, ec->show_pending.count, ec->show_pending.running);
6564    if (ec->show_pending.count == 0 && ec->show_pending.running)
6565      {
6566         ec->show_pending.running = EINA_FALSE;
6567         if (ec->frame)
6568           {
6569              ELOGF("E_CLIENT", "evas_object_show by unset show_pending", ec);
6570              evas_object_show(ec->frame);
6571              //e_comp_object_damage(ec->frame, 0, 0, ec->w, ec->h);
6572              EC_CHANGED(ec);
6573           }
6574      }
6575
6576    return ec->show_pending.count;
6577 }
6578
6579 static Eina_Bool
6580 _e_client_surface_tree_foreach_helper(E_Client *ec, E_Client_Surface_Tree_Foreach func, void *data)
6581 {
6582    E_Client *subc;
6583    Eina_List *l, *ll;
6584    Eina_Bool res = EINA_TRUE;
6585    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
6586
6587    if (!cdata)
6588      return res;
6589
6590    EINA_LIST_FOREACH_SAFE(cdata->sub.below_list, l, ll, subc)
6591      {
6592         res = _e_client_surface_tree_foreach_helper(subc, func, data);
6593         if (!res)
6594           break;
6595      }
6596
6597    if (res)
6598      {
6599         res = func(data, ec);
6600         if (res)
6601           {
6602              EINA_LIST_FOREACH_SAFE(cdata->sub.list, l, ll, subc)
6603                {
6604                   res = _e_client_surface_tree_foreach_helper(subc,
6605                                                               func,
6606                                                               data);
6607                   if (!res)
6608                     break;
6609                }
6610           }
6611      }
6612
6613    return res;
6614 }
6615
6616 E_API void
6617 e_client_surface_tree_foreach(E_Client *ec, E_Client_Surface_Tree_Foreach func, void *data)
6618 {
6619    EINA_SAFETY_ON_NULL_RETURN(ec);
6620    EINA_SAFETY_ON_NULL_RETURN(func);
6621
6622    _e_client_surface_tree_foreach_helper(ec, func, data);
6623 }
6624
6625 EINTERN E_Comp_Wl_Client_Data *
6626 e_client_cdata_new(E_Client *ec)
6627 {
6628    E_Comp_Wl_Client_Data *cdata;
6629
6630    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
6631
6632    if (!(cdata = E_NEW(E_Comp_Wl_Client_Data, 1)))
6633      {
6634         ERR("Could not allocate new E_Comp_Wl_Client_Data structure");
6635         return NULL;
6636      }
6637    ec->comp_data = cdata;
6638
6639    return cdata;
6640 }
6641
6642 EINTERN void
6643 e_client_cdata_free(E_Client *ec)
6644 {
6645   EINA_SAFETY_ON_NULL_RETURN(ec);
6646   if (!ec->comp_data) return;
6647
6648   E_FREE(ec->comp_data);
6649 }
6650
6651 EINTERN E_Comp_Wl_Client_Data *
6652 e_client_cdata_get(E_Client *ec)
6653 {
6654    if (!ec) return NULL;
6655
6656    return ec->comp_data;
6657 }
6658
6659 EINTERN Eina_Bool
6660 e_client_map_set(E_Client *ec, E_Map *em)
6661 {
6662    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6663
6664    return e_map_set_to_comp_object(em, ec->frame);
6665 }
6666
6667 E_API E_Map *
6668 e_client_map_get(const E_Client *ec)
6669 {
6670    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
6671
6672    return e_map_get_from_comp_object(ec->frame);
6673 }
6674
6675 EINTERN Eina_Bool
6676 e_client_map_enable_set(E_Client *ec, Eina_Bool enable)
6677 {
6678    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6679    EINA_SAFETY_ON_NULL_RETURN_VAL(ec->frame, EINA_FALSE);
6680
6681    evas_object_map_enable_set(ec->frame, enable);
6682
6683    return EINA_TRUE;
6684 }
6685
6686 EINTERN void
6687 e_client_belong_to_parent_set(E_Client *ec, Eina_Bool set)
6688 {
6689    if (!ec) return;
6690    ec->belong_to_parent = set;
6691 }
6692
6693 EINTERN Eina_Bool
6694 e_client_is_belong_to_parent(E_Client *ec)
6695 {
6696    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6697    return ec->belong_to_parent;
6698 }
6699
6700 EINTERN void
6701 e_client_transient_policy_set(E_Client *ec, E_Transient policy)
6702 {
6703    if (!ec) return;
6704    ec->transient_policy = policy;
6705 }
6706
6707 E_API E_Transient
6708 e_client_transient_policy_get(E_Client *ec)
6709 {
6710    if (!ec) return E_TRANSIENT_ABOVE;
6711    return ec->transient_policy;
6712 }
6713
6714 EINTERN void
6715 e_client_resize_object_create_cb_set(E_Client_Resize_Object_Create_Cb cb)
6716 {
6717    if (_e_client_resize_object_create_cb && cb)
6718      CRI("ATTEMPTING TO OVERWRITE EXISTING CLIENT RESIZE OBJECT CREATE HOOK!!!");
6719    _e_client_resize_object_create_cb = cb;
6720 }
6721
6722 EINTERN void
6723 e_client_resize_unit_size_set(E_Client *ec, unsigned int unit_size)
6724 {
6725    if (!ec) return;
6726
6727    // FYI, we consider 0 and 1 to be the same value as a default unit size.
6728    ec->manage_resize.unit_size = unit_size;
6729 }
6730
6731 EINTERN void
6732 e_client_desk_zoom_enable_set(E_Client *ec, Eina_Bool enable)
6733 {
6734    if (!ec) return;
6735    ec->desk_zoom.enable = enable;
6736 }
6737
6738 EINTERN Eina_Bool
6739 e_client_desk_zoom_enable_get(E_Client *ec)
6740 {
6741    if (!ec) return EINA_FALSE;
6742    return ec->desk_zoom.enable;
6743 }
6744
6745 EINTERN void
6746 e_client_layout_apply(E_Client *ec, Eina_Bool apply)
6747 {
6748    if (!ec) return;
6749    ec->apply_layout = apply;
6750 }
6751
6752 EINTERN Eina_Bool
6753 e_client_is_layout_apply(E_Client *ec)
6754 {
6755    if (!ec) return EINA_FALSE;
6756    return ec->apply_layout;
6757 }
6758
6759 E_API E_Client *
6760 e_client_from_surface_resource(struct wl_resource *surface_resource)
6761 {
6762    EINA_SAFETY_ON_NULL_RETURN_VAL(surface_resource, NULL);
6763
6764    return e_comp_wl_util_client_from_surface_resource(surface_resource);
6765 }
6766
6767 EINTERN void
6768 e_client_fps_update(E_Client *ec)
6769 {
6770    double dt;
6771    double tim;
6772
6773    EINA_SAFETY_ON_NULL_RETURN(ec);
6774
6775    if (!ec->fps.enabled) return;
6776
6777    tim = ecore_time_get();
6778
6779    dt = tim - ec->fps.frametimes[0];
6780
6781    ec->fps.frametimes[0] = tim;
6782    ec->fps.time += dt;
6783    ec->fps.cframes++;
6784
6785    if (ec->fps.lapse == 0.0)
6786      {
6787         ec->fps.lapse = tim;
6788         ec->fps.flapse = ec->fps.cframes;
6789      }
6790    else if ((tim - ec->fps.lapse) >= 0.5)
6791      {
6792         ec->fps.fps = (ec->fps.cframes - ec->fps.flapse) /
6793                       (tim - ec->fps.lapse);
6794         ec->fps.lapse = tim;
6795         ec->fps.flapse = ec->fps.cframes;
6796         ec->fps.time = 0.0;
6797      }
6798 }
6799
6800 EINTERN Eina_Bool
6801 e_client_fps_get(E_Client *ec, double *fps)
6802 {
6803    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6804
6805    if (ec->fps.old_fps == ec->fps.fps)
6806      return EINA_FALSE;
6807
6808    if (ec->fps.fps > 0.0)
6809      {
6810         *fps = ec->fps.fps;
6811         ec->fps.old_fps = ec->fps.fps;
6812         return EINA_TRUE;
6813      }
6814
6815    return EINA_FALSE;
6816 }
6817
6818 EINTERN void
6819 e_client_fps_enable(E_Client *ec, Eina_Bool enable)
6820 {
6821    EINA_SAFETY_ON_NULL_RETURN(ec);
6822
6823    ec->fps.enabled = enable;
6824 }
6825
6826 EINTERN Eina_Bool
6827 e_client_explicit_sync_get(E_Client *ec)
6828 {
6829    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6830
6831    return ec->explicit_sync;
6832 }
6833
6834 EINTERN Eina_Bool
6835 e_client_explicit_sync_set(E_Client *ec, Eina_Bool enable)
6836 {
6837    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6838
6839    ec->explicit_sync = enable;
6840
6841    return EINA_TRUE;
6842 }
6843
6844 EINTERN int
6845 e_client_explicit_sync_acquire_fence_fd_get(E_Client *ec)
6846 {
6847    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, -1);
6848
6849    return ec->acquire_fence_fd;
6850 }
6851
6852 EINTERN Eina_Bool
6853 e_client_explicit_sync_acquire_fence_fd_set(E_Client *ec, int fd)
6854 {
6855   EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6856
6857   ec->acquire_fence_fd = fd;
6858
6859   return EINA_TRUE;
6860 }
6861
6862 EINTERN Eina_Bool
6863 e_client_intercept_hook_auto_placement_call(E_Client *ec)
6864 {
6865   // no need to call the intercept hook if ec is NULL.
6866   if (!ec) return EINA_FALSE;
6867
6868   if (!_e_client_intercept_hook_call(E_CLIENT_INTERCEPT_HOOK_AUTO_PLACEMENT, ec))
6869     {
6870        ELOGF("FOCUS", "E_CLIENT_INTERCEPT_HOOK_AUTO_PLACEMENT Intercepted.", ec);
6871        return EINA_TRUE;
6872     }
6873
6874   return EINA_FALSE;
6875 }
6876
6877 EINTERN void
6878 e_client_iconify_event_send(E_Client *ec)
6879 {
6880    EINA_SAFETY_ON_NULL_RETURN(ec);
6881
6882    _e_client_event_simple(ec, E_EVENT_CLIENT_ICONIFY);
6883 }
6884
6885 EINTERN void
6886 e_client_uniconify_event_send(E_Client *ec)
6887 {
6888    EINA_SAFETY_ON_NULL_RETURN(ec);
6889
6890    _e_client_event_simple(ec, E_EVENT_CLIENT_UNICONIFY);
6891 }
6892
6893 EINTERN void
6894 e_client_stack_transient_for_done_notify(E_Client *ec)
6895 {
6896    EINA_SAFETY_ON_NULL_RETURN(ec);
6897
6898    wl_signal_emit_mutable(&PRI(ec)->events.stack_transient_for_done, NULL);
6899 }
6900
6901 EINTERN void
6902 e_client_eval_pre_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
6903 {
6904    API_ENTRY;
6905    wl_signal_add(&priv->events.eval_pre_fetch, listener);
6906 }
6907
6908 EINTERN void
6909 e_client_eval_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
6910 {
6911    API_ENTRY;
6912    wl_signal_add(&priv->events.eval_fetch, listener);
6913 }
6914
6915 EINTERN void
6916 e_client_eval_pre_post_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
6917 {
6918    API_ENTRY;
6919    wl_signal_add(&priv->events.eval_pre_post_fetch, listener);
6920 }
6921
6922 EINTERN void
6923 e_client_eval_post_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
6924 {
6925    API_ENTRY;
6926    wl_signal_add(&priv->events.eval_post_fetch, listener);
6927 }
6928
6929 EINTERN void
6930 e_client_eval_pre_frame_assign_listener_add(E_Client *ec, struct wl_listener *listener)
6931 {
6932    API_ENTRY;
6933    wl_signal_add(&priv->events.eval_pre_frame_assign, listener);
6934 }
6935
6936 EINTERN void
6937 e_client_eval_post_frame_assign_listener_add(E_Client *ec, struct wl_listener *listener)
6938 {
6939    API_ENTRY;
6940    wl_signal_add(&priv->events.eval_post_frame_assign, listener);
6941 }
6942
6943 EINTERN void
6944 e_client_eval_pre_new_client_listener_add(E_Client *ec, struct wl_listener *listener)
6945 {
6946    API_ENTRY;
6947    wl_signal_add(&priv->events.eval_pre_new_client, listener);
6948 }
6949
6950 EINTERN void
6951 e_client_eval_post_new_client_listener_add(E_Client *ec, struct wl_listener *listener)
6952 {
6953    API_ENTRY;
6954    wl_signal_add(&priv->events.eval_post_new_client, listener);
6955 }
6956
6957 EINTERN void
6958 e_client_eval_visibility_listener_add(E_Client *ec, struct wl_listener *listener)
6959 {
6960    API_ENTRY;
6961    wl_signal_add(&priv->events.eval_visibility, listener);
6962 }
6963
6964 EINTERN void
6965 e_client_eval_visibility_end_listener_add(E_Client *ec, struct wl_listener *listener)
6966 {
6967    API_ENTRY;
6968    wl_signal_add(&priv->events.eval_visibility_end, listener);
6969 }
6970
6971 EINTERN void
6972 e_client_eval_end_listener_add(E_Client *ec, struct wl_listener *listener)
6973 {
6974    API_ENTRY;
6975    wl_signal_add(&priv->events.eval_end, listener);
6976 }
6977
6978 EINTERN void
6979 e_client_move_begin_listener_add(E_Client *ec, struct wl_listener *listener)
6980 {
6981    API_ENTRY;
6982    wl_signal_add(&priv->events.move_begin, listener);
6983 }
6984
6985 EINTERN void
6986 e_client_move_update_listener_add(E_Client *ec, struct wl_listener *listener)
6987 {
6988    API_ENTRY;
6989    wl_signal_add(&priv->events.move_update, listener);
6990 }
6991
6992 EINTERN void
6993 e_client_move_end_listener_add(E_Client *ec, struct wl_listener *listener)
6994 {
6995    API_ENTRY;
6996    wl_signal_add(&priv->events.move_end, listener);
6997 }
6998
6999 EINTERN void
7000 e_client_move_resize_begin_listener_add(E_Client *ec, struct wl_listener *listener)
7001 {
7002    API_ENTRY;
7003    wl_signal_add(&priv->events.move_resize_begin, listener);
7004 }
7005
7006 EINTERN void
7007 e_client_move_resize_update_listener_add(E_Client *ec, struct wl_listener *listener)
7008 {
7009    API_ENTRY;
7010    wl_signal_add(&priv->events.move_resize_update, listener);
7011 }
7012
7013 EINTERN void
7014 e_client_move_resize_end_listener_add(E_Client *ec, struct wl_listener *listener)
7015 {
7016    API_ENTRY;
7017    wl_signal_add(&priv->events.move_resize_end, listener);
7018 }
7019
7020 EINTERN void
7021 e_client_destroy_listener_add(E_Client *ec, struct wl_listener *listener)
7022 {
7023    API_ENTRY;
7024    wl_signal_add(&priv->events.destroy, listener);
7025 }
7026
7027 EINTERN void
7028 e_client_new_client_listener_add(E_Client *ec, struct wl_listener *listener)
7029 {
7030    API_ENTRY;
7031    wl_signal_add(&priv->events.new_client, listener);
7032 }
7033
7034 EINTERN void
7035 e_client_new_client_post_listener_add(E_Client *ec, struct wl_listener *listener)
7036 {
7037    API_ENTRY;
7038    wl_signal_add(&priv->events.new_client_post, listener);
7039 }
7040
7041 EINTERN void
7042 e_client_unredirect_listener_add(E_Client *ec, struct wl_listener *listener)
7043 {
7044    API_ENTRY;
7045    wl_signal_add(&priv->events.unredirect, listener);
7046 }
7047
7048 EINTERN void
7049 e_client_redirect_listener_add(E_Client *ec, struct wl_listener *listener)
7050 {
7051    API_ENTRY;
7052    wl_signal_add(&priv->events.redirect, listener);
7053 }
7054
7055 EINTERN void
7056 e_client_aux_hint_change_listener_add(E_Client *ec, struct wl_listener *listener)
7057 {
7058    API_ENTRY;
7059    wl_signal_add(&priv->events.aux_hint_change, listener);
7060 }
7061
7062 EINTERN void
7063 e_client_window_role_change_listener_add(E_Client *ec, struct wl_listener *listener)
7064 {
7065    API_ENTRY;
7066    wl_signal_add(&priv->events.window_role_change, listener);
7067 }
7068
7069 EINTERN void
7070 e_client_transform_change_listener_add(E_Client *ec, struct wl_listener *listener)
7071 {
7072    API_ENTRY;
7073    wl_signal_add(&priv->events.transform_change, listener);
7074 }
7075
7076 EINTERN void
7077 e_client_activate_done_listener_add(E_Client *ec, struct wl_listener *listener)
7078 {
7079    API_ENTRY;
7080    wl_signal_add(&priv->events.activate_done, listener);
7081 }
7082
7083 EINTERN void
7084 e_client_mouse_in_listener_add(E_Client *ec, struct wl_listener *listener)
7085 {
7086    API_ENTRY;
7087    wl_signal_add(&priv->events.mouse_in, listener);
7088 }
7089
7090 EINTERN void
7091 e_client_mouse_out_listener_add(E_Client *ec, struct wl_listener *listener)
7092 {
7093    API_ENTRY;
7094    wl_signal_add(&priv->events.mouse_out, listener);
7095 }
7096
7097 EINTERN void
7098 e_client_mouse_down_listener_add(E_Client *ec, struct wl_listener *listener)
7099 {
7100    API_ENTRY;
7101    wl_signal_add(&priv->events.mouse_down, listener);
7102 }
7103
7104 EINTERN void
7105 e_client_focus_set_listener_add(E_Client *ec, struct wl_listener *listener)
7106 {
7107    API_ENTRY;
7108    wl_signal_add(&priv->events.focus_set, listener);
7109 }
7110
7111 EINTERN void
7112 e_client_focus_unset_listener_add(E_Client *ec, struct wl_listener *listener)
7113 {
7114    API_ENTRY;
7115    wl_signal_add(&priv->events.focus_unset, listener);
7116 }
7117
7118 EINTERN void
7119 e_client_focus_defer_set_listener_add(E_Client *ec, struct wl_listener *listener)
7120 {
7121    API_ENTRY;
7122    wl_signal_add(&priv->events.focus_defer_set, listener);
7123 }
7124
7125 EINTERN void
7126 e_client_focus_latest_set_listener_add(E_Client *ec, struct wl_listener *listener)
7127 {
7128    API_ENTRY;
7129    wl_signal_add(&priv->events.focus_latest_set, listener);
7130 }
7131
7132 EINTERN void
7133 e_client_iconify_listener_add(E_Client *ec, struct wl_listener *listener)
7134 {
7135    API_ENTRY;
7136    wl_signal_add(&priv->events.iconify, listener);
7137 }
7138
7139 EINTERN void
7140 e_client_uniconify_listener_add(E_Client *ec, struct wl_listener *listener)
7141 {
7142    API_ENTRY;
7143    wl_signal_add(&priv->events.uniconify, listener);
7144 }
7145
7146 EINTERN void
7147 e_client_maximize_listener_add(E_Client *ec, struct wl_listener *listener)
7148 {
7149    API_ENTRY;
7150    wl_signal_add(&priv->events.maximize, listener);
7151 }
7152
7153 EINTERN void
7154 e_client_unmaximize_listener_add(E_Client *ec, struct wl_listener *listener)
7155 {
7156    API_ENTRY;
7157    wl_signal_add(&priv->events.unmaximize, listener);
7158 }
7159
7160 EINTERN void
7161 e_client_fullscreen_pre_listener_add(E_Client *ec, struct wl_listener *listener)
7162 {
7163    API_ENTRY;
7164    wl_signal_add(&priv->events.fullscreen_pre, listener);
7165 }
7166
7167 EINTERN void
7168 e_client_fullscreen_listener_add(E_Client *ec, struct wl_listener *listener)
7169 {
7170    API_ENTRY;
7171    wl_signal_add(&priv->events.fullscreen, listener);
7172 }
7173
7174 EINTERN void
7175 e_client_unfullscreen_listener_add(E_Client *ec, struct wl_listener *listener)
7176 {
7177    API_ENTRY;
7178    wl_signal_add(&priv->events.unfullscreen, listener);
7179 }
7180
7181 EINTERN void
7182 e_client_move_listener_add(E_Client *ec, struct wl_listener *listener)
7183 {
7184    API_ENTRY;
7185    wl_signal_add(&priv->events.move, listener);
7186 }
7187
7188 EINTERN void
7189 e_client_raise_listener_add(E_Client *ec, struct wl_listener *listener)
7190 {
7191    API_ENTRY;
7192    wl_signal_add(&priv->events.raise, listener);
7193 }
7194
7195 EINTERN void
7196 e_client_lower_listener_add(E_Client *ec, struct wl_listener *listener)
7197 {
7198    API_ENTRY;
7199    wl_signal_add(&priv->events.lower, listener);
7200 }
7201
7202 EINTERN void
7203 e_client_stack_below_listener_add(E_Client *ec, struct wl_listener *listener)
7204 {
7205    API_ENTRY;
7206    wl_signal_add(&priv->events.stack_below, listener);
7207 }
7208
7209 EINTERN void
7210 e_client_stack_above_listener_add(E_Client *ec, struct wl_listener *listener)
7211 {
7212    API_ENTRY;
7213    wl_signal_add(&priv->events.stack_above, listener);
7214 }
7215
7216 EINTERN void
7217 e_client_layer_set_listener_add(E_Client *ec, struct wl_listener *listener)
7218 {
7219    API_ENTRY;
7220    wl_signal_add(&priv->events.layer_set, listener);
7221 }
7222
7223 EINTERN void
7224 e_client_stack_transient_for_done_listener_add(E_Client *ec, struct wl_listener *listener)
7225 {
7226    API_ENTRY;
7227    wl_signal_add(&priv->events.stack_transient_for_done, listener);
7228 }
7229
7230 EINTERN void
7231 e_client_stick_listener_add(E_Client *ec, struct wl_listener *listener)
7232 {
7233    API_ENTRY;
7234    wl_signal_add(&priv->events.stick, listener);
7235 }
7236
7237 EINTERN void
7238 e_client_unstick_listener_add(E_Client *ec, struct wl_listener *listener)
7239 {
7240    API_ENTRY;
7241    wl_signal_add(&priv->events.unstick, listener);
7242 }
7243
7244 EINTERN struct wl_listener *
7245 e_client_destroy_listener_get(E_Client *ec, wl_notify_func_t notify)
7246 {
7247    API_ENTRY_VAL(NULL);
7248    return wl_signal_get(&priv->events.destroy, notify);
7249 }