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