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