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