e_client: remove no more used function e_client_input_rect_under_pointer_get
[platform/upstream/enlightenment.git] / src / bin / e_client.c
1 #include "e.h"
2 #include "e_client_intern.h"
3
4 #define PRI(ec) ((E_Client_Private *)e_object_data_get(E_OBJECT(ec)))
5
6 #define API_ENTRY \
7    EINA_SAFETY_ON_NULL_RETURN(ec); \
8    E_Client_Private *priv = PRI(ec)
9
10 #define API_ENTRY_VAL(ret) \
11    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, ret); \
12    E_Client_Private *priv = PRI(ec)
13
14 typedef struct _E_Client_Private E_Client_Private;
15
16 struct _E_Client_Private
17 {
18    struct
19      {
20         struct wl_signal eval_pre_fetch;
21         struct wl_signal eval_fetch;
22         struct wl_signal eval_pre_post_fetch;
23         struct wl_signal eval_post_fetch;
24         struct wl_signal eval_pre_frame_assign;
25         struct wl_signal eval_post_frame_assign;
26         struct wl_signal eval_pre_new_client;
27         struct wl_signal eval_post_new_client;
28         struct wl_signal eval_visibility;
29         struct wl_signal eval_visibility_end;
30         struct wl_signal eval_end;
31
32         struct wl_signal move_begin;
33         struct wl_signal move_update;
34         struct wl_signal move_end;
35         struct wl_signal move_resize_begin;
36         struct wl_signal move_resize_update;
37         struct wl_signal move_resize_end;
38
39         struct wl_signal destroy;
40         struct wl_signal new_client;
41         struct wl_signal new_client_post;
42
43         struct wl_signal unredirect;
44         struct wl_signal redirect;
45
46         struct wl_signal aux_hint_change;
47         struct wl_signal window_role_change;
48         struct wl_signal transform_change;
49         struct wl_signal activate_done;
50
51         struct wl_signal mouse_in;
52         struct wl_signal mouse_out;
53         struct wl_signal mouse_down;
54
55         struct wl_signal focus_set;
56         struct wl_signal focus_unset;
57         struct wl_signal focus_defer_set;
58         struct wl_signal focus_latest_set;
59
60         struct wl_signal iconify;
61         struct wl_signal uniconify;
62         struct wl_signal maximize;
63         struct wl_signal unmaximize;
64         struct wl_signal fullscreen_pre;
65         struct wl_signal fullscreen;
66         struct wl_signal unfullscreen;
67
68         struct wl_signal move;
69
70         struct wl_signal 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    if (e_comp_wl->drag_client == client) return EINA_TRUE;
1739
1740    return EINA_FALSE;
1741 }
1742
1743 static E_Client *
1744 _e_client_under_pointer_helper(E_Desk *desk, E_Client *exclude, int x, int y)
1745 {
1746    E_Client *ec = NULL, *cec;
1747
1748    E_CLIENT_REVERSE_FOREACH(cec)
1749      {
1750         if (_e_client_under_pointer_helper_ignore_client(desk, cec)) continue;
1751         if ((exclude) && (cec == exclude)) continue;
1752         if (!E_INSIDE(x, y, cec->x, cec->y, cec->w, cec->h))
1753           continue;
1754         /* If the layer is higher, the position of the window is higher
1755          * (always on top vs always below) */
1756         if (!ec || (cec->layer > ec->layer))
1757           ec = cec;
1758      }
1759    return ec;
1760 }
1761
1762 static E_Client *
1763 _e_client_under_pointer_input_helper(E_Desk *desk, int x, int y)
1764 {
1765    E_Client *ec = NULL, *cec;
1766
1767    E_CLIENT_REVERSE_FOREACH(cec)
1768      {
1769         if (_e_client_under_pointer_helper_ignore_client(desk, cec)) continue;
1770
1771         Eina_List *list = NULL;
1772         Eina_Rectangle *rect;
1773         Eina_Bool inside = EINA_FALSE;
1774         e_comp_object_input_rect_get(cec->frame, &list);
1775         if (list)
1776           {
1777              EINA_LIST_FREE(list, rect)
1778                {
1779                   if (E_INSIDE(x, y, rect->x, rect->y, rect->w, rect->h))
1780                     inside = EINA_TRUE;
1781                }
1782           }
1783         else if (E_INSIDE(x, y, cec->x, cec->y, cec->w, cec->h))
1784           {
1785              inside = EINA_TRUE;
1786           }
1787
1788         if (!inside) continue;
1789         /* If the layer is higher, the position of the window is higher
1790          * (always on top vs always below) */
1791         if (!ec || (cec->layer > ec->layer))
1792           ec = cec;
1793      }
1794
1795    return ec;
1796 }
1797
1798 ////////////////////////////////////////////////
1799
1800 static void
1801 _e_client_zones_layout_calc(E_Client *ec, int *zx, int *zy, int *zw, int *zh)
1802 {
1803    int x, y, w, h;
1804    E_Zone *zone_above, *zone_below, *zone_left, *zone_right;
1805    E_Zone *zone;
1806
1807    zone = e_comp_zone_find_by_ec(ec);
1808    if (!zone) return;
1809    x = zone->x;
1810    y = zone->y;
1811    w = zone->w;
1812    h = zone->h;
1813
1814    if (eina_list_count(e_comp->zones) == 1)
1815      {
1816         if (zx) *zx = x;
1817         if (zy) *zy = y;
1818         if (zw) *zw = w;
1819         if (zh) *zh = h;
1820         return;
1821      }
1822
1823    zone_left = e_comp_zone_xy_get((x - w + 5), y);
1824    zone_right = e_comp_zone_xy_get((x + w + 5), y);
1825    zone_above = e_comp_zone_xy_get(x, (y - h + 5));
1826    zone_below = e_comp_zone_xy_get(x, (y + h + 5));
1827
1828    if (!(zone_above) && (y))
1829      zone_above = e_comp_zone_xy_get(x, (h - 5));
1830
1831    if (!(zone_left) && (x))
1832      zone_left = e_comp_zone_xy_get((x - 5), y);
1833
1834    if (zone_right)
1835      w = zone_right->x + zone_right->w;
1836
1837    if (zone_left)
1838      w = zone->x + zone->w;
1839
1840    if (zone_below)
1841      h = zone_below->y + zone_below->h;
1842
1843    if (zone_above)
1844      h = zone->y + zone->h;
1845
1846    if ((zone_left) && (zone_right))
1847      w = zone->w + zone_right->x;
1848
1849    if ((zone_above) && (zone_below))
1850      h = zone->h + zone_below->y;
1851
1852    if (x) x -= zone->w;
1853    if (y) y -= zone->h;
1854
1855    if (zx) *zx = x > 0 ? x : 0;
1856    if (zy) *zy = y > 0 ? y : 0;
1857    if (zw) *zw = w;
1858    if (zh) *zh = h;
1859 }
1860
1861 static void
1862 _e_client_stay_within_canvas(E_Client *ec, int x, int y, int *new_x, int *new_y)
1863 {
1864    int new_x_max, new_y_max;
1865    int zw, zh;
1866    Eina_Bool lw, lh;
1867    E_Zone *zone;
1868
1869    zone = e_comp_zone_find_by_ec(ec);
1870    if (!zone)
1871      {
1872         if (new_x) *new_x = x;
1873         if (new_y) *new_y = y;
1874         return;
1875      }
1876
1877    _e_client_zones_layout_calc(ec, NULL, NULL, &zw, &zh);
1878
1879    new_x_max = zw - ec->w;
1880    new_y_max = zh - ec->h;
1881    lw = ec->w > zw ? EINA_TRUE : EINA_FALSE;
1882    lh = ec->h > zh ? EINA_TRUE : EINA_FALSE;
1883
1884    if (lw)
1885      {
1886         if (x <= new_x_max)
1887           *new_x = new_x_max;
1888         else if (x >= 0)
1889           *new_x = 0;
1890      }
1891    else
1892      {
1893         if (x >= new_x_max)
1894           *new_x = new_x_max;
1895         else if (x <= 0)
1896           *new_x = 0;
1897      }
1898
1899    if (lh)
1900      {
1901         if (y <= new_y_max)
1902           *new_y = new_y_max;
1903         else if (y >= 0)
1904           *new_y = 0;
1905      }
1906    else
1907      {
1908         if (y >= new_y_max)
1909           *new_y = new_y_max;
1910         else if (y <= 0)
1911           *new_y = 0;
1912      }
1913 }
1914
1915 static void
1916 _e_client_stay_within_canvas_margin(E_Client *ec, int x, int y, int *new_x, int *new_y)
1917 {
1918    int new_x_max, new_y_max, new_x_min, new_y_min;
1919    int margin_w, margin_h;
1920    int zw, zh;
1921    int cw, ch;
1922    E_Zone *zone;
1923
1924    zone = e_comp_zone_find_by_ec(ec);
1925    if (!zone)
1926      {
1927         if (new_x) *new_x = x;
1928         if (new_y) *new_y = y;
1929         return;
1930      }
1931
1932    cw = ec->w;
1933    ch = ec->h;
1934
1935    _e_client_zones_layout_calc(ec, NULL, NULL, &zw, &zh);
1936
1937    margin_w = zw/3;
1938    margin_h = zh/10;
1939
1940    new_x_min = (margin_w > cw) ? 0 : -(cw - margin_w);
1941    new_x_max = (margin_w > cw) ? (zw - cw) : (zw - margin_w);
1942    new_y_min = (margin_h > ch) ? 0 : -(ch - margin_h);
1943    new_y_max = (margin_h > ch) ? (zh - ch) : (zh - margin_h);
1944
1945    if (x >= new_x_max)
1946      *new_x = new_x_max;
1947    else if (x <= new_x_min)
1948      *new_x = new_x_min;
1949
1950    if (y >= new_y_max)
1951      *new_y = new_y_max;
1952    else if (y <= new_y_min)
1953      *new_y = new_y_min;
1954
1955 }
1956
1957 ////////////////////////////////////////////////
1958
1959 static void
1960 _e_client_transform_core_activate_set(E_Client *ec, Eina_Bool set)
1961 {
1962    if (ec->transform_core.activate == set) return;
1963
1964    ec->transform_core.activate = set;
1965
1966    if (set)
1967      {
1968         if (ec->transform_core.result.enable)
1969           e_client_map_enable_set(ec, EINA_TRUE);
1970      }
1971    else
1972      {
1973         e_client_map_enable_set(ec, EINA_FALSE);
1974      }
1975 }
1976
1977 static void
1978 _e_client_cb_evas_hide(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
1979 {
1980    E_Client *ec = data;
1981
1982    if (stopping) return; //ignore all of this if we're shutting down!
1983    if (e_object_is_del(data)) return; //client is about to die
1984    if (ec->cur_mouse_action)
1985      {
1986         if (ec->cur_mouse_action->func.end_mouse)
1987           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", NULL);
1988         else if (ec->cur_mouse_action->func.end)
1989           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
1990         E_FREE_FUNC(ec->cur_mouse_action, e_object_unref);
1991      }
1992    if (action_client == ec) _e_client_action_finish();
1993
1994    ec->want_focus = ec->take_focus = 0;
1995
1996    _e_client_transform_core_activate_set(ec, EINA_FALSE);
1997
1998    if (ec->new_client) return;
1999    _e_client_event_hide(ec);
2000
2001    EC_CHANGED(ec);
2002 }
2003
2004 static void
2005 _e_client_cb_evas_shade_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
2006 {
2007    E_Client *ec = data;
2008
2009    if (e_object_is_del(data)) return;
2010
2011    ec->shading = 0;
2012    ec->shaded = !(ec->shaded);
2013    ec->changes.shaded = 1;
2014    ec->changes.shading = 1;
2015    e_client_comp_hidden_set(ec, ec->shaded);
2016 }
2017
2018 static void
2019 _e_client_cb_evas_move(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
2020 {
2021    E_Client *ec = data;
2022    E_Map *map;
2023    Evas_Coord x, y;
2024
2025    if (e_object_is_del(data)) return;
2026
2027    ec->pre_res_change.valid = 0;
2028
2029    _e_client_event_simple(ec, E_EVENT_CLIENT_MOVE);
2030
2031    evas_object_geometry_get(ec->frame, &x, &y, NULL, NULL);
2032    if ((e_config->transient.move) && (ec->transients))
2033      {
2034         Eina_List *list = eina_list_clone(ec->transients);
2035         E_Client *child;
2036
2037         EINA_LIST_FREE(list, child)
2038           {
2039              if (child->vkbd.vkbd) continue;
2040
2041              evas_object_move(child->frame,
2042                               child->x + x - ec->pre_cb.x,
2043                               child->y + y - ec->pre_cb.y);
2044           }
2045      }
2046    if (ec->moving || (ecmove == ec))
2047      {
2048         wl_signal_emit_mutable(&PRI(ec)->events.move_resize_update, NULL);
2049         _e_client_hook_call(E_CLIENT_HOOK_MOVE_UPDATE, ec);
2050      }
2051
2052    if ((!ec->moving) && (ec->transformed))
2053      {
2054         map = e_client_map_get(ec);
2055         _e_client_transform_geometry_save(ec, map);
2056         e_map_free(map);
2057      }
2058
2059    ec->pre_cb.x = x; ec->pre_cb.y = y;
2060
2061    wl_signal_emit_mutable(&PRI(ec)->events.move, NULL);
2062
2063    e_comp_visibility_calculation_set(EINA_TRUE);
2064 }
2065
2066 static void
2067 _e_client_cb_evas_resize(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
2068 {
2069    E_Client *ec = data;
2070    Evas_Coord x, y, w, h;
2071
2072    if (e_object_is_del(data)) return;
2073
2074    ec->pre_res_change.valid = 0;
2075
2076    _e_client_event_simple(ec, E_EVENT_CLIENT_RESIZE);
2077
2078    evas_object_geometry_get(ec->frame, &x, &y, &w, &h);
2079    if ((e_config->transient.resize) && (ec->transients))
2080      {
2081         Eina_List *list = eina_list_clone(ec->transients);
2082         E_Client *child;
2083
2084         EINA_LIST_FREE(list, child)
2085           {
2086              Evas_Coord nx, ny, nw, nh;
2087
2088              if ((ec->pre_cb.w > 0) && (ec->pre_cb.h > 0))
2089                {
2090                   nx = x + (((child->x - x) * w) / ec->pre_cb.w);
2091                   ny = y + (((child->y - y) * h) / ec->pre_cb.h);
2092                   nw = (child->w * w) / ec->pre_cb.w;
2093                   nh = (child->h * h) / ec->pre_cb.h;
2094                   nx += ((nw - child->w) / 2);
2095                   ny += ((nh - child->h) / 2);
2096                   evas_object_move(child->frame, nx, ny);
2097                }
2098           }
2099      }
2100
2101    if (e_client_util_resizing_get(ec) || (ecresize == ec))
2102      {
2103          wl_signal_emit_mutable(&PRI(ec)->events.move_resize_update, NULL);
2104         _e_client_hook_call(E_CLIENT_HOOK_RESIZE_UPDATE, ec);
2105      }
2106    ec->pre_cb.w = w; ec->pre_cb.h = h;
2107
2108    e_client_transform_core_update(ec);
2109    e_comp_visibility_calculation_set(EINA_TRUE);
2110 }
2111
2112 static void
2113 _e_client_cb_evas_show(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
2114 {
2115    E_Client *ec = data;
2116
2117    if (e_object_is_del(data)) return;
2118
2119    _e_client_transform_core_activate_set(ec, EINA_TRUE);
2120
2121    _e_client_event_show(ec);
2122    EC_CHANGED(ec);
2123 }
2124
2125 static void
2126 _e_client_cb_evas_restack(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
2127 {
2128    E_Client *ec = data;
2129    E_Comp_Wl_Client_Data *child_cdata = NULL;
2130
2131    if (e_object_is_del(data)) return;
2132    if (ec->layer_block) return;
2133    if (ec->layer_pending) return;
2134    if (e_config->transient.raise && ec->transients)
2135      {
2136         Eina_List *list = eina_list_clone(ec->transients);
2137         E_Client *child, *below = NULL, *above = NULL;
2138         E_Transient transient_policy;
2139
2140         E_LIST_REVERSE_FREE(list, child)
2141           {
2142              child_cdata = e_client_cdata_get(child);
2143              if (child_cdata && !child_cdata->mapped)
2144                {
2145                   ELOGF("COMP", "STACK CHANGE CHILD. BUT not mapped. skip. child(ec:%p, win:0x%08zx)", ec, child, e_client_util_win_get(child));
2146                   continue;
2147                }
2148
2149              /* Don't stack iconic transients. If the user wants these shown,
2150               * that's another option.
2151               */
2152              if (child->iconic && e_client_is_iconified_by_client(child)) continue;
2153
2154              transient_policy = e_client_transient_policy_get(child);
2155              if (transient_policy == E_TRANSIENT_ABOVE)
2156                {
2157                   if (below)
2158                     e_client_stack_below(child, below);
2159                   else
2160                     e_client_stack_above(child, ec);
2161                   below = child;
2162                }
2163              else if (transient_policy == E_TRANSIENT_BELOW)
2164                {
2165                   if (above)
2166                     e_client_stack_below(child, above);
2167                   else
2168                     e_client_stack_below(child, ec);
2169                   above = child;
2170                }
2171
2172           }
2173      }
2174    if (ec->unredirected_single) return;
2175    _e_client_event_simple(ec, E_EVENT_CLIENT_STACK);
2176
2177    e_comp_visibility_calculation_set(EINA_TRUE);
2178 }
2179
2180 ////////////////////////////////////////////////
2181 static void
2182 _e_client_aux_hint_eval(E_Client *ec)
2183 {
2184    if (!ec) return;
2185
2186    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
2187    Eina_List *l, *ll;
2188    E_Comp_Wl_Aux_Hint *hint;
2189
2190    if (cdata && cdata->aux_hint.changed)
2191      {
2192         wl_signal_emit_mutable(&PRI(ec)->events.aux_hint_change, NULL);
2193         _e_client_hook_call(E_CLIENT_HOOK_AUX_HINT_CHANGE, ec);
2194
2195         EINA_LIST_FOREACH_SAFE(cdata->aux_hint.hints, l, ll, hint)
2196           {
2197              hint->changed = EINA_FALSE;
2198              if (hint->deleted)
2199                {
2200                   ELOGF("COMP", "AUX_HINT |Del [%d:%s:%s]", ec, hint->id, hint->hint, hint->val);
2201                   if (hint->hint) eina_stringshare_del(hint->hint);
2202                   if (hint->val) eina_stringshare_del(hint->val);
2203                   cdata->aux_hint.hints = eina_list_remove_list(cdata->aux_hint.hints, l);
2204                   E_FREE(hint);
2205                }
2206           }
2207         cdata->aux_hint.changed = 0;
2208      }
2209 }
2210
2211 static void
2212 _e_client_eval(E_Client *ec)
2213 {
2214    int send_event = 1;
2215    unsigned int prop = 0;
2216    int tx, ty;
2217
2218    if (e_object_is_del(E_OBJECT(ec)))
2219      {
2220         CRI("_e_client_eval(%p) with deleted border! - %d\n", ec, ec->new_client);
2221         ec->changed = 0;
2222         return;
2223      }
2224
2225    TRACE_DS_BEGIN(CLIENT:EVAL);
2226
2227    wl_signal_emit_mutable(&PRI(ec)->events.eval_pre_new_client, NULL);
2228    if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_PRE_NEW_CLIENT, ec))
2229      {
2230         TRACE_DS_END();
2231         return;
2232      }
2233
2234    if ((ec->new_client) && (!e_client_util_ignored_get(ec)))
2235      {
2236         wl_signal_emit_mutable(&PRI(ec)->events.eval_post_new_client, NULL);
2237         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_POST_NEW_CLIENT, ec))
2238           {
2239              TRACE_DS_END();
2240              return;
2241           }
2242      }
2243
2244    /* effect changes to the window border itself */
2245    if ((ec->changes.shading))
2246      {
2247         /*  show at start of unshade (but don't hide until end of shade) */
2248         ec->changes.shading = 0;
2249         send_event = 0;
2250      }
2251    if (ec->changes.shaded) send_event = 0;
2252    if ((ec->changes.shaded) && (ec->changes.pos) && (ec->changes.size))
2253      {
2254         ec->changes.shaded = 0;
2255      }
2256    else if ((ec->changes.shaded) && (ec->changes.pos))
2257      {
2258         ec->changes.size = 1;
2259         ec->changes.shaded = 0;
2260      }
2261    else if ((ec->changes.shaded) && (ec->changes.size))
2262      {
2263         ec->changes.shaded = 0;
2264      }
2265    else if (ec->changes.shaded)
2266      {
2267         ec->changes.shaded = 0;
2268      }
2269
2270    if (ec->changes.size)
2271      {
2272         ec->changes.size = 0;
2273         if ((!ec->shaded) && (!ec->shading))
2274           evas_object_resize(ec->frame, ec->w, ec->h);
2275
2276         prop |= E_CLIENT_PROPERTY_SIZE;
2277      }
2278    if (ec->changes.pos)
2279      {
2280         ec->changes.tz_position = 0;
2281         ec->changes.pos = 0;
2282         evas_object_move(ec->frame, ec->x, ec->y);
2283         prop |= E_CLIENT_PROPERTY_POS;
2284      }
2285
2286    if (ec->changes.reset_gravity)
2287      {
2288         ec->changes.reset_gravity = 0;
2289         prop |= E_CLIENT_PROPERTY_GRAVITY;
2290      }
2291
2292    if (ec->changes.title)
2293      {
2294         ec->changes.title = 0;
2295         prop |= E_CLIENT_PROPERTY_TITLE;
2296      }
2297
2298    if ((ec->changes.visible) && (ec->visible) && (ec->new_client) && (!ec->iconic))
2299      {
2300         int x, y;
2301
2302         e_input_device_pointer_xy_get(NULL, &x, &y);
2303         if ((!ec->placed) && (!ec->re_manage) &&
2304             (e_config->window_placement_policy == E_WINDOW_PLACEMENT_MANUAL) &&
2305             (!((ec->icccm.transient_for != 0) ||
2306                (ec->dialog))) &&
2307             (!ecmove) && (!ecresize))
2308           {
2309              /* Set this window into moving state */
2310
2311              ec->cur_mouse_action = e_action_find("window_move");
2312              if (ec->cur_mouse_action)
2313                {
2314                   if ((!ec->cur_mouse_action->func.end_mouse) &&
2315                       (!ec->cur_mouse_action->func.end))
2316                     ec->cur_mouse_action = NULL;
2317                   if (ec->cur_mouse_action)
2318                     {
2319                        int t;
2320                        tx = x - (ec->w >> 1);
2321                        e_comp_object_frame_geometry_get(ec->frame, NULL, NULL, &t, NULL);
2322                        ty = y - (t >> 1);
2323                        e_client_pos_set(ec, tx, ty);
2324                        EC_CHANGED(ec);
2325                        ec->changes.pos = 1;
2326                     }
2327                }
2328           }
2329
2330         evas_object_show(ec->frame);
2331         if (evas_object_visible_get(ec->frame))
2332           {
2333              ec->changes.visible = 0;
2334              _e_client_event_show(ec);
2335           }
2336      }
2337    else if ((ec->changes.visible) && (ec->new_client))
2338      {
2339         ec->changes.visible = 0;
2340         if (!ec->iconic)
2341           _e_client_event_hide(ec);
2342      }
2343
2344    if (ec->changes.icon)
2345      {
2346         ec->changes.icon = 0;
2347      }
2348
2349    if (ec->new_client)
2350      e_comp->new_clients--;
2351    ec->new_client = 0;
2352    ec->changed = ec->changes.pos || ec->changes.size ||
2353                  ec->changes.stack || ec->changes.prop || ec->changes.border ||
2354                  ec->changes.reset_gravity || ec->changes.shading || ec->changes.shaded ||
2355                  ec->changes.shape || ec->changes.shape_input || ec->changes.icon ||
2356                  ec->changes.internal_state ||
2357                  ec->changes.need_maximize || ec->changes.need_unmaximize;
2358    ec->changes.stack = 0;
2359
2360    if (ec->changes.need_maximize)
2361      {
2362         E_Maximize max = ec->maximized;
2363         ec->maximized = E_MAXIMIZE_NONE;
2364         e_client_maximize(ec, max);
2365         ec->changes.need_maximize = 0;
2366      }
2367    else if (ec->changes.need_unmaximize)
2368      {
2369         e_client_unmaximize(ec, ec->maximized);
2370         ec->changes.need_unmaximize = 0;
2371      }
2372
2373    if (ec->need_fullscreen)
2374      {
2375         e_client_fullscreen(ec, e_config->fullscreen_policy);
2376         ec->need_fullscreen = 0;
2377      }
2378
2379    if (ec->changes.accepts_focus)
2380      {
2381         if ((!ec->icccm.accepts_focus) && (!ec->icccm.take_focus))
2382           {
2383              if (!ec->focused)
2384                ec->changes.accepts_focus = 0;
2385           }
2386      }
2387
2388    if (send_event && prop)
2389      {
2390         _e_client_event_property(ec, prop);
2391      }
2392
2393    _e_client_aux_hint_eval(ec);
2394
2395    e_client_transform_core_update(ec);
2396
2397    wl_signal_emit_mutable(&PRI(ec)->events.eval_end, NULL);
2398    _e_client_hook_call(E_CLIENT_HOOK_EVAL_END, ec);
2399
2400    TRACE_DS_END();
2401 }
2402
2403 EINTERN void
2404 e_client_frame_update(E_Client *ec)
2405 {
2406    const char *bordername;
2407
2408    EINA_SAFETY_ON_NULL_RETURN(ec);
2409    if (e_object_is_del(E_OBJECT(ec))) return;
2410
2411    ec->border.changed = 0;
2412    if (!e_comp_object_frame_allowed(ec->frame)) return;
2413    if (ec->fullscreen || ec->borderless)
2414      bordername = "borderless";
2415    else if (ec->bordername)
2416      bordername = ec->bordername;
2417    else if (ec->mwm.borderless)
2418      bordername = "borderless";
2419    else if (((ec->icccm.transient_for != 0) || (ec->dialog)) &&
2420             (ec->icccm.min_w == ec->icccm.max_w) &&
2421             (ec->icccm.min_h == ec->icccm.max_h))
2422      bordername = "noresize_dialog";
2423    else if ((ec->icccm.min_w == ec->icccm.max_w) &&
2424             (ec->icccm.min_h == ec->icccm.max_h))
2425      bordername = "noresize";
2426    else if (ec->shaped)
2427      bordername = "shaped";
2428    else if (ec->urgent)
2429      bordername = "urgent";
2430    else if (ec->netwm.state.modal)
2431      bordername = "modal";
2432    else if ((ec->netwm.state.skip_taskbar) ||
2433             (ec->netwm.state.skip_pager))
2434      bordername = "skipped";
2435   /*
2436    else if ((ec->internal) && (ec->icccm.class) &&
2437             (!strncmp(ec->icccm.class, "e_fwin", 6)))
2438      bordername = "internal_fileman";
2439   */
2440    else
2441      bordername = e_config->theme_default_border_style;
2442    if (!bordername) bordername = "default";
2443
2444    e_client_border_set(ec, bordername);
2445 }
2446
2447 static Eina_Bool
2448 _e_client_type_match(E_Client *ec, E_Config_Client_Type *m)
2449 {
2450    if (!ec || !m) return EINA_FALSE;
2451    if (e_object_is_del(E_OBJECT(ec))) return EINA_FALSE;
2452
2453    if ((int)ec->netwm.type != m->window_type)
2454      return EINA_FALSE;
2455
2456 #if defined(__cplusplus) || defined(c_plusplus)
2457    if (m->clas)
2458      {
2459         if (!ec->icccm.cpp_class)
2460           return EINA_FALSE;
2461
2462         if (!e_util_glob_match(ec->icccm.cpp_class, m->clas))
2463           return EINA_FALSE;
2464      }
2465 #else
2466    if (m->clas)
2467      {
2468         if (!ec->icccm.class)
2469           return EINA_FALSE;
2470
2471         if (!e_util_glob_match(ec->icccm.class, m->clas))
2472           return EINA_FALSE;
2473      }
2474 #endif
2475
2476    if (m->name)
2477      {
2478         if (ec->icccm.name && e_util_glob_match(ec->icccm.name, m->name))
2479           return EINA_TRUE;
2480
2481         if (ec->icccm.title && e_util_glob_match(ec->icccm.title, m->name))
2482           return EINA_TRUE;
2483
2484         if (ec->netwm.name && e_util_glob_match(ec->netwm.name, m->name))
2485           return EINA_TRUE;
2486      }
2487
2488    return EINA_FALSE;
2489 }
2490
2491 EINTERN int
2492 e_client_type_update(E_Client *ec)
2493 {
2494    E_Config_Client_Type *m;
2495    Eina_List *l;
2496    int type = 0;
2497
2498    if (!e_config->client_types) return 0;
2499
2500    EINA_LIST_FOREACH(e_config->client_types, l, m)
2501      {
2502         if (!_e_client_type_match(ec, m)) continue;
2503         else
2504           {
2505              type = m->client_type;
2506              break;
2507           }
2508      }
2509
2510    if (ec->client_type != type)
2511      {
2512         ec->client_type = type;
2513         _e_client_event_property(ec, E_CLIENT_PROPERTY_CLIENT_TYPE);
2514      }
2515
2516    return ec->client_type;
2517 }
2518
2519 static void
2520 _e_client_transform_sub_apply(E_Client *ec, E_Client *epc, double zoom)
2521 {
2522    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
2523    E_Client *subc;
2524    Eina_List *l;
2525    int px = 0, py = 0;
2526    int ox = 0, oy = 0, ow, oh;
2527    int mx, my, mw, mh;
2528    E_Map *map;
2529
2530    EINA_SAFETY_ON_FALSE_RETURN(e_comp_wl_subsurface_check(ec));
2531
2532    e_comp_wl_subsurface_position_get(ec, &ox, &oy);
2533    ow = cdata->width_from_viewport;
2534    oh = cdata->height_from_viewport;
2535
2536    map = e_client_map_get(epc);
2537    e_map_point_coord_get(map, 0, &px, &py, 0);
2538    e_map_free(map);
2539
2540    mx = ox * zoom + px;
2541    my = oy * zoom + py;
2542    mw = ow * zoom;
2543    mh = oh * zoom;
2544
2545    map = e_map_new_with_direct_render(ec->transform_core.direct_render);
2546    e_map_util_points_populate_from_geometry(map, mx, my, mw, mh, 0);
2547    e_map_util_object_move_sync_set(map, EINA_TRUE);
2548    e_client_map_set(ec, map);
2549    e_client_map_enable_set(ec, EINA_TRUE);
2550
2551    EINA_LIST_FOREACH(cdata->sub.list, l, subc)
2552      _e_client_transform_sub_apply(subc, ec, zoom);
2553    EINA_LIST_REVERSE_FOREACH(cdata->sub.below_list, l, subc)
2554      _e_client_transform_sub_apply(subc, ec, zoom);
2555
2556    e_map_free(map);
2557 }
2558
2559 static void
2560 _e_client_transient_for_group_make(E_Client *ec, Eina_List **list)
2561 {
2562    E_Client *child;
2563    Eina_List *l;
2564
2565    if (!ec) return;
2566    if (!e_config->transient.raise) return;
2567
2568    EINA_LIST_FOREACH(ec->transients, l, child)
2569      {
2570         if (!child) continue;
2571         if (child->iconic) continue;
2572         if (e_client_transient_policy_get(child) == E_TRANSIENT_ABOVE)
2573           {
2574              *list = eina_list_prepend(*list, child);
2575              _e_client_transient_for_group_make(child, list);
2576           }
2577      }
2578 }
2579
2580 EINTERN E_Client *
2581 e_client_transient_child_top_get(E_Client *ec, Eina_Bool consider_focus)
2582 {
2583    E_Client *top_ec = NULL;
2584    Eina_List *transient_list = NULL;
2585
2586    _e_client_transient_for_group_make(ec, &transient_list);
2587
2588    if (transient_list)
2589      {
2590         Eina_List *l = NULL;
2591         E_Client *temp_ec = NULL;
2592         E_Client *temp_ec2 = NULL;
2593
2594         E_CLIENT_REVERSE_FOREACH(temp_ec)
2595           {
2596              if (top_ec) break;
2597              if (temp_ec == ec)
2598                {
2599                   top_ec = ec;
2600                   break;
2601                }
2602
2603              EINA_LIST_FOREACH(transient_list, l, temp_ec2)
2604                {
2605                   if (temp_ec == temp_ec2)
2606                     {
2607                        if (consider_focus)
2608                          {
2609                             if ((temp_ec2->icccm.accepts_focus) ||
2610                                 (temp_ec2->icccm.take_focus))
2611                               {
2612                                  top_ec = temp_ec2;
2613                               }
2614                          }
2615                        else
2616                          {
2617                             top_ec = temp_ec2;
2618                          }
2619                        break;
2620                     }
2621                }
2622           }
2623         eina_list_free(transient_list);
2624      }
2625    return top_ec;
2626 }
2627
2628 #ifdef EC_IS_NOT_VISIBLE
2629 # undef EC_IS_NOT_VISIBLE
2630 #endif
2631 #define EC_IS_NOT_VISIBLE if (ec->visibility.obscured != E_VISIBILITY_UNOBSCURED)
2632
2633 EINTERN Eina_Bool
2634 e_client_visibility_touched_check(E_Client *ec)
2635 {
2636    int tx, ty;
2637
2638    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
2639
2640    tx = wl_fixed_to_int(e_comp->wl_comp_data->ptr.x);
2641    ty = wl_fixed_to_int(e_comp->wl_comp_data->ptr.y);
2642
2643    return _e_client_position_inside_input_rect(ec, tx, ty);
2644 }
2645
2646 EINTERN void
2647 e_client_visibility_change_notify(E_Client *ec)
2648 {
2649    EINA_SAFETY_ON_NULL_RETURN(ec);
2650
2651    if (ec->visibility.changed)
2652      _e_client_event_simple(ec, E_EVENT_CLIENT_VISIBILITY_CHANGE);
2653
2654    wl_signal_emit_mutable(&PRI(ec)->events.eval_visibility, NULL);
2655    _e_client_hook_call(E_CLIENT_HOOK_EVAL_VISIBILITY, ec);
2656 }
2657
2658 EINTERN void
2659 e_client_visibility_end_notify(void)
2660 {
2661    // FIXME: This hook means that the visiblitiy calculation of a zone is done
2662    //        at this idle handler.This is a hook for a zone, not for a client.
2663    //        Therefore, this hook may be defined as a zone hook,
2664    //        ex) E_ZONE_HOOK_EVAL_VISIBILITY_END or E_ZONE_HOOK_EVAL_VISIBILITY_DONE.
2665    _e_client_hook_call(E_CLIENT_HOOK_EVAL_VISIBILITY_END, NULL);
2666 }
2667
2668 static Eina_Bool
2669 _e_client_transform_core_check_change(E_Client *ec)
2670 {
2671    int w = 0;
2672    int h = 0;
2673    Eina_Bool check = EINA_FALSE;
2674    if (!ec) return EINA_FALSE;
2675
2676    if (ec->frame)
2677      evas_object_geometry_get(ec->frame, 0, 0, &w, &h);
2678
2679    // check client position or size change
2680    if (ec->x != ec->transform_core.backup.client_x ||
2681        ec->y != ec->transform_core.backup.client_y ||
2682        ec->w != ec->transform_core.backup.client_w ||
2683        ec->h != ec->transform_core.backup.client_h ||
2684        w     != ec->transform_core.backup.frame_w ||
2685        h     != ec->transform_core.backup.frame_h ||
2686        ec->argb != ec->transform_core.backup.argb)
2687      {
2688         check = EINA_TRUE;
2689         ec->transform_core.backup.client_x = ec->x;
2690         ec->transform_core.backup.client_y = ec->y;
2691         ec->transform_core.backup.client_w = ec->w;
2692         ec->transform_core.backup.client_h = ec->h;
2693         ec->transform_core.backup.frame_w = w;
2694         ec->transform_core.backup.frame_h = h;
2695         ec->transform_core.backup.argb = ec->argb;
2696      }
2697
2698    // check new transform or del transform
2699    if (ec->transform_core.changed)
2700      {
2701         check = EINA_TRUE;
2702         ec->transform_core.changed = EINA_FALSE;
2703      }
2704
2705    // check each transform change
2706    if (ec->transform_core.transform_list)
2707      {
2708         Eina_List *l;
2709         Eina_List *l_next;
2710         E_Util_Transform *transform;
2711
2712         EINA_LIST_FOREACH_SAFE(ec->transform_core.transform_list, l, l_next, transform)
2713           {
2714              // del transform check
2715              if (e_util_transform_ref_count_get(transform) <= 1)
2716                {
2717                   ec->transform_core.transform_list = eina_list_remove(ec->transform_core.transform_list, transform);
2718                   e_util_transform_unref(transform);
2719                   check = EINA_TRUE;
2720                   continue;
2721                }
2722
2723              // transform change test
2724              if (e_util_transform_change_get(transform))
2725                {
2726                   check = EINA_TRUE;
2727                   e_util_transform_change_unset(transform);
2728                }
2729           }
2730      }
2731
2732    if (e_comp_wl_subsurface_check(ec))
2733      {
2734         // check parent matrix change
2735         E_Client *parent = e_comp_wl_subsurface_parent_get(ec);
2736         if (parent && parent->transform_core.result.enable)
2737           {
2738              ec->transform_core.parent.enable = EINA_TRUE;
2739
2740              if (!e_util_transform_matrix_equal_check(&ec->transform_core.parent.matrix,
2741                                                       &parent->transform_core.result.matrix))
2742                {
2743                   check = EINA_TRUE;
2744                   ec->transform_core.parent.matrix = parent->transform_core.result.matrix;
2745                }
2746              if (memcmp(&ec->transform_core.parent.zoom, &parent->transform_core.result.transform.zoom, sizeof(E_Util_Transform_Zoom)) != 0)
2747                {
2748                   check = EINA_TRUE;
2749                   ec->transform_core.parent.zoom = parent->transform_core.result.transform.zoom;
2750                }
2751           }
2752         else if (ec->transform_core.parent.enable)
2753           {
2754              ec->transform_core.parent.enable = EINA_FALSE;
2755              e_util_transform_matrix_load_identity(&ec->transform_core.parent.matrix);
2756              ec->transform_core.parent.zoom.zoom_x = 1.0;
2757              ec->transform_core.parent.zoom.zoom_y = 1.0;
2758              ec->transform_core.parent.zoom.cx = 0;
2759              ec->transform_core.parent.zoom.cy = 0;
2760              check = EINA_TRUE;
2761           }
2762      }
2763
2764    return check;
2765 }
2766
2767 static void
2768 _e_client_transform_core_boundary_update(E_Client *ec, E_Util_Transform_Rect_Vertex *vertices)
2769 {
2770    int minx = 99999, miny = 99999;
2771    int maxx = -99999, maxy = -99999;
2772    int x, y;
2773    int i;
2774
2775    if (!ec) return;
2776    if (!ec->frame) return;
2777    if (!ec->transform_core.result.enable) return;
2778    if (!vertices) return;
2779
2780    for (i = 0; i < 4; ++i)
2781      {
2782         x = 0;
2783         y = 0;
2784
2785         e_util_transform_vertices_pos_round_get(vertices, i, &x, &y, 0, 0);
2786
2787         if (x < minx) minx = x;
2788         if (y < miny) miny = y;
2789         if (x > maxx) maxx = x;
2790         if (y > maxy) maxy = y;
2791      }
2792
2793    ec->transform_core.result.boundary.x = minx;
2794    ec->transform_core.result.boundary.y = miny;
2795    ec->transform_core.result.boundary.w = maxx - minx;
2796    ec->transform_core.result.boundary.h = maxy - miny;
2797
2798    ELOGF("COMP", "[Transform][boundary][%d %d %d %d]",
2799          ec,
2800          ec->transform_core.result.boundary.x,
2801          ec->transform_core.result.boundary.y,
2802          ec->transform_core.result.boundary.w,
2803          ec->transform_core.result.boundary.h);
2804 }
2805
2806 static E_Map *
2807 _e_client_transform_core_map_new(Evas_Object *obj,
2808                                  E_Util_Transform_Rect_Vertex *vertices,
2809                                  E_Util_Transform *transform,
2810                                  Eina_Bool direct_render)
2811 {
2812    E_Map *map;
2813    int i;
2814    int x, y;
2815    double u, v;
2816
2817    map = e_map_new_with_direct_render(direct_render);
2818    EINA_SAFETY_ON_NULL_RETURN_VAL(map, NULL);
2819
2820    e_map_util_points_populate_from_object_full(map, obj, 0);
2821    e_map_util_points_color_set(map, 255, 255, 255, 255);
2822
2823    for (i = 0 ; i < 4 ; ++i)
2824      {
2825         x = 0;
2826         y = 0;
2827
2828         e_util_transform_vertices_pos_round_get(vertices, i, &x, &y, 0, 0);
2829         e_map_point_coord_set(map, i, x, y, 1.0);
2830
2831         if (transform && e_util_transform_texcoord_flag_get(transform))
2832           {
2833              u = 0.0;
2834              v = 0.0;
2835
2836              e_util_transform_texcoord_get(transform, i, &u, &v);
2837              e_map_point_image_uv_set(map, i, u, v);
2838           }
2839      }
2840
2841    return map;
2842 }
2843
2844 static void
2845 _e_client_transform_core_vertices_apply_with_zoom(E_Client *ec,
2846                                         Evas_Object *obj,
2847                                         E_Util_Transform_Rect_Vertex *vertices,
2848                                         E_Util_Transform *transform,
2849                                         E_Util_Transform_Zoom zoom)
2850 {
2851    E_Map *map = NULL;
2852
2853    if (!obj) return;
2854
2855    if (vertices)
2856      {
2857         map = _e_client_transform_core_map_new(obj, vertices, transform,
2858                                                ec->transform_core.direct_render);
2859         EINA_SAFETY_ON_NULL_RETURN(map);
2860
2861         e_map_util_zoom(map, zoom.zoom_x, zoom.zoom_y, zoom.cx, zoom.cy);
2862
2863         e_comp_object_map_set(obj, map);
2864
2865         if (ec->transform_core.activate)
2866           e_comp_object_map_enable_set(obj, EINA_TRUE);
2867         else
2868           e_comp_object_map_enable_set(obj, EINA_FALSE);
2869
2870         e_map_free(map);
2871      }
2872    else
2873      evas_object_map_enable_set(obj, EINA_FALSE);
2874 }
2875
2876 static void
2877 _e_client_transform_core_vertices_apply(E_Client *ec,
2878                                         Evas_Object *obj,
2879                                         E_Util_Transform_Rect_Vertex *vertices,
2880                                         E_Util_Transform *transform)
2881 {
2882    E_Map *map = NULL;
2883
2884    if (!obj) return;
2885
2886    if (vertices)
2887      {
2888         map = _e_client_transform_core_map_new(obj, vertices, transform,
2889                                                ec->transform_core.direct_render);
2890         EINA_SAFETY_ON_NULL_RETURN(map);
2891
2892         e_comp_object_map_set(obj, map);
2893
2894         if (ec->transform_core.activate)
2895           e_comp_object_map_enable_set(obj, EINA_TRUE);
2896         else
2897           e_comp_object_map_enable_set(obj, EINA_FALSE);
2898
2899         e_map_free(map);
2900      }
2901    else
2902      evas_object_map_enable_set(obj, EINA_FALSE);
2903 }
2904
2905 static void
2906 _e_client_transform_core_sub_update(E_Client *ec, E_Util_Transform_Rect_Vertex *vertices)
2907 {
2908    Eina_List *l;
2909    E_Client *subc;
2910    E_Comp_Wl_Client_Data *cdata;
2911
2912    if (!ec) return;
2913
2914    cdata = e_client_cdata_get(ec);
2915    if (!cdata) return;
2916
2917    EINA_LIST_FOREACH(cdata->sub.list, l, subc)
2918       e_client_transform_core_update(subc);
2919
2920    EINA_LIST_FOREACH(cdata->sub.below_list, l, subc)
2921       e_client_transform_core_update(subc);
2922 }
2923
2924 static void
2925 _e_client_cb_hook_shell_surface_ready(void *data EINA_UNUSED, E_Client *ec)
2926 {
2927    if (EINA_UNLIKELY(!ec))
2928      return;
2929
2930    _e_client_aux_hint_eval(ec);
2931 }
2932
2933 // FIXME: This function has to be deleted and it remains for the backward compatibility.
2934 //        Please find and fix to use e_comp_visibility_calculation_set(EINA_TRUE)
2935 //        instead of e_client_visibility_calculate() call at e20 modules.
2936 E_API void
2937 e_client_visibility_calculate(void)
2938 {
2939    e_comp_visibility_calculation_set(EINA_TRUE);
2940 }
2941
2942 E_API void
2943 e_client_visibility_skip_set(E_Client *ec, Eina_Bool skip)
2944 {
2945    if (!ec) return;
2946
2947    ELOGF("POL_VIS", "visibility skip set to %d", ec, skip);
2948    ec->visibility.skip = skip;
2949 }
2950
2951 E_API void
2952 e_client_post_raise_lower_set(E_Client *ec, Eina_Bool raise_set, Eina_Bool lower_set)
2953 {
2954    if (!ec) return;
2955
2956    ec->post_raise = raise_set;
2957    ec->post_lower = lower_set;
2958 }
2959
2960 E_API Eina_Bool
2961 e_client_first_mapped_get(E_Client *ec)
2962 {
2963    if (!ec) return EINA_FALSE;
2964
2965    return ec->first_mapped;
2966 }
2967
2968 EINTERN Eina_Bool e_client_mapped_get(E_Client *ec)
2969 {
2970    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
2971    EINA_SAFETY_ON_NULL_RETURN_VAL(cdata, EINA_FALSE);
2972
2973   return cdata->mapped;
2974 }
2975
2976 EINTERN void
2977 e_client_mapped_set(E_Client *ec, Eina_Bool set)
2978 {
2979    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
2980    EINA_SAFETY_ON_NULL_RETURN(cdata);
2981
2982    cdata->mapped = set;
2983 }
2984
2985
2986 ////////////////////////////////////////////////
2987 EINTERN Eina_Bool
2988 e_client_clients_hash_exist()
2989 {
2990   int pix_id;
2991
2992   for (pix_id = 0; pix_id < E_PIXMAP_TYPE_MAX; pix_id++)
2993     {
2994       if (eina_hash_population(clients_hash[pix_id]))
2995         return EINA_TRUE;
2996     }
2997
2998   return EINA_FALSE;
2999 }
3000
3001 EINTERN void
3002 e_client_idler_before(Eina_Bool *check_focus)
3003 {
3004    const Eina_List *l;
3005    E_Client *ec;
3006
3007    *check_focus = EINA_FALSE;
3008
3009    if (!e_client_clients_hash_exist()) return;
3010
3011    TRACE_DS_BEGIN(CLIENT:IDLE BEFORE);
3012
3013    EINA_LIST_FOREACH(e_comp->clients, l, ec)
3014      {
3015         // pass 1 - eval0. fetch properties on new or on change and
3016         // call hooks to decide what to do - maybe move/resize
3017         if (ec->ignored || (!ec->changed)) continue;
3018
3019         wl_signal_emit_mutable(&PRI(ec)->events.eval_pre_fetch, NULL);
3020         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_PRE_FETCH, ec)) continue;
3021
3022
3023         /* FETCH is hooked by the compositor to get client hints */
3024         wl_signal_emit_mutable(&PRI(ec)->events.eval_fetch, NULL);
3025         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_FETCH, ec)) continue;
3026
3027         if (ec->new_client)
3028           {
3029              e_client_type_update(ec);
3030           }
3031
3032         /* PRE_POST_FETCH calls e_remember apply for new client */
3033         wl_signal_emit_mutable(&PRI(ec)->events.eval_pre_post_fetch, NULL);
3034         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_PRE_POST_FETCH, ec)) continue;
3035         wl_signal_emit_mutable(&PRI(ec)->events.eval_post_fetch, NULL);
3036         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_POST_FETCH, ec)) continue;
3037         wl_signal_emit_mutable(&PRI(ec)->events.eval_pre_frame_assign, NULL);
3038         if (!_e_client_hook_call(E_CLIENT_HOOK_EVAL_PRE_FRAME_ASSIGN, ec)) continue;
3039
3040         wl_signal_emit_mutable(&PRI(ec)->events.eval_post_frame_assign, NULL);
3041         _e_client_hook_call(E_CLIENT_HOOK_EVAL_POST_FRAME_ASSIGN, ec);
3042      }
3043    // pass 2 - show and hide windows needing hide and eval (main eval)
3044    E_CLIENT_FOREACH(ec)
3045      {
3046         if (e_object_is_del(E_OBJECT(ec))) continue;
3047         if (ec->ignored)
3048           {
3049              // ignored client but needing eval (aux hint) such as remote surfaces
3050              if (ec->changed)
3051                {
3052                   E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
3053                   if (cdata && cdata->first_commit)
3054                     _e_client_aux_hint_eval(ec);
3055                }
3056              continue;
3057           }
3058
3059         if (ec->changes.visible)
3060           {
3061              if (ec->visible)
3062                {
3063                   if ((!ec->new_client) &&
3064                       (!ec->changes.pos) &&
3065                       (!ec->changes.size))
3066                     {
3067                        evas_object_show(ec->frame);
3068                        ec->changes.visible = !evas_object_visible_get(ec->frame);
3069                     }
3070                }
3071              else
3072                {
3073                   evas_object_hide(ec->frame);
3074                   ec->changes.visible = 0;
3075                }
3076           }
3077
3078         if (ec->changed)
3079           {
3080              _e_client_eval(ec);
3081              e_comp_visibility_calculation_set(EINA_TRUE);
3082              if (ec->changes.accepts_focus)
3083                *check_focus = EINA_TRUE;
3084              ec->changes.accepts_focus = 0;
3085           }
3086
3087         if ((ec->changes.visible) && (ec->visible) && (!ec->changed))
3088           {
3089              evas_object_show(ec->frame);
3090              ec->changes.visible = !evas_object_visible_get(ec->frame);
3091              ec->changed = ec->changes.visible;
3092              e_comp_visibility_calculation_set(EINA_TRUE);
3093           }
3094      }
3095
3096    TRACE_DS_END();
3097 }
3098
3099
3100 EINTERN Eina_Bool
3101 e_client_init(void)
3102 {
3103    int pix_id;
3104    for (pix_id = 0; pix_id < E_PIXMAP_TYPE_MAX; pix_id++)
3105      clients_hash[pix_id] = eina_hash_pointer_new(NULL);
3106
3107    E_COMP_WL_HOOK_APPEND(hooks, E_COMP_WL_HOOK_SHELL_SURFACE_READY, _e_client_cb_hook_shell_surface_ready, NULL);
3108
3109    E_EVENT_CLIENT_ADD = ecore_event_type_new();
3110    E_EVENT_CLIENT_REMOVE = ecore_event_type_new();
3111    E_EVENT_CLIENT_DESK_SET = ecore_event_type_new();
3112    E_EVENT_CLIENT_ZONE_SET = ecore_event_type_new();
3113    E_EVENT_CLIENT_RESIZE = ecore_event_type_new();
3114    E_EVENT_CLIENT_MOVE = ecore_event_type_new();
3115    E_EVENT_CLIENT_SHOW = ecore_event_type_new();
3116    E_EVENT_CLIENT_HIDE = ecore_event_type_new();
3117    E_EVENT_CLIENT_ICONIFY = ecore_event_type_new();
3118    E_EVENT_CLIENT_UNICONIFY = ecore_event_type_new();
3119    E_EVENT_CLIENT_STACK = ecore_event_type_new();
3120    E_EVENT_CLIENT_FOCUS_IN = ecore_event_type_new();
3121    E_EVENT_CLIENT_FOCUS_OUT = ecore_event_type_new();
3122    E_EVENT_CLIENT_PROPERTY = ecore_event_type_new();
3123    E_EVENT_CLIENT_FULLSCREEN = ecore_event_type_new();
3124    E_EVENT_CLIENT_UNFULLSCREEN = ecore_event_type_new();
3125 #ifdef _F_ZONE_WINDOW_ROTATION_
3126    E_EVENT_CLIENT_ROTATION_CHANGE_BEGIN = ecore_event_type_new();
3127    E_EVENT_CLIENT_ROTATION_CHANGE_CANCEL = ecore_event_type_new();
3128    E_EVENT_CLIENT_ROTATION_CHANGE_END = ecore_event_type_new();
3129    E_EVENT_CLIENT_ROTATION_GEOMETRY_SET = ecore_event_type_new();
3130 #endif
3131    E_EVENT_CLIENT_VISIBILITY_CHANGE = ecore_event_type_new();
3132    E_EVENT_CLIENT_BUFFER_CHANGE = ecore_event_type_new();
3133    E_EVENT_CLIENT_FOCUS_SKIP_SET = ecore_event_type_new();;
3134    E_EVENT_CLIENT_FOCUS_SKIP_UNSET = ecore_event_type_new();;
3135
3136    return (!!clients_hash[1]);
3137 }
3138
3139 EINTERN void
3140 e_client_shutdown(void)
3141 {
3142    int pix_id;
3143    for (pix_id = 0; pix_id < E_PIXMAP_TYPE_MAX; pix_id++)
3144      E_FREE_FUNC(clients_hash[pix_id], eina_hash_free);
3145
3146    E_FREE_LIST(hooks, e_comp_wl_hook_del);
3147    E_FREE_LIST(handlers, ecore_event_handler_del);
3148
3149 }
3150
3151 E_API void
3152 e_client_unignore(E_Client *ec)
3153 {
3154    E_OBJECT_CHECK(ec);
3155    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3156    if (!ec->ignored) return;
3157
3158    ec->ignored = 0;
3159    _e_client_event_add(ec);
3160 }
3161
3162 E_API E_Client *
3163 e_client_new(E_Pixmap *cp, int first_map, int internal)
3164 {
3165    E_Client *ec;
3166    E_Pixmap_Type type;
3167
3168    type = e_pixmap_type_get(cp);
3169    if (type >= E_PIXMAP_TYPE_MAX) return NULL;
3170    if (eina_hash_find(clients_hash[type], &cp)) return NULL;
3171
3172    ec = E_OBJECT_ALLOC(E_Client, E_CLIENT_TYPE, _e_client_free);
3173    if (!ec) return NULL;
3174    e_object_del_func_set(E_OBJECT(ec), E_OBJECT_CLEANUP_FUNC(_e_client_del));
3175
3176    if (!_e_client_private_init(ec))
3177      {
3178         e_object_del(E_OBJECT(ec));
3179         return NULL;
3180      }
3181
3182    uuid_generate(ec->uuid);
3183
3184    ec->focus_policy_override = E_FOCUS_LAST;
3185    e_client_size_set(ec, 1, 1);
3186    ec->internal = internal;
3187
3188    ec->pixmap = cp;
3189    e_pixmap_client_set(cp, ec);
3190    ec->resize_mode = E_POINTER_RESIZE_NONE;
3191    ec->layer = E_LAYER_CLIENT_NORMAL;
3192    ec->first_mapped = EINA_FALSE;
3193    ec->post_raise = EINA_TRUE;
3194    ec->post_lower = EINA_FALSE;
3195    ec->animatable = EINA_TRUE;
3196    ec->maximize_type = e_config->maximize_policy & E_MAXIMIZE_TYPE;
3197
3198    /* FIXME: if first_map is 1 then we should ignore the first hide event
3199     * or ensure the window is already hidden and events flushed before we
3200     * create a border for it */
3201    if (first_map)
3202      {
3203         ec->changes.pos = 1;
3204         ec->re_manage = 1;
3205         // needed to be 1 for internal windw and on restart.
3206         // ec->ignore_first_unmap = 2;
3207      }
3208    ec->offer_resistance = 1;
3209    ec->new_client = 1;
3210    e_comp->new_clients++;
3211
3212    ec->exp_iconify.by_client = 0;
3213    ec->exp_iconify.not_raise = 0;
3214    ec->exp_iconify.skip_iconify = 0;
3215    ec->exp_iconify.skip_by_remote = 0;
3216    if (e_config->deiconify_approve)
3217      ec->exp_iconify.deiconify_update= 1;
3218    else
3219      ec->exp_iconify.deiconify_update= 0;
3220    if (e_config->use_buffer_flush)
3221      ec->exp_iconify.buffer_flush = 1;
3222    else
3223      ec->exp_iconify.buffer_flush = 0;
3224
3225    e_client_iconified_type_set(ec, E_ICONIFIED_TYPE_NONE);
3226
3227    wl_signal_emit_mutable(&PRI(ec)->events.new_client, NULL);
3228    if (!_e_client_hook_call(E_CLIENT_HOOK_NEW_CLIENT, ec))
3229      {
3230         /* delete the above allocated object */
3231         //e_object_del(E_OBJECT(ec));
3232         return NULL;
3233      }
3234
3235    _e_client_aux_hint_eval(ec);
3236
3237    ec->icccm.title = NULL;
3238    ec->icccm.name = NULL;
3239 #if defined(__cplusplus) || defined(c_plusplus)
3240    ec->icccm.cpp_class = NULL;
3241 #else
3242    ec->icccm.class = NULL;
3243 #endif
3244    ec->icccm.icon_name = NULL;
3245    ec->icccm.machine = NULL;
3246    ec->icccm.min_w = 1;
3247    ec->icccm.min_h = 1;
3248    ec->icccm.max_w = 32767;
3249    ec->icccm.max_h = 32767;
3250    ec->icccm.base_w = 0;
3251    ec->icccm.base_h = 0;
3252    ec->icccm.step_w = -1;
3253    ec->icccm.step_h = -1;
3254    ec->icccm.min_aspect = 0.0;
3255    ec->icccm.max_aspect = 0.0;
3256
3257    ec->netwm.pid = 0;
3258    ec->netwm.name = NULL;
3259    ec->netwm.icon_name = NULL;
3260    ec->netwm.desktop = 0;
3261    ec->netwm.state.modal = 0;
3262    ec->netwm.state.sticky = 0;
3263    ec->netwm.state.shaded = 0;
3264    ec->netwm.state.hidden = 0;
3265    ec->netwm.state.maximized_v = 0;
3266    ec->netwm.state.maximized_h = 0;
3267    ec->netwm.state.skip_taskbar = 0;
3268    ec->netwm.state.skip_pager = 0;
3269    ec->netwm.state.fullscreen = 0;
3270    ec->netwm.state.stacking = E_STACKING_NONE;
3271    ec->netwm.action.move = 0;
3272    ec->netwm.action.resize = 0;
3273    ec->netwm.action.minimize = 0;
3274    ec->netwm.action.shade = 0;
3275    ec->netwm.action.stick = 0;
3276    ec->netwm.action.maximized_h = 0;
3277    ec->netwm.action.maximized_v = 0;
3278    ec->netwm.action.fullscreen = 0;
3279    ec->netwm.action.change_desktop = 0;
3280    ec->netwm.action.close = 0;
3281    ec->netwm.opacity = 255;
3282
3283    ec->visibility.obscured = E_VISIBILITY_UNKNOWN;
3284    ec->visibility.opaque = -1;
3285    ec->visibility.changed = 0;
3286    ec->visibility.skip = 0;
3287    ec->visibility.last_sent_type = E_VISIBILITY_UNKNOWN;
3288
3289    ec->transform.zoom = 1.0;
3290    ec->transform.angle = 0.0;
3291    ec->transform_core.direct_render = EINA_TRUE;
3292    ec->transform_core.activate = EINA_TRUE;
3293
3294    ec->pointer_enter_sent = EINA_FALSE;
3295
3296    ec->acquire_fence_fd = -1;
3297
3298    EC_CHANGED(ec);
3299
3300    e_comp->clients = eina_list_append(e_comp->clients, ec);
3301    eina_hash_add(clients_hash[type], &ec->pixmap, ec);
3302
3303    ELOGF("COMP", "CLIENT ADD. cp:%p, argb:%d, internal:%d, ignored:%d", ec, cp, ec->argb, internal, ec->ignored);
3304    if (!ec->ignored)
3305      _e_client_event_add(ec);
3306    e_comp_object_client_add(ec);
3307    if (ec->frame)
3308      {
3309         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_SHOW, _e_client_cb_evas_show, ec);
3310         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_HIDE, _e_client_cb_evas_hide, ec);
3311         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_MOVE, _e_client_cb_evas_move, ec);
3312         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_RESIZE, _e_client_cb_evas_resize, ec);
3313         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_RESTACK, _e_client_cb_evas_restack, ec);
3314         evas_object_smart_callback_add(ec->frame, "shade_done", _e_client_cb_evas_shade_done, ec);
3315      }
3316
3317    wl_signal_emit_mutable(&PRI(ec)->events.new_client_post, NULL);
3318
3319 #ifdef _F_E_CLIENT_NEW_CLIENT_POST_HOOK_
3320    _e_client_hook_call(E_CLIENT_HOOK_NEW_CLIENT_POST, ec);
3321 #endif
3322
3323    ec->manage_resize.resize_obj = NULL;
3324    ec->manage_resize.x = ec->manage_resize.y = ec->manage_resize.w = ec->manage_resize.h = 0;
3325    ec->manage_resize.enable_aspect_ratio = EINA_FALSE;
3326    ec->manage_resize.aw = ec->manage_resize.ah = 0;
3327    ec->manage_resize.header_h = 0;
3328    ec->manage_resize.footer_h = 0;
3329
3330    ec->visibility.ignore_geometry = e_config->calc_vis_ignore_geometry;
3331
3332    return ec;
3333 }
3334
3335 E_API Eina_Bool e_client_is_internal(E_Client *ec)
3336 {
3337    E_OBJECT_CHECK_RETURN(ec, EINA_TRUE);
3338    return ec->internal;
3339 }
3340
3341 EINTERN void
3342 e_client_desk_iconify_skip_set(E_Client *ec, Eina_Bool skip)
3343 {
3344    if (!ec) return;
3345    ec->user_skip_winlist = skip;
3346 }
3347
3348 EINTERN Eina_Bool
3349 e_client_desk_iconify_skip_get(E_Client *ec)
3350 {
3351    if (!ec) return EINA_FALSE;
3352    return ec->user_skip_winlist;
3353 }
3354
3355 EINTERN Eina_Bool
3356 e_client_comp_grabbed_get(void)
3357 {
3358    return comp_grabbed;
3359 }
3360
3361 EINTERN E_Client *
3362 e_client_action_get(void)
3363 {
3364    return action_client;
3365 }
3366
3367
3368 //////////////////////////////////////////////////////////
3369
3370 EINTERN void
3371 e_client_mouse_in(E_Client *ec, int x, int y)
3372 {
3373    E_Desk *desk;
3374
3375    if (comp_grabbed) return;
3376    if (e_object_is_del(E_OBJECT(ec))) return;
3377    desk = e_comp_desk_find_by_ec(ec);
3378    if (desk && desk->animate_count) return;
3379    ec->mouse.current.mx = x;
3380    ec->mouse.current.my = y;
3381    ec->mouse.in = 1;
3382
3383    wl_signal_emit_mutable(&PRI(ec)->events.mouse_in, NULL);
3384 }
3385
3386 EINTERN void
3387 e_client_mouse_out(E_Client *ec, int x, int y)
3388 {
3389    E_Desk *desk;
3390
3391    if (comp_grabbed) return;
3392    if (ec->fullscreen) return;
3393    if (e_object_is_del(E_OBJECT(ec))) return;
3394    desk = e_comp_desk_find_by_ec(ec);
3395    if (desk && desk->animate_count) return;
3396
3397    ec->mouse.current.mx = x;
3398    ec->mouse.current.my = y;
3399    ec->mouse.in = 0;
3400
3401    wl_signal_emit_mutable(&PRI(ec)->events.mouse_out, NULL);
3402 }
3403
3404 EINTERN void
3405 e_client_mouse_wheel(E_Client *ec, Evas_Point *output, E_Binding_Event_Wheel *ev)
3406 {
3407    EINA_SAFETY_ON_NULL_RETURN(ec);
3408    if (action_client) return;
3409    ec->mouse.current.mx = output->x;
3410    ec->mouse.current.my = output->y;
3411 }
3412
3413 EINTERN void
3414 e_client_mouse_down(E_Client *ec, int button, Evas_Point *output, E_Binding_Event_Mouse_Button *ev)
3415 {
3416    EINA_SAFETY_ON_NULL_RETURN(ec);
3417
3418    if (action_client || ec->iconic || e_client_util_ignored_get(ec)) return;
3419    if ((button >= 1) && (button <= 3))
3420      {
3421         ec->mouse.last_down[button - 1].mx = output->x;
3422         ec->mouse.last_down[button - 1].my = output->y;
3423         ec->mouse.last_down[button - 1].x = ec->x;
3424         ec->mouse.last_down[button - 1].y = ec->y;
3425         ec->mouse.last_down[button - 1].w = ec->w;
3426         ec->mouse.last_down[button - 1].h = ec->h;
3427      }
3428    else
3429      {
3430         ec->moveinfo.down.x = ec->x;
3431         ec->moveinfo.down.y = ec->y;
3432         ec->moveinfo.down.w = ec->w;
3433         ec->moveinfo.down.h = ec->h;
3434      }
3435    ec->mouse.current.mx = output->x;
3436    ec->mouse.current.my = output->y;
3437    if ((button >= 1) && (button <= 3))
3438      {
3439         ec->mouse.last_down[button - 1].mx = output->x;
3440         ec->mouse.last_down[button - 1].my = output->y;
3441         ec->mouse.last_down[button - 1].x = ec->x;
3442         ec->mouse.last_down[button - 1].y = ec->y;
3443         ec->mouse.last_down[button - 1].w = ec->w;
3444         ec->mouse.last_down[button - 1].h = ec->h;
3445      }
3446    else
3447      {
3448         ec->moveinfo.down.x = ec->x;
3449         ec->moveinfo.down.y = ec->y;
3450         ec->moveinfo.down.w = ec->w;
3451         ec->moveinfo.down.h = ec->h;
3452      }
3453    ec->mouse.current.mx = output->x;
3454    ec->mouse.current.my = output->y;
3455
3456    wl_signal_emit_mutable(&PRI(ec)->events.mouse_down, NULL);
3457 }
3458
3459 EINTERN void
3460 e_client_mouse_up(E_Client *ec, int button, Evas_Point *output, E_Binding_Event_Mouse_Button* ev)
3461 {
3462    EINA_SAFETY_ON_NULL_RETURN(ec);
3463    if (ec->iconic || e_client_util_ignored_get(ec)) return;
3464    if ((button >= 1) && (button <= 3))
3465      {
3466         ec->mouse.last_up[button - 1].mx = output->x;
3467         ec->mouse.last_up[button - 1].my = output->y;
3468         ec->mouse.last_up[button - 1].x = ec->x;
3469         ec->mouse.last_up[button - 1].y = ec->y;
3470      }
3471    ec->mouse.current.mx = output->x;
3472    ec->mouse.current.my = output->y;
3473    /* also we don't pass the same params that went in - then again that */
3474    /* should be ok as we are just ending the action if it has an end */
3475    if (ec->cur_mouse_action)
3476      {
3477         if (ec->cur_mouse_action->func.end_mouse)
3478           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", ev);
3479         else if (ec->cur_mouse_action->func.end)
3480           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
3481         e_object_unref(E_OBJECT(ec->cur_mouse_action));
3482         ec->cur_mouse_action = NULL;
3483      }
3484
3485    if ((button >= 1) && (button <= 3))
3486      {
3487         ec->mouse.last_up[button - 1].mx = output->x;
3488         ec->mouse.last_up[button - 1].my = output->y;
3489         ec->mouse.last_up[button - 1].x = ec->x;
3490         ec->mouse.last_up[button - 1].y = ec->y;
3491      }
3492 }
3493
3494 E_API void
3495 e_client_stay_within_canvas_margin(E_Client *ec)
3496 {
3497    int new_x = ec->x;
3498    int new_y = ec->y;
3499
3500    if (ec->floating)
3501      {
3502         _e_client_stay_within_canvas_margin(ec, ec->x, ec->y, &new_x, &new_y);
3503
3504         if ((ec->x != new_x) || (ec->y != new_y))
3505           evas_object_move(ec->frame, new_x, new_y);
3506      }
3507 }
3508
3509 EINTERN void
3510 e_client_mouse_move(E_Client *ec, Evas_Point *output)
3511 {
3512    EINA_SAFETY_ON_NULL_RETURN(ec);
3513    if (ec->iconic || e_client_util_ignored_get(ec)) return;
3514    ec->mouse.current.mx = output->x;
3515    ec->mouse.current.my = output->y;
3516    if (e_client_util_moving_get(ec))
3517      {
3518         _e_client_move_handle(ec);
3519      }
3520    else if (e_client_util_resizing_get(ec))
3521      {
3522         _e_client_resize_handle(ec);
3523      }
3524 }
3525 ///////////////////////////////////////////////////////
3526
3527 EINTERN void
3528 e_client_res_change_geometry_save(E_Client *ec)
3529 {
3530    E_OBJECT_CHECK(ec);
3531    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3532
3533    if (ec->pre_res_change.valid) return;
3534    ec->pre_res_change.valid = 1;
3535    ec->pre_res_change.x = ec->x;
3536    ec->pre_res_change.y = ec->y;
3537    ec->pre_res_change.w = ec->w;
3538    ec->pre_res_change.h = ec->h;
3539    ec->pre_res_change.saved.x = ec->saved.x;
3540    ec->pre_res_change.saved.y = ec->saved.y;
3541    ec->pre_res_change.saved.w = ec->saved.w;
3542    ec->pre_res_change.saved.h = ec->saved.h;
3543 }
3544
3545 EINTERN void
3546 e_client_res_change_geometry_restore(E_Client *ec)
3547 {
3548    E_Zone *zone;
3549
3550    struct
3551    {
3552       unsigned char valid : 1;
3553       int           x, y, w, h;
3554       struct
3555       {
3556          int x, y, w, h;
3557       } saved;
3558    } pre_res_change;
3559
3560    E_OBJECT_CHECK(ec);
3561    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3562    if (!ec->pre_res_change.valid) return;
3563    if (ec->new_client) return;
3564
3565    zone = e_comp_zone_find_by_ec(ec);
3566    if (!zone) return;
3567
3568    memcpy(&pre_res_change, &ec->pre_res_change, sizeof(pre_res_change));
3569
3570    if (ec->fullscreen)
3571      {
3572         e_client_unfullscreen(ec);
3573         e_client_fullscreen(ec, e_config->fullscreen_policy);
3574      }
3575    else if (ec->maximized != E_MAXIMIZE_NONE)
3576      {
3577         E_Maximize max;
3578
3579         max = ec->maximized;
3580         e_client_unmaximize(ec, E_MAXIMIZE_BOTH);
3581         e_client_maximize(ec, max);
3582      }
3583    else
3584      {
3585         int x, y, w, h, zx, zy, zw, zh;
3586
3587         ec->saved.x = ec->pre_res_change.saved.x;
3588         ec->saved.y = ec->pre_res_change.saved.y;
3589         ec->saved.w = ec->pre_res_change.saved.w;
3590         ec->saved.h = ec->pre_res_change.saved.h;
3591
3592         e_zone_useful_geometry_get(zone, &zx, &zy, &zw, &zh);
3593
3594         if (ec->saved.w > zw)
3595           ec->saved.w = zw;
3596         if ((ec->saved.x + ec->saved.w) > (zx + zw))
3597           ec->saved.x = zx + zw - ec->saved.w;
3598
3599         if (ec->saved.h > zh)
3600           ec->saved.h = zh;
3601         if ((ec->saved.y + ec->saved.h) > (zy + zh))
3602           ec->saved.y = zy + zh - ec->saved.h;
3603
3604         x = ec->pre_res_change.x;
3605         y = ec->pre_res_change.y;
3606         w = ec->pre_res_change.w;
3607         h = ec->pre_res_change.h;
3608         if (w > zw)
3609           w = zw;
3610         if (h > zh)
3611           h = zh;
3612         if ((x + w) > (zx + zw))
3613           x = zx + zw - w;
3614         if ((y + h) > (zy + zh))
3615           y = zy + zh - h;
3616         evas_object_geometry_set(ec->frame, x, y, w, h);
3617      }
3618    memcpy(&ec->pre_res_change, &pre_res_change, sizeof(pre_res_change));
3619 }
3620
3621 EINTERN void
3622 e_client_pos_set(E_Client *ec, int x, int y)
3623 {
3624    if (!ec) return;
3625    ec->x = x;
3626    ec->y = y;
3627 }
3628
3629 EINTERN void
3630 e_client_pos_get(E_Client *ec, int *x, int *y)
3631 {
3632    int ex = 0;
3633    int ey = 0;
3634
3635    if (ec)
3636      {
3637         ex = ec->x;
3638         ey = ec->y;
3639      }
3640
3641    if (x) *x = ex;
3642    if (y) *y = ey;
3643 }
3644
3645 E_API void
3646 e_client_size_set(E_Client *ec, int w, int h)
3647 {
3648    if (!ec) return;
3649    ec->w = w;
3650    ec->h = h;
3651 }
3652
3653 E_API void
3654 e_client_size_get(E_Client *ec, int *w, int *h)
3655 {
3656    int ew = 0;
3657    int eh = 0;
3658
3659    if (ec)
3660      {
3661         ew = ec->w;
3662         eh = ec->h;
3663      }
3664
3665    if (w) *w = ew;
3666    if (h) *h = eh;
3667 }
3668
3669 E_API void
3670 e_client_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
3671 {
3672    int gx = 0;
3673    int gy = 0;
3674    int gw = 0;
3675    int gh = 0;
3676
3677    E_OBJECT_CHECK(ec);
3678    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3679
3680    if (e_client_transform_core_enable_get(ec))
3681      {
3682         gx = ec->transform_core.result.boundary.x;
3683         gy = ec->transform_core.result.boundary.y;
3684         gw = ec->transform_core.result.boundary.w;
3685         gh = ec->transform_core.result.boundary.h;
3686      }
3687    else
3688      {
3689         if (ec->frame)
3690           {
3691              evas_object_geometry_get(ec->frame, &gx, &gy, &gw, &gh);
3692              if (gw == 0 && gh == 0)
3693                {
3694                   /* In this case, there is no image buffer in e_comp_object, thus it
3695                    * should return geometry value of ec itself. It usually happens if
3696                    * new ec is not mapped yet.
3697                    */
3698                   gw = ec->w;
3699                   gh = ec->h;
3700                   gx = ec->x;
3701                   gy = ec->y;
3702                }
3703           }
3704         else
3705           {
3706              gx = ec->x;
3707              gy = ec->y;
3708              gw = ec->w;
3709              gh = ec->h;
3710           }
3711      }
3712
3713    if (x) *x = gx;
3714    if (y) *y = gy;
3715    if (w) *w = gw;
3716    if (h) *h = gh;
3717 }
3718
3719 E_API E_Client *
3720 e_client_above_get(const E_Client *ec)
3721 {
3722    unsigned int x;
3723    E_Client *ec2;
3724
3725    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
3726    if (EINA_INLIST_GET(ec)->next) //check current layer
3727      {
3728         EINA_INLIST_FOREACH(EINA_INLIST_GET(ec)->next, ec2)
3729           {
3730              if (ec == ec2)
3731                {
3732                   ELOGF("FATAL", "CHECK the ec inlist next", ec);
3733                   continue;
3734                }
3735              if (!e_object_is_del(E_OBJECT(ec2)))
3736                return ec2;
3737           }
3738      }
3739    if (ec->layer == E_LAYER_CLIENT_CURSOR) return NULL;
3740    if (e_comp_canvas_client_layer_map(ec->layer) == 9999) return NULL;
3741
3742    g_rec_mutex_lock(&e_comp->input_key_grabs_mutex);
3743    /* go up the layers until we find one */
3744    for (x = e_comp_canvas_layer_map(ec->layer) + 1; x <= e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x++)
3745      {
3746         if (!e_comp->layers[x].clients) continue;
3747         EINA_INLIST_FOREACH(e_comp->layers[x].clients, ec2)
3748           {
3749              if (ec == ec2)
3750                {
3751                   ELOGF("FATAL", "EC exist above layer. ec layer_map:%d, cur layer_map:%d",
3752                         ec, e_comp_canvas_layer_map(ec->layer), x);
3753                   continue;
3754                }
3755              if (!e_object_is_del(E_OBJECT(ec2)))
3756                {
3757                   g_rec_mutex_unlock(&e_comp->input_key_grabs_mutex);
3758                   return ec2;
3759                }
3760           }
3761      }
3762    g_rec_mutex_unlock(&e_comp->input_key_grabs_mutex);
3763
3764    return NULL;
3765 }
3766
3767 E_API E_Client *
3768 e_client_below_get(const E_Client *ec)
3769 {
3770    unsigned int x;
3771    E_Client *ec2;
3772    Eina_Inlist *l;
3773    E_Layer ec_layer, ec_layer_cw;
3774    int cw_layer;
3775
3776    E_OBJECT_CHECK_RETURN(ec, NULL);
3777    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, NULL);
3778
3779    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
3780    if (EINA_INLIST_GET(ec)->prev) //check current layer
3781      {
3782         for (l = EINA_INLIST_GET(ec)->prev; l; l = l->prev)
3783           {
3784              ec2 = EINA_INLIST_CONTAINER_GET(l, E_Client);
3785              if (ec == ec2)
3786                {
3787                   ELOGF("FATAL", "CHECK the ec inlist prev", ec);
3788                   continue;
3789                }
3790              if (!e_object_is_del(E_OBJECT(ec2)))
3791                return ec2;
3792           }
3793      }
3794
3795    // check layer validation
3796    ec_layer = ec->layer;
3797    if (ec->layer_block || ec->layer_pending)
3798      {
3799         cw_layer = e_comp_object_layer_get(ec->frame);
3800         if (cw_layer >= 0)
3801           {
3802              ec_layer_cw = e_comp_canvas_layer_map_to(cw_layer);
3803              if (ec_layer != ec_layer_cw)
3804                {
3805                   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);
3806                   ec_layer = ec_layer_cw;
3807                }
3808           }
3809      }
3810
3811    if (ec_layer == E_LAYER_CLIENT_DESKTOP) return NULL;
3812    if (e_comp_canvas_client_layer_map(ec_layer) == 9999) return NULL;
3813
3814    /* go down the layers until we find one */
3815    x = e_comp_canvas_layer_map(ec_layer);
3816    if (x > 0) x--;
3817
3818    g_rec_mutex_lock(&e_comp->input_key_grabs_mutex);
3819    for (; x >= e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x--)
3820      {
3821         if (!e_comp->layers[x].clients) continue;
3822         EINA_INLIST_REVERSE_FOREACH(e_comp->layers[x].clients, ec2)
3823           {
3824              if (ec == ec2)
3825                {
3826                   ELOGF("FATAL", "EC exist below layer. ec layer_map:%d, cur layer_map:%d",
3827                         ec, e_comp_canvas_layer_map(ec_layer), x);
3828                   continue;
3829                }
3830              if (!e_object_is_del(E_OBJECT(ec2)))
3831                {
3832                   g_rec_mutex_unlock(&e_comp->input_key_grabs_mutex);
3833                   return ec2;
3834                }
3835           }
3836      }
3837    g_rec_mutex_unlock(&e_comp->input_key_grabs_mutex);
3838
3839    return NULL;
3840 }
3841
3842 E_API E_Client *
3843 e_client_bottom_get(void)
3844 {
3845    unsigned int x;
3846    g_rec_mutex_lock(&e_comp->input_key_grabs_mutex);
3847    for (x = e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x <= e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x++)
3848      {
3849         E_Client *ec2;
3850
3851         if (!e_comp->layers[x].clients) continue;
3852         EINA_INLIST_FOREACH(e_comp->layers[x].clients, ec2)
3853           if (!e_object_is_del(E_OBJECT(ec2)))
3854             {
3855                g_rec_mutex_unlock(&e_comp->input_key_grabs_mutex);
3856                return ec2;
3857             }
3858      }
3859    g_rec_mutex_unlock(&e_comp->input_key_grabs_mutex);
3860
3861    return NULL;
3862 }
3863
3864 E_API E_Client *
3865 e_client_top_get(void)
3866 {
3867    unsigned int x;
3868    g_rec_mutex_lock(&e_comp->input_key_grabs_mutex);
3869    for (x = e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x >= e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x--)
3870      {
3871         E_Client *ec2;
3872
3873         if (!e_comp->layers[x].clients) continue;
3874         EINA_INLIST_REVERSE_FOREACH(e_comp->layers[x].clients, ec2)
3875           if (!e_object_is_del(E_OBJECT(ec2)))
3876             {
3877                g_rec_mutex_unlock(&e_comp->input_key_grabs_mutex);
3878                return ec2;
3879             }
3880      }
3881    g_rec_mutex_unlock(&e_comp->input_key_grabs_mutex);
3882
3883    return NULL;
3884 }
3885
3886 EINTERN unsigned int
3887 e_clients_count(void)
3888 {
3889    return eina_list_count(e_comp->clients);
3890 }
3891
3892
3893 /**
3894  * Set a callback which will be called just prior to updating the
3895  * move coordinates for a border
3896  */
3897 EINTERN void
3898 e_client_move_intercept_cb_set(E_Client *ec, E_Client_Move_Intercept_Cb cb)
3899 {
3900    ec->move_intercept_cb = cb;
3901 }
3902
3903 ///////////////////////////////////////
3904
3905 E_API E_Client_Hook *
3906 e_client_hook_add(E_Client_Hook_Point hookpoint, E_Client_Hook_Cb func, const void *data)
3907 {
3908    E_Client_Hook *ch;
3909
3910    EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_CLIENT_HOOK_LAST, NULL);
3911    ch = E_NEW(E_Client_Hook, 1);
3912    if (!ch) return NULL;
3913    ch->hookpoint = hookpoint;
3914    ch->func = func;
3915    ch->data = (void*)data;
3916    _e_client_hooks[hookpoint] = eina_inlist_append(_e_client_hooks[hookpoint], EINA_INLIST_GET(ch));
3917    return ch;
3918 }
3919
3920 E_API void
3921 e_client_hook_del(E_Client_Hook *ch)
3922 {
3923    ch->delete_me = 1;
3924    if (_e_client_hooks_walking == 0)
3925      {
3926         _e_client_hooks[ch->hookpoint] = eina_inlist_remove(_e_client_hooks[ch->hookpoint], EINA_INLIST_GET(ch));
3927         free(ch);
3928      }
3929    else
3930      _e_client_hooks_delete++;
3931 }
3932
3933 ///////////////////////////////////////
3934
3935 E_API E_Client_Intercept_Hook *
3936 e_client_intercept_hook_add(E_Client_Intercept_Hook_Point hookpoint, E_Client_Intercept_Hook_Cb func, const void *data)
3937 {
3938    E_Client_Intercept_Hook *ch;
3939
3940    EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_CLIENT_INTERCEPT_HOOK_LAST, NULL);
3941    ch = E_NEW(E_Client_Intercept_Hook, 1);
3942    if (!ch) return NULL;
3943    ch->hookpoint = hookpoint;
3944    ch->func = func;
3945    ch->data = (void*)data;
3946    _e_client_intercept_hooks[hookpoint] = eina_inlist_append(_e_client_intercept_hooks[hookpoint], EINA_INLIST_GET(ch));
3947    return ch;
3948 }
3949
3950 E_API void
3951 e_client_intercept_hook_del(E_Client_Intercept_Hook *ch)
3952 {
3953    if (!ch) return;
3954
3955    ch->delete_me = 1;
3956    if (_e_client_intercept_hooks_walking == 0)
3957      {
3958         _e_client_intercept_hooks[ch->hookpoint] =
3959            eina_inlist_remove(_e_client_intercept_hooks[ch->hookpoint], EINA_INLIST_GET(ch));
3960         free(ch);
3961      }
3962    else
3963      _e_client_intercept_hooks_delete++;
3964 }
3965
3966 E_API void
3967 e_client_focus_latest_set(E_Client *ec)
3968 {
3969    EINA_SAFETY_ON_NULL_RETURN(ec);
3970
3971    wl_signal_emit_mutable(&PRI(ec)->events.focus_latest_set, NULL);
3972 }
3973
3974 E_API void
3975 e_client_focus_defer_set(E_Client *ec)
3976 {
3977    EINA_SAFETY_ON_NULL_RETURN(ec);
3978
3979    wl_signal_emit_mutable(&PRI(ec)->events.focus_defer_set, NULL);
3980 }
3981
3982 EINTERN void
3983 e_client_focused_set(E_Client *ec)
3984 {
3985    E_Client *focused_ec;
3986    E_Zone *zone;
3987
3988    if (ec)
3989      ELOGF("FOCUS", "CLIENT FOCUSED_SET : SET", ec);
3990    else
3991      ELOGF("FOCUS", "CLIENT FOCUSED_SET : UNSET", NULL);
3992
3993   focused_ec = e_comp_focused_ec_get();
3994   if (ec == focused_ec) return;
3995
3996    TRACE_DS_BEGIN(CLIENT:FOCUSED SET);
3997
3998    // unset the current focused_ec if focused_ec is not being deleted
3999    if (focused_ec)
4000      {
4001        if (!e_object_is_del(E_OBJECT(focused_ec)))
4002          {
4003             // FIXME: Remove focus_unset event of client.
4004             //        Instead, make zone focus_unset event and use it.
4005             wl_signal_emit_mutable(&PRI(focused_ec)->events.focus_unset, NULL);
4006             _e_client_hook_call(E_CLIENT_HOOK_FOCUS_UNSET, focused_ec);
4007
4008             if (e_object_ref_get(E_OBJECT(focused_ec)) > 0)
4009               {
4010                  _e_client_event_simple(focused_ec, E_EVENT_CLIENT_FOCUS_OUT);
4011                  e_client_urgent_set(focused_ec, focused_ec->icccm.urgent);
4012               }
4013          }
4014      }
4015
4016    // clear the current focused_ec when ec is NULL
4017    if (!ec)
4018      {
4019         zone = e_comp_zone_find_by_ec(focused_ec);
4020         e_zone_focus_clear(zone);
4021         TRACE_DS_END();
4022         return;
4023      }
4024
4025    // FIXME: Remove focus_set event of client.
4026    //        Instead, make zone focus_set event and use it.
4027    // set the new current focused_ec
4028    wl_signal_emit_mutable(&PRI(ec)->events.focus_set, NULL);
4029    _e_client_hook_call(E_CLIENT_HOOK_FOCUS_SET, ec);
4030
4031    // send the client_focuse_in event
4032    _e_client_event_simple(ec, E_EVENT_CLIENT_FOCUS_IN);
4033
4034    TRACE_DS_END();
4035 }
4036
4037 EINTERN void
4038 e_client_activate(E_Client *ec)
4039 {
4040    E_OBJECT_CHECK(ec);
4041    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4042
4043    TRACE_DS_BEGIN(CLIENT:ACTIVATE);
4044
4045    ELOGF("COMP", "Set launching flag..", ec);
4046    ec->launching = EINA_TRUE;
4047
4048    ec->exp_iconify.not_raise = 0;
4049
4050    if (ec->iconic)
4051      {
4052          if (!ec->lock_user_iconify)
4053            e_client_uniconify(ec);
4054      }
4055    ELOGF("COMP", "Un-Set ICONIFY BY CLIENT", ec);
4056    ec->exp_iconify.by_client = 0;
4057    e_client_iconified_type_set(ec, E_ICONIFIED_TYPE_NONE);
4058
4059    wl_signal_emit_mutable(&PRI(ec)->events.activate_done, NULL);
4060    _e_client_hook_call(E_CLIENT_HOOK_ACTIVATE_DONE, ec);
4061
4062    TRACE_DS_END();
4063 }
4064
4065 E_API E_Client *
4066 e_client_focused_get(void)
4067 {
4068    return e_comp_focused_ec_get();
4069 }
4070
4071 EINTERN Eina_List *
4072 e_client_lost_windows_get(E_Zone *zone)
4073 {
4074    Eina_List *list = NULL;
4075    const Eina_List *l;
4076    E_Client *ec;
4077    int loss_overlap = 5;
4078
4079    E_OBJECT_CHECK_RETURN(zone, NULL);
4080    E_OBJECT_TYPE_CHECK_RETURN(zone, E_ZONE_TYPE, NULL);
4081    EINA_LIST_FOREACH(e_comp->clients, l, ec)
4082      {
4083         if (!e_zone_has_ec(zone, ec)) continue;
4084         if (e_client_util_ignored_get(ec)) continue;
4085
4086         if (!E_INTERSECTS(zone->x + loss_overlap,
4087                           zone->y + loss_overlap,
4088                           zone->w - (2 * loss_overlap),
4089                           zone->h - (2 * loss_overlap),
4090                           ec->x, ec->y, ec->w, ec->h))
4091           {
4092              list = eina_list_append(list, ec);
4093           }
4094      }
4095    return list;
4096 }
4097
4098 ///////////////////////////////////////
4099
4100 EINTERN void
4101 e_client_shade(E_Client *ec, E_Direction dir)
4102 {
4103    E_OBJECT_CHECK(ec);
4104    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4105    if ((ec->shaded) || (ec->shading) || (ec->fullscreen) ||
4106        ((ec->maximized) && (!e_config->allow_manip))) return;
4107    if (!e_util_strcmp("borderless", ec->bordername)) return;
4108    if (!e_comp_object_frame_allowed(ec->frame)) return;
4109
4110    ec->take_focus = 0;
4111    ec->shading = 1;
4112    ec->shade_dir = dir;
4113
4114    evas_object_smart_callback_call(ec->frame, "shaded", (uintptr_t*)dir);
4115 }
4116
4117 EINTERN void
4118 e_client_unshade(E_Client *ec, E_Direction dir)
4119 {
4120    E_OBJECT_CHECK(ec);
4121    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4122    if ((!ec->shaded) || (ec->shading))
4123      return;
4124
4125    ec->shading = 1;
4126    ec->shade_dir = 0;
4127
4128    evas_object_smart_callback_call(ec->frame, "unshaded", (uintptr_t*)dir);
4129 }
4130
4131 ///////////////////////////////////////
4132
4133 EINTERN void
4134 e_client_maximized_geometry_set(E_Client *ec, int x, int y, int w, int h)
4135 {
4136    if (!ec) return;
4137
4138    ec->maximized_info.x = x;
4139    ec->maximized_info.y = y;
4140    ec->maximized_info.w = w;
4141    ec->maximized_info.h = h;
4142
4143    e_client_frame_geometry_set(ec, x, y, w, h);
4144 }
4145
4146 EINTERN void
4147 e_client_maximized_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
4148 {
4149    if (!ec) return;
4150
4151    if (x) *x = ec->maximized_info.x;
4152    if (y) *y = ec->maximized_info.y;
4153    if (w) *w = ec->maximized_info.w;
4154    if (h) *h = ec->maximized_info.h;
4155 }
4156
4157 EINTERN void
4158 e_client_maximize_update(E_Client *ec)
4159 {
4160    E_Maximize max;
4161
4162    E_OBJECT_CHECK(ec);
4163    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4164
4165    if (ec->maximized)
4166      {
4167         max = ec->maximized;
4168         ec->maximized = 0;
4169         e_client_maximize(ec, max);
4170      }
4171 }
4172
4173 E_API void
4174 e_client_maximize(E_Client *ec, E_Maximize max)
4175 {
4176    E_OBJECT_CHECK(ec);
4177    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4178
4179    if (!(max & E_MAXIMIZE_DIRECTION)) max |= E_MAXIMIZE_BOTH;
4180
4181    if ((ec->shaded) || (ec->shading)) return;
4182
4183    if ((ec->maximized & E_MAXIMIZE_DIRECTION) == (max & E_MAXIMIZE_DIRECTION))
4184      {
4185         if ((ec->maximized & E_MAXIMIZE_TYPE) == (max & E_MAXIMIZE_TYPE))
4186           return;
4187      }
4188
4189    if (ec->new_client)
4190      {
4191         ec->changes.need_maximize = 1;
4192         ec->maximized &= ~E_MAXIMIZE_TYPE;
4193         ec->maximized |= max;
4194         EC_CHANGED(ec);
4195         return;
4196      }
4197
4198    if (!ec->fullscreen)
4199      {
4200         // call the maximize hook of a client
4201         wl_signal_emit_mutable(&PRI(ec)->events.maximize, &max);
4202
4203         // store the E_Maximize value
4204         ec->maximized = max;
4205         ec->changes.need_unmaximize = 0;
4206
4207         evas_object_smart_callback_call(ec->frame, "maximize_done", NULL);
4208      }
4209    else
4210      {
4211         // store the E_Maximize value
4212         ec->maximized = max;
4213         ec->changes.need_unmaximize = 0;
4214      }
4215 }
4216
4217 E_API void
4218 e_client_unmaximize(E_Client *ec, E_Maximize max)
4219 {
4220    E_OBJECT_CHECK(ec);
4221    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4222
4223    if (!(max & E_MAXIMIZE_DIRECTION))
4224      {
4225         CRI("BUG: Unmaximize call without direction!");
4226         return;
4227      }
4228    if (ec->new_client)
4229      {
4230         ec->changes.need_unmaximize = 1;
4231         EC_CHANGED(ec);
4232         return;
4233      }
4234
4235    if ((ec->shaded) || (ec->shading)) return;
4236
4237    /* Remove directions not used */
4238    max &= (ec->maximized & E_MAXIMIZE_DIRECTION);
4239    /* Can only remove existing maximization directions */
4240    if (!max) return;
4241
4242    if (!ec->fullscreen)
4243      {
4244         evas_object_smart_callback_call(ec->frame, "unmaximize_pre", NULL);
4245
4246         // call the unmaximize hook of a client
4247         wl_signal_emit_mutable(&PRI(ec)->events.unmaximize, &max);
4248
4249         evas_object_smart_callback_call(ec->frame, "unmaximize_done", NULL);
4250      }
4251
4252    ec->maximized = E_MAXIMIZE_NONE;
4253    ec->changes.need_unmaximize = 0;
4254 }
4255
4256 EINTERN void
4257 e_client_fullscreen(E_Client *ec, E_Fullscreen policy)
4258 {
4259    E_OBJECT_CHECK(ec);
4260    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4261
4262    if ((ec->shaded) || (ec->shading) || (ec->fullscreen)) return;
4263
4264    // call the fullscreen_pre hook of a client
4265    wl_signal_emit_mutable(&PRI(ec)->events.fullscreen_pre, NULL);
4266    _e_client_hook_call(E_CLIENT_HOOK_FULLSCREEN_PRE, ec);
4267
4268    if (ec->skip_fullscreen) return;
4269    if (ec->new_client)
4270      {
4271         ec->need_fullscreen = 1;
4272         return;
4273      }
4274
4275    ec->saved.layer = ec->layer;
4276    e_client_layer_set(ec, E_LAYER_CLIENT_FULLSCREEN);
4277
4278    ec->fullscreen = 1;
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    ec->need_fullscreen = 0;
4295
4296    if ((ec->shaded) || (ec->shading)) return;
4297    if (!ec->fullscreen) return;
4298
4299    ec->fullscreen = 0;
4300
4301    E_Fullscreen policy = ec->fullscreen_policy;
4302
4303    // call the unfullscreen hook of a client
4304    wl_signal_emit_mutable(&PRI(ec)->events.unfullscreen, &policy);
4305
4306    e_client_layer_set(ec, ec->saved.layer);
4307
4308    ec->fullscreen_policy = E_FULLSCREEN_RESIZE;
4309
4310    _e_client_event_simple(ec, E_EVENT_CLIENT_UNFULLSCREEN);
4311 }
4312
4313 ///////////////////////////////////////
4314 EINTERN Eina_Bool
4315 e_client_is_parent_iconify_by_client(E_Client *ec)
4316 {
4317    E_Client *parent = ec->parent;
4318    if (!parent) return EINA_FALSE;
4319
4320    if ((parent->exp_iconify.type == E_ICONIFIED_TYPE_ICONIFY_BY_CLIENT) ||
4321        (parent->exp_iconify.type == E_ICONIFIED_TYPE_PARENT_ICONIFY_BY_CLIENT))
4322      return EINA_TRUE;
4323
4324    return EINA_FALSE;
4325 }
4326
4327 E_API void
4328 e_client_iconify(E_Client *ec)
4329 {
4330    E_OBJECT_CHECK(ec);
4331    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4332
4333    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
4334    Eina_Bool iconified_by_client = e_client_is_iconified_by_client(ec);
4335
4336    ELOGF("TZVIS", "ICONIFY  |iconic:%d  |argb:%d       |not_raise:%d   |by_client:%d, type:%d",
4337          ec, ec->iconic, ec->argb, (unsigned int)ec->exp_iconify.not_raise,
4338          ec->exp_iconify.by_client, ec->exp_iconify.type);
4339
4340    if (ec->shading || ec->iconic) return;
4341    if (ec->exp_iconify.skip_iconify && !iconified_by_client) return;
4342    if (ec->exp_iconify.skip_by_remote) return;
4343    if (!cdata || !cdata->mapped)
4344      {
4345         if (!iconified_by_client)
4346           {
4347              ELOGF("TZVIS", "Not mapped.. So, don't iconify", ec);
4348              return;
4349           }
4350         else
4351           {
4352              ELOGF("TZVIS", "Not mapped.. But, iconify by user request", ec);
4353           }
4354      }
4355
4356    TRACE_DS_BEGIN(CLIENT:ICONIFY);
4357
4358    wl_signal_emit_mutable(&PRI(ec)->events.iconify, NULL);
4359    _e_client_hook_call(E_CLIENT_HOOK_ICONIFY, ec);
4360
4361    TRACE_DS_END();
4362 }
4363
4364 E_API void
4365 e_client_uniconify(E_Client *ec)
4366 {
4367    E_Comp_Wl_Client_Data *cdata;
4368
4369    E_OBJECT_CHECK(ec);
4370    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4371
4372    cdata = e_client_cdata_get(ec);
4373
4374    ELOGF("TZVIS", "UNICONIFY|iconic:%d  |argb:%d       |not_raise:%d  |by_client:%d, type:%d |mapped:%d",
4375          ec, ec->iconic, ec->argb, (unsigned int)ec->exp_iconify.not_raise,
4376          ec->exp_iconify.by_client, ec->exp_iconify.type,
4377          cdata ? cdata->mapped : 0);
4378
4379    if (ec->shading || (!ec->iconic)) return;
4380
4381    TRACE_DS_BEGIN(CLIENT:UNICONIFY);
4382
4383     // call the uniconify hook of a client
4384    wl_signal_emit_mutable(&PRI(ec)->events.uniconify, NULL);
4385    _e_client_hook_call(E_CLIENT_HOOK_UNICONIFY, ec);
4386
4387    TRACE_DS_END();
4388 }
4389
4390 E_API void
4391 e_client_iconified_type_set(E_Client *ec, E_Iconified_Type type)
4392 {
4393    if (!ec) return;
4394    ec->exp_iconify.type = type;
4395 }
4396
4397 EINTERN E_Iconified_Type
4398 e_client_iconified_type_get(E_Client *ec)
4399 {
4400    if (!ec) return E_ICONIFIED_TYPE_NONE;
4401    return ec->exp_iconify.type;
4402 }
4403
4404 E_API Eina_Bool e_client_is_iconified_by_client(E_Client *ec)
4405 {
4406    if (!ec) return EINA_FALSE;
4407
4408    if (ec->exp_iconify.type == E_ICONIFIED_TYPE_ICONIFY_BY_CLIENT)
4409      return EINA_TRUE;
4410
4411    if (ec->exp_iconify.type == E_ICONIFIED_TYPE_DESK_ICONIFY_BY_CLIENT)
4412      return EINA_TRUE;
4413
4414    if (ec->exp_iconify.type == E_ICONIFIED_TYPE_PARENT_ICONIFY_BY_CLIENT)
4415      return EINA_TRUE;
4416
4417    if (ec->exp_iconify.by_client)
4418      {
4419         ELOGF("POL", "CHECK. mismatch value. by_client:%d, type:%d", ec, ec->exp_iconify.by_client, ec->exp_iconify.type);
4420         return EINA_TRUE;
4421      }
4422
4423    return EINA_FALSE;
4424 }
4425
4426 ///////////////////////////////////////
4427
4428 EINTERN void
4429 e_client_urgent_set(E_Client *ec, Eina_Bool urgent)
4430 {
4431    E_OBJECT_CHECK(ec);
4432    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4433
4434    urgent = !!urgent;
4435    if (urgent == ec->urgent) return;
4436    _e_client_event_property(ec, E_CLIENT_PROPERTY_URGENCY);
4437    if (urgent && (!ec->focused) && (!ec->want_focus))
4438      {
4439         e_comp_object_signal_emit(ec->frame, "e,state,urgent", "e");
4440         ec->urgent = urgent;
4441      }
4442    else
4443      {
4444         e_comp_object_signal_emit(ec->frame, "e,state,not_urgent", "e");
4445         ec->urgent = 0;
4446      }
4447 }
4448
4449 ///////////////////////////////////////
4450
4451 EINTERN void
4452 e_client_stick(E_Client *ec)
4453 {
4454    E_OBJECT_CHECK(ec);
4455    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4456    if (ec->sticky) return;
4457
4458    // call the stick hook of a client
4459    wl_signal_emit_mutable(&PRI(ec)->events.stick, NULL);
4460
4461    // send the sticky property event of a client
4462    _e_client_event_property(ec, E_CLIENT_PROPERTY_STICKY);
4463 }
4464
4465 EINTERN void
4466 e_client_unstick(E_Client *ec)
4467 {
4468    E_OBJECT_CHECK(ec);
4469    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4470
4471    if (!ec->sticky) return;
4472
4473    // call the unstick hook of a client
4474    wl_signal_emit_mutable(&PRI(ec)->events.unstick, NULL);
4475
4476   // send the sticky property event of a client
4477    _e_client_event_property(ec, E_CLIENT_PROPERTY_STICKY);
4478 }
4479
4480 EINTERN void
4481 e_client_pinned_set(E_Client *ec, Eina_Bool set)
4482 {
4483    E_Layer layer;
4484
4485    EINA_SAFETY_ON_NULL_RETURN(ec);
4486    if (set)
4487      layer = E_LAYER_CLIENT_ABOVE;
4488    else
4489      layer = E_LAYER_CLIENT_NORMAL;
4490
4491    e_client_layer_set(ec, layer);
4492
4493    EC_CHANGED(ec);
4494 }
4495
4496 ///////////////////////////////////////
4497
4498 EINTERN Eina_Bool
4499 e_client_border_set(E_Client *ec, const char *name)
4500 {
4501    Eina_Stringshare *pborder;
4502
4503    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
4504    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, EINA_FALSE);
4505    if (!e_comp_object_frame_allowed(ec->frame)) return EINA_FALSE;
4506    if (ec->border.changed)
4507      CRI("CALLING WHEN border.changed SET!");
4508
4509    if (!e_util_strcmp(ec->border.name, name)) return EINA_TRUE;
4510    if (ec->mwm.borderless && name && strcmp(name, "borderless"))
4511      {
4512         CRI("border change attempted for MWM borderless client!");
4513      }
4514    pborder = ec->border.name;
4515    ec->border.name = eina_stringshare_add(name);
4516    if (e_comp_object_frame_theme_set(ec->frame, name))
4517      {
4518         eina_stringshare_del(pborder);
4519         return EINA_TRUE;
4520      }
4521    eina_stringshare_del(ec->border.name);
4522    ec->border.name = pborder;
4523    return EINA_FALSE;
4524 }
4525
4526 ///////////////////////////////////////
4527
4528 EINTERN void
4529 e_client_comp_hidden_set(E_Client *ec, Eina_Bool hidden)
4530 {
4531    E_OBJECT_CHECK(ec);
4532    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4533
4534    hidden = !!hidden;
4535    if (ec->comp_hidden == hidden) return;
4536    ec->comp_hidden = hidden;
4537    evas_object_smart_callback_call(ec->frame, "comp_hidden", NULL);
4538 }
4539
4540 ///////////////////////////////////////
4541
4542 EINTERN void
4543 e_client_act_move_keyboard(E_Client *ec)
4544 {
4545    EINA_SAFETY_ON_NULL_RETURN(ec);
4546
4547    if (!_e_client_move_begin(ec))
4548      return;
4549
4550    _e_client_action_init(ec);
4551    _e_client_action_move_timeout_add();
4552
4553    wl_signal_emit_mutable(&PRI(ec)->events.move_update, NULL);
4554    if (!_e_client_hook_call(E_CLIENT_HOOK_MOVE_UPDATE, ec)) return;
4555    evas_object_freeze_events_set(ec->frame, 1);
4556
4557    if (!action_handler_mouse)
4558      action_handler_mouse = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, _e_client_move_mouse_down, NULL);
4559 }
4560
4561 EINTERN void
4562 e_client_act_resize_keyboard(E_Client *ec)
4563 {
4564    EINA_SAFETY_ON_NULL_RETURN(ec);
4565
4566    ec->resize_mode = E_POINTER_RESIZE_TL;
4567    ec->keyboard_resizing = 1;
4568    if (!e_client_resize_begin(ec))
4569      {
4570         ec->keyboard_resizing = 0;
4571         return;
4572      }
4573
4574    _e_client_action_init(ec);
4575    _e_client_action_resize_timeout_add();
4576    evas_object_freeze_events_set(ec->frame, 1);
4577
4578    if (!action_handler_mouse)
4579      action_handler_mouse = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, _e_client_resize_mouse_down, NULL);
4580 }
4581
4582 EINTERN void
4583 e_client_act_move_begin(E_Client *ec, E_Binding_Event_Mouse_Button *ev)
4584 {
4585    E_OBJECT_CHECK(ec);
4586    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4587    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4588    if (ev)
4589      {
4590         char source[256];
4591
4592         snprintf(source, sizeof(source) - 1, "mouse,down,%i", ev->button);
4593         _e_client_moveinfo_gather(ec, source);
4594      }
4595    if (!_e_client_move_begin(ec))
4596      return;
4597
4598    _e_client_action_init(ec);
4599 }
4600
4601 E_API void
4602 e_client_act_move_end(E_Client *ec, E_Binding_Event_Mouse_Button *ev EINA_UNUSED)
4603 {
4604    E_OBJECT_CHECK(ec);
4605    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4606    if (!ec->moving) return;
4607    _e_client_move_end(ec);
4608    _e_client_action_finish();
4609 }
4610
4611 EINTERN void
4612 e_client_act_resize_begin(E_Client *ec, E_Binding_Event_Mouse_Button *ev, E_Pointer_Mode resize_mode)
4613 {
4614    E_OBJECT_CHECK(ec);
4615    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4616    if (ec->lock_user_size || ec->shaded || ec->shading) return;
4617    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4618    if (ev)
4619      {
4620         char source[256];
4621         snprintf(source, sizeof(source) - 1, "mouse,down,%i", ev->button);
4622         _e_client_moveinfo_gather(ec, source);
4623
4624         if (resize_mode != E_POINTER_RESIZE_NONE)
4625           {
4626              ec->resize_mode = resize_mode;
4627           }
4628         else
4629           {
4630              /* Use canvas.x, canvas.y of event.
4631               * Transformed coordinates has to be considered for accurate resize_mode
4632               * rather than absolute coordinates. */
4633              if ((ev->canvas.x > (ec->x + ec->w / 5)) &&
4634                  (ev->canvas.x < (ec->x + ec->w * 4 / 5)))
4635                {
4636                   if (ev->canvas.y < (ec->y + ec->h / 2)) ec->resize_mode = E_POINTER_RESIZE_T;
4637                   else ec->resize_mode = E_POINTER_RESIZE_B;
4638                }
4639              else if (ev->canvas.x < (ec->x + ec->w / 2))
4640                {
4641                   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;
4642                   else if (ev->canvas.y < (ec->y + ec->h / 2)) ec->resize_mode = E_POINTER_RESIZE_TL;
4643                   else ec->resize_mode = E_POINTER_RESIZE_BL;
4644                }
4645              else
4646                {
4647                   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;
4648                   else if (ev->canvas.y < (ec->y + ec->h / 2)) ec->resize_mode = E_POINTER_RESIZE_TR;
4649                   else ec->resize_mode = E_POINTER_RESIZE_BR;
4650                }
4651           }
4652      }
4653    if (!e_client_resize_begin(ec))
4654      return;
4655    _e_client_action_init(ec);
4656 }
4657
4658 EINTERN void
4659 e_client_act_resize_end(E_Client *ec, E_Binding_Event_Mouse_Button *ev EINA_UNUSED)
4660 {
4661    E_OBJECT_CHECK(ec);
4662    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4663    if (e_client_util_resizing_get(ec))
4664      {
4665         _e_client_resize_end(ec);
4666         ec->changes.reset_gravity = 1;
4667         if (!e_object_is_del(E_OBJECT(ec)))
4668           EC_CHANGED(ec);
4669      }
4670    _e_client_action_finish();
4671 }
4672
4673 EINTERN void
4674 e_client_act_menu_begin(E_Client *ec, E_Binding_Event_Mouse_Button *ev, int key)
4675 {
4676    E_OBJECT_CHECK(ec);
4677    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4678 }
4679
4680 EINTERN void
4681 e_client_act_close_begin(E_Client *ec)
4682 {
4683    E_OBJECT_CHECK(ec);
4684    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4685    if (ec->lock_close) return;
4686    if (ec->icccm.delete_request)
4687      {
4688         ec->delete_requested = 1;
4689         evas_object_smart_callback_call(ec->frame, "delete_request", NULL);
4690      }
4691    else if (e_config->kill_if_close_not_possible)
4692      {
4693         e_client_act_kill_begin(ec);
4694      }
4695 }
4696
4697 EINTERN void
4698 e_client_act_kill_begin(E_Client *ec)
4699 {
4700    E_OBJECT_CHECK(ec);
4701    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4702    if (ec->internal) return;
4703    if (ec->lock_close) return;
4704    if ((ec->netwm.pid > 1) && (e_config->kill_process))
4705      {
4706         kill(ec->netwm.pid, SIGINT);
4707         ec->kill_timer = ecore_timer_add(e_config->kill_timer_wait,
4708                                          _e_client_cb_kill_timer, ec);
4709      }
4710    else
4711      evas_object_smart_callback_call(ec->frame, "kill_request", NULL);
4712 }
4713
4714 ////////////////////////////////////////////
4715
4716 EINTERN void
4717 e_client_ping(E_Client *ec)
4718 {
4719    E_OBJECT_CHECK(ec);
4720    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4721
4722    if (!e_config->ping_clients) return;
4723
4724    EINA_SAFETY_ON_TRUE_RETURN(e_object_is_del(E_OBJECT(ec)));
4725
4726    ec->ping_ok = 0;
4727    evas_object_smart_callback_call(ec->frame, "ping", NULL);
4728    ec->ping = ecore_loop_time_get();
4729    if (ec->ping_poller) ecore_poller_del(ec->ping_poller);
4730    ec->ping_poller = ecore_poller_add(ECORE_POLLER_CORE,
4731                                       e_config->ping_clients_interval,
4732                                       _e_client_cb_ping_poller, ec);
4733 }
4734
4735 ////////////////////////////////////////////
4736 E_API void
4737 e_client_cursor_map_apply(E_Client *ec, int rotation, int x, int y)
4738 {
4739    // TODO: remove(deprecate) this e_client_cursor_map_apply.
4740 }
4741
4742 EINTERN void
4743 e_client_move_cancel(void)
4744 {
4745    if (!ecmove) return;
4746    if (ecmove->cur_mouse_action)
4747      {
4748         E_Client *ec;
4749
4750         ec = ecmove;
4751         e_object_ref(E_OBJECT(ec));
4752         if (ec->cur_mouse_action->func.end_mouse)
4753           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", NULL);
4754         else if (ec->cur_mouse_action->func.end)
4755           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
4756         e_object_unref(E_OBJECT(ec->cur_mouse_action));
4757         ec->cur_mouse_action = NULL;
4758         e_object_unref(E_OBJECT(ec));
4759      }
4760    else
4761      _e_client_move_end(ecmove);
4762 }
4763
4764 EINTERN void
4765 e_client_resize_cancel(void)
4766 {
4767    if (!ecresize) return;
4768    if (ecresize->cur_mouse_action)
4769      {
4770         E_Client *ec;
4771
4772         ec = ecresize;
4773         e_object_ref(E_OBJECT(ec));
4774         if (ec->cur_mouse_action->func.end_mouse)
4775           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", NULL);
4776         else if (ec->cur_mouse_action->func.end)
4777           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
4778         e_object_unref(E_OBJECT(ec->cur_mouse_action));
4779         ec->cur_mouse_action = NULL;
4780         e_object_unref(E_OBJECT(ec));
4781      }
4782    else
4783      _e_client_resize_end(ecresize);
4784 }
4785
4786 EINTERN Eina_Bool
4787 e_client_resize_begin(E_Client *ec)
4788 {
4789    if ((ec->shaded) || (ec->shading) ||
4790        (ec->fullscreen) || (ec->lock_user_size))
4791      goto error;
4792    if (!_e_client_action_input_win_new()) goto error;
4793    ecresize = ec;
4794    if (ec->manage_resize.enable_aspect_ratio)
4795      {
4796         ELOGF("RESIZE", "Set resize aspect ratio.. ratio(%dx%d)", ec, ec->w, ec->h);
4797         ec->manage_resize.aw = ec->w;
4798         ec->manage_resize.ah = ec->h - ec->manage_resize.header_h - ec->manage_resize.footer_h;
4799      }
4800
4801    wl_signal_emit_mutable(&PRI(ec)->events.move_begin, NULL);
4802    _e_client_hook_call(E_CLIENT_HOOK_RESIZE_BEGIN, ec);
4803    if (ec->transformed)
4804      _e_client_transform_resize_begin(ec);
4805    if (!e_client_util_resizing_get(ec))
4806      {
4807         if (ecresize == ec) ecresize = NULL;
4808         _e_client_action_input_win_del();
4809         return EINA_FALSE;
4810      }
4811    if (!ec->lock_user_stacking)
4812      {
4813         if (e_config->border_raise_on_mouse_action)
4814           e_client_raise(ec);
4815      }
4816
4817    if (e_comp->hwc)
4818      e_comp_client_override_add(ec);
4819
4820    return EINA_TRUE;
4821 error:
4822    ec->resize_mode = E_POINTER_RESIZE_NONE;
4823    return EINA_FALSE;
4824 }
4825
4826
4827 ////////////////////////////////////////////
4828
4829 EINTERN void
4830 e_client_frame_recalc(E_Client *ec)
4831 {
4832    EINA_SAFETY_ON_NULL_RETURN(ec);
4833    if (!ec->frame) return;
4834    evas_object_smart_callback_call(ec->frame, "frame_recalc", NULL);
4835 }
4836
4837 ////////////////////////////////////////////
4838
4839 EINTERN void
4840 e_client_signal_move_begin(E_Client *ec, const char *sig, const char *src EINA_UNUSED)
4841 {
4842    E_OBJECT_CHECK(ec);
4843    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4844
4845    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4846    _e_client_moveinfo_gather(ec, sig);
4847    if (!_e_client_move_begin(ec)) return;
4848 }
4849
4850 EINTERN void
4851 e_client_signal_move_end(E_Client *ec, const char *sig EINA_UNUSED, const char *src EINA_UNUSED)
4852 {
4853    E_OBJECT_CHECK(ec);
4854    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4855    if (!ec->moving) return;
4856    _e_client_move_end(ec);
4857 }
4858
4859 EINTERN void
4860 e_client_signal_resize_begin(E_Client *ec, const char *dir, const char *sig, const char *src EINA_UNUSED)
4861 {
4862    int resize_mode = E_POINTER_RESIZE_BR;
4863
4864    E_OBJECT_CHECK(ec);
4865    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4866
4867    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4868    if (!strcmp(dir, "tl"))
4869      {
4870         resize_mode = E_POINTER_RESIZE_TL;
4871      }
4872    else if (!strcmp(dir, "t"))
4873      {
4874         resize_mode = E_POINTER_RESIZE_T;
4875      }
4876    else if (!strcmp(dir, "tr"))
4877      {
4878         resize_mode = E_POINTER_RESIZE_TR;
4879      }
4880    else if (!strcmp(dir, "r"))
4881      {
4882         resize_mode = E_POINTER_RESIZE_R;
4883      }
4884    else if (!strcmp(dir, "br"))
4885      {
4886         resize_mode = E_POINTER_RESIZE_BR;
4887      }
4888    else if (!strcmp(dir, "b"))
4889      {
4890         resize_mode = E_POINTER_RESIZE_B;
4891      }
4892    else if (!strcmp(dir, "bl"))
4893      {
4894         resize_mode = E_POINTER_RESIZE_BL;
4895      }
4896    else if (!strcmp(dir, "l"))
4897      {
4898         resize_mode = E_POINTER_RESIZE_L;
4899      }
4900    ec->resize_mode = resize_mode;
4901    _e_client_moveinfo_gather(ec, sig);
4902    if (!e_client_resize_begin(ec))
4903      return;
4904 }
4905
4906 EINTERN void
4907 e_client_signal_resize_end(E_Client *ec, const char *dir EINA_UNUSED, const char *sig EINA_UNUSED, const char *src EINA_UNUSED)
4908 {
4909    E_OBJECT_CHECK(ec);
4910    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4911    if (!e_client_util_resizing_get(ec)) return;
4912    _e_client_resize_handle(ec);
4913    _e_client_resize_end(ec);
4914    ec->changes.reset_gravity = 1;
4915    EC_CHANGED(ec);
4916 }
4917
4918 ////////////////////////////////////////////
4919
4920 EINTERN void
4921 e_client_resize_limit(E_Client *ec, int *w, int *h)
4922 {
4923    double a;
4924    Eina_Bool inc_h;
4925
4926    E_OBJECT_CHECK(ec);
4927    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4928
4929    inc_h = (*h - ec->h > 0);
4930    if (ec->frame)
4931      e_comp_object_frame_wh_unadjust(ec->frame, *w, *h, w, h);
4932    if (*h < 1) *h = 1;
4933    if (*w < 1) *w = 1;
4934    if ((ec->icccm.base_w >= 0) &&
4935        (ec->icccm.base_h >= 0))
4936      {
4937         int tw, th;
4938
4939         tw = *w - ec->icccm.base_w;
4940         th = *h - ec->icccm.base_h;
4941         if (tw < 1) tw = 1;
4942         if (th < 1) th = 1;
4943         a = (double)(tw) / (double)(th);
4944         if ((ec->icccm.min_aspect != 0.0) &&
4945             (a < ec->icccm.min_aspect))
4946           {
4947              if (inc_h)
4948                tw = th * ec->icccm.min_aspect;
4949              else
4950                th = tw / ec->icccm.max_aspect;
4951              *w = tw + ec->icccm.base_w;
4952              *h = th + ec->icccm.base_h;
4953           }
4954         else if ((ec->icccm.max_aspect != 0.0) &&
4955                  (a > ec->icccm.max_aspect))
4956           {
4957              tw = th * ec->icccm.max_aspect;
4958              *w = tw + ec->icccm.base_w;
4959           }
4960      }
4961    else
4962      {
4963         a = (double)*w / (double)*h;
4964         if ((ec->icccm.min_aspect != 0.0) &&
4965             (a < ec->icccm.min_aspect))
4966           {
4967              if (inc_h)
4968                *w = *h * ec->icccm.min_aspect;
4969              else
4970                *h = *w / ec->icccm.min_aspect;
4971           }
4972         else if ((ec->icccm.max_aspect != 0.0) &&
4973                  (a > ec->icccm.max_aspect))
4974           *w = *h * ec->icccm.max_aspect;
4975      }
4976    if (ec->icccm.step_w > 0)
4977      {
4978         if (ec->icccm.base_w >= 0)
4979           *w = ec->icccm.base_w +
4980             (((*w - ec->icccm.base_w) / ec->icccm.step_w) *
4981              ec->icccm.step_w);
4982         else
4983           *w = ec->icccm.min_w +
4984             (((*w - ec->icccm.min_w) / ec->icccm.step_w) *
4985              ec->icccm.step_w);
4986      }
4987    if (ec->icccm.step_h > 0)
4988      {
4989         if (ec->icccm.base_h >= 0)
4990           *h = ec->icccm.base_h +
4991             (((*h - ec->icccm.base_h) / ec->icccm.step_h) *
4992              ec->icccm.step_h);
4993         else
4994           *h = ec->icccm.min_h +
4995             (((*h - ec->icccm.min_h) / ec->icccm.step_h) *
4996              ec->icccm.step_h);
4997      }
4998
4999    if (*h < 1) *h = 1;
5000    if (*w < 1) *w = 1;
5001
5002    if ((ec->icccm.max_w > 0) && (*w > ec->icccm.max_w)) *w = ec->icccm.max_w;
5003    else if (*w < ec->icccm.min_w)
5004      *w = ec->icccm.min_w;
5005    if ((ec->icccm.max_h > 0) && (*h > ec->icccm.max_h)) *h = ec->icccm.max_h;
5006    else if (*h < ec->icccm.min_h)
5007      *h = ec->icccm.min_h;
5008
5009    if (ec->frame)
5010      e_comp_object_frame_wh_adjust(ec->frame, *w, *h, w, h);
5011 }
5012
5013 ////////////////////////////////////////////
5014
5015
5016
5017 EINTERN E_Client *
5018 e_client_under_pointer_get(E_Desk *desk, E_Client *exclude)
5019 {
5020    int x, y;
5021
5022    /* We need to ensure that we can get the comp window for the
5023     * zone of either the given desk or the desk of the excluded
5024     * window, so return if neither is given */
5025    if (desk)
5026      e_input_device_pointer_xy_get(NULL, &x, &y);
5027    else if (exclude)
5028      e_input_device_pointer_xy_get(NULL, &x, &y);
5029    else
5030      return NULL;
5031
5032    if (!desk)
5033      {
5034         desk = exclude->desk;
5035         if (!desk)
5036           {
5037              if (exclude->zone)
5038                desk = e_desk_current_get(exclude->zone);
5039              else
5040                desk = e_desk_current_get(e_zone_current_get());
5041           }
5042      }
5043
5044    return desk ? _e_client_under_pointer_helper(desk, exclude, x, y) : NULL;
5045 }
5046
5047 E_API E_Client *e_client_under_position_get(E_Desk *desk, int x, int y, E_Client *exclude)
5048 {
5049    if (!desk) return NULL;
5050
5051    return _e_client_under_pointer_helper(desk, exclude, x, y);
5052 }
5053
5054 E_API E_Client *e_client_under_position_input_get(E_Desk *desk, int x, int y)
5055 {
5056    if (!desk) return NULL;
5057
5058    return _e_client_under_pointer_input_helper(desk, x, y);
5059 }
5060
5061 ////////////////////////////////////////////
5062
5063 ////////////////////////////////////////////
5064
5065 E_API void
5066 e_client_redirected_set(E_Client *ec, Eina_Bool set)
5067 {
5068    EINA_SAFETY_ON_NULL_RETURN(ec);
5069    if (ec->input_only) return;
5070    set = !!set;
5071    if (ec->redirected == set) return;
5072    if (set)
5073      {
5074         e_client_frame_recalc(ec);
5075
5076         wl_signal_emit_mutable(&PRI(ec)->events.redirect, NULL);
5077         if (!_e_client_hook_call(E_CLIENT_HOOK_REDIRECT, ec)) return;
5078      }
5079    else
5080      {
5081         wl_signal_emit_mutable(&PRI(ec)->events.unredirect, NULL);
5082         if (!_e_client_hook_call(E_CLIENT_HOOK_UNREDIRECT, ec)) return;
5083      }
5084    e_comp_object_redirected_set(ec->frame, set);
5085    ec->redirected = !!set;
5086 }
5087
5088 ////////////////////////////////////////////
5089
5090 EINTERN Eina_Bool
5091 e_client_is_stacking(const E_Client *ec)
5092 {
5093    return e_comp->layers[e_comp_canvas_layer_map(ec->layer)].obj == ec->frame;
5094 }
5095
5096 ////////////////////////////////////////////
5097
5098 E_API void
5099 e_client_transform_update(E_Client *ec)
5100 {
5101    if (e_client_util_resizing_get(ec))
5102      _e_client_transform_resize(ec);
5103 }
5104
5105 ////////////////////////////////////////////
5106
5107 EINTERN void
5108 e_client_transform_apply(E_Client *ec, double angle, double zoom, int cx, int cy)
5109 {
5110    E_Map *map;
5111    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
5112    E_Client *subc;
5113    Eina_List *l;
5114
5115    if (e_comp_wl_subsurface_check(ec))
5116      return;
5117
5118    /* check if it's different with current state */
5119    if ((ec->transform.angle == angle) &&
5120        (ec->transform.zoom == zoom) &&
5121        (ec->transform.center.x == cx) &&
5122        (ec->transform.center.y == cy))
5123      return;
5124
5125    /* use previous value if any required value is invalid */
5126    if (angle == -1.0)
5127      angle = ec->transform.angle;
5128    if (zoom == -1.0)
5129      zoom = ec->transform.zoom;
5130    if (!E_INSIDE(cx, cy,
5131                  ec->client.x, ec->client.y,
5132                  ec->client.w, ec->client.h))
5133      {
5134         cx = ec->transform.center.x;
5135         cy = ec->transform.center.y;
5136      }
5137
5138    if ((angle == 0) && (zoom == 1.0))
5139      {
5140         e_client_transform_clear(ec);
5141         return;
5142      }
5143
5144    map = e_map_new_with_direct_render(ec->transform_core.direct_render);
5145    e_map_util_points_populate_from_object_full(map, ec->frame, 0);
5146
5147    e_map_util_rotate(map, angle, cx, cy);
5148    _e_client_transform_geometry_save(ec, map);
5149
5150    e_map_util_zoom(map, zoom, zoom, cx, cy);
5151
5152    e_map_util_object_move_sync_set(map, EINA_TRUE);
5153    e_client_map_set(ec, map);
5154    e_client_map_enable_set(ec, EINA_TRUE);
5155
5156    EINA_LIST_FOREACH(cdata->sub.list, l, subc)
5157      _e_client_transform_sub_apply(subc, ec, zoom);
5158    EINA_LIST_REVERSE_FOREACH(cdata->sub.below_list, l, subc)
5159      _e_client_transform_sub_apply(subc, ec, zoom);
5160
5161    e_map_free(map);
5162
5163    ec->transform.zoom = zoom;
5164    ec->transform.angle = angle;
5165    ec->transform.center.x = cx;
5166    ec->transform.center.y = cy;
5167    ec->transformed = EINA_TRUE;
5168 }
5169
5170 ////////////////////////////////////////////
5171
5172 EINTERN void
5173 e_client_transform_clear(E_Client *ec)
5174 {
5175    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
5176    E_Client *subc;
5177    Eina_List *l;
5178
5179    e_client_map_enable_set(ec, EINA_FALSE);
5180    e_client_map_set(ec, NULL);
5181
5182    EINA_LIST_FOREACH(cdata->sub.list, l, subc)
5183      _e_client_transform_sub_apply(subc, ec, 1.0);
5184    EINA_LIST_REVERSE_FOREACH(cdata->sub.below_list, l, subc)
5185      _e_client_transform_sub_apply(subc, ec, 1.0);
5186
5187    ec->transform.zoom = 1.0;
5188    ec->transform.angle = 0.0;
5189    ec->transformed = EINA_FALSE;
5190 }
5191
5192 E_API Eina_Bool
5193 e_client_transform_core_enable_get(E_Client *ec)
5194 {
5195    if (!ec) return EINA_FALSE;
5196    return ec->transform_core.result.enable;
5197 }
5198
5199 E_API void
5200 e_client_transform_core_add(E_Client *ec, E_Util_Transform *transform)
5201 {
5202    if (!ec) return;
5203    if (!transform) return;
5204
5205    // duplication check
5206    if (ec->transform_core.transform_list &&
5207        eina_list_data_find(ec->transform_core.transform_list, transform) == transform)
5208      {
5209         return;
5210      }
5211
5212    ec->transform_core.transform_list = eina_list_append(ec->transform_core.transform_list, transform);
5213    ec->transform_core.changed = EINA_TRUE;
5214    e_util_transform_ref(transform);
5215   // e_client_transform_core_update(ec);
5216 }
5217
5218 E_API void
5219 e_client_transform_core_remove(E_Client *ec, E_Util_Transform *transform)
5220 {
5221    if (!ec) return;
5222    if (!transform) return;
5223
5224    if (ec->transform_core.transform_list &&
5225        eina_list_data_find(ec->transform_core.transform_list, transform) == transform)
5226      {
5227         ec->transform_core.transform_list = eina_list_remove(ec->transform_core.transform_list, transform);
5228         e_util_transform_unref(transform);
5229         ec->transform_core.changed = EINA_TRUE;
5230      }
5231
5232    e_client_transform_core_update(ec);
5233 }
5234
5235 E_API void
5236 e_client_transform_core_update(E_Client *ec)
5237 {
5238    if (!ec) return;
5239    if (ec->new_client) return;
5240    if (!_e_client_transform_core_check_change(ec)) return;
5241
5242    if (ec->transform_core.transform_list || ec->transform_core.parent.enable)
5243      {
5244         E_Util_Transform_Rect source_rect;
5245         E_Util_Transform_Matrix matrix, boundary_matrix;
5246         E_Util_Transform_Zoom zoom;
5247         Eina_List *l;
5248         Eina_Bool background;
5249         E_Util_Transform *temp_trans;
5250
5251         // 1. init state
5252         ec->transform_core.result.enable = EINA_TRUE;
5253         e_util_transform_rect_client_rect_get(&source_rect, ec);
5254         e_util_transform_init(&ec->transform_core.result.transform);
5255
5256         // 2. merge transform
5257         EINA_LIST_FOREACH(ec->transform_core.transform_list, l, temp_trans)
5258           {
5259              e_util_transform_merge(&ec->transform_core.result.transform, temp_trans);
5260           }
5261         zoom = ec->transform_core.result.transform.zoom;
5262
5263         // 2.5 check viewport
5264         if (e_util_transform_viewport_flag_get(&ec->transform_core.result.transform))
5265           {
5266              int vx = 0, vy = 0, vw = 0, vh = 0;
5267              e_util_transform_viewport_get(&ec->transform_core.result.transform, &vx, &vy, &vw, &vh);
5268              e_util_transform_rect_init(&source_rect, vx, vy, vw, vh);
5269           }
5270
5271         // 3. apply background transform
5272         matrix = e_util_transform_convert_to_matrix(&ec->transform_core.result.transform, &source_rect);
5273
5274         if (e_util_transform_bg_transform_flag_get(&ec->transform_core.result.transform))
5275           {
5276              boundary_matrix = e_util_transform_bg_convert_to_matrix(&ec->transform_core.result.transform, &source_rect);
5277              background = EINA_TRUE;
5278           }
5279         else
5280           {
5281              background = EINA_FALSE;
5282              boundary_matrix = matrix;
5283           }
5284
5285         if (background != ec->transform_core.background)
5286           {
5287              if (background)
5288                {
5289                   e_comp_object_transform_bg_set(ec->frame, EINA_TRUE);
5290                }
5291              else
5292                {
5293                   e_comp_object_transform_bg_set(ec->frame, EINA_FALSE);
5294                }
5295
5296              ec->transform_core.background = background;
5297           }
5298
5299         // 3.1 if 24bit window then set transp rect
5300         if (!ec->argb)
5301           {
5302              int angle = 0;
5303
5304              e_util_transform_rotation_round_get(&ec->transform_core.result.transform, 0, 0, &angle);
5305              angle %= 90;
5306
5307              if (angle == 0) // when transform angle is 0, 90, 180, 270, 360. then set transp rect
5308                e_comp_object_transform_transp_set(ec->frame, EINA_TRUE);
5309              else
5310                e_comp_object_transform_transp_set(ec->frame, EINA_FALSE);
5311           }
5312         else
5313           e_comp_object_transform_transp_set(ec->frame, EINA_FALSE);
5314
5315         // 3.5 parent matrix multiply
5316         if (ec->transform_core.parent.enable)
5317           {
5318              matrix = e_util_transform_matrix_multiply(&ec->transform_core.parent.matrix,
5319                                                        &matrix);
5320              boundary_matrix = e_util_transform_matrix_multiply(&ec->transform_core.parent.matrix,
5321                                                                 &boundary_matrix);
5322
5323              ec->transform_core.result.transform.use_zoom = EINA_TRUE;
5324              zoom.zoom_x *= ec->transform_core.parent.zoom.zoom_x;
5325              zoom.zoom_y *= ec->transform_core.parent.zoom.zoom_y;
5326              zoom.cx += ec->transform_core.parent.zoom.cx;
5327              zoom.cy += ec->transform_core.parent.zoom.cy;
5328           }
5329
5330         // 4. apply matrix to vertices
5331         ec->transform_core.result.matrix = matrix;
5332         ec->transform_core.result.inv_matrix = e_util_transform_matrix_inverse_get(&matrix);
5333         ec->transform_core.result.vertices = e_util_transform_rect_to_vertices(&source_rect);
5334         ec->transform_core.result.boundary.vertices = e_util_transform_rect_to_vertices(&source_rect);
5335         ec->transform_core.result.vertices = e_util_transform_matrix_multiply_rect_vertex(&matrix,
5336                                                                                           &ec->transform_core.result.vertices);
5337         ec->transform_core.result.boundary.vertices = e_util_transform_matrix_multiply_rect_vertex(&boundary_matrix,
5338                                                                                                    &ec->transform_core.result.boundary.vertices);
5339         ec->transform_core.result.transform.zoom = zoom;
5340
5341         // 5. apply vertices
5342         if (ec->transform_core.result.transform.use_zoom)
5343           {
5344              // TODO: apply zoom values to vertices
5345              e_comp_object_transform_transp_vertices_set_with_zoom(ec->frame, &ec->transform_core.result.vertices,
5346                                                                    ec->transform_core.result.transform.zoom);
5347              e_comp_object_transform_bg_vertices_set_with_zoom(ec->frame, &ec->transform_core.result.boundary.vertices,
5348                                                                ec->transform_core.result.transform.zoom);
5349              _e_client_transform_core_boundary_update(ec, &ec->transform_core.result.boundary.vertices);
5350              _e_client_transform_core_vertices_apply_with_zoom(ec, ec->frame, &ec->transform_core.result.vertices, &ec->transform_core.result.transform,
5351                                                                ec->transform_core.result.transform.zoom);
5352           }
5353         else
5354           {
5355              e_comp_object_transform_transp_vertices_set(ec->frame, &ec->transform_core.result.vertices);
5356              e_comp_object_transform_bg_vertices_set(ec->frame, &ec->transform_core.result.boundary.vertices);
5357              _e_client_transform_core_boundary_update(ec, &ec->transform_core.result.boundary.vertices);
5358              _e_client_transform_core_vertices_apply(ec, ec->frame, &ec->transform_core.result.vertices, &ec->transform_core.result.transform);
5359           }
5360
5361         // 6. subsurface update
5362         _e_client_transform_core_sub_update(ec, &ec->transform_core.result.vertices);
5363
5364         if (!e_object_is_del(E_OBJECT(ec)))
5365           {
5366              wl_signal_emit_mutable(&PRI(ec)->events.transform_change, NULL);
5367              _e_client_hook_call(E_CLIENT_HOOK_TRANSFORM_CHANGE, ec);
5368           }
5369      }
5370    else
5371      {
5372         if (ec->transform_core.result.enable)
5373           {
5374              ec->transform_core.result.enable = EINA_FALSE;
5375              _e_client_transform_core_vertices_apply(ec, ec->frame, NULL, NULL);
5376              e_comp_object_transform_bg_set(ec->frame, EINA_FALSE);
5377              ec->transform_core.background = EINA_FALSE;
5378              e_comp_object_transform_transp_set(ec->frame, EINA_FALSE);
5379              _e_client_transform_core_sub_update(ec, NULL);
5380
5381              if (!e_object_is_del(E_OBJECT(ec)))
5382                {
5383                   wl_signal_emit_mutable(&PRI(ec)->events.transform_change, NULL);
5384                   _e_client_hook_call(E_CLIENT_HOOK_TRANSFORM_CHANGE, ec);
5385                }
5386           }
5387      }
5388
5389    e_comp_visibility_calculation_set(EINA_TRUE);
5390 }
5391
5392 E_API int
5393 e_client_transform_core_transform_count_get(E_Client *ec)
5394 {
5395    if (!ec) return 0;
5396    if (!ec->transform_core.transform_list) return 0;
5397    return eina_list_count(ec->transform_core.transform_list);
5398 }
5399
5400 E_API E_Util_Transform*
5401 e_client_transform_core_transform_get(E_Client *ec, int index)
5402 {
5403    if (!ec) return NULL;
5404    if (!ec->transform_core.transform_list) return NULL;
5405    if (index < 0 || index >= e_client_transform_core_transform_count_get(ec))
5406       return NULL;
5407
5408    return (E_Util_Transform*)eina_list_nth(ec->transform_core.transform_list, index);
5409 }
5410
5411 E_API void
5412 e_client_transform_core_input_transform(E_Client *ec, int x, int y, int *out_x, int *out_y)
5413 {
5414    E_Util_Transform_Vertex vertex, result_vertex;
5415
5416    if (!ec) return;
5417    if (!e_client_transform_core_enable_get(ec)) return;
5418
5419    e_util_transform_vertex_init(&vertex, x, y, 0.0, 1.0);
5420
5421    result_vertex = e_util_transform_matrix_multiply_vertex(&ec->transform_core.result.inv_matrix, &vertex);
5422    e_util_transform_vertex_pos_round_get(&result_vertex, out_x, out_y, NULL, NULL);
5423 }
5424
5425 E_API void
5426 e_client_transform_core_input_inv_transform(E_Client *ec, int x, int y, int *out_x, int *out_y)
5427 {
5428    E_Util_Transform_Vertex vertex, result_vertex;
5429
5430    if (!ec) return;
5431    if (!e_client_transform_core_enable_get(ec)) return;
5432
5433    e_util_transform_vertex_init(&vertex, x, y, 0.0, 1.0);
5434
5435    result_vertex = e_util_transform_matrix_multiply_vertex(&ec->transform_core.result.matrix, &vertex);
5436    e_util_transform_vertex_pos_round_get(&result_vertex, out_x, out_y, NULL, NULL);
5437 }
5438
5439 EINTERN void
5440 e_client_transform_core_input_inv_rect_transform(E_Client *ec, int x, int y, int *out_x, int *out_y)
5441 {
5442    int gw = 0, gh = 0;
5443    if (!ec) return;
5444    if (!e_client_transform_core_enable_get(ec)) return;
5445    e_client_geometry_get(ec, NULL, NULL, &gw, &gh);
5446
5447    e_util_transform_matrix_inv_rect_coords_get(&ec->transform_core.result.transform,
5448                                                &ec->transform_core.result.vertices,
5449                                                gw, gh,
5450                                                x, y, out_x, out_y);
5451 }
5452
5453 E_API void
5454 e_client_transform_core_direct_render_set(E_Client *ec, Eina_Bool set)
5455 {
5456    EINA_SAFETY_ON_NULL_RETURN(ec);
5457
5458    if (ec->transform_core.direct_render == set) return;
5459
5460    ec->transform_core.direct_render = set;
5461    ec->transform_core.changed = EINA_TRUE;
5462
5463    e_client_transform_core_update(ec);
5464 }
5465
5466 EINTERN E_Pixmap *
5467 e_client_pixmap_change(E_Client *ec, E_Pixmap *newcp)
5468 {
5469    E_Pixmap_Type oldtype, newtype;
5470    E_Pixmap *oldcp;
5471
5472    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
5473    EINA_SAFETY_ON_NULL_RETURN_VAL(ec->pixmap, NULL);
5474    EINA_SAFETY_ON_NULL_RETURN_VAL(newcp, NULL);
5475
5476    oldcp = ec->pixmap;
5477
5478    oldtype = e_pixmap_type_get(oldcp);
5479    if (oldtype >= E_PIXMAP_TYPE_MAX) return NULL;
5480
5481    newtype = e_pixmap_type_get(newcp);
5482    if (newtype >= E_PIXMAP_TYPE_MAX) return NULL;
5483
5484    if (eina_hash_find(clients_hash[oldtype], &oldcp))
5485      eina_hash_del_by_key(clients_hash[oldtype], &oldcp);
5486    e_pixmap_client_set(oldcp, NULL);
5487
5488    ec->pixmap = newcp;
5489    e_pixmap_client_set(newcp, ec);
5490
5491    eina_hash_add(clients_hash[newtype], &newcp, ec);
5492
5493    return oldcp;
5494 }
5495
5496 E_API void
5497 e_client_window_role_set(E_Client *ec, const char *role)
5498 {
5499    EINA_SAFETY_ON_NULL_RETURN(ec);
5500
5501    if (eina_stringshare_replace(&ec->icccm.window_role, role))
5502      {
5503         wl_signal_emit_mutable(&PRI(ec)->events.window_role_change, NULL);
5504         _e_client_hook_call(E_CLIENT_HOOK_WINDOW_ROLE_CHANGE, ec);
5505      }
5506 }
5507
5508 EINTERN Eina_Bool
5509 e_client_key_send(E_Client *ec, int keycode, Eina_Bool pressed, Ecore_Device *dev, unsigned int time)
5510 {
5511    Eina_Bool res;
5512
5513    res = e_comp_wl_key_send(ec, keycode, pressed, dev, time);
5514
5515    return res;
5516 }
5517
5518 EINTERN Eina_Bool
5519 e_client_key_cancel(E_Client *ec, int keycode, Ecore_Device *dev, unsigned int time)
5520 {
5521    Eina_Bool res;
5522
5523    res = e_comp_wl_key_cancel(ec, keycode, dev, time);
5524
5525    return res;
5526 }
5527
5528 EINTERN Eina_Bool
5529 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)
5530 {
5531    Eina_Bool res;
5532
5533    res = e_comp_wl_touch_send(ec, idx, x, y, pressed, dev, radius_x, radius_y, pressure, angle, time);
5534
5535    return res;
5536 }
5537
5538 EINTERN Eina_Bool
5539 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)
5540 {
5541    Eina_Bool res;
5542
5543    res = e_comp_wl_touch_update_send(ec, idx, x, y, dev, radius_x, radius_y, pressure, angle, time);
5544
5545    return res;
5546 }
5547
5548 EINTERN Eina_Bool
5549 e_client_touch_cancel_send(E_Client *ec)
5550 {
5551    Eina_Bool res;
5552
5553    res = e_comp_wl_touch_cancel_send(ec);
5554
5555    return res;
5556 }
5557
5558 EINTERN Eina_Bool
5559 e_client_mouse_button_send(E_Client *ec, int buttons, Eina_Bool pressed, Ecore_Device *dev, unsigned int time)
5560 {
5561    Eina_Bool res;
5562
5563    res = e_comp_wl_mouse_button_send(ec, buttons, pressed, dev, time);
5564
5565    return res;
5566 }
5567
5568 EINTERN Eina_Bool
5569 e_client_mouse_move_send(E_Client *ec, int x, int y, Ecore_Device *dev, unsigned int time)
5570 {
5571    Eina_Bool res;
5572
5573    res = e_comp_wl_mouse_move_send(ec, x, y, dev, time);
5574
5575    return res;
5576 }
5577
5578 EINTERN Eina_Bool
5579 e_client_mouse_wheel_send(E_Client *ec, int direction, int z, Ecore_Device *dev, unsigned int time)
5580 {
5581    Eina_Bool res;
5582
5583    res = e_comp_wl_mouse_wheel_send(ec, direction, z, dev, time);
5584
5585    return res;
5586 }
5587
5588 EINTERN Eina_Bool
5589 e_client_mouse_in_send(E_Client *ec, int x, int y, Ecore_Device *dev, unsigned int time)
5590 {
5591    Eina_Bool res;
5592
5593    res = e_comp_wl_mouse_in_send(ec, x, y, dev, time);
5594
5595    return res;
5596 }
5597
5598 EINTERN Eina_Bool
5599 e_client_mouse_out_send(E_Client *ec, Ecore_Device *dev, unsigned int time)
5600 {
5601    Eina_Bool res;
5602
5603    res = e_comp_wl_mouse_out_send(ec, dev, time);
5604
5605    return res;
5606 }
5607
5608 E_API Eina_Bool
5609 e_client_video_client_has(E_Client *ec)
5610 {
5611    return e_comp_wl_video_subsurface_has(ec);
5612 }
5613
5614 E_API Eina_Bool
5615 e_client_normal_client_has(E_Client *ec)
5616 {
5617    return e_comp_wl_normal_subsurface_has(ec);
5618 }
5619
5620 E_API Eina_Bool
5621 e_client_cursor_hide(E_Client *ec)
5622 {
5623    return e_comp_wl_cursor_hide(ec);
5624 }
5625
5626 E_API void
5627 e_client_visibility_force_obscured_set(E_Client *ec, Eina_Bool set)
5628 {
5629    if (!ec) return;
5630
5631    ELOGF("TZVIS", "VIS_FORCE_OBSCURED :%d", ec, set);
5632
5633    ec->visibility.force_obscured = set;
5634    e_comp_visibility_calculation_set(EINA_TRUE);
5635 }
5636
5637 EINTERN E_Capture_Save_State
5638 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)
5639 {
5640    return e_comp_wl_capture_client_image_save(ec, dir, name, func_end, data, skip_child);
5641 }
5642
5643 static void
5644 _e_client_base_output_resolution_hook_subsurf_create(void *data, E_Client *subc)
5645 {
5646    E_Client *ec, *parent;
5647
5648    ec = data;
5649    if (ec != subc)
5650      return;
5651
5652    ec->base_output_resolution.use = 0;
5653    ec->base_output_resolution.w = 0;
5654    ec->base_output_resolution.h = 0;
5655    if (ec->base_output_resolution.transform)
5656      {
5657         e_client_transform_core_remove(ec, ec->base_output_resolution.transform);
5658         E_FREE_FUNC(ec->base_output_resolution.transform, e_util_transform_del);
5659         ELOGF("POL_APPINFO", "Cancel TRANSFORM for subsurface", ec);
5660      }
5661
5662    /* Update transform for toplevel surface.
5663     * The transform of subsurface will be updated by its parent accordingly. */
5664    parent = e_comp_wl_topmost_parent_get(ec);
5665    if (parent)
5666      {
5667         parent->transform_core.changed = EINA_TRUE;
5668         e_client_transform_core_update(parent);
5669      }
5670
5671    /* TODO: Do we need to apply it again if subsurface is destroyed? */
5672 }
5673
5674 static void
5675 _e_client_base_output_resolution_set(E_Client *ec, int width, int height)
5676 {
5677    if (!ec) return;
5678    ec->base_output_resolution.use = 1;
5679    ec->base_output_resolution.w = width;
5680    ec->base_output_resolution.h = height;
5681    ec->base_output_resolution.transform = e_util_transform_new();
5682    e_util_transform_role_set(ec->base_output_resolution.transform, "base_output_resolution");
5683    e_client_transform_core_add(ec, ec->base_output_resolution.transform);
5684
5685    if (!ec->base_output_resolution.hook_subsurf_create)
5686      {
5687         ec->base_output_resolution.hook_subsurf_create =
5688            e_comp_wl_hook_add(E_COMP_WL_HOOK_SUBSURFACE_CREATE,
5689                               _e_client_base_output_resolution_hook_subsurf_create,
5690                               ec);
5691      }
5692 }
5693
5694 E_API void
5695 e_client_base_output_resolution_transform_adjust(E_Client *ec)
5696 {
5697    E_Desk *desk;
5698
5699    EINA_SAFETY_ON_NULL_RETURN(ec);
5700    if (!ec->base_output_resolution.use) return;
5701    if (!ec->base_output_resolution.transform) return;
5702
5703    desk = e_comp_desk_find_by_ec(ec);
5704    EINA_SAFETY_ON_NULL_RETURN(desk);
5705
5706    ELOGF("POL_APPINFO", "Apply TRANSFORM... desk:(%dx%d), ec:(%dx%d)",
5707          ec, desk->geom.w, desk->geom.h, ec->w, ec->h);
5708
5709    e_util_transform_scale(ec->base_output_resolution.transform,
5710                           (double)desk->geom.w /(double)ec->base_output_resolution.w,
5711                           (double)desk->geom.h /(double)ec->base_output_resolution.h,
5712                           1.0);
5713    e_client_transform_core_update(ec);
5714 }
5715
5716 E_API Eina_Bool
5717 e_client_base_output_resolution_update(E_Client *ec)
5718 {
5719    E_Appinfo *eai = NULL;
5720    int configured_width, configured_height;
5721    int width, height;
5722    E_Desk *desk;
5723
5724    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
5725
5726   if (!e_config->configured_output_resolution.use) return EINA_TRUE;
5727   if (ec->base_output_resolution.use) return EINA_TRUE;
5728
5729   /* Check whether it's subsurface or not
5730    * The resolution of subsurface will follow the resolution of its toplevel surface.
5731    * Transform for subsurface will be applied when toplevel surface does by
5732    * implementation of e_client_transform_core.
5733    */
5734   if (e_comp_wl_subsurface_check(ec))
5735     return EINA_FALSE;
5736
5737    desk = e_comp_desk_find_by_ec(ec);
5738    EINA_SAFETY_ON_NULL_RETURN_VAL(desk, EINA_FALSE);
5739
5740   configured_width = e_config->configured_output_resolution.w;
5741   configured_height = e_config->configured_output_resolution.h;
5742
5743   if (!ec->netwm.pid)
5744     {
5745        ELOGF("POL_APPINFO", "NO PID... USE configured_output_resolution(%d,%d) pid:%d", ec,
5746              configured_width, configured_height, ec->netwm.pid);
5747        goto use_configured;
5748     }
5749
5750    eai = e_appinfo_find_with_pid(ec->netwm.pid);
5751    if (!eai)
5752      {
5753         ELOGF("POL_APPINFO", "NO APPINFO... USE configured_output_resolution(%d,%d) pid:%d", ec,
5754               configured_width, configured_height, ec->netwm.pid);
5755         goto use_configured;
5756      }
5757
5758    if (!e_appinfo_base_output_resolution_get(eai, &width, &height))
5759      {
5760         ELOGF("POL_APPINFO", "NO BASE SCREEN RESOLUTION... USE configured_output_resolution(%d,%d) pid:%d", ec,
5761               configured_width, configured_height, ec->netwm.pid);
5762         goto use_configured;
5763       }
5764
5765    if ((width == 0) && (height == 0))
5766      {
5767         ELOGF("POL_APPINFO", "SKIP SET BASE SCREEN RESOLUTION... base_output_resolution size:(%d,%d) pid:%d", ec, width, height, ec->netwm.pid);
5768         return EINA_TRUE;
5769      }
5770
5771    if ((desk->geom.w == width) && (desk->geom.h == height))
5772      {
5773         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);
5774         return EINA_TRUE;
5775      }
5776
5777    /* set the base_output_resolution of the e_client */
5778    _e_client_base_output_resolution_set(ec, width, height);
5779
5780    ELOGF("POL_APPINFO", "USE base_output_resolution(%d,%d) pid:%d", ec, width, height, ec->netwm.pid);
5781
5782    return EINA_TRUE;
5783
5784 use_configured:
5785
5786    if ((desk->geom.w == configured_width) && (desk->geom.h == configured_height))
5787      {
5788         ELOGF("POL_APPINFO", "SKIP use configured_output_resolution (same with desk size:(%d,%d), pid:%d)", ec, configured_width, configured_height, ec->netwm.pid);
5789      }
5790    else
5791      {
5792         /* set the base_output_resolution of the e_client as a default */
5793         _e_client_base_output_resolution_set(ec, configured_width, configured_height);
5794      }
5795
5796    return EINA_TRUE;
5797 }
5798
5799 E_API Eina_Bool
5800 e_client_base_output_resolution_useful_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
5801 {
5802    int zx, zy, zw, zh;
5803    E_Zone *zone;
5804
5805    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
5806
5807    zone = e_comp_zone_find_by_ec(ec);
5808    EINA_SAFETY_ON_NULL_RETURN_VAL(zone, EINA_FALSE);
5809
5810    e_zone_useful_geometry_get(zone, &zx, &zy, &zw, &zh);
5811
5812    if (x) *x = zx;
5813    if (y) *y = zy;
5814    if (w) *w = zw;
5815    if (h) *h = zh;
5816
5817    if (ec->base_output_resolution.use)
5818      {
5819         if (w) *w = ec->base_output_resolution.w;
5820         if (h) *h = ec->base_output_resolution.h;
5821      }
5822
5823    return EINA_TRUE;
5824 }
5825
5826 E_API Eina_Bool
5827 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)
5828 {
5829    int zx, zy, zw, zh;
5830    E_Zone *zone;
5831
5832    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
5833
5834    zone = e_comp_zone_find_by_ec(ec);
5835    EINA_SAFETY_ON_NULL_RETURN_VAL(zone, EINA_FALSE);
5836
5837    e_zone_desk_useful_geometry_get(zone, ec->desk, &zx, &zy, &zw, &zh, consider_obstacle_area);
5838
5839    if (x) *x = zx;
5840    if (y) *y = zy;
5841    if (w) *w = zw;
5842    if (h) *h = zh;
5843
5844    if (ec->base_output_resolution.use)
5845      {
5846         // TODO: Consider obstacle area
5847         if (w) *w = ec->base_output_resolution.w;
5848         if (h) *h = ec->base_output_resolution.h;
5849      }
5850
5851    return EINA_TRUE;
5852 }
5853
5854 /* change the base_output_resolution of the bind_ec by checking the base_output_resolution of provider_ec's appinfo */
5855 EINTERN Eina_Bool
5856 e_client_base_output_resolution_rsm_update(E_Client *bind_ec, E_Client *provider_ec)
5857 {
5858    E_Appinfo *epai = NULL;
5859    int configured_width, configured_height;
5860    int width, height;
5861    E_Desk *bind_ec_desk;
5862
5863    EINA_SAFETY_ON_NULL_RETURN_VAL(bind_ec, EINA_FALSE);
5864    EINA_SAFETY_ON_NULL_RETURN_VAL(provider_ec, EINA_FALSE);
5865
5866    bind_ec_desk = e_comp_desk_find_by_ec(bind_ec);
5867    EINA_SAFETY_ON_NULL_RETURN_VAL(bind_ec_desk, EINA_FALSE);
5868
5869   if (!e_config->configured_output_resolution.use) return EINA_TRUE;
5870
5871   configured_width = e_config->configured_output_resolution.w;
5872   configured_height = e_config->configured_output_resolution.h;
5873
5874   if (bind_ec->base_output_resolution.use)
5875     {
5876        ELOGF("POL_APPINFO", "DELETE EXISTED BINDER BASE SCREEN RESOLUTION... base_output_resolution is same with desk size:(%d,%d), bind_pid:%d", bind_ec,
5877              bind_ec->base_output_resolution.w, bind_ec->base_output_resolution.h, bind_ec->netwm.pid);
5878
5879        bind_ec->base_output_resolution.use = 0;
5880        bind_ec->base_output_resolution.w = 0;
5881        bind_ec->base_output_resolution.h = 0;
5882        e_client_transform_core_remove(bind_ec, bind_ec->base_output_resolution.transform);
5883        E_FREE_FUNC(bind_ec->base_output_resolution.transform, e_util_transform_del);
5884     }
5885
5886   if (!provider_ec->netwm.pid)
5887     {
5888        ELOGF("POL_APPINFO", "NO PROVIDER PID... USE configured_output_resolution(%d,%d) provider_pid:%d", provider_ec,
5889              configured_width, configured_height, provider_ec->netwm.pid);
5890        goto use_configured;
5891     }
5892
5893    epai = e_appinfo_find_with_pid(provider_ec->netwm.pid);
5894    if (!epai)
5895      {
5896         ELOGF("POL_APPINFO", "NO PROVIDER APPINFO... USE configured_output_resolution(%d,%d) provider_pid:%d", provider_ec,
5897               configured_width, configured_height, provider_ec->netwm.pid);
5898         goto use_configured;
5899      }
5900
5901    if (!e_appinfo_base_output_resolution_get(epai, &width, &height))
5902      {
5903         ELOGF("POL_APPINFO", "NO PROVIDER APPINFO BASE SCREEN RESOLUTION... USE configured_output_resolution(%d,%d) provider_pid:%d", provider_ec,
5904               configured_width, configured_height, provider_ec->netwm.pid);
5905         goto use_configured;
5906       }
5907
5908    if ((width == 0) && (height == 0))
5909      {
5910         ELOGF("POL_APPINFO", "NO PROVIDER WIDTH and HEIGHT... SKIP base_output_resolution due to size:(%d,%d) provider_pid:%d", provider_ec,
5911              width, height, provider_ec->netwm.pid);
5912         return EINA_TRUE;
5913      }
5914
5915    if ((bind_ec_desk->geom.w == width) && (bind_ec_desk->geom.h == height))
5916      {
5917         ELOGF("POL_APPINFO", "SKIP SET BINDER BASE SCREEN RESOLUTION... base_output_resolution is same with desk size:(%d,%d), bind_pid:%d", bind_ec,
5918             width, height, bind_ec->netwm.pid);
5919         return EINA_TRUE;
5920      }
5921
5922    /* set the base_output_resolution of the e_client */
5923    _e_client_base_output_resolution_set(bind_ec, width, height);
5924    e_client_base_output_resolution_transform_adjust(bind_ec);
5925
5926    ELOGF("POL_APPINFO", "USE BINDER base_output_resolution(%d,%d) bind_pid:%d", bind_ec, width, height, bind_ec->netwm.pid);
5927
5928    return EINA_TRUE;
5929
5930 use_configured:
5931
5932    if ((bind_ec_desk->geom.w == configured_width) && (bind_ec_desk->geom.h == configured_height))
5933      {
5934         ELOGF("POL_APPINFO", "SKIP BINDER use configured_output_resolution (same with desk size:(%d,%d), bind_pid:%d)", bind_ec,
5935              configured_width, configured_height, bind_ec->netwm.pid);
5936      }
5937    else
5938      {
5939         /* set the base_output_resolution of the e_client as a default */
5940         _e_client_base_output_resolution_set(bind_ec, configured_width, configured_height);
5941      }
5942
5943    return EINA_TRUE;
5944 }
5945
5946 /* tizen_move_resize */
5947 EINTERN Eina_Bool
5948 e_client_pending_geometry_has(E_Client *ec)
5949 {
5950    if (!eina_list_count(ec->surface_sync.pending_geometry))
5951      return EINA_FALSE;
5952
5953    return ec->surface_sync.wait_commit;
5954 }
5955
5956 EINTERN void
5957 e_client_pending_geometry_flush(E_Client *ec)
5958 {
5959    E_Client_Pending_Geometry *geo;
5960
5961    if (!eina_list_count(ec->surface_sync.pending_geometry))
5962      {
5963         EINA_LIST_FREE(ec->surface_sync.pending_geometry, geo)
5964           {
5965              E_FREE(geo);
5966           }
5967         ec->surface_sync.wait_commit = EINA_FALSE;
5968         ELOGF("POSSIZE", "pending geometry has flushed", ec);
5969      }
5970 }
5971
5972 EINTERN void
5973 e_client_pending_geometry_last_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
5974 {
5975    Eina_List *l;
5976    E_Client_Pending_Geometry *geo;
5977    int gx = 0;
5978    int gy = 0;
5979    int gw = 0;
5980    int gh = 0;
5981
5982    EINA_LIST_REVERSE_FOREACH(ec->surface_sync.pending_geometry, l, geo)
5983      {
5984         gx = geo->x;
5985         gy = geo->y;
5986         gw = geo->w;
5987         gh = geo->h;
5988         break;
5989      }
5990
5991    if (x) *x = gx;
5992    if (y) *y = gy;
5993    if (w) *w = gw;
5994    if (h) *h = gh;
5995 }
5996
5997 E_API void
5998 e_client_frame_focus_set(E_Client *ec, Eina_Bool focus)
5999 {
6000    if (!ec) return;
6001    evas_object_focus_set(ec->frame, focus);
6002 }
6003
6004 EINTERN void
6005 e_client_frame_geometry_set(E_Client *ec, int x, int y, int w, int h)
6006 {
6007    if (!ec) return;
6008
6009    if (ec->internal || ec->input_only)
6010      {
6011         evas_object_geometry_set(ec->frame, x, y, w, h);
6012      }
6013    else
6014      {
6015         if ((ec->w != w) || (ec->h != h))
6016           {
6017              ELOGF("POSSIZE", "Set move_after_resize. old(%d,%d,%dx%d), new(%d,%d,%dx%d)", ec, ec->x, ec->y, ec->w, ec->h, x, y, w, h);
6018              ec->move_after_resize = EINA_TRUE;
6019
6020              e_client_pos_set(ec, x, y);
6021              evas_object_resize(ec->frame, w, h);
6022           }
6023         else
6024           evas_object_geometry_set(ec->frame, x, y, w, h);
6025      }
6026 }
6027
6028 EAPI void
6029 e_client_util_move_resize_without_frame(E_Client *ec, int x, int y, int w, int h)
6030 {
6031    if (!ec) return;
6032
6033    if (ec->internal || ec->input_only)
6034      {
6035         e_client_util_move_without_frame(ec, x, y);
6036         e_client_util_resize_without_frame(ec, w, h);
6037      }
6038    else
6039      {
6040         if ((ec->w != w) || (ec->h != h))
6041           {
6042              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);
6043              ec->move_after_resize = EINA_TRUE;
6044
6045              e_comp_object_frame_xy_adjust(ec->frame, x, y, &x, &y);
6046              e_client_pos_set(ec, x, y);
6047              e_client_util_resize_without_frame(ec, w, h);
6048           }
6049         else
6050           {
6051              e_client_util_move_without_frame(ec, x, y);
6052              e_client_util_resize_without_frame(ec, w, h);
6053           }
6054      }
6055 }
6056
6057 E_API Eina_Bool
6058 e_client_layer_set(E_Client *ec,
6059                    E_Layer layer)
6060 {
6061    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
6062    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, EINA_FALSE);
6063    if (!ec->frame) return EINA_FALSE;
6064
6065    if (e_comp_canvas_client_layer_map(layer) == 9999)
6066      return EINA_FALSE; //invalid layer is not allowed
6067
6068    if (ec->desk_area.enable)
6069      {
6070         if (e_client_layer_set_by_desk_area(ec, layer))
6071           {
6072              // restack according to desk group rule
6073              e_desk_area_ec_rearrange(ec->desk_area.desk_area, ec);
6074              return EINA_TRUE;
6075           }
6076      }
6077    ec->desk_area.layer_backup = layer;
6078
6079    evas_object_layer_set(ec->frame, layer);
6080    if (ec->layer != layer)
6081      {
6082         /* check exceptional case */
6083         if ((ec->fullscreen) &&
6084             (ec->saved.layer != layer))
6085           {
6086              ELOGF("LAYER", "(%d) fail to backup at saved.layer for fullscreen", ec, layer);
6087              return EINA_FALSE;
6088           }
6089         // if e_comp_object fail to change ec->layer due to ec->layer_pending or block
6090         // leave log and apply ec->layer according to set
6091         // as a result it restores back to given layer when pending or block is free
6092         ELOGF("LAYER", "change layer from %d to %d if in case layer pending(%d) or block(%d)",
6093               ec, ec->layer, layer, ec->layer_pending, ec->layer_block);
6094         if (ec->layer_pending || ec->layer_block)
6095           {
6096              ec->layer = layer;
6097              return EINA_TRUE;
6098           }
6099      }
6100
6101    wl_signal_emit_mutable(&PRI(ec)->events.layer_set, NULL);
6102
6103    return EINA_TRUE;
6104 }
6105
6106 E_API E_Layer
6107 e_client_layer_get(E_Client *ec)
6108 {
6109    short layer;
6110
6111    E_OBJECT_CHECK_RETURN(ec, E_LAYER_BOTTOM);
6112    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, E_LAYER_BOTTOM);
6113    if (!ec->frame) return E_LAYER_BOTTOM;
6114
6115    layer = evas_object_layer_get(ec->frame);
6116    if (ec->layer != layer)
6117      {
6118         /* client could be on temperory layer while pending or block,
6119          * in that case, client restores back to ec->layer after pending/block finish */
6120         if (ec->layer_block || ec->layer_pending)
6121           return ec->layer;
6122
6123         /* otherwise, client is on unexpected layer */
6124         ELOGF("LAYER", "layer dismatch ec->layer %d | evas obj layer %d ",
6125               ec, ec->layer, layer);
6126
6127         if (e_comp_canvas_client_layer_map(layer) == 9999)
6128           return E_LAYER_BOTTOM; //not on E_LAYER_CLIENT
6129      }
6130
6131    return ec->layer;
6132 }
6133
6134 static void
6135 _e_client_desk_area_original_layer_save(E_Client *ec, E_Layer layer)
6136 {
6137    E_OBJECT_CHECK(ec);
6138    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
6139    ec->desk_area.layer_backup = layer;
6140 }
6141
6142 EINTERN Eina_Bool
6143 e_client_layer_set_by_desk_area(E_Client *ec, E_Layer layer)
6144 {
6145    E_Desk_Area *eda;
6146    E_Layer edg_layer;
6147    E_Layer org_layer;
6148
6149    if (!ec) return EINA_FALSE;
6150    if (!ec->frame) return EINA_FALSE;
6151    if (!ec->desk_area.enable) return EINA_FALSE;
6152    if (!ec->desk_area.desk_area) return EINA_FALSE;
6153
6154    eda = ec->desk_area.desk_area;
6155
6156    // save original layer
6157    _e_client_desk_area_original_layer_save(ec, layer);
6158
6159    // get desk_area layer
6160    edg_layer = (E_Layer)e_desk_area_layer_get(eda);
6161    org_layer = e_client_desk_area_original_layer_get(ec);
6162
6163    ELOGF("EDG", "layer_set by desk_area... layer:%d, org_layer:%d, new_layer:%d", ec, layer, org_layer, edg_layer);
6164    if (org_layer == edg_layer)
6165      {
6166         e_client_raise(ec);
6167      }
6168    else
6169      {
6170         evas_object_layer_set(ec->frame, edg_layer);
6171         if (edg_layer == ec->layer)
6172           e_client_raise(ec);
6173      }
6174
6175    return EINA_TRUE;
6176 }
6177
6178 EINTERN void
6179 e_client_desk_area_original_layer_restore(E_Client *ec)
6180 {
6181    if (!ec) return;
6182
6183    // Do we need to check ec->desk_area.enable?
6184    // if ec->desk_area.enable is true, then e_client_layer_set calls
6185    // e_desk_area_ec_edg_layer_set(). that's too bad. :(
6186    // so, we MUST make a policy for ordering of the desk group layer restore
6187    // and the desk group enable.
6188    if (ec->desk_area.enable) return;
6189    e_client_layer_set(ec, ec->desk_area.layer_backup);
6190 }
6191
6192 EINTERN E_Layer
6193 e_client_desk_area_original_layer_get(E_Client *ec)
6194 {
6195    if (!ec) return E_LAYER_DESKTOP;
6196
6197    if (ec->desk_area.enable)
6198      return ec->desk_area.layer_backup;
6199    else
6200      return ec->layer;
6201 }
6202
6203 EINTERN Eina_Bool
6204 e_client_desk_area_client_layer_set(E_Client *ec, E_Desk_Area_Client_Layer edgc_layer)
6205 {
6206    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
6207    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, EINA_FALSE);
6208    if ((edgc_layer < E_DESK_AREA_CLIENT_LAYER_DESKTOP) ||
6209        (edgc_layer >= E_DESK_AREA_CLIENT_LAYER_MAX))
6210      return EINA_FALSE;
6211
6212    ec->desk_area.edgc_layer = edgc_layer;
6213    return EINA_TRUE;
6214 }
6215
6216 EINTERN E_Desk_Area_Client_Layer
6217 e_client_desk_area_client_layer_get(E_Client *ec)
6218 {
6219    E_OBJECT_CHECK_RETURN(ec, E_DESK_AREA_CLIENT_LAYER_DESKTOP);
6220
6221    return ec->desk_area.edgc_layer;
6222 }
6223
6224 //FIXME: use e_desk_area_ec_reassign(eda, ec) instead of this api
6225 E_API Eina_Bool
6226 e_client_desk_area_set(E_Client *ec, E_Desk_Area *eda)
6227 {
6228    E_Desk_Area *old_edg;
6229
6230    if (!ec) return EINA_FALSE;
6231
6232 #if 0 // if this is removed.. then below if (eda != old_edg) is removed also...
6233    if (ec->desk_area.desk_area == eda)
6234      return EINA_TRUE;
6235 #endif
6236
6237    ELOGF("EDG", "Desk Group Set (new:%p, old:%p)", ec, eda, ec->desk_area.desk_area);
6238    old_edg = ec->desk_area.desk_area;
6239    if (old_edg)
6240      e_desk_area_ec_remove(old_edg, ec);
6241
6242    ec->desk_area.desk_area = eda;
6243    e_desk_area_ec_add(eda, ec);
6244
6245 #if 0 // if this is removed.. then above if (ec->desk_area.desk_area == eda) is removed also...
6246    if (eda != old_edg)
6247 #endif
6248      {
6249         e_desk_area_ec_update(eda, ec);
6250         e_desk_area_ec_rearrange(ec->desk_area.desk_area, ec);
6251      }
6252
6253    return EINA_TRUE;
6254 }
6255
6256 static void
6257 _raise_between_sibling_under_parent(E_Client *ec)
6258 {
6259    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);
6260    e_client_stack_below(ec, ec->parent);
6261 }
6262
6263 static void
6264 _raise_between_sibling_on_parent(E_Client *ec)
6265 {
6266    E_Client *top_child = NULL;
6267    top_child = e_client_transient_child_top_get(ec->parent, EINA_FALSE);
6268    if (!top_child)
6269      {
6270         ELOGF("POL", "RAISE child window... Stack above on the parent (win:%zx, ec:%p)", ec, e_client_util_win_get(ec->parent), ec->parent);
6271         e_client_stack_above(ec, ec->parent);
6272      }
6273    else
6274      {
6275         if (top_child != ec)
6276           {
6277              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);
6278              e_client_stack_above(ec, top_child);
6279           }
6280         else
6281           ELOGF("POL", "RAISE child window between sibling... already on the top. STAY", ec);
6282      }
6283 }
6284
6285 static void
6286 _raise_belong_to_parent(E_Client *ec)
6287 {
6288    if (e_client_transient_policy_get(ec) == E_TRANSIENT_BELOW)
6289      _raise_between_sibling_under_parent(ec);
6290    else
6291      _raise_between_sibling_on_parent(ec);
6292 }
6293
6294 E_API void
6295 e_client_raise(E_Client *ec)
6296 {
6297    if (!ec) return;
6298
6299    if (ec->desk_area.enable)
6300      {
6301         E_Desk_Area *eda;
6302         eda = ec->desk_area.desk_area;
6303         if (eda)
6304           {
6305              e_desk_area_ec_raise(eda, ec);
6306              return;
6307           }
6308      }
6309
6310    if (ec->parent && e_client_is_belong_to_parent(ec))
6311      _raise_belong_to_parent(ec);
6312    else
6313      evas_object_raise(ec->frame);
6314
6315    wl_signal_emit_mutable(&PRI(ec)->events.raise, NULL);
6316 }
6317
6318 static void
6319 _e_client_transient_for_below_group_make(E_Client *ec, Eina_List **list)
6320 {
6321    // list : Head is the bottommost child
6322    E_Client *child;
6323    Eina_List *l;
6324
6325    if (!ec) return;
6326
6327    EINA_LIST_REVERSE_FOREACH(ec->transients, l, child)
6328      {
6329         if (!child) continue;
6330         if (e_client_transient_policy_get(child) != E_TRANSIENT_BELOW) continue;
6331         if (!e_client_is_belong_to_parent(child)) continue;
6332
6333         *list = eina_list_prepend(*list, child);
6334         _e_client_transient_for_group_make(child, list);
6335      }
6336 }
6337
6338 E_API E_Client *
6339 e_client_transient_child_bottom_get(E_Client *ec)
6340 {
6341    E_Client *bottom_ec = NULL;
6342    Eina_List *transient_below_list = NULL;
6343    Eina_List *l = NULL;
6344
6345    _e_client_transient_for_below_group_make(ec, &transient_below_list);
6346
6347    if (transient_below_list)
6348      {
6349         E_Client *temp_ec = NULL;
6350         E_Client *temp_ec2 = NULL;
6351
6352         E_CLIENT_FOREACH(temp_ec)
6353           {
6354              if (bottom_ec) break;
6355
6356              if (temp_ec == ec)
6357                {
6358                   bottom_ec = ec;
6359                   break;
6360                }
6361
6362              EINA_LIST_FOREACH(transient_below_list, l, temp_ec2)
6363                {
6364                   if (temp_ec == temp_ec2)
6365                     {
6366                        bottom_ec = temp_ec2;
6367                        break;
6368                     }
6369                }
6370           }
6371         eina_list_free(transient_below_list);
6372      }
6373    return bottom_ec;
6374 }
6375
6376 static void
6377 _lower_between_sibling_under_parent(E_Client *ec)
6378 {
6379    E_Client *bottom_child = NULL;
6380    bottom_child = e_client_transient_child_bottom_get(ec->parent);
6381    if (!bottom_child)
6382      {
6383         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);
6384         e_client_stack_below(ec, ec->parent);
6385      }
6386    else
6387      {
6388         if (bottom_child != ec)
6389           {
6390              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);
6391              e_client_stack_below(ec, bottom_child);
6392           }
6393         else
6394           ELOGF("POL", "LOWER child window between sibling... already under the bottom. STAY", ec);
6395      }
6396 }
6397
6398 static void
6399 _lower_between_sibling_on_parent(E_Client *ec)
6400 {
6401    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);
6402    e_client_stack_above(ec, ec->parent);
6403 }
6404
6405 static void
6406 _lower_belong_to_parent(E_Client *ec)
6407 {
6408    if (e_client_transient_policy_get(ec) == E_TRANSIENT_BELOW)
6409      _lower_between_sibling_under_parent(ec);
6410    else
6411      _lower_between_sibling_on_parent(ec);
6412 }
6413
6414 E_API void
6415 e_client_lower(E_Client *ec)
6416 {
6417    if (!ec) return;
6418
6419    if (ec->desk_area.enable)
6420      {
6421         E_Desk_Area *eda;
6422         eda = ec->desk_area.desk_area;
6423         if (eda)
6424           {
6425              e_desk_area_ec_lower(eda, ec);
6426
6427              wl_signal_emit_mutable(&PRI(ec)->events.lower, NULL);
6428              return;
6429           }
6430      }
6431
6432    if (ec->parent && e_client_is_belong_to_parent(ec))
6433      _lower_belong_to_parent(ec);
6434    else
6435      evas_object_lower(ec->frame);
6436
6437    wl_signal_emit_mutable(&PRI(ec)->events.lower, NULL);
6438 }
6439
6440 E_API void
6441 e_client_stack_above(E_Client *ec, E_Client *above)
6442 {
6443    if (!ec) return;
6444    if (!ec->frame) return;
6445    if (!above) return;
6446    if (!above->frame) return;
6447
6448    if (ec->desk_area.enable)
6449      {
6450         E_Desk_Area *eda;
6451         eda = ec->desk_area.desk_area;
6452         if (eda)
6453           {
6454              e_desk_area_ec_stack_above(eda, ec, above);
6455              return;
6456           }
6457      }
6458
6459    evas_object_stack_above(ec->frame, above->frame);
6460
6461    wl_signal_emit_mutable(&PRI(ec)->events.stack_above, NULL);
6462 }
6463
6464 E_API void
6465 e_client_stack_below(E_Client *ec, E_Client *below)
6466 {
6467    if (!ec) return;
6468    if (!ec->frame) return;
6469    if (!below) return;
6470    if (!below->frame) return;
6471
6472    if (ec->desk_area.enable)
6473      {
6474         E_Desk_Area *eda;
6475         eda = ec->desk_area.desk_area;
6476         if (eda)
6477           {
6478              e_desk_area_ec_stack_below(eda, ec, below);
6479              return;
6480           }
6481      }
6482
6483    evas_object_stack_below(ec->frame, below->frame);
6484
6485    wl_signal_emit_mutable(&PRI(ec)->events.stack_below, NULL);
6486 }
6487
6488 E_API int
6489 e_client_show_pending_set(E_Client *ec)
6490 {
6491    if (!ec) return 0;
6492
6493    ec->show_pending.count++;
6494    ELOGF("E_CLIENT", "SET show_pending. (count:%d, run:%d)", ec, ec->show_pending.count, ec->show_pending.running);
6495    return ec->show_pending.count;
6496 }
6497
6498 E_API int
6499 e_client_show_pending_unset(E_Client *ec)
6500 {
6501    if (!ec) return 0;
6502    if (ec->show_pending.count <= 0) return 0;
6503
6504    ec->show_pending.count--;
6505    ELOGF("E_CLIENT", "UNSET show_pending. (count:%d, run:%d)", ec, ec->show_pending.count, ec->show_pending.running);
6506    if (ec->show_pending.count == 0 && ec->show_pending.running)
6507      {
6508         ec->show_pending.running = EINA_FALSE;
6509         if (ec->frame)
6510           {
6511              ELOGF("E_CLIENT", "evas_object_show by unset show_pending", ec);
6512              evas_object_show(ec->frame);
6513              //e_comp_object_damage(ec->frame, 0, 0, ec->w, ec->h);
6514              EC_CHANGED(ec);
6515           }
6516      }
6517
6518    return ec->show_pending.count;
6519 }
6520
6521 static Eina_Bool
6522 _e_client_surface_tree_foreach_helper(E_Client *ec, E_Client_Surface_Tree_Foreach func, void *data)
6523 {
6524    E_Client *subc;
6525    Eina_List *l, *ll;
6526    Eina_Bool res = EINA_TRUE;
6527    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
6528
6529    if (!cdata)
6530      return res;
6531
6532    EINA_LIST_FOREACH_SAFE(cdata->sub.below_list, l, ll, subc)
6533      {
6534         res = _e_client_surface_tree_foreach_helper(subc, func, data);
6535         if (!res)
6536           break;
6537      }
6538
6539    if (res)
6540      {
6541         res = func(data, ec);
6542         if (res)
6543           {
6544              EINA_LIST_FOREACH_SAFE(cdata->sub.list, l, ll, subc)
6545                {
6546                   res = _e_client_surface_tree_foreach_helper(subc,
6547                                                               func,
6548                                                               data);
6549                   if (!res)
6550                     break;
6551                }
6552           }
6553      }
6554
6555    return res;
6556 }
6557
6558 E_API void
6559 e_client_surface_tree_foreach(E_Client *ec, E_Client_Surface_Tree_Foreach func, void *data)
6560 {
6561    EINA_SAFETY_ON_NULL_RETURN(ec);
6562    EINA_SAFETY_ON_NULL_RETURN(func);
6563
6564    _e_client_surface_tree_foreach_helper(ec, func, data);
6565 }
6566
6567 EINTERN E_Comp_Wl_Client_Data *
6568 e_client_cdata_new(E_Client *ec)
6569 {
6570    E_Comp_Wl_Client_Data *cdata;
6571
6572    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
6573
6574    if (!(cdata = E_NEW(E_Comp_Wl_Client_Data, 1)))
6575      {
6576         ERR("Could not allocate new E_Comp_Wl_Client_Data structure");
6577         return NULL;
6578      }
6579    ec->comp_data = cdata;
6580
6581    return cdata;
6582 }
6583
6584 EINTERN void
6585 e_client_cdata_free(E_Client *ec)
6586 {
6587   EINA_SAFETY_ON_NULL_RETURN(ec);
6588   if (!ec->comp_data) return;
6589
6590   E_FREE(ec->comp_data);
6591 }
6592
6593 EINTERN E_Comp_Wl_Client_Data *
6594 e_client_cdata_get(E_Client *ec)
6595 {
6596    if (!ec) return NULL;
6597
6598    return ec->comp_data;
6599 }
6600
6601 EINTERN Eina_Bool
6602 e_client_map_set(E_Client *ec, E_Map *em)
6603 {
6604    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6605
6606    return e_map_set_to_comp_object(em, ec->frame);
6607 }
6608
6609 E_API E_Map *
6610 e_client_map_get(const E_Client *ec)
6611 {
6612    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
6613
6614    return e_map_get_from_comp_object(ec->frame);
6615 }
6616
6617 EINTERN Eina_Bool
6618 e_client_map_enable_set(E_Client *ec, Eina_Bool enable)
6619 {
6620    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6621    EINA_SAFETY_ON_NULL_RETURN_VAL(ec->frame, EINA_FALSE);
6622
6623    evas_object_map_enable_set(ec->frame, enable);
6624
6625    return EINA_TRUE;
6626 }
6627
6628 EINTERN void
6629 e_client_belong_to_parent_set(E_Client *ec, Eina_Bool set)
6630 {
6631    if (!ec) return;
6632    ec->belong_to_parent = set;
6633 }
6634
6635 EINTERN Eina_Bool
6636 e_client_is_belong_to_parent(E_Client *ec)
6637 {
6638    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6639    return ec->belong_to_parent;
6640 }
6641
6642 EINTERN void
6643 e_client_transient_policy_set(E_Client *ec, E_Transient policy)
6644 {
6645    if (!ec) return;
6646    ec->transient_policy = policy;
6647 }
6648
6649 E_API E_Transient
6650 e_client_transient_policy_get(E_Client *ec)
6651 {
6652    if (!ec) return E_TRANSIENT_ABOVE;
6653    return ec->transient_policy;
6654 }
6655
6656 EINTERN void
6657 e_client_resize_object_create_cb_set(E_Client_Resize_Object_Create_Cb cb)
6658 {
6659    if (_e_client_resize_object_create_cb && cb)
6660      CRI("ATTEMPTING TO OVERWRITE EXISTING CLIENT RESIZE OBJECT CREATE HOOK!!!");
6661    _e_client_resize_object_create_cb = cb;
6662 }
6663
6664 EINTERN void
6665 e_client_resize_unit_size_set(E_Client *ec, unsigned int unit_size)
6666 {
6667    if (!ec) return;
6668
6669    // FYI, we consider 0 and 1 to be the same value as a default unit size.
6670    ec->manage_resize.unit_size = unit_size;
6671 }
6672
6673 EINTERN void
6674 e_client_desk_zoom_enable_set(E_Client *ec, Eina_Bool enable)
6675 {
6676    if (!ec) return;
6677    ec->desk_zoom.enable = enable;
6678 }
6679
6680 EINTERN Eina_Bool
6681 e_client_desk_zoom_enable_get(E_Client *ec)
6682 {
6683    if (!ec) return EINA_FALSE;
6684    return ec->desk_zoom.enable;
6685 }
6686
6687 EINTERN void
6688 e_client_layout_apply(E_Client *ec, Eina_Bool apply)
6689 {
6690    if (!ec) return;
6691    ec->apply_layout = apply;
6692 }
6693
6694 EINTERN Eina_Bool
6695 e_client_is_layout_apply(E_Client *ec)
6696 {
6697    if (!ec) return EINA_FALSE;
6698    return ec->apply_layout;
6699 }
6700
6701 E_API E_Client *
6702 e_client_from_surface_resource(struct wl_resource *surface_resource)
6703 {
6704    EINA_SAFETY_ON_NULL_RETURN_VAL(surface_resource, NULL);
6705
6706    return e_comp_wl_util_client_from_surface_resource(surface_resource);
6707 }
6708
6709 EINTERN void
6710 e_client_fps_update(E_Client *ec)
6711 {
6712    double dt;
6713    double tim;
6714
6715    EINA_SAFETY_ON_NULL_RETURN(ec);
6716
6717    if (!ec->fps.enabled) return;
6718
6719    tim = ecore_time_get();
6720
6721    dt = tim - ec->fps.frametimes[0];
6722
6723    ec->fps.frametimes[0] = tim;
6724    ec->fps.time += dt;
6725    ec->fps.cframes++;
6726
6727    if (ec->fps.lapse == 0.0)
6728      {
6729         ec->fps.lapse = tim;
6730         ec->fps.flapse = ec->fps.cframes;
6731      }
6732    else if ((tim - ec->fps.lapse) >= 0.5)
6733      {
6734         ec->fps.fps = (ec->fps.cframes - ec->fps.flapse) /
6735                       (tim - ec->fps.lapse);
6736         ec->fps.lapse = tim;
6737         ec->fps.flapse = ec->fps.cframes;
6738         ec->fps.time = 0.0;
6739      }
6740 }
6741
6742 EINTERN Eina_Bool
6743 e_client_fps_get(E_Client *ec, double *fps)
6744 {
6745    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6746
6747    if (ec->fps.old_fps == ec->fps.fps)
6748      return EINA_FALSE;
6749
6750    if (ec->fps.fps > 0.0)
6751      {
6752         *fps = ec->fps.fps;
6753         ec->fps.old_fps = ec->fps.fps;
6754         return EINA_TRUE;
6755      }
6756
6757    return EINA_FALSE;
6758 }
6759
6760 EINTERN void
6761 e_client_fps_enable(E_Client *ec, Eina_Bool enable)
6762 {
6763    EINA_SAFETY_ON_NULL_RETURN(ec);
6764
6765    ec->fps.enabled = enable;
6766 }
6767
6768 EINTERN Eina_Bool
6769 e_client_explicit_sync_get(E_Client *ec)
6770 {
6771    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6772
6773    return ec->explicit_sync;
6774 }
6775
6776 EINTERN Eina_Bool
6777 e_client_explicit_sync_set(E_Client *ec, Eina_Bool enable)
6778 {
6779    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6780
6781    ec->explicit_sync = enable;
6782
6783    return EINA_TRUE;
6784 }
6785
6786 EINTERN int
6787 e_client_explicit_sync_acquire_fence_fd_get(E_Client *ec)
6788 {
6789    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, -1);
6790
6791    return ec->acquire_fence_fd;
6792 }
6793
6794 EINTERN Eina_Bool
6795 e_client_explicit_sync_acquire_fence_fd_set(E_Client *ec, int fd)
6796 {
6797   EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6798
6799   ec->acquire_fence_fd = fd;
6800
6801   return EINA_TRUE;
6802 }
6803
6804 EINTERN Eina_Bool
6805 e_client_intercept_hook_auto_placement_call(E_Client *ec)
6806 {
6807   // no need to call the intercept hook if ec is NULL.
6808   if (!ec) return EINA_FALSE;
6809
6810   if (!_e_client_intercept_hook_call(E_CLIENT_INTERCEPT_HOOK_AUTO_PLACEMENT, ec))
6811     {
6812        ELOGF("FOCUS", "E_CLIENT_INTERCEPT_HOOK_AUTO_PLACEMENT Intercepted.", ec);
6813        return EINA_TRUE;
6814     }
6815
6816   return EINA_FALSE;
6817 }
6818
6819 EINTERN void
6820 e_client_iconify_event_send(E_Client *ec)
6821 {
6822    EINA_SAFETY_ON_NULL_RETURN(ec);
6823
6824    _e_client_event_simple(ec, E_EVENT_CLIENT_ICONIFY);
6825 }
6826
6827 EINTERN void
6828 e_client_uniconify_event_send(E_Client *ec)
6829 {
6830    EINA_SAFETY_ON_NULL_RETURN(ec);
6831
6832    _e_client_event_simple(ec, E_EVENT_CLIENT_UNICONIFY);
6833 }
6834
6835 EINTERN void
6836 e_client_stack_transient_for_done_notify(E_Client *ec)
6837 {
6838    EINA_SAFETY_ON_NULL_RETURN(ec);
6839
6840    wl_signal_emit_mutable(&PRI(ec)->events.stack_transient_for_done, NULL);
6841 }
6842
6843 EINTERN void
6844 e_client_eval_pre_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
6845 {
6846    API_ENTRY;
6847    wl_signal_add(&priv->events.eval_pre_fetch, listener);
6848 }
6849
6850 EINTERN struct wl_listener *
6851 e_client_eval_pre_fetch_listener_get(E_Client *ec, wl_notify_func_t notify)
6852 {
6853    API_ENTRY_VAL(NULL);
6854    return wl_signal_get(&priv->events.eval_pre_fetch, notify);
6855 }
6856
6857 EINTERN void
6858 e_client_eval_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
6859 {
6860    API_ENTRY;
6861    wl_signal_add(&priv->events.eval_fetch, listener);
6862 }
6863
6864 EINTERN struct wl_listener *
6865 e_client_eval_fetch_listener_get(E_Client *ec, wl_notify_func_t notify)
6866 {
6867    API_ENTRY_VAL(NULL);
6868    return wl_signal_get(&priv->events.eval_fetch, notify);
6869 }
6870
6871 EINTERN void
6872 e_client_eval_pre_post_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
6873 {
6874    API_ENTRY;
6875    wl_signal_add(&priv->events.eval_pre_post_fetch, listener);
6876 }
6877
6878 EINTERN struct wl_listener *
6879 e_client_eval_pre_post_fetch_listener_get(E_Client *ec, wl_notify_func_t notify)
6880 {
6881    API_ENTRY_VAL(NULL);
6882    return wl_signal_get(&priv->events.eval_pre_post_fetch, notify);
6883 }
6884
6885 EINTERN void
6886 e_client_eval_post_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
6887 {
6888    API_ENTRY;
6889    wl_signal_add(&priv->events.eval_post_fetch, listener);
6890 }
6891
6892 EINTERN struct wl_listener *
6893 e_client_eval_post_fetch_listener_get(E_Client *ec, wl_notify_func_t notify)
6894 {
6895    API_ENTRY_VAL(NULL);
6896    return wl_signal_get(&priv->events.eval_post_fetch, notify);
6897 }
6898
6899 EINTERN void
6900 e_client_eval_pre_frame_assign_listener_add(E_Client *ec, struct wl_listener *listener)
6901 {
6902    API_ENTRY;
6903    wl_signal_add(&priv->events.eval_pre_frame_assign, listener);
6904 }
6905
6906 EINTERN struct wl_listener *
6907 e_client_eval_pre_frame_assign_listener_get(E_Client *ec, wl_notify_func_t notify)
6908 {
6909    API_ENTRY_VAL(NULL);
6910    return wl_signal_get(&priv->events.eval_pre_frame_assign, notify);
6911 }
6912
6913 EINTERN void
6914 e_client_eval_post_frame_assign_listener_add(E_Client *ec, struct wl_listener *listener)
6915 {
6916    API_ENTRY;
6917    wl_signal_add(&priv->events.eval_post_frame_assign, listener);
6918 }
6919
6920 EINTERN struct wl_listener *
6921 e_client_eval_post_frame_assign_listener_get(E_Client *ec, wl_notify_func_t notify)
6922 {
6923    API_ENTRY_VAL(NULL);
6924    return wl_signal_get(&priv->events.eval_post_frame_assign, notify);
6925 }
6926
6927 EINTERN void
6928 e_client_eval_pre_new_client_listener_add(E_Client *ec, struct wl_listener *listener)
6929 {
6930    API_ENTRY;
6931    wl_signal_add(&priv->events.eval_pre_new_client, listener);
6932 }
6933
6934 EINTERN struct wl_listener *
6935 e_client_eval_pre_new_client_listener_get(E_Client *ec, wl_notify_func_t notify)
6936 {
6937    API_ENTRY_VAL(NULL);
6938    return wl_signal_get(&priv->events.eval_pre_new_client, notify);
6939 }
6940
6941 EINTERN void
6942 e_client_eval_post_new_client_listener_add(E_Client *ec, struct wl_listener *listener)
6943 {
6944    API_ENTRY;
6945    wl_signal_add(&priv->events.eval_post_new_client, listener);
6946 }
6947
6948 EINTERN struct wl_listener *
6949 e_client_eval_post_new_client_listener_get(E_Client *ec, wl_notify_func_t notify)
6950 {
6951    API_ENTRY_VAL(NULL);
6952    return wl_signal_get(&priv->events.eval_post_new_client, notify);
6953 }
6954
6955 EINTERN void
6956 e_client_eval_visibility_listener_add(E_Client *ec, struct wl_listener *listener)
6957 {
6958    API_ENTRY;
6959    wl_signal_add(&priv->events.eval_visibility, listener);
6960 }
6961
6962 EINTERN struct wl_listener *
6963 e_client_eval_visibility_listener_get(E_Client *ec, wl_notify_func_t notify)
6964 {
6965    API_ENTRY_VAL(NULL);
6966    return wl_signal_get(&priv->events.eval_visibility, notify);
6967 }
6968
6969 EINTERN void
6970 e_client_eval_visibility_end_listener_add(E_Client *ec, struct wl_listener *listener)
6971 {
6972    API_ENTRY;
6973    wl_signal_add(&priv->events.eval_visibility_end, listener);
6974 }
6975
6976 EINTERN struct wl_listener *
6977 e_client_eval_visibility_end_listener_get(E_Client *ec, wl_notify_func_t notify)
6978 {
6979    API_ENTRY_VAL(NULL);
6980    return wl_signal_get(&priv->events.eval_visibility_end, notify);
6981 }
6982
6983 EINTERN void
6984 e_client_eval_end_listener_add(E_Client *ec, struct wl_listener *listener)
6985 {
6986    API_ENTRY;
6987    wl_signal_add(&priv->events.eval_end, listener);
6988 }
6989
6990 EINTERN struct wl_listener *
6991 e_client_eval_end_listener_get(E_Client *ec, wl_notify_func_t notify)
6992 {
6993    API_ENTRY_VAL(NULL);
6994    return wl_signal_get(&priv->events.eval_end, notify);
6995 }
6996
6997 EINTERN void
6998 e_client_move_begin_listener_add(E_Client *ec, struct wl_listener *listener)
6999 {
7000    API_ENTRY;
7001    wl_signal_add(&priv->events.move_begin, listener);
7002 }
7003
7004 EINTERN struct wl_listener *
7005 e_client_move_begin_listener_get(E_Client *ec, wl_notify_func_t notify)
7006 {
7007    API_ENTRY_VAL(NULL);
7008    return wl_signal_get(&priv->events.move_begin, notify);
7009 }
7010
7011 EINTERN void
7012 e_client_move_update_listener_add(E_Client *ec, struct wl_listener *listener)
7013 {
7014    API_ENTRY;
7015    wl_signal_add(&priv->events.move_update, listener);
7016 }
7017
7018 EINTERN struct wl_listener *
7019 e_client_move_update_listener_get(E_Client *ec, wl_notify_func_t notify)
7020 {
7021    API_ENTRY_VAL(NULL);
7022    return wl_signal_get(&priv->events.move_update, notify);
7023 }
7024
7025 EINTERN void
7026 e_client_move_end_listener_add(E_Client *ec, struct wl_listener *listener)
7027 {
7028    API_ENTRY;
7029    wl_signal_add(&priv->events.move_end, listener);
7030 }
7031
7032 EINTERN struct wl_listener *
7033 e_client_move_end_listener_get(E_Client *ec, wl_notify_func_t notify)
7034 {
7035    API_ENTRY_VAL(NULL);
7036    return wl_signal_get(&priv->events.move_end, notify);
7037 }
7038
7039 EINTERN void
7040 e_client_move_resize_begin_listener_add(E_Client *ec, struct wl_listener *listener)
7041 {
7042    API_ENTRY;
7043    wl_signal_add(&priv->events.move_resize_begin, listener);
7044 }
7045
7046 EINTERN struct wl_listener *
7047 e_client_move_resize_begin_listener_get(E_Client *ec, wl_notify_func_t notify)
7048 {
7049    API_ENTRY_VAL(NULL);
7050    return wl_signal_get(&priv->events.move_resize_begin, notify);
7051 }
7052
7053 EINTERN void
7054 e_client_move_resize_update_listener_add(E_Client *ec, struct wl_listener *listener)
7055 {
7056    API_ENTRY;
7057    wl_signal_add(&priv->events.move_resize_update, listener);
7058 }
7059
7060 EINTERN struct wl_listener *
7061 e_client_move_resize_update_listener_get(E_Client *ec, wl_notify_func_t notify)
7062 {
7063    API_ENTRY_VAL(NULL);
7064    return wl_signal_get(&priv->events.move_resize_update, notify);
7065 }
7066
7067 EINTERN void
7068 e_client_move_resize_end_listener_add(E_Client *ec, struct wl_listener *listener)
7069 {
7070    API_ENTRY;
7071    wl_signal_add(&priv->events.move_resize_end, listener);
7072 }
7073
7074 EINTERN struct wl_listener *
7075 e_client_move_resize_end_listener_get(E_Client *ec, wl_notify_func_t notify)
7076 {
7077    API_ENTRY_VAL(NULL);
7078    return wl_signal_get(&priv->events.move_resize_end, notify);
7079 }
7080
7081 EINTERN void
7082 e_client_destroy_listener_add(E_Client *ec, struct wl_listener *listener)
7083 {
7084    API_ENTRY;
7085    wl_signal_add(&priv->events.destroy, listener);
7086 }
7087
7088 EINTERN struct wl_listener *
7089 e_client_destroy_listener_get(E_Client *ec, wl_notify_func_t notify)
7090 {
7091    API_ENTRY_VAL(NULL);
7092    return wl_signal_get(&priv->events.destroy, notify);
7093 }
7094
7095 EINTERN void
7096 e_client_new_client_listener_add(E_Client *ec, struct wl_listener *listener)
7097 {
7098    API_ENTRY;
7099    wl_signal_add(&priv->events.new_client, listener);
7100 }
7101
7102 EINTERN struct wl_listener *
7103 e_client_new_client_listener_get(E_Client *ec, wl_notify_func_t notify)
7104 {
7105    API_ENTRY_VAL(NULL);
7106    return wl_signal_get(&priv->events.new_client, notify);
7107 }
7108
7109 EINTERN void
7110 e_client_new_client_post_listener_add(E_Client *ec, struct wl_listener *listener)
7111 {
7112    API_ENTRY;
7113    wl_signal_add(&priv->events.new_client_post, listener);
7114 }
7115
7116 EINTERN struct wl_listener *
7117 e_client_new_client_post_listener_get(E_Client *ec, wl_notify_func_t notify)
7118 {
7119    API_ENTRY_VAL(NULL);
7120    return wl_signal_get(&priv->events.new_client_post, notify);
7121 }
7122
7123 EINTERN void
7124 e_client_unredirect_listener_add(E_Client *ec, struct wl_listener *listener)
7125 {
7126    API_ENTRY;
7127    wl_signal_add(&priv->events.unredirect, listener);
7128 }
7129
7130 EINTERN struct wl_listener *
7131 e_client_unredirect_listener_get(E_Client *ec, wl_notify_func_t notify)
7132 {
7133    API_ENTRY_VAL(NULL);
7134    return wl_signal_get(&priv->events.unredirect, notify);
7135 }
7136
7137 EINTERN void
7138 e_client_redirect_listener_add(E_Client *ec, struct wl_listener *listener)
7139 {
7140    API_ENTRY;
7141    wl_signal_add(&priv->events.redirect, listener);
7142 }
7143
7144 EINTERN struct wl_listener *
7145 e_client_redirect_listener_get(E_Client *ec, wl_notify_func_t notify)
7146 {
7147    API_ENTRY_VAL(NULL);
7148    return wl_signal_get(&priv->events.redirect, notify);
7149 }
7150
7151 EINTERN void
7152 e_client_aux_hint_change_listener_add(E_Client *ec, struct wl_listener *listener)
7153 {
7154    API_ENTRY;
7155    wl_signal_add(&priv->events.aux_hint_change, listener);
7156 }
7157
7158 EINTERN struct wl_listener *
7159 e_client_aux_hint_change_listener_get(E_Client *ec, wl_notify_func_t notify)
7160 {
7161    API_ENTRY_VAL(NULL);
7162    return wl_signal_get(&priv->events.aux_hint_change, notify);
7163 }
7164
7165 EINTERN void
7166 e_client_window_role_change_listener_add(E_Client *ec, struct wl_listener *listener)
7167 {
7168    API_ENTRY;
7169    wl_signal_add(&priv->events.window_role_change, listener);
7170 }
7171
7172 EINTERN struct wl_listener *
7173 e_client_window_role_change_listener_get(E_Client *ec, wl_notify_func_t notify)
7174 {
7175    API_ENTRY_VAL(NULL);
7176    return wl_signal_get(&priv->events.window_role_change, notify);
7177 }
7178
7179 EINTERN void
7180 e_client_transform_change_listener_add(E_Client *ec, struct wl_listener *listener)
7181 {
7182    API_ENTRY;
7183    wl_signal_add(&priv->events.transform_change, listener);
7184 }
7185
7186 EINTERN struct wl_listener *
7187 e_client_transform_change_listener_get(E_Client *ec, wl_notify_func_t notify)
7188 {
7189    API_ENTRY_VAL(NULL);
7190    return wl_signal_get(&priv->events.transform_change, notify);
7191 }
7192
7193 EINTERN void
7194 e_client_activate_done_listener_add(E_Client *ec, struct wl_listener *listener)
7195 {
7196    API_ENTRY;
7197    wl_signal_add(&priv->events.activate_done, listener);
7198 }
7199
7200 EINTERN struct wl_listener *
7201 e_client_activate_done_listener_get(E_Client *ec, wl_notify_func_t notify)
7202 {
7203    API_ENTRY_VAL(NULL);
7204    return wl_signal_get(&priv->events.activate_done, notify);
7205 }
7206
7207 EINTERN void
7208 e_client_mouse_in_listener_add(E_Client *ec, struct wl_listener *listener)
7209 {
7210    API_ENTRY;
7211    wl_signal_add(&priv->events.mouse_in, listener);
7212 }
7213
7214 EINTERN struct wl_listener *
7215 e_client_mouse_in_listener_get(E_Client *ec, wl_notify_func_t notify)
7216 {
7217    API_ENTRY_VAL(NULL);
7218    return wl_signal_get(&priv->events.mouse_in, notify);
7219 }
7220
7221 EINTERN void
7222 e_client_mouse_out_listener_add(E_Client *ec, struct wl_listener *listener)
7223 {
7224    API_ENTRY;
7225    wl_signal_add(&priv->events.mouse_out, listener);
7226 }
7227
7228 EINTERN struct wl_listener *
7229 e_client_mouse_out_listener_get(E_Client *ec, wl_notify_func_t notify)
7230 {
7231    API_ENTRY_VAL(NULL);
7232    return wl_signal_get(&priv->events.mouse_out, notify);
7233 }
7234
7235 EINTERN void
7236 e_client_mouse_down_listener_add(E_Client *ec, struct wl_listener *listener)
7237 {
7238    API_ENTRY;
7239    wl_signal_add(&priv->events.mouse_down, listener);
7240 }
7241
7242 EINTERN struct wl_listener *
7243 e_client_mouse_down_listener_get(E_Client *ec, wl_notify_func_t notify)
7244 {
7245    API_ENTRY_VAL(NULL);
7246    return wl_signal_get(&priv->events.mouse_down, notify);
7247 }
7248
7249 EINTERN void
7250 e_client_focus_set_listener_add(E_Client *ec, struct wl_listener *listener)
7251 {
7252    API_ENTRY;
7253    wl_signal_add(&priv->events.focus_set, listener);
7254 }
7255
7256 EINTERN struct wl_listener *
7257 e_client_focus_set_listener_get(E_Client *ec, wl_notify_func_t notify)
7258 {
7259    API_ENTRY_VAL(NULL);
7260    return wl_signal_get(&priv->events.focus_set, notify);
7261 }
7262
7263 EINTERN void
7264 e_client_focus_unset_listener_add(E_Client *ec, struct wl_listener *listener)
7265 {
7266    API_ENTRY;
7267    wl_signal_add(&priv->events.focus_unset, listener);
7268 }
7269
7270 EINTERN struct wl_listener *
7271 e_client_focus_unset_listener_get(E_Client *ec, wl_notify_func_t notify)
7272 {
7273    API_ENTRY_VAL(NULL);
7274    return wl_signal_get(&priv->events.focus_unset, notify);
7275 }
7276
7277 EINTERN void
7278 e_client_focus_defer_set_listener_add(E_Client *ec, struct wl_listener *listener)
7279 {
7280    API_ENTRY;
7281    wl_signal_add(&priv->events.focus_defer_set, listener);
7282 }
7283
7284 EINTERN struct wl_listener *
7285 e_client_focus_defer_set_listener_get(E_Client *ec, wl_notify_func_t notify)
7286 {
7287    API_ENTRY_VAL(NULL);
7288    return wl_signal_get(&priv->events.focus_defer_set, notify);
7289 }
7290
7291 EINTERN void
7292 e_client_focus_latest_set_listener_add(E_Client *ec, struct wl_listener *listener)
7293 {
7294    API_ENTRY;
7295    wl_signal_add(&priv->events.focus_latest_set, listener);
7296 }
7297
7298 EINTERN struct wl_listener *
7299 e_client_focus_latest_set_listener_get(E_Client *ec, wl_notify_func_t notify)
7300 {
7301    API_ENTRY_VAL(NULL);
7302    return wl_signal_get(&priv->events.focus_latest_set, notify);
7303 }
7304
7305 EINTERN void
7306 e_client_iconify_listener_add(E_Client *ec, struct wl_listener *listener)
7307 {
7308    API_ENTRY;
7309    wl_signal_add(&priv->events.iconify, listener);
7310 }
7311
7312 EINTERN struct wl_listener *
7313 e_client_iconify_listener_get(E_Client *ec, wl_notify_func_t notify)
7314 {
7315    API_ENTRY_VAL(NULL);
7316    return wl_signal_get(&priv->events.iconify, notify);
7317 }
7318
7319 EINTERN void
7320 e_client_uniconify_listener_add(E_Client *ec, struct wl_listener *listener)
7321 {
7322    API_ENTRY;
7323    wl_signal_add(&priv->events.uniconify, listener);
7324 }
7325
7326 EINTERN struct wl_listener *
7327 e_client_uniconify_listener_get(E_Client *ec, wl_notify_func_t notify)
7328 {
7329    API_ENTRY_VAL(NULL);
7330    return wl_signal_get(&priv->events.uniconify, notify);
7331 }
7332
7333 EINTERN void
7334 e_client_maximize_listener_add(E_Client *ec, struct wl_listener *listener)
7335 {
7336    API_ENTRY;
7337    wl_signal_add(&priv->events.maximize, listener);
7338 }
7339
7340 EINTERN struct wl_listener *
7341 e_client_maximize_listener_get(E_Client *ec, wl_notify_func_t notify)
7342 {
7343    API_ENTRY_VAL(NULL);
7344    return wl_signal_get(&priv->events.maximize, notify);
7345 }
7346
7347 EINTERN void
7348 e_client_unmaximize_listener_add(E_Client *ec, struct wl_listener *listener)
7349 {
7350    API_ENTRY;
7351    wl_signal_add(&priv->events.unmaximize, listener);
7352 }
7353
7354 EINTERN struct wl_listener *
7355 e_client_unmaximize_listener_get(E_Client *ec, wl_notify_func_t notify)
7356 {
7357    API_ENTRY_VAL(NULL);
7358    return wl_signal_get(&priv->events.unmaximize, notify);
7359 }
7360
7361 EINTERN void
7362 e_client_fullscreen_pre_listener_add(E_Client *ec, struct wl_listener *listener)
7363 {
7364    API_ENTRY;
7365    wl_signal_add(&priv->events.fullscreen_pre, listener);
7366 }
7367
7368 EINTERN struct wl_listener *
7369 e_client_fullscreen_pre_listener_get(E_Client *ec, wl_notify_func_t notify)
7370 {
7371    API_ENTRY_VAL(NULL);
7372    return wl_signal_get(&priv->events.fullscreen_pre, notify);
7373 }
7374
7375 EINTERN void
7376 e_client_fullscreen_listener_add(E_Client *ec, struct wl_listener *listener)
7377 {
7378    API_ENTRY;
7379    wl_signal_add(&priv->events.fullscreen, listener);
7380 }
7381
7382 EINTERN struct wl_listener *
7383 e_client_fullscreen_listener_get(E_Client *ec, wl_notify_func_t notify)
7384 {
7385    API_ENTRY_VAL(NULL);
7386    return wl_signal_get(&priv->events.fullscreen, notify);
7387 }
7388
7389 EINTERN void
7390 e_client_unfullscreen_listener_add(E_Client *ec, struct wl_listener *listener)
7391 {
7392    API_ENTRY;
7393    wl_signal_add(&priv->events.unfullscreen, listener);
7394 }
7395
7396 EINTERN struct wl_listener *
7397 e_client_unfullscreen_listener_get(E_Client *ec, wl_notify_func_t notify)
7398 {
7399    API_ENTRY_VAL(NULL);
7400    return wl_signal_get(&priv->events.unfullscreen, notify);
7401 }
7402
7403 EINTERN void
7404 e_client_move_listener_add(E_Client *ec, struct wl_listener *listener)
7405 {
7406    API_ENTRY;
7407    wl_signal_add(&priv->events.move, listener);
7408 }
7409
7410 EINTERN struct wl_listener *
7411 e_client_move_listener_get(E_Client *ec, wl_notify_func_t notify)
7412 {
7413    API_ENTRY_VAL(NULL);
7414    return wl_signal_get(&priv->events.move, notify);
7415 }
7416
7417 EINTERN void
7418 e_client_raise_listener_add(E_Client *ec, struct wl_listener *listener)
7419 {
7420    API_ENTRY;
7421    wl_signal_add(&priv->events.raise, listener);
7422 }
7423
7424 EINTERN struct wl_listener *
7425 e_client_raise_listener_get(E_Client *ec, wl_notify_func_t notify)
7426 {
7427    API_ENTRY_VAL(NULL);
7428    return wl_signal_get(&priv->events.raise, notify);
7429 }
7430
7431 EINTERN void
7432 e_client_lower_listener_add(E_Client *ec, struct wl_listener *listener)
7433 {
7434    API_ENTRY;
7435    wl_signal_add(&priv->events.lower, listener);
7436 }
7437
7438 EINTERN struct wl_listener *
7439 e_client_lower_listener_get(E_Client *ec, wl_notify_func_t notify)
7440 {
7441    API_ENTRY_VAL(NULL);
7442    return wl_signal_get(&priv->events.lower, notify);
7443 }
7444
7445 EINTERN void
7446 e_client_stack_below_listener_add(E_Client *ec, struct wl_listener *listener)
7447 {
7448    API_ENTRY;
7449    wl_signal_add(&priv->events.stack_below, listener);
7450 }
7451
7452 EINTERN struct wl_listener *
7453 e_client_stack_below_listener_get(E_Client *ec, wl_notify_func_t notify)
7454 {
7455    API_ENTRY_VAL(NULL);
7456    return wl_signal_get(&priv->events.stack_below, notify);
7457 }
7458
7459 EINTERN void
7460 e_client_stack_above_listener_add(E_Client *ec, struct wl_listener *listener)
7461 {
7462    API_ENTRY;
7463    wl_signal_add(&priv->events.stack_above, listener);
7464 }
7465
7466 EINTERN struct wl_listener *
7467 e_client_stack_above_listener_get(E_Client *ec, wl_notify_func_t notify)
7468 {
7469    API_ENTRY_VAL(NULL);
7470    return wl_signal_get(&priv->events.stack_above, notify);
7471 }
7472
7473 EINTERN void
7474 e_client_layer_set_listener_add(E_Client *ec, struct wl_listener *listener)
7475 {
7476    API_ENTRY;
7477    wl_signal_add(&priv->events.layer_set, listener);
7478 }
7479
7480 EINTERN struct wl_listener *
7481 e_client_layer_set_listener_get(E_Client *ec, wl_notify_func_t notify)
7482 {
7483    API_ENTRY_VAL(NULL);
7484    return wl_signal_get(&priv->events.layer_set, notify);
7485 }
7486
7487 EINTERN void
7488 e_client_stack_transient_for_done_listener_add(E_Client *ec, struct wl_listener *listener)
7489 {
7490    API_ENTRY;
7491    wl_signal_add(&priv->events.stack_transient_for_done, listener);
7492 }
7493
7494 EINTERN struct wl_listener *
7495 e_client_stack_transient_for_done_listener_get(E_Client *ec, wl_notify_func_t notify)
7496 {
7497    API_ENTRY_VAL(NULL);
7498    return wl_signal_get(&priv->events.stack_transient_for_done, notify);
7499 }
7500
7501 EINTERN void
7502 e_client_stick_listener_add(E_Client *ec, struct wl_listener *listener)
7503 {
7504    API_ENTRY;
7505    wl_signal_add(&priv->events.stick, listener);
7506 }
7507
7508 EINTERN struct wl_listener *
7509 e_client_stick_listener_get(E_Client *ec, wl_notify_func_t notify)
7510 {
7511    API_ENTRY_VAL(NULL);
7512    return wl_signal_get(&priv->events.stick, notify);
7513 }
7514
7515 EINTERN void
7516 e_client_unstick_listener_add(E_Client *ec, struct wl_listener *listener)
7517 {
7518    API_ENTRY;
7519    wl_signal_add(&priv->events.unstick, listener);
7520 }
7521
7522 EINTERN struct wl_listener *
7523 e_client_unstick_listener_get(E_Client *ec, wl_notify_func_t notify)
7524 {
7525    API_ENTRY_VAL(NULL);
7526    return wl_signal_get(&priv->events.unstick, notify);
7527 }