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