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