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