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