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