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