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