e_client/e_config: add configuration for fullscreen layer
[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 static E_Layer
3163 _e_client_convert_fullscreen_layer(int layer)
3164 {
3165    if (layer <= E_LAYER_CLIENT_NORMAL)
3166      return E_LAYER_CLIENT_NORMAL;
3167    else if (layer <= E_LAYER_CLIENT_ABOVE)
3168      return E_LAYER_CLIENT_ABOVE;
3169    else if (layer <= E_LAYER_CLIENT_EDGE)
3170      return E_LAYER_CLIENT_EDGE;
3171    else
3172      return E_LAYER_CLIENT_FULLSCREEN;
3173 }
3174
3175 E_API E_Client *
3176 e_client_new(E_Pixmap *cp, int first_map, int internal)
3177 {
3178    E_Client *ec;
3179    E_Pixmap_Type type;
3180
3181    type = e_pixmap_type_get(cp);
3182    if (type >= E_PIXMAP_TYPE_MAX) return NULL;
3183    if (eina_hash_find(clients_hash[type], &cp)) return NULL;
3184
3185    ec = E_OBJECT_ALLOC(E_Client, E_CLIENT_TYPE, _e_client_free);
3186    if (!ec) return NULL;
3187    e_object_del_func_set(E_OBJECT(ec), E_OBJECT_CLEANUP_FUNC(_e_client_del));
3188
3189    if (!_e_client_private_init(ec))
3190      {
3191         e_object_del(E_OBJECT(ec));
3192         return NULL;
3193      }
3194
3195    uuid_generate(ec->uuid);
3196
3197    ec->focus_policy_override = E_FOCUS_LAST;
3198    e_client_size_set(ec, 1, 1);
3199    ec->internal = internal;
3200
3201    ec->pixmap = cp;
3202    e_pixmap_client_set(cp, ec);
3203    ec->resize_mode = E_POINTER_RESIZE_NONE;
3204    ec->layer = E_LAYER_CLIENT_NORMAL;
3205    ec->first_mapped = EINA_FALSE;
3206    ec->post_raise = EINA_TRUE;
3207    ec->post_lower = EINA_FALSE;
3208    ec->animatable = EINA_TRUE;
3209    ec->maximize_type = e_config->maximize_policy & E_MAXIMIZE_TYPE;
3210    ec->fullscreen_layer = _e_client_convert_fullscreen_layer(e_config->fullscreen_layer);
3211
3212    /* FIXME: if first_map is 1 then we should ignore the first hide event
3213     * or ensure the window is already hidden and events flushed before we
3214     * create a border for it */
3215    if (first_map)
3216      {
3217         ec->changes.pos = 1;
3218         ec->re_manage = 1;
3219         // needed to be 1 for internal windw and on restart.
3220         // ec->ignore_first_unmap = 2;
3221      }
3222    ec->offer_resistance = 1;
3223    ec->new_client = 1;
3224    e_comp->new_clients++;
3225
3226    ec->exp_iconify.by_client = 0;
3227    ec->exp_iconify.not_raise = 0;
3228    ec->exp_iconify.skip_iconify = 0;
3229    ec->exp_iconify.skip_by_remote = 0;
3230    if (e_config->deiconify_approve)
3231      ec->exp_iconify.deiconify_update= 1;
3232    else
3233      ec->exp_iconify.deiconify_update= 0;
3234    if (e_config->use_buffer_flush)
3235      ec->exp_iconify.buffer_flush = 1;
3236    else
3237      ec->exp_iconify.buffer_flush = 0;
3238
3239    e_client_iconified_type_set(ec, E_ICONIFIED_TYPE_NONE);
3240
3241    wl_signal_emit_mutable(&PRI(ec)->events.new_client, NULL);
3242    if (!_e_client_hook_call(E_CLIENT_HOOK_NEW_CLIENT, ec))
3243      {
3244         /* delete the above allocated object */
3245         //e_object_del(E_OBJECT(ec));
3246         return NULL;
3247      }
3248
3249    _e_client_aux_hint_eval(ec);
3250
3251    ec->icccm.title = NULL;
3252    ec->icccm.name = NULL;
3253 #if defined(__cplusplus) || defined(c_plusplus)
3254    ec->icccm.cpp_class = NULL;
3255 #else
3256    ec->icccm.class = NULL;
3257 #endif
3258    ec->icccm.icon_name = NULL;
3259    ec->icccm.machine = NULL;
3260    ec->icccm.min_w = 1;
3261    ec->icccm.min_h = 1;
3262    ec->icccm.max_w = 32767;
3263    ec->icccm.max_h = 32767;
3264    ec->icccm.base_w = 0;
3265    ec->icccm.base_h = 0;
3266    ec->icccm.step_w = -1;
3267    ec->icccm.step_h = -1;
3268    ec->icccm.min_aspect = 0.0;
3269    ec->icccm.max_aspect = 0.0;
3270
3271    ec->netwm.pid = 0;
3272    ec->netwm.name = NULL;
3273    ec->netwm.icon_name = NULL;
3274    ec->netwm.desktop = 0;
3275    ec->netwm.state.modal = 0;
3276    ec->netwm.state.sticky = 0;
3277    ec->netwm.state.shaded = 0;
3278    ec->netwm.state.hidden = 0;
3279    ec->netwm.state.maximized_v = 0;
3280    ec->netwm.state.maximized_h = 0;
3281    ec->netwm.state.skip_taskbar = 0;
3282    ec->netwm.state.skip_pager = 0;
3283    ec->netwm.state.fullscreen = 0;
3284    ec->netwm.state.stacking = E_STACKING_NONE;
3285    ec->netwm.action.move = 0;
3286    ec->netwm.action.resize = 0;
3287    ec->netwm.action.minimize = 0;
3288    ec->netwm.action.shade = 0;
3289    ec->netwm.action.stick = 0;
3290    ec->netwm.action.maximized_h = 0;
3291    ec->netwm.action.maximized_v = 0;
3292    ec->netwm.action.fullscreen = 0;
3293    ec->netwm.action.change_desktop = 0;
3294    ec->netwm.action.close = 0;
3295    ec->netwm.opacity = 255;
3296
3297    ec->visibility.obscured = E_VISIBILITY_UNKNOWN;
3298    ec->visibility.opaque = -1;
3299    ec->visibility.changed = 0;
3300    ec->visibility.skip = 0;
3301    ec->visibility.last_sent_type = E_VISIBILITY_UNKNOWN;
3302
3303    ec->transform.zoom = 1.0;
3304    ec->transform.angle = 0.0;
3305    ec->transform_core.direct_render = EINA_TRUE;
3306    ec->transform_core.activate = EINA_TRUE;
3307
3308    ec->pointer_enter_sent = EINA_FALSE;
3309
3310    ec->acquire_fence_fd = -1;
3311
3312    EC_CHANGED(ec);
3313
3314    e_comp->clients = eina_list_append(e_comp->clients, ec);
3315    eina_hash_add(clients_hash[type], &ec->pixmap, ec);
3316
3317    ELOGF("COMP", "CLIENT ADD. cp:%p, argb:%d, internal:%d, ignored:%d", ec, cp, ec->argb, internal, ec->ignored);
3318    if (!ec->ignored)
3319      _e_client_event_add(ec);
3320    e_comp_object_client_add(ec);
3321    if (ec->frame)
3322      {
3323         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_SHOW, _e_client_cb_evas_show, ec);
3324         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_HIDE, _e_client_cb_evas_hide, ec);
3325         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_MOVE, _e_client_cb_evas_move, ec);
3326         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_RESIZE, _e_client_cb_evas_resize, ec);
3327         evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_RESTACK, _e_client_cb_evas_restack, ec);
3328         evas_object_smart_callback_add(ec->frame, "shade_done", _e_client_cb_evas_shade_done, ec);
3329      }
3330
3331    wl_signal_emit_mutable(&PRI(ec)->events.new_client_post, NULL);
3332
3333 #ifdef _F_E_CLIENT_NEW_CLIENT_POST_HOOK_
3334    _e_client_hook_call(E_CLIENT_HOOK_NEW_CLIENT_POST, ec);
3335 #endif
3336
3337    ec->manage_resize.resize_obj = NULL;
3338    ec->manage_resize.x = ec->manage_resize.y = ec->manage_resize.w = ec->manage_resize.h = 0;
3339    ec->manage_resize.enable_aspect_ratio = EINA_FALSE;
3340    ec->manage_resize.aw = ec->manage_resize.ah = 0;
3341    ec->manage_resize.header_h = 0;
3342    ec->manage_resize.footer_h = 0;
3343
3344    ec->visibility.ignore_geometry = e_config->calc_vis_ignore_geometry;
3345
3346    return ec;
3347 }
3348
3349 E_API Eina_Bool e_client_is_internal(E_Client *ec)
3350 {
3351    E_OBJECT_CHECK_RETURN(ec, EINA_TRUE);
3352    return ec->internal;
3353 }
3354
3355 EINTERN void
3356 e_client_desk_iconify_skip_set(E_Client *ec, Eina_Bool skip)
3357 {
3358    if (!ec) return;
3359    ec->user_skip_winlist = skip;
3360 }
3361
3362 EINTERN Eina_Bool
3363 e_client_desk_iconify_skip_get(E_Client *ec)
3364 {
3365    if (!ec) return EINA_FALSE;
3366    return ec->user_skip_winlist;
3367 }
3368
3369 EINTERN Eina_Bool
3370 e_client_comp_grabbed_get(void)
3371 {
3372    return comp_grabbed;
3373 }
3374
3375 EINTERN E_Client *
3376 e_client_action_get(void)
3377 {
3378    return action_client;
3379 }
3380
3381
3382 //////////////////////////////////////////////////////////
3383
3384 EINTERN void
3385 e_client_mouse_in(E_Client *ec, int x, int y)
3386 {
3387    E_Desk *desk;
3388
3389    if (comp_grabbed) return;
3390    if (e_object_is_del(E_OBJECT(ec))) return;
3391    desk = e_comp_desk_find_by_ec(ec);
3392    if (desk && desk->animate_count) return;
3393    ec->mouse.current.mx = x;
3394    ec->mouse.current.my = y;
3395    ec->mouse.in = 1;
3396
3397    wl_signal_emit_mutable(&PRI(ec)->events.mouse_in, NULL);
3398 }
3399
3400 EINTERN void
3401 e_client_mouse_out(E_Client *ec, int x, int y)
3402 {
3403    E_Desk *desk;
3404
3405    if (comp_grabbed) return;
3406    if (ec->fullscreen) return;
3407    if (e_object_is_del(E_OBJECT(ec))) return;
3408    desk = e_comp_desk_find_by_ec(ec);
3409    if (desk && desk->animate_count) return;
3410
3411    ec->mouse.current.mx = x;
3412    ec->mouse.current.my = y;
3413    ec->mouse.in = 0;
3414
3415    wl_signal_emit_mutable(&PRI(ec)->events.mouse_out, NULL);
3416 }
3417
3418 EINTERN void
3419 e_client_mouse_wheel(E_Client *ec, Evas_Point *output, E_Binding_Event_Wheel *ev)
3420 {
3421    EINA_SAFETY_ON_NULL_RETURN(ec);
3422    if (action_client) return;
3423    ec->mouse.current.mx = output->x;
3424    ec->mouse.current.my = output->y;
3425 }
3426
3427 EINTERN void
3428 e_client_mouse_down(E_Client *ec, int button, Evas_Point *output, E_Binding_Event_Mouse_Button *ev)
3429 {
3430    EINA_SAFETY_ON_NULL_RETURN(ec);
3431
3432    if (action_client || ec->iconic || e_client_util_ignored_get(ec)) return;
3433    if ((button >= 1) && (button <= 3))
3434      {
3435         ec->mouse.last_down[button - 1].mx = output->x;
3436         ec->mouse.last_down[button - 1].my = output->y;
3437         ec->mouse.last_down[button - 1].x = ec->x;
3438         ec->mouse.last_down[button - 1].y = ec->y;
3439         ec->mouse.last_down[button - 1].w = ec->w;
3440         ec->mouse.last_down[button - 1].h = ec->h;
3441      }
3442    else
3443      {
3444         ec->moveinfo.down.x = ec->x;
3445         ec->moveinfo.down.y = ec->y;
3446         ec->moveinfo.down.w = ec->w;
3447         ec->moveinfo.down.h = ec->h;
3448      }
3449    ec->mouse.current.mx = output->x;
3450    ec->mouse.current.my = output->y;
3451    if ((button >= 1) && (button <= 3))
3452      {
3453         ec->mouse.last_down[button - 1].mx = output->x;
3454         ec->mouse.last_down[button - 1].my = output->y;
3455         ec->mouse.last_down[button - 1].x = ec->x;
3456         ec->mouse.last_down[button - 1].y = ec->y;
3457         ec->mouse.last_down[button - 1].w = ec->w;
3458         ec->mouse.last_down[button - 1].h = ec->h;
3459      }
3460    else
3461      {
3462         ec->moveinfo.down.x = ec->x;
3463         ec->moveinfo.down.y = ec->y;
3464         ec->moveinfo.down.w = ec->w;
3465         ec->moveinfo.down.h = ec->h;
3466      }
3467    ec->mouse.current.mx = output->x;
3468    ec->mouse.current.my = output->y;
3469
3470    wl_signal_emit_mutable(&PRI(ec)->events.mouse_down, NULL);
3471 }
3472
3473 EINTERN void
3474 e_client_mouse_up(E_Client *ec, int button, Evas_Point *output, E_Binding_Event_Mouse_Button* ev)
3475 {
3476    EINA_SAFETY_ON_NULL_RETURN(ec);
3477    if (ec->iconic || e_client_util_ignored_get(ec)) return;
3478    if ((button >= 1) && (button <= 3))
3479      {
3480         ec->mouse.last_up[button - 1].mx = output->x;
3481         ec->mouse.last_up[button - 1].my = output->y;
3482         ec->mouse.last_up[button - 1].x = ec->x;
3483         ec->mouse.last_up[button - 1].y = ec->y;
3484      }
3485    ec->mouse.current.mx = output->x;
3486    ec->mouse.current.my = output->y;
3487    /* also we don't pass the same params that went in - then again that */
3488    /* should be ok as we are just ending the action if it has an end */
3489    if (ec->cur_mouse_action)
3490      {
3491         if (ec->cur_mouse_action->func.end_mouse)
3492           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", ev);
3493         else if (ec->cur_mouse_action->func.end)
3494           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
3495         e_object_unref(E_OBJECT(ec->cur_mouse_action));
3496         ec->cur_mouse_action = NULL;
3497      }
3498
3499    if ((button >= 1) && (button <= 3))
3500      {
3501         ec->mouse.last_up[button - 1].mx = output->x;
3502         ec->mouse.last_up[button - 1].my = output->y;
3503         ec->mouse.last_up[button - 1].x = ec->x;
3504         ec->mouse.last_up[button - 1].y = ec->y;
3505      }
3506 }
3507
3508 E_API void
3509 e_client_stay_within_canvas_margin(E_Client *ec)
3510 {
3511    int new_x = ec->x;
3512    int new_y = ec->y;
3513
3514    if (ec->floating)
3515      {
3516         _e_client_stay_within_canvas_margin(ec, ec->x, ec->y, &new_x, &new_y);
3517
3518         if ((ec->x != new_x) || (ec->y != new_y))
3519           evas_object_move(ec->frame, new_x, new_y);
3520      }
3521 }
3522
3523 EINTERN void
3524 e_client_mouse_move(E_Client *ec, Evas_Point *output)
3525 {
3526    EINA_SAFETY_ON_NULL_RETURN(ec);
3527    if (ec->iconic || e_client_util_ignored_get(ec)) return;
3528    ec->mouse.current.mx = output->x;
3529    ec->mouse.current.my = output->y;
3530    if (e_client_util_moving_get(ec))
3531      {
3532         _e_client_move_handle(ec);
3533      }
3534    else if (e_client_util_resizing_get(ec))
3535      {
3536         _e_client_resize_handle(ec);
3537      }
3538 }
3539 ///////////////////////////////////////////////////////
3540
3541 EINTERN void
3542 e_client_res_change_geometry_save(E_Client *ec)
3543 {
3544    E_OBJECT_CHECK(ec);
3545    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3546
3547    if (ec->pre_res_change.valid) return;
3548    ec->pre_res_change.valid = 1;
3549    ec->pre_res_change.x = ec->x;
3550    ec->pre_res_change.y = ec->y;
3551    ec->pre_res_change.w = ec->w;
3552    ec->pre_res_change.h = ec->h;
3553    ec->pre_res_change.saved.x = ec->saved.x;
3554    ec->pre_res_change.saved.y = ec->saved.y;
3555    ec->pre_res_change.saved.w = ec->saved.w;
3556    ec->pre_res_change.saved.h = ec->saved.h;
3557 }
3558
3559 EINTERN void
3560 e_client_res_change_geometry_restore(E_Client *ec)
3561 {
3562    E_Zone *zone;
3563
3564    struct
3565    {
3566       unsigned char valid : 1;
3567       int           x, y, w, h;
3568       struct
3569       {
3570          int x, y, w, h;
3571       } saved;
3572    } pre_res_change;
3573
3574    E_OBJECT_CHECK(ec);
3575    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3576    if (!ec->pre_res_change.valid) return;
3577    if (ec->new_client) return;
3578
3579    zone = e_comp_zone_find_by_ec(ec);
3580    if (!zone) return;
3581
3582    memcpy(&pre_res_change, &ec->pre_res_change, sizeof(pre_res_change));
3583
3584    if (ec->fullscreen)
3585      {
3586         e_client_unfullscreen(ec);
3587         e_client_fullscreen(ec, e_config->fullscreen_policy);
3588      }
3589    else if (ec->maximized != E_MAXIMIZE_NONE)
3590      {
3591         E_Maximize max;
3592
3593         max = ec->maximized;
3594         e_client_unmaximize(ec, E_MAXIMIZE_BOTH);
3595         e_client_maximize(ec, max);
3596      }
3597    else
3598      {
3599         int x, y, w, h, zx, zy, zw, zh;
3600
3601         ec->saved.x = ec->pre_res_change.saved.x;
3602         ec->saved.y = ec->pre_res_change.saved.y;
3603         ec->saved.w = ec->pre_res_change.saved.w;
3604         ec->saved.h = ec->pre_res_change.saved.h;
3605
3606         e_zone_useful_geometry_get(zone, &zx, &zy, &zw, &zh);
3607
3608         if (ec->saved.w > zw)
3609           ec->saved.w = zw;
3610         if ((ec->saved.x + ec->saved.w) > (zx + zw))
3611           ec->saved.x = zx + zw - ec->saved.w;
3612
3613         if (ec->saved.h > zh)
3614           ec->saved.h = zh;
3615         if ((ec->saved.y + ec->saved.h) > (zy + zh))
3616           ec->saved.y = zy + zh - ec->saved.h;
3617
3618         x = ec->pre_res_change.x;
3619         y = ec->pre_res_change.y;
3620         w = ec->pre_res_change.w;
3621         h = ec->pre_res_change.h;
3622         if (w > zw)
3623           w = zw;
3624         if (h > zh)
3625           h = zh;
3626         if ((x + w) > (zx + zw))
3627           x = zx + zw - w;
3628         if ((y + h) > (zy + zh))
3629           y = zy + zh - h;
3630         evas_object_geometry_set(ec->frame, x, y, w, h);
3631      }
3632    memcpy(&ec->pre_res_change, &pre_res_change, sizeof(pre_res_change));
3633 }
3634
3635 EINTERN void
3636 e_client_pos_set(E_Client *ec, int x, int y)
3637 {
3638    if (!ec) return;
3639    ec->x = x;
3640    ec->y = y;
3641 }
3642
3643 EINTERN void
3644 e_client_pos_get(E_Client *ec, int *x, int *y)
3645 {
3646    int ex = 0;
3647    int ey = 0;
3648
3649    if (ec)
3650      {
3651         ex = ec->x;
3652         ey = ec->y;
3653      }
3654
3655    if (x) *x = ex;
3656    if (y) *y = ey;
3657 }
3658
3659 E_API void
3660 e_client_size_set(E_Client *ec, int w, int h)
3661 {
3662    if (!ec) return;
3663    ec->w = w;
3664    ec->h = h;
3665 }
3666
3667 E_API void
3668 e_client_size_get(E_Client *ec, int *w, int *h)
3669 {
3670    int ew = 0;
3671    int eh = 0;
3672
3673    if (ec)
3674      {
3675         ew = ec->w;
3676         eh = ec->h;
3677      }
3678
3679    if (w) *w = ew;
3680    if (h) *h = eh;
3681 }
3682
3683 E_API void
3684 e_client_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
3685 {
3686    int gx = 0;
3687    int gy = 0;
3688    int gw = 0;
3689    int gh = 0;
3690
3691    E_OBJECT_CHECK(ec);
3692    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
3693
3694    if (e_client_transform_core_enable_get(ec))
3695      {
3696         gx = ec->transform_core.result.boundary.x;
3697         gy = ec->transform_core.result.boundary.y;
3698         gw = ec->transform_core.result.boundary.w;
3699         gh = ec->transform_core.result.boundary.h;
3700      }
3701    else
3702      {
3703         if (ec->frame)
3704           {
3705              evas_object_geometry_get(ec->frame, &gx, &gy, &gw, &gh);
3706              if (gw == 0 && gh == 0)
3707                {
3708                   /* In this case, there is no image buffer in e_comp_object, thus it
3709                    * should return geometry value of ec itself. It usually happens if
3710                    * new ec is not mapped yet.
3711                    */
3712                   gw = ec->w;
3713                   gh = ec->h;
3714                   gx = ec->x;
3715                   gy = ec->y;
3716                }
3717           }
3718         else
3719           {
3720              gx = ec->x;
3721              gy = ec->y;
3722              gw = ec->w;
3723              gh = ec->h;
3724           }
3725      }
3726
3727    if (x) *x = gx;
3728    if (y) *y = gy;
3729    if (w) *w = gw;
3730    if (h) *h = gh;
3731 }
3732
3733 E_API E_Client *
3734 e_client_above_get(const E_Client *ec)
3735 {
3736    unsigned int x;
3737    E_Client *ec2;
3738
3739    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
3740    if (EINA_INLIST_GET(ec)->next) //check current layer
3741      {
3742         EINA_INLIST_FOREACH(EINA_INLIST_GET(ec)->next, ec2)
3743           {
3744              if (ec == ec2)
3745                {
3746                   ELOGF("FATAL", "CHECK the ec inlist next", ec);
3747                   continue;
3748                }
3749              if (!e_object_is_del(E_OBJECT(ec2)))
3750                return ec2;
3751           }
3752      }
3753    if (ec->layer == E_LAYER_CLIENT_CURSOR) return NULL;
3754    if (e_comp_canvas_client_layer_map(ec->layer) == 9999) return NULL;
3755
3756    g_rec_mutex_lock(&e_comp->ec_list_mutex);
3757    /* go up the layers until we find one */
3758    for (x = e_comp_canvas_layer_map(ec->layer) + 1; x <= e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x++)
3759      {
3760         if (!e_comp->layers[x].clients) continue;
3761         EINA_INLIST_FOREACH(e_comp->layers[x].clients, ec2)
3762           {
3763              if (ec == ec2)
3764                {
3765                   ELOGF("FATAL", "EC exist above layer. ec layer_map:%d, cur layer_map:%d",
3766                         ec, e_comp_canvas_layer_map(ec->layer), x);
3767                   continue;
3768                }
3769              if (!e_object_is_del(E_OBJECT(ec2)))
3770                {
3771                   g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3772                   return ec2;
3773                }
3774           }
3775      }
3776    g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3777
3778    return NULL;
3779 }
3780
3781 E_API E_Client *
3782 e_client_below_get(const E_Client *ec)
3783 {
3784    unsigned int x;
3785    E_Client *ec2;
3786    Eina_Inlist *l;
3787    E_Layer ec_layer, ec_layer_cw;
3788    int cw_layer;
3789
3790    E_OBJECT_CHECK_RETURN(ec, NULL);
3791    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, NULL);
3792
3793    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
3794    if (EINA_INLIST_GET(ec)->prev) //check current layer
3795      {
3796         for (l = EINA_INLIST_GET(ec)->prev; l; l = l->prev)
3797           {
3798              ec2 = EINA_INLIST_CONTAINER_GET(l, E_Client);
3799              if (ec == ec2)
3800                {
3801                   ELOGF("FATAL", "CHECK the ec inlist prev", ec);
3802                   continue;
3803                }
3804              if (!e_object_is_del(E_OBJECT(ec2)))
3805                return ec2;
3806           }
3807      }
3808
3809    // check layer validation
3810    ec_layer = ec->layer;
3811    if (ec->layer_block || ec->layer_pending)
3812      {
3813         cw_layer = e_comp_object_layer_get(ec->frame);
3814         if (cw_layer >= 0)
3815           {
3816              ec_layer_cw = e_comp_canvas_layer_map_to(cw_layer);
3817              if (ec_layer != ec_layer_cw)
3818                {
3819                   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);
3820                   ec_layer = ec_layer_cw;
3821                }
3822           }
3823      }
3824
3825    if (ec_layer == E_LAYER_CLIENT_DESKTOP) return NULL;
3826    if (e_comp_canvas_client_layer_map(ec_layer) == 9999) return NULL;
3827
3828    /* go down the layers until we find one */
3829    x = e_comp_canvas_layer_map(ec_layer);
3830    if (x > 0) x--;
3831
3832    g_rec_mutex_lock(&e_comp->ec_list_mutex);
3833    for (; x >= e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x--)
3834      {
3835         if (!e_comp->layers[x].clients) continue;
3836         EINA_INLIST_REVERSE_FOREACH(e_comp->layers[x].clients, ec2)
3837           {
3838              if (ec == ec2)
3839                {
3840                   ELOGF("FATAL", "EC exist below layer. ec layer_map:%d, cur layer_map:%d",
3841                         ec, e_comp_canvas_layer_map(ec_layer), x);
3842                   continue;
3843                }
3844              if (!e_object_is_del(E_OBJECT(ec2)))
3845                {
3846                   g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3847                   return ec2;
3848                }
3849           }
3850      }
3851    g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3852
3853    return NULL;
3854 }
3855
3856 E_API E_Client *
3857 e_client_bottom_get(void)
3858 {
3859    unsigned int x;
3860    g_rec_mutex_lock(&e_comp->ec_list_mutex);
3861    for (x = e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x <= e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x++)
3862      {
3863         E_Client *ec2;
3864
3865         if (!e_comp->layers[x].clients) continue;
3866         EINA_INLIST_FOREACH(e_comp->layers[x].clients, ec2)
3867           if (!e_object_is_del(E_OBJECT(ec2)))
3868             {
3869                g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3870                return ec2;
3871             }
3872      }
3873    g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3874
3875    return NULL;
3876 }
3877
3878 E_API E_Client *
3879 e_client_top_get(void)
3880 {
3881    unsigned int x;
3882    g_rec_mutex_lock(&e_comp->ec_list_mutex);
3883    for (x = e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x >= e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x--)
3884      {
3885         E_Client *ec2;
3886
3887         if (!e_comp->layers[x].clients) continue;
3888         EINA_INLIST_REVERSE_FOREACH(e_comp->layers[x].clients, ec2)
3889           if (!e_object_is_del(E_OBJECT(ec2)))
3890             {
3891                g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3892                return ec2;
3893             }
3894      }
3895    g_rec_mutex_unlock(&e_comp->ec_list_mutex);
3896
3897    return NULL;
3898 }
3899
3900 EINTERN unsigned int
3901 e_clients_count(void)
3902 {
3903    return eina_list_count(e_comp->clients);
3904 }
3905
3906
3907 /**
3908  * Set a callback which will be called just prior to updating the
3909  * move coordinates for a border
3910  */
3911 EINTERN void
3912 e_client_move_intercept_cb_set(E_Client *ec, E_Client_Move_Intercept_Cb cb)
3913 {
3914    ec->move_intercept_cb = cb;
3915 }
3916
3917 ///////////////////////////////////////
3918
3919 E_API E_Client_Hook *
3920 e_client_hook_add(E_Client_Hook_Point hookpoint, E_Client_Hook_Cb func, const void *data)
3921 {
3922    E_Client_Hook *ch;
3923
3924    EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_CLIENT_HOOK_LAST, NULL);
3925    ch = E_NEW(E_Client_Hook, 1);
3926    if (!ch) return NULL;
3927    ch->hookpoint = hookpoint;
3928    ch->func = func;
3929    ch->data = (void*)data;
3930    _e_client_hooks[hookpoint] = eina_inlist_append(_e_client_hooks[hookpoint], EINA_INLIST_GET(ch));
3931    return ch;
3932 }
3933
3934 E_API void
3935 e_client_hook_del(E_Client_Hook *ch)
3936 {
3937    ch->delete_me = 1;
3938    if (_e_client_hooks_walking == 0)
3939      {
3940         _e_client_hooks[ch->hookpoint] = eina_inlist_remove(_e_client_hooks[ch->hookpoint], EINA_INLIST_GET(ch));
3941         free(ch);
3942      }
3943    else
3944      _e_client_hooks_delete++;
3945 }
3946
3947 ///////////////////////////////////////
3948
3949 E_API E_Client_Intercept_Hook *
3950 e_client_intercept_hook_add(E_Client_Intercept_Hook_Point hookpoint, E_Client_Intercept_Hook_Cb func, const void *data)
3951 {
3952    E_Client_Intercept_Hook *ch;
3953
3954    EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_CLIENT_INTERCEPT_HOOK_LAST, NULL);
3955    ch = E_NEW(E_Client_Intercept_Hook, 1);
3956    if (!ch) return NULL;
3957    ch->hookpoint = hookpoint;
3958    ch->func = func;
3959    ch->data = (void*)data;
3960    _e_client_intercept_hooks[hookpoint] = eina_inlist_append(_e_client_intercept_hooks[hookpoint], EINA_INLIST_GET(ch));
3961    return ch;
3962 }
3963
3964 E_API void
3965 e_client_intercept_hook_del(E_Client_Intercept_Hook *ch)
3966 {
3967    if (!ch) return;
3968
3969    ch->delete_me = 1;
3970    if (_e_client_intercept_hooks_walking == 0)
3971      {
3972         _e_client_intercept_hooks[ch->hookpoint] =
3973            eina_inlist_remove(_e_client_intercept_hooks[ch->hookpoint], EINA_INLIST_GET(ch));
3974         free(ch);
3975      }
3976    else
3977      _e_client_intercept_hooks_delete++;
3978 }
3979
3980 E_API void
3981 e_client_focus_latest_set(E_Client *ec)
3982 {
3983    EINA_SAFETY_ON_NULL_RETURN(ec);
3984
3985    wl_signal_emit_mutable(&PRI(ec)->events.focus_latest_set, NULL);
3986 }
3987
3988 E_API void
3989 e_client_focus_defer_set(E_Client *ec)
3990 {
3991    EINA_SAFETY_ON_NULL_RETURN(ec);
3992
3993    wl_signal_emit_mutable(&PRI(ec)->events.focus_defer_set, NULL);
3994 }
3995
3996 EINTERN void
3997 e_client_focused_set(E_Client *ec)
3998 {
3999    E_Client *focused_ec;
4000    E_Zone *zone;
4001
4002    if (ec)
4003      ELOGF("FOCUS", "CLIENT FOCUSED_SET : SET", ec);
4004    else
4005      ELOGF("FOCUS", "CLIENT FOCUSED_SET : UNSET", NULL);
4006
4007   focused_ec = e_comp_focused_ec_get();
4008   if (ec == focused_ec) return;
4009
4010    TRACE_DS_BEGIN(CLIENT:FOCUSED SET);
4011
4012    // unset the current focused_ec if focused_ec is not being deleted
4013    if (focused_ec)
4014      {
4015        if (!e_object_is_del(E_OBJECT(focused_ec)))
4016          {
4017             // FIXME: Remove focus_unset event of client.
4018             //        Instead, make zone focus_unset event and use it.
4019             wl_signal_emit_mutable(&PRI(focused_ec)->events.focus_unset, NULL);
4020             _e_client_hook_call(E_CLIENT_HOOK_FOCUS_UNSET, focused_ec);
4021
4022             if (e_object_ref_get(E_OBJECT(focused_ec)) > 0)
4023               {
4024                  _e_client_event_simple(focused_ec, E_EVENT_CLIENT_FOCUS_OUT);
4025                  e_client_urgent_set(focused_ec, focused_ec->icccm.urgent);
4026               }
4027          }
4028      }
4029
4030    // clear the current focused_ec when ec is NULL
4031    if (!ec)
4032      {
4033         zone = e_comp_zone_find_by_ec(focused_ec);
4034         e_zone_focus_clear(zone);
4035         TRACE_DS_END();
4036         return;
4037      }
4038
4039    // FIXME: Remove focus_set event of client.
4040    //        Instead, make zone focus_set event and use it.
4041    // set the new current focused_ec
4042    wl_signal_emit_mutable(&PRI(ec)->events.focus_set, NULL);
4043    _e_client_hook_call(E_CLIENT_HOOK_FOCUS_SET, ec);
4044
4045    // send the client_focuse_in event
4046    _e_client_event_simple(ec, E_EVENT_CLIENT_FOCUS_IN);
4047
4048    TRACE_DS_END();
4049 }
4050
4051 EINTERN void
4052 e_client_activate(E_Client *ec)
4053 {
4054    E_OBJECT_CHECK(ec);
4055    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4056
4057    TRACE_DS_BEGIN(CLIENT:ACTIVATE);
4058
4059    ELOGF("COMP", "Set launching flag..", ec);
4060    ec->launching = EINA_TRUE;
4061
4062    ec->exp_iconify.not_raise = 0;
4063
4064    if (ec->iconic)
4065      {
4066          if (!ec->lock_user_iconify)
4067            e_client_uniconify(ec);
4068      }
4069    ELOGF("COMP", "Un-Set ICONIFY BY CLIENT", ec);
4070    ec->exp_iconify.by_client = 0;
4071    e_client_iconified_type_set(ec, E_ICONIFIED_TYPE_NONE);
4072
4073    wl_signal_emit_mutable(&PRI(ec)->events.activate_done, NULL);
4074    _e_client_hook_call(E_CLIENT_HOOK_ACTIVATE_DONE, ec);
4075
4076    TRACE_DS_END();
4077 }
4078
4079 E_API E_Client *
4080 e_client_focused_get(void)
4081 {
4082    return e_comp_focused_ec_get();
4083 }
4084
4085 EINTERN Eina_List *
4086 e_client_lost_windows_get(E_Zone *zone)
4087 {
4088    Eina_List *list = NULL;
4089    const Eina_List *l;
4090    E_Client *ec;
4091    int loss_overlap = 5;
4092
4093    E_OBJECT_CHECK_RETURN(zone, NULL);
4094    E_OBJECT_TYPE_CHECK_RETURN(zone, E_ZONE_TYPE, NULL);
4095    EINA_LIST_FOREACH(e_comp->clients, l, ec)
4096      {
4097         if (!e_zone_has_ec(zone, ec)) continue;
4098         if (e_client_util_ignored_get(ec)) continue;
4099
4100         if (!E_INTERSECTS(zone->x + loss_overlap,
4101                           zone->y + loss_overlap,
4102                           zone->w - (2 * loss_overlap),
4103                           zone->h - (2 * loss_overlap),
4104                           ec->x, ec->y, ec->w, ec->h))
4105           {
4106              list = eina_list_append(list, ec);
4107           }
4108      }
4109    return list;
4110 }
4111
4112 ///////////////////////////////////////
4113
4114 EINTERN void
4115 e_client_shade(E_Client *ec, E_Direction dir)
4116 {
4117    E_OBJECT_CHECK(ec);
4118    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4119    if ((ec->shaded) || (ec->shading) || (ec->fullscreen) ||
4120        ((ec->maximized) && (!e_config->allow_manip))) return;
4121    if (!e_util_strcmp("borderless", ec->bordername)) return;
4122    if (!e_comp_object_frame_allowed(ec->frame)) return;
4123
4124    ec->take_focus = 0;
4125    ec->shading = 1;
4126    ec->shade_dir = dir;
4127
4128    evas_object_smart_callback_call(ec->frame, "shaded", (uintptr_t*)dir);
4129 }
4130
4131 EINTERN void
4132 e_client_unshade(E_Client *ec, E_Direction dir)
4133 {
4134    E_OBJECT_CHECK(ec);
4135    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4136    if ((!ec->shaded) || (ec->shading))
4137      return;
4138
4139    ec->shading = 1;
4140    ec->shade_dir = 0;
4141
4142    evas_object_smart_callback_call(ec->frame, "unshaded", (uintptr_t*)dir);
4143 }
4144
4145 ///////////////////////////////////////
4146
4147 EINTERN void
4148 e_client_maximized_geometry_set(E_Client *ec, int x, int y, int w, int h)
4149 {
4150    if (!ec) return;
4151
4152    ec->maximized_info.x = x;
4153    ec->maximized_info.y = y;
4154    ec->maximized_info.w = w;
4155    ec->maximized_info.h = h;
4156
4157    e_client_frame_geometry_set(ec, x, y, w, h);
4158 }
4159
4160 EINTERN void
4161 e_client_maximized_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
4162 {
4163    if (!ec) return;
4164
4165    if (x) *x = ec->maximized_info.x;
4166    if (y) *y = ec->maximized_info.y;
4167    if (w) *w = ec->maximized_info.w;
4168    if (h) *h = ec->maximized_info.h;
4169 }
4170
4171 EINTERN void
4172 e_client_maximize_update(E_Client *ec)
4173 {
4174    E_Maximize max;
4175
4176    E_OBJECT_CHECK(ec);
4177    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4178
4179    if (ec->maximized)
4180      {
4181         max = ec->maximized;
4182         ec->maximized = 0;
4183         e_client_maximize(ec, max);
4184      }
4185 }
4186
4187 E_API void
4188 e_client_maximize(E_Client *ec, E_Maximize max)
4189 {
4190    E_OBJECT_CHECK(ec);
4191    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4192
4193    if (!(max & E_MAXIMIZE_DIRECTION)) max |= E_MAXIMIZE_BOTH;
4194
4195    if ((ec->shaded) || (ec->shading)) return;
4196
4197    if ((ec->maximized & E_MAXIMIZE_DIRECTION) == (max & E_MAXIMIZE_DIRECTION))
4198      {
4199         if ((ec->maximized & E_MAXIMIZE_TYPE) == (max & E_MAXIMIZE_TYPE))
4200           return;
4201      }
4202
4203    if (ec->new_client)
4204      {
4205         ec->changes.need_maximize = 1;
4206         ec->maximized &= ~E_MAXIMIZE_TYPE;
4207         ec->maximized |= max;
4208         EC_CHANGED(ec);
4209         return;
4210      }
4211
4212    if (!ec->fullscreen)
4213      {
4214         // call the maximize hook of a client
4215         wl_signal_emit_mutable(&PRI(ec)->events.maximize, &max);
4216
4217         // store the E_Maximize value
4218         ec->maximized = max;
4219         ec->changes.need_unmaximize = 0;
4220
4221         evas_object_smart_callback_call(ec->frame, "maximize_done", NULL);
4222      }
4223    else
4224      {
4225         // store the E_Maximize value
4226         ec->maximized = max;
4227         ec->changes.need_unmaximize = 0;
4228      }
4229 }
4230
4231 E_API void
4232 e_client_unmaximize(E_Client *ec, E_Maximize max)
4233 {
4234    E_OBJECT_CHECK(ec);
4235    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4236
4237    if (!(max & E_MAXIMIZE_DIRECTION))
4238      {
4239         CRI("BUG: Unmaximize call without direction!");
4240         return;
4241      }
4242    if (ec->new_client)
4243      {
4244         ec->changes.need_unmaximize = 1;
4245         EC_CHANGED(ec);
4246         return;
4247      }
4248
4249    if ((ec->shaded) || (ec->shading)) return;
4250
4251    /* Remove directions not used */
4252    max &= (ec->maximized & E_MAXIMIZE_DIRECTION);
4253    /* Can only remove existing maximization directions */
4254    if (!max) return;
4255
4256    if (!ec->fullscreen)
4257      {
4258         evas_object_smart_callback_call(ec->frame, "unmaximize_pre", NULL);
4259
4260         // call the unmaximize hook of a client
4261         wl_signal_emit_mutable(&PRI(ec)->events.unmaximize, &max);
4262
4263         evas_object_smart_callback_call(ec->frame, "unmaximize_done", NULL);
4264      }
4265
4266    ec->maximized = E_MAXIMIZE_NONE;
4267    ec->changes.need_unmaximize = 0;
4268 }
4269
4270 EINTERN void
4271 e_client_fullscreen(E_Client *ec, E_Fullscreen policy)
4272 {
4273    E_OBJECT_CHECK(ec);
4274    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4275
4276    if ((ec->shaded) || (ec->shading) || (ec->fullscreen)) return;
4277
4278    // call the fullscreen_pre hook of a client
4279    wl_signal_emit_mutable(&PRI(ec)->events.fullscreen_pre, NULL);
4280    _e_client_hook_call(E_CLIENT_HOOK_FULLSCREEN_PRE, ec);
4281
4282    if (ec->skip_fullscreen) return;
4283    if (ec->new_client)
4284      {
4285         ec->need_fullscreen = 1;
4286         return;
4287      }
4288
4289    ec->saved.layer = ec->layer;
4290    e_client_layer_set(ec, ec->fullscreen_layer);
4291
4292    ec->fullscreen = 1;
4293
4294    // call the fullscreen hook of a client
4295    wl_signal_emit_mutable(&PRI(ec)->events.fullscreen, &policy);
4296
4297    ec->fullscreen_policy = policy;
4298
4299    _e_client_event_simple(ec, E_EVENT_CLIENT_FULLSCREEN);
4300 }
4301
4302 EINTERN void
4303 e_client_unfullscreen(E_Client *ec)
4304 {
4305    E_OBJECT_CHECK(ec);
4306    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4307
4308    ec->need_fullscreen = 0;
4309
4310    if ((ec->shaded) || (ec->shading)) return;
4311    if (!ec->fullscreen) return;
4312
4313    ec->fullscreen = 0;
4314
4315    E_Fullscreen policy = ec->fullscreen_policy;
4316
4317    // call the unfullscreen hook of a client
4318    wl_signal_emit_mutable(&PRI(ec)->events.unfullscreen, &policy);
4319
4320    e_client_layer_set(ec, ec->saved.layer);
4321
4322    ec->fullscreen_policy = E_FULLSCREEN_RESIZE;
4323
4324    _e_client_event_simple(ec, E_EVENT_CLIENT_UNFULLSCREEN);
4325 }
4326
4327 ///////////////////////////////////////
4328 EINTERN Eina_Bool
4329 e_client_is_parent_iconify_by_client(E_Client *ec)
4330 {
4331    E_Client *parent = ec->parent;
4332    if (!parent) return EINA_FALSE;
4333
4334    if ((parent->exp_iconify.type == E_ICONIFIED_TYPE_ICONIFY_BY_CLIENT) ||
4335        (parent->exp_iconify.type == E_ICONIFIED_TYPE_PARENT_ICONIFY_BY_CLIENT))
4336      return EINA_TRUE;
4337
4338    return EINA_FALSE;
4339 }
4340
4341 E_API void
4342 e_client_iconify(E_Client *ec)
4343 {
4344    E_OBJECT_CHECK(ec);
4345    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4346
4347    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
4348    Eina_Bool iconified_by_client = e_client_is_iconified_by_client(ec);
4349
4350    ELOGF("TZVIS", "ICONIFY  |iconic:%d  |argb:%d       |not_raise:%d   |by_client:%d, type:%d",
4351          ec, ec->iconic, ec->argb, (unsigned int)ec->exp_iconify.not_raise,
4352          ec->exp_iconify.by_client, ec->exp_iconify.type);
4353
4354    if (ec->shading || ec->iconic) return;
4355    if (ec->exp_iconify.skip_iconify && !iconified_by_client) return;
4356    if (ec->exp_iconify.skip_by_remote) return;
4357    if (!cdata || !cdata->mapped)
4358      {
4359         if (!iconified_by_client)
4360           {
4361              ELOGF("TZVIS", "Not mapped.. So, don't iconify", ec);
4362              return;
4363           }
4364         else
4365           {
4366              ELOGF("TZVIS", "Not mapped.. But, iconify by user request", ec);
4367           }
4368      }
4369
4370    TRACE_DS_BEGIN(CLIENT:ICONIFY);
4371
4372    wl_signal_emit_mutable(&PRI(ec)->events.iconify, NULL);
4373    _e_client_hook_call(E_CLIENT_HOOK_ICONIFY, ec);
4374
4375    TRACE_DS_END();
4376 }
4377
4378 E_API void
4379 e_client_uniconify(E_Client *ec)
4380 {
4381    E_Comp_Wl_Client_Data *cdata;
4382
4383    E_OBJECT_CHECK(ec);
4384    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4385
4386    cdata = e_client_cdata_get(ec);
4387
4388    ELOGF("TZVIS", "UNICONIFY|iconic:%d  |argb:%d       |not_raise:%d  |by_client:%d, type:%d |mapped:%d",
4389          ec, ec->iconic, ec->argb, (unsigned int)ec->exp_iconify.not_raise,
4390          ec->exp_iconify.by_client, ec->exp_iconify.type,
4391          cdata ? cdata->mapped : 0);
4392
4393    if (ec->shading || (!ec->iconic)) return;
4394
4395    TRACE_DS_BEGIN(CLIENT:UNICONIFY);
4396
4397     // call the uniconify hook of a client
4398    wl_signal_emit_mutable(&PRI(ec)->events.uniconify, NULL);
4399    _e_client_hook_call(E_CLIENT_HOOK_UNICONIFY, ec);
4400
4401    TRACE_DS_END();
4402 }
4403
4404 E_API void
4405 e_client_iconified_type_set(E_Client *ec, E_Iconified_Type type)
4406 {
4407    if (!ec) return;
4408    ec->exp_iconify.type = type;
4409 }
4410
4411 EINTERN E_Iconified_Type
4412 e_client_iconified_type_get(E_Client *ec)
4413 {
4414    if (!ec) return E_ICONIFIED_TYPE_NONE;
4415    return ec->exp_iconify.type;
4416 }
4417
4418 E_API Eina_Bool e_client_is_iconified_by_client(E_Client *ec)
4419 {
4420    if (!ec) return EINA_FALSE;
4421
4422    if (ec->exp_iconify.type == E_ICONIFIED_TYPE_ICONIFY_BY_CLIENT)
4423      return EINA_TRUE;
4424
4425    if (ec->exp_iconify.type == E_ICONIFIED_TYPE_DESK_ICONIFY_BY_CLIENT)
4426      return EINA_TRUE;
4427
4428    if (ec->exp_iconify.type == E_ICONIFIED_TYPE_PARENT_ICONIFY_BY_CLIENT)
4429      return EINA_TRUE;
4430
4431    if (ec->exp_iconify.by_client)
4432      {
4433         ELOGF("POL", "CHECK. mismatch value. by_client:%d, type:%d", ec, ec->exp_iconify.by_client, ec->exp_iconify.type);
4434         return EINA_TRUE;
4435      }
4436
4437    return EINA_FALSE;
4438 }
4439
4440 ///////////////////////////////////////
4441
4442 EINTERN void
4443 e_client_urgent_set(E_Client *ec, Eina_Bool urgent)
4444 {
4445    E_OBJECT_CHECK(ec);
4446    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4447
4448    urgent = !!urgent;
4449    if (urgent == ec->urgent) return;
4450    _e_client_event_property(ec, E_CLIENT_PROPERTY_URGENCY);
4451    if (urgent && (!ec->focused) && (!ec->want_focus))
4452      {
4453         e_comp_object_signal_emit(ec->frame, "e,state,urgent", "e");
4454         ec->urgent = urgent;
4455      }
4456    else
4457      {
4458         e_comp_object_signal_emit(ec->frame, "e,state,not_urgent", "e");
4459         ec->urgent = 0;
4460      }
4461 }
4462
4463 ///////////////////////////////////////
4464
4465 EINTERN void
4466 e_client_stick(E_Client *ec)
4467 {
4468    E_OBJECT_CHECK(ec);
4469    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4470    if (ec->sticky) return;
4471
4472    // call the stick hook of a client
4473    wl_signal_emit_mutable(&PRI(ec)->events.stick, NULL);
4474
4475    // send the sticky property event of a client
4476    _e_client_event_property(ec, E_CLIENT_PROPERTY_STICKY);
4477 }
4478
4479 EINTERN void
4480 e_client_unstick(E_Client *ec)
4481 {
4482    E_OBJECT_CHECK(ec);
4483    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4484
4485    if (!ec->sticky) return;
4486
4487    // call the unstick hook of a client
4488    wl_signal_emit_mutable(&PRI(ec)->events.unstick, NULL);
4489
4490   // send the sticky property event of a client
4491    _e_client_event_property(ec, E_CLIENT_PROPERTY_STICKY);
4492 }
4493
4494 EINTERN void
4495 e_client_pinned_set(E_Client *ec, Eina_Bool set)
4496 {
4497    E_Layer layer;
4498
4499    EINA_SAFETY_ON_NULL_RETURN(ec);
4500    if (set)
4501      layer = E_LAYER_CLIENT_ABOVE;
4502    else
4503      layer = E_LAYER_CLIENT_NORMAL;
4504
4505    e_client_layer_set(ec, layer);
4506
4507    EC_CHANGED(ec);
4508 }
4509
4510 ///////////////////////////////////////
4511
4512 EINTERN Eina_Bool
4513 e_client_border_set(E_Client *ec, const char *name)
4514 {
4515    Eina_Stringshare *pborder;
4516
4517    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
4518    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, EINA_FALSE);
4519    if (!e_comp_object_frame_allowed(ec->frame)) return EINA_FALSE;
4520    if (ec->border.changed)
4521      CRI("CALLING WHEN border.changed SET!");
4522
4523    if (!e_util_strcmp(ec->border.name, name)) return EINA_TRUE;
4524    if (ec->mwm.borderless && name && strcmp(name, "borderless"))
4525      {
4526         CRI("border change attempted for MWM borderless client!");
4527      }
4528    pborder = ec->border.name;
4529    ec->border.name = eina_stringshare_add(name);
4530    if (e_comp_object_frame_theme_set(ec->frame, name))
4531      {
4532         eina_stringshare_del(pborder);
4533         return EINA_TRUE;
4534      }
4535    eina_stringshare_del(ec->border.name);
4536    ec->border.name = pborder;
4537    return EINA_FALSE;
4538 }
4539
4540 ///////////////////////////////////////
4541
4542 EINTERN void
4543 e_client_comp_hidden_set(E_Client *ec, Eina_Bool hidden)
4544 {
4545    E_OBJECT_CHECK(ec);
4546    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4547
4548    hidden = !!hidden;
4549    if (ec->comp_hidden == hidden) return;
4550    ec->comp_hidden = hidden;
4551    evas_object_smart_callback_call(ec->frame, "comp_hidden", NULL);
4552 }
4553
4554 ///////////////////////////////////////
4555
4556 EINTERN void
4557 e_client_act_move_keyboard(E_Client *ec)
4558 {
4559    EINA_SAFETY_ON_NULL_RETURN(ec);
4560
4561    if (!_e_client_move_begin(ec))
4562      return;
4563
4564    _e_client_action_init(ec);
4565    _e_client_action_move_timeout_add();
4566
4567    wl_signal_emit_mutable(&PRI(ec)->events.move_update, NULL);
4568    if (!_e_client_hook_call(E_CLIENT_HOOK_MOVE_UPDATE, ec)) return;
4569    evas_object_freeze_events_set(ec->frame, 1);
4570
4571    if (!action_handler_mouse)
4572      action_handler_mouse = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, _e_client_move_mouse_down, NULL);
4573 }
4574
4575 EINTERN void
4576 e_client_act_resize_keyboard(E_Client *ec)
4577 {
4578    EINA_SAFETY_ON_NULL_RETURN(ec);
4579
4580    ec->resize_mode = E_POINTER_RESIZE_TL;
4581    ec->keyboard_resizing = 1;
4582    if (!e_client_resize_begin(ec))
4583      {
4584         ec->keyboard_resizing = 0;
4585         return;
4586      }
4587
4588    _e_client_action_init(ec);
4589    _e_client_action_resize_timeout_add();
4590    evas_object_freeze_events_set(ec->frame, 1);
4591
4592    if (!action_handler_mouse)
4593      action_handler_mouse = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, _e_client_resize_mouse_down, NULL);
4594 }
4595
4596 EINTERN void
4597 e_client_act_move_begin(E_Client *ec, E_Binding_Event_Mouse_Button *ev)
4598 {
4599    E_OBJECT_CHECK(ec);
4600    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4601    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4602    if (ev)
4603      {
4604         char source[256];
4605
4606         snprintf(source, sizeof(source) - 1, "mouse,down,%i", ev->button);
4607         _e_client_moveinfo_gather(ec, source);
4608      }
4609    if (!_e_client_move_begin(ec))
4610      return;
4611
4612    _e_client_action_init(ec);
4613 }
4614
4615 E_API void
4616 e_client_act_move_end(E_Client *ec, E_Binding_Event_Mouse_Button *ev EINA_UNUSED)
4617 {
4618    E_OBJECT_CHECK(ec);
4619    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4620    if (!ec->moving) return;
4621    _e_client_move_end(ec);
4622    _e_client_action_finish();
4623 }
4624
4625 EINTERN void
4626 e_client_act_resize_begin(E_Client *ec, E_Binding_Event_Mouse_Button *ev, E_Pointer_Mode resize_mode)
4627 {
4628    E_OBJECT_CHECK(ec);
4629    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4630    if (ec->lock_user_size || ec->shaded || ec->shading) return;
4631    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4632    if (ev)
4633      {
4634         char source[256];
4635         snprintf(source, sizeof(source) - 1, "mouse,down,%i", ev->button);
4636         _e_client_moveinfo_gather(ec, source);
4637
4638         if (resize_mode != E_POINTER_RESIZE_NONE)
4639           {
4640              ec->resize_mode = resize_mode;
4641           }
4642         else
4643           {
4644              /* Use canvas.x, canvas.y of event.
4645               * Transformed coordinates has to be considered for accurate resize_mode
4646               * rather than absolute coordinates. */
4647              if ((ev->canvas.x > (ec->x + ec->w / 5)) &&
4648                  (ev->canvas.x < (ec->x + ec->w * 4 / 5)))
4649                {
4650                   if (ev->canvas.y < (ec->y + ec->h / 2)) ec->resize_mode = E_POINTER_RESIZE_T;
4651                   else ec->resize_mode = E_POINTER_RESIZE_B;
4652                }
4653              else if (ev->canvas.x < (ec->x + ec->w / 2))
4654                {
4655                   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;
4656                   else if (ev->canvas.y < (ec->y + ec->h / 2)) ec->resize_mode = E_POINTER_RESIZE_TL;
4657                   else ec->resize_mode = E_POINTER_RESIZE_BL;
4658                }
4659              else
4660                {
4661                   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;
4662                   else if (ev->canvas.y < (ec->y + ec->h / 2)) ec->resize_mode = E_POINTER_RESIZE_TR;
4663                   else ec->resize_mode = E_POINTER_RESIZE_BR;
4664                }
4665           }
4666      }
4667    if (!e_client_resize_begin(ec))
4668      return;
4669    _e_client_action_init(ec);
4670 }
4671
4672 EINTERN void
4673 e_client_act_resize_end(E_Client *ec, E_Binding_Event_Mouse_Button *ev EINA_UNUSED)
4674 {
4675    E_OBJECT_CHECK(ec);
4676    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4677    if (e_client_util_resizing_get(ec))
4678      {
4679         _e_client_resize_end(ec);
4680         ec->changes.reset_gravity = 1;
4681         if (!e_object_is_del(E_OBJECT(ec)))
4682           EC_CHANGED(ec);
4683      }
4684    _e_client_action_finish();
4685 }
4686
4687 EINTERN void
4688 e_client_act_menu_begin(E_Client *ec, E_Binding_Event_Mouse_Button *ev, int key)
4689 {
4690    E_OBJECT_CHECK(ec);
4691    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4692 }
4693
4694 EINTERN void
4695 e_client_act_close_begin(E_Client *ec)
4696 {
4697    E_OBJECT_CHECK(ec);
4698    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4699    if (ec->lock_close) return;
4700    if (ec->icccm.delete_request)
4701      {
4702         ec->delete_requested = 1;
4703         evas_object_smart_callback_call(ec->frame, "delete_request", NULL);
4704      }
4705    else if (e_config->kill_if_close_not_possible)
4706      {
4707         e_client_act_kill_begin(ec);
4708      }
4709 }
4710
4711 EINTERN void
4712 e_client_act_kill_begin(E_Client *ec)
4713 {
4714    E_OBJECT_CHECK(ec);
4715    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4716    if (ec->internal) return;
4717    if (ec->lock_close) return;
4718    if ((ec->netwm.pid > 1) && (e_config->kill_process))
4719      {
4720         kill(ec->netwm.pid, SIGINT);
4721         ec->kill_timer = ecore_timer_add(e_config->kill_timer_wait,
4722                                          _e_client_cb_kill_timer, ec);
4723      }
4724    else
4725      evas_object_smart_callback_call(ec->frame, "kill_request", NULL);
4726 }
4727
4728 ////////////////////////////////////////////
4729
4730 EINTERN void
4731 e_client_ping(E_Client *ec)
4732 {
4733    E_OBJECT_CHECK(ec);
4734    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4735
4736    if (!e_config->ping_clients) return;
4737
4738    EINA_SAFETY_ON_TRUE_RETURN(e_object_is_del(E_OBJECT(ec)));
4739
4740    ec->ping_ok = 0;
4741    evas_object_smart_callback_call(ec->frame, "ping", NULL);
4742    ec->ping = ecore_loop_time_get();
4743    if (ec->ping_poller) ecore_poller_del(ec->ping_poller);
4744    ec->ping_poller = ecore_poller_add(ECORE_POLLER_CORE,
4745                                       e_config->ping_clients_interval,
4746                                       _e_client_cb_ping_poller, ec);
4747 }
4748
4749 ////////////////////////////////////////////
4750 E_API void
4751 e_client_cursor_map_apply(E_Client *ec, int rotation, int x, int y)
4752 {
4753    // TODO: remove(deprecate) this e_client_cursor_map_apply.
4754 }
4755
4756 EINTERN void
4757 e_client_move_cancel(void)
4758 {
4759    if (!ecmove) return;
4760    if (ecmove->cur_mouse_action)
4761      {
4762         E_Client *ec;
4763
4764         ec = ecmove;
4765         e_object_ref(E_OBJECT(ec));
4766         if (ec->cur_mouse_action->func.end_mouse)
4767           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", NULL);
4768         else if (ec->cur_mouse_action->func.end)
4769           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
4770         e_object_unref(E_OBJECT(ec->cur_mouse_action));
4771         ec->cur_mouse_action = NULL;
4772         e_object_unref(E_OBJECT(ec));
4773      }
4774    else
4775      _e_client_move_end(ecmove);
4776 }
4777
4778 EINTERN void
4779 e_client_resize_cancel(void)
4780 {
4781    if (!ecresize) return;
4782    if (ecresize->cur_mouse_action)
4783      {
4784         E_Client *ec;
4785
4786         ec = ecresize;
4787         e_object_ref(E_OBJECT(ec));
4788         if (ec->cur_mouse_action->func.end_mouse)
4789           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", NULL);
4790         else if (ec->cur_mouse_action->func.end)
4791           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
4792         e_object_unref(E_OBJECT(ec->cur_mouse_action));
4793         ec->cur_mouse_action = NULL;
4794         e_object_unref(E_OBJECT(ec));
4795      }
4796    else
4797      _e_client_resize_end(ecresize);
4798 }
4799
4800 EINTERN Eina_Bool
4801 e_client_resize_begin(E_Client *ec)
4802 {
4803    if ((ec->shaded) || (ec->shading) ||
4804        (ec->fullscreen) || (ec->lock_user_size))
4805      goto error;
4806    if (!_e_client_action_input_win_new()) goto error;
4807    ecresize = ec;
4808    if (ec->manage_resize.enable_aspect_ratio)
4809      {
4810         ELOGF("RESIZE", "Set resize aspect ratio.. ratio(%dx%d)", ec, ec->w, ec->h);
4811         ec->manage_resize.aw = ec->w;
4812         ec->manage_resize.ah = ec->h - ec->manage_resize.header_h - ec->manage_resize.footer_h;
4813      }
4814
4815    wl_signal_emit_mutable(&PRI(ec)->events.move_begin, NULL);
4816    _e_client_hook_call(E_CLIENT_HOOK_RESIZE_BEGIN, ec);
4817    if (ec->transformed)
4818      _e_client_transform_resize_begin(ec);
4819    if (!e_client_util_resizing_get(ec))
4820      {
4821         if (ecresize == ec) ecresize = NULL;
4822         _e_client_action_input_win_del();
4823         return EINA_FALSE;
4824      }
4825    if (!ec->lock_user_stacking)
4826      {
4827         if (e_config->border_raise_on_mouse_action)
4828           e_client_raise(ec);
4829      }
4830
4831    if (e_comp->hwc)
4832      e_comp_client_override_add(ec);
4833
4834    return EINA_TRUE;
4835 error:
4836    ec->resize_mode = E_POINTER_RESIZE_NONE;
4837    return EINA_FALSE;
4838 }
4839
4840
4841 ////////////////////////////////////////////
4842
4843 EINTERN void
4844 e_client_frame_recalc(E_Client *ec)
4845 {
4846    EINA_SAFETY_ON_NULL_RETURN(ec);
4847    if (!ec->frame) return;
4848    evas_object_smart_callback_call(ec->frame, "frame_recalc", NULL);
4849 }
4850
4851 ////////////////////////////////////////////
4852
4853 EINTERN void
4854 e_client_signal_move_begin(E_Client *ec, const char *sig, const char *src EINA_UNUSED)
4855 {
4856    E_OBJECT_CHECK(ec);
4857    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4858
4859    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4860    _e_client_moveinfo_gather(ec, sig);
4861    if (!_e_client_move_begin(ec)) return;
4862 }
4863
4864 EINTERN void
4865 e_client_signal_move_end(E_Client *ec, const char *sig EINA_UNUSED, const char *src EINA_UNUSED)
4866 {
4867    E_OBJECT_CHECK(ec);
4868    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4869    if (!ec->moving) return;
4870    _e_client_move_end(ec);
4871 }
4872
4873 EINTERN void
4874 e_client_signal_resize_begin(E_Client *ec, const char *dir, const char *sig, const char *src EINA_UNUSED)
4875 {
4876    int resize_mode = E_POINTER_RESIZE_BR;
4877
4878    E_OBJECT_CHECK(ec);
4879    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4880
4881    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4882    if (!strcmp(dir, "tl"))
4883      {
4884         resize_mode = E_POINTER_RESIZE_TL;
4885      }
4886    else if (!strcmp(dir, "t"))
4887      {
4888         resize_mode = E_POINTER_RESIZE_T;
4889      }
4890    else if (!strcmp(dir, "tr"))
4891      {
4892         resize_mode = E_POINTER_RESIZE_TR;
4893      }
4894    else if (!strcmp(dir, "r"))
4895      {
4896         resize_mode = E_POINTER_RESIZE_R;
4897      }
4898    else if (!strcmp(dir, "br"))
4899      {
4900         resize_mode = E_POINTER_RESIZE_BR;
4901      }
4902    else if (!strcmp(dir, "b"))
4903      {
4904         resize_mode = E_POINTER_RESIZE_B;
4905      }
4906    else if (!strcmp(dir, "bl"))
4907      {
4908         resize_mode = E_POINTER_RESIZE_BL;
4909      }
4910    else if (!strcmp(dir, "l"))
4911      {
4912         resize_mode = E_POINTER_RESIZE_L;
4913      }
4914    ec->resize_mode = resize_mode;
4915    _e_client_moveinfo_gather(ec, sig);
4916    if (!e_client_resize_begin(ec))
4917      return;
4918 }
4919
4920 EINTERN void
4921 e_client_signal_resize_end(E_Client *ec, const char *dir EINA_UNUSED, const char *sig EINA_UNUSED, const char *src EINA_UNUSED)
4922 {
4923    E_OBJECT_CHECK(ec);
4924    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4925    if (!e_client_util_resizing_get(ec)) return;
4926    _e_client_resize_handle(ec);
4927    _e_client_resize_end(ec);
4928    ec->changes.reset_gravity = 1;
4929    EC_CHANGED(ec);
4930 }
4931
4932 ////////////////////////////////////////////
4933
4934 EINTERN void
4935 e_client_resize_limit(E_Client *ec, int *w, int *h)
4936 {
4937    double a;
4938    Eina_Bool inc_h;
4939
4940    E_OBJECT_CHECK(ec);
4941    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4942
4943    inc_h = (*h - ec->h > 0);
4944    if (ec->frame)
4945      e_comp_object_frame_wh_unadjust(ec->frame, *w, *h, w, h);
4946    if (*h < 1) *h = 1;
4947    if (*w < 1) *w = 1;
4948    if ((ec->icccm.base_w >= 0) &&
4949        (ec->icccm.base_h >= 0))
4950      {
4951         int tw, th;
4952
4953         tw = *w - ec->icccm.base_w;
4954         th = *h - ec->icccm.base_h;
4955         if (tw < 1) tw = 1;
4956         if (th < 1) th = 1;
4957         a = (double)(tw) / (double)(th);
4958         if ((ec->icccm.min_aspect != 0.0) &&
4959             (a < ec->icccm.min_aspect))
4960           {
4961              if (inc_h)
4962                tw = th * ec->icccm.min_aspect;
4963              else
4964                th = tw / ec->icccm.max_aspect;
4965              *w = tw + ec->icccm.base_w;
4966              *h = th + ec->icccm.base_h;
4967           }
4968         else if ((ec->icccm.max_aspect != 0.0) &&
4969                  (a > ec->icccm.max_aspect))
4970           {
4971              tw = th * ec->icccm.max_aspect;
4972              *w = tw + ec->icccm.base_w;
4973           }
4974      }
4975    else
4976      {
4977         a = (double)*w / (double)*h;
4978         if ((ec->icccm.min_aspect != 0.0) &&
4979             (a < ec->icccm.min_aspect))
4980           {
4981              if (inc_h)
4982                *w = *h * ec->icccm.min_aspect;
4983              else
4984                *h = *w / ec->icccm.min_aspect;
4985           }
4986         else if ((ec->icccm.max_aspect != 0.0) &&
4987                  (a > ec->icccm.max_aspect))
4988           *w = *h * ec->icccm.max_aspect;
4989      }
4990    if (ec->icccm.step_w > 0)
4991      {
4992         if (ec->icccm.base_w >= 0)
4993           *w = ec->icccm.base_w +
4994             (((*w - ec->icccm.base_w) / ec->icccm.step_w) *
4995              ec->icccm.step_w);
4996         else
4997           *w = ec->icccm.min_w +
4998             (((*w - ec->icccm.min_w) / ec->icccm.step_w) *
4999              ec->icccm.step_w);
5000      }
5001    if (ec->icccm.step_h > 0)
5002      {
5003         if (ec->icccm.base_h >= 0)
5004           *h = ec->icccm.base_h +
5005             (((*h - ec->icccm.base_h) / ec->icccm.step_h) *
5006              ec->icccm.step_h);
5007         else
5008           *h = ec->icccm.min_h +
5009             (((*h - ec->icccm.min_h) / ec->icccm.step_h) *
5010              ec->icccm.step_h);
5011      }
5012
5013    if (*h < 1) *h = 1;
5014    if (*w < 1) *w = 1;
5015
5016    if ((ec->icccm.max_w > 0) && (*w > ec->icccm.max_w)) *w = ec->icccm.max_w;
5017    else if (*w < ec->icccm.min_w)
5018      *w = ec->icccm.min_w;
5019    if ((ec->icccm.max_h > 0) && (*h > ec->icccm.max_h)) *h = ec->icccm.max_h;
5020    else if (*h < ec->icccm.min_h)
5021      *h = ec->icccm.min_h;
5022
5023    if (ec->frame)
5024      e_comp_object_frame_wh_adjust(ec->frame, *w, *h, w, h);
5025 }
5026
5027 ////////////////////////////////////////////
5028
5029
5030
5031 EINTERN E_Client *
5032 e_client_under_pointer_get(E_Desk *desk, E_Client *exclude)
5033 {
5034    int x, y;
5035
5036    /* We need to ensure that we can get the comp window for the
5037     * zone of either the given desk or the desk of the excluded
5038     * window, so return if neither is given */
5039    if (desk)
5040      e_input_device_pointer_xy_get(NULL, &x, &y);
5041    else if (exclude)
5042      e_input_device_pointer_xy_get(NULL, &x, &y);
5043    else
5044      return NULL;
5045
5046    if (!desk)
5047      {
5048         desk = exclude->desk;
5049         if (!desk)
5050           {
5051              if (exclude->zone)
5052                desk = e_desk_current_get(exclude->zone);
5053              else
5054                desk = e_desk_current_get(e_zone_current_get());
5055           }
5056      }
5057
5058    return desk ? _e_client_under_pointer_helper(desk, exclude, x, y) : NULL;
5059 }
5060
5061 E_API E_Client *e_client_under_position_get(E_Desk *desk, int x, int y, E_Client *exclude)
5062 {
5063    if (!desk) return NULL;
5064
5065    return _e_client_under_pointer_helper(desk, exclude, x, y);
5066 }
5067
5068 E_API E_Client *e_client_under_position_input_get(E_Desk *desk, int x, int y)
5069 {
5070    if (!desk) return NULL;
5071
5072    return _e_client_under_pointer_input_helper(desk, x, y);
5073 }
5074
5075 ////////////////////////////////////////////
5076
5077 ////////////////////////////////////////////
5078
5079 E_API void
5080 e_client_redirected_set(E_Client *ec, Eina_Bool set)
5081 {
5082    EINA_SAFETY_ON_NULL_RETURN(ec);
5083    if (ec->input_only) return;
5084    set = !!set;
5085    if (ec->redirected == set) return;
5086    if (set)
5087      {
5088         e_client_frame_recalc(ec);
5089
5090         wl_signal_emit_mutable(&PRI(ec)->events.redirect, NULL);
5091         if (!_e_client_hook_call(E_CLIENT_HOOK_REDIRECT, ec)) return;
5092      }
5093    else
5094      {
5095         wl_signal_emit_mutable(&PRI(ec)->events.unredirect, NULL);
5096         if (!_e_client_hook_call(E_CLIENT_HOOK_UNREDIRECT, ec)) return;
5097      }
5098    e_comp_object_redirected_set(ec->frame, set);
5099    ec->redirected = !!set;
5100 }
5101
5102 ////////////////////////////////////////////
5103
5104 EINTERN Eina_Bool
5105 e_client_is_stacking(const E_Client *ec)
5106 {
5107    return e_comp->layers[e_comp_canvas_layer_map(ec->layer)].obj == ec->frame;
5108 }
5109
5110 ////////////////////////////////////////////
5111
5112 E_API void
5113 e_client_transform_update(E_Client *ec)
5114 {
5115    if (e_client_util_resizing_get(ec))
5116      _e_client_transform_resize(ec);
5117 }
5118
5119 ////////////////////////////////////////////
5120
5121 EINTERN void
5122 e_client_transform_apply(E_Client *ec, double angle, double zoom, int cx, int cy)
5123 {
5124    E_Map *map;
5125    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
5126    E_Client *subc;
5127    Eina_List *l;
5128
5129    if (e_comp_wl_subsurface_check(ec))
5130      return;
5131
5132    /* check if it's different with current state */
5133    if ((ec->transform.angle == angle) &&
5134        (ec->transform.zoom == zoom) &&
5135        (ec->transform.center.x == cx) &&
5136        (ec->transform.center.y == cy))
5137      return;
5138
5139    /* use previous value if any required value is invalid */
5140    if (angle == -1.0)
5141      angle = ec->transform.angle;
5142    if (zoom == -1.0)
5143      zoom = ec->transform.zoom;
5144    if (!E_INSIDE(cx, cy,
5145                  ec->client.x, ec->client.y,
5146                  ec->client.w, ec->client.h))
5147      {
5148         cx = ec->transform.center.x;
5149         cy = ec->transform.center.y;
5150      }
5151
5152    if ((angle == 0) && (zoom == 1.0))
5153      {
5154         e_client_transform_clear(ec);
5155         return;
5156      }
5157
5158    map = e_map_new_with_direct_render(ec->transform_core.direct_render);
5159    e_map_util_points_populate_from_object_full(map, ec->frame, 0);
5160
5161    e_map_util_rotate(map, angle, cx, cy);
5162    _e_client_transform_geometry_save(ec, map);
5163
5164    e_map_util_zoom(map, zoom, zoom, cx, cy);
5165
5166    e_map_util_object_move_sync_set(map, EINA_TRUE);
5167    e_client_map_set(ec, map);
5168    e_client_map_enable_set(ec, EINA_TRUE);
5169
5170    EINA_LIST_FOREACH(cdata->sub.list, l, subc)
5171      _e_client_transform_sub_apply(subc, ec, zoom);
5172    EINA_LIST_REVERSE_FOREACH(cdata->sub.below_list, l, subc)
5173      _e_client_transform_sub_apply(subc, ec, zoom);
5174
5175    e_map_free(map);
5176
5177    ec->transform.zoom = zoom;
5178    ec->transform.angle = angle;
5179    ec->transform.center.x = cx;
5180    ec->transform.center.y = cy;
5181    ec->transformed = EINA_TRUE;
5182 }
5183
5184 ////////////////////////////////////////////
5185
5186 EINTERN void
5187 e_client_transform_clear(E_Client *ec)
5188 {
5189    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
5190    E_Client *subc;
5191    Eina_List *l;
5192
5193    e_client_map_enable_set(ec, EINA_FALSE);
5194    e_client_map_set(ec, NULL);
5195
5196    EINA_LIST_FOREACH(cdata->sub.list, l, subc)
5197      _e_client_transform_sub_apply(subc, ec, 1.0);
5198    EINA_LIST_REVERSE_FOREACH(cdata->sub.below_list, l, subc)
5199      _e_client_transform_sub_apply(subc, ec, 1.0);
5200
5201    ec->transform.zoom = 1.0;
5202    ec->transform.angle = 0.0;
5203    ec->transformed = EINA_FALSE;
5204 }
5205
5206 E_API Eina_Bool
5207 e_client_transform_core_enable_get(E_Client *ec)
5208 {
5209    if (!ec) return EINA_FALSE;
5210    return ec->transform_core.result.enable;
5211 }
5212
5213 E_API void
5214 e_client_transform_core_add(E_Client *ec, E_Util_Transform *transform)
5215 {
5216    if (!ec) return;
5217    if (!transform) return;
5218
5219    // duplication check
5220    if (ec->transform_core.transform_list &&
5221        eina_list_data_find(ec->transform_core.transform_list, transform) == transform)
5222      {
5223         return;
5224      }
5225
5226    ec->transform_core.transform_list = eina_list_append(ec->transform_core.transform_list, transform);
5227    ec->transform_core.changed = EINA_TRUE;
5228    e_util_transform_ref(transform);
5229   // e_client_transform_core_update(ec);
5230 }
5231
5232 E_API void
5233 e_client_transform_core_remove(E_Client *ec, E_Util_Transform *transform)
5234 {
5235    if (!ec) return;
5236    if (!transform) return;
5237
5238    if (ec->transform_core.transform_list &&
5239        eina_list_data_find(ec->transform_core.transform_list, transform) == transform)
5240      {
5241         ec->transform_core.transform_list = eina_list_remove(ec->transform_core.transform_list, transform);
5242         e_util_transform_unref(transform);
5243         ec->transform_core.changed = EINA_TRUE;
5244      }
5245
5246    e_client_transform_core_update(ec);
5247 }
5248
5249 E_API void
5250 e_client_transform_core_update(E_Client *ec)
5251 {
5252    if (!ec) return;
5253    if (ec->new_client) return;
5254    if (!_e_client_transform_core_check_change(ec)) return;
5255
5256    if (ec->transform_core.transform_list || ec->transform_core.parent.enable)
5257      {
5258         E_Util_Transform_Rect source_rect;
5259         E_Util_Transform_Matrix matrix, boundary_matrix;
5260         E_Util_Transform_Zoom zoom;
5261         Eina_List *l;
5262         Eina_Bool background;
5263         E_Util_Transform *temp_trans;
5264
5265         // 1. init state
5266         ec->transform_core.result.enable = EINA_TRUE;
5267         e_util_transform_rect_client_rect_get(&source_rect, ec);
5268         e_util_transform_init(&ec->transform_core.result.transform);
5269
5270         // 2. merge transform
5271         EINA_LIST_FOREACH(ec->transform_core.transform_list, l, temp_trans)
5272           {
5273              e_util_transform_merge(&ec->transform_core.result.transform, temp_trans);
5274           }
5275         zoom = ec->transform_core.result.transform.zoom;
5276
5277         // 2.5 check viewport
5278         if (e_util_transform_viewport_flag_get(&ec->transform_core.result.transform))
5279           {
5280              int vx = 0, vy = 0, vw = 0, vh = 0;
5281              e_util_transform_viewport_get(&ec->transform_core.result.transform, &vx, &vy, &vw, &vh);
5282              e_util_transform_rect_init(&source_rect, vx, vy, vw, vh);
5283           }
5284
5285         // 3. apply background transform
5286         matrix = e_util_transform_convert_to_matrix(&ec->transform_core.result.transform, &source_rect);
5287
5288         if (e_util_transform_bg_transform_flag_get(&ec->transform_core.result.transform))
5289           {
5290              boundary_matrix = e_util_transform_bg_convert_to_matrix(&ec->transform_core.result.transform, &source_rect);
5291              background = EINA_TRUE;
5292           }
5293         else
5294           {
5295              background = EINA_FALSE;
5296              boundary_matrix = matrix;
5297           }
5298
5299         if (background != ec->transform_core.background)
5300           {
5301              if (background)
5302                {
5303                   e_comp_object_transform_bg_set(ec->frame, EINA_TRUE);
5304                }
5305              else
5306                {
5307                   e_comp_object_transform_bg_set(ec->frame, EINA_FALSE);
5308                }
5309
5310              ec->transform_core.background = background;
5311           }
5312
5313         // 3.1 if 24bit window then set transp rect
5314         if (!ec->argb)
5315           {
5316              int angle = 0;
5317
5318              e_util_transform_rotation_round_get(&ec->transform_core.result.transform, 0, 0, &angle);
5319              angle %= 90;
5320
5321              if (angle == 0) // when transform angle is 0, 90, 180, 270, 360. then set transp rect
5322                e_comp_object_transform_transp_set(ec->frame, EINA_TRUE);
5323              else
5324                e_comp_object_transform_transp_set(ec->frame, EINA_FALSE);
5325           }
5326         else
5327           e_comp_object_transform_transp_set(ec->frame, EINA_FALSE);
5328
5329         // 3.5 parent matrix multiply
5330         if (ec->transform_core.parent.enable)
5331           {
5332              matrix = e_util_transform_matrix_multiply(&ec->transform_core.parent.matrix,
5333                                                        &matrix);
5334              boundary_matrix = e_util_transform_matrix_multiply(&ec->transform_core.parent.matrix,
5335                                                                 &boundary_matrix);
5336
5337              ec->transform_core.result.transform.use_zoom = EINA_TRUE;
5338              zoom.zoom_x *= ec->transform_core.parent.zoom.zoom_x;
5339              zoom.zoom_y *= ec->transform_core.parent.zoom.zoom_y;
5340              zoom.cx += ec->transform_core.parent.zoom.cx;
5341              zoom.cy += ec->transform_core.parent.zoom.cy;
5342           }
5343
5344         // 4. apply matrix to vertices
5345         ec->transform_core.result.matrix = matrix;
5346         ec->transform_core.result.inv_matrix = e_util_transform_matrix_inverse_get(&matrix);
5347         ec->transform_core.result.vertices = e_util_transform_rect_to_vertices(&source_rect);
5348         ec->transform_core.result.boundary.vertices = e_util_transform_rect_to_vertices(&source_rect);
5349         ec->transform_core.result.vertices = e_util_transform_matrix_multiply_rect_vertex(&matrix,
5350                                                                                           &ec->transform_core.result.vertices);
5351         ec->transform_core.result.boundary.vertices = e_util_transform_matrix_multiply_rect_vertex(&boundary_matrix,
5352                                                                                                    &ec->transform_core.result.boundary.vertices);
5353         ec->transform_core.result.transform.zoom = zoom;
5354
5355         // 5. apply vertices
5356         if (ec->transform_core.result.transform.use_zoom)
5357           {
5358              // TODO: apply zoom values to vertices
5359              e_comp_object_transform_transp_vertices_set_with_zoom(ec->frame, &ec->transform_core.result.vertices,
5360                                                                    ec->transform_core.result.transform.zoom);
5361              e_comp_object_transform_bg_vertices_set_with_zoom(ec->frame, &ec->transform_core.result.boundary.vertices,
5362                                                                ec->transform_core.result.transform.zoom);
5363              _e_client_transform_core_boundary_update(ec, &ec->transform_core.result.boundary.vertices);
5364              _e_client_transform_core_vertices_apply_with_zoom(ec, ec->frame, &ec->transform_core.result.vertices, &ec->transform_core.result.transform,
5365                                                                ec->transform_core.result.transform.zoom);
5366           }
5367         else
5368           {
5369              e_comp_object_transform_transp_vertices_set(ec->frame, &ec->transform_core.result.vertices);
5370              e_comp_object_transform_bg_vertices_set(ec->frame, &ec->transform_core.result.boundary.vertices);
5371              _e_client_transform_core_boundary_update(ec, &ec->transform_core.result.boundary.vertices);
5372              _e_client_transform_core_vertices_apply(ec, ec->frame, &ec->transform_core.result.vertices, &ec->transform_core.result.transform);
5373           }
5374
5375         // 6. subsurface update
5376         _e_client_transform_core_sub_update(ec, &ec->transform_core.result.vertices);
5377
5378         if (!e_object_is_del(E_OBJECT(ec)))
5379           {
5380              wl_signal_emit_mutable(&PRI(ec)->events.transform_change, NULL);
5381              _e_client_hook_call(E_CLIENT_HOOK_TRANSFORM_CHANGE, ec);
5382           }
5383      }
5384    else
5385      {
5386         if (ec->transform_core.result.enable)
5387           {
5388              ec->transform_core.result.enable = EINA_FALSE;
5389              _e_client_transform_core_vertices_apply(ec, ec->frame, NULL, NULL);
5390              e_comp_object_transform_bg_set(ec->frame, EINA_FALSE);
5391              ec->transform_core.background = EINA_FALSE;
5392              e_comp_object_transform_transp_set(ec->frame, EINA_FALSE);
5393              _e_client_transform_core_sub_update(ec, NULL);
5394
5395              if (!e_object_is_del(E_OBJECT(ec)))
5396                {
5397                   wl_signal_emit_mutable(&PRI(ec)->events.transform_change, NULL);
5398                   _e_client_hook_call(E_CLIENT_HOOK_TRANSFORM_CHANGE, ec);
5399                }
5400           }
5401      }
5402
5403    e_comp_visibility_calculation_set(EINA_TRUE);
5404 }
5405
5406 E_API int
5407 e_client_transform_core_transform_count_get(E_Client *ec)
5408 {
5409    if (!ec) return 0;
5410    if (!ec->transform_core.transform_list) return 0;
5411    return eina_list_count(ec->transform_core.transform_list);
5412 }
5413
5414 E_API E_Util_Transform*
5415 e_client_transform_core_transform_get(E_Client *ec, int index)
5416 {
5417    if (!ec) return NULL;
5418    if (!ec->transform_core.transform_list) return NULL;
5419    if (index < 0 || index >= e_client_transform_core_transform_count_get(ec))
5420       return NULL;
5421
5422    return (E_Util_Transform*)eina_list_nth(ec->transform_core.transform_list, index);
5423 }
5424
5425 E_API void
5426 e_client_transform_core_input_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.inv_matrix, &vertex);
5436    e_util_transform_vertex_pos_round_get(&result_vertex, out_x, out_y, NULL, NULL);
5437 }
5438
5439 E_API void
5440 e_client_transform_core_input_inv_transform(E_Client *ec, int x, int y, int *out_x, int *out_y)
5441 {
5442    E_Util_Transform_Vertex vertex, result_vertex;
5443
5444    if (!ec) return;
5445    if (!e_client_transform_core_enable_get(ec)) return;
5446
5447    e_util_transform_vertex_init(&vertex, x, y, 0.0, 1.0);
5448
5449    result_vertex = e_util_transform_matrix_multiply_vertex(&ec->transform_core.result.matrix, &vertex);
5450    e_util_transform_vertex_pos_round_get(&result_vertex, out_x, out_y, NULL, NULL);
5451 }
5452
5453 EINTERN void
5454 e_client_transform_core_input_inv_rect_transform(E_Client *ec, int x, int y, int *out_x, int *out_y)
5455 {
5456    int gw = 0, gh = 0;
5457    if (!ec) return;
5458    if (!e_client_transform_core_enable_get(ec)) return;
5459    e_client_geometry_get(ec, NULL, NULL, &gw, &gh);
5460
5461    e_util_transform_matrix_inv_rect_coords_get(&ec->transform_core.result.transform,
5462                                                &ec->transform_core.result.vertices,
5463                                                gw, gh,
5464                                                x, y, out_x, out_y);
5465 }
5466
5467 E_API void
5468 e_client_transform_core_direct_render_set(E_Client *ec, Eina_Bool set)
5469 {
5470    EINA_SAFETY_ON_NULL_RETURN(ec);
5471
5472    if (ec->transform_core.direct_render == set) return;
5473
5474    ec->transform_core.direct_render = set;
5475    ec->transform_core.changed = EINA_TRUE;
5476
5477    e_client_transform_core_update(ec);
5478 }
5479
5480 EINTERN E_Pixmap *
5481 e_client_pixmap_change(E_Client *ec, E_Pixmap *newcp)
5482 {
5483    E_Pixmap_Type oldtype, newtype;
5484    E_Pixmap *oldcp;
5485
5486    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
5487    EINA_SAFETY_ON_NULL_RETURN_VAL(ec->pixmap, NULL);
5488    EINA_SAFETY_ON_NULL_RETURN_VAL(newcp, NULL);
5489
5490    oldcp = ec->pixmap;
5491
5492    oldtype = e_pixmap_type_get(oldcp);
5493    if (oldtype >= E_PIXMAP_TYPE_MAX) return NULL;
5494
5495    newtype = e_pixmap_type_get(newcp);
5496    if (newtype >= E_PIXMAP_TYPE_MAX) return NULL;
5497
5498    if (eina_hash_find(clients_hash[oldtype], &oldcp))
5499      eina_hash_del_by_key(clients_hash[oldtype], &oldcp);
5500    e_pixmap_client_set(oldcp, NULL);
5501
5502    ec->pixmap = newcp;
5503    e_pixmap_client_set(newcp, ec);
5504
5505    eina_hash_add(clients_hash[newtype], &newcp, ec);
5506
5507    return oldcp;
5508 }
5509
5510 E_API void
5511 e_client_window_role_set(E_Client *ec, const char *role)
5512 {
5513    EINA_SAFETY_ON_NULL_RETURN(ec);
5514
5515    if (eina_stringshare_replace(&ec->icccm.window_role, role))
5516      {
5517         wl_signal_emit_mutable(&PRI(ec)->events.window_role_change, NULL);
5518         _e_client_hook_call(E_CLIENT_HOOK_WINDOW_ROLE_CHANGE, ec);
5519      }
5520 }
5521
5522 EINTERN Eina_Bool
5523 e_client_key_send(E_Client *ec, int keycode, Eina_Bool pressed, Ecore_Device *dev, unsigned int time)
5524 {
5525    Eina_Bool res;
5526
5527    res = e_comp_wl_key_send(ec, keycode, pressed, dev, time);
5528
5529    return res;
5530 }
5531
5532 EINTERN Eina_Bool
5533 e_client_key_cancel(E_Client *ec, int keycode, Ecore_Device *dev, unsigned int time)
5534 {
5535    Eina_Bool res;
5536
5537    res = e_comp_wl_key_cancel(ec, keycode, dev, time);
5538
5539    return res;
5540 }
5541
5542 EINTERN Eina_Bool
5543 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)
5544 {
5545    Eina_Bool res;
5546
5547    res = e_comp_wl_touch_send(ec, idx, x, y, pressed, dev, radius_x, radius_y, pressure, angle, time);
5548
5549    return res;
5550 }
5551
5552 EINTERN Eina_Bool
5553 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)
5554 {
5555    Eina_Bool res;
5556
5557    res = e_comp_wl_touch_update_send(ec, idx, x, y, dev, radius_x, radius_y, pressure, angle, time);
5558
5559    return res;
5560 }
5561
5562 EINTERN Eina_Bool
5563 e_client_touch_cancel_send(E_Client *ec)
5564 {
5565    Eina_Bool res;
5566
5567    res = e_comp_wl_touch_cancel_send(ec);
5568
5569    return res;
5570 }
5571
5572 EINTERN Eina_Bool
5573 e_client_mouse_button_send(E_Client *ec, int buttons, Eina_Bool pressed, Ecore_Device *dev, unsigned int time)
5574 {
5575    Eina_Bool res;
5576
5577    res = e_comp_wl_mouse_button_send(ec, buttons, pressed, dev, time);
5578
5579    return res;
5580 }
5581
5582 EINTERN Eina_Bool
5583 e_client_mouse_move_send(E_Client *ec, int x, int y, Ecore_Device *dev, unsigned int time)
5584 {
5585    Eina_Bool res;
5586
5587    res = e_comp_wl_mouse_move_send(ec, x, y, dev, time);
5588
5589    return res;
5590 }
5591
5592 EINTERN Eina_Bool
5593 e_client_mouse_wheel_send(E_Client *ec, int direction, int z, Ecore_Device *dev, unsigned int time)
5594 {
5595    Eina_Bool res;
5596
5597    res = e_comp_wl_mouse_wheel_send(ec, direction, z, dev, time);
5598
5599    return res;
5600 }
5601
5602 EINTERN Eina_Bool
5603 e_client_mouse_in_send(E_Client *ec, int x, int y, Ecore_Device *dev, unsigned int time)
5604 {
5605    Eina_Bool res;
5606
5607    res = e_comp_wl_mouse_in_send(ec, x, y, dev, time);
5608
5609    return res;
5610 }
5611
5612 EINTERN Eina_Bool
5613 e_client_mouse_out_send(E_Client *ec, Ecore_Device *dev, unsigned int time)
5614 {
5615    Eina_Bool res;
5616
5617    res = e_comp_wl_mouse_out_send(ec, dev, time);
5618
5619    return res;
5620 }
5621
5622 E_API Eina_Bool
5623 e_client_video_client_has(E_Client *ec)
5624 {
5625    return e_comp_wl_video_subsurface_has(ec);
5626 }
5627
5628 E_API Eina_Bool
5629 e_client_normal_client_has(E_Client *ec)
5630 {
5631    return e_comp_wl_normal_subsurface_has(ec);
5632 }
5633
5634 E_API Eina_Bool
5635 e_client_cursor_hide(E_Client *ec)
5636 {
5637    return e_comp_wl_cursor_hide(ec);
5638 }
5639
5640 E_API void
5641 e_client_visibility_force_obscured_set(E_Client *ec, Eina_Bool set)
5642 {
5643    if (!ec) return;
5644
5645    ELOGF("TZVIS", "VIS_FORCE_OBSCURED :%d", ec, set);
5646
5647    ec->visibility.force_obscured = set;
5648    e_comp_visibility_calculation_set(EINA_TRUE);
5649 }
5650
5651 EINTERN E_Capture_Save_State
5652 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)
5653 {
5654    return e_comp_wl_capture_client_image_save(ec, dir, name, func_end, data, skip_child);
5655 }
5656
5657 static void
5658 _e_client_base_output_resolution_hook_subsurf_create(void *data, E_Client *subc)
5659 {
5660    E_Client *ec, *parent;
5661
5662    ec = data;
5663    if (ec != subc)
5664      return;
5665
5666    ec->base_output_resolution.use = 0;
5667    ec->base_output_resolution.w = 0;
5668    ec->base_output_resolution.h = 0;
5669    if (ec->base_output_resolution.transform)
5670      {
5671         e_client_transform_core_remove(ec, ec->base_output_resolution.transform);
5672         E_FREE_FUNC(ec->base_output_resolution.transform, e_util_transform_del);
5673         ELOGF("POL_APPINFO", "Cancel TRANSFORM for subsurface", ec);
5674      }
5675
5676    /* Update transform for toplevel surface.
5677     * The transform of subsurface will be updated by its parent accordingly. */
5678    parent = e_comp_wl_topmost_parent_get(ec);
5679    if (parent)
5680      {
5681         parent->transform_core.changed = EINA_TRUE;
5682         e_client_transform_core_update(parent);
5683      }
5684
5685    /* TODO: Do we need to apply it again if subsurface is destroyed? */
5686 }
5687
5688 static void
5689 _e_client_base_output_resolution_set(E_Client *ec, int width, int height)
5690 {
5691    if (!ec) return;
5692    ec->base_output_resolution.use = 1;
5693    ec->base_output_resolution.w = width;
5694    ec->base_output_resolution.h = height;
5695    ec->base_output_resolution.transform = e_util_transform_new();
5696    e_util_transform_role_set(ec->base_output_resolution.transform, "base_output_resolution");
5697    e_client_transform_core_add(ec, ec->base_output_resolution.transform);
5698
5699    if (!ec->base_output_resolution.hook_subsurf_create)
5700      {
5701         ec->base_output_resolution.hook_subsurf_create =
5702            e_comp_wl_hook_add(E_COMP_WL_HOOK_SUBSURFACE_CREATE,
5703                               _e_client_base_output_resolution_hook_subsurf_create,
5704                               ec);
5705      }
5706 }
5707
5708 E_API void
5709 e_client_base_output_resolution_transform_adjust(E_Client *ec)
5710 {
5711    E_Desk *desk;
5712
5713    EINA_SAFETY_ON_NULL_RETURN(ec);
5714    if (!ec->base_output_resolution.use) return;
5715    if (!ec->base_output_resolution.transform) return;
5716
5717    desk = e_comp_desk_find_by_ec(ec);
5718    EINA_SAFETY_ON_NULL_RETURN(desk);
5719
5720    ELOGF("POL_APPINFO", "Apply TRANSFORM... desk:(%dx%d), ec:(%dx%d)",
5721          ec, desk->geom.w, desk->geom.h, ec->w, ec->h);
5722
5723    e_util_transform_scale(ec->base_output_resolution.transform,
5724                           (double)desk->geom.w /(double)ec->base_output_resolution.w,
5725                           (double)desk->geom.h /(double)ec->base_output_resolution.h,
5726                           1.0);
5727    e_client_transform_core_update(ec);
5728 }
5729
5730 E_API Eina_Bool
5731 e_client_base_output_resolution_update(E_Client *ec)
5732 {
5733    E_Appinfo *eai = NULL;
5734    int configured_width, configured_height;
5735    int width, height;
5736    E_Desk *desk;
5737
5738    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
5739
5740   if (!e_config->configured_output_resolution.use) return EINA_TRUE;
5741   if (ec->base_output_resolution.use) return EINA_TRUE;
5742
5743   /* Check whether it's subsurface or not
5744    * The resolution of subsurface will follow the resolution of its toplevel surface.
5745    * Transform for subsurface will be applied when toplevel surface does by
5746    * implementation of e_client_transform_core.
5747    */
5748   if (e_comp_wl_subsurface_check(ec))
5749     return EINA_FALSE;
5750
5751    desk = e_comp_desk_find_by_ec(ec);
5752    EINA_SAFETY_ON_NULL_RETURN_VAL(desk, EINA_FALSE);
5753
5754   configured_width = e_config->configured_output_resolution.w;
5755   configured_height = e_config->configured_output_resolution.h;
5756
5757   if (!ec->netwm.pid)
5758     {
5759        ELOGF("POL_APPINFO", "NO PID... USE configured_output_resolution(%d,%d) pid:%d", ec,
5760              configured_width, configured_height, ec->netwm.pid);
5761        goto use_configured;
5762     }
5763
5764    eai = e_appinfo_find_with_pid(ec->netwm.pid);
5765    if (!eai)
5766      {
5767         ELOGF("POL_APPINFO", "NO APPINFO... USE configured_output_resolution(%d,%d) pid:%d", ec,
5768               configured_width, configured_height, ec->netwm.pid);
5769         goto use_configured;
5770      }
5771
5772    if (!e_appinfo_base_output_resolution_get(eai, &width, &height))
5773      {
5774         ELOGF("POL_APPINFO", "NO BASE SCREEN RESOLUTION... USE configured_output_resolution(%d,%d) pid:%d", ec,
5775               configured_width, configured_height, ec->netwm.pid);
5776         goto use_configured;
5777       }
5778
5779    if ((width == 0) && (height == 0))
5780      {
5781         ELOGF("POL_APPINFO", "SKIP SET BASE SCREEN RESOLUTION... base_output_resolution size:(%d,%d) pid:%d", ec, width, height, ec->netwm.pid);
5782         return EINA_TRUE;
5783      }
5784
5785    if ((desk->geom.w == width) && (desk->geom.h == height))
5786      {
5787         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);
5788         return EINA_TRUE;
5789      }
5790
5791    /* set the base_output_resolution of the e_client */
5792    _e_client_base_output_resolution_set(ec, width, height);
5793
5794    ELOGF("POL_APPINFO", "USE base_output_resolution(%d,%d) pid:%d", ec, width, height, ec->netwm.pid);
5795
5796    return EINA_TRUE;
5797
5798 use_configured:
5799
5800    if ((desk->geom.w == configured_width) && (desk->geom.h == configured_height))
5801      {
5802         ELOGF("POL_APPINFO", "SKIP use configured_output_resolution (same with desk size:(%d,%d), pid:%d)", ec, configured_width, configured_height, ec->netwm.pid);
5803      }
5804    else
5805      {
5806         /* set the base_output_resolution of the e_client as a default */
5807         _e_client_base_output_resolution_set(ec, configured_width, configured_height);
5808      }
5809
5810    return EINA_TRUE;
5811 }
5812
5813 E_API Eina_Bool
5814 e_client_base_output_resolution_useful_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
5815 {
5816    int zx, zy, zw, zh;
5817    E_Zone *zone;
5818
5819    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
5820
5821    zone = e_comp_zone_find_by_ec(ec);
5822    EINA_SAFETY_ON_NULL_RETURN_VAL(zone, EINA_FALSE);
5823
5824    e_zone_useful_geometry_get(zone, &zx, &zy, &zw, &zh);
5825
5826    if (x) *x = zx;
5827    if (y) *y = zy;
5828    if (w) *w = zw;
5829    if (h) *h = zh;
5830
5831    if (ec->base_output_resolution.use)
5832      {
5833         if (w) *w = ec->base_output_resolution.w;
5834         if (h) *h = ec->base_output_resolution.h;
5835      }
5836
5837    return EINA_TRUE;
5838 }
5839
5840 E_API Eina_Bool
5841 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)
5842 {
5843    int zx, zy, zw, zh;
5844    E_Zone *zone;
5845
5846    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
5847
5848    zone = e_comp_zone_find_by_ec(ec);
5849    EINA_SAFETY_ON_NULL_RETURN_VAL(zone, EINA_FALSE);
5850
5851    e_zone_desk_useful_geometry_get(zone, ec->desk, &zx, &zy, &zw, &zh, consider_obstacle_area);
5852
5853    if (x) *x = zx;
5854    if (y) *y = zy;
5855    if (w) *w = zw;
5856    if (h) *h = zh;
5857
5858    if (ec->base_output_resolution.use)
5859      {
5860         // TODO: Consider obstacle area
5861         if (w) *w = ec->base_output_resolution.w;
5862         if (h) *h = ec->base_output_resolution.h;
5863      }
5864
5865    return EINA_TRUE;
5866 }
5867
5868 /* change the base_output_resolution of the bind_ec by checking the base_output_resolution of provider_ec's appinfo */
5869 EINTERN Eina_Bool
5870 e_client_base_output_resolution_rsm_update(E_Client *bind_ec, E_Client *provider_ec)
5871 {
5872    E_Appinfo *epai = NULL;
5873    int configured_width, configured_height;
5874    int width, height;
5875    E_Desk *bind_ec_desk;
5876
5877    EINA_SAFETY_ON_NULL_RETURN_VAL(bind_ec, EINA_FALSE);
5878    EINA_SAFETY_ON_NULL_RETURN_VAL(provider_ec, EINA_FALSE);
5879
5880    bind_ec_desk = e_comp_desk_find_by_ec(bind_ec);
5881    EINA_SAFETY_ON_NULL_RETURN_VAL(bind_ec_desk, EINA_FALSE);
5882
5883   if (!e_config->configured_output_resolution.use) return EINA_TRUE;
5884
5885   configured_width = e_config->configured_output_resolution.w;
5886   configured_height = e_config->configured_output_resolution.h;
5887
5888   if (bind_ec->base_output_resolution.use)
5889     {
5890        ELOGF("POL_APPINFO", "DELETE EXISTED BINDER BASE SCREEN RESOLUTION... base_output_resolution is same with desk size:(%d,%d), bind_pid:%d", bind_ec,
5891              bind_ec->base_output_resolution.w, bind_ec->base_output_resolution.h, bind_ec->netwm.pid);
5892
5893        bind_ec->base_output_resolution.use = 0;
5894        bind_ec->base_output_resolution.w = 0;
5895        bind_ec->base_output_resolution.h = 0;
5896        e_client_transform_core_remove(bind_ec, bind_ec->base_output_resolution.transform);
5897        E_FREE_FUNC(bind_ec->base_output_resolution.transform, e_util_transform_del);
5898     }
5899
5900   if (!provider_ec->netwm.pid)
5901     {
5902        ELOGF("POL_APPINFO", "NO PROVIDER PID... USE configured_output_resolution(%d,%d) provider_pid:%d", provider_ec,
5903              configured_width, configured_height, provider_ec->netwm.pid);
5904        goto use_configured;
5905     }
5906
5907    epai = e_appinfo_find_with_pid(provider_ec->netwm.pid);
5908    if (!epai)
5909      {
5910         ELOGF("POL_APPINFO", "NO PROVIDER APPINFO... USE configured_output_resolution(%d,%d) provider_pid:%d", provider_ec,
5911               configured_width, configured_height, provider_ec->netwm.pid);
5912         goto use_configured;
5913      }
5914
5915    if (!e_appinfo_base_output_resolution_get(epai, &width, &height))
5916      {
5917         ELOGF("POL_APPINFO", "NO PROVIDER APPINFO BASE SCREEN RESOLUTION... USE configured_output_resolution(%d,%d) provider_pid:%d", provider_ec,
5918               configured_width, configured_height, provider_ec->netwm.pid);
5919         goto use_configured;
5920       }
5921
5922    if ((width == 0) && (height == 0))
5923      {
5924         ELOGF("POL_APPINFO", "NO PROVIDER WIDTH and HEIGHT... SKIP base_output_resolution due to size:(%d,%d) provider_pid:%d", provider_ec,
5925              width, height, provider_ec->netwm.pid);
5926         return EINA_TRUE;
5927      }
5928
5929    if ((bind_ec_desk->geom.w == width) && (bind_ec_desk->geom.h == height))
5930      {
5931         ELOGF("POL_APPINFO", "SKIP SET BINDER BASE SCREEN RESOLUTION... base_output_resolution is same with desk size:(%d,%d), bind_pid:%d", bind_ec,
5932             width, height, bind_ec->netwm.pid);
5933         return EINA_TRUE;
5934      }
5935
5936    /* set the base_output_resolution of the e_client */
5937    _e_client_base_output_resolution_set(bind_ec, width, height);
5938    e_client_base_output_resolution_transform_adjust(bind_ec);
5939
5940    ELOGF("POL_APPINFO", "USE BINDER base_output_resolution(%d,%d) bind_pid:%d", bind_ec, width, height, bind_ec->netwm.pid);
5941
5942    return EINA_TRUE;
5943
5944 use_configured:
5945
5946    if ((bind_ec_desk->geom.w == configured_width) && (bind_ec_desk->geom.h == configured_height))
5947      {
5948         ELOGF("POL_APPINFO", "SKIP BINDER use configured_output_resolution (same with desk size:(%d,%d), bind_pid:%d)", bind_ec,
5949              configured_width, configured_height, bind_ec->netwm.pid);
5950      }
5951    else
5952      {
5953         /* set the base_output_resolution of the e_client as a default */
5954         _e_client_base_output_resolution_set(bind_ec, configured_width, configured_height);
5955      }
5956
5957    return EINA_TRUE;
5958 }
5959
5960 /* tizen_move_resize */
5961 EINTERN Eina_Bool
5962 e_client_pending_geometry_has(E_Client *ec)
5963 {
5964    if (!eina_list_count(ec->surface_sync.pending_geometry))
5965      return EINA_FALSE;
5966
5967    return ec->surface_sync.wait_commit;
5968 }
5969
5970 EINTERN void
5971 e_client_pending_geometry_flush(E_Client *ec)
5972 {
5973    E_Client_Pending_Geometry *geo;
5974
5975    if (!eina_list_count(ec->surface_sync.pending_geometry))
5976      {
5977         EINA_LIST_FREE(ec->surface_sync.pending_geometry, geo)
5978           {
5979              E_FREE(geo);
5980           }
5981         ec->surface_sync.wait_commit = EINA_FALSE;
5982         ELOGF("POSSIZE", "pending geometry has flushed", ec);
5983      }
5984 }
5985
5986 EINTERN void
5987 e_client_pending_geometry_last_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
5988 {
5989    Eina_List *l;
5990    E_Client_Pending_Geometry *geo;
5991    int gx = 0;
5992    int gy = 0;
5993    int gw = 0;
5994    int gh = 0;
5995
5996    EINA_LIST_REVERSE_FOREACH(ec->surface_sync.pending_geometry, l, geo)
5997      {
5998         gx = geo->x;
5999         gy = geo->y;
6000         gw = geo->w;
6001         gh = geo->h;
6002         break;
6003      }
6004
6005    if (x) *x = gx;
6006    if (y) *y = gy;
6007    if (w) *w = gw;
6008    if (h) *h = gh;
6009 }
6010
6011 E_API void
6012 e_client_frame_focus_set(E_Client *ec, Eina_Bool focus)
6013 {
6014    if (!ec) return;
6015    evas_object_focus_set(ec->frame, focus);
6016 }
6017
6018 EINTERN void
6019 e_client_frame_geometry_set(E_Client *ec, int x, int y, int w, int h)
6020 {
6021    if (!ec) return;
6022
6023    if (ec->internal || ec->input_only)
6024      {
6025         evas_object_geometry_set(ec->frame, x, y, w, h);
6026      }
6027    else
6028      {
6029         if ((ec->w != w) || (ec->h != h))
6030           {
6031              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);
6032              ec->move_after_resize = EINA_TRUE;
6033
6034              e_client_pos_set(ec, x, y);
6035              evas_object_resize(ec->frame, w, h);
6036           }
6037         else
6038           evas_object_geometry_set(ec->frame, x, y, w, h);
6039      }
6040 }
6041
6042 EAPI void
6043 e_client_util_move_resize_without_frame(E_Client *ec, int x, int y, int w, int h)
6044 {
6045    if (!ec) return;
6046
6047    if (ec->internal || ec->input_only)
6048      {
6049         e_client_util_move_without_frame(ec, x, y);
6050         e_client_util_resize_without_frame(ec, w, h);
6051      }
6052    else
6053      {
6054         if ((ec->w != w) || (ec->h != h))
6055           {
6056              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);
6057              ec->move_after_resize = EINA_TRUE;
6058
6059              e_comp_object_frame_xy_adjust(ec->frame, x, y, &x, &y);
6060              e_client_pos_set(ec, x, y);
6061              e_client_util_resize_without_frame(ec, w, h);
6062           }
6063         else
6064           {
6065              e_client_util_move_without_frame(ec, x, y);
6066              e_client_util_resize_without_frame(ec, w, h);
6067           }
6068      }
6069 }
6070
6071 E_API Eina_Bool
6072 e_client_layer_set(E_Client *ec,
6073                    E_Layer layer)
6074 {
6075    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
6076    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, EINA_FALSE);
6077    if (!ec->frame) return EINA_FALSE;
6078
6079    if (e_comp_canvas_client_layer_map(layer) == 9999)
6080      return EINA_FALSE; //invalid layer is not allowed
6081
6082    if (ec->desk_area.enable)
6083      {
6084         if (e_client_layer_set_by_desk_area(ec, layer))
6085           {
6086              // restack according to desk group rule
6087              e_desk_area_ec_rearrange(ec->desk_area.desk_area, ec);
6088              return EINA_TRUE;
6089           }
6090      }
6091    ec->desk_area.layer_backup = layer;
6092
6093    evas_object_layer_set(ec->frame, layer);
6094    if (ec->layer != layer)
6095      {
6096         /* check exceptional case */
6097         if ((ec->fullscreen) &&
6098             (ec->saved.layer != layer))
6099           {
6100              ELOGF("LAYER", "(%d) fail to backup at saved.layer for fullscreen", ec, layer);
6101              return EINA_FALSE;
6102           }
6103         // if e_comp_object fail to change ec->layer due to ec->layer_pending or block
6104         // leave log and apply ec->layer according to set
6105         // as a result it restores back to given layer when pending or block is free
6106         ELOGF("LAYER", "change layer from %d to %d if in case layer pending(%d) or block(%d)",
6107               ec, ec->layer, layer, ec->layer_pending, ec->layer_block);
6108         if (ec->layer_pending || ec->layer_block)
6109           {
6110              ec->layer = layer;
6111              return EINA_TRUE;
6112           }
6113      }
6114
6115    wl_signal_emit_mutable(&PRI(ec)->events.layer_set, NULL);
6116
6117    return EINA_TRUE;
6118 }
6119
6120 E_API E_Layer
6121 e_client_layer_get(E_Client *ec)
6122 {
6123    short layer;
6124
6125    E_OBJECT_CHECK_RETURN(ec, E_LAYER_BOTTOM);
6126    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, E_LAYER_BOTTOM);
6127    if (!ec->frame) return E_LAYER_BOTTOM;
6128
6129    layer = evas_object_layer_get(ec->frame);
6130    if (ec->layer != layer)
6131      {
6132         /* client could be on temperory layer while pending or block,
6133          * in that case, client restores back to ec->layer after pending/block finish */
6134         if (ec->layer_block || ec->layer_pending)
6135           return ec->layer;
6136
6137         /* otherwise, client is on unexpected layer */
6138         ELOGF("LAYER", "layer dismatch ec->layer %d | evas obj layer %d ",
6139               ec, ec->layer, layer);
6140
6141         if (e_comp_canvas_client_layer_map(layer) == 9999)
6142           return E_LAYER_BOTTOM; //not on E_LAYER_CLIENT
6143      }
6144
6145    return ec->layer;
6146 }
6147
6148 static void
6149 _e_client_desk_area_original_layer_save(E_Client *ec, E_Layer layer)
6150 {
6151    E_OBJECT_CHECK(ec);
6152    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
6153    ec->desk_area.layer_backup = layer;
6154 }
6155
6156 EINTERN Eina_Bool
6157 e_client_layer_set_by_desk_area(E_Client *ec, E_Layer layer)
6158 {
6159    E_Desk_Area *eda;
6160    E_Layer edg_layer;
6161    E_Layer org_layer;
6162
6163    if (!ec) return EINA_FALSE;
6164    if (!ec->frame) return EINA_FALSE;
6165    if (!ec->desk_area.enable) return EINA_FALSE;
6166    if (!ec->desk_area.desk_area) return EINA_FALSE;
6167
6168    eda = ec->desk_area.desk_area;
6169
6170    // save original layer
6171    _e_client_desk_area_original_layer_save(ec, layer);
6172
6173    // get desk_area layer
6174    edg_layer = (E_Layer)e_desk_area_layer_get(eda);
6175    org_layer = e_client_desk_area_original_layer_get(ec);
6176
6177    ELOGF("EDG", "layer_set by desk_area... layer:%d, org_layer:%d, new_layer:%d", ec, layer, org_layer, edg_layer);
6178    if (org_layer == edg_layer)
6179      {
6180         e_client_raise(ec);
6181      }
6182    else
6183      {
6184         evas_object_layer_set(ec->frame, edg_layer);
6185         if (edg_layer == ec->layer)
6186           e_client_raise(ec);
6187      }
6188
6189    return EINA_TRUE;
6190 }
6191
6192 EINTERN void
6193 e_client_desk_area_original_layer_restore(E_Client *ec)
6194 {
6195    if (!ec) return;
6196
6197    // Do we need to check ec->desk_area.enable?
6198    // if ec->desk_area.enable is true, then e_client_layer_set calls
6199    // e_desk_area_ec_edg_layer_set(). that's too bad. :(
6200    // so, we MUST make a policy for ordering of the desk group layer restore
6201    // and the desk group enable.
6202    if (ec->desk_area.enable) return;
6203    e_client_layer_set(ec, ec->desk_area.layer_backup);
6204 }
6205
6206 EINTERN E_Layer
6207 e_client_desk_area_original_layer_get(E_Client *ec)
6208 {
6209    if (!ec) return E_LAYER_DESKTOP;
6210
6211    if (ec->desk_area.enable)
6212      return ec->desk_area.layer_backup;
6213    else
6214      return ec->layer;
6215 }
6216
6217 EINTERN Eina_Bool
6218 e_client_desk_area_client_layer_set(E_Client *ec, E_Desk_Area_Client_Layer edgc_layer)
6219 {
6220    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
6221    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, EINA_FALSE);
6222    if ((edgc_layer < E_DESK_AREA_CLIENT_LAYER_DESKTOP) ||
6223        (edgc_layer >= E_DESK_AREA_CLIENT_LAYER_MAX))
6224      return EINA_FALSE;
6225
6226    ec->desk_area.edgc_layer = edgc_layer;
6227    return EINA_TRUE;
6228 }
6229
6230 EINTERN E_Desk_Area_Client_Layer
6231 e_client_desk_area_client_layer_get(E_Client *ec)
6232 {
6233    E_OBJECT_CHECK_RETURN(ec, E_DESK_AREA_CLIENT_LAYER_DESKTOP);
6234
6235    return ec->desk_area.edgc_layer;
6236 }
6237
6238 //FIXME: use e_desk_area_ec_reassign(eda, ec) instead of this api
6239 E_API Eina_Bool
6240 e_client_desk_area_set(E_Client *ec, E_Desk_Area *eda)
6241 {
6242    E_Desk_Area *old_edg;
6243
6244    if (!ec) return EINA_FALSE;
6245
6246 #if 0 // if this is removed.. then below if (eda != old_edg) is removed also...
6247    if (ec->desk_area.desk_area == eda)
6248      return EINA_TRUE;
6249 #endif
6250
6251    ELOGF("EDG", "Desk Group Set (new:%p, old:%p)", ec, eda, ec->desk_area.desk_area);
6252    old_edg = ec->desk_area.desk_area;
6253    if (old_edg)
6254      e_desk_area_ec_remove(old_edg, ec);
6255
6256    ec->desk_area.desk_area = eda;
6257    e_desk_area_ec_add(eda, ec);
6258
6259 #if 0 // if this is removed.. then above if (ec->desk_area.desk_area == eda) is removed also...
6260    if (eda != old_edg)
6261 #endif
6262      {
6263         e_desk_area_ec_update(eda, ec);
6264         e_desk_area_ec_rearrange(ec->desk_area.desk_area, ec);
6265      }
6266
6267    return EINA_TRUE;
6268 }
6269
6270 static void
6271 _raise_between_sibling_under_parent(E_Client *ec)
6272 {
6273    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);
6274    e_client_stack_below(ec, ec->parent);
6275 }
6276
6277 static void
6278 _raise_between_sibling_on_parent(E_Client *ec)
6279 {
6280    E_Client *top_child = NULL;
6281    top_child = e_client_transient_child_top_get(ec->parent, EINA_FALSE);
6282    if (!top_child)
6283      {
6284         ELOGF("POL", "RAISE child window... Stack above on the parent (win:%zx, ec:%p)", ec, e_client_util_win_get(ec->parent), ec->parent);
6285         e_client_stack_above(ec, ec->parent);
6286      }
6287    else
6288      {
6289         if (top_child != ec)
6290           {
6291              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);
6292              e_client_stack_above(ec, top_child);
6293           }
6294         else
6295           ELOGF("POL", "RAISE child window between sibling... already on the top. STAY", ec);
6296      }
6297 }
6298
6299 static void
6300 _raise_belong_to_parent(E_Client *ec)
6301 {
6302    if (e_client_transient_policy_get(ec) == E_TRANSIENT_BELOW)
6303      _raise_between_sibling_under_parent(ec);
6304    else
6305      _raise_between_sibling_on_parent(ec);
6306 }
6307
6308 E_API void
6309 e_client_raise(E_Client *ec)
6310 {
6311    if (!ec) return;
6312
6313    if (ec->desk_area.enable)
6314      {
6315         E_Desk_Area *eda;
6316         eda = ec->desk_area.desk_area;
6317         if (eda)
6318           {
6319              e_desk_area_ec_raise(eda, ec);
6320              return;
6321           }
6322      }
6323
6324    if (ec->parent && e_client_is_belong_to_parent(ec))
6325      _raise_belong_to_parent(ec);
6326    else
6327      evas_object_raise(ec->frame);
6328
6329    wl_signal_emit_mutable(&PRI(ec)->events.raise, NULL);
6330 }
6331
6332 static void
6333 _e_client_transient_for_below_group_make(E_Client *ec, Eina_List **list)
6334 {
6335    // list : Head is the bottommost child
6336    E_Client *child;
6337    Eina_List *l;
6338
6339    if (!ec) return;
6340
6341    EINA_LIST_REVERSE_FOREACH(ec->transients, l, child)
6342      {
6343         if (!child) continue;
6344         if (e_client_transient_policy_get(child) != E_TRANSIENT_BELOW) continue;
6345         if (!e_client_is_belong_to_parent(child)) continue;
6346
6347         *list = eina_list_prepend(*list, child);
6348         _e_client_transient_for_group_make(child, list);
6349      }
6350 }
6351
6352 E_API E_Client *
6353 e_client_transient_child_bottom_get(E_Client *ec)
6354 {
6355    E_Client *bottom_ec = NULL;
6356    Eina_List *transient_below_list = NULL;
6357    Eina_List *l = NULL;
6358
6359    _e_client_transient_for_below_group_make(ec, &transient_below_list);
6360
6361    if (transient_below_list)
6362      {
6363         E_Client *temp_ec = NULL;
6364         E_Client *temp_ec2 = NULL;
6365
6366         E_CLIENT_FOREACH(temp_ec)
6367           {
6368              if (bottom_ec) break;
6369
6370              if (temp_ec == ec)
6371                {
6372                   bottom_ec = ec;
6373                   break;
6374                }
6375
6376              EINA_LIST_FOREACH(transient_below_list, l, temp_ec2)
6377                {
6378                   if (temp_ec == temp_ec2)
6379                     {
6380                        bottom_ec = temp_ec2;
6381                        break;
6382                     }
6383                }
6384           }
6385         eina_list_free(transient_below_list);
6386      }
6387    return bottom_ec;
6388 }
6389
6390 static void
6391 _lower_between_sibling_under_parent(E_Client *ec)
6392 {
6393    E_Client *bottom_child = NULL;
6394    bottom_child = e_client_transient_child_bottom_get(ec->parent);
6395    if (!bottom_child)
6396      {
6397         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);
6398         e_client_stack_below(ec, ec->parent);
6399      }
6400    else
6401      {
6402         if (bottom_child != ec)
6403           {
6404              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);
6405              e_client_stack_below(ec, bottom_child);
6406           }
6407         else
6408           ELOGF("POL", "LOWER child window between sibling... already under the bottom. STAY", ec);
6409      }
6410 }
6411
6412 static void
6413 _lower_between_sibling_on_parent(E_Client *ec)
6414 {
6415    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);
6416    e_client_stack_above(ec, ec->parent);
6417 }
6418
6419 static void
6420 _lower_belong_to_parent(E_Client *ec)
6421 {
6422    if (e_client_transient_policy_get(ec) == E_TRANSIENT_BELOW)
6423      _lower_between_sibling_under_parent(ec);
6424    else
6425      _lower_between_sibling_on_parent(ec);
6426 }
6427
6428 E_API void
6429 e_client_lower(E_Client *ec)
6430 {
6431    if (!ec) return;
6432
6433    if (ec->desk_area.enable)
6434      {
6435         E_Desk_Area *eda;
6436         eda = ec->desk_area.desk_area;
6437         if (eda)
6438           {
6439              e_desk_area_ec_lower(eda, ec);
6440
6441              wl_signal_emit_mutable(&PRI(ec)->events.lower, NULL);
6442              return;
6443           }
6444      }
6445
6446    if (ec->parent && e_client_is_belong_to_parent(ec))
6447      _lower_belong_to_parent(ec);
6448    else
6449      evas_object_lower(ec->frame);
6450
6451    wl_signal_emit_mutable(&PRI(ec)->events.lower, NULL);
6452 }
6453
6454 E_API void
6455 e_client_stack_above(E_Client *ec, E_Client *above)
6456 {
6457    if (!ec) return;
6458    if (!ec->frame) return;
6459    if (!above) return;
6460    if (!above->frame) return;
6461
6462    if (ec->desk_area.enable)
6463      {
6464         E_Desk_Area *eda;
6465         eda = ec->desk_area.desk_area;
6466         if (eda)
6467           {
6468              e_desk_area_ec_stack_above(eda, ec, above);
6469              return;
6470           }
6471      }
6472
6473    evas_object_stack_above(ec->frame, above->frame);
6474
6475    wl_signal_emit_mutable(&PRI(ec)->events.stack_above, NULL);
6476 }
6477
6478 E_API void
6479 e_client_stack_below(E_Client *ec, E_Client *below)
6480 {
6481    if (!ec) return;
6482    if (!ec->frame) return;
6483    if (!below) return;
6484    if (!below->frame) return;
6485
6486    if (ec->desk_area.enable)
6487      {
6488         E_Desk_Area *eda;
6489         eda = ec->desk_area.desk_area;
6490         if (eda)
6491           {
6492              e_desk_area_ec_stack_below(eda, ec, below);
6493              return;
6494           }
6495      }
6496
6497    evas_object_stack_below(ec->frame, below->frame);
6498
6499    wl_signal_emit_mutable(&PRI(ec)->events.stack_below, NULL);
6500 }
6501
6502 E_API int
6503 e_client_show_pending_set(E_Client *ec)
6504 {
6505    if (!ec) return 0;
6506
6507    ec->show_pending.count++;
6508    ELOGF("E_CLIENT", "SET show_pending. (count:%d, run:%d)", ec, ec->show_pending.count, ec->show_pending.running);
6509    return ec->show_pending.count;
6510 }
6511
6512 E_API int
6513 e_client_show_pending_unset(E_Client *ec)
6514 {
6515    if (!ec) return 0;
6516    if (ec->show_pending.count <= 0) return 0;
6517
6518    ec->show_pending.count--;
6519    ELOGF("E_CLIENT", "UNSET show_pending. (count:%d, run:%d)", ec, ec->show_pending.count, ec->show_pending.running);
6520    if (ec->show_pending.count == 0 && ec->show_pending.running)
6521      {
6522         ec->show_pending.running = EINA_FALSE;
6523         if (ec->frame)
6524           {
6525              ELOGF("E_CLIENT", "evas_object_show by unset show_pending", ec);
6526              evas_object_show(ec->frame);
6527              //e_comp_object_damage(ec->frame, 0, 0, ec->w, ec->h);
6528              EC_CHANGED(ec);
6529           }
6530      }
6531
6532    return ec->show_pending.count;
6533 }
6534
6535 static Eina_Bool
6536 _e_client_surface_tree_foreach_helper(E_Client *ec, E_Client_Surface_Tree_Foreach func, void *data)
6537 {
6538    E_Client *subc;
6539    Eina_List *l, *ll;
6540    Eina_Bool res = EINA_TRUE;
6541    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
6542
6543    if (!cdata)
6544      return res;
6545
6546    EINA_LIST_FOREACH_SAFE(cdata->sub.below_list, l, ll, subc)
6547      {
6548         res = _e_client_surface_tree_foreach_helper(subc, func, data);
6549         if (!res)
6550           break;
6551      }
6552
6553    if (res)
6554      {
6555         res = func(data, ec);
6556         if (res)
6557           {
6558              EINA_LIST_FOREACH_SAFE(cdata->sub.list, l, ll, subc)
6559                {
6560                   res = _e_client_surface_tree_foreach_helper(subc,
6561                                                               func,
6562                                                               data);
6563                   if (!res)
6564                     break;
6565                }
6566           }
6567      }
6568
6569    return res;
6570 }
6571
6572 E_API void
6573 e_client_surface_tree_foreach(E_Client *ec, E_Client_Surface_Tree_Foreach func, void *data)
6574 {
6575    EINA_SAFETY_ON_NULL_RETURN(ec);
6576    EINA_SAFETY_ON_NULL_RETURN(func);
6577
6578    _e_client_surface_tree_foreach_helper(ec, func, data);
6579 }
6580
6581 EINTERN E_Comp_Wl_Client_Data *
6582 e_client_cdata_new(E_Client *ec)
6583 {
6584    E_Comp_Wl_Client_Data *cdata;
6585
6586    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
6587
6588    if (!(cdata = E_NEW(E_Comp_Wl_Client_Data, 1)))
6589      {
6590         ERR("Could not allocate new E_Comp_Wl_Client_Data structure");
6591         return NULL;
6592      }
6593    ec->comp_data = cdata;
6594
6595    return cdata;
6596 }
6597
6598 EINTERN void
6599 e_client_cdata_free(E_Client *ec)
6600 {
6601   EINA_SAFETY_ON_NULL_RETURN(ec);
6602   if (!ec->comp_data) return;
6603
6604   E_FREE(ec->comp_data);
6605 }
6606
6607 EINTERN E_Comp_Wl_Client_Data *
6608 e_client_cdata_get(E_Client *ec)
6609 {
6610    if (!ec) return NULL;
6611
6612    return ec->comp_data;
6613 }
6614
6615 EINTERN Eina_Bool
6616 e_client_map_set(E_Client *ec, E_Map *em)
6617 {
6618    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6619
6620    return e_map_set_to_comp_object(em, ec->frame);
6621 }
6622
6623 E_API E_Map *
6624 e_client_map_get(const E_Client *ec)
6625 {
6626    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
6627
6628    return e_map_get_from_comp_object(ec->frame);
6629 }
6630
6631 EINTERN Eina_Bool
6632 e_client_map_enable_set(E_Client *ec, Eina_Bool enable)
6633 {
6634    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6635    EINA_SAFETY_ON_NULL_RETURN_VAL(ec->frame, EINA_FALSE);
6636
6637    evas_object_map_enable_set(ec->frame, enable);
6638
6639    return EINA_TRUE;
6640 }
6641
6642 EINTERN void
6643 e_client_belong_to_parent_set(E_Client *ec, Eina_Bool set)
6644 {
6645    if (!ec) return;
6646    ec->belong_to_parent = set;
6647 }
6648
6649 EINTERN Eina_Bool
6650 e_client_is_belong_to_parent(E_Client *ec)
6651 {
6652    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6653    return ec->belong_to_parent;
6654 }
6655
6656 EINTERN void
6657 e_client_transient_policy_set(E_Client *ec, E_Transient policy)
6658 {
6659    if (!ec) return;
6660    ec->transient_policy = policy;
6661 }
6662
6663 E_API E_Transient
6664 e_client_transient_policy_get(E_Client *ec)
6665 {
6666    if (!ec) return E_TRANSIENT_ABOVE;
6667    return ec->transient_policy;
6668 }
6669
6670 EINTERN void
6671 e_client_resize_object_create_cb_set(E_Client_Resize_Object_Create_Cb cb)
6672 {
6673    if (_e_client_resize_object_create_cb && cb)
6674      CRI("ATTEMPTING TO OVERWRITE EXISTING CLIENT RESIZE OBJECT CREATE HOOK!!!");
6675    _e_client_resize_object_create_cb = cb;
6676 }
6677
6678 EINTERN void
6679 e_client_resize_unit_size_set(E_Client *ec, unsigned int unit_size)
6680 {
6681    if (!ec) return;
6682
6683    // FYI, we consider 0 and 1 to be the same value as a default unit size.
6684    ec->manage_resize.unit_size = unit_size;
6685 }
6686
6687 EINTERN void
6688 e_client_desk_zoom_enable_set(E_Client *ec, Eina_Bool enable)
6689 {
6690    if (!ec) return;
6691    ec->desk_zoom.enable = enable;
6692 }
6693
6694 EINTERN Eina_Bool
6695 e_client_desk_zoom_enable_get(E_Client *ec)
6696 {
6697    if (!ec) return EINA_FALSE;
6698    return ec->desk_zoom.enable;
6699 }
6700
6701 EINTERN void
6702 e_client_layout_apply(E_Client *ec, Eina_Bool apply)
6703 {
6704    if (!ec) return;
6705    ec->apply_layout = apply;
6706 }
6707
6708 EINTERN Eina_Bool
6709 e_client_is_layout_apply(E_Client *ec)
6710 {
6711    if (!ec) return EINA_FALSE;
6712    return ec->apply_layout;
6713 }
6714
6715 E_API E_Client *
6716 e_client_from_surface_resource(struct wl_resource *surface_resource)
6717 {
6718    EINA_SAFETY_ON_NULL_RETURN_VAL(surface_resource, NULL);
6719
6720    return e_comp_wl_util_client_from_surface_resource(surface_resource);
6721 }
6722
6723 EINTERN void
6724 e_client_fps_update(E_Client *ec)
6725 {
6726    double dt;
6727    double tim;
6728
6729    EINA_SAFETY_ON_NULL_RETURN(ec);
6730
6731    if (!ec->fps.enabled) return;
6732
6733    tim = ecore_time_get();
6734
6735    dt = tim - ec->fps.frametimes[0];
6736
6737    ec->fps.frametimes[0] = tim;
6738    ec->fps.time += dt;
6739    ec->fps.cframes++;
6740
6741    if (ec->fps.lapse == 0.0)
6742      {
6743         ec->fps.lapse = tim;
6744         ec->fps.flapse = ec->fps.cframes;
6745      }
6746    else if ((tim - ec->fps.lapse) >= 0.5)
6747      {
6748         ec->fps.fps = (ec->fps.cframes - ec->fps.flapse) /
6749                       (tim - ec->fps.lapse);
6750         ec->fps.lapse = tim;
6751         ec->fps.flapse = ec->fps.cframes;
6752         ec->fps.time = 0.0;
6753      }
6754 }
6755
6756 EINTERN Eina_Bool
6757 e_client_fps_get(E_Client *ec, double *fps)
6758 {
6759    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6760
6761    if (ec->fps.old_fps == ec->fps.fps)
6762      return EINA_FALSE;
6763
6764    if (ec->fps.fps > 0.0)
6765      {
6766         *fps = ec->fps.fps;
6767         ec->fps.old_fps = ec->fps.fps;
6768         return EINA_TRUE;
6769      }
6770
6771    return EINA_FALSE;
6772 }
6773
6774 EINTERN void
6775 e_client_fps_enable(E_Client *ec, Eina_Bool enable)
6776 {
6777    EINA_SAFETY_ON_NULL_RETURN(ec);
6778
6779    ec->fps.enabled = enable;
6780 }
6781
6782 EINTERN Eina_Bool
6783 e_client_explicit_sync_get(E_Client *ec)
6784 {
6785    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6786
6787    return ec->explicit_sync;
6788 }
6789
6790 EINTERN Eina_Bool
6791 e_client_explicit_sync_set(E_Client *ec, Eina_Bool enable)
6792 {
6793    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6794
6795    ec->explicit_sync = enable;
6796
6797    return EINA_TRUE;
6798 }
6799
6800 EINTERN int
6801 e_client_explicit_sync_acquire_fence_fd_get(E_Client *ec)
6802 {
6803    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, -1);
6804
6805    return ec->acquire_fence_fd;
6806 }
6807
6808 EINTERN Eina_Bool
6809 e_client_explicit_sync_acquire_fence_fd_set(E_Client *ec, int fd)
6810 {
6811   EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6812
6813   ec->acquire_fence_fd = fd;
6814
6815   return EINA_TRUE;
6816 }
6817
6818 EINTERN Eina_Bool
6819 e_client_intercept_hook_auto_placement_call(E_Client *ec)
6820 {
6821   // no need to call the intercept hook if ec is NULL.
6822   if (!ec) return EINA_FALSE;
6823
6824   if (!_e_client_intercept_hook_call(E_CLIENT_INTERCEPT_HOOK_AUTO_PLACEMENT, ec))
6825     {
6826        ELOGF("FOCUS", "E_CLIENT_INTERCEPT_HOOK_AUTO_PLACEMENT Intercepted.", ec);
6827        return EINA_TRUE;
6828     }
6829
6830   return EINA_FALSE;
6831 }
6832
6833 EINTERN void
6834 e_client_iconify_event_send(E_Client *ec)
6835 {
6836    EINA_SAFETY_ON_NULL_RETURN(ec);
6837
6838    _e_client_event_simple(ec, E_EVENT_CLIENT_ICONIFY);
6839 }
6840
6841 EINTERN void
6842 e_client_uniconify_event_send(E_Client *ec)
6843 {
6844    EINA_SAFETY_ON_NULL_RETURN(ec);
6845
6846    _e_client_event_simple(ec, E_EVENT_CLIENT_UNICONIFY);
6847 }
6848
6849 EINTERN void
6850 e_client_stack_transient_for_done_notify(E_Client *ec)
6851 {
6852    EINA_SAFETY_ON_NULL_RETURN(ec);
6853
6854    wl_signal_emit_mutable(&PRI(ec)->events.stack_transient_for_done, NULL);
6855 }
6856
6857 EINTERN void
6858 e_client_eval_pre_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
6859 {
6860    API_ENTRY;
6861    wl_signal_add(&priv->events.eval_pre_fetch, listener);
6862 }
6863
6864 EINTERN struct wl_listener *
6865 e_client_eval_pre_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_pre_fetch, notify);
6869 }
6870
6871 EINTERN void
6872 e_client_eval_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
6873 {
6874    API_ENTRY;
6875    wl_signal_add(&priv->events.eval_fetch, listener);
6876 }
6877
6878 EINTERN struct wl_listener *
6879 e_client_eval_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_fetch, notify);
6883 }
6884
6885 EINTERN void
6886 e_client_eval_pre_post_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
6887 {
6888    API_ENTRY;
6889    wl_signal_add(&priv->events.eval_pre_post_fetch, listener);
6890 }
6891
6892 EINTERN struct wl_listener *
6893 e_client_eval_pre_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_pre_post_fetch, notify);
6897 }
6898
6899 EINTERN void
6900 e_client_eval_post_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
6901 {
6902    API_ENTRY;
6903    wl_signal_add(&priv->events.eval_post_fetch, listener);
6904 }
6905
6906 EINTERN struct wl_listener *
6907 e_client_eval_post_fetch_listener_get(E_Client *ec, wl_notify_func_t notify)
6908 {
6909    API_ENTRY_VAL(NULL);
6910    return wl_signal_get(&priv->events.eval_post_fetch, notify);
6911 }
6912
6913 EINTERN void
6914 e_client_eval_pre_frame_assign_listener_add(E_Client *ec, struct wl_listener *listener)
6915 {
6916    API_ENTRY;
6917    wl_signal_add(&priv->events.eval_pre_frame_assign, listener);
6918 }
6919
6920 EINTERN struct wl_listener *
6921 e_client_eval_pre_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_pre_frame_assign, notify);
6925 }
6926
6927 EINTERN void
6928 e_client_eval_post_frame_assign_listener_add(E_Client *ec, struct wl_listener *listener)
6929 {
6930    API_ENTRY;
6931    wl_signal_add(&priv->events.eval_post_frame_assign, listener);
6932 }
6933
6934 EINTERN struct wl_listener *
6935 e_client_eval_post_frame_assign_listener_get(E_Client *ec, wl_notify_func_t notify)
6936 {
6937    API_ENTRY_VAL(NULL);
6938    return wl_signal_get(&priv->events.eval_post_frame_assign, notify);
6939 }
6940
6941 EINTERN void
6942 e_client_eval_pre_new_client_listener_add(E_Client *ec, struct wl_listener *listener)
6943 {
6944    API_ENTRY;
6945    wl_signal_add(&priv->events.eval_pre_new_client, listener);
6946 }
6947
6948 EINTERN struct wl_listener *
6949 e_client_eval_pre_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_pre_new_client, notify);
6953 }
6954
6955 EINTERN void
6956 e_client_eval_post_new_client_listener_add(E_Client *ec, struct wl_listener *listener)
6957 {
6958    API_ENTRY;
6959    wl_signal_add(&priv->events.eval_post_new_client, listener);
6960 }
6961
6962 EINTERN struct wl_listener *
6963 e_client_eval_post_new_client_listener_get(E_Client *ec, wl_notify_func_t notify)
6964 {
6965    API_ENTRY_VAL(NULL);
6966    return wl_signal_get(&priv->events.eval_post_new_client, notify);
6967 }
6968
6969 EINTERN void
6970 e_client_eval_visibility_listener_add(E_Client *ec, struct wl_listener *listener)
6971 {
6972    API_ENTRY;
6973    wl_signal_add(&priv->events.eval_visibility, listener);
6974 }
6975
6976 EINTERN struct wl_listener *
6977 e_client_eval_visibility_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, notify);
6981 }
6982
6983 EINTERN void
6984 e_client_eval_visibility_end_listener_add(E_Client *ec, struct wl_listener *listener)
6985 {
6986    API_ENTRY;
6987    wl_signal_add(&priv->events.eval_visibility_end, listener);
6988 }
6989
6990 EINTERN struct wl_listener *
6991 e_client_eval_visibility_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_visibility_end, notify);
6995 }
6996
6997 EINTERN void
6998 e_client_eval_end_listener_add(E_Client *ec, struct wl_listener *listener)
6999 {
7000    API_ENTRY;
7001    wl_signal_add(&priv->events.eval_end, listener);
7002 }
7003
7004 EINTERN struct wl_listener *
7005 e_client_eval_end_listener_get(E_Client *ec, wl_notify_func_t notify)
7006 {
7007    API_ENTRY_VAL(NULL);
7008    return wl_signal_get(&priv->events.eval_end, notify);
7009 }
7010
7011 EINTERN void
7012 e_client_move_begin_listener_add(E_Client *ec, struct wl_listener *listener)
7013 {
7014    API_ENTRY;
7015    wl_signal_add(&priv->events.move_begin, listener);
7016 }
7017
7018 EINTERN struct wl_listener *
7019 e_client_move_begin_listener_get(E_Client *ec, wl_notify_func_t notify)
7020 {
7021    API_ENTRY_VAL(NULL);
7022    return wl_signal_get(&priv->events.move_begin, notify);
7023 }
7024
7025 EINTERN void
7026 e_client_move_update_listener_add(E_Client *ec, struct wl_listener *listener)
7027 {
7028    API_ENTRY;
7029    wl_signal_add(&priv->events.move_update, listener);
7030 }
7031
7032 EINTERN struct wl_listener *
7033 e_client_move_update_listener_get(E_Client *ec, wl_notify_func_t notify)
7034 {
7035    API_ENTRY_VAL(NULL);
7036    return wl_signal_get(&priv->events.move_update, notify);
7037 }
7038
7039 EINTERN void
7040 e_client_move_end_listener_add(E_Client *ec, struct wl_listener *listener)
7041 {
7042    API_ENTRY;
7043    wl_signal_add(&priv->events.move_end, listener);
7044 }
7045
7046 EINTERN struct wl_listener *
7047 e_client_move_end_listener_get(E_Client *ec, wl_notify_func_t notify)
7048 {
7049    API_ENTRY_VAL(NULL);
7050    return wl_signal_get(&priv->events.move_end, notify);
7051 }
7052
7053 EINTERN void
7054 e_client_move_resize_begin_listener_add(E_Client *ec, struct wl_listener *listener)
7055 {
7056    API_ENTRY;
7057    wl_signal_add(&priv->events.move_resize_begin, listener);
7058 }
7059
7060 EINTERN struct wl_listener *
7061 e_client_move_resize_begin_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_begin, notify);
7065 }
7066
7067 EINTERN void
7068 e_client_move_resize_update_listener_add(E_Client *ec, struct wl_listener *listener)
7069 {
7070    API_ENTRY;
7071    wl_signal_add(&priv->events.move_resize_update, listener);
7072 }
7073
7074 EINTERN struct wl_listener *
7075 e_client_move_resize_update_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_update, notify);
7079 }
7080
7081 EINTERN void
7082 e_client_move_resize_end_listener_add(E_Client *ec, struct wl_listener *listener)
7083 {
7084    API_ENTRY;
7085    wl_signal_add(&priv->events.move_resize_end, listener);
7086 }
7087
7088 EINTERN struct wl_listener *
7089 e_client_move_resize_end_listener_get(E_Client *ec, wl_notify_func_t notify)
7090 {
7091    API_ENTRY_VAL(NULL);
7092    return wl_signal_get(&priv->events.move_resize_end, notify);
7093 }
7094
7095 EINTERN void
7096 e_client_destroy_listener_add(E_Client *ec, struct wl_listener *listener)
7097 {
7098    API_ENTRY;
7099    wl_signal_add(&priv->events.destroy, listener);
7100 }
7101
7102 EINTERN struct wl_listener *
7103 e_client_destroy_listener_get(E_Client *ec, wl_notify_func_t notify)
7104 {
7105    API_ENTRY_VAL(NULL);
7106    return wl_signal_get(&priv->events.destroy, notify);
7107 }
7108
7109 EINTERN void
7110 e_client_new_client_listener_add(E_Client *ec, struct wl_listener *listener)
7111 {
7112    API_ENTRY;
7113    wl_signal_add(&priv->events.new_client, listener);
7114 }
7115
7116 EINTERN struct wl_listener *
7117 e_client_new_client_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, notify);
7121 }
7122
7123 EINTERN void
7124 e_client_new_client_post_listener_add(E_Client *ec, struct wl_listener *listener)
7125 {
7126    API_ENTRY;
7127    wl_signal_add(&priv->events.new_client_post, listener);
7128 }
7129
7130 EINTERN struct wl_listener *
7131 e_client_new_client_post_listener_get(E_Client *ec, wl_notify_func_t notify)
7132 {
7133    API_ENTRY_VAL(NULL);
7134    return wl_signal_get(&priv->events.new_client_post, notify);
7135 }
7136
7137 EINTERN void
7138 e_client_unredirect_listener_add(E_Client *ec, struct wl_listener *listener)
7139 {
7140    API_ENTRY;
7141    wl_signal_add(&priv->events.unredirect, listener);
7142 }
7143
7144 EINTERN struct wl_listener *
7145 e_client_unredirect_listener_get(E_Client *ec, wl_notify_func_t notify)
7146 {
7147    API_ENTRY_VAL(NULL);
7148    return wl_signal_get(&priv->events.unredirect, notify);
7149 }
7150
7151 EINTERN void
7152 e_client_redirect_listener_add(E_Client *ec, struct wl_listener *listener)
7153 {
7154    API_ENTRY;
7155    wl_signal_add(&priv->events.redirect, listener);
7156 }
7157
7158 EINTERN struct wl_listener *
7159 e_client_redirect_listener_get(E_Client *ec, wl_notify_func_t notify)
7160 {
7161    API_ENTRY_VAL(NULL);
7162    return wl_signal_get(&priv->events.redirect, notify);
7163 }
7164
7165 EINTERN void
7166 e_client_aux_hint_change_listener_add(E_Client *ec, struct wl_listener *listener)
7167 {
7168    API_ENTRY;
7169    wl_signal_add(&priv->events.aux_hint_change, listener);
7170 }
7171
7172 EINTERN struct wl_listener *
7173 e_client_aux_hint_change_listener_get(E_Client *ec, wl_notify_func_t notify)
7174 {
7175    API_ENTRY_VAL(NULL);
7176    return wl_signal_get(&priv->events.aux_hint_change, notify);
7177 }
7178
7179 EINTERN void
7180 e_client_window_role_change_listener_add(E_Client *ec, struct wl_listener *listener)
7181 {
7182    API_ENTRY;
7183    wl_signal_add(&priv->events.window_role_change, listener);
7184 }
7185
7186 EINTERN struct wl_listener *
7187 e_client_window_role_change_listener_get(E_Client *ec, wl_notify_func_t notify)
7188 {
7189    API_ENTRY_VAL(NULL);
7190    return wl_signal_get(&priv->events.window_role_change, notify);
7191 }
7192
7193 EINTERN void
7194 e_client_transform_change_listener_add(E_Client *ec, struct wl_listener *listener)
7195 {
7196    API_ENTRY;
7197    wl_signal_add(&priv->events.transform_change, listener);
7198 }
7199
7200 EINTERN struct wl_listener *
7201 e_client_transform_change_listener_get(E_Client *ec, wl_notify_func_t notify)
7202 {
7203    API_ENTRY_VAL(NULL);
7204    return wl_signal_get(&priv->events.transform_change, notify);
7205 }
7206
7207 EINTERN void
7208 e_client_activate_done_listener_add(E_Client *ec, struct wl_listener *listener)
7209 {
7210    API_ENTRY;
7211    wl_signal_add(&priv->events.activate_done, listener);
7212 }
7213
7214 EINTERN struct wl_listener *
7215 e_client_activate_done_listener_get(E_Client *ec, wl_notify_func_t notify)
7216 {
7217    API_ENTRY_VAL(NULL);
7218    return wl_signal_get(&priv->events.activate_done, notify);
7219 }
7220
7221 EINTERN void
7222 e_client_mouse_in_listener_add(E_Client *ec, struct wl_listener *listener)
7223 {
7224    API_ENTRY;
7225    wl_signal_add(&priv->events.mouse_in, listener);
7226 }
7227
7228 EINTERN struct wl_listener *
7229 e_client_mouse_in_listener_get(E_Client *ec, wl_notify_func_t notify)
7230 {
7231    API_ENTRY_VAL(NULL);
7232    return wl_signal_get(&priv->events.mouse_in, notify);
7233 }
7234
7235 EINTERN void
7236 e_client_mouse_out_listener_add(E_Client *ec, struct wl_listener *listener)
7237 {
7238    API_ENTRY;
7239    wl_signal_add(&priv->events.mouse_out, listener);
7240 }
7241
7242 EINTERN struct wl_listener *
7243 e_client_mouse_out_listener_get(E_Client *ec, wl_notify_func_t notify)
7244 {
7245    API_ENTRY_VAL(NULL);
7246    return wl_signal_get(&priv->events.mouse_out, notify);
7247 }
7248
7249 EINTERN void
7250 e_client_mouse_down_listener_add(E_Client *ec, struct wl_listener *listener)
7251 {
7252    API_ENTRY;
7253    wl_signal_add(&priv->events.mouse_down, listener);
7254 }
7255
7256 EINTERN struct wl_listener *
7257 e_client_mouse_down_listener_get(E_Client *ec, wl_notify_func_t notify)
7258 {
7259    API_ENTRY_VAL(NULL);
7260    return wl_signal_get(&priv->events.mouse_down, notify);
7261 }
7262
7263 EINTERN void
7264 e_client_focus_set_listener_add(E_Client *ec, struct wl_listener *listener)
7265 {
7266    API_ENTRY;
7267    wl_signal_add(&priv->events.focus_set, listener);
7268 }
7269
7270 EINTERN struct wl_listener *
7271 e_client_focus_set_listener_get(E_Client *ec, wl_notify_func_t notify)
7272 {
7273    API_ENTRY_VAL(NULL);
7274    return wl_signal_get(&priv->events.focus_set, notify);
7275 }
7276
7277 EINTERN void
7278 e_client_focus_unset_listener_add(E_Client *ec, struct wl_listener *listener)
7279 {
7280    API_ENTRY;
7281    wl_signal_add(&priv->events.focus_unset, listener);
7282 }
7283
7284 EINTERN struct wl_listener *
7285 e_client_focus_unset_listener_get(E_Client *ec, wl_notify_func_t notify)
7286 {
7287    API_ENTRY_VAL(NULL);
7288    return wl_signal_get(&priv->events.focus_unset, notify);
7289 }
7290
7291 EINTERN void
7292 e_client_focus_defer_set_listener_add(E_Client *ec, struct wl_listener *listener)
7293 {
7294    API_ENTRY;
7295    wl_signal_add(&priv->events.focus_defer_set, listener);
7296 }
7297
7298 EINTERN struct wl_listener *
7299 e_client_focus_defer_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_defer_set, notify);
7303 }
7304
7305 EINTERN void
7306 e_client_focus_latest_set_listener_add(E_Client *ec, struct wl_listener *listener)
7307 {
7308    API_ENTRY;
7309    wl_signal_add(&priv->events.focus_latest_set, listener);
7310 }
7311
7312 EINTERN struct wl_listener *
7313 e_client_focus_latest_set_listener_get(E_Client *ec, wl_notify_func_t notify)
7314 {
7315    API_ENTRY_VAL(NULL);
7316    return wl_signal_get(&priv->events.focus_latest_set, notify);
7317 }
7318
7319 EINTERN void
7320 e_client_iconify_listener_add(E_Client *ec, struct wl_listener *listener)
7321 {
7322    API_ENTRY;
7323    wl_signal_add(&priv->events.iconify, listener);
7324 }
7325
7326 EINTERN struct wl_listener *
7327 e_client_iconify_listener_get(E_Client *ec, wl_notify_func_t notify)
7328 {
7329    API_ENTRY_VAL(NULL);
7330    return wl_signal_get(&priv->events.iconify, notify);
7331 }
7332
7333 EINTERN void
7334 e_client_uniconify_listener_add(E_Client *ec, struct wl_listener *listener)
7335 {
7336    API_ENTRY;
7337    wl_signal_add(&priv->events.uniconify, listener);
7338 }
7339
7340 EINTERN struct wl_listener *
7341 e_client_uniconify_listener_get(E_Client *ec, wl_notify_func_t notify)
7342 {
7343    API_ENTRY_VAL(NULL);
7344    return wl_signal_get(&priv->events.uniconify, notify);
7345 }
7346
7347 EINTERN void
7348 e_client_maximize_listener_add(E_Client *ec, struct wl_listener *listener)
7349 {
7350    API_ENTRY;
7351    wl_signal_add(&priv->events.maximize, listener);
7352 }
7353
7354 EINTERN struct wl_listener *
7355 e_client_maximize_listener_get(E_Client *ec, wl_notify_func_t notify)
7356 {
7357    API_ENTRY_VAL(NULL);
7358    return wl_signal_get(&priv->events.maximize, notify);
7359 }
7360
7361 EINTERN void
7362 e_client_unmaximize_listener_add(E_Client *ec, struct wl_listener *listener)
7363 {
7364    API_ENTRY;
7365    wl_signal_add(&priv->events.unmaximize, listener);
7366 }
7367
7368 EINTERN struct wl_listener *
7369 e_client_unmaximize_listener_get(E_Client *ec, wl_notify_func_t notify)
7370 {
7371    API_ENTRY_VAL(NULL);
7372    return wl_signal_get(&priv->events.unmaximize, notify);
7373 }
7374
7375 EINTERN void
7376 e_client_fullscreen_pre_listener_add(E_Client *ec, struct wl_listener *listener)
7377 {
7378    API_ENTRY;
7379    wl_signal_add(&priv->events.fullscreen_pre, listener);
7380 }
7381
7382 EINTERN struct wl_listener *
7383 e_client_fullscreen_pre_listener_get(E_Client *ec, wl_notify_func_t notify)
7384 {
7385    API_ENTRY_VAL(NULL);
7386    return wl_signal_get(&priv->events.fullscreen_pre, notify);
7387 }
7388
7389 EINTERN void
7390 e_client_fullscreen_listener_add(E_Client *ec, struct wl_listener *listener)
7391 {
7392    API_ENTRY;
7393    wl_signal_add(&priv->events.fullscreen, listener);
7394 }
7395
7396 EINTERN struct wl_listener *
7397 e_client_fullscreen_listener_get(E_Client *ec, wl_notify_func_t notify)
7398 {
7399    API_ENTRY_VAL(NULL);
7400    return wl_signal_get(&priv->events.fullscreen, notify);
7401 }
7402
7403 EINTERN void
7404 e_client_unfullscreen_listener_add(E_Client *ec, struct wl_listener *listener)
7405 {
7406    API_ENTRY;
7407    wl_signal_add(&priv->events.unfullscreen, listener);
7408 }
7409
7410 EINTERN struct wl_listener *
7411 e_client_unfullscreen_listener_get(E_Client *ec, wl_notify_func_t notify)
7412 {
7413    API_ENTRY_VAL(NULL);
7414    return wl_signal_get(&priv->events.unfullscreen, notify);
7415 }
7416
7417 EINTERN void
7418 e_client_move_listener_add(E_Client *ec, struct wl_listener *listener)
7419 {
7420    API_ENTRY;
7421    wl_signal_add(&priv->events.move, listener);
7422 }
7423
7424 EINTERN struct wl_listener *
7425 e_client_move_listener_get(E_Client *ec, wl_notify_func_t notify)
7426 {
7427    API_ENTRY_VAL(NULL);
7428    return wl_signal_get(&priv->events.move, notify);
7429 }
7430
7431 EINTERN void
7432 e_client_raise_listener_add(E_Client *ec, struct wl_listener *listener)
7433 {
7434    API_ENTRY;
7435    wl_signal_add(&priv->events.raise, listener);
7436 }
7437
7438 EINTERN struct wl_listener *
7439 e_client_raise_listener_get(E_Client *ec, wl_notify_func_t notify)
7440 {
7441    API_ENTRY_VAL(NULL);
7442    return wl_signal_get(&priv->events.raise, notify);
7443 }
7444
7445 EINTERN void
7446 e_client_lower_listener_add(E_Client *ec, struct wl_listener *listener)
7447 {
7448    API_ENTRY;
7449    wl_signal_add(&priv->events.lower, listener);
7450 }
7451
7452 EINTERN struct wl_listener *
7453 e_client_lower_listener_get(E_Client *ec, wl_notify_func_t notify)
7454 {
7455    API_ENTRY_VAL(NULL);
7456    return wl_signal_get(&priv->events.lower, notify);
7457 }
7458
7459 EINTERN void
7460 e_client_stack_below_listener_add(E_Client *ec, struct wl_listener *listener)
7461 {
7462    API_ENTRY;
7463    wl_signal_add(&priv->events.stack_below, listener);
7464 }
7465
7466 EINTERN struct wl_listener *
7467 e_client_stack_below_listener_get(E_Client *ec, wl_notify_func_t notify)
7468 {
7469    API_ENTRY_VAL(NULL);
7470    return wl_signal_get(&priv->events.stack_below, notify);
7471 }
7472
7473 EINTERN void
7474 e_client_stack_above_listener_add(E_Client *ec, struct wl_listener *listener)
7475 {
7476    API_ENTRY;
7477    wl_signal_add(&priv->events.stack_above, listener);
7478 }
7479
7480 EINTERN struct wl_listener *
7481 e_client_stack_above_listener_get(E_Client *ec, wl_notify_func_t notify)
7482 {
7483    API_ENTRY_VAL(NULL);
7484    return wl_signal_get(&priv->events.stack_above, notify);
7485 }
7486
7487 EINTERN void
7488 e_client_layer_set_listener_add(E_Client *ec, struct wl_listener *listener)
7489 {
7490    API_ENTRY;
7491    wl_signal_add(&priv->events.layer_set, listener);
7492 }
7493
7494 EINTERN struct wl_listener *
7495 e_client_layer_set_listener_get(E_Client *ec, wl_notify_func_t notify)
7496 {
7497    API_ENTRY_VAL(NULL);
7498    return wl_signal_get(&priv->events.layer_set, notify);
7499 }
7500
7501 EINTERN void
7502 e_client_stack_transient_for_done_listener_add(E_Client *ec, struct wl_listener *listener)
7503 {
7504    API_ENTRY;
7505    wl_signal_add(&priv->events.stack_transient_for_done, listener);
7506 }
7507
7508 EINTERN struct wl_listener *
7509 e_client_stack_transient_for_done_listener_get(E_Client *ec, wl_notify_func_t notify)
7510 {
7511    API_ENTRY_VAL(NULL);
7512    return wl_signal_get(&priv->events.stack_transient_for_done, notify);
7513 }
7514
7515 EINTERN void
7516 e_client_stick_listener_add(E_Client *ec, struct wl_listener *listener)
7517 {
7518    API_ENTRY;
7519    wl_signal_add(&priv->events.stick, listener);
7520 }
7521
7522 EINTERN struct wl_listener *
7523 e_client_stick_listener_get(E_Client *ec, wl_notify_func_t notify)
7524 {
7525    API_ENTRY_VAL(NULL);
7526    return wl_signal_get(&priv->events.stick, notify);
7527 }
7528
7529 EINTERN void
7530 e_client_unstick_listener_add(E_Client *ec, struct wl_listener *listener)
7531 {
7532    API_ENTRY;
7533    wl_signal_add(&priv->events.unstick, listener);
7534 }
7535
7536 EINTERN struct wl_listener *
7537 e_client_unstick_listener_get(E_Client *ec, wl_notify_func_t notify)
7538 {
7539    API_ENTRY_VAL(NULL);
7540    return wl_signal_get(&priv->events.unstick, notify);
7541 }