e_zone: remove REFACTOR_ZONE_DESK feature
[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    e_comp_object_redirected_set(ec->frame, 0);
947    e_comp_object_render_update_del(ec->frame);
948
949    E_OBJECT(ec)->references++;
950
951    if (ec->new_client)
952      e_comp->new_clients--;
953
954    if (ec->e.state.video_parent && ec->e.state.video_parent_client)
955      {
956         ec->e.state.video_parent_client->e.state.video_child =
957           eina_list_remove(ec->e.state.video_parent_client->e.state.video_child, ec);
958      }
959    if (ec->e.state.video_child)
960      {
961         E_Client *tmp;
962
963         EINA_LIST_FREE(ec->e.state.video_child, tmp)
964           tmp->e.state.video_parent_client = NULL;
965      }
966    E_FREE_FUNC(ec->kill_timer, ecore_timer_del);
967    E_FREE_LIST(ec->pending_resize, free);
968
969    E_FREE_FUNC(ec->map_timer, ecore_timer_del);
970
971    ec->transients = eina_list_free(ec->transients);
972    if (ec->netwm.icons)
973      {
974         int i;
975         for (i = 0; i < ec->netwm.num_icons; i++)
976           free(ec->netwm.icons[i].data);
977         E_FREE(ec->netwm.icons);
978      }
979    E_FREE(ec->netwm.extra_types);
980    eina_stringshare_replace(&ec->border.name, NULL);
981    eina_stringshare_replace(&ec->bordername, NULL);
982    eina_stringshare_replace(&ec->icccm.name, NULL);
983 #if defined(__cplusplus) || defined(c_plusplus)
984    eina_stringshare_replace(&ec->icccm.cpp_class, NULL);
985 #else
986    eina_stringshare_replace(&ec->icccm.class, NULL);
987 #endif
988    eina_stringshare_replace(&ec->icccm.title, NULL);
989    eina_stringshare_replace(&ec->icccm.icon_name, NULL);
990    eina_stringshare_replace(&ec->icccm.machine, NULL);
991    eina_stringshare_replace(&ec->icccm.window_role, NULL);
992    if ((ec->icccm.command.argc > 0) && (ec->icccm.command.argv))
993      {
994         int i;
995
996         for (i = 0; i < ec->icccm.command.argc; i++)
997           free(ec->icccm.command.argv[i]);
998         E_FREE(ec->icccm.command.argv);
999      }
1000    eina_stringshare_replace(&ec->netwm.name, NULL);
1001    eina_stringshare_replace(&ec->netwm.icon_name, NULL);
1002    eina_stringshare_replace(&ec->internal_icon, NULL);
1003    eina_stringshare_replace(&ec->internal_icon_key, NULL);
1004
1005    E_FREE_FUNC(ec->frame, evas_object_del);
1006
1007    E_OBJECT(ec)->references--;
1008    ELOGF("COMP", "CLIENT FREE", ec);
1009
1010    e_uuid_store_entry_del(ec->uuid);
1011
1012    _e_client_private_finish(ec);
1013    free(ec);
1014 }
1015
1016 static void
1017 _e_client_del(E_Client *ec)
1018 {
1019    E_Client *child;
1020    E_Pixmap_Type type;
1021
1022    ec->changed = 0;
1023
1024    if (ec == e_comp_object_dim_client_get())
1025      {
1026         INF("[DIM] client deleted\n");
1027         e_comp_object_dim_client_set(NULL);
1028      }
1029
1030    if (ec->cur_mouse_action)
1031      {
1032         if (ec->cur_mouse_action->func.end)
1033           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
1034      }
1035    if (action_client == ec) _e_client_action_finish();
1036
1037    if (!stopping)
1038      {
1039         e_client_comp_hidden_set(ec, 1);
1040         evas_object_pass_events_set(ec->frame, 1);
1041      }
1042
1043    E_FREE_FUNC(ec->ping_poller, ecore_poller_del);
1044
1045    wl_signal_emit_mutable(&PRI(ec)->events.destroy, NULL);
1046
1047    /* must be called before parent/child clear */
1048    _e_client_hook_call(E_CLIENT_HOOK_DEL, ec);
1049
1050    _e_client_event_remove(ec);
1051
1052    ELOGF("COMP", "CLIENT DEL", ec);
1053
1054    if (ec->parent)
1055      {
1056         ec->parent->transients = eina_list_remove(ec->parent->transients, ec);
1057         ec->parent = NULL;
1058      }
1059    EINA_LIST_FREE(ec->transients, child)
1060      child->parent = NULL;
1061
1062    type = e_pixmap_type_get(ec->pixmap);
1063    if (type < E_PIXMAP_TYPE_MAX)
1064      eina_hash_del_by_key(clients_hash[type], &ec->pixmap);
1065    e_comp->clients = eina_list_remove(e_comp->clients, ec);
1066    e_comp_object_render_update_del(ec->frame);
1067    e_comp_post_update_purge(ec);
1068    if (e_pixmap_free(ec->pixmap))
1069      e_pixmap_client_set(ec->pixmap, NULL);
1070    ec->pixmap = NULL;
1071
1072    // base_output_resolution
1073    e_client_transform_core_remove(ec, ec->base_output_resolution.transform);
1074    e_util_transform_del(ec->base_output_resolution.transform);
1075    ec->base_output_resolution.transform = NULL;
1076    E_FREE_FUNC(ec->base_output_resolution.hook_subsurf_create, e_comp_wl_hook_del);
1077
1078    if (ec->transform_core.transform_list)
1079      {
1080         E_Util_Transform *transform;
1081
1082         EINA_LIST_FREE(ec->transform_core.transform_list, transform)
1083           {
1084              e_util_transform_unref(transform);
1085           }
1086      }
1087
1088    ec->transform_core.result.enable = EINA_FALSE;
1089
1090    _e_client_resize_object_del(ec);
1091
1092    e_comp_visibility_calculation_set(EINA_TRUE);
1093 }
1094
1095 ///////////////////////////////////////////
1096
1097 static Eina_Bool
1098 _e_client_cb_kill_timer(void *data)
1099 {
1100    E_Client *ec = data;
1101
1102 // dont wait until it's hung -
1103 //   if (ec->hung)
1104 //     {
1105    if (ec->netwm.pid > 1)
1106      kill(ec->netwm.pid, SIGKILL);
1107 //     }
1108    ec->kill_timer = NULL;
1109    return ECORE_CALLBACK_CANCEL;
1110 }
1111
1112 static Eina_Bool
1113 _e_client_cb_ping_poller(void *data)
1114 {
1115    E_Client *ec;
1116
1117    ec = data;
1118    if (e_object_is_del(E_OBJECT(ec)))
1119      {
1120         ec->ping_poller = NULL;
1121         return ECORE_CALLBACK_CANCEL;
1122      }
1123
1124    if (ec->ping_ok)
1125      {
1126         if (ec->hung)
1127           {
1128              ec->hung = 0;
1129              evas_object_smart_callback_call(ec->frame, "unhung", NULL);
1130              E_FREE_FUNC(ec->kill_timer, ecore_timer_del);
1131           }
1132      }
1133    else
1134      {
1135         /* if time between last ping and now is greater
1136          * than half the ping interval... */
1137         if ((ecore_loop_time_get() - ec->ping) >
1138             ((e_config->ping_clients_interval *
1139               ecore_poller_poll_interval_get(ECORE_POLLER_CORE)) / 2.0))
1140           {
1141              if (!ec->hung)
1142                {
1143                   ec->hung = 1;
1144                   evas_object_smart_callback_call(ec->frame, "hung", NULL);
1145                   /* FIXME: if below dialog is up - hide it now */
1146                }
1147              if (ec->delete_requested)
1148                {
1149                   /* FIXME: pop up dialog saying app is hung - kill client, or pid */
1150                   e_client_act_kill_begin(ec);
1151                }
1152           }
1153      }
1154    ec->ping_poller = NULL;
1155    e_client_ping(ec);
1156    return ECORE_CALLBACK_CANCEL;
1157 }
1158
1159 ///////////////////////////////////////////
1160
1161 static int
1162 _e_client_action_input_win_new(void)
1163 {
1164    if (comp_grabbed)
1165      {
1166         CRI("DOUBLE COMP GRAB! ACK!!!!");
1167         return 1;
1168      }
1169    comp_grabbed = e_comp_grab_input(1, 1);
1170    if (!comp_grabbed) _e_client_action_input_win_del();
1171    return comp_grabbed;
1172 }
1173
1174 static void
1175 _e_client_action_init(E_Client *ec)
1176 {
1177    action_orig.x = ec->x;
1178    action_orig.y = ec->y;
1179    action_orig.w = ec->w;
1180    action_orig.h = ec->h;
1181
1182    if (action_client)
1183      {
1184         action_client->keyboard_resizing = 0;
1185      }
1186    action_client = ec;
1187 }
1188
1189 static int
1190 _e_client_move_begin(E_Client *ec)
1191 {
1192    if ((ec->fullscreen) || (ec->lock_user_location))
1193      return 0;
1194
1195    if (!_e_client_action_input_win_new()) return 0;
1196    ec->moving = 1;
1197    ecmove = ec;
1198
1199    wl_signal_emit_mutable(&PRI(ec)->events.move_begin, NULL);
1200    _e_client_hook_call(E_CLIENT_HOOK_MOVE_BEGIN, ec);
1201    if (!ec->moving)
1202      {
1203         if (ecmove == ec) ecmove = NULL;
1204         _e_client_action_input_win_del();
1205         return 0;
1206      }
1207    if (!ec->lock_user_stacking)
1208      {
1209         if (e_config->border_raise_on_mouse_action)
1210           e_client_raise(ec);
1211      }
1212
1213    if (e_comp->hwc)
1214      e_comp_client_override_add(ec);
1215
1216    return 1;
1217 }
1218
1219 static int
1220 _e_client_move_end(E_Client *ec)
1221 {
1222    ec->moving = 0;
1223    _e_client_action_input_win_del();
1224
1225    wl_signal_emit_mutable(&PRI(ec)->events.move_end, NULL);
1226    _e_client_hook_call(E_CLIENT_HOOK_MOVE_END, ec);
1227
1228    if (ec->transformed)
1229      _e_client_transform_move_end(ec);
1230
1231    if (e_comp->hwc)
1232      e_comp_client_override_del(ec);
1233
1234    ecmove = NULL;
1235    return 1;
1236 }
1237
1238 static Eina_Bool
1239 _e_client_action_move_timeout(void *data EINA_UNUSED)
1240 {
1241    _e_client_move_end(action_client);
1242    _e_client_action_finish();
1243    return ECORE_CALLBACK_CANCEL;
1244 }
1245
1246 static void
1247 _e_client_action_move_timeout_add(void)
1248 {
1249    E_FREE_FUNC(action_timer, ecore_timer_del);
1250    if (e_config->border_keyboard.timeout)
1251      action_timer = ecore_timer_add(e_config->border_keyboard.timeout, _e_client_action_move_timeout, NULL);
1252 }
1253
1254 static Eina_Bool
1255 _e_client_move_mouse_down(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
1256 {
1257    if (!comp_grabbed) return ECORE_CALLBACK_RENEW;
1258
1259    if (!action_client)
1260      ERR("no action_client!");
1261
1262    if (action_client) _e_client_move_end(action_client);
1263    _e_client_action_finish();
1264    return ECORE_CALLBACK_DONE;
1265 }
1266
1267 static void
1268 _e_client_moveinfo_gather(E_Client *ec, const char *source)
1269 {
1270    if (e_util_glob_match(source, "mouse,*,1"))
1271      ec->moveinfo.down.button = 1;
1272    else if (e_util_glob_match(source, "mouse,*,2"))
1273      ec->moveinfo.down.button = 2;
1274    else if (e_util_glob_match(source, "mouse,*,3"))
1275      ec->moveinfo.down.button = 3;
1276    else
1277      ec->moveinfo.down.button = 0;
1278    if ((ec->moveinfo.down.button >= 1) && (ec->moveinfo.down.button <= 3))
1279      {
1280         ec->moveinfo.down.mx = ec->mouse.last_down[ec->moveinfo.down.button - 1].mx;
1281         ec->moveinfo.down.my = ec->mouse.last_down[ec->moveinfo.down.button - 1].my;
1282      }
1283    else
1284      {
1285         ec->moveinfo.down.mx = ec->mouse.current.mx;
1286         ec->moveinfo.down.my = ec->mouse.current.my;
1287      }
1288 }
1289
1290 static void
1291 _e_client_move_handle(E_Client *ec)
1292 {
1293    int x, y;
1294
1295    if ((ec->moveinfo.down.button >= 1) && (ec->moveinfo.down.button <= 3))
1296      {
1297         x = ec->mouse.last_down[ec->moveinfo.down.button - 1].x +
1298            (ec->mouse.current.mx - ec->moveinfo.down.mx);
1299         y = ec->mouse.last_down[ec->moveinfo.down.button - 1].y +
1300            (ec->mouse.current.my - ec->moveinfo.down.my);
1301      }
1302    else
1303      {
1304         x = ec->moveinfo.down.x +
1305            (ec->mouse.current.mx - ec->moveinfo.down.mx);
1306         y = ec->moveinfo.down.y +
1307            (ec->mouse.current.my - ec->moveinfo.down.my);
1308      }
1309
1310    if (e_config->screen_limits == E_CLIENT_OFFSCREEN_LIMIT_ALLOW_NONE)
1311      _e_client_stay_within_canvas(ec, x, y, &x, &y);
1312
1313    if (ec->floating)
1314      _e_client_stay_within_canvas_margin(ec, x, y, &x, &y);
1315
1316    evas_object_move(ec->frame, x, y);
1317
1318    if (e_client_transform_core_enable_get(ec))
1319      {
1320         e_client_transform_core_update(ec);
1321      }
1322 }
1323
1324 static Evas_Object *
1325 _e_client_resize_object_rectangle_get(E_Client *ec)
1326 {
1327    Evas_Object *resize_obj = NULL;
1328
1329    resize_obj = evas_object_rectangle_add(evas_object_evas_get(ec->frame));
1330    EINA_SAFETY_ON_NULL_RETURN_VAL(resize_obj, NULL);
1331
1332    if (e_config->resize_object.customize)
1333      {
1334         evas_object_color_set(resize_obj,
1335                               e_config->resize_object.r,
1336                               e_config->resize_object.g,
1337                               e_config->resize_object.b,
1338                               e_config->resize_object.a);
1339      }
1340    else
1341      evas_object_color_set(resize_obj, 128, 128, 128, 100);
1342
1343    return resize_obj;
1344 }
1345
1346 static Evas_Object *
1347 _e_client_resize_object_image_get(E_Client *ec)
1348 {
1349    int err;
1350    Evas_Object *resize_obj = NULL;
1351
1352    if (!e_config->resize_object.image_path)
1353      {
1354         ELOGF("COMP", "NO resize_object image! Make default resize_object", ec);
1355         goto get_rectangle;
1356      }
1357
1358    resize_obj = evas_object_image_add(evas_object_evas_get(ec->frame));
1359    EINA_SAFETY_ON_NULL_RETURN_VAL(resize_obj, NULL);
1360
1361    evas_object_image_file_set(resize_obj, e_config->resize_object.image_path, NULL);
1362    err = evas_object_image_load_error_get(resize_obj);
1363    if (err != EVAS_LOAD_ERROR_NONE)
1364      {
1365         ELOGF("COMP", "Image load error. path:%s, errno:%d. Make default resize_object",
1366               ec, e_config->resize_object.image_path, err);
1367         evas_object_del(resize_obj);
1368         resize_obj = NULL;
1369         goto get_rectangle;
1370      }
1371
1372    evas_object_image_fill_set(resize_obj, 0, 0, ec->w, ec->h);
1373    evas_object_image_filled_set(resize_obj, EINA_TRUE);
1374
1375    evas_object_image_border_set(resize_obj,
1376                                 e_config->resize_object.border_width.l,
1377                                 e_config->resize_object.border_width.r,
1378                                 e_config->resize_object.border_width.t,
1379                                 e_config->resize_object.border_width.b);
1380
1381    return resize_obj;
1382
1383 get_rectangle:
1384    return _e_client_resize_object_rectangle_get(ec);
1385 }
1386
1387 static Evas_Object *
1388 _e_client_resize_object_create(E_Client *ec)
1389 {
1390    EINA_SAFETY_ON_NULL_RETURN_VAL(ec->frame, NULL);
1391
1392    Evas_Object *resize_obj = NULL;
1393
1394    if (_e_client_resize_object_create_cb)
1395      resize_obj = _e_client_resize_object_create_cb(ec);
1396    else
1397      {
1398         if (e_config->resize_object.type == 1) // image object
1399           {
1400              resize_obj = _e_client_resize_object_image_get(ec);
1401           }
1402         else // rectangle
1403           {
1404              resize_obj = _e_client_resize_object_rectangle_get(ec);
1405           }
1406      }
1407    EINA_SAFETY_ON_NULL_RETURN_VAL(resize_obj, NULL);
1408
1409    evas_object_pass_events_set(resize_obj, EINA_TRUE);
1410    evas_object_layer_set(resize_obj, evas_object_layer_get(ec->frame));
1411    evas_object_stack_above(resize_obj, ec->frame);
1412    evas_object_name_set(resize_obj, "resize_object");
1413
1414    return resize_obj;
1415 }
1416
1417 static void
1418 _e_client_resize_object_del(E_Client *ec)
1419 {
1420    if (ec == NULL) return;
1421    if (ec->manage_resize.resize_obj == NULL) return;
1422
1423    evas_object_hide(ec->manage_resize.resize_obj);
1424    evas_object_del(ec->manage_resize.resize_obj);
1425    ec->manage_resize.resize_obj = NULL;
1426 }
1427
1428 static void
1429 _e_client_resize_handle(E_Client *ec)
1430 {
1431    int x, y, w, h;
1432    int new_x, new_y, new_w, new_h;
1433    int tw, th;
1434    int trans_x = 0, trans_y = 0;
1435    int trans_w = 0, trans_h = 0;
1436
1437    if (ec->transformed)
1438      {
1439         _e_client_transform_resize_handle(ec);
1440         return;
1441      }
1442
1443    x = ec->x;
1444    y = ec->y;
1445    w = ec->w;
1446    h = ec->h;
1447
1448    if ((ec->resize_mode == E_POINTER_RESIZE_TR) ||
1449        (ec->resize_mode == E_POINTER_RESIZE_R) ||
1450        (ec->resize_mode == E_POINTER_RESIZE_BR))
1451      {
1452         if ((ec->moveinfo.down.button >= 1) &&
1453             (ec->moveinfo.down.button <= 3))
1454           w = ec->mouse.last_down[ec->moveinfo.down.button - 1].w +
1455             (ec->mouse.current.mx - ec->moveinfo.down.mx);
1456         else
1457           w = ec->moveinfo.down.w + (ec->mouse.current.mx - ec->moveinfo.down.mx);
1458      }
1459    else if ((ec->resize_mode == E_POINTER_RESIZE_TL) ||
1460             (ec->resize_mode == E_POINTER_RESIZE_L) ||
1461             (ec->resize_mode == E_POINTER_RESIZE_BL))
1462      {
1463         if ((ec->moveinfo.down.button >= 1) &&
1464             (ec->moveinfo.down.button <= 3))
1465           w = ec->mouse.last_down[ec->moveinfo.down.button - 1].w -
1466             (ec->mouse.current.mx - ec->moveinfo.down.mx);
1467         else
1468           w = ec->moveinfo.down.w - (ec->mouse.current.mx - ec->moveinfo.down.mx);
1469      }
1470
1471    if ((ec->resize_mode == E_POINTER_RESIZE_TL) ||
1472        (ec->resize_mode == E_POINTER_RESIZE_T) ||
1473        (ec->resize_mode == E_POINTER_RESIZE_TR))
1474      {
1475         if ((ec->moveinfo.down.button >= 1) &&
1476             (ec->moveinfo.down.button <= 3))
1477           h = ec->mouse.last_down[ec->moveinfo.down.button - 1].h -
1478             (ec->mouse.current.my - ec->moveinfo.down.my);
1479         else
1480           h = ec->moveinfo.down.h - (ec->mouse.current.my - ec->moveinfo.down.my);
1481      }
1482    else if ((ec->resize_mode == E_POINTER_RESIZE_BL) ||
1483             (ec->resize_mode == E_POINTER_RESIZE_B) ||
1484             (ec->resize_mode == E_POINTER_RESIZE_BR))
1485      {
1486         if ((ec->moveinfo.down.button >= 1) &&
1487             (ec->moveinfo.down.button <= 3))
1488           h = ec->mouse.last_down[ec->moveinfo.down.button - 1].h +
1489             (ec->mouse.current.my - ec->moveinfo.down.my);
1490         else
1491           h = ec->moveinfo.down.h + (ec->mouse.current.my - ec->moveinfo.down.my);
1492      }
1493    tw = ec->w;
1494    th = ec->h;
1495
1496    if ((ec->resize_mode == E_POINTER_RESIZE_T) ||
1497        (ec->resize_mode == E_POINTER_RESIZE_TL) ||
1498        (ec->resize_mode == E_POINTER_RESIZE_L) ||
1499        (ec->resize_mode == E_POINTER_RESIZE_BL))
1500      x += (tw - w);
1501    if ((ec->resize_mode == E_POINTER_RESIZE_L) ||
1502        (ec->resize_mode == E_POINTER_RESIZE_TL) ||
1503        (ec->resize_mode == E_POINTER_RESIZE_T) ||
1504        (ec->resize_mode == E_POINTER_RESIZE_TR))
1505      y += (th - h);
1506
1507    new_x = x;
1508    new_y = y;
1509    new_w = w;
1510    new_h = h;
1511    if (e_config->screen_limits == E_CLIENT_OFFSCREEN_LIMIT_ALLOW_NONE)
1512      {
1513         E_Zone *zone;
1514         zone = e_comp_zone_find_by_ec(ec);
1515         if (zone)
1516           {
1517              w = MIN(w, zone->w);
1518              h = MIN(h, zone->h);
1519           }
1520      }
1521    e_client_resize_limit(ec, &new_w, &new_h);
1522
1523    if (ec->manage_resize.enable_aspect_ratio)
1524      {
1525         if ((ec->resize_mode == E_POINTER_RESIZE_TL) ||
1526             (ec->resize_mode == E_POINTER_RESIZE_L) ||
1527             (ec->resize_mode == E_POINTER_RESIZE_BL) ||
1528             (ec->resize_mode == E_POINTER_RESIZE_TR) ||
1529             (ec->resize_mode == E_POINTER_RESIZE_R) ||
1530             (ec->resize_mode == E_POINTER_RESIZE_BR))
1531           {
1532              new_h = (int) ec->manage_resize.ah / ec->manage_resize.aw * new_w;
1533           }
1534         else if ((ec->resize_mode == E_POINTER_RESIZE_T) ||
1535                  (ec->resize_mode == E_POINTER_RESIZE_B))
1536           {
1537              new_w = (int) ec->manage_resize.aw / ec->manage_resize.ah * new_h;
1538           }
1539           new_h += ec->manage_resize.header_h;
1540           new_h += ec->manage_resize.footer_h;
1541      }
1542
1543    if ((ec->resize_mode == E_POINTER_RESIZE_T) ||
1544        (ec->resize_mode == E_POINTER_RESIZE_TL) ||
1545        (ec->resize_mode == E_POINTER_RESIZE_L) ||
1546        (ec->resize_mode == E_POINTER_RESIZE_BL))
1547      new_x += (w - new_w);
1548    if ((ec->resize_mode == E_POINTER_RESIZE_L) ||
1549        (ec->resize_mode == E_POINTER_RESIZE_TL) ||
1550        (ec->resize_mode == E_POINTER_RESIZE_T) ||
1551        (ec->resize_mode == E_POINTER_RESIZE_TR))
1552      new_y += (h - new_h);
1553
1554    if (e_config->interactive_resize)
1555      {
1556         evas_object_geometry_set(ec->frame, new_x, new_y, new_w, new_h);
1557      }
1558    else
1559      {
1560         if (ec->manage_resize.resize_obj == NULL)
1561           {
1562              ec->manage_resize.resize_obj = _e_client_resize_object_create(ec);
1563              EINA_SAFETY_ON_NULL_RETURN(ec->manage_resize.resize_obj);
1564           }
1565
1566         if (e_client_transform_core_enable_get(ec))
1567           {
1568              e_client_transform_core_input_inv_transform(ec, new_x, new_y, &trans_x, &trans_y);
1569              e_client_transform_core_input_inv_transform(ec, new_w, new_h, &trans_w, &trans_h);
1570              evas_object_geometry_set(ec->manage_resize.resize_obj, trans_x, trans_y, trans_w, trans_h);
1571           }
1572         else
1573           evas_object_geometry_set(ec->manage_resize.resize_obj, new_x, new_y, new_w, new_h);
1574         evas_object_show(ec->manage_resize.resize_obj);
1575
1576         ec->manage_resize.x = new_x;
1577         ec->manage_resize.y = new_y;
1578         ec->manage_resize.w = new_w;
1579         ec->manage_resize.h = new_h;
1580      }
1581 }
1582
1583 static int
1584 _e_client_adjust_size_by_ppu(int size, int start_size, unsigned int ppu)
1585 {
1586    if (ppu <= 1) return size;
1587
1588    unsigned int remainder = size % ppu;
1589    if (remainder == 0) return size;
1590
1591    int gap = size - start_size;
1592    int new_size = size;
1593    if (gap > 0)
1594      new_size = size + (ppu - remainder);
1595    else
1596      new_size = size - remainder;
1597
1598    return new_size;
1599 }
1600
1601 static int
1602 _e_client_adjust_position_by_ppu(int pos, int size, int prev_pos, int prev_size)
1603 {
1604    int new_pos = 0;
1605
1606    if (prev_pos == pos)
1607      new_pos = pos;
1608    else
1609      new_pos = (prev_pos + prev_size) - size;
1610
1611    return new_pos;
1612 }
1613
1614 static void
1615 _e_client_adjust_geometry_by_resize_ppu(E_Client *ec)
1616 {
1617    if (ec->manage_resize.unit_size <= 1) return;
1618
1619    ec->manage_resize.w = _e_client_adjust_size_by_ppu(ec->manage_resize.w, ec->w, ec->manage_resize.unit_size);
1620    ec->manage_resize.h = _e_client_adjust_size_by_ppu(ec->manage_resize.h, ec->h, ec->manage_resize.unit_size);
1621
1622    ec->manage_resize.x = _e_client_adjust_position_by_ppu(ec->manage_resize.x, ec->manage_resize.w, ec->x, ec->w);
1623    ec->manage_resize.y = _e_client_adjust_position_by_ppu(ec->manage_resize.y, ec->manage_resize.h, ec->y, ec->h);
1624 }
1625
1626 static int
1627 _e_client_resize_end(E_Client *ec)
1628 {
1629    ec->resize_mode = E_POINTER_RESIZE_NONE;
1630    _e_client_action_input_win_del();
1631
1632    wl_signal_emit_mutable(&PRI(ec)->events.move_resize_end, NULL);
1633    _e_client_hook_call(E_CLIENT_HOOK_RESIZE_END, ec);
1634
1635    if (ec->transformed)
1636      _e_client_transform_resize_end(ec);
1637
1638    if (e_comp->hwc)
1639      e_comp_client_override_del(ec);
1640
1641    ecresize = NULL;
1642
1643    if (!e_config->interactive_resize)
1644      {
1645         if (ec->manage_resize.resize_obj)
1646           {
1647              if (ec->manage_resize.unit_size > 1)
1648                _e_client_adjust_geometry_by_resize_ppu(ec);
1649
1650              e_client_frame_geometry_set(ec,
1651                                          ec->manage_resize.x,
1652                                          ec->manage_resize.y,
1653                                          ec->manage_resize.w,
1654                                          ec->manage_resize.h);
1655              _e_client_resize_object_del(ec);
1656           }
1657      }
1658
1659    return 1;
1660 }
1661
1662 static Eina_Bool
1663 _e_client_action_resize_timeout(void *data EINA_UNUSED)
1664 {
1665    _e_client_resize_end(action_client);
1666    _e_client_action_finish();
1667    return ECORE_CALLBACK_CANCEL;
1668 }
1669
1670 static void
1671 _e_client_action_resize_timeout_add(void)
1672 {
1673    E_FREE_FUNC(action_timer, ecore_timer_del);
1674    if (e_config->border_keyboard.timeout)
1675      action_timer = ecore_timer_add(e_config->border_keyboard.timeout, _e_client_action_resize_timeout, NULL);
1676 }
1677
1678 static Eina_Bool
1679 _e_client_resize_mouse_down(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
1680 {
1681    if (!comp_grabbed) return ECORE_CALLBACK_RENEW;
1682
1683    if (!action_client)
1684      ERR("no action_client!");
1685
1686    if (action_client) _e_client_resize_end(action_client);
1687    _e_client_action_finish();
1688    return ECORE_CALLBACK_DONE;
1689 }
1690
1691 ////////////////////////////////////////////////
1692
1693 static Eina_Bool
1694 _e_client_position_inside_input_rect(E_Client *ec, int tx, int ty)
1695 {
1696    int x, y, w, h;
1697    Eina_Bool res = EINA_FALSE;
1698    Eina_List *list = NULL, *l;
1699    Eina_Rectangle *data;
1700
1701    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
1702
1703    e_client_geometry_get(ec, &x, &y, &w, &h);
1704    e_comp_object_input_rect_get(ec->frame, &list);
1705    if (list)
1706      {
1707         EINA_LIST_FOREACH(list, l, data)
1708           {
1709              if ((tx >= x + data->x) && (tx <= x + data->x + data->w) &&
1710                  (ty >= y + data->y) && (ty <= y + data->y + data->h))
1711                {
1712                   res = EINA_TRUE;
1713                   break;
1714                }
1715           }
1716         list = eina_list_free(list);
1717      }
1718    else
1719      {
1720         if ((tx >= x) && (tx <= x + w) &&
1721             (ty >= y) && (ty <= y + h))
1722           {
1723              res = EINA_TRUE;
1724           }
1725      }
1726
1727    return res;
1728 }
1729
1730 static Eina_Bool
1731 _e_client_under_pointer_helper_ignore_client(E_Desk *desk, E_Client *client)
1732 {
1733    /* If a border was specified which should be excluded from the list
1734     * (because it will be closed shortly for example), skip */
1735    if (e_client_util_ignored_get(client) || (!e_desk_has_ec(desk, client))) return EINA_TRUE;
1736    if (!evas_object_visible_get(client->frame)) return EINA_TRUE;
1737    if (e_policy_client_is_cursor(client)) return EINA_TRUE;
1738
1739    return EINA_FALSE;
1740 }
1741
1742 static E_Client *
1743 _e_client_under_pointer_helper(E_Desk *desk, E_Client *exclude, int x, int y)
1744 {
1745    E_Client *ec = NULL, *cec;
1746
1747    E_CLIENT_REVERSE_FOREACH(cec)
1748      {
1749         if (_e_client_under_pointer_helper_ignore_client(desk, cec)) continue;
1750         if ((exclude) && (cec == exclude)) continue;
1751         if (!E_INSIDE(x, y, cec->x, cec->y, cec->w, cec->h))
1752           continue;
1753         /* If the layer is higher, the position of the window is higher
1754          * (always on top vs always below) */
1755         if (!ec || (cec->layer > ec->layer))
1756           ec = cec;
1757      }
1758    return ec;
1759 }
1760
1761 static E_Client *
1762 _e_client_input_rect_under_pointer_helper(E_Desk *desk, E_Client *exclude, int x, int y)
1763 {
1764    E_Client *ec = NULL, *cec;
1765    int cx, cy, cw, ch;
1766
1767    E_CLIENT_REVERSE_FOREACH(cec)
1768      {
1769         /* If a border was specified which should be excluded from the list
1770          * (because it will be closed shortly for example), skip */
1771         if (e_client_util_ignored_get(cec) || (!e_desk_has_ec(desk, cec))) continue;
1772         if (!evas_object_visible_get(cec->frame)) continue;
1773         if (e_policy_client_is_cursor(cec)) continue;
1774         if ((exclude) && (cec == exclude)) continue;
1775         e_client_geometry_get(cec, &cx, &cy, &cw, &ch);
1776         if (!E_INSIDE(x, y, cx, cy, cw, ch))
1777           continue;
1778         /* If the layer is higher, the position of the window is higher
1779          * (always on top vs always below) */
1780         if (ec && (cec->layer <= ec->layer)) continue;
1781         if (_e_client_position_inside_input_rect(cec, x, y))
1782           ec = cec;
1783      }
1784
1785    return ec;
1786 }
1787
1788 static E_Client *
1789 _e_client_under_pointer_input_helper(E_Desk *desk, int x, int y)
1790 {
1791    E_Client *ec = NULL, *cec;
1792
1793    E_CLIENT_REVERSE_FOREACH(cec)
1794      {
1795         if (_e_client_under_pointer_helper_ignore_client(desk, cec)) continue;
1796
1797         Eina_List *list = NULL;
1798         Eina_Rectangle *rect;
1799         Eina_Bool inside = EINA_FALSE;
1800         e_comp_object_input_rect_get(cec->frame, &list);
1801         if (list)
1802           {
1803              EINA_LIST_FREE(list, rect)
1804                {
1805                   if (E_INSIDE(x, y, rect->x, rect->y, rect->w, rect->h))
1806                     inside = EINA_TRUE;
1807                }
1808           }
1809         else if (E_INSIDE(x, y, cec->x, cec->y, cec->w, cec->h))
1810           {
1811              inside = EINA_TRUE;
1812           }
1813
1814         if (!inside) continue;
1815         /* If the layer is higher, the position of the window is higher
1816          * (always on top vs always below) */
1817         if (!ec || (cec->layer > ec->layer))
1818           ec = cec;
1819      }
1820
1821    return ec;
1822 }
1823
1824 ////////////////////////////////////////////////
1825
1826 static void
1827 _e_client_zones_layout_calc(E_Client *ec, int *zx, int *zy, int *zw, int *zh)
1828 {
1829    int x, y, w, h;
1830    E_Zone *zone_above, *zone_below, *zone_left, *zone_right;
1831    E_Zone *zone;
1832
1833    zone = e_comp_zone_find_by_ec(ec);
1834    if (!zone) return;
1835    x = zone->x;
1836    y = zone->y;
1837    w = zone->w;
1838    h = zone->h;
1839
1840    if (eina_list_count(e_comp->zones) == 1)
1841      {
1842         if (zx) *zx = x;
1843         if (zy) *zy = y;
1844         if (zw) *zw = w;
1845         if (zh) *zh = h;
1846         return;
1847      }
1848
1849    zone_left = e_comp_zone_xy_get((x - w + 5), y);
1850    zone_right = e_comp_zone_xy_get((x + w + 5), y);
1851    zone_above = e_comp_zone_xy_get(x, (y - h + 5));
1852    zone_below = e_comp_zone_xy_get(x, (y + h + 5));
1853
1854    if (!(zone_above) && (y))
1855      zone_above = e_comp_zone_xy_get(x, (h - 5));
1856
1857    if (!(zone_left) && (x))
1858      zone_left = e_comp_zone_xy_get((x - 5), y);
1859
1860    if (zone_right)
1861      w = zone_right->x + zone_right->w;
1862
1863    if (zone_left)
1864      w = zone->x + zone->w;
1865
1866    if (zone_below)
1867      h = zone_below->y + zone_below->h;
1868
1869    if (zone_above)
1870      h = zone->y + zone->h;
1871
1872    if ((zone_left) && (zone_right))
1873      w = zone->w + zone_right->x;
1874
1875    if ((zone_above) && (zone_below))
1876      h = zone->h + zone_below->y;
1877
1878    if (x) x -= zone->w;
1879    if (y) y -= zone->h;
1880
1881    if (zx) *zx = x > 0 ? x : 0;
1882    if (zy) *zy = y > 0 ? y : 0;
1883    if (zw) *zw = w;
1884    if (zh) *zh = h;
1885 }
1886
1887 static void
1888 _e_client_stay_within_canvas(E_Client *ec, int x, int y, int *new_x, int *new_y)
1889 {
1890    int new_x_max, new_y_max;
1891    int zw, zh;
1892    Eina_Bool lw, lh;
1893    E_Zone *zone;
1894
1895    zone = e_comp_zone_find_by_ec(ec);
1896    if (!zone)
1897      {
1898         if (new_x) *new_x = x;
1899         if (new_y) *new_y = y;
1900         return;
1901      }
1902
1903    _e_client_zones_layout_calc(ec, NULL, NULL, &zw, &zh);
1904
1905    new_x_max = zw - ec->w;
1906    new_y_max = zh - ec->h;
1907    lw = ec->w > zw ? EINA_TRUE : EINA_FALSE;
1908    lh = ec->h > zh ? EINA_TRUE : EINA_FALSE;
1909
1910    if (lw)
1911      {
1912         if (x <= new_x_max)
1913           *new_x = new_x_max;
1914         else if (x >= 0)
1915           *new_x = 0;
1916      }
1917    else
1918      {
1919         if (x >= new_x_max)
1920           *new_x = new_x_max;
1921         else if (x <= 0)
1922           *new_x = 0;
1923      }
1924
1925    if (lh)
1926      {
1927         if (y <= new_y_max)
1928           *new_y = new_y_max;
1929         else if (y >= 0)
1930           *new_y = 0;
1931      }
1932    else
1933      {
1934         if (y >= new_y_max)
1935           *new_y = new_y_max;
1936         else if (y <= 0)
1937           *new_y = 0;
1938      }
1939 }
1940
1941 static void
1942 _e_client_stay_within_canvas_margin(E_Client *ec, int x, int y, int *new_x, int *new_y)
1943 {
1944    int new_x_max, new_y_max, new_x_min, new_y_min;
1945    int margin_w, margin_h;
1946    int zw, zh;
1947    int cw, ch;
1948    E_Zone *zone;
1949
1950    zone = e_comp_zone_find_by_ec(ec);
1951    if (!zone)
1952      {
1953         if (new_x) *new_x = x;
1954         if (new_y) *new_y = y;
1955         return;
1956      }
1957
1958    cw = ec->w;
1959    ch = ec->h;
1960
1961    _e_client_zones_layout_calc(ec, NULL, NULL, &zw, &zh);
1962
1963    margin_w = zw/3;
1964    margin_h = zh/10;
1965
1966    new_x_min = (margin_w > cw) ? 0 : -(cw - margin_w);
1967    new_x_max = (margin_w > cw) ? (zw - cw) : (zw - margin_w);
1968    new_y_min = (margin_h > ch) ? 0 : -(ch - margin_h);
1969    new_y_max = (margin_h > ch) ? (zh - ch) : (zh - margin_h);
1970
1971    if (x >= new_x_max)
1972      *new_x = new_x_max;
1973    else if (x <= new_x_min)
1974      *new_x = new_x_min;
1975
1976    if (y >= new_y_max)
1977      *new_y = new_y_max;
1978    else if (y <= new_y_min)
1979      *new_y = new_y_min;
1980
1981 }
1982
1983 ////////////////////////////////////////////////
1984
1985 static void
1986 _e_client_transform_core_activate_set(E_Client *ec, Eina_Bool set)
1987 {
1988    if (ec->transform_core.activate == set) return;
1989
1990    ec->transform_core.activate = set;
1991
1992    if (set)
1993      {
1994         if (ec->transform_core.result.enable)
1995           e_client_map_enable_set(ec, EINA_TRUE);
1996      }
1997    else
1998      {
1999         e_client_map_enable_set(ec, EINA_FALSE);
2000      }
2001 }
2002
2003 static void
2004 _e_client_cb_evas_hide(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
2005 {
2006    E_Client *ec = data;
2007
2008    if (stopping) return; //ignore all of this if we're shutting down!
2009    if (e_object_is_del(data)) return; //client is about to die
2010    if (ec->cur_mouse_action)
2011      {
2012         if (ec->cur_mouse_action->func.end_mouse)
2013           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", NULL);
2014         else if (ec->cur_mouse_action->func.end)
2015           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
2016         E_FREE_FUNC(ec->cur_mouse_action, e_object_unref);
2017      }
2018    if (action_client == ec) _e_client_action_finish();
2019
2020    ec->want_focus = ec->take_focus = 0;
2021
2022    _e_client_transform_core_activate_set(ec, EINA_FALSE);
2023
2024    if (ec->new_client) return;
2025    _e_client_event_hide(ec);
2026
2027    EC_CHANGED(ec);
2028 }
2029
2030 static void
2031 _e_client_cb_evas_shade_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
2032 {
2033    E_Client *ec = data;
2034
2035    if (e_object_is_del(data)) return;
2036
2037    ec->shading = 0;
2038    ec->shaded = !(ec->shaded);
2039    ec->changes.shaded = 1;
2040    ec->changes.shading = 1;
2041    e_client_comp_hidden_set(ec, ec->shaded);
2042 }
2043
2044 static void
2045 _e_client_cb_evas_move(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
2046 {
2047    E_Client *ec = data;
2048    E_Map *map;
2049    Evas_Coord x, y;
2050
2051    if (e_object_is_del(data)) return;
2052
2053    ec->pre_res_change.valid = 0;
2054
2055    _e_client_event_simple(ec, E_EVENT_CLIENT_MOVE);
2056
2057    evas_object_geometry_get(ec->frame, &x, &y, NULL, NULL);
2058    if ((e_config->transient.move) && (ec->transients))
2059      {
2060         Eina_List *list = eina_list_clone(ec->transients);
2061         E_Client *child;
2062
2063         EINA_LIST_FREE(list, child)
2064           {
2065              if (child->vkbd.vkbd) continue;
2066
2067              evas_object_move(child->frame,
2068                               child->x + x - ec->pre_cb.x,
2069                               child->y + y - ec->pre_cb.y);
2070           }
2071      }
2072    if (ec->moving || (ecmove == ec))
2073      {
2074         wl_signal_emit_mutable(&PRI(ec)->events.move_resize_update, NULL);
2075         _e_client_hook_call(E_CLIENT_HOOK_MOVE_UPDATE, ec);
2076      }
2077
2078    if ((!ec->moving) && (ec->transformed))
2079      {
2080         map = e_client_map_get(ec);
2081         _e_client_transform_geometry_save(ec, map);
2082         e_map_free(map);
2083      }
2084
2085    ec->pre_cb.x = x; ec->pre_cb.y = y;
2086
2087    wl_signal_emit_mutable(&PRI(ec)->events.move, NULL);
2088
2089    e_comp_visibility_calculation_set(EINA_TRUE);
2090 }
2091
2092 static void
2093 _e_client_cb_evas_resize(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
2094 {
2095    E_Client *ec = data;
2096    Evas_Coord x, y, w, h;
2097
2098    if (e_object_is_del(data)) return;
2099
2100    ec->pre_res_change.valid = 0;
2101
2102    _e_client_event_simple(ec, E_EVENT_CLIENT_RESIZE);
2103
2104    evas_object_geometry_get(ec->frame, &x, &y, &w, &h);
2105    if ((e_config->transient.resize) && (ec->transients))
2106      {
2107         Eina_List *list = eina_list_clone(ec->transients);
2108         E_Client *child;
2109
2110         EINA_LIST_FREE(list, child)
2111           {
2112              Evas_Coord nx, ny, nw, nh;
2113
2114              if ((ec->pre_cb.w > 0) && (ec->pre_cb.h > 0))
2115                {
2116                   nx = x + (((child->x - x) * w) / ec->pre_cb.w);
2117                   ny = y + (((child->y - y) * h) / ec->pre_cb.h);
2118                   nw = (child->w * w) / ec->pre_cb.w;
2119                   nh = (child->h * h) / ec->pre_cb.h;
2120                   nx += ((nw - child->w) / 2);
2121                   ny += ((nh - child->h) / 2);
2122                   evas_object_move(child->frame, nx, ny);
2123                }
2124           }
2125      }
2126
2127    if (e_client_util_resizing_get(ec) || (ecresize == ec))
2128      {
2129          wl_signal_emit_mutable(&PRI(ec)->events.move_resize_update, NULL);
2130         _e_client_hook_call(E_CLIENT_HOOK_RESIZE_UPDATE, ec);
2131      }
2132    ec->pre_cb.w = w; ec->pre_cb.h = h;
2133
2134    e_client_transform_core_update(ec);
2135    e_comp_visibility_calculation_set(EINA_TRUE);
2136 }
2137
2138 static void
2139 _e_client_cb_evas_show(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
2140 {
2141    E_Client *ec = data;
2142
2143    if (e_object_is_del(data)) return;
2144
2145    _e_client_transform_core_activate_set(ec, EINA_TRUE);
2146
2147    _e_client_event_show(ec);
2148    EC_CHANGED(ec);
2149 }
2150
2151 static void
2152 _e_client_cb_evas_restack(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
2153 {
2154    E_Client *ec = data;
2155    E_Comp_Wl_Client_Data *child_cdata = NULL;
2156
2157    if (e_object_is_del(data)) return;
2158    if (ec->layer_block) return;
2159    if (ec->layer_pending) return;
2160    if (e_config->transient.raise && ec->transients)
2161      {
2162         Eina_List *list = eina_list_clone(ec->transients);
2163         E_Client *child, *below = NULL, *above = NULL;
2164         E_Transient transient_policy;
2165
2166         E_LIST_REVERSE_FREE(list, child)
2167           {
2168              child_cdata = e_client_cdata_get(child);
2169              if (child_cdata && !child_cdata->mapped)
2170                {
2171                   ELOGF("COMP", "STACK CHANGE CHILD. BUT not mapped. skip. child(ec:%p, win:0x%08zx)", ec, child, e_client_util_win_get(child));
2172                   continue;
2173                }
2174
2175              /* Don't stack iconic transients. If the user wants these shown,
2176               * that's another option.
2177               */
2178              if (child->iconic && e_client_is_iconified_by_client(child)) continue;
2179
2180              transient_policy = e_client_transient_policy_get(child);
2181              if (transient_policy == E_TRANSIENT_ABOVE)
2182                {
2183                   if (below)
2184                     e_client_stack_below(child, below);
2185                   else
2186                     e_client_stack_above(child, ec);
2187                   below = child;
2188                }
2189              else if (transient_policy == E_TRANSIENT_BELOW)
2190                {
2191                   if (above)
2192                     e_client_stack_below(child, above);
2193                   else
2194                     e_client_stack_below(child, ec);
2195                   above = child;
2196                }
2197
2198           }
2199      }
2200    if (ec->unredirected_single) return;
2201    _e_client_event_simple(ec, E_EVENT_CLIENT_STACK);
2202
2203    e_comp_visibility_calculation_set(EINA_TRUE);
2204 }
2205
2206 ////////////////////////////////////////////////
2207 static void
2208 _e_client_aux_hint_eval(E_Client *ec)
2209 {
2210    if (!ec) return;
2211
2212    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
2213    Eina_List *l, *ll;
2214    E_Comp_Wl_Aux_Hint *hint;
2215
2216    if (cdata && cdata->aux_hint.changed)
2217      {
2218         wl_signal_emit_mutable(&PRI(ec)->events.aux_hint_change, NULL);
2219         _e_client_hook_call(E_CLIENT_HOOK_AUX_HINT_CHANGE, ec);
2220
2221         EINA_LIST_FOREACH_SAFE(cdata->aux_hint.hints, l, ll, hint)
2222           {
2223              hint->changed = EINA_FALSE;
2224              if (hint->deleted)
2225                {
2226                   ELOGF("COMP", "AUX_HINT |Del [%d:%s:%s]", ec, hint->id, hint->hint, hint->val);
2227                   if (hint->hint) eina_stringshare_del(hint->hint);
2228                   if (hint->val) eina_stringshare_del(hint->val);
2229                   cdata->aux_hint.hints = eina_list_remove_list(cdata->aux_hint.hints, l);
2230                   E_FREE(hint);
2231                }
2232           }
2233         cdata->aux_hint.changed = 0;
2234      }
2235 }
2236
2237 static void
2238 _e_client_eval(E_Client *ec)
2239 {
2240    int send_event = 1;
2241    unsigned int prop = 0;
2242    int tx, ty;
2243
2244    if (e_object_is_del(E_OBJECT(ec)))
2245      {
2246         CRI("_e_client_eval(%p) with deleted border! - %d\n", ec, ec->new_client);
2247         ec->changed = 0;
2248         return;
2249      }
2250
2251    TRACE_DS_BEGIN(CLIENT:EVAL);
2252
2253    wl_signal_emit_mutable(&PRI(ec)->events.eval_pre_new_client, NULL);
2254    if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_PRE_NEW_CLIENT, ec))
2255      {
2256         TRACE_DS_END();
2257         return;
2258      }
2259
2260    if ((ec->new_client) && (!e_client_util_ignored_get(ec)))
2261      {
2262         wl_signal_emit_mutable(&PRI(ec)->events.eval_post_new_client, NULL);
2263         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_POST_NEW_CLIENT, ec))
2264           {
2265              TRACE_DS_END();
2266              return;
2267           }
2268      }
2269
2270    /* effect changes to the window border itself */
2271    if ((ec->changes.shading))
2272      {
2273         /*  show at start of unshade (but don't hide until end of shade) */
2274         ec->changes.shading = 0;
2275         send_event = 0;
2276      }
2277    if (ec->changes.shaded) send_event = 0;
2278    if ((ec->changes.shaded) && (ec->changes.pos) && (ec->changes.size))
2279      {
2280         ec->changes.shaded = 0;
2281      }
2282    else if ((ec->changes.shaded) && (ec->changes.pos))
2283      {
2284         ec->changes.size = 1;
2285         ec->changes.shaded = 0;
2286      }
2287    else if ((ec->changes.shaded) && (ec->changes.size))
2288      {
2289         ec->changes.shaded = 0;
2290      }
2291    else if (ec->changes.shaded)
2292      {
2293         ec->changes.shaded = 0;
2294      }
2295
2296    if (ec->changes.size)
2297      {
2298         ec->changes.size = 0;
2299         if ((!ec->shaded) && (!ec->shading))
2300           evas_object_resize(ec->frame, ec->w, ec->h);
2301
2302         prop |= E_CLIENT_PROPERTY_SIZE;
2303      }
2304    if (ec->changes.pos)
2305      {
2306         ec->changes.tz_position = 0;
2307         ec->changes.pos = 0;
2308         evas_object_move(ec->frame, ec->x, ec->y);
2309         prop |= E_CLIENT_PROPERTY_POS;
2310      }
2311
2312    if (ec->changes.reset_gravity)
2313      {
2314         ec->changes.reset_gravity = 0;
2315         prop |= E_CLIENT_PROPERTY_GRAVITY;
2316      }
2317
2318    if (ec->changes.title)
2319      {
2320         ec->changes.title = 0;
2321         prop |= E_CLIENT_PROPERTY_TITLE;
2322      }
2323
2324    if ((ec->changes.visible) && (ec->visible) && (ec->new_client) && (!ec->iconic))
2325      {
2326         int x, y;
2327
2328         e_input_device_pointer_xy_get(NULL, &x, &y);
2329         if ((!ec->placed) && (!ec->re_manage) &&
2330             (e_config->window_placement_policy == E_WINDOW_PLACEMENT_MANUAL) &&
2331             (!((ec->icccm.transient_for != 0) ||
2332                (ec->dialog))) &&
2333             (!ecmove) && (!ecresize))
2334           {
2335              /* Set this window into moving state */
2336
2337              ec->cur_mouse_action = e_action_find("window_move");
2338              if (ec->cur_mouse_action)
2339                {
2340                   if ((!ec->cur_mouse_action->func.end_mouse) &&
2341                       (!ec->cur_mouse_action->func.end))
2342                     ec->cur_mouse_action = NULL;
2343                   if (ec->cur_mouse_action)
2344                     {
2345                        int t;
2346                        tx = x - (ec->w >> 1);
2347                        e_comp_object_frame_geometry_get(ec->frame, NULL, NULL, &t, NULL);
2348                        ty = y - (t >> 1);
2349                        e_client_pos_set(ec, tx, ty);
2350                        EC_CHANGED(ec);
2351                        ec->changes.pos = 1;
2352                     }
2353                }
2354           }
2355
2356         evas_object_show(ec->frame);
2357         if (evas_object_visible_get(ec->frame))
2358           {
2359              ec->changes.visible = 0;
2360              _e_client_event_show(ec);
2361           }
2362      }
2363    else if ((ec->changes.visible) && (ec->new_client))
2364      {
2365         ec->changes.visible = 0;
2366         if (!ec->iconic)
2367           _e_client_event_hide(ec);
2368      }
2369
2370    if (ec->changes.icon)
2371      {
2372         ec->changes.icon = 0;
2373      }
2374
2375    if (ec->new_client)
2376      e_comp->new_clients--;
2377    ec->new_client = 0;
2378    ec->changed = ec->changes.pos || ec->changes.size ||
2379                  ec->changes.stack || ec->changes.prop || ec->changes.border ||
2380                  ec->changes.reset_gravity || ec->changes.shading || ec->changes.shaded ||
2381                  ec->changes.shape || ec->changes.shape_input || ec->changes.icon ||
2382                  ec->changes.internal_state ||
2383                  ec->changes.need_maximize || ec->changes.need_unmaximize;
2384    ec->changes.stack = 0;
2385
2386    if (ec->changes.need_maximize)
2387      {
2388         E_Maximize max = ec->maximized;
2389         ec->maximized = E_MAXIMIZE_NONE;
2390         e_client_maximize(ec, max);
2391         ec->changes.need_maximize = 0;
2392      }
2393    else if (ec->changes.need_unmaximize)
2394      {
2395         e_client_unmaximize(ec, ec->maximized);
2396         ec->changes.need_unmaximize = 0;
2397      }
2398
2399    if (ec->need_fullscreen)
2400      {
2401         e_client_fullscreen(ec, e_config->fullscreen_policy);
2402         ec->need_fullscreen = 0;
2403      }
2404
2405    if (ec->changes.accepts_focus)
2406      {
2407         if ((!ec->icccm.accepts_focus) && (!ec->icccm.take_focus))
2408           {
2409              if (!ec->focused)
2410                ec->changes.accepts_focus = 0;
2411           }
2412      }
2413
2414    if (send_event && prop)
2415      {
2416         _e_client_event_property(ec, prop);
2417      }
2418
2419    _e_client_aux_hint_eval(ec);
2420
2421    e_client_transform_core_update(ec);
2422
2423    wl_signal_emit_mutable(&PRI(ec)->events.eval_end, NULL);
2424    _e_client_hook_call(E_CLIENT_HOOK_EVAL_END, ec);
2425
2426    TRACE_DS_END();
2427 }
2428
2429 EINTERN void
2430 e_client_frame_update(E_Client *ec)
2431 {
2432    const char *bordername;
2433
2434    EINA_SAFETY_ON_NULL_RETURN(ec);
2435    if (e_object_is_del(E_OBJECT(ec))) return;
2436
2437    ec->border.changed = 0;
2438    if (!e_comp_object_frame_allowed(ec->frame)) return;
2439    if (ec->fullscreen || ec->borderless)
2440      bordername = "borderless";
2441    else if (ec->bordername)
2442      bordername = ec->bordername;
2443    else if (ec->mwm.borderless)
2444      bordername = "borderless";
2445    else if (((ec->icccm.transient_for != 0) || (ec->dialog)) &&
2446             (ec->icccm.min_w == ec->icccm.max_w) &&
2447             (ec->icccm.min_h == ec->icccm.max_h))
2448      bordername = "noresize_dialog";
2449    else if ((ec->icccm.min_w == ec->icccm.max_w) &&
2450             (ec->icccm.min_h == ec->icccm.max_h))
2451      bordername = "noresize";
2452    else if (ec->shaped)
2453      bordername = "shaped";
2454    else if (ec->urgent)
2455      bordername = "urgent";
2456    else if (ec->netwm.state.modal)
2457      bordername = "modal";
2458    else if ((ec->netwm.state.skip_taskbar) ||
2459             (ec->netwm.state.skip_pager))
2460      bordername = "skipped";
2461   /*
2462    else if ((ec->internal) && (ec->icccm.class) &&
2463             (!strncmp(ec->icccm.class, "e_fwin", 6)))
2464      bordername = "internal_fileman";
2465   */
2466    else
2467      bordername = e_config->theme_default_border_style;
2468    if (!bordername) bordername = "default";
2469
2470    e_client_border_set(ec, bordername);
2471 }
2472
2473 static Eina_Bool
2474 _e_client_type_match(E_Client *ec, E_Config_Client_Type *m)
2475 {
2476    if (!ec || !m) return EINA_FALSE;
2477    if (e_object_is_del(E_OBJECT(ec))) return EINA_FALSE;
2478
2479    if ((int)ec->netwm.type != m->window_type)
2480      return EINA_FALSE;
2481
2482 #if defined(__cplusplus) || defined(c_plusplus)
2483    if (m->clas)
2484      {
2485         if (!ec->icccm.cpp_class)
2486           return EINA_FALSE;
2487
2488         if (!e_util_glob_match(ec->icccm.cpp_class, m->clas))
2489           return EINA_FALSE;
2490      }
2491 #else
2492    if (m->clas)
2493      {
2494         if (!ec->icccm.class)
2495           return EINA_FALSE;
2496
2497         if (!e_util_glob_match(ec->icccm.class, m->clas))
2498           return EINA_FALSE;
2499      }
2500 #endif
2501
2502    if (m->name)
2503      {
2504         if (ec->icccm.name && e_util_glob_match(ec->icccm.name, m->name))
2505           return EINA_TRUE;
2506
2507         if (ec->icccm.title && e_util_glob_match(ec->icccm.title, m->name))
2508           return EINA_TRUE;
2509
2510         if (ec->netwm.name && e_util_glob_match(ec->netwm.name, m->name))
2511           return EINA_TRUE;
2512      }
2513
2514    return EINA_FALSE;
2515 }
2516
2517 EINTERN int
2518 e_client_type_update(E_Client *ec)
2519 {
2520    E_Config_Client_Type *m;
2521    Eina_List *l;
2522    int type = 0;
2523
2524    if (!e_config->client_types) return 0;
2525
2526    EINA_LIST_FOREACH(e_config->client_types, l, m)
2527      {
2528         if (!_e_client_type_match(ec, m)) continue;
2529         else
2530           {
2531              type = m->client_type;
2532              break;
2533           }
2534      }
2535
2536    if (ec->client_type != type)
2537      {
2538         ec->client_type = type;
2539         _e_client_event_property(ec, E_CLIENT_PROPERTY_CLIENT_TYPE);
2540      }
2541
2542    return ec->client_type;
2543 }
2544
2545 static void
2546 _e_client_transform_sub_apply(E_Client *ec, E_Client *epc, double zoom)
2547 {
2548    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
2549    E_Client *subc;
2550    Eina_List *l;
2551    int px = 0, py = 0;
2552    int ox = 0, oy = 0, ow, oh;
2553    int mx, my, mw, mh;
2554    E_Map *map;
2555
2556    EINA_SAFETY_ON_FALSE_RETURN(e_comp_wl_subsurface_check(ec));
2557
2558    e_comp_wl_subsurface_position_get(ec, &ox, &oy);
2559    ow = cdata->width_from_viewport;
2560    oh = cdata->height_from_viewport;
2561
2562    map = e_client_map_get(epc);
2563    e_map_point_coord_get(map, 0, &px, &py, 0);
2564    e_map_free(map);
2565
2566    mx = ox * zoom + px;
2567    my = oy * zoom + py;
2568    mw = ow * zoom;
2569    mh = oh * zoom;
2570
2571    map = e_map_new_with_direct_render(ec->transform_core.direct_render);
2572    e_map_util_points_populate_from_geometry(map, mx, my, mw, mh, 0);
2573    e_map_util_object_move_sync_set(map, EINA_TRUE);
2574    e_client_map_set(ec, map);
2575    e_client_map_enable_set(ec, EINA_TRUE);
2576
2577    EINA_LIST_FOREACH(cdata->sub.list, l, subc)
2578      _e_client_transform_sub_apply(subc, ec, zoom);
2579    EINA_LIST_REVERSE_FOREACH(cdata->sub.below_list, l, subc)
2580      _e_client_transform_sub_apply(subc, ec, zoom);
2581
2582    e_map_free(map);
2583 }
2584
2585 static void
2586 _e_client_transient_for_group_make(E_Client *ec, Eina_List **list)
2587 {
2588    E_Client *child;
2589    Eina_List *l;
2590
2591    if (!ec) return;
2592    if (!e_config->transient.raise) return;
2593
2594    EINA_LIST_FOREACH(ec->transients, l, child)
2595      {
2596         if (!child) continue;
2597         if (child->iconic) continue;
2598         if (e_client_transient_policy_get(child) == E_TRANSIENT_ABOVE)
2599           {
2600              *list = eina_list_prepend(*list, child);
2601              _e_client_transient_for_group_make(child, list);
2602           }
2603      }
2604 }
2605
2606 EINTERN E_Client *
2607 e_client_transient_child_top_get(E_Client *ec, Eina_Bool consider_focus)
2608 {
2609    E_Client *top_ec = NULL;
2610    Eina_List *transient_list = NULL;
2611
2612    _e_client_transient_for_group_make(ec, &transient_list);
2613
2614    if (transient_list)
2615      {
2616         Eina_List *l = NULL;
2617         E_Client *temp_ec = NULL;
2618         E_Client *temp_ec2 = NULL;
2619
2620         E_CLIENT_REVERSE_FOREACH(temp_ec)
2621           {
2622              if (top_ec) break;
2623              if (temp_ec == ec)
2624                {
2625                   top_ec = ec;
2626                   break;
2627                }
2628
2629              EINA_LIST_FOREACH(transient_list, l, temp_ec2)
2630                {
2631                   if (temp_ec == temp_ec2)
2632                     {
2633                        if (consider_focus)
2634                          {
2635                             if ((temp_ec2->icccm.accepts_focus) ||
2636                                 (temp_ec2->icccm.take_focus))
2637                               {
2638                                  top_ec = temp_ec2;
2639                               }
2640                          }
2641                        else
2642                          {
2643                             top_ec = temp_ec2;
2644                          }
2645                        break;
2646                     }
2647                }
2648           }
2649         eina_list_free(transient_list);
2650      }
2651    return top_ec;
2652 }
2653
2654 #ifdef EC_IS_NOT_VISIBLE
2655 # undef EC_IS_NOT_VISIBLE
2656 #endif
2657 #define EC_IS_NOT_VISIBLE if (ec->visibility.obscured != E_VISIBILITY_UNOBSCURED)
2658
2659 EINTERN Eina_Bool
2660 e_client_visibility_touched_check(E_Client *ec)
2661 {
2662    int tx, ty;
2663
2664    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
2665
2666    tx = wl_fixed_to_int(e_comp->wl_comp_data->ptr.x);
2667    ty = wl_fixed_to_int(e_comp->wl_comp_data->ptr.y);
2668
2669    return _e_client_position_inside_input_rect(ec, tx, ty);
2670 }
2671
2672 EINTERN void
2673 e_client_visibility_change_notify(E_Client *ec)
2674 {
2675    EINA_SAFETY_ON_NULL_RETURN(ec);
2676
2677    if (ec->visibility.changed)
2678      _e_client_event_simple(ec, E_EVENT_CLIENT_VISIBILITY_CHANGE);
2679
2680    wl_signal_emit_mutable(&PRI(ec)->events.eval_visibility, NULL);
2681    _e_client_hook_call(E_CLIENT_HOOK_EVAL_VISIBILITY, ec);
2682 }
2683
2684 EINTERN void
2685 e_client_visibility_end_notify(void)
2686 {
2687    // FIXME: This hook means that the visiblitiy calculation of a zone is done
2688    //        at this idle handler.This is a hook for a zone, not for a client.
2689    //        Therefore, this hook may be defined as a zone hook,
2690    //        ex) E_ZONE_HOOK_EVAL_VISIBILITY_END or E_ZONE_HOOK_EVAL_VISIBILITY_DONE.
2691    _e_client_hook_call(E_CLIENT_HOOK_EVAL_VISIBILITY_END, NULL);
2692 }
2693
2694 static Eina_Bool
2695 _e_client_transform_core_check_change(E_Client *ec)
2696 {
2697    int w = 0;
2698    int h = 0;
2699    Eina_Bool check = EINA_FALSE;
2700    if (!ec) return EINA_FALSE;
2701
2702    if (ec->frame)
2703      evas_object_geometry_get(ec->frame, 0, 0, &w, &h);
2704
2705    // check client position or size change
2706    if (ec->x != ec->transform_core.backup.client_x ||
2707        ec->y != ec->transform_core.backup.client_y ||
2708        ec->w != ec->transform_core.backup.client_w ||
2709        ec->h != ec->transform_core.backup.client_h ||
2710        w     != ec->transform_core.backup.frame_w ||
2711        h     != ec->transform_core.backup.frame_h ||
2712        ec->argb != ec->transform_core.backup.argb)
2713      {
2714         check = EINA_TRUE;
2715         ec->transform_core.backup.client_x = ec->x;
2716         ec->transform_core.backup.client_y = ec->y;
2717         ec->transform_core.backup.client_w = ec->w;
2718         ec->transform_core.backup.client_h = ec->h;
2719         ec->transform_core.backup.frame_w = w;
2720         ec->transform_core.backup.frame_h = h;
2721         ec->transform_core.backup.argb = ec->argb;
2722      }
2723
2724    // check new transform or del transform
2725    if (ec->transform_core.changed)
2726      {
2727         check = EINA_TRUE;
2728         ec->transform_core.changed = EINA_FALSE;
2729      }
2730
2731    // check each transform change
2732    if (ec->transform_core.transform_list)
2733      {
2734         Eina_List *l;
2735         Eina_List *l_next;
2736         E_Util_Transform *transform;
2737
2738         EINA_LIST_FOREACH_SAFE(ec->transform_core.transform_list, l, l_next, transform)
2739           {
2740              // del transform check
2741              if (e_util_transform_ref_count_get(transform) <= 1)
2742                {
2743                   ec->transform_core.transform_list = eina_list_remove(ec->transform_core.transform_list, transform);
2744                   e_util_transform_unref(transform);
2745                   check = EINA_TRUE;
2746                   continue;
2747                }
2748
2749              // transform change test
2750              if (e_util_transform_change_get(transform))
2751                {
2752                   check = EINA_TRUE;
2753                   e_util_transform_change_unset(transform);
2754                }
2755           }
2756      }
2757
2758    if (e_comp_wl_subsurface_check(ec))
2759      {
2760         // check parent matrix change
2761         E_Client *parent = e_comp_wl_subsurface_parent_get(ec);
2762         if (parent && parent->transform_core.result.enable)
2763           {
2764              ec->transform_core.parent.enable = EINA_TRUE;
2765
2766              if (!e_util_transform_matrix_equal_check(&ec->transform_core.parent.matrix,
2767                                                       &parent->transform_core.result.matrix))
2768                {
2769                   check = EINA_TRUE;
2770                   ec->transform_core.parent.matrix = parent->transform_core.result.matrix;
2771                }
2772              if (memcmp(&ec->transform_core.parent.zoom, &parent->transform_core.result.transform.zoom, sizeof(E_Util_Transform_Zoom)) != 0)
2773                {
2774                   check = EINA_TRUE;
2775                   ec->transform_core.parent.zoom = parent->transform_core.result.transform.zoom;
2776                }
2777           }
2778         else if (ec->transform_core.parent.enable)
2779           {
2780              ec->transform_core.parent.enable = EINA_FALSE;
2781              e_util_transform_matrix_load_identity(&ec->transform_core.parent.matrix);
2782              ec->transform_core.parent.zoom.zoom_x = 1.0;
2783              ec->transform_core.parent.zoom.zoom_y = 1.0;
2784              ec->transform_core.parent.zoom.cx = 0;
2785              ec->transform_core.parent.zoom.cy = 0;
2786              check = EINA_TRUE;
2787           }
2788      }
2789
2790    return check;
2791 }
2792
2793 static void
2794 _e_client_transform_core_boundary_update(E_Client *ec, E_Util_Transform_Rect_Vertex *vertices)
2795 {
2796    int minx = 99999, miny = 99999;
2797    int maxx = -99999, maxy = -99999;
2798    int x, y;
2799    int i;
2800
2801    if (!ec) return;
2802    if (!ec->frame) return;
2803    if (!ec->transform_core.result.enable) return;
2804    if (!vertices) return;
2805
2806    for (i = 0; i < 4; ++i)
2807      {
2808         x = 0;
2809         y = 0;
2810
2811         e_util_transform_vertices_pos_round_get(vertices, i, &x, &y, 0, 0);
2812
2813         if (x < minx) minx = x;
2814         if (y < miny) miny = y;
2815         if (x > maxx) maxx = x;
2816         if (y > maxy) maxy = y;
2817      }
2818
2819    ec->transform_core.result.boundary.x = minx;
2820    ec->transform_core.result.boundary.y = miny;
2821    ec->transform_core.result.boundary.w = maxx - minx;
2822    ec->transform_core.result.boundary.h = maxy - miny;
2823
2824    ELOGF("COMP", "[Transform][boundary][%d %d %d %d]",
2825          ec,
2826          ec->transform_core.result.boundary.x,
2827          ec->transform_core.result.boundary.y,
2828          ec->transform_core.result.boundary.w,
2829          ec->transform_core.result.boundary.h);
2830 }
2831
2832 static E_Map *
2833 _e_client_transform_core_map_new(Evas_Object *obj,
2834                                  E_Util_Transform_Rect_Vertex *vertices,
2835                                  E_Util_Transform *transform,
2836                                  Eina_Bool direct_render)
2837 {
2838    E_Map *map;
2839    int i;
2840    int x, y;
2841    double u, v;
2842
2843    map = e_map_new_with_direct_render(direct_render);
2844    EINA_SAFETY_ON_NULL_RETURN_VAL(map, NULL);
2845
2846    e_map_util_points_populate_from_object_full(map, obj, 0);
2847    e_map_util_points_color_set(map, 255, 255, 255, 255);
2848
2849    for (i = 0 ; i < 4 ; ++i)
2850      {
2851         x = 0;
2852         y = 0;
2853
2854         e_util_transform_vertices_pos_round_get(vertices, i, &x, &y, 0, 0);
2855         e_map_point_coord_set(map, i, x, y, 1.0);
2856
2857         if (transform && e_util_transform_texcoord_flag_get(transform))
2858           {
2859              u = 0.0;
2860              v = 0.0;
2861
2862              e_util_transform_texcoord_get(transform, i, &u, &v);
2863              e_map_point_image_uv_set(map, i, u, v);
2864           }
2865      }
2866
2867    return map;
2868 }
2869
2870 static void
2871 _e_client_transform_core_vertices_apply_with_zoom(E_Client *ec,
2872                                         Evas_Object *obj,
2873                                         E_Util_Transform_Rect_Vertex *vertices,
2874                                         E_Util_Transform *transform,
2875                                         E_Util_Transform_Zoom zoom)
2876 {
2877    E_Map *map = NULL;
2878
2879    if (!obj) return;
2880
2881    if (vertices)
2882      {
2883         map = _e_client_transform_core_map_new(obj, vertices, transform,
2884                                                ec->transform_core.direct_render);
2885         EINA_SAFETY_ON_NULL_RETURN(map);
2886
2887         e_map_util_zoom(map, zoom.zoom_x, zoom.zoom_y, zoom.cx, zoom.cy);
2888
2889         e_comp_object_map_set(obj, map);
2890
2891         if (ec->transform_core.activate)
2892           e_comp_object_map_enable_set(obj, EINA_TRUE);
2893         else
2894           e_comp_object_map_enable_set(obj, EINA_FALSE);
2895
2896         e_map_free(map);
2897      }
2898    else
2899      evas_object_map_enable_set(obj, EINA_FALSE);
2900 }
2901
2902 static void
2903 _e_client_transform_core_vertices_apply(E_Client *ec,
2904                                         Evas_Object *obj,
2905                                         E_Util_Transform_Rect_Vertex *vertices,
2906                                         E_Util_Transform *transform)
2907 {
2908    E_Map *map = NULL;
2909
2910    if (!obj) return;
2911
2912    if (vertices)
2913      {
2914         map = _e_client_transform_core_map_new(obj, vertices, transform,
2915                                                ec->transform_core.direct_render);
2916         EINA_SAFETY_ON_NULL_RETURN(map);
2917
2918         e_comp_object_map_set(obj, map);
2919
2920         if (ec->transform_core.activate)
2921           e_comp_object_map_enable_set(obj, EINA_TRUE);
2922         else
2923           e_comp_object_map_enable_set(obj, EINA_FALSE);
2924
2925         e_map_free(map);
2926      }
2927    else
2928      evas_object_map_enable_set(obj, EINA_FALSE);
2929 }
2930
2931 static void
2932 _e_client_transform_core_sub_update(E_Client *ec, E_Util_Transform_Rect_Vertex *vertices)
2933 {
2934    Eina_List *l;
2935    E_Client *subc;
2936    E_Comp_Wl_Client_Data *cdata;
2937
2938    if (!ec) return;
2939
2940    cdata = e_client_cdata_get(ec);
2941    if (!cdata) return;
2942
2943    EINA_LIST_FOREACH(cdata->sub.list, l, subc)
2944       e_client_transform_core_update(subc);
2945
2946    EINA_LIST_FOREACH(cdata->sub.below_list, l, subc)
2947       e_client_transform_core_update(subc);
2948 }
2949
2950 static void
2951 _e_client_cb_hook_shell_surface_ready(void *data EINA_UNUSED, E_Client *ec)
2952 {
2953    if (EINA_UNLIKELY(!ec))
2954      return;
2955
2956    _e_client_aux_hint_eval(ec);
2957 }
2958
2959 // FIXME: This function has to be deleted and it remains for the backward compatibility.
2960 //        Please find and fix to use e_comp_visibility_calculation_set(EINA_TRUE)
2961 //        instead of e_client_visibility_calculate() call at e20 modules.
2962 E_API void
2963 e_client_visibility_calculate(void)
2964 {
2965    e_comp_visibility_calculation_set(EINA_TRUE);
2966 }
2967
2968 E_API void
2969 e_client_visibility_skip_set(E_Client *ec, Eina_Bool skip)
2970 {
2971    if (!ec) return;
2972
2973    ELOGF("POL_VIS", "visibility skip set to %d", ec, skip);
2974    ec->visibility.skip = skip;
2975 }
2976
2977 E_API void
2978 e_client_post_raise_lower_set(E_Client *ec, Eina_Bool raise_set, Eina_Bool lower_set)
2979 {
2980    if (!ec) return;
2981
2982    ec->post_raise = raise_set;
2983    ec->post_lower = lower_set;
2984 }
2985
2986 E_API Eina_Bool
2987 e_client_first_mapped_get(E_Client *ec)
2988 {
2989    if (!ec) return EINA_FALSE;
2990
2991    return ec->first_mapped;
2992 }
2993
2994 EINTERN Eina_Bool e_client_mapped_get(E_Client *ec)
2995 {
2996    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
2997    EINA_SAFETY_ON_NULL_RETURN_VAL(cdata, EINA_FALSE);
2998
2999   return cdata->mapped;
3000 }
3001
3002 EINTERN void
3003 e_client_mapped_set(E_Client *ec, Eina_Bool set)
3004 {
3005    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
3006    EINA_SAFETY_ON_NULL_RETURN(cdata);
3007
3008    cdata->mapped = set;
3009 }
3010
3011
3012 ////////////////////////////////////////////////
3013 EINTERN Eina_Bool
3014 e_client_clients_hash_exist()
3015 {
3016   int pix_id;
3017
3018   for (pix_id = 0; pix_id < E_PIXMAP_TYPE_MAX; pix_id++)
3019     {
3020       if (eina_hash_population(clients_hash[pix_id]))
3021         return EINA_TRUE;
3022     }
3023
3024   return EINA_FALSE;
3025 }
3026
3027 EINTERN void
3028 e_client_idler_before(Eina_Bool *check_focus)
3029 {
3030    const Eina_List *l;
3031    E_Client *ec;
3032
3033    *check_focus = EINA_FALSE;
3034
3035    if (!e_client_clients_hash_exist()) return;
3036
3037    TRACE_DS_BEGIN(CLIENT:IDLE BEFORE);
3038
3039    EINA_LIST_FOREACH(e_comp->clients, l, ec)
3040      {
3041         // pass 1 - eval0. fetch properties on new or on change and
3042         // call hooks to decide what to do - maybe move/resize
3043         if (ec->ignored || (!ec->changed)) continue;
3044
3045         wl_signal_emit_mutable(&PRI(ec)->events.eval_pre_fetch, NULL);
3046         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_PRE_FETCH, ec)) continue;
3047
3048
3049         /* FETCH is hooked by the compositor to get client hints */
3050         wl_signal_emit_mutable(&PRI(ec)->events.eval_fetch, NULL);
3051         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_FETCH, ec)) continue;
3052
3053         if (ec->new_client)
3054           {
3055              e_client_type_update(ec);
3056           }
3057
3058         /* PRE_POST_FETCH calls e_remember apply for new client */
3059         wl_signal_emit_mutable(&PRI(ec)->events.eval_pre_post_fetch, NULL);
3060         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_PRE_POST_FETCH, ec)) continue;
3061         wl_signal_emit_mutable(&PRI(ec)->events.eval_post_fetch, NULL);
3062         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_POST_FETCH, ec)) continue;
3063         wl_signal_emit_mutable(&PRI(ec)->events.eval_pre_frame_assign, NULL);
3064         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_PRE_FRAME_ASSIGN, ec)) continue;
3065
3066         wl_signal_emit_mutable(&PRI(ec)->events.eval_post_frame_assign, NULL);
3067         _e_client_hook_call(E_CLIENT_HOOK_EVAL_POST_FRAME_ASSIGN, ec);
3068      }
3069    // pass 2 - show and hide windows needing hide and eval (main eval)
3070    E_CLIENT_FOREACH(ec)
3071      {
3072         if (e_object_is_del(E_OBJECT(ec))) continue;
3073         if (ec->ignored)
3074           {
3075              // ignored client but needing eval (aux hint) such as remote surfaces
3076              if (ec->changed)
3077                {
3078                   E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
3079                   if (cdata && cdata->first_commit)
3080                     _e_client_aux_hint_eval(ec);
3081                }
3082              continue;
3083           }
3084
3085         if (ec->changes.visible)
3086           {
3087              if (ec->visible)
3088                {
3089                   if ((!ec->new_client) &&
3090                       (!ec->changes.pos) &&
3091                       (!ec->changes.size))
3092                     {
3093                        evas_object_show(ec->frame);
3094                        ec->changes.visible = !evas_object_visible_get(ec->frame);
3095                     }
3096                }
3097              else
3098                {
3099                   evas_object_hide(ec->frame);
3100                   ec->changes.visible = 0;
3101                }
3102           }
3103
3104         if (ec->changed)
3105           {
3106              _e_client_eval(ec);
3107              e_comp_visibility_calculation_set(EINA_TRUE);
3108              if (ec->changes.accepts_focus)
3109                *check_focus = EINA_TRUE;
3110              ec->changes.accepts_focus = 0;
3111           }
3112
3113         if ((ec->changes.visible) && (ec->visible) && (!ec->changed))
3114           {
3115              evas_object_show(ec->frame);
3116              ec->changes.visible = !evas_object_visible_get(ec->frame);
3117              ec->changed = ec->changes.visible;
3118              e_comp_visibility_calculation_set(EINA_TRUE);
3119           }
3120      }
3121
3122    TRACE_DS_END();
3123 }
3124
3125
3126 EINTERN Eina_Bool
3127 e_client_init(void)
3128 {
3129    int pix_id;
3130    for (pix_id = 0; pix_id < E_PIXMAP_TYPE_MAX; pix_id++)
3131      clients_hash[pix_id] = eina_hash_pointer_new(NULL);
3132
3133    E_COMP_WL_HOOK_APPEND(hooks, E_COMP_WL_HOOK_SHELL_SURFACE_READY, _e_client_cb_hook_shell_surface_ready, NULL);
3134
3135    E_EVENT_CLIENT_ADD = ecore_event_type_new();
3136    E_EVENT_CLIENT_REMOVE = ecore_event_type_new();
3137    E_EVENT_CLIENT_DESK_SET = ecore_event_type_new();
3138    E_EVENT_CLIENT_ZONE_SET = ecore_event_type_new();
3139    E_EVENT_CLIENT_RESIZE = ecore_event_type_new();
3140    E_EVENT_CLIENT_MOVE = ecore_event_type_new();
3141    E_EVENT_CLIENT_SHOW = ecore_event_type_new();
3142    E_EVENT_CLIENT_HIDE = ecore_event_type_new();
3143    E_EVENT_CLIENT_ICONIFY = ecore_event_type_new();
3144    E_EVENT_CLIENT_UNICONIFY = ecore_event_type_new();
3145    E_EVENT_CLIENT_STACK = ecore_event_type_new();
3146    E_EVENT_CLIENT_FOCUS_IN = ecore_event_type_new();
3147    E_EVENT_CLIENT_FOCUS_OUT = ecore_event_type_new();
3148    E_EVENT_CLIENT_PROPERTY = ecore_event_type_new();
3149    E_EVENT_CLIENT_FULLSCREEN = ecore_event_type_new();
3150    E_EVENT_CLIENT_UNFULLSCREEN = ecore_event_type_new();
3151 #ifdef _F_ZONE_WINDOW_ROTATION_
3152    E_EVENT_CLIENT_ROTATION_CHANGE_BEGIN = ecore_event_type_new();
3153    E_EVENT_CLIENT_ROTATION_CHANGE_CANCEL = ecore_event_type_new();
3154    E_EVENT_CLIENT_ROTATION_CHANGE_END = ecore_event_type_new();
3155    E_EVENT_CLIENT_ROTATION_GEOMETRY_SET = ecore_event_type_new();
3156 #endif
3157    E_EVENT_CLIENT_VISIBILITY_CHANGE = ecore_event_type_new();
3158    E_EVENT_CLIENT_BUFFER_CHANGE = ecore_event_type_new();
3159    E_EVENT_CLIENT_FOCUS_SKIP_SET = ecore_event_type_new();;
3160    E_EVENT_CLIENT_FOCUS_SKIP_UNSET = ecore_event_type_new();;
3161
3162    return (!!clients_hash[1]);
3163 }
3164
3165 EINTERN void
3166 e_client_shutdown(void)
3167 {
3168    int pix_id;
3169    for (pix_id = 0; pix_id < E_PIXMAP_TYPE_MAX; pix_id++)
3170      E_FREE_FUNC(clients_hash[pix_id], eina_hash_free);
3171
3172    E_FREE_LIST(hooks, e_comp_wl_hook_del);
3173    E_FREE_LIST(handlers, ecore_event_handler_del);
3174
3175 }
3176
3177 E_API void
3178 e_client_unignore(E_Client *ec)
3179 {
3180    E_OBJECT_CHECK(ec);
3181    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3182    if (!ec->ignored) return;
3183
3184    ec->ignored = 0;
3185    _e_client_event_add(ec);
3186 }
3187
3188 E_API E_Client *
3189 e_client_new(E_Pixmap *cp, int first_map, int internal)
3190 {
3191    E_Client *ec;
3192    E_Pixmap_Type type;
3193
3194    type = e_pixmap_type_get(cp);
3195    if (type >= E_PIXMAP_TYPE_MAX) return NULL;
3196    if (eina_hash_find(clients_hash[type], &cp)) return NULL;
3197
3198    ec = E_OBJECT_ALLOC(E_Client, E_CLIENT_TYPE, _e_client_free);
3199    if (!ec) return NULL;
3200    e_object_del_func_set(E_OBJECT(ec), E_OBJECT_CLEANUP_FUNC(_e_client_del));
3201
3202    if (!_e_client_private_init(ec))
3203      {
3204         e_object_del(E_OBJECT(ec));
3205         return NULL;
3206      }
3207
3208    uuid_generate(ec->uuid);
3209
3210    ec->focus_policy_override = E_FOCUS_LAST;
3211    e_client_size_set(ec, 1, 1);
3212    ec->internal = internal;
3213
3214    ec->pixmap = cp;
3215    e_pixmap_client_set(cp, ec);
3216    ec->resize_mode = E_POINTER_RESIZE_NONE;
3217    ec->layer = E_LAYER_CLIENT_NORMAL;
3218    ec->first_mapped = EINA_FALSE;
3219    ec->post_raise = EINA_TRUE;
3220    ec->post_lower = EINA_FALSE;
3221    ec->animatable = EINA_TRUE;
3222    ec->maximize_type = e_config->maximize_policy & E_MAXIMIZE_TYPE;
3223
3224    /* FIXME: if first_map is 1 then we should ignore the first hide event
3225     * or ensure the window is already hidden and events flushed before we
3226     * create a border for it */
3227    if (first_map)
3228      {
3229         ec->changes.pos = 1;
3230         ec->re_manage = 1;
3231         // needed to be 1 for internal windw and on restart.
3232         // ec->ignore_first_unmap = 2;
3233      }
3234    ec->offer_resistance = 1;
3235    ec->new_client = 1;
3236    e_comp->new_clients++;
3237
3238    ec->exp_iconify.by_client = 0;
3239    ec->exp_iconify.not_raise = 0;
3240    ec->exp_iconify.skip_iconify = 0;
3241    ec->exp_iconify.skip_by_remote = 0;
3242    if (e_config->deiconify_approve)
3243      ec->exp_iconify.deiconify_update= 1;
3244    else
3245      ec->exp_iconify.deiconify_update= 0;
3246    if (e_config->use_buffer_flush)
3247      ec->exp_iconify.buffer_flush = 1;
3248    else
3249      ec->exp_iconify.buffer_flush = 0;
3250
3251    e_client_iconified_type_set(ec, E_ICONIFIED_TYPE_NONE);
3252
3253    wl_signal_emit_mutable(&PRI(ec)->events.new_client, NULL);
3254    if (!_e_client_hook_call(E_CLIENT_HOOK_NEW_CLIENT, ec))
3255      {
3256         /* delete the above allocated object */
3257         //e_object_del(E_OBJECT(ec));
3258         return NULL;
3259      }
3260
3261    _e_client_aux_hint_eval(ec);
3262
3263    ec->icccm.title = NULL;
3264    ec->icccm.name = NULL;
3265 #if defined(__cplusplus) || defined(c_plusplus)
3266    ec->icccm.cpp_class = NULL;
3267 #else
3268    ec->icccm.class = NULL;
3269 #endif
3270    ec->icccm.icon_name = NULL;
3271    ec->icccm.machine = NULL;
3272    ec->icccm.min_w = 1;
3273    ec->icccm.min_h = 1;
3274    ec->icccm.max_w = 32767;
3275    ec->icccm.max_h = 32767;
3276    ec->icccm.base_w = 0;
3277    ec->icccm.base_h = 0;
3278    ec->icccm.step_w = -1;
3279    ec->icccm.step_h = -1;
3280    ec->icccm.min_aspect = 0.0;
3281    ec->icccm.max_aspect = 0.0;
3282
3283    ec->netwm.pid = 0;
3284    ec->netwm.name = NULL;
3285    ec->netwm.icon_name = NULL;
3286    ec->netwm.desktop = 0;
3287    ec->netwm.state.modal = 0;
3288    ec->netwm.state.sticky = 0;
3289    ec->netwm.state.shaded = 0;
3290    ec->netwm.state.hidden = 0;
3291    ec->netwm.state.maximized_v = 0;
3292    ec->netwm.state.maximized_h = 0;
3293    ec->netwm.state.skip_taskbar = 0;
3294    ec->netwm.state.skip_pager = 0;
3295    ec->netwm.state.fullscreen = 0;
3296    ec->netwm.state.stacking = E_STACKING_NONE;
3297    ec->netwm.action.move = 0;
3298    ec->netwm.action.resize = 0;
3299    ec->netwm.action.minimize = 0;
3300    ec->netwm.action.shade = 0;
3301    ec->netwm.action.stick = 0;
3302    ec->netwm.action.maximized_h = 0;
3303    ec->netwm.action.maximized_v = 0;
3304    ec->netwm.action.fullscreen = 0;
3305    ec->netwm.action.change_desktop = 0;
3306    ec->netwm.action.close = 0;
3307    ec->netwm.opacity = 255;
3308
3309    ec->visibility.obscured = E_VISIBILITY_UNKNOWN;
3310    ec->visibility.opaque = -1;
3311    ec->visibility.changed = 0;
3312    ec->visibility.skip = 0;
3313    ec->visibility.last_sent_type = E_VISIBILITY_UNKNOWN;
3314
3315    ec->transform.zoom = 1.0;
3316    ec->transform.angle = 0.0;
3317    ec->transform_core.direct_render = EINA_TRUE;
3318    ec->transform_core.activate = EINA_TRUE;
3319
3320    ec->pointer_enter_sent = EINA_FALSE;
3321
3322    ec->acquire_fence_fd = -1;
3323
3324    EC_CHANGED(ec);
3325
3326    e_comp->clients = eina_list_append(e_comp->clients, ec);
3327    eina_hash_add(clients_hash[type], &ec->pixmap, ec);
3328
3329    ELOGF("COMP", "CLIENT ADD. cp:%p, argb:%d, internal:%d, ignored:%d", ec, cp, ec->argb, internal, ec->ignored);
3330    if (!ec->ignored)
3331      _e_client_event_add(ec);
3332    e_comp_object_client_add(ec);
3333    if (ec->frame)
3334      {
3335         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_SHOW, _e_client_cb_evas_show, ec);
3336         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_HIDE, _e_client_cb_evas_hide, ec);
3337         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_MOVE, _e_client_cb_evas_move, ec);
3338         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_RESIZE, _e_client_cb_evas_resize, ec);
3339         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_RESTACK, _e_client_cb_evas_restack, ec);
3340         evas_object_smart_callback_add(ec->frame, "shade_done", _e_client_cb_evas_shade_done, ec);
3341      }
3342
3343    wl_signal_emit_mutable(&PRI(ec)->events.new_client_post, NULL);
3344
3345 #ifdef _F_E_CLIENT_NEW_CLIENT_POST_HOOK_
3346    _e_client_hook_call(E_CLIENT_HOOK_NEW_CLIENT_POST, ec);
3347 #endif
3348
3349    ec->manage_resize.resize_obj = NULL;
3350    ec->manage_resize.x = ec->manage_resize.y = ec->manage_resize.w = ec->manage_resize.h = 0;
3351    ec->manage_resize.enable_aspect_ratio = EINA_FALSE;
3352    ec->manage_resize.aw = ec->manage_resize.ah = 0;
3353    ec->manage_resize.header_h = 0;
3354    ec->manage_resize.footer_h = 0;
3355
3356    ec->visibility.ignore_geometry = e_config->calc_vis_ignore_geometry;
3357
3358    return ec;
3359 }
3360
3361 E_API Eina_Bool e_client_is_internal(E_Client *ec)
3362 {
3363    E_OBJECT_CHECK_RETURN(ec, EINA_TRUE);
3364    return ec->internal;
3365 }
3366
3367 EINTERN void
3368 e_client_desk_iconify_skip_set(E_Client *ec, Eina_Bool skip)
3369 {
3370    if (!ec) return;
3371    ec->user_skip_winlist = skip;
3372 }
3373
3374 EINTERN Eina_Bool
3375 e_client_desk_iconify_skip_get(E_Client *ec)
3376 {
3377    if (!ec) return EINA_FALSE;
3378    return ec->user_skip_winlist;
3379 }
3380
3381 EINTERN Eina_Bool
3382 e_client_comp_grabbed_get(void)
3383 {
3384    return comp_grabbed;
3385 }
3386
3387 EINTERN E_Client *
3388 e_client_action_get(void)
3389 {
3390    return action_client;
3391 }
3392
3393
3394 //////////////////////////////////////////////////////////
3395
3396 EINTERN void
3397 e_client_mouse_in(E_Client *ec, int x, int y)
3398 {
3399    E_Desk *desk;
3400
3401    if (comp_grabbed) return;
3402    if (e_object_is_del(E_OBJECT(ec))) return;
3403    desk = e_comp_desk_find_by_ec(ec);
3404    if (desk && desk->animate_count) return;
3405    ec->mouse.current.mx = x;
3406    ec->mouse.current.my = y;
3407    ec->mouse.in = 1;
3408
3409    wl_signal_emit_mutable(&PRI(ec)->events.mouse_in, NULL);
3410 }
3411
3412 EINTERN void
3413 e_client_mouse_out(E_Client *ec, int x, int y)
3414 {
3415    E_Desk *desk;
3416
3417    if (comp_grabbed) return;
3418    if (ec->fullscreen) return;
3419    if (e_object_is_del(E_OBJECT(ec))) return;
3420    desk = e_comp_desk_find_by_ec(ec);
3421    if (desk && desk->animate_count) return;
3422
3423    ec->mouse.current.mx = x;
3424    ec->mouse.current.my = y;
3425    ec->mouse.in = 0;
3426
3427    wl_signal_emit_mutable(&PRI(ec)->events.mouse_out, NULL);
3428 }
3429
3430 EINTERN void
3431 e_client_mouse_wheel(E_Client *ec, Evas_Point *output, E_Binding_Event_Wheel *ev)
3432 {
3433    EINA_SAFETY_ON_NULL_RETURN(ec);
3434    if (action_client) return;
3435    ec->mouse.current.mx = output->x;
3436    ec->mouse.current.my = output->y;
3437 }
3438
3439 EINTERN void
3440 e_client_mouse_down(E_Client *ec, int button, Evas_Point *output, E_Binding_Event_Mouse_Button *ev)
3441 {
3442    EINA_SAFETY_ON_NULL_RETURN(ec);
3443
3444    if (action_client || ec->iconic || e_client_util_ignored_get(ec)) return;
3445    if ((button >= 1) && (button <= 3))
3446      {
3447         ec->mouse.last_down[button - 1].mx = output->x;
3448         ec->mouse.last_down[button - 1].my = output->y;
3449         ec->mouse.last_down[button - 1].x = ec->x;
3450         ec->mouse.last_down[button - 1].y = ec->y;
3451         ec->mouse.last_down[button - 1].w = ec->w;
3452         ec->mouse.last_down[button - 1].h = ec->h;
3453      }
3454    else
3455      {
3456         ec->moveinfo.down.x = ec->x;
3457         ec->moveinfo.down.y = ec->y;
3458         ec->moveinfo.down.w = ec->w;
3459         ec->moveinfo.down.h = ec->h;
3460      }
3461    ec->mouse.current.mx = output->x;
3462    ec->mouse.current.my = output->y;
3463    if ((button >= 1) && (button <= 3))
3464      {
3465         ec->mouse.last_down[button - 1].mx = output->x;
3466         ec->mouse.last_down[button - 1].my = output->y;
3467         ec->mouse.last_down[button - 1].x = ec->x;
3468         ec->mouse.last_down[button - 1].y = ec->y;
3469         ec->mouse.last_down[button - 1].w = ec->w;
3470         ec->mouse.last_down[button - 1].h = ec->h;
3471      }
3472    else
3473      {
3474         ec->moveinfo.down.x = ec->x;
3475         ec->moveinfo.down.y = ec->y;
3476         ec->moveinfo.down.w = ec->w;
3477         ec->moveinfo.down.h = ec->h;
3478      }
3479    ec->mouse.current.mx = output->x;
3480    ec->mouse.current.my = output->y;
3481
3482    wl_signal_emit_mutable(&PRI(ec)->events.mouse_down, NULL);
3483 }
3484
3485 EINTERN void
3486 e_client_mouse_up(E_Client *ec, int button, Evas_Point *output, E_Binding_Event_Mouse_Button* ev)
3487 {
3488    EINA_SAFETY_ON_NULL_RETURN(ec);
3489    if (ec->iconic || e_client_util_ignored_get(ec)) return;
3490    if ((button >= 1) && (button <= 3))
3491      {
3492         ec->mouse.last_up[button - 1].mx = output->x;
3493         ec->mouse.last_up[button - 1].my = output->y;
3494         ec->mouse.last_up[button - 1].x = ec->x;
3495         ec->mouse.last_up[button - 1].y = ec->y;
3496      }
3497    ec->mouse.current.mx = output->x;
3498    ec->mouse.current.my = output->y;
3499    /* also we don't pass the same params that went in - then again that */
3500    /* should be ok as we are just ending the action if it has an end */
3501    if (ec->cur_mouse_action)
3502      {
3503         if (ec->cur_mouse_action->func.end_mouse)
3504           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", ev);
3505         else if (ec->cur_mouse_action->func.end)
3506           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
3507         e_object_unref(E_OBJECT(ec->cur_mouse_action));
3508         ec->cur_mouse_action = NULL;
3509      }
3510
3511    if ((button >= 1) && (button <= 3))
3512      {
3513         ec->mouse.last_up[button - 1].mx = output->x;
3514         ec->mouse.last_up[button - 1].my = output->y;
3515         ec->mouse.last_up[button - 1].x = ec->x;
3516         ec->mouse.last_up[button - 1].y = ec->y;
3517      }
3518 }
3519
3520 E_API void
3521 e_client_stay_within_canvas_margin(E_Client *ec)
3522 {
3523    int new_x = ec->x;
3524    int new_y = ec->y;
3525
3526    if (ec->floating)
3527      {
3528         _e_client_stay_within_canvas_margin(ec, ec->x, ec->y, &new_x, &new_y);
3529
3530         if ((ec->x != new_x) || (ec->y != new_y))
3531           evas_object_move(ec->frame, new_x, new_y);
3532      }
3533 }
3534
3535 EINTERN void
3536 e_client_mouse_move(E_Client *ec, Evas_Point *output)
3537 {
3538    EINA_SAFETY_ON_NULL_RETURN(ec);
3539    if (ec->iconic || e_client_util_ignored_get(ec)) return;
3540    ec->mouse.current.mx = output->x;
3541    ec->mouse.current.my = output->y;
3542    if (e_client_util_moving_get(ec))
3543      {
3544         _e_client_move_handle(ec);
3545      }
3546    else if (e_client_util_resizing_get(ec))
3547      {
3548         _e_client_resize_handle(ec);
3549      }
3550 }
3551 ///////////////////////////////////////////////////////
3552
3553 EINTERN void
3554 e_client_res_change_geometry_save(E_Client *ec)
3555 {
3556    E_OBJECT_CHECK(ec);
3557    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3558
3559    if (ec->pre_res_change.valid) return;
3560    ec->pre_res_change.valid = 1;
3561    ec->pre_res_change.x = ec->x;
3562    ec->pre_res_change.y = ec->y;
3563    ec->pre_res_change.w = ec->w;
3564    ec->pre_res_change.h = ec->h;
3565    ec->pre_res_change.saved.x = ec->saved.x;
3566    ec->pre_res_change.saved.y = ec->saved.y;
3567    ec->pre_res_change.saved.w = ec->saved.w;
3568    ec->pre_res_change.saved.h = ec->saved.h;
3569 }
3570
3571 EINTERN void
3572 e_client_res_change_geometry_restore(E_Client *ec)
3573 {
3574    E_Zone *zone;
3575
3576    struct
3577    {
3578       unsigned char valid : 1;
3579       int           x, y, w, h;
3580       struct
3581       {
3582          int x, y, w, h;
3583       } saved;
3584    } pre_res_change;
3585
3586    E_OBJECT_CHECK(ec);
3587    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3588    if (!ec->pre_res_change.valid) return;
3589    if (ec->new_client) return;
3590
3591    zone = e_comp_zone_find_by_ec(ec);
3592    if (!zone) return;
3593
3594    memcpy(&pre_res_change, &ec->pre_res_change, sizeof(pre_res_change));
3595
3596    if (ec->fullscreen)
3597      {
3598         e_client_unfullscreen(ec);
3599         e_client_fullscreen(ec, e_config->fullscreen_policy);
3600      }
3601    else if (ec->maximized != E_MAXIMIZE_NONE)
3602      {
3603         E_Maximize max;
3604
3605         max = ec->maximized;
3606         e_client_unmaximize(ec, E_MAXIMIZE_BOTH);
3607         e_client_maximize(ec, max);
3608      }
3609    else
3610      {
3611         int x, y, w, h, zx, zy, zw, zh;
3612
3613         ec->saved.x = ec->pre_res_change.saved.x;
3614         ec->saved.y = ec->pre_res_change.saved.y;
3615         ec->saved.w = ec->pre_res_change.saved.w;
3616         ec->saved.h = ec->pre_res_change.saved.h;
3617
3618         e_zone_useful_geometry_get(zone, &zx, &zy, &zw, &zh);
3619
3620         if (ec->saved.w > zw)
3621           ec->saved.w = zw;
3622         if ((ec->saved.x + ec->saved.w) > (zx + zw))
3623           ec->saved.x = zx + zw - ec->saved.w;
3624
3625         if (ec->saved.h > zh)
3626           ec->saved.h = zh;
3627         if ((ec->saved.y + ec->saved.h) > (zy + zh))
3628           ec->saved.y = zy + zh - ec->saved.h;
3629
3630         x = ec->pre_res_change.x;
3631         y = ec->pre_res_change.y;
3632         w = ec->pre_res_change.w;
3633         h = ec->pre_res_change.h;
3634         if (w > zw)
3635           w = zw;
3636         if (h > zh)
3637           h = zh;
3638         if ((x + w) > (zx + zw))
3639           x = zx + zw - w;
3640         if ((y + h) > (zy + zh))
3641           y = zy + zh - h;
3642         evas_object_geometry_set(ec->frame, x, y, w, h);
3643      }
3644    memcpy(&ec->pre_res_change, &pre_res_change, sizeof(pre_res_change));
3645 }
3646
3647 EINTERN void
3648 e_client_pos_set(E_Client *ec, int x, int y)
3649 {
3650    if (!ec) return;
3651    ec->x = x;
3652    ec->y = y;
3653 }
3654
3655 EINTERN void
3656 e_client_pos_get(E_Client *ec, int *x, int *y)
3657 {
3658    int ex = 0;
3659    int ey = 0;
3660
3661    if (ec)
3662      {
3663         ex = ec->x;
3664         ey = ec->y;
3665      }
3666
3667    if (x) *x = ex;
3668    if (y) *y = ey;
3669 }
3670
3671 E_API void
3672 e_client_size_set(E_Client *ec, int w, int h)
3673 {
3674    if (!ec) return;
3675    ec->w = w;
3676    ec->h = h;
3677 }
3678
3679 E_API void
3680 e_client_size_get(E_Client *ec, int *w, int *h)
3681 {
3682    int ew = 0;
3683    int eh = 0;
3684
3685    if (ec)
3686      {
3687         ew = ec->w;
3688         eh = ec->h;
3689      }
3690
3691    if (w) *w = ew;
3692    if (h) *h = eh;
3693 }
3694
3695 E_API void
3696 e_client_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
3697 {
3698    int gx = 0;
3699    int gy = 0;
3700    int gw = 0;
3701    int gh = 0;
3702
3703    E_OBJECT_CHECK(ec);
3704    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3705
3706    if (e_client_transform_core_enable_get(ec))
3707      {
3708         gx = ec->transform_core.result.boundary.x;
3709         gy = ec->transform_core.result.boundary.y;
3710         gw = ec->transform_core.result.boundary.w;
3711         gh = ec->transform_core.result.boundary.h;
3712      }
3713    else
3714      {
3715         if (ec->frame)
3716           {
3717              evas_object_geometry_get(ec->frame, &gx, &gy, &gw, &gh);
3718              if (gw == 0 && gh == 0)
3719                {
3720                   /* In this case, there is no image buffer in e_comp_object, thus it
3721                    * should return geometry value of ec itself. It usually happens if
3722                    * new ec is not mapped yet.
3723                    */
3724                   gw = ec->w;
3725                   gh = ec->h;
3726                   gx = ec->x;
3727                   gy = ec->y;
3728                }
3729           }
3730         else
3731           {
3732              gx = ec->x;
3733              gy = ec->y;
3734              gw = ec->w;
3735              gh = ec->h;
3736           }
3737      }
3738
3739    if (x) *x = gx;
3740    if (y) *y = gy;
3741    if (w) *w = gw;
3742    if (h) *h = gh;
3743 }
3744
3745 E_API E_Client *
3746 e_client_above_get(const E_Client *ec)
3747 {
3748    unsigned int x;
3749    E_Client *ec2;
3750
3751    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
3752    if (EINA_INLIST_GET(ec)->next) //check current layer
3753      {
3754         EINA_INLIST_FOREACH(EINA_INLIST_GET(ec)->next, ec2)
3755           {
3756              if (ec == ec2)
3757                {
3758                   ELOGF("FATAL", "CHECK the ec inlist next", ec);
3759                   continue;
3760                }
3761              if (!e_object_is_del(E_OBJECT(ec2)))
3762                return ec2;
3763           }
3764      }
3765    if (ec->layer == E_LAYER_CLIENT_CURSOR) return NULL;
3766    if (e_comp_canvas_client_layer_map(ec->layer) == 9999) return NULL;
3767
3768    g_rec_mutex_lock(&e_comp->input_key_grabs_mutex);
3769    /* go up the layers until we find one */
3770    for (x = e_comp_canvas_layer_map(ec->layer) + 1; x <= e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x++)
3771      {
3772         if (!e_comp->layers[x].clients) continue;
3773         EINA_INLIST_FOREACH(e_comp->layers[x].clients, ec2)
3774           {
3775              if (ec == ec2)
3776                {
3777                   ELOGF("FATAL", "EC exist above layer. ec layer_map:%d, cur layer_map:%d",
3778                         ec, e_comp_canvas_layer_map(ec->layer), x);
3779                   continue;
3780                }
3781              if (!e_object_is_del(E_OBJECT(ec2)))
3782                {
3783                   g_rec_mutex_unlock(&e_comp->input_key_grabs_mutex);
3784                   return ec2;
3785                }
3786           }
3787      }
3788    g_rec_mutex_unlock(&e_comp->input_key_grabs_mutex);
3789
3790    return NULL;
3791 }
3792
3793 E_API E_Client *
3794 e_client_below_get(const E_Client *ec)
3795 {
3796    unsigned int x;
3797    E_Client *ec2;
3798    Eina_Inlist *l;
3799    E_Layer ec_layer, ec_layer_cw;
3800    int cw_layer;
3801
3802    E_OBJECT_CHECK_RETURN(ec, NULL);
3803    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, NULL);
3804
3805    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
3806    if (EINA_INLIST_GET(ec)->prev) //check current layer
3807      {
3808         for (l = EINA_INLIST_GET(ec)->prev; l; l = l->prev)
3809           {
3810              ec2 = EINA_INLIST_CONTAINER_GET(l, E_Client);
3811              if (ec == ec2)
3812                {
3813                   ELOGF("FATAL", "CHECK the ec inlist prev", ec);
3814                   continue;
3815                }
3816              if (!e_object_is_del(E_OBJECT(ec2)))
3817                return ec2;
3818           }
3819      }
3820
3821    // check layer validation
3822    ec_layer = ec->layer;
3823    if (ec->layer_block || ec->layer_pending)
3824      {
3825         cw_layer = e_comp_object_layer_get(ec->frame);
3826         if (cw_layer >= 0)
3827           {
3828              ec_layer_cw = e_comp_canvas_layer_map_to(cw_layer);
3829              if (ec_layer != ec_layer_cw)
3830                {
3831                   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);
3832                   ec_layer = ec_layer_cw;
3833                }
3834           }
3835      }
3836
3837    if (ec_layer == E_LAYER_CLIENT_DESKTOP) return NULL;
3838    if (e_comp_canvas_client_layer_map(ec_layer) == 9999) return NULL;
3839
3840    /* go down the layers until we find one */
3841    x = e_comp_canvas_layer_map(ec_layer);
3842    if (x > 0) x--;
3843
3844    g_rec_mutex_lock(&e_comp->input_key_grabs_mutex);
3845    for (; x >= e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x--)
3846      {
3847         if (!e_comp->layers[x].clients) continue;
3848         EINA_INLIST_REVERSE_FOREACH(e_comp->layers[x].clients, ec2)
3849           {
3850              if (ec == ec2)
3851                {
3852                   ELOGF("FATAL", "EC exist below layer. ec layer_map:%d, cur layer_map:%d",
3853                         ec, e_comp_canvas_layer_map(ec_layer), x);
3854                   continue;
3855                }
3856              if (!e_object_is_del(E_OBJECT(ec2)))
3857                {
3858                   g_rec_mutex_unlock(&e_comp->input_key_grabs_mutex);
3859                   return ec2;
3860                }
3861           }
3862      }
3863    g_rec_mutex_unlock(&e_comp->input_key_grabs_mutex);
3864
3865    return NULL;
3866 }
3867
3868 E_API E_Client *
3869 e_client_bottom_get(void)
3870 {
3871    unsigned int x;
3872    g_rec_mutex_lock(&e_comp->input_key_grabs_mutex);
3873    for (x = e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x <= e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x++)
3874      {
3875         E_Client *ec2;
3876
3877         if (!e_comp->layers[x].clients) continue;
3878         EINA_INLIST_FOREACH(e_comp->layers[x].clients, ec2)
3879           if (!e_object_is_del(E_OBJECT(ec2)))
3880             {
3881                g_rec_mutex_unlock(&e_comp->input_key_grabs_mutex);
3882                return ec2;
3883             }
3884      }
3885    g_rec_mutex_unlock(&e_comp->input_key_grabs_mutex);
3886
3887    return NULL;
3888 }
3889
3890 E_API E_Client *
3891 e_client_top_get(void)
3892 {
3893    unsigned int x;
3894    g_rec_mutex_lock(&e_comp->input_key_grabs_mutex);
3895    for (x = e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x >= e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x--)
3896      {
3897         E_Client *ec2;
3898
3899         if (!e_comp->layers[x].clients) continue;
3900         EINA_INLIST_REVERSE_FOREACH(e_comp->layers[x].clients, ec2)
3901           if (!e_object_is_del(E_OBJECT(ec2)))
3902             {
3903                g_rec_mutex_unlock(&e_comp->input_key_grabs_mutex);
3904                return ec2;
3905             }
3906      }
3907    g_rec_mutex_unlock(&e_comp->input_key_grabs_mutex);
3908
3909    return NULL;
3910 }
3911
3912 EINTERN unsigned int
3913 e_clients_count(void)
3914 {
3915    return eina_list_count(e_comp->clients);
3916 }
3917
3918
3919 /**
3920  * Set a callback which will be called just prior to updating the
3921  * move coordinates for a border
3922  */
3923 EINTERN void
3924 e_client_move_intercept_cb_set(E_Client *ec, E_Client_Move_Intercept_Cb cb)
3925 {
3926    ec->move_intercept_cb = cb;
3927 }
3928
3929 ///////////////////////////////////////
3930
3931 E_API E_Client_Hook *
3932 e_client_hook_add(E_Client_Hook_Point hookpoint, E_Client_Hook_Cb func, const void *data)
3933 {
3934    E_Client_Hook *ch;
3935
3936    EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_CLIENT_HOOK_LAST, NULL);
3937    ch = E_NEW(E_Client_Hook, 1);
3938    if (!ch) return NULL;
3939    ch->hookpoint = hookpoint;
3940    ch->func = func;
3941    ch->data = (void*)data;
3942    _e_client_hooks[hookpoint] = eina_inlist_append(_e_client_hooks[hookpoint], EINA_INLIST_GET(ch));
3943    return ch;
3944 }
3945
3946 E_API void
3947 e_client_hook_del(E_Client_Hook *ch)
3948 {
3949    ch->delete_me = 1;
3950    if (_e_client_hooks_walking == 0)
3951      {
3952         _e_client_hooks[ch->hookpoint] = eina_inlist_remove(_e_client_hooks[ch->hookpoint], EINA_INLIST_GET(ch));
3953         free(ch);
3954      }
3955    else
3956      _e_client_hooks_delete++;
3957 }
3958
3959 ///////////////////////////////////////
3960
3961 E_API E_Client_Intercept_Hook *
3962 e_client_intercept_hook_add(E_Client_Intercept_Hook_Point hookpoint, E_Client_Intercept_Hook_Cb func, const void *data)
3963 {
3964    E_Client_Intercept_Hook *ch;
3965
3966    EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_CLIENT_INTERCEPT_HOOK_LAST, NULL);
3967    ch = E_NEW(E_Client_Intercept_Hook, 1);
3968    if (!ch) return NULL;
3969    ch->hookpoint = hookpoint;
3970    ch->func = func;
3971    ch->data = (void*)data;
3972    _e_client_intercept_hooks[hookpoint] = eina_inlist_append(_e_client_intercept_hooks[hookpoint], EINA_INLIST_GET(ch));
3973    return ch;
3974 }
3975
3976 E_API void
3977 e_client_intercept_hook_del(E_Client_Intercept_Hook *ch)
3978 {
3979    if (!ch) return;
3980
3981    ch->delete_me = 1;
3982    if (_e_client_intercept_hooks_walking == 0)
3983      {
3984         _e_client_intercept_hooks[ch->hookpoint] =
3985            eina_inlist_remove(_e_client_intercept_hooks[ch->hookpoint], EINA_INLIST_GET(ch));
3986         free(ch);
3987      }
3988    else
3989      _e_client_intercept_hooks_delete++;
3990 }
3991
3992 E_API void
3993 e_client_focus_latest_set(E_Client *ec)
3994 {
3995    EINA_SAFETY_ON_NULL_RETURN(ec);
3996
3997    wl_signal_emit_mutable(&PRI(ec)->events.focus_latest_set, NULL);
3998 }
3999
4000 E_API void
4001 e_client_focus_defer_set(E_Client *ec)
4002 {
4003    EINA_SAFETY_ON_NULL_RETURN(ec);
4004
4005    wl_signal_emit_mutable(&PRI(ec)->events.focus_defer_set, NULL);
4006 }
4007
4008 EINTERN void
4009 e_client_focused_set(E_Client *ec)
4010 {
4011    E_Client *focused_ec;
4012    E_Zone *zone;
4013
4014    if (ec)
4015      ELOGF("FOCUS", "CLIENT FOCUSED_SET : SET", ec);
4016    else
4017      ELOGF("FOCUS", "CLIENT FOCUSED_SET : UNSET", NULL);
4018
4019   focused_ec = e_comp_focused_ec_get();
4020   if (ec == focused_ec) return;
4021
4022    TRACE_DS_BEGIN(CLIENT:FOCUSED SET);
4023
4024    // unset the current focused_ec if focused_ec is not being deleted
4025    if (focused_ec)
4026      {
4027        if (!e_object_is_del(E_OBJECT(focused_ec)))
4028          {
4029             // FIXME: Remove focus_unset event of client.
4030             //        Instead, make zone focus_unset event and use it.
4031             wl_signal_emit_mutable(&PRI(focused_ec)->events.focus_unset, NULL);
4032             _e_client_hook_call(E_CLIENT_HOOK_FOCUS_UNSET, focused_ec);
4033
4034             if (e_object_ref_get(E_OBJECT(focused_ec)) > 0)
4035               {
4036                  _e_client_event_simple(focused_ec, E_EVENT_CLIENT_FOCUS_OUT);
4037                  e_client_urgent_set(focused_ec, focused_ec->icccm.urgent);
4038               }
4039          }
4040      }
4041
4042    // clear the current focused_ec when ec is NULL
4043    if (!ec)
4044      {
4045         zone = e_comp_zone_find_by_ec(focused_ec);
4046         e_zone_focus_clear(zone);
4047         TRACE_DS_END();
4048         return;
4049      }
4050
4051    // FIXME: Remove focus_set event of client.
4052    //        Instead, make zone focus_set event and use it.
4053    // set the new current focused_ec
4054    wl_signal_emit_mutable(&PRI(ec)->events.focus_set, NULL);
4055    _e_client_hook_call(E_CLIENT_HOOK_FOCUS_SET, ec);
4056
4057    // send the client_focuse_in event
4058    _e_client_event_simple(ec, E_EVENT_CLIENT_FOCUS_IN);
4059
4060    TRACE_DS_END();
4061 }
4062
4063 EINTERN void
4064 e_client_activate(E_Client *ec)
4065 {
4066    E_OBJECT_CHECK(ec);
4067    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4068
4069    TRACE_DS_BEGIN(CLIENT:ACTIVATE);
4070
4071    ELOGF("COMP", "Set launching flag..", ec);
4072    ec->launching = EINA_TRUE;
4073
4074    ec->exp_iconify.not_raise = 0;
4075
4076    if (ec->iconic)
4077      {
4078          if (!ec->lock_user_iconify)
4079            e_client_uniconify(ec);
4080      }
4081    ELOGF("COMP", "Un-Set ICONIFY BY CLIENT", ec);
4082    ec->exp_iconify.by_client = 0;
4083    e_client_iconified_type_set(ec, E_ICONIFIED_TYPE_NONE);
4084
4085    wl_signal_emit_mutable(&PRI(ec)->events.activate_done, NULL);
4086    _e_client_hook_call(E_CLIENT_HOOK_ACTIVATE_DONE, ec);
4087
4088    TRACE_DS_END();
4089 }
4090
4091 E_API E_Client *
4092 e_client_focused_get(void)
4093 {
4094    return e_comp_focused_ec_get();
4095 }
4096
4097 EINTERN Eina_List *
4098 e_client_lost_windows_get(E_Zone *zone)
4099 {
4100    Eina_List *list = NULL;
4101    const Eina_List *l;
4102    E_Client *ec;
4103    int loss_overlap = 5;
4104
4105    E_OBJECT_CHECK_RETURN(zone, NULL);
4106    E_OBJECT_TYPE_CHECK_RETURN(zone, E_ZONE_TYPE, NULL);
4107    EINA_LIST_FOREACH(e_comp->clients, l, ec)
4108      {
4109         if (!e_zone_has_ec(zone, ec)) continue;
4110         if (e_client_util_ignored_get(ec)) continue;
4111
4112         if (!E_INTERSECTS(zone->x + loss_overlap,
4113                           zone->y + loss_overlap,
4114                           zone->w - (2 * loss_overlap),
4115                           zone->h - (2 * loss_overlap),
4116                           ec->x, ec->y, ec->w, ec->h))
4117           {
4118              list = eina_list_append(list, ec);
4119           }
4120      }
4121    return list;
4122 }
4123
4124 ///////////////////////////////////////
4125
4126 EINTERN void
4127 e_client_shade(E_Client *ec, E_Direction dir)
4128 {
4129    E_OBJECT_CHECK(ec);
4130    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4131    if ((ec->shaded) || (ec->shading) || (ec->fullscreen) ||
4132        ((ec->maximized) && (!e_config->allow_manip))) return;
4133    if (!e_util_strcmp("borderless", ec->bordername)) return;
4134    if (!e_comp_object_frame_allowed(ec->frame)) return;
4135
4136    ec->take_focus = 0;
4137    ec->shading = 1;
4138    ec->shade_dir = dir;
4139
4140    evas_object_smart_callback_call(ec->frame, "shaded", (uintptr_t*)dir);
4141 }
4142
4143 EINTERN void
4144 e_client_unshade(E_Client *ec, E_Direction dir)
4145 {
4146    E_OBJECT_CHECK(ec);
4147    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4148    if ((!ec->shaded) || (ec->shading))
4149      return;
4150
4151    ec->shading = 1;
4152    ec->shade_dir = 0;
4153
4154    evas_object_smart_callback_call(ec->frame, "unshaded", (uintptr_t*)dir);
4155 }
4156
4157 ///////////////////////////////////////
4158
4159 EINTERN void
4160 e_client_maximized_geometry_set(E_Client *ec, int x, int y, int w, int h)
4161 {
4162    if (!ec) return;
4163
4164    ec->maximized_info.x = x;
4165    ec->maximized_info.y = y;
4166    ec->maximized_info.w = w;
4167    ec->maximized_info.h = h;
4168
4169    e_client_frame_geometry_set(ec, x, y, w, h);
4170 }
4171
4172 EINTERN void
4173 e_client_maximized_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
4174 {
4175    if (!ec) return;
4176
4177    if (x) *x = ec->maximized_info.x;
4178    if (y) *y = ec->maximized_info.y;
4179    if (w) *w = ec->maximized_info.w;
4180    if (h) *h = ec->maximized_info.h;
4181 }
4182
4183 EINTERN void
4184 e_client_maximize_update(E_Client *ec)
4185 {
4186    E_Maximize max;
4187
4188    E_OBJECT_CHECK(ec);
4189    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4190
4191    if (ec->maximized)
4192      {
4193         max = ec->maximized;
4194         ec->maximized = 0;
4195         e_client_maximize(ec, max);
4196      }
4197 }
4198
4199 E_API void
4200 e_client_maximize(E_Client *ec, E_Maximize max)
4201 {
4202    E_OBJECT_CHECK(ec);
4203    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4204
4205    if (!(max & E_MAXIMIZE_DIRECTION)) max |= E_MAXIMIZE_BOTH;
4206
4207    if ((ec->shaded) || (ec->shading)) return;
4208
4209    if ((ec->maximized & E_MAXIMIZE_DIRECTION) == (max & E_MAXIMIZE_DIRECTION))
4210      {
4211         if ((ec->maximized & E_MAXIMIZE_TYPE) == (max & E_MAXIMIZE_TYPE))
4212           return;
4213      }
4214
4215    if (ec->new_client)
4216      {
4217         ec->changes.need_maximize = 1;
4218         ec->maximized &= ~E_MAXIMIZE_TYPE;
4219         ec->maximized |= max;
4220         EC_CHANGED(ec);
4221         return;
4222      }
4223
4224    // call the maximize hook of a client
4225    wl_signal_emit_mutable(&PRI(ec)->events.maximize, &max);
4226
4227    // store the E_Maximize value
4228    ec->maximized = max;
4229    ec->changes.need_unmaximize = 0;
4230
4231    evas_object_smart_callback_call(ec->frame, "maximize_done", NULL);
4232 }
4233
4234 E_API void
4235 e_client_unmaximize(E_Client *ec, E_Maximize max)
4236 {
4237    E_OBJECT_CHECK(ec);
4238    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4239
4240    if (!(max & E_MAXIMIZE_DIRECTION))
4241      {
4242         CRI("BUG: Unmaximize call without direction!");
4243         return;
4244      }
4245    if (ec->new_client)
4246      {
4247         ec->changes.need_unmaximize = 1;
4248         EC_CHANGED(ec);
4249         return;
4250      }
4251
4252    if ((ec->shaded) || (ec->shading)) return;
4253
4254    /* Remove directions not used */
4255    max &= (ec->maximized & E_MAXIMIZE_DIRECTION);
4256    /* Can only remove existing maximization directions */
4257    if (!max) return;
4258
4259    evas_object_smart_callback_call(ec->frame, "unmaximize_pre", NULL);
4260
4261    // call the unmaximize hook of a client
4262    wl_signal_emit_mutable(&PRI(ec)->events.unmaximize, &max);
4263
4264    evas_object_smart_callback_call(ec->frame, "unmaximize_done", NULL);
4265    ec->changes.need_unmaximize = 0;
4266 }
4267
4268 EINTERN void
4269 e_client_fullscreen(E_Client *ec, E_Fullscreen policy)
4270 {
4271    E_OBJECT_CHECK(ec);
4272    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4273
4274    if ((ec->shaded) || (ec->shading) || (ec->fullscreen)) return;
4275
4276    // call the fullscreen_pre hook of a client
4277    wl_signal_emit_mutable(&PRI(ec)->events.fullscreen_pre, NULL);
4278    _e_client_hook_call(E_CLIENT_HOOK_FULLSCREEN_PRE, ec);
4279
4280    // call the fullscreen hook of a client
4281    wl_signal_emit_mutable(&PRI(ec)->events.fullscreen, &policy);
4282
4283    ec->fullscreen_policy = policy;
4284
4285    _e_client_event_simple(ec, E_EVENT_CLIENT_FULLSCREEN);
4286 }
4287
4288 EINTERN void
4289 e_client_unfullscreen(E_Client *ec)
4290 {
4291    E_OBJECT_CHECK(ec);
4292    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4293
4294    if ((ec->shaded) || (ec->shading)) return;
4295    if (!ec->fullscreen) return;
4296
4297    // call the unfullscreen hook of a client
4298    wl_signal_emit_mutable(&PRI(ec)->events.unfullscreen, NULL);
4299
4300    ec->fullscreen_policy = E_FULLSCREEN_RESIZE;
4301
4302    _e_client_event_simple(ec, E_EVENT_CLIENT_UNFULLSCREEN);
4303 }
4304
4305 ///////////////////////////////////////
4306 EINTERN Eina_Bool
4307 e_client_is_parent_iconify_by_client(E_Client *ec)
4308 {
4309    E_Client *parent = ec->parent;
4310    if (!parent) return EINA_FALSE;
4311
4312    if ((parent->exp_iconify.type == E_ICONIFIED_TYPE_ICONIFY_BY_CLIENT) ||
4313        (parent->exp_iconify.type == E_ICONIFIED_TYPE_PARENT_ICONIFY_BY_CLIENT))
4314      return EINA_TRUE;
4315
4316    return EINA_FALSE;
4317 }
4318
4319 E_API void
4320 e_client_iconify(E_Client *ec)
4321 {
4322    E_OBJECT_CHECK(ec);
4323    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4324
4325    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
4326    Eina_Bool iconified_by_client = e_client_is_iconified_by_client(ec);
4327
4328    ELOGF("TZVIS", "ICONIFY  |iconic:%d  |argb:%d       |not_raise:%d   |by_client:%d, type:%d",
4329          ec, ec->iconic, ec->argb, (unsigned int)ec->exp_iconify.not_raise,
4330          ec->exp_iconify.by_client, ec->exp_iconify.type);
4331
4332    if (ec->shading || ec->iconic) return;
4333    if (ec->exp_iconify.skip_iconify && !iconified_by_client) return;
4334    if (ec->exp_iconify.skip_by_remote) return;
4335    if (!cdata || !cdata->mapped)
4336      {
4337         if (!iconified_by_client)
4338           {
4339              ELOGF("TZVIS", "Not mapped.. So, don't iconify", ec);
4340              return;
4341           }
4342         else
4343           {
4344              ELOGF("TZVIS", "Not mapped.. But, iconify by user request", ec);
4345           }
4346      }
4347
4348    TRACE_DS_BEGIN(CLIENT:ICONIFY);
4349
4350    wl_signal_emit_mutable(&PRI(ec)->events.iconify, NULL);
4351    _e_client_hook_call(E_CLIENT_HOOK_ICONIFY, ec);
4352
4353    TRACE_DS_END();
4354 }
4355
4356 E_API void
4357 e_client_uniconify(E_Client *ec)
4358 {
4359    E_Comp_Wl_Client_Data *cdata;
4360
4361    E_OBJECT_CHECK(ec);
4362    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4363
4364    cdata = e_client_cdata_get(ec);
4365
4366    ELOGF("TZVIS", "UNICONIFY|iconic:%d  |argb:%d       |not_raise:%d  |by_client:%d, type:%d |mapped:%d",
4367          ec, ec->iconic, ec->argb, (unsigned int)ec->exp_iconify.not_raise,
4368          ec->exp_iconify.by_client, ec->exp_iconify.type,
4369          cdata ? cdata->mapped : 0);
4370
4371    if (ec->shading || (!ec->iconic)) return;
4372
4373    TRACE_DS_BEGIN(CLIENT:UNICONIFY);
4374
4375     // call the uniconify hook of a client
4376    wl_signal_emit_mutable(&PRI(ec)->events.uniconify, NULL);
4377    _e_client_hook_call(E_CLIENT_HOOK_UNICONIFY, ec);
4378
4379    TRACE_DS_END();
4380 }
4381
4382 E_API void
4383 e_client_iconified_type_set(E_Client *ec, E_Iconified_Type type)
4384 {
4385    if (!ec) return;
4386    ec->exp_iconify.type = type;
4387 }
4388
4389 EINTERN E_Iconified_Type
4390 e_client_iconified_type_get(E_Client *ec)
4391 {
4392    if (!ec) return E_ICONIFIED_TYPE_NONE;
4393    return ec->exp_iconify.type;
4394 }
4395
4396 E_API Eina_Bool e_client_is_iconified_by_client(E_Client *ec)
4397 {
4398    if (!ec) return EINA_FALSE;
4399
4400    if (ec->exp_iconify.type == E_ICONIFIED_TYPE_ICONIFY_BY_CLIENT)
4401      return EINA_TRUE;
4402
4403    if (ec->exp_iconify.type == E_ICONIFIED_TYPE_DESK_ICONIFY_BY_CLIENT)
4404      return EINA_TRUE;
4405
4406    if (ec->exp_iconify.type == E_ICONIFIED_TYPE_PARENT_ICONIFY_BY_CLIENT)
4407      return EINA_TRUE;
4408
4409    if (ec->exp_iconify.by_client)
4410      {
4411         ELOGF("POL", "CHECK. mismatch value. by_client:%d, type:%d", ec, ec->exp_iconify.by_client, ec->exp_iconify.type);
4412         return EINA_TRUE;
4413      }
4414
4415    return EINA_FALSE;
4416 }
4417
4418 ///////////////////////////////////////
4419
4420 EINTERN void
4421 e_client_urgent_set(E_Client *ec, Eina_Bool urgent)
4422 {
4423    E_OBJECT_CHECK(ec);
4424    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4425
4426    urgent = !!urgent;
4427    if (urgent == ec->urgent) return;
4428    _e_client_event_property(ec, E_CLIENT_PROPERTY_URGENCY);
4429    if (urgent && (!ec->focused) && (!ec->want_focus))
4430      {
4431         e_comp_object_signal_emit(ec->frame, "e,state,urgent", "e");
4432         ec->urgent = urgent;
4433      }
4434    else
4435      {
4436         e_comp_object_signal_emit(ec->frame, "e,state,not_urgent", "e");
4437         ec->urgent = 0;
4438      }
4439 }
4440
4441 ///////////////////////////////////////
4442
4443 EINTERN void
4444 e_client_stick(E_Client *ec)
4445 {
4446    E_OBJECT_CHECK(ec);
4447    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4448    if (ec->sticky) return;
4449
4450    // call the stick hook of a client
4451    wl_signal_emit_mutable(&PRI(ec)->events.stick, NULL);
4452
4453    // send the sticky property event of a client
4454    _e_client_event_property(ec, E_CLIENT_PROPERTY_STICKY);
4455 }
4456
4457 EINTERN void
4458 e_client_unstick(E_Client *ec)
4459 {
4460    E_OBJECT_CHECK(ec);
4461    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4462
4463    if (!ec->sticky) return;
4464
4465    // call the unstick hook of a client
4466    wl_signal_emit_mutable(&PRI(ec)->events.unstick, NULL);
4467
4468   // send the sticky property event of a client
4469    _e_client_event_property(ec, E_CLIENT_PROPERTY_STICKY);
4470 }
4471
4472 EINTERN void
4473 e_client_pinned_set(E_Client *ec, Eina_Bool set)
4474 {
4475    E_Layer layer;
4476
4477    EINA_SAFETY_ON_NULL_RETURN(ec);
4478    if (set)
4479      layer = E_LAYER_CLIENT_ABOVE;
4480    else
4481      layer = E_LAYER_CLIENT_NORMAL;
4482
4483    e_client_layer_set(ec, layer);
4484
4485    EC_CHANGED(ec);
4486 }
4487
4488 ///////////////////////////////////////
4489
4490 EINTERN Eina_Bool
4491 e_client_border_set(E_Client *ec, const char *name)
4492 {
4493    Eina_Stringshare *pborder;
4494
4495    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
4496    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, EINA_FALSE);
4497    if (!e_comp_object_frame_allowed(ec->frame)) return EINA_FALSE;
4498    if (ec->border.changed)
4499      CRI("CALLING WHEN border.changed SET!");
4500
4501    if (!e_util_strcmp(ec->border.name, name)) return EINA_TRUE;
4502    if (ec->mwm.borderless && name && strcmp(name, "borderless"))
4503      {
4504         CRI("border change attempted for MWM borderless client!");
4505      }
4506    pborder = ec->border.name;
4507    ec->border.name = eina_stringshare_add(name);
4508    if (e_comp_object_frame_theme_set(ec->frame, name))
4509      {
4510         eina_stringshare_del(pborder);
4511         return EINA_TRUE;
4512      }
4513    eina_stringshare_del(ec->border.name);
4514    ec->border.name = pborder;
4515    return EINA_FALSE;
4516 }
4517
4518 ///////////////////////////////////////
4519
4520 EINTERN void
4521 e_client_comp_hidden_set(E_Client *ec, Eina_Bool hidden)
4522 {
4523    E_OBJECT_CHECK(ec);
4524    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4525
4526    hidden = !!hidden;
4527    if (ec->comp_hidden == hidden) return;
4528    ec->comp_hidden = hidden;
4529    evas_object_smart_callback_call(ec->frame, "comp_hidden", NULL);
4530 }
4531
4532 ///////////////////////////////////////
4533
4534 EINTERN void
4535 e_client_act_move_keyboard(E_Client *ec)
4536 {
4537    EINA_SAFETY_ON_NULL_RETURN(ec);
4538
4539    if (!_e_client_move_begin(ec))
4540      return;
4541
4542    _e_client_action_init(ec);
4543    _e_client_action_move_timeout_add();
4544
4545    wl_signal_emit_mutable(&PRI(ec)->events.move_update, NULL);
4546    if (!_e_client_hook_call(E_CLIENT_HOOK_MOVE_UPDATE, ec)) return;
4547    evas_object_freeze_events_set(ec->frame, 1);
4548
4549    if (!action_handler_mouse)
4550      action_handler_mouse = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, _e_client_move_mouse_down, NULL);
4551 }
4552
4553 EINTERN void
4554 e_client_act_resize_keyboard(E_Client *ec)
4555 {
4556    EINA_SAFETY_ON_NULL_RETURN(ec);
4557
4558    ec->resize_mode = E_POINTER_RESIZE_TL;
4559    ec->keyboard_resizing = 1;
4560    if (!e_client_resize_begin(ec))
4561      {
4562         ec->keyboard_resizing = 0;
4563         return;
4564      }
4565
4566    _e_client_action_init(ec);
4567    _e_client_action_resize_timeout_add();
4568    evas_object_freeze_events_set(ec->frame, 1);
4569
4570    if (!action_handler_mouse)
4571      action_handler_mouse = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, _e_client_resize_mouse_down, NULL);
4572 }
4573
4574 EINTERN void
4575 e_client_act_move_begin(E_Client *ec, E_Binding_Event_Mouse_Button *ev)
4576 {
4577    E_OBJECT_CHECK(ec);
4578    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4579    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4580    if (ev)
4581      {
4582         char source[256];
4583
4584         snprintf(source, sizeof(source) - 1, "mouse,down,%i", ev->button);
4585         _e_client_moveinfo_gather(ec, source);
4586      }
4587    if (!_e_client_move_begin(ec))
4588      return;
4589
4590    _e_client_action_init(ec);
4591 }
4592
4593 E_API void
4594 e_client_act_move_end(E_Client *ec, E_Binding_Event_Mouse_Button *ev EINA_UNUSED)
4595 {
4596    E_OBJECT_CHECK(ec);
4597    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4598    if (!ec->moving) return;
4599    _e_client_move_end(ec);
4600    _e_client_action_finish();
4601 }
4602
4603 EINTERN void
4604 e_client_act_resize_begin(E_Client *ec, E_Binding_Event_Mouse_Button *ev, E_Pointer_Mode resize_mode)
4605 {
4606    E_OBJECT_CHECK(ec);
4607    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4608    if (ec->lock_user_size || ec->shaded || ec->shading) return;
4609    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4610    if (ev)
4611      {
4612         char source[256];
4613         snprintf(source, sizeof(source) - 1, "mouse,down,%i", ev->button);
4614         _e_client_moveinfo_gather(ec, source);
4615
4616         if (resize_mode != E_POINTER_RESIZE_NONE)
4617           {
4618              ec->resize_mode = resize_mode;
4619           }
4620         else
4621           {
4622              /* Use canvas.x, canvas.y of event.
4623               * Transformed coordinates has to be considered for accurate resize_mode
4624               * rather than absolute coordinates. */
4625              if ((ev->canvas.x > (ec->x + ec->w / 5)) &&
4626                  (ev->canvas.x < (ec->x + ec->w * 4 / 5)))
4627                {
4628                   if (ev->canvas.y < (ec->y + ec->h / 2)) ec->resize_mode = E_POINTER_RESIZE_T;
4629                   else ec->resize_mode = E_POINTER_RESIZE_B;
4630                }
4631              else if (ev->canvas.x < (ec->x + ec->w / 2))
4632                {
4633                   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;
4634                   else if (ev->canvas.y < (ec->y + ec->h / 2)) ec->resize_mode = E_POINTER_RESIZE_TL;
4635                   else ec->resize_mode = E_POINTER_RESIZE_BL;
4636                }
4637              else
4638                {
4639                   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;
4640                   else if (ev->canvas.y < (ec->y + ec->h / 2)) ec->resize_mode = E_POINTER_RESIZE_TR;
4641                   else ec->resize_mode = E_POINTER_RESIZE_BR;
4642                }
4643           }
4644      }
4645    if (!e_client_resize_begin(ec))
4646      return;
4647    _e_client_action_init(ec);
4648 }
4649
4650 EINTERN void
4651 e_client_act_resize_end(E_Client *ec, E_Binding_Event_Mouse_Button *ev EINA_UNUSED)
4652 {
4653    E_OBJECT_CHECK(ec);
4654    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4655    if (e_client_util_resizing_get(ec))
4656      {
4657         _e_client_resize_end(ec);
4658         ec->changes.reset_gravity = 1;
4659         if (!e_object_is_del(E_OBJECT(ec)))
4660           EC_CHANGED(ec);
4661      }
4662    _e_client_action_finish();
4663 }
4664
4665 EINTERN void
4666 e_client_act_menu_begin(E_Client *ec, E_Binding_Event_Mouse_Button *ev, int key)
4667 {
4668    E_OBJECT_CHECK(ec);
4669    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4670 }
4671
4672 EINTERN void
4673 e_client_act_close_begin(E_Client *ec)
4674 {
4675    E_OBJECT_CHECK(ec);
4676    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4677    if (ec->lock_close) return;
4678    if (ec->icccm.delete_request)
4679      {
4680         ec->delete_requested = 1;
4681         evas_object_smart_callback_call(ec->frame, "delete_request", NULL);
4682      }
4683    else if (e_config->kill_if_close_not_possible)
4684      {
4685         e_client_act_kill_begin(ec);
4686      }
4687 }
4688
4689 EINTERN void
4690 e_client_act_kill_begin(E_Client *ec)
4691 {
4692    E_OBJECT_CHECK(ec);
4693    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4694    if (ec->internal) return;
4695    if (ec->lock_close) return;
4696    if ((ec->netwm.pid > 1) && (e_config->kill_process))
4697      {
4698         kill(ec->netwm.pid, SIGINT);
4699         ec->kill_timer = ecore_timer_add(e_config->kill_timer_wait,
4700                                          _e_client_cb_kill_timer, ec);
4701      }
4702    else
4703      evas_object_smart_callback_call(ec->frame, "kill_request", NULL);
4704 }
4705
4706 ////////////////////////////////////////////
4707
4708 EINTERN void
4709 e_client_ping(E_Client *ec)
4710 {
4711    E_OBJECT_CHECK(ec);
4712    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4713
4714    if (!e_config->ping_clients) return;
4715
4716    EINA_SAFETY_ON_TRUE_RETURN(e_object_is_del(E_OBJECT(ec)));
4717
4718    ec->ping_ok = 0;
4719    evas_object_smart_callback_call(ec->frame, "ping", NULL);
4720    ec->ping = ecore_loop_time_get();
4721    if (ec->ping_poller) ecore_poller_del(ec->ping_poller);
4722    ec->ping_poller = ecore_poller_add(ECORE_POLLER_CORE,
4723                                       e_config->ping_clients_interval,
4724                                       _e_client_cb_ping_poller, ec);
4725 }
4726
4727 ////////////////////////////////////////////
4728 E_API void
4729 e_client_cursor_map_apply(E_Client *ec, int rotation, int x, int y)
4730 {
4731    // TODO: remove(deprecate) this e_client_cursor_map_apply.
4732 }
4733
4734 EINTERN void
4735 e_client_move_cancel(void)
4736 {
4737    if (!ecmove) return;
4738    if (ecmove->cur_mouse_action)
4739      {
4740         E_Client *ec;
4741
4742         ec = ecmove;
4743         e_object_ref(E_OBJECT(ec));
4744         if (ec->cur_mouse_action->func.end_mouse)
4745           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", NULL);
4746         else if (ec->cur_mouse_action->func.end)
4747           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
4748         e_object_unref(E_OBJECT(ec->cur_mouse_action));
4749         ec->cur_mouse_action = NULL;
4750         e_object_unref(E_OBJECT(ec));
4751      }
4752    else
4753      _e_client_move_end(ecmove);
4754 }
4755
4756 EINTERN void
4757 e_client_resize_cancel(void)
4758 {
4759    if (!ecresize) return;
4760    if (ecresize->cur_mouse_action)
4761      {
4762         E_Client *ec;
4763
4764         ec = ecresize;
4765         e_object_ref(E_OBJECT(ec));
4766         if (ec->cur_mouse_action->func.end_mouse)
4767           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", NULL);
4768         else if (ec->cur_mouse_action->func.end)
4769           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
4770         e_object_unref(E_OBJECT(ec->cur_mouse_action));
4771         ec->cur_mouse_action = NULL;
4772         e_object_unref(E_OBJECT(ec));
4773      }
4774    else
4775      _e_client_resize_end(ecresize);
4776 }
4777
4778 EINTERN Eina_Bool
4779 e_client_resize_begin(E_Client *ec)
4780 {
4781    if ((ec->shaded) || (ec->shading) ||
4782        (ec->fullscreen) || (ec->lock_user_size))
4783      goto error;
4784    if (!_e_client_action_input_win_new()) goto error;
4785    ecresize = ec;
4786    if (ec->manage_resize.enable_aspect_ratio)
4787      {
4788         ELOGF("RESIZE", "Set resize aspect ratio.. ratio(%dx%d)", ec, ec->w, ec->h);
4789         ec->manage_resize.aw = ec->w;
4790         ec->manage_resize.ah = ec->h - ec->manage_resize.header_h - ec->manage_resize.footer_h;
4791      }
4792
4793    wl_signal_emit_mutable(&PRI(ec)->events.move_begin, NULL);
4794    _e_client_hook_call(E_CLIENT_HOOK_RESIZE_BEGIN, ec);
4795    if (ec->transformed)
4796      _e_client_transform_resize_begin(ec);
4797    if (!e_client_util_resizing_get(ec))
4798      {
4799         if (ecresize == ec) ecresize = NULL;
4800         _e_client_action_input_win_del();
4801         return EINA_FALSE;
4802      }
4803    if (!ec->lock_user_stacking)
4804      {
4805         if (e_config->border_raise_on_mouse_action)
4806           e_client_raise(ec);
4807      }
4808
4809    if (e_comp->hwc)
4810      e_comp_client_override_add(ec);
4811
4812    return EINA_TRUE;
4813 error:
4814    ec->resize_mode = E_POINTER_RESIZE_NONE;
4815    return EINA_FALSE;
4816 }
4817
4818
4819 ////////////////////////////////////////////
4820
4821 EINTERN void
4822 e_client_frame_recalc(E_Client *ec)
4823 {
4824    EINA_SAFETY_ON_NULL_RETURN(ec);
4825    if (!ec->frame) return;
4826    evas_object_smart_callback_call(ec->frame, "frame_recalc", NULL);
4827 }
4828
4829 ////////////////////////////////////////////
4830
4831 EINTERN void
4832 e_client_signal_move_begin(E_Client *ec, const char *sig, const char *src EINA_UNUSED)
4833 {
4834    E_OBJECT_CHECK(ec);
4835    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4836
4837    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4838    _e_client_moveinfo_gather(ec, sig);
4839    if (!_e_client_move_begin(ec)) return;
4840 }
4841
4842 EINTERN void
4843 e_client_signal_move_end(E_Client *ec, const char *sig EINA_UNUSED, const char *src EINA_UNUSED)
4844 {
4845    E_OBJECT_CHECK(ec);
4846    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4847    if (!ec->moving) return;
4848    _e_client_move_end(ec);
4849 }
4850
4851 EINTERN void
4852 e_client_signal_resize_begin(E_Client *ec, const char *dir, const char *sig, const char *src EINA_UNUSED)
4853 {
4854    int resize_mode = E_POINTER_RESIZE_BR;
4855
4856    E_OBJECT_CHECK(ec);
4857    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4858
4859    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4860    if (!strcmp(dir, "tl"))
4861      {
4862         resize_mode = E_POINTER_RESIZE_TL;
4863      }
4864    else if (!strcmp(dir, "t"))
4865      {
4866         resize_mode = E_POINTER_RESIZE_T;
4867      }
4868    else if (!strcmp(dir, "tr"))
4869      {
4870         resize_mode = E_POINTER_RESIZE_TR;
4871      }
4872    else if (!strcmp(dir, "r"))
4873      {
4874         resize_mode = E_POINTER_RESIZE_R;
4875      }
4876    else if (!strcmp(dir, "br"))
4877      {
4878         resize_mode = E_POINTER_RESIZE_BR;
4879      }
4880    else if (!strcmp(dir, "b"))
4881      {
4882         resize_mode = E_POINTER_RESIZE_B;
4883      }
4884    else if (!strcmp(dir, "bl"))
4885      {
4886         resize_mode = E_POINTER_RESIZE_BL;
4887      }
4888    else if (!strcmp(dir, "l"))
4889      {
4890         resize_mode = E_POINTER_RESIZE_L;
4891      }
4892    ec->resize_mode = resize_mode;
4893    _e_client_moveinfo_gather(ec, sig);
4894    if (!e_client_resize_begin(ec))
4895      return;
4896 }
4897
4898 EINTERN void
4899 e_client_signal_resize_end(E_Client *ec, const char *dir EINA_UNUSED, const char *sig EINA_UNUSED, const char *src EINA_UNUSED)
4900 {
4901    E_OBJECT_CHECK(ec);
4902    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4903    if (!e_client_util_resizing_get(ec)) return;
4904    _e_client_resize_handle(ec);
4905    _e_client_resize_end(ec);
4906    ec->changes.reset_gravity = 1;
4907    EC_CHANGED(ec);
4908 }
4909
4910 ////////////////////////////////////////////
4911
4912 EINTERN void
4913 e_client_resize_limit(E_Client *ec, int *w, int *h)
4914 {
4915    double a;
4916    Eina_Bool inc_h;
4917
4918    E_OBJECT_CHECK(ec);
4919    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4920
4921    inc_h = (*h - ec->h > 0);
4922    if (ec->frame)
4923      e_comp_object_frame_wh_unadjust(ec->frame, *w, *h, w, h);
4924    if (*h < 1) *h = 1;
4925    if (*w < 1) *w = 1;
4926    if ((ec->icccm.base_w >= 0) &&
4927        (ec->icccm.base_h >= 0))
4928      {
4929         int tw, th;
4930
4931         tw = *w - ec->icccm.base_w;
4932         th = *h - ec->icccm.base_h;
4933         if (tw < 1) tw = 1;
4934         if (th < 1) th = 1;
4935         a = (double)(tw) / (double)(th);
4936         if ((ec->icccm.min_aspect != 0.0) &&
4937             (a < ec->icccm.min_aspect))
4938           {
4939              if (inc_h)
4940                tw = th * ec->icccm.min_aspect;
4941              else
4942                th = tw / ec->icccm.max_aspect;
4943              *w = tw + ec->icccm.base_w;
4944              *h = th + ec->icccm.base_h;
4945           }
4946         else if ((ec->icccm.max_aspect != 0.0) &&
4947                  (a > ec->icccm.max_aspect))
4948           {
4949              tw = th * ec->icccm.max_aspect;
4950              *w = tw + ec->icccm.base_w;
4951           }
4952      }
4953    else
4954      {
4955         a = (double)*w / (double)*h;
4956         if ((ec->icccm.min_aspect != 0.0) &&
4957             (a < ec->icccm.min_aspect))
4958           {
4959              if (inc_h)
4960                *w = *h * ec->icccm.min_aspect;
4961              else
4962                *h = *w / ec->icccm.min_aspect;
4963           }
4964         else if ((ec->icccm.max_aspect != 0.0) &&
4965                  (a > ec->icccm.max_aspect))
4966           *w = *h * ec->icccm.max_aspect;
4967      }
4968    if (ec->icccm.step_w > 0)
4969      {
4970         if (ec->icccm.base_w >= 0)
4971           *w = ec->icccm.base_w +
4972             (((*w - ec->icccm.base_w) / ec->icccm.step_w) *
4973              ec->icccm.step_w);
4974         else
4975           *w = ec->icccm.min_w +
4976             (((*w - ec->icccm.min_w) / ec->icccm.step_w) *
4977              ec->icccm.step_w);
4978      }
4979    if (ec->icccm.step_h > 0)
4980      {
4981         if (ec->icccm.base_h >= 0)
4982           *h = ec->icccm.base_h +
4983             (((*h - ec->icccm.base_h) / ec->icccm.step_h) *
4984              ec->icccm.step_h);
4985         else
4986           *h = ec->icccm.min_h +
4987             (((*h - ec->icccm.min_h) / ec->icccm.step_h) *
4988              ec->icccm.step_h);
4989      }
4990
4991    if (*h < 1) *h = 1;
4992    if (*w < 1) *w = 1;
4993
4994    if ((ec->icccm.max_w > 0) && (*w > ec->icccm.max_w)) *w = ec->icccm.max_w;
4995    else if (*w < ec->icccm.min_w)
4996      *w = ec->icccm.min_w;
4997    if ((ec->icccm.max_h > 0) && (*h > ec->icccm.max_h)) *h = ec->icccm.max_h;
4998    else if (*h < ec->icccm.min_h)
4999      *h = ec->icccm.min_h;
5000
5001    if (ec->frame)
5002      e_comp_object_frame_wh_adjust(ec->frame, *w, *h, w, h);
5003 }
5004
5005 ////////////////////////////////////////////
5006
5007
5008
5009 EINTERN E_Client *
5010 e_client_under_pointer_get(E_Desk *desk, E_Client *exclude)
5011 {
5012    int x, y;
5013
5014    /* We need to ensure that we can get the comp window for the
5015     * zone of either the given desk or the desk of the excluded
5016     * window, so return if neither is given */
5017    if (desk)
5018      e_input_device_pointer_xy_get(NULL, &x, &y);
5019    else if (exclude)
5020      e_input_device_pointer_xy_get(NULL, &x, &y);
5021    else
5022      return NULL;
5023
5024    if (!desk)
5025      {
5026         desk = exclude->desk;
5027         if (!desk)
5028           {
5029              if (exclude->zone)
5030                desk = e_desk_current_get(exclude->zone);
5031              else
5032                desk = e_desk_current_get(e_zone_current_get());
5033           }
5034      }
5035
5036    return desk ? _e_client_under_pointer_helper(desk, exclude, x, y) : NULL;
5037 }
5038
5039 E_API E_Client *e_client_under_position_get(E_Desk *desk, int x, int y, E_Client *exclude)
5040 {
5041    if (!desk) return NULL;
5042
5043    return _e_client_under_pointer_helper(desk, exclude, x, y);
5044 }
5045
5046 E_API E_Client *e_client_under_position_input_get(E_Desk *desk, int x, int y)
5047 {
5048    if (!desk) return NULL;
5049
5050    return _e_client_under_pointer_input_helper(desk, x, y);
5051 }
5052
5053 EINTERN E_Client *
5054 e_client_input_rect_under_pointer_get(E_Desk *desk, E_Client *exclude)
5055 {
5056    int x, y;
5057
5058    /* We need to ensure that we can get the comp window for the
5059     * zone of either the given desk or the desk of the excluded
5060     * window, so return if neither is given */
5061    if (desk)
5062      e_input_device_pointer_xy_get(NULL, &x, &y);
5063    else if (exclude)
5064      e_input_device_pointer_xy_get(NULL, &x, &y);
5065    else
5066      return NULL;
5067
5068    if (!desk)
5069      {
5070         desk = exclude->desk;
5071         if (!desk)
5072           {
5073              if (exclude->zone)
5074                desk = e_desk_current_get(exclude->zone);
5075              else
5076                desk = e_desk_current_get(e_zone_current_get());
5077           }
5078      }
5079
5080    return desk ? _e_client_input_rect_under_pointer_helper(desk, exclude, x, y) : NULL;
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 }