e_comp_wl: remove "maximize_done" smart call
[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    else
4488      {
4489         // store the E_Maximize value
4490         ec->maximized = max;
4491         ec->changes.need_unmaximize = 0;
4492      }
4493 }
4494
4495 E_API void
4496 e_client_unmaximize(E_Client *ec, E_Maximize max)
4497 {
4498    E_OBJECT_CHECK(ec);
4499    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4500
4501    if (!(max & E_MAXIMIZE_DIRECTION))
4502      {
4503         CRI("BUG: Unmaximize call without direction!");
4504         return;
4505      }
4506    if (ec->new_client)
4507      {
4508         ec->changes.need_unmaximize = 1;
4509         EC_CHANGED(ec);
4510         return;
4511      }
4512
4513    /* Remove directions not used */
4514    max &= (ec->maximized & E_MAXIMIZE_DIRECTION);
4515    /* Can only remove existing maximization directions */
4516    if (!max) return;
4517
4518    if (!ec->fullscreen)
4519      {
4520         evas_object_smart_callback_call(ec->frame, "unmaximize_pre", NULL);
4521
4522         // call the unmaximize hook of a client
4523         wl_signal_emit(&PRI(ec)->events.unmaximize, &max);
4524
4525         evas_object_smart_callback_call(ec->frame, "unmaximize_done", NULL);
4526      }
4527
4528    ec->maximized = E_MAXIMIZE_NONE;
4529    ec->changes.need_unmaximize = 0;
4530 }
4531
4532 EINTERN void
4533 e_client_fullscreen(E_Client *ec, E_Fullscreen policy)
4534 {
4535    E_OBJECT_CHECK(ec);
4536    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4537
4538    if (ec->fullscreen) return;
4539
4540    // call the fullscreen_pre hook of a client
4541    wl_signal_emit(&PRI(ec)->events.fullscreen_pre, NULL);
4542    _e_client_hook_call(E_CLIENT_HOOK_FULLSCREEN_PRE, ec);
4543
4544    if (ec->skip_fullscreen) return;
4545    if (ec->new_client)
4546      {
4547         ec->need_fullscreen = 1;
4548         return;
4549      }
4550
4551    ec->saved.layer = ec->layer;
4552    e_client_layer_set(ec, ec->fullscreen_layer);
4553
4554    ec->fullscreen = 1;
4555
4556    // call the fullscreen hook of a client
4557    wl_signal_emit(&PRI(ec)->events.fullscreen, &policy);
4558
4559    ec->fullscreen_policy = policy;
4560
4561    _e_client_event_simple(ec, E_EVENT_CLIENT_FULLSCREEN);
4562 }
4563
4564 EINTERN void
4565 e_client_unfullscreen(E_Client *ec)
4566 {
4567    E_OBJECT_CHECK(ec);
4568    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4569
4570    ec->need_fullscreen = 0;
4571
4572    if (!ec->fullscreen) return;
4573
4574    ec->fullscreen = 0;
4575
4576    E_Fullscreen policy = ec->fullscreen_policy;
4577
4578    // call the unfullscreen hook of a client
4579    wl_signal_emit(&PRI(ec)->events.unfullscreen, &policy);
4580
4581    e_client_layer_set(ec, ec->saved.layer);
4582
4583    ec->fullscreen_policy = E_FULLSCREEN_RESIZE;
4584
4585    _e_client_event_simple(ec, E_EVENT_CLIENT_UNFULLSCREEN);
4586 }
4587
4588 ///////////////////////////////////////
4589 EINTERN Eina_Bool
4590 e_client_is_parent_iconify_by_client(E_Client *ec)
4591 {
4592    E_Client *parent = ec->parent;
4593    if (!parent) return EINA_FALSE;
4594
4595    if ((parent->exp_iconify.type == E_ICONIFIED_TYPE_ICONIFY_BY_CLIENT) ||
4596        (parent->exp_iconify.type == E_ICONIFIED_TYPE_PARENT_ICONIFY_BY_CLIENT))
4597      return EINA_TRUE;
4598
4599    return EINA_FALSE;
4600 }
4601
4602 E_API void
4603 e_client_iconify(E_Client *ec)
4604 {
4605    E_OBJECT_CHECK(ec);
4606    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4607
4608    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
4609    Eina_Bool iconified_by_client = e_client_is_iconified_by_client(ec);
4610
4611    ELOGF("TZVIS", "ICONIFY  |iconic:%d  |argb:%d       |not_raise:%d   |by_client:%d, type:%d",
4612          ec, ec->iconic, ec->argb, (unsigned int)ec->exp_iconify.not_raise,
4613          ec->exp_iconify.by_client, ec->exp_iconify.type);
4614
4615    if (ec->iconic) return;
4616    if (ec->exp_iconify.skip_iconify && !iconified_by_client) return;
4617    if (ec->exp_iconify.skip_by_remote) return;
4618    if (!cdata || !cdata->mapped)
4619      {
4620         if (!iconified_by_client)
4621           {
4622              ELOGF("TZVIS", "Not mapped.. So, don't iconify", ec);
4623              return;
4624           }
4625         else
4626           {
4627              ELOGF("TZVIS", "Not mapped.. But, iconify by user request", ec);
4628           }
4629      }
4630
4631    TRACE_DS_BEGIN(CLIENT:ICONIFY);
4632
4633    wl_signal_emit(&PRI(ec)->events.iconify, NULL);
4634    _e_client_hook_call(E_CLIENT_HOOK_ICONIFY, ec);
4635
4636    TRACE_DS_END();
4637 }
4638
4639 E_API void
4640 e_client_uniconify(E_Client *ec)
4641 {
4642    E_Comp_Wl_Client_Data *cdata;
4643
4644    E_OBJECT_CHECK(ec);
4645    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4646
4647    cdata = e_client_cdata_get(ec);
4648
4649    ELOGF("TZVIS", "UNICONIFY|iconic:%d  |argb:%d       |not_raise:%d  |by_client:%d, type:%d |mapped:%d",
4650          ec, ec->iconic, ec->argb, (unsigned int)ec->exp_iconify.not_raise,
4651          ec->exp_iconify.by_client, ec->exp_iconify.type,
4652          cdata ? cdata->mapped : 0);
4653
4654    if (!ec->iconic) return;
4655
4656    TRACE_DS_BEGIN(CLIENT:UNICONIFY);
4657
4658     // call the uniconify hook of a client
4659    wl_signal_emit(&PRI(ec)->events.uniconify, NULL);
4660    _e_client_hook_call(E_CLIENT_HOOK_UNICONIFY, ec);
4661
4662    TRACE_DS_END();
4663 }
4664
4665 E_API void
4666 e_client_iconified_type_set(E_Client *ec, E_Iconified_Type type)
4667 {
4668    if (!ec) return;
4669    ec->exp_iconify.type = type;
4670 }
4671
4672 EINTERN E_Iconified_Type
4673 e_client_iconified_type_get(E_Client *ec)
4674 {
4675    if (!ec) return E_ICONIFIED_TYPE_NONE;
4676    return ec->exp_iconify.type;
4677 }
4678
4679 E_API Eina_Bool e_client_is_iconified_by_client(E_Client *ec)
4680 {
4681    if (!ec) return EINA_FALSE;
4682
4683    if (ec->exp_iconify.type == E_ICONIFIED_TYPE_ICONIFY_BY_CLIENT)
4684      return EINA_TRUE;
4685
4686    if (ec->exp_iconify.type == E_ICONIFIED_TYPE_DESK_ICONIFY_BY_CLIENT)
4687      return EINA_TRUE;
4688
4689    if (ec->exp_iconify.type == E_ICONIFIED_TYPE_PARENT_ICONIFY_BY_CLIENT)
4690      return EINA_TRUE;
4691
4692    if (ec->exp_iconify.by_client)
4693      {
4694         ELOGF("POL", "CHECK. mismatch value. by_client:%d, type:%d", ec, ec->exp_iconify.by_client, ec->exp_iconify.type);
4695         return EINA_TRUE;
4696      }
4697
4698    return EINA_FALSE;
4699 }
4700
4701 ///////////////////////////////////////
4702
4703 EINTERN void e_client_hide_by_request_set(E_Client *ec, Eina_Bool set)
4704 {
4705    API_ENTRY;
4706    priv->hide_by_request = set;
4707 }
4708
4709 EINTERN Eina_Bool e_client_hide_by_request_get(E_Client *ec)
4710 {
4711    API_ENTRY_VAL(EINA_FALSE);
4712    return priv->hide_by_request;
4713 }
4714
4715 EINTERN void e_client_focus_check_set(E_Client *ec, Eina_Bool set)
4716 {
4717    API_ENTRY;
4718    priv->focus_check = set;
4719 }
4720
4721 EINTERN Eina_Bool e_client_focus_check_get(E_Client *ec)
4722 {
4723    API_ENTRY_VAL(EINA_FALSE);
4724    return priv->focus_check;
4725 }
4726
4727 ///////////////////////////////////////
4728
4729 EINTERN void
4730 e_client_stick(E_Client *ec)
4731 {
4732    E_OBJECT_CHECK(ec);
4733    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4734    if (ec->sticky) return;
4735
4736    // call the stick hook of a client
4737    wl_signal_emit(&PRI(ec)->events.stick, NULL);
4738
4739    // send the sticky property event of a client
4740    _e_client_event_property(ec, E_CLIENT_PROPERTY_STICKY);
4741 }
4742
4743 EINTERN void
4744 e_client_unstick(E_Client *ec)
4745 {
4746    E_OBJECT_CHECK(ec);
4747    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4748
4749    if (!ec->sticky) return;
4750
4751    // call the unstick hook of a client
4752    wl_signal_emit(&PRI(ec)->events.unstick, NULL);
4753
4754   // send the sticky property event of a client
4755    _e_client_event_property(ec, E_CLIENT_PROPERTY_STICKY);
4756 }
4757
4758 EINTERN void
4759 e_client_pinned_set(E_Client *ec, Eina_Bool set)
4760 {
4761    E_Layer layer;
4762
4763    EINA_SAFETY_ON_NULL_RETURN(ec);
4764    if (set)
4765      layer = E_LAYER_CLIENT_ABOVE;
4766    else
4767      layer = E_LAYER_CLIENT_NORMAL;
4768
4769    e_client_layer_set(ec, layer);
4770
4771    EC_CHANGED(ec);
4772 }
4773
4774 ///////////////////////////////////////
4775
4776 ///////////////////////////////////////
4777
4778 EINTERN void
4779 e_client_comp_hidden_set(E_Client *ec, Eina_Bool hidden)
4780 {
4781    E_OBJECT_CHECK(ec);
4782    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4783
4784    hidden = !!hidden;
4785    if (ec->comp_hidden == hidden) return;
4786    ec->comp_hidden = hidden;
4787    evas_object_smart_callback_call(ec->frame, "comp_hidden", NULL);
4788 }
4789
4790 ///////////////////////////////////////
4791
4792 EINTERN void
4793 e_client_act_move_keyboard(E_Client *ec)
4794 {
4795    EINA_SAFETY_ON_NULL_RETURN(ec);
4796
4797    if (!_e_client_move_begin(ec))
4798      return;
4799
4800    _e_client_action_init(ec);
4801    _e_client_action_move_timeout_add();
4802
4803    wl_signal_emit(&PRI(ec)->events.move_update, NULL);
4804    if (!_e_client_hook_call(E_CLIENT_HOOK_MOVE_UPDATE, ec)) return;
4805    evas_object_freeze_events_set(ec->frame, 1);
4806
4807    if (!action_handler_mouse)
4808      action_handler_mouse = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, _e_client_move_mouse_down, NULL);
4809 }
4810
4811 EINTERN void
4812 e_client_act_resize_keyboard(E_Client *ec)
4813 {
4814    EINA_SAFETY_ON_NULL_RETURN(ec);
4815
4816    ec->resize_mode = E_POINTER_RESIZE_TL;
4817    ec->keyboard_resizing = 1;
4818    if (!e_client_resize_begin(ec))
4819      {
4820         ec->keyboard_resizing = 0;
4821         return;
4822      }
4823
4824    _e_client_action_init(ec);
4825    _e_client_action_resize_timeout_add();
4826    evas_object_freeze_events_set(ec->frame, 1);
4827
4828    if (!action_handler_mouse)
4829      action_handler_mouse = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, _e_client_resize_mouse_down, NULL);
4830 }
4831
4832 EINTERN void
4833 e_client_act_move_begin(E_Client *ec, E_Binding_Event_Mouse_Button *ev)
4834 {
4835    E_OBJECT_CHECK(ec);
4836    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4837    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4838    if (ev)
4839      {
4840         char source[256];
4841
4842         snprintf(source, sizeof(source) - 1, "mouse,down,%i", ev->button);
4843         _e_client_moveinfo_gather(ec, source);
4844      }
4845    if (!_e_client_move_begin(ec))
4846      return;
4847
4848    _e_client_action_init(ec);
4849 }
4850
4851 E_API void
4852 e_client_act_move_end(E_Client *ec, E_Binding_Event_Mouse_Button *ev EINA_UNUSED)
4853 {
4854    E_OBJECT_CHECK(ec);
4855    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4856    if (!ec->moving) return;
4857    _e_client_move_end(ec);
4858    _e_client_action_finish();
4859 }
4860
4861 EINTERN void
4862 e_client_act_resize_begin(E_Client *ec, E_Binding_Event_Mouse_Button *ev, E_Pointer_Mode resize_mode)
4863 {
4864    E_OBJECT_CHECK(ec);
4865    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4866    if (ec->lock_user_size) return;
4867    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
4868    if (ev)
4869      {
4870         char source[256];
4871         snprintf(source, sizeof(source) - 1, "mouse,down,%i", ev->button);
4872         _e_client_moveinfo_gather(ec, source);
4873
4874         if (resize_mode != E_POINTER_RESIZE_NONE)
4875           {
4876              ec->resize_mode = resize_mode;
4877           }
4878         else
4879           {
4880              /* Use canvas.x, canvas.y of event.
4881               * Transformed coordinates has to be considered for accurate resize_mode
4882               * rather than absolute coordinates. */
4883              if ((ev->canvas.x > (ec->x + ec->w / 5)) &&
4884                  (ev->canvas.x < (ec->x + ec->w * 4 / 5)))
4885                {
4886                   if (ev->canvas.y < (ec->y + ec->h / 2)) ec->resize_mode = E_POINTER_RESIZE_T;
4887                   else ec->resize_mode = E_POINTER_RESIZE_B;
4888                }
4889              else if (ev->canvas.x < (ec->x + ec->w / 2))
4890                {
4891                   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;
4892                   else if (ev->canvas.y < (ec->y + ec->h / 2)) ec->resize_mode = E_POINTER_RESIZE_TL;
4893                   else ec->resize_mode = E_POINTER_RESIZE_BL;
4894                }
4895              else
4896                {
4897                   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;
4898                   else if (ev->canvas.y < (ec->y + ec->h / 2)) ec->resize_mode = E_POINTER_RESIZE_TR;
4899                   else ec->resize_mode = E_POINTER_RESIZE_BR;
4900                }
4901           }
4902      }
4903    if (!e_client_resize_begin(ec))
4904      return;
4905    _e_client_action_init(ec);
4906 }
4907
4908 EINTERN void
4909 e_client_act_resize_end(E_Client *ec, E_Binding_Event_Mouse_Button *ev EINA_UNUSED)
4910 {
4911    E_OBJECT_CHECK(ec);
4912    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4913    if (e_client_util_resizing_get(ec))
4914      {
4915         _e_client_resize_end(ec);
4916         ec->changes.reset_gravity = 1;
4917         if (!e_object_is_del(E_OBJECT(ec)))
4918           EC_CHANGED(ec);
4919      }
4920    _e_client_action_finish();
4921 }
4922
4923 EINTERN void
4924 e_client_act_menu_begin(E_Client *ec, E_Binding_Event_Mouse_Button *ev, int key)
4925 {
4926    E_OBJECT_CHECK(ec);
4927    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4928 }
4929
4930 EINTERN void
4931 e_client_act_close_begin(E_Client *ec)
4932 {
4933    E_OBJECT_CHECK(ec);
4934    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4935    if (ec->lock_close) return;
4936    if (ec->icccm.delete_request)
4937      {
4938         ec->delete_requested = 1;
4939         evas_object_smart_callback_call(ec->frame, "delete_request", NULL);
4940      }
4941    else if (e_config->kill_if_close_not_possible)
4942      {
4943         e_client_act_kill_begin(ec);
4944      }
4945 }
4946
4947 EINTERN void
4948 e_client_act_kill_begin(E_Client *ec)
4949 {
4950    E_OBJECT_CHECK(ec);
4951    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4952    if (ec->internal) return;
4953    if (ec->lock_close) return;
4954    if ((ec->netwm.pid > 1) && (e_config->kill_process))
4955      {
4956         kill(ec->netwm.pid, SIGINT);
4957         ec->kill_timer = ecore_timer_add(e_config->kill_timer_wait,
4958                                          _e_client_cb_kill_timer, ec);
4959      }
4960    else
4961      evas_object_smart_callback_call(ec->frame, "kill_request", NULL);
4962 }
4963
4964 ////////////////////////////////////////////
4965
4966 EINTERN void
4967 e_client_ping(E_Client *ec)
4968 {
4969    E_OBJECT_CHECK(ec);
4970    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
4971
4972    if (!e_config->ping_clients) return;
4973
4974    EINA_SAFETY_ON_TRUE_RETURN(e_object_is_del(E_OBJECT(ec)));
4975
4976    ec->ping_ok = 0;
4977    evas_object_smart_callback_call(ec->frame, "ping", NULL);
4978    ec->ping = ecore_loop_time_get();
4979    if (ec->ping_poller) ecore_poller_del(ec->ping_poller);
4980    ec->ping_poller = ecore_poller_add(ECORE_POLLER_CORE,
4981                                       e_config->ping_clients_interval,
4982                                       _e_client_cb_ping_poller, ec);
4983 }
4984
4985 ////////////////////////////////////////////
4986 E_API void
4987 e_client_cursor_map_apply(E_Client *ec, int rotation, int x, int y)
4988 {
4989    // TODO: remove(deprecate) this e_client_cursor_map_apply.
4990 }
4991
4992 EINTERN void
4993 e_client_move_cancel(void)
4994 {
4995    if (!ecmove) return;
4996    if (ecmove->cur_mouse_action)
4997      {
4998         E_Client *ec;
4999
5000         ec = ecmove;
5001         e_object_ref(E_OBJECT(ec));
5002         if (ec->cur_mouse_action->func.end_mouse)
5003           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", NULL);
5004         else if (ec->cur_mouse_action->func.end)
5005           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
5006         e_object_unref(E_OBJECT(ec->cur_mouse_action));
5007         ec->cur_mouse_action = NULL;
5008         e_object_unref(E_OBJECT(ec));
5009      }
5010    else
5011      _e_client_move_end(ecmove);
5012 }
5013
5014 EINTERN void
5015 e_client_resize_cancel(void)
5016 {
5017    if (!ecresize) return;
5018    if (ecresize->cur_mouse_action)
5019      {
5020         E_Client *ec;
5021
5022         ec = ecresize;
5023         e_object_ref(E_OBJECT(ec));
5024         if (ec->cur_mouse_action->func.end_mouse)
5025           ec->cur_mouse_action->func.end_mouse(E_OBJECT(ec), "", NULL);
5026         else if (ec->cur_mouse_action->func.end)
5027           ec->cur_mouse_action->func.end(E_OBJECT(ec), "");
5028         e_object_unref(E_OBJECT(ec->cur_mouse_action));
5029         ec->cur_mouse_action = NULL;
5030         e_object_unref(E_OBJECT(ec));
5031      }
5032    else
5033      _e_client_resize_end(ecresize);
5034 }
5035
5036 EINTERN Eina_Bool
5037 e_client_resize_begin(E_Client *ec)
5038 {
5039    if ((ec->fullscreen) || (ec->lock_user_size))
5040      goto error;
5041    if (!_e_client_action_input_win_new()) goto error;
5042    ecresize = ec;
5043    if (ec->manage_resize.enable_aspect_ratio)
5044      {
5045         ELOGF("RESIZE", "Set resize aspect ratio.. ratio(%dx%d)", ec, ec->w, ec->h);
5046         ec->manage_resize.aw = ec->w;
5047         ec->manage_resize.ah = ec->h - ec->manage_resize.header_h - ec->manage_resize.footer_h;
5048      }
5049
5050    wl_signal_emit(&PRI(ec)->events.move_begin, NULL);
5051    _e_client_hook_call(E_CLIENT_HOOK_RESIZE_BEGIN, ec);
5052    if (ec->transformed)
5053      _e_client_transform_resize_begin(ec);
5054    if (!e_client_util_resizing_get(ec))
5055      {
5056         if (ecresize == ec) ecresize = NULL;
5057         _e_client_action_input_win_del();
5058         return EINA_FALSE;
5059      }
5060    if (!ec->lock_user_stacking)
5061      {
5062         if (e_config->border_raise_on_mouse_action)
5063           e_client_raise(ec);
5064      }
5065
5066    if (e_comp->hwc)
5067      e_comp_client_override_add(ec);
5068
5069    return EINA_TRUE;
5070 error:
5071    ec->resize_mode = E_POINTER_RESIZE_NONE;
5072    return EINA_FALSE;
5073 }
5074
5075
5076 ////////////////////////////////////////////
5077
5078 EINTERN void
5079 e_client_frame_recalc(E_Client *ec)
5080 {
5081    EINA_SAFETY_ON_NULL_RETURN(ec);
5082    if (!ec->frame) return;
5083    evas_object_smart_callback_call(ec->frame, "frame_recalc", NULL);
5084 }
5085
5086 ////////////////////////////////////////////
5087
5088 EINTERN void
5089 e_client_signal_move_begin(E_Client *ec, const char *sig, const char *src EINA_UNUSED)
5090 {
5091    E_OBJECT_CHECK(ec);
5092    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
5093
5094    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
5095    _e_client_moveinfo_gather(ec, sig);
5096    if (!_e_client_move_begin(ec)) return;
5097 }
5098
5099 EINTERN void
5100 e_client_signal_move_end(E_Client *ec, const char *sig EINA_UNUSED, const char *src EINA_UNUSED)
5101 {
5102    E_OBJECT_CHECK(ec);
5103    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
5104    if (!ec->moving) return;
5105    _e_client_move_end(ec);
5106 }
5107
5108 EINTERN void
5109 e_client_signal_resize_begin(E_Client *ec, const char *dir, const char *sig, const char *src EINA_UNUSED)
5110 {
5111    int resize_mode = E_POINTER_RESIZE_BR;
5112
5113    E_OBJECT_CHECK(ec);
5114    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
5115
5116    if (e_client_util_resizing_get(ec) || (ec->moving)) return;
5117    if (!strcmp(dir, "tl"))
5118      {
5119         resize_mode = E_POINTER_RESIZE_TL;
5120      }
5121    else if (!strcmp(dir, "t"))
5122      {
5123         resize_mode = E_POINTER_RESIZE_T;
5124      }
5125    else if (!strcmp(dir, "tr"))
5126      {
5127         resize_mode = E_POINTER_RESIZE_TR;
5128      }
5129    else if (!strcmp(dir, "r"))
5130      {
5131         resize_mode = E_POINTER_RESIZE_R;
5132      }
5133    else if (!strcmp(dir, "br"))
5134      {
5135         resize_mode = E_POINTER_RESIZE_BR;
5136      }
5137    else if (!strcmp(dir, "b"))
5138      {
5139         resize_mode = E_POINTER_RESIZE_B;
5140      }
5141    else if (!strcmp(dir, "bl"))
5142      {
5143         resize_mode = E_POINTER_RESIZE_BL;
5144      }
5145    else if (!strcmp(dir, "l"))
5146      {
5147         resize_mode = E_POINTER_RESIZE_L;
5148      }
5149    ec->resize_mode = resize_mode;
5150    _e_client_moveinfo_gather(ec, sig);
5151    if (!e_client_resize_begin(ec))
5152      return;
5153 }
5154
5155 EINTERN void
5156 e_client_signal_resize_end(E_Client *ec, const char *dir EINA_UNUSED, const char *sig EINA_UNUSED, const char *src EINA_UNUSED)
5157 {
5158    E_OBJECT_CHECK(ec);
5159    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
5160    if (!e_client_util_resizing_get(ec)) return;
5161    _e_client_resize_handle(ec);
5162    _e_client_resize_end(ec);
5163    ec->changes.reset_gravity = 1;
5164    EC_CHANGED(ec);
5165 }
5166
5167 ////////////////////////////////////////////
5168
5169 EINTERN void
5170 e_client_resize_limit(E_Client *ec, int *w, int *h)
5171 {
5172    E_OBJECT_CHECK(ec);
5173    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
5174
5175    if (ec->frame)
5176      e_comp_object_frame_wh_unadjust(ec->frame, *w, *h, w, h);
5177    if (*h < 1) *h = 1;
5178    if (*w < 1) *w = 1;
5179
5180    if ((ec->icccm.max_w > 0) && (*w > ec->icccm.max_w)) *w = ec->icccm.max_w;
5181    else if (*w < ec->icccm.min_w)
5182      *w = ec->icccm.min_w;
5183    if ((ec->icccm.max_h > 0) && (*h > ec->icccm.max_h)) *h = ec->icccm.max_h;
5184    else if (*h < ec->icccm.min_h)
5185      *h = ec->icccm.min_h;
5186
5187    if (ec->frame)
5188      e_comp_object_frame_wh_adjust(ec->frame, *w, *h, w, h);
5189 }
5190
5191 ////////////////////////////////////////////
5192
5193
5194
5195 EINTERN E_Client *
5196 e_client_under_pointer_get(E_Desk *desk, E_Client *exclude)
5197 {
5198    int x, y;
5199
5200    /* We need to ensure that we can get the comp window for the
5201     * zone of either the given desk or the desk of the excluded
5202     * window, so return if neither is given */
5203    if (desk)
5204      e_input_device_pointer_xy_get(NULL, &x, &y);
5205    else if (exclude)
5206      e_input_device_pointer_xy_get(NULL, &x, &y);
5207    else
5208      return NULL;
5209
5210    if (!desk)
5211      {
5212         desk = exclude->desk;
5213         if (!desk)
5214           {
5215              if (exclude->zone)
5216                desk = e_desk_current_get(exclude->zone);
5217              else
5218                desk = e_desk_current_get(e_zone_current_get());
5219           }
5220      }
5221
5222    return desk ? _e_client_under_pointer_helper(desk, exclude, x, y) : NULL;
5223 }
5224
5225 E_API E_Client *e_client_under_position_get(E_Desk *desk, int x, int y, E_Client *exclude)
5226 {
5227    if (!desk) return NULL;
5228
5229    return _e_client_under_pointer_helper(desk, exclude, x, y);
5230 }
5231
5232 E_API E_Client *e_client_under_position_input_get(E_Desk *desk, int x, int y)
5233 {
5234    if (!desk) return NULL;
5235
5236    return _e_client_under_pointer_input_helper(desk, x, y);
5237 }
5238
5239 ////////////////////////////////////////////
5240
5241 ////////////////////////////////////////////
5242
5243 E_API void
5244 e_client_redirected_set(E_Client *ec, Eina_Bool set)
5245 {
5246    EINA_SAFETY_ON_NULL_RETURN(ec);
5247    if (ec->input_only) return;
5248    set = !!set;
5249    if (ec->redirected == set) return;
5250    if (set)
5251      {
5252         e_client_frame_recalc(ec);
5253
5254         wl_signal_emit(&PRI(ec)->events.redirect, NULL);
5255         if (!_e_client_hook_call(E_CLIENT_HOOK_REDIRECT, ec)) return;
5256      }
5257    else
5258      {
5259         wl_signal_emit(&PRI(ec)->events.unredirect, NULL);
5260         if (!_e_client_hook_call(E_CLIENT_HOOK_UNREDIRECT, ec)) return;
5261      }
5262    e_comp_object_redirected_set(ec->frame, set);
5263    ec->redirected = !!set;
5264 }
5265
5266 ////////////////////////////////////////////
5267
5268 E_API void
5269 e_client_transform_update(E_Client *ec)
5270 {
5271    if (e_client_util_resizing_get(ec))
5272      _e_client_transform_resize(ec);
5273 }
5274
5275 ////////////////////////////////////////////
5276
5277 EINTERN void
5278 e_client_transform_apply(E_Client *ec, double angle, double zoom, int cx, int cy)
5279 {
5280    E_Map *map;
5281    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
5282    E_Client *subc;
5283    Eina_List *l;
5284
5285    if (e_comp_wl_subsurface_check(ec))
5286      return;
5287
5288    /* check if it's different with current state */
5289    if ((ec->transform.angle == angle) &&
5290        (ec->transform.zoom == zoom) &&
5291        (ec->transform.center.x == cx) &&
5292        (ec->transform.center.y == cy))
5293      return;
5294
5295    /* use previous value if any required value is invalid */
5296    if (angle == -1.0)
5297      angle = ec->transform.angle;
5298    if (zoom == -1.0)
5299      zoom = ec->transform.zoom;
5300    if (!E_INSIDE(cx, cy,
5301                  ec->client.x, ec->client.y,
5302                  ec->client.w, ec->client.h))
5303      {
5304         cx = ec->transform.center.x;
5305         cy = ec->transform.center.y;
5306      }
5307
5308    if ((angle == 0) && (zoom == 1.0))
5309      {
5310         e_client_transform_clear(ec);
5311         return;
5312      }
5313
5314    map = e_map_new_with_direct_render(ec->transform_core.direct_render);
5315    e_map_util_points_populate_from_object_full(map, ec->frame, 0);
5316
5317    e_map_util_rotate(map, angle, cx, cy);
5318    _e_client_transform_geometry_save(ec, map);
5319
5320    e_map_util_zoom(map, zoom, zoom, cx, cy);
5321
5322    e_map_util_object_move_sync_set(map, EINA_TRUE);
5323    e_client_map_set(ec, map);
5324    e_client_map_enable_set(ec, EINA_TRUE);
5325
5326    EINA_LIST_FOREACH(cdata->sub.list, l, subc)
5327      _e_client_transform_sub_apply(subc, ec, zoom);
5328    EINA_LIST_REVERSE_FOREACH(cdata->sub.below_list, l, subc)
5329      _e_client_transform_sub_apply(subc, ec, zoom);
5330
5331    e_map_free(map);
5332
5333    ec->transform.zoom = zoom;
5334    ec->transform.angle = angle;
5335    ec->transform.center.x = cx;
5336    ec->transform.center.y = cy;
5337    ec->transformed = EINA_TRUE;
5338 }
5339
5340 ////////////////////////////////////////////
5341
5342 EINTERN void
5343 e_client_transform_clear(E_Client *ec)
5344 {
5345    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
5346    E_Client *subc;
5347    Eina_List *l;
5348
5349    e_client_map_enable_set(ec, EINA_FALSE);
5350    e_client_map_set(ec, NULL);
5351
5352    EINA_LIST_FOREACH(cdata->sub.list, l, subc)
5353      _e_client_transform_sub_apply(subc, ec, 1.0);
5354    EINA_LIST_REVERSE_FOREACH(cdata->sub.below_list, l, subc)
5355      _e_client_transform_sub_apply(subc, ec, 1.0);
5356
5357    ec->transform.zoom = 1.0;
5358    ec->transform.angle = 0.0;
5359    ec->transformed = EINA_FALSE;
5360 }
5361
5362 E_API Eina_Bool
5363 e_client_transform_core_enable_get(E_Client *ec)
5364 {
5365    if (!ec) return EINA_FALSE;
5366    return ec->transform_core.result.enable;
5367 }
5368
5369 E_API void
5370 e_client_transform_core_add(E_Client *ec, E_Util_Transform *transform)
5371 {
5372    if (!ec) return;
5373    if (!transform) return;
5374
5375    // duplication check
5376    if (ec->transform_core.transform_list &&
5377        eina_list_data_find(ec->transform_core.transform_list, transform) == transform)
5378      {
5379         return;
5380      }
5381
5382    ec->transform_core.transform_list = eina_list_append(ec->transform_core.transform_list, transform);
5383    ec->transform_core.changed = EINA_TRUE;
5384    e_util_transform_ref(transform);
5385   // e_client_transform_core_update(ec);
5386 }
5387
5388 E_API void
5389 e_client_transform_core_remove(E_Client *ec, E_Util_Transform *transform)
5390 {
5391    if (!ec) return;
5392    if (!transform) return;
5393
5394    if (ec->transform_core.transform_list &&
5395        eina_list_data_find(ec->transform_core.transform_list, transform) == transform)
5396      {
5397         ec->transform_core.transform_list = eina_list_remove(ec->transform_core.transform_list, transform);
5398         e_util_transform_unref(transform);
5399         ec->transform_core.changed = EINA_TRUE;
5400      }
5401
5402    e_client_transform_core_update(ec);
5403 }
5404
5405 E_API void
5406 e_client_transform_core_update(E_Client *ec)
5407 {
5408    if (!ec) return;
5409    if (ec->new_client) return;
5410    if (!_e_client_transform_core_check_change(ec)) return;
5411
5412    if (ec->transform_core.transform_list || ec->transform_core.parent.enable)
5413      {
5414         E_Util_Transform_Rect source_rect;
5415         E_Util_Transform_Matrix matrix, boundary_matrix;
5416         E_Util_Transform_Zoom zoom;
5417         Eina_List *l;
5418         Eina_Bool background;
5419         E_Util_Transform *temp_trans;
5420
5421         // 1. init state
5422         ec->transform_core.result.enable = EINA_TRUE;
5423         e_util_transform_rect_client_rect_get(&source_rect, ec);
5424         e_util_transform_init(&ec->transform_core.result.transform);
5425
5426         // 2. merge transform
5427         EINA_LIST_FOREACH(ec->transform_core.transform_list, l, temp_trans)
5428           {
5429              e_util_transform_merge(&ec->transform_core.result.transform, temp_trans);
5430           }
5431         zoom = ec->transform_core.result.transform.zoom;
5432
5433         // 2.5 check viewport
5434         if (e_util_transform_viewport_flag_get(&ec->transform_core.result.transform))
5435           {
5436              int vx = 0, vy = 0, vw = 0, vh = 0;
5437              e_util_transform_viewport_get(&ec->transform_core.result.transform, &vx, &vy, &vw, &vh);
5438              e_util_transform_rect_init(&source_rect, vx, vy, vw, vh);
5439           }
5440
5441         // 3. apply background transform
5442         matrix = e_util_transform_convert_to_matrix(&ec->transform_core.result.transform, &source_rect);
5443
5444         if (e_util_transform_bg_transform_flag_get(&ec->transform_core.result.transform))
5445           {
5446              boundary_matrix = e_util_transform_bg_convert_to_matrix(&ec->transform_core.result.transform, &source_rect);
5447              background = EINA_TRUE;
5448           }
5449         else
5450           {
5451              background = EINA_FALSE;
5452              boundary_matrix = matrix;
5453           }
5454
5455         if (background != ec->transform_core.background)
5456           {
5457              if (background)
5458                {
5459                   e_comp_object_transform_bg_set(ec->frame, EINA_TRUE);
5460                }
5461              else
5462                {
5463                   e_comp_object_transform_bg_set(ec->frame, EINA_FALSE);
5464                }
5465
5466              ec->transform_core.background = background;
5467           }
5468
5469         // 3.1 if 24bit window then set transp rect
5470         if (!ec->argb)
5471           {
5472              int angle = 0;
5473
5474              e_util_transform_rotation_round_get(&ec->transform_core.result.transform, 0, 0, &angle);
5475              angle %= 90;
5476
5477              if (angle == 0) // when transform angle is 0, 90, 180, 270, 360. then set transp rect
5478                e_comp_object_transform_transp_set(ec->frame, EINA_TRUE);
5479              else
5480                e_comp_object_transform_transp_set(ec->frame, EINA_FALSE);
5481           }
5482         else
5483           e_comp_object_transform_transp_set(ec->frame, EINA_FALSE);
5484
5485         // 3.5 parent matrix multiply
5486         if (ec->transform_core.parent.enable)
5487           {
5488              matrix = e_util_transform_matrix_multiply(&ec->transform_core.parent.matrix,
5489                                                        &matrix);
5490              boundary_matrix = e_util_transform_matrix_multiply(&ec->transform_core.parent.matrix,
5491                                                                 &boundary_matrix);
5492
5493              ec->transform_core.result.transform.use_zoom = EINA_TRUE;
5494              zoom.zoom_x *= ec->transform_core.parent.zoom.zoom_x;
5495              zoom.zoom_y *= ec->transform_core.parent.zoom.zoom_y;
5496              zoom.cx += ec->transform_core.parent.zoom.cx;
5497              zoom.cy += ec->transform_core.parent.zoom.cy;
5498           }
5499
5500         // 4. apply matrix to vertices
5501         ec->transform_core.result.matrix = matrix;
5502         ec->transform_core.result.inv_matrix = e_util_transform_matrix_inverse_get(&matrix);
5503         ec->transform_core.result.vertices = e_util_transform_rect_to_vertices(&source_rect);
5504         ec->transform_core.result.boundary.vertices = e_util_transform_rect_to_vertices(&source_rect);
5505         ec->transform_core.result.vertices = e_util_transform_matrix_multiply_rect_vertex(&matrix,
5506                                                                                           &ec->transform_core.result.vertices);
5507         ec->transform_core.result.boundary.vertices = e_util_transform_matrix_multiply_rect_vertex(&boundary_matrix,
5508                                                                                                    &ec->transform_core.result.boundary.vertices);
5509         ec->transform_core.result.transform.zoom = zoom;
5510
5511         // 5. apply vertices
5512         if (ec->transform_core.result.transform.use_zoom)
5513           {
5514              // TODO: apply zoom values to vertices
5515              e_comp_object_transform_transp_vertices_set_with_zoom(ec->frame, &ec->transform_core.result.vertices,
5516                                                                    ec->transform_core.result.transform.zoom);
5517              e_comp_object_transform_bg_vertices_set_with_zoom(ec->frame, &ec->transform_core.result.boundary.vertices,
5518                                                                ec->transform_core.result.transform.zoom);
5519              _e_client_transform_core_boundary_update(ec, &ec->transform_core.result.boundary.vertices);
5520              _e_client_transform_core_vertices_apply_with_zoom(ec, ec->frame, &ec->transform_core.result.vertices, &ec->transform_core.result.transform,
5521                                                                ec->transform_core.result.transform.zoom);
5522           }
5523         else
5524           {
5525              e_comp_object_transform_transp_vertices_set(ec->frame, &ec->transform_core.result.vertices);
5526              e_comp_object_transform_bg_vertices_set(ec->frame, &ec->transform_core.result.boundary.vertices);
5527              _e_client_transform_core_boundary_update(ec, &ec->transform_core.result.boundary.vertices);
5528              _e_client_transform_core_vertices_apply(ec, ec->frame, &ec->transform_core.result.vertices, &ec->transform_core.result.transform);
5529           }
5530
5531         // 6. subsurface update
5532         _e_client_transform_core_sub_update(ec, &ec->transform_core.result.vertices);
5533
5534         if (!e_object_is_del(E_OBJECT(ec)))
5535           {
5536              wl_signal_emit(&PRI(ec)->events.transform_change, NULL);
5537              _e_client_hook_call(E_CLIENT_HOOK_TRANSFORM_CHANGE, ec);
5538           }
5539      }
5540    else
5541      {
5542         if (ec->transform_core.result.enable)
5543           {
5544              ec->transform_core.result.enable = EINA_FALSE;
5545              _e_client_transform_core_vertices_apply(ec, ec->frame, NULL, NULL);
5546              e_comp_object_transform_bg_set(ec->frame, EINA_FALSE);
5547              ec->transform_core.background = EINA_FALSE;
5548              e_comp_object_transform_transp_set(ec->frame, EINA_FALSE);
5549              _e_client_transform_core_sub_update(ec, NULL);
5550
5551              if (!e_object_is_del(E_OBJECT(ec)))
5552                {
5553                   wl_signal_emit(&PRI(ec)->events.transform_change, NULL);
5554                   _e_client_hook_call(E_CLIENT_HOOK_TRANSFORM_CHANGE, ec);
5555                }
5556           }
5557      }
5558
5559    e_comp_visibility_calculation_set(EINA_TRUE);
5560 }
5561
5562 E_API int
5563 e_client_transform_core_transform_count_get(E_Client *ec)
5564 {
5565    if (!ec) return 0;
5566    if (!ec->transform_core.transform_list) return 0;
5567    return eina_list_count(ec->transform_core.transform_list);
5568 }
5569
5570 E_API E_Util_Transform*
5571 e_client_transform_core_transform_get(E_Client *ec, int index)
5572 {
5573    if (!ec) return NULL;
5574    if (!ec->transform_core.transform_list) return NULL;
5575    if (index < 0 || index >= e_client_transform_core_transform_count_get(ec))
5576       return NULL;
5577
5578    return (E_Util_Transform*)eina_list_nth(ec->transform_core.transform_list, index);
5579 }
5580
5581 E_API void
5582 e_client_transform_core_input_transform(E_Client *ec, int x, int y, int *out_x, int *out_y)
5583 {
5584    E_Util_Transform_Vertex vertex, result_vertex;
5585
5586    if (!ec) return;
5587    if (!e_client_transform_core_enable_get(ec)) return;
5588
5589    e_util_transform_vertex_init(&vertex, x, y, 0.0, 1.0);
5590
5591    result_vertex = e_util_transform_matrix_multiply_vertex(&ec->transform_core.result.inv_matrix, &vertex);
5592    e_util_transform_vertex_pos_round_get(&result_vertex, out_x, out_y, NULL, NULL);
5593 }
5594
5595 E_API void
5596 e_client_transform_core_input_inv_transform(E_Client *ec, int x, int y, int *out_x, int *out_y)
5597 {
5598    E_Util_Transform_Vertex vertex, result_vertex;
5599
5600    if (!ec) return;
5601    if (!e_client_transform_core_enable_get(ec)) return;
5602
5603    e_util_transform_vertex_init(&vertex, x, y, 0.0, 1.0);
5604
5605    result_vertex = e_util_transform_matrix_multiply_vertex(&ec->transform_core.result.matrix, &vertex);
5606    e_util_transform_vertex_pos_round_get(&result_vertex, out_x, out_y, NULL, NULL);
5607 }
5608
5609 EINTERN void
5610 e_client_transform_core_input_inv_rect_transform(E_Client *ec, int x, int y, int *out_x, int *out_y)
5611 {
5612    int gw = 0, gh = 0;
5613    if (!ec) return;
5614    if (!e_client_transform_core_enable_get(ec)) return;
5615    e_client_geometry_get(ec, NULL, NULL, &gw, &gh);
5616
5617    e_util_transform_matrix_inv_rect_coords_get(&ec->transform_core.result.transform,
5618                                                &ec->transform_core.result.vertices,
5619                                                gw, gh,
5620                                                x, y, out_x, out_y);
5621 }
5622
5623 E_API void
5624 e_client_transform_core_direct_render_set(E_Client *ec, Eina_Bool set)
5625 {
5626    EINA_SAFETY_ON_NULL_RETURN(ec);
5627
5628    if (ec->transform_core.direct_render == set) return;
5629
5630    ec->transform_core.direct_render = set;
5631    ec->transform_core.changed = EINA_TRUE;
5632
5633    e_client_transform_core_update(ec);
5634 }
5635
5636 EINTERN E_Pixmap *
5637 e_client_pixmap_change(E_Client *ec, E_Pixmap *newcp)
5638 {
5639    E_Pixmap_Type oldtype, newtype;
5640    E_Pixmap *oldcp;
5641
5642    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
5643    EINA_SAFETY_ON_NULL_RETURN_VAL(ec->pixmap, NULL);
5644    EINA_SAFETY_ON_NULL_RETURN_VAL(newcp, NULL);
5645
5646    oldcp = ec->pixmap;
5647
5648    oldtype = e_pixmap_type_get(oldcp);
5649    if (oldtype >= E_PIXMAP_TYPE_MAX) return NULL;
5650
5651    newtype = e_pixmap_type_get(newcp);
5652    if (newtype >= E_PIXMAP_TYPE_MAX) return NULL;
5653
5654    if (eina_hash_find(clients_hash[oldtype], &oldcp))
5655      eina_hash_del_by_key(clients_hash[oldtype], &oldcp);
5656    e_pixmap_client_set(oldcp, NULL);
5657
5658    ec->pixmap = newcp;
5659    e_pixmap_client_set(newcp, ec);
5660
5661    eina_hash_add(clients_hash[newtype], &newcp, ec);
5662
5663    return oldcp;
5664 }
5665
5666 E_API void
5667 e_client_window_role_set(E_Client *ec, const char *role)
5668 {
5669    EINA_SAFETY_ON_NULL_RETURN(ec);
5670
5671    if (eina_stringshare_replace(&ec->icccm.window_role, role))
5672      {
5673         wl_signal_emit(&PRI(ec)->events.window_role_change, NULL);
5674         _e_client_hook_call(E_CLIENT_HOOK_WINDOW_ROLE_CHANGE, ec);
5675      }
5676 }
5677
5678 EINTERN Eina_Bool
5679 e_client_key_send(E_Client *ec, int keycode, Eina_Bool pressed, Ecore_Device *dev, unsigned int time)
5680 {
5681    Eina_Bool res;
5682
5683    res = e_comp_wl_key_send(ec, keycode, pressed, dev, time);
5684
5685    return res;
5686 }
5687
5688 EINTERN Eina_Bool
5689 e_client_key_cancel(E_Client *ec, int keycode, Ecore_Device *dev, unsigned int time)
5690 {
5691    Eina_Bool res;
5692
5693    res = e_comp_wl_key_cancel(ec, keycode, dev, time);
5694
5695    return res;
5696 }
5697
5698 EINTERN Eina_Bool
5699 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)
5700 {
5701    Eina_Bool res;
5702
5703    res = e_comp_wl_touch_send(ec, idx, x, y, pressed, dev, radius_x, radius_y, pressure, angle, time);
5704
5705    return res;
5706 }
5707
5708 EINTERN Eina_Bool
5709 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)
5710 {
5711    Eina_Bool res;
5712
5713    res = e_comp_wl_touch_update_send(ec, idx, x, y, dev, radius_x, radius_y, pressure, angle, time);
5714
5715    return res;
5716 }
5717
5718 EINTERN Eina_Bool
5719 e_client_touch_cancel_send(E_Client *ec)
5720 {
5721    Eina_Bool res;
5722
5723    res = e_comp_wl_touch_cancel_send(ec);
5724
5725    return res;
5726 }
5727
5728 EINTERN Eina_Bool
5729 e_client_mouse_button_send(E_Client *ec, int buttons, Eina_Bool pressed, Ecore_Device *dev, unsigned int time)
5730 {
5731    Eina_Bool res;
5732
5733    res = e_comp_wl_mouse_button_send(ec, buttons, pressed, dev, time);
5734
5735    return res;
5736 }
5737
5738 EINTERN Eina_Bool
5739 e_client_mouse_move_send(E_Client *ec, int x, int y, Ecore_Device *dev, unsigned int time)
5740 {
5741    Eina_Bool res;
5742
5743    res = e_comp_wl_mouse_move_send(ec, x, y, dev, time);
5744
5745    return res;
5746 }
5747
5748 EINTERN Eina_Bool
5749 e_client_mouse_wheel_send(E_Client *ec, int direction, int z, Ecore_Device *dev, unsigned int time)
5750 {
5751    Eina_Bool res;
5752
5753    res = e_comp_wl_mouse_wheel_send(ec, direction, z, dev, time);
5754
5755    return res;
5756 }
5757
5758 EINTERN Eina_Bool
5759 e_client_mouse_in_send(E_Client *ec, int x, int y, Ecore_Device *dev, unsigned int time)
5760 {
5761    Eina_Bool res;
5762
5763    res = e_comp_wl_mouse_in_send(ec, x, y, dev, time);
5764
5765    return res;
5766 }
5767
5768 EINTERN Eina_Bool
5769 e_client_mouse_out_send(E_Client *ec, Ecore_Device *dev, unsigned int time)
5770 {
5771    Eina_Bool res;
5772
5773    res = e_comp_wl_mouse_out_send(ec, dev, time);
5774
5775    return res;
5776 }
5777
5778 E_API Eina_Bool
5779 e_client_video_client_has(E_Client *ec)
5780 {
5781    return e_comp_wl_video_subsurface_has(ec);
5782 }
5783
5784 E_API Eina_Bool
5785 e_client_normal_client_has(E_Client *ec)
5786 {
5787    return e_comp_wl_normal_subsurface_has(ec);
5788 }
5789
5790 E_API Eina_Bool
5791 e_client_cursor_hide(E_Client *ec)
5792 {
5793    return e_comp_wl_cursor_hide(ec);
5794 }
5795
5796 E_API void
5797 e_client_visibility_force_obscured_set(E_Client *ec, Eina_Bool set)
5798 {
5799    if (!ec) return;
5800
5801    ELOGF("TZVIS", "VIS_FORCE_OBSCURED :%d", ec, set);
5802
5803    ec->visibility.force_obscured = set;
5804    e_comp_visibility_calculation_set(EINA_TRUE);
5805 }
5806
5807 EINTERN E_Capture_Save_State
5808 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)
5809 {
5810    return e_comp_wl_capture_client_image_save(ec, dir, name, func_end, data, skip_child);
5811 }
5812
5813 static void
5814 _e_client_base_output_resolution_hook_subsurf_create(void *data, E_Client *subc)
5815 {
5816    E_Client *ec, *parent;
5817
5818    ec = data;
5819    if (ec != subc)
5820      return;
5821
5822    ec->base_output_resolution.use = 0;
5823    ec->base_output_resolution.w = 0;
5824    ec->base_output_resolution.h = 0;
5825    if (ec->base_output_resolution.transform)
5826      {
5827         e_client_transform_core_remove(ec, ec->base_output_resolution.transform);
5828         E_FREE_FUNC(ec->base_output_resolution.transform, e_util_transform_del);
5829         ELOGF("POL_APPINFO", "Cancel TRANSFORM for subsurface", ec);
5830      }
5831
5832    /* Update transform for toplevel surface.
5833     * The transform of subsurface will be updated by its parent accordingly. */
5834    parent = e_comp_wl_topmost_parent_get(ec);
5835    if (parent)
5836      {
5837         parent->transform_core.changed = EINA_TRUE;
5838         e_client_transform_core_update(parent);
5839      }
5840
5841    /* TODO: Do we need to apply it again if subsurface is destroyed? */
5842 }
5843
5844 static void
5845 _e_client_base_output_resolution_set(E_Client *ec, int width, int height)
5846 {
5847    if (!ec) return;
5848    ec->base_output_resolution.use = 1;
5849    ec->base_output_resolution.w = width;
5850    ec->base_output_resolution.h = height;
5851    ec->base_output_resolution.transform = e_util_transform_new();
5852    e_util_transform_role_set(ec->base_output_resolution.transform, "base_output_resolution");
5853    e_client_transform_core_add(ec, ec->base_output_resolution.transform);
5854
5855    if (!ec->base_output_resolution.hook_subsurf_create)
5856      {
5857         ec->base_output_resolution.hook_subsurf_create =
5858            e_comp_wl_hook_add(E_COMP_WL_HOOK_SUBSURFACE_CREATE,
5859                               _e_client_base_output_resolution_hook_subsurf_create,
5860                               ec);
5861      }
5862 }
5863
5864 E_API void
5865 e_client_base_output_resolution_transform_adjust(E_Client *ec)
5866 {
5867    E_Desk *desk;
5868
5869    EINA_SAFETY_ON_NULL_RETURN(ec);
5870    if (!ec->base_output_resolution.use) return;
5871    if (!ec->base_output_resolution.transform) return;
5872
5873    desk = e_comp_desk_find_by_ec(ec);
5874    EINA_SAFETY_ON_NULL_RETURN(desk);
5875
5876    ELOGF("POL_APPINFO", "Apply TRANSFORM... desk:(%dx%d), ec:(%dx%d)",
5877          ec, desk->geom.w, desk->geom.h, ec->w, ec->h);
5878
5879    e_util_transform_scale(ec->base_output_resolution.transform,
5880                           (double)desk->geom.w /(double)ec->base_output_resolution.w,
5881                           (double)desk->geom.h /(double)ec->base_output_resolution.h,
5882                           1.0);
5883    e_client_transform_core_update(ec);
5884 }
5885
5886 E_API Eina_Bool
5887 e_client_base_output_resolution_update(E_Client *ec)
5888 {
5889    E_Appinfo *eai = NULL;
5890    int configured_width, configured_height;
5891    int width, height;
5892    E_Desk *desk;
5893
5894    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
5895
5896   if (!e_config->configured_output_resolution.use) return EINA_TRUE;
5897   if (ec->base_output_resolution.use) return EINA_TRUE;
5898
5899   /* Check whether it's subsurface or not
5900    * The resolution of subsurface will follow the resolution of its toplevel surface.
5901    * Transform for subsurface will be applied when toplevel surface does by
5902    * implementation of e_client_transform_core.
5903    */
5904   if (e_comp_wl_subsurface_check(ec))
5905     return EINA_FALSE;
5906
5907    desk = e_comp_desk_find_by_ec(ec);
5908    EINA_SAFETY_ON_NULL_RETURN_VAL(desk, EINA_FALSE);
5909
5910   configured_width = e_config->configured_output_resolution.w;
5911   configured_height = e_config->configured_output_resolution.h;
5912
5913   if (!ec->netwm.pid)
5914     {
5915        ELOGF("POL_APPINFO", "NO PID... USE configured_output_resolution(%d,%d) pid:%d", ec,
5916              configured_width, configured_height, ec->netwm.pid);
5917        goto use_configured;
5918     }
5919
5920    eai = e_appinfo_find_with_pid(ec->netwm.pid);
5921    if (!eai)
5922      {
5923         ELOGF("POL_APPINFO", "NO APPINFO... USE configured_output_resolution(%d,%d) pid:%d", ec,
5924               configured_width, configured_height, ec->netwm.pid);
5925         goto use_configured;
5926      }
5927
5928    if (!e_appinfo_base_output_resolution_available_get(eai))
5929      {
5930         ELOGF("POL_APPINFO", "NO AVAILABLE BASE SCREEN RESOLUTION... QUERY base_output_resolution", ec);
5931         e_policy_base_output_resolution_info_update(ec->netwm.pid);
5932      }
5933
5934    if (!e_appinfo_base_output_resolution_get(eai, &width, &height))
5935      {
5936         ELOGF("POL_APPINFO", "NO BASE SCREEN RESOLUTION... USE configured_output_resolution(%d,%d) pid:%d", ec,
5937               configured_width, configured_height, ec->netwm.pid);
5938         goto use_configured;
5939       }
5940
5941    if ((width == 0) && (height == 0))
5942      {
5943         ELOGF("POL_APPINFO", "SKIP SET BASE SCREEN RESOLUTION... base_output_resolution size:(%d,%d) pid:%d", ec, width, height, ec->netwm.pid);
5944         return EINA_TRUE;
5945      }
5946
5947    if ((desk->geom.w == width) && (desk->geom.h == height))
5948      {
5949         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);
5950         return EINA_TRUE;
5951      }
5952
5953    /* set the base_output_resolution of the e_client */
5954    _e_client_base_output_resolution_set(ec, width, height);
5955
5956    ELOGF("POL_APPINFO", "USE base_output_resolution(%d,%d) pid:%d", ec, width, height, ec->netwm.pid);
5957
5958    return EINA_TRUE;
5959
5960 use_configured:
5961
5962    if ((desk->geom.w == configured_width) && (desk->geom.h == configured_height))
5963      {
5964         ELOGF("POL_APPINFO", "SKIP use configured_output_resolution (same with desk size:(%d,%d), pid:%d)", ec, configured_width, configured_height, ec->netwm.pid);
5965      }
5966    else
5967      {
5968         /* set the base_output_resolution of the e_client as a default */
5969         _e_client_base_output_resolution_set(ec, configured_width, configured_height);
5970      }
5971
5972    return EINA_TRUE;
5973 }
5974
5975 E_API Eina_Bool
5976 e_client_base_output_resolution_useful_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
5977 {
5978    int zx, zy, zw, zh;
5979    E_Zone *zone;
5980
5981    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
5982
5983    zone = e_comp_zone_find_by_ec(ec);
5984    EINA_SAFETY_ON_NULL_RETURN_VAL(zone, EINA_FALSE);
5985
5986    e_zone_useful_geometry_get(zone, &zx, &zy, &zw, &zh);
5987
5988    if (x) *x = zx;
5989    if (y) *y = zy;
5990    if (w) *w = zw;
5991    if (h) *h = zh;
5992
5993    if (ec->base_output_resolution.use)
5994      {
5995         if (w) *w = ec->base_output_resolution.w;
5996         if (h) *h = ec->base_output_resolution.h;
5997      }
5998
5999    return EINA_TRUE;
6000 }
6001
6002 E_API Eina_Bool
6003 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)
6004 {
6005    int zx, zy, zw, zh;
6006    E_Zone *zone;
6007
6008    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
6009
6010    zone = e_comp_zone_find_by_ec(ec);
6011    EINA_SAFETY_ON_NULL_RETURN_VAL(zone, EINA_FALSE);
6012
6013    e_zone_desk_useful_geometry_get(zone, ec->desk, &zx, &zy, &zw, &zh, consider_obstacle_area);
6014
6015    if (x) *x = zx;
6016    if (y) *y = zy;
6017    if (w) *w = zw;
6018    if (h) *h = zh;
6019
6020    if (ec->base_output_resolution.use)
6021      {
6022         // TODO: Consider obstacle area
6023         if (w) *w = ec->base_output_resolution.w;
6024         if (h) *h = ec->base_output_resolution.h;
6025      }
6026
6027    return EINA_TRUE;
6028 }
6029
6030 /* change the base_output_resolution of the bind_ec by checking the base_output_resolution of provider_ec's appinfo */
6031 EINTERN Eina_Bool
6032 e_client_base_output_resolution_rsm_update(E_Client *bind_ec, E_Client *provider_ec)
6033 {
6034    E_Appinfo *epai = NULL;
6035    int configured_width, configured_height;
6036    int width, height;
6037    E_Desk *bind_ec_desk;
6038
6039    EINA_SAFETY_ON_NULL_RETURN_VAL(bind_ec, EINA_FALSE);
6040    EINA_SAFETY_ON_NULL_RETURN_VAL(provider_ec, EINA_FALSE);
6041
6042    bind_ec_desk = e_comp_desk_find_by_ec(bind_ec);
6043    EINA_SAFETY_ON_NULL_RETURN_VAL(bind_ec_desk, EINA_FALSE);
6044
6045   if (!e_config->configured_output_resolution.use) return EINA_TRUE;
6046
6047   configured_width = e_config->configured_output_resolution.w;
6048   configured_height = e_config->configured_output_resolution.h;
6049
6050   if (bind_ec->base_output_resolution.use)
6051     {
6052        ELOGF("POL_APPINFO", "DELETE EXISTED BINDER BASE SCREEN RESOLUTION... base_output_resolution is same with desk size:(%d,%d), bind_pid:%d", bind_ec,
6053              bind_ec->base_output_resolution.w, bind_ec->base_output_resolution.h, bind_ec->netwm.pid);
6054
6055        bind_ec->base_output_resolution.use = 0;
6056        bind_ec->base_output_resolution.w = 0;
6057        bind_ec->base_output_resolution.h = 0;
6058        e_client_transform_core_remove(bind_ec, bind_ec->base_output_resolution.transform);
6059        E_FREE_FUNC(bind_ec->base_output_resolution.transform, e_util_transform_del);
6060     }
6061
6062   if (!provider_ec->netwm.pid)
6063     {
6064        ELOGF("POL_APPINFO", "NO PROVIDER PID... USE configured_output_resolution(%d,%d) provider_pid:%d", provider_ec,
6065              configured_width, configured_height, provider_ec->netwm.pid);
6066        goto use_configured;
6067     }
6068
6069    epai = e_appinfo_find_with_pid(provider_ec->netwm.pid);
6070    if (!epai)
6071      {
6072         ELOGF("POL_APPINFO", "NO PROVIDER APPINFO... USE configured_output_resolution(%d,%d) provider_pid:%d", provider_ec,
6073               configured_width, configured_height, provider_ec->netwm.pid);
6074         goto use_configured;
6075      }
6076
6077    if (!e_appinfo_base_output_resolution_get(epai, &width, &height))
6078      {
6079         ELOGF("POL_APPINFO", "NO PROVIDER APPINFO BASE SCREEN RESOLUTION... USE configured_output_resolution(%d,%d) provider_pid:%d", provider_ec,
6080               configured_width, configured_height, provider_ec->netwm.pid);
6081         goto use_configured;
6082       }
6083
6084    if ((width == 0) && (height == 0))
6085      {
6086         ELOGF("POL_APPINFO", "NO PROVIDER WIDTH and HEIGHT... SKIP base_output_resolution due to size:(%d,%d) provider_pid:%d", provider_ec,
6087              width, height, provider_ec->netwm.pid);
6088         return EINA_TRUE;
6089      }
6090
6091    if ((bind_ec_desk->geom.w == width) && (bind_ec_desk->geom.h == height))
6092      {
6093         ELOGF("POL_APPINFO", "SKIP SET BINDER BASE SCREEN RESOLUTION... base_output_resolution is same with desk size:(%d,%d), bind_pid:%d", bind_ec,
6094             width, height, bind_ec->netwm.pid);
6095         return EINA_TRUE;
6096      }
6097
6098    /* set the base_output_resolution of the e_client */
6099    _e_client_base_output_resolution_set(bind_ec, width, height);
6100    e_client_base_output_resolution_transform_adjust(bind_ec);
6101
6102    ELOGF("POL_APPINFO", "USE BINDER base_output_resolution(%d,%d) bind_pid:%d", bind_ec, width, height, bind_ec->netwm.pid);
6103
6104    return EINA_TRUE;
6105
6106 use_configured:
6107
6108    if ((bind_ec_desk->geom.w == configured_width) && (bind_ec_desk->geom.h == configured_height))
6109      {
6110         ELOGF("POL_APPINFO", "SKIP BINDER use configured_output_resolution (same with desk size:(%d,%d), bind_pid:%d)", bind_ec,
6111              configured_width, configured_height, bind_ec->netwm.pid);
6112      }
6113    else
6114      {
6115         /* set the base_output_resolution of the e_client as a default */
6116         _e_client_base_output_resolution_set(bind_ec, configured_width, configured_height);
6117      }
6118
6119    return EINA_TRUE;
6120 }
6121
6122 /* tizen_move_resize */
6123 EINTERN Eina_Bool
6124 e_client_pending_geometry_has(E_Client *ec)
6125 {
6126    if (!eina_list_count(ec->surface_sync.pending_geometry))
6127      return EINA_FALSE;
6128
6129    return ec->surface_sync.wait_commit;
6130 }
6131
6132 EINTERN void
6133 e_client_pending_geometry_flush(E_Client *ec)
6134 {
6135    E_Client_Pending_Geometry *geo;
6136
6137    if (!eina_list_count(ec->surface_sync.pending_geometry))
6138      {
6139         EINA_LIST_FREE(ec->surface_sync.pending_geometry, geo)
6140           {
6141              E_FREE(geo);
6142           }
6143         ec->surface_sync.wait_commit = EINA_FALSE;
6144         ELOGF("POSSIZE", "pending geometry has flushed", ec);
6145      }
6146 }
6147
6148 EINTERN void
6149 e_client_pending_geometry_last_geometry_get(E_Client *ec, int *x, int *y, int *w, int *h)
6150 {
6151    Eina_List *l;
6152    E_Client_Pending_Geometry *geo;
6153    int gx = 0;
6154    int gy = 0;
6155    int gw = 0;
6156    int gh = 0;
6157
6158    EINA_LIST_REVERSE_FOREACH(ec->surface_sync.pending_geometry, l, geo)
6159      {
6160         gx = geo->x;
6161         gy = geo->y;
6162         gw = geo->w;
6163         gh = geo->h;
6164         break;
6165      }
6166
6167    if (x) *x = gx;
6168    if (y) *y = gy;
6169    if (w) *w = gw;
6170    if (h) *h = gh;
6171 }
6172
6173 E_API void
6174 e_client_frame_focus_set(E_Client *ec, Eina_Bool focus)
6175 {
6176    if (!ec) return;
6177    evas_object_focus_set(ec->frame, focus);
6178 }
6179
6180 EINTERN void
6181 e_client_frame_geometry_set(E_Client *ec, int x, int y, int w, int h)
6182 {
6183    if (!ec) return;
6184
6185    if (ec->internal || ec->input_only)
6186      {
6187         evas_object_geometry_set(ec->frame, x, y, w, h);
6188      }
6189    else
6190      {
6191         if ((ec->w != w) || (ec->h != h))
6192           {
6193              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);
6194              ec->move_after_resize = EINA_TRUE;
6195
6196              e_client_pos_set(ec, x, y);
6197              evas_object_resize(ec->frame, w, h);
6198           }
6199         else
6200           evas_object_geometry_set(ec->frame, x, y, w, h);
6201      }
6202 }
6203
6204 EAPI void
6205 e_client_util_move_resize_without_frame(E_Client *ec, int x, int y, int w, int h)
6206 {
6207    if (!ec) return;
6208
6209    if (ec->internal || ec->input_only)
6210      {
6211         e_client_util_move_without_frame(ec, x, y);
6212         e_client_util_resize_without_frame(ec, w, h);
6213      }
6214    else
6215      {
6216         if ((ec->w != w) || (ec->h != h))
6217           {
6218              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);
6219              ec->move_after_resize = EINA_TRUE;
6220
6221              e_comp_object_frame_xy_adjust(ec->frame, x, y, &x, &y);
6222              e_client_pos_set(ec, x, y);
6223              e_client_util_resize_without_frame(ec, w, h);
6224           }
6225         else
6226           {
6227              e_client_util_move_without_frame(ec, x, y);
6228              e_client_util_resize_without_frame(ec, w, h);
6229           }
6230      }
6231 }
6232
6233 static void
6234 _e_input_thread_client_layer_set(void *data)
6235 {
6236    E_Input_Thread_Request_EClient_Data *ec_data = data;
6237    EINA_SAFETY_ON_NULL_RETURN(ec_data);
6238
6239    INF("[input thread|%s] ec(%p), layer(%d)\n", __func__, ec_data->ec, ec_data->layer);
6240    e_input_thread_client_layer_set(e_input_thread_client_get(ec_data->ec), ec_data->layer);
6241 }
6242
6243 EINTERN void
6244 e_client_input_thread_layer_set(E_Client *ec, E_Layer layer)
6245 {
6246    EINA_SAFETY_ON_NULL_RETURN(ec);
6247
6248    E_Input_Thread_Request_EClient_Data ec_data;
6249    memset(&ec_data, 0, sizeof(E_Input_Thread_Request_EClient_Data));
6250
6251    ec_data.ec = ec;
6252    ec_data.layer = layer;
6253
6254    INF("[%s] ec(%p), layer(%d)\n", __func__, ec, layer);
6255    e_input_thread_safe_call(_e_input_thread_client_layer_set, &ec_data, sizeof(E_Input_Thread_Request_EClient_Data));
6256 }
6257
6258 E_API Eina_Bool
6259 e_client_layer_set(E_Client *ec,
6260                    E_Layer layer)
6261 {
6262    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
6263    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, EINA_FALSE);
6264    if (!ec->frame) return EINA_FALSE;
6265
6266    if (e_comp_canvas_client_layer_map(layer) == 9999)
6267      return EINA_FALSE; //invalid layer is not allowed
6268
6269 #ifdef REFACTOR_DESK_AREA
6270 #else
6271    if (ec->desk_area.enable)
6272      {
6273         if (e_client_layer_set_by_desk_area(ec, layer))
6274           {
6275              // restack according to desk group rule
6276              e_desk_area_ec_rearrange(ec->desk_area.desk_area, ec);
6277              return EINA_TRUE;
6278           }
6279      }
6280    ec->desk_area.layer_backup = layer;
6281 #endif
6282
6283    evas_object_layer_set(ec->frame, layer);
6284    if (ec->layer != layer)
6285      {
6286         /* check exceptional case */
6287         if ((ec->fullscreen) &&
6288             (ec->saved.layer != layer))
6289           {
6290              ELOGF("LAYER", "(%d) fail to backup at saved.layer for fullscreen", ec, layer);
6291              return EINA_FALSE;
6292           }
6293         // if e_comp_object fail to change ec->layer due to ec->layer_pending or block
6294         // leave log and apply ec->layer according to set
6295         // as a result it restores back to given layer when pending or block is free
6296         ELOGF("LAYER", "change layer from %d to %d if in case layer pending(%d) or block(%d)",
6297               ec, ec->layer, layer, ec->layer_pending, ec->layer_block);
6298         if (ec->layer_pending || ec->layer_block)
6299           {
6300              ec->layer = layer;
6301              e_client_input_thread_layer_set(ec, layer);
6302              return EINA_TRUE;
6303           }
6304      }
6305
6306    wl_signal_emit(&PRI(ec)->events.set_layer, NULL);
6307
6308    return EINA_TRUE;
6309 }
6310
6311 E_API E_Layer
6312 e_client_layer_get(E_Client *ec)
6313 {
6314    short layer;
6315
6316    E_OBJECT_CHECK_RETURN(ec, E_LAYER_BOTTOM);
6317    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, E_LAYER_BOTTOM);
6318    if (!ec->frame) return E_LAYER_BOTTOM;
6319
6320    layer = evas_object_layer_get(ec->frame);
6321    if (ec->layer != layer)
6322      {
6323         /* client could be on temperory layer while pending or block,
6324          * in that case, client restores back to ec->layer after pending/block finish */
6325         if (ec->layer_block || ec->layer_pending)
6326           return ec->layer;
6327
6328         /* otherwise, client is on unexpected layer */
6329         ELOGF("LAYER", "layer dismatch ec->layer %d | evas obj layer %d ",
6330               ec, ec->layer, layer);
6331
6332         if (e_comp_canvas_client_layer_map(layer) == 9999)
6333           return E_LAYER_BOTTOM; //not on E_LAYER_CLIENT
6334      }
6335
6336    return ec->layer;
6337 }
6338
6339 #ifdef REFACTOR_DESK_AREA
6340 #else
6341 static void
6342 _e_client_desk_area_original_layer_save(E_Client *ec, E_Layer layer)
6343 {
6344    E_OBJECT_CHECK(ec);
6345    E_OBJECT_TYPE_CHECK(ec, E_CLIENT_TYPE);
6346    ec->desk_area.layer_backup = layer;
6347 }
6348
6349 EINTERN Eina_Bool
6350 e_client_layer_set_by_desk_area(E_Client *ec, E_Layer layer)
6351 {
6352    E_Desk_Area *eda;
6353    E_Layer edg_layer;
6354    E_Layer org_layer;
6355
6356    if (!ec) return EINA_FALSE;
6357    if (!ec->frame) return EINA_FALSE;
6358    if (!ec->desk_area.enable) return EINA_FALSE;
6359    if (!ec->desk_area.desk_area) return EINA_FALSE;
6360
6361    eda = ec->desk_area.desk_area;
6362
6363    // save original layer
6364    _e_client_desk_area_original_layer_save(ec, layer);
6365
6366    // get desk_area layer
6367    edg_layer = (E_Layer)e_desk_area_layer_get(eda);
6368    org_layer = e_client_desk_area_original_layer_get(ec);
6369
6370    ELOGF("EDG", "layer_set by desk_area... layer:%d, org_layer:%d, new_layer:%d", ec, layer, org_layer, edg_layer);
6371    if (org_layer == edg_layer)
6372      {
6373         e_client_raise(ec);
6374      }
6375    else
6376      {
6377         evas_object_layer_set(ec->frame, edg_layer);
6378         if (edg_layer == ec->layer)
6379           e_client_raise(ec);
6380      }
6381
6382    return EINA_TRUE;
6383 }
6384
6385 EINTERN void
6386 e_client_desk_area_original_layer_restore(E_Client *ec)
6387 {
6388    if (!ec) return;
6389
6390    // Do we need to check ec->desk_area.enable?
6391    // if ec->desk_area.enable is true, then e_client_layer_set calls
6392    // e_desk_area_ec_edg_layer_set(). that's too bad. :(
6393    // so, we MUST make a policy for ordering of the desk group layer restore
6394    // and the desk group enable.
6395    if (ec->desk_area.enable) return;
6396    e_client_layer_set(ec, ec->desk_area.layer_backup);
6397 }
6398
6399 EINTERN E_Layer
6400 e_client_desk_area_original_layer_get(E_Client *ec)
6401 {
6402    if (!ec) return E_LAYER_DESKTOP;
6403
6404    if (ec->desk_area.enable)
6405      return ec->desk_area.layer_backup;
6406    else
6407      return ec->layer;
6408 }
6409
6410 EINTERN Eina_Bool
6411 e_client_desk_area_client_layer_set(E_Client *ec, E_Desk_Area_Client_Layer edgc_layer)
6412 {
6413    E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
6414    E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, EINA_FALSE);
6415    if ((edgc_layer < E_DESK_AREA_CLIENT_LAYER_DESKTOP) ||
6416        (edgc_layer >= E_DESK_AREA_CLIENT_LAYER_MAX))
6417      return EINA_FALSE;
6418
6419    ec->desk_area.edgc_layer = edgc_layer;
6420    return EINA_TRUE;
6421 }
6422
6423 EINTERN E_Desk_Area_Client_Layer
6424 e_client_desk_area_client_layer_get(E_Client *ec)
6425 {
6426    E_OBJECT_CHECK_RETURN(ec, E_DESK_AREA_CLIENT_LAYER_DESKTOP);
6427
6428    return ec->desk_area.edgc_layer;
6429 }
6430
6431 //FIXME: use e_desk_area_ec_reassign(eda, ec) instead of this api
6432 E_API Eina_Bool
6433 e_client_desk_area_set(E_Client *ec, E_Desk_Area *eda)
6434 {
6435    E_Desk_Area *old_edg;
6436
6437    if (!ec) return EINA_FALSE;
6438
6439 #if 0 // if this is removed.. then below if (eda != old_edg) is removed also...
6440    if (ec->desk_area.desk_area == eda)
6441      return EINA_TRUE;
6442 #endif
6443
6444    ELOGF("EDG", "Desk Group Set (new:%p, old:%p)", ec, eda, ec->desk_area.desk_area);
6445    old_edg = ec->desk_area.desk_area;
6446    if (old_edg)
6447      e_desk_area_ec_remove(old_edg, ec);
6448
6449    ec->desk_area.desk_area = eda;
6450    e_desk_area_ec_add(eda, ec);
6451
6452 #if 0 // if this is removed.. then above if (ec->desk_area.desk_area == eda) is removed also...
6453    if (eda != old_edg)
6454 #endif
6455      {
6456         e_desk_area_ec_update(eda, ec);
6457         e_desk_area_ec_rearrange(ec->desk_area.desk_area, ec);
6458      }
6459
6460    return EINA_TRUE;
6461 }
6462 #endif
6463
6464 static void
6465 _raise_between_sibling_under_parent(E_Client *ec)
6466 {
6467    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);
6468    e_client_stack_below(ec, ec->parent);
6469 }
6470
6471 static void
6472 _raise_between_sibling_on_parent(E_Client *ec)
6473 {
6474    E_Client *top_child = NULL;
6475    top_child = e_client_transient_child_top_get(ec->parent, EINA_FALSE);
6476    if (!top_child)
6477      {
6478         ELOGF("POL", "RAISE child window... Stack above on the parent (win:%zx, ec:%p)", ec, e_client_util_win_get(ec->parent), ec->parent);
6479         e_client_stack_above(ec, ec->parent);
6480      }
6481    else
6482      {
6483         if (top_child != ec)
6484           {
6485              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);
6486              e_client_stack_above(ec, top_child);
6487           }
6488         else
6489           ELOGF("POL", "RAISE child window between sibling... already on the top. STAY", ec);
6490      }
6491 }
6492
6493 static void
6494 _raise_belong_to_parent(E_Client *ec)
6495 {
6496    if (e_client_transient_policy_get(ec) == E_TRANSIENT_BELOW)
6497      _raise_between_sibling_under_parent(ec);
6498    else
6499      _raise_between_sibling_on_parent(ec);
6500 }
6501
6502 E_API void
6503 e_client_raise(E_Client *ec)
6504 {
6505    if (!ec) return;
6506
6507 #ifdef REFACTOR_DESK_AREA
6508 #else
6509    if (ec->desk_area.enable)
6510      {
6511         E_Desk_Area *eda;
6512         eda = ec->desk_area.desk_area;
6513         if (eda)
6514           {
6515              e_desk_area_ec_raise(eda, ec);
6516              return;
6517           }
6518      }
6519 #endif
6520
6521    if (ec->parent && e_client_is_belong_to_parent(ec))
6522      _raise_belong_to_parent(ec);
6523    else
6524      evas_object_raise(ec->frame);
6525
6526    wl_signal_emit(&PRI(ec)->events.raise, NULL);
6527 }
6528
6529 static void
6530 _e_client_transient_for_below_group_make(E_Client *ec, Eina_List **list)
6531 {
6532    // list : Head is the bottommost child
6533    E_Client *child;
6534    Eina_List *l;
6535
6536    if (!ec) return;
6537
6538    EINA_LIST_REVERSE_FOREACH(ec->transients, l, child)
6539      {
6540         if (!child) continue;
6541         if (e_client_transient_policy_get(child) != E_TRANSIENT_BELOW) continue;
6542         if (!e_client_is_belong_to_parent(child)) continue;
6543
6544         *list = eina_list_prepend(*list, child);
6545         _e_client_transient_for_group_make(child, list);
6546      }
6547 }
6548
6549 E_API E_Client *
6550 e_client_transient_child_bottom_get(E_Client *ec)
6551 {
6552    E_Client *bottom_ec = NULL;
6553    Eina_List *transient_below_list = NULL;
6554    Eina_List *l = NULL;
6555
6556    _e_client_transient_for_below_group_make(ec, &transient_below_list);
6557
6558    if (transient_below_list)
6559      {
6560         E_Client *temp_ec = NULL;
6561         E_Client *temp_ec2 = NULL;
6562
6563         E_CLIENT_FOREACH(temp_ec)
6564           {
6565              if (bottom_ec) break;
6566
6567              if (temp_ec == ec)
6568                {
6569                   bottom_ec = ec;
6570                   break;
6571                }
6572
6573              EINA_LIST_FOREACH(transient_below_list, l, temp_ec2)
6574                {
6575                   if (temp_ec == temp_ec2)
6576                     {
6577                        bottom_ec = temp_ec2;
6578                        break;
6579                     }
6580                }
6581           }
6582         eina_list_free(transient_below_list);
6583      }
6584    return bottom_ec;
6585 }
6586
6587 static void
6588 _lower_between_sibling_under_parent(E_Client *ec)
6589 {
6590    E_Client *bottom_child = NULL;
6591    bottom_child = e_client_transient_child_bottom_get(ec->parent);
6592    if (!bottom_child)
6593      {
6594         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);
6595         e_client_stack_below(ec, ec->parent);
6596      }
6597    else
6598      {
6599         if (bottom_child != ec)
6600           {
6601              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);
6602              e_client_stack_below(ec, bottom_child);
6603           }
6604         else
6605           ELOGF("POL", "LOWER child window between sibling... already under the bottom. STAY", ec);
6606      }
6607 }
6608
6609 static void
6610 _lower_between_sibling_on_parent(E_Client *ec)
6611 {
6612    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);
6613    e_client_stack_above(ec, ec->parent);
6614 }
6615
6616 static void
6617 _lower_belong_to_parent(E_Client *ec)
6618 {
6619    if (e_client_transient_policy_get(ec) == E_TRANSIENT_BELOW)
6620      _lower_between_sibling_under_parent(ec);
6621    else
6622      _lower_between_sibling_on_parent(ec);
6623 }
6624
6625 E_API void
6626 e_client_lower(E_Client *ec)
6627 {
6628    if (!ec) return;
6629
6630 #ifdef REFACTOR_DESK_AREA
6631 #else
6632    if (ec->desk_area.enable)
6633      {
6634         E_Desk_Area *eda;
6635         eda = ec->desk_area.desk_area;
6636         if (eda)
6637           {
6638              e_desk_area_ec_lower(eda, ec);
6639
6640              wl_signal_emit(&PRI(ec)->events.lower, NULL);
6641              return;
6642           }
6643      }
6644 #endif
6645
6646    if (ec->parent && e_client_is_belong_to_parent(ec))
6647      _lower_belong_to_parent(ec);
6648    else
6649      evas_object_lower(ec->frame);
6650
6651    wl_signal_emit(&PRI(ec)->events.lower, NULL);
6652 }
6653
6654 E_API void
6655 e_client_stack_above(E_Client *ec, E_Client *above)
6656 {
6657    if (!ec) return;
6658    if (!ec->frame) return;
6659    if (!above) return;
6660    if (!above->frame) return;
6661
6662 #ifdef REFACTOR_DESK_AREA
6663 #else
6664    if (ec->desk_area.enable)
6665      {
6666         E_Desk_Area *eda;
6667         eda = ec->desk_area.desk_area;
6668         if (eda)
6669           {
6670              e_desk_area_ec_stack_above(eda, ec, above);
6671              return;
6672           }
6673      }
6674 #endif
6675
6676    evas_object_stack_above(ec->frame, above->frame);
6677
6678    wl_signal_emit(&PRI(ec)->events.stack_above, NULL);
6679 }
6680
6681 E_API void
6682 e_client_stack_below(E_Client *ec, E_Client *below)
6683 {
6684    if (!ec) return;
6685    if (!ec->frame) return;
6686    if (!below) return;
6687    if (!below->frame) return;
6688
6689 #ifdef REFACTOR_DESK_AREA
6690 #else
6691    if (ec->desk_area.enable)
6692      {
6693         E_Desk_Area *eda;
6694         eda = ec->desk_area.desk_area;
6695         if (eda)
6696           {
6697              e_desk_area_ec_stack_below(eda, ec, below);
6698              return;
6699           }
6700      }
6701 #endif
6702
6703    evas_object_stack_below(ec->frame, below->frame);
6704
6705    wl_signal_emit(&PRI(ec)->events.stack_below, NULL);
6706 }
6707
6708 E_API int
6709 e_client_show_pending_set(E_Client *ec)
6710 {
6711    if (!ec) return 0;
6712
6713    ec->show_pending.count++;
6714    ELOGF("E_CLIENT", "SET show_pending. (count:%d, run:%d)", ec, ec->show_pending.count, ec->show_pending.running);
6715    return ec->show_pending.count;
6716 }
6717
6718 E_API int
6719 e_client_show_pending_unset(E_Client *ec)
6720 {
6721    if (!ec) return 0;
6722    if (ec->show_pending.count <= 0) return 0;
6723
6724    ec->show_pending.count--;
6725    ELOGF("E_CLIENT", "UNSET show_pending. (count:%d, run:%d)", ec, ec->show_pending.count, ec->show_pending.running);
6726    if (ec->show_pending.count == 0 && ec->show_pending.running)
6727      {
6728         ec->show_pending.running = EINA_FALSE;
6729         if (ec->frame)
6730           {
6731              ELOGF("E_CLIENT", "evas_object_show by unset show_pending", ec);
6732              evas_object_show(ec->frame);
6733              //e_comp_object_damage(ec->frame, 0, 0, ec->w, ec->h);
6734              EC_CHANGED(ec);
6735           }
6736      }
6737
6738    return ec->show_pending.count;
6739 }
6740
6741 static Eina_Bool
6742 _e_client_surface_tree_foreach_helper(E_Client *ec, E_Client_Surface_Tree_Foreach func, void *data)
6743 {
6744    E_Client *subc;
6745    Eina_List *l, *ll;
6746    Eina_Bool res = EINA_TRUE;
6747    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
6748
6749    if (!cdata)
6750      return res;
6751
6752    EINA_LIST_FOREACH_SAFE(cdata->sub.below_list, l, ll, subc)
6753      {
6754         res = _e_client_surface_tree_foreach_helper(subc, func, data);
6755         if (!res)
6756           break;
6757      }
6758
6759    if (res)
6760      {
6761         res = func(data, ec);
6762         if (res)
6763           {
6764              EINA_LIST_FOREACH_SAFE(cdata->sub.list, l, ll, subc)
6765                {
6766                   res = _e_client_surface_tree_foreach_helper(subc,
6767                                                               func,
6768                                                               data);
6769                   if (!res)
6770                     break;
6771                }
6772           }
6773      }
6774
6775    return res;
6776 }
6777
6778 E_API void
6779 e_client_surface_tree_foreach(E_Client *ec, E_Client_Surface_Tree_Foreach func, void *data)
6780 {
6781    EINA_SAFETY_ON_NULL_RETURN(ec);
6782    EINA_SAFETY_ON_NULL_RETURN(func);
6783
6784    _e_client_surface_tree_foreach_helper(ec, func, data);
6785 }
6786
6787 EINTERN E_Comp_Wl_Client_Data *
6788 e_client_cdata_new(E_Client *ec)
6789 {
6790    E_Comp_Wl_Client_Data *cdata;
6791
6792    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
6793
6794    if (!(cdata = E_NEW(E_Comp_Wl_Client_Data, 1)))
6795      {
6796         ERR("Could not allocate new E_Comp_Wl_Client_Data structure");
6797         return NULL;
6798      }
6799    ec->comp_data = cdata;
6800
6801    return cdata;
6802 }
6803
6804 EINTERN void
6805 e_client_cdata_free(E_Client *ec)
6806 {
6807   EINA_SAFETY_ON_NULL_RETURN(ec);
6808   if (!ec->comp_data) return;
6809
6810   E_FREE(ec->comp_data);
6811 }
6812
6813 EINTERN E_Comp_Wl_Client_Data *
6814 e_client_cdata_get(E_Client *ec)
6815 {
6816    if (!ec) return NULL;
6817
6818    return ec->comp_data;
6819 }
6820
6821 EINTERN Eina_Bool
6822 e_client_map_set(E_Client *ec, E_Map *em)
6823 {
6824    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6825
6826    return e_map_set_to_comp_object(em, ec->frame);
6827 }
6828
6829 E_API E_Map *
6830 e_client_map_get(const E_Client *ec)
6831 {
6832    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
6833
6834    return e_map_get_from_comp_object(ec->frame);
6835 }
6836
6837 EINTERN Eina_Bool
6838 e_client_map_enable_set(E_Client *ec, Eina_Bool enable)
6839 {
6840    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6841    EINA_SAFETY_ON_NULL_RETURN_VAL(ec->frame, EINA_FALSE);
6842
6843    evas_object_map_enable_set(ec->frame, enable);
6844
6845    return EINA_TRUE;
6846 }
6847
6848 EINTERN void
6849 e_client_belong_to_parent_set(E_Client *ec, Eina_Bool set)
6850 {
6851    if (!ec) return;
6852    ec->belong_to_parent = set;
6853 }
6854
6855 EINTERN Eina_Bool
6856 e_client_is_belong_to_parent(E_Client *ec)
6857 {
6858    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6859    return ec->belong_to_parent;
6860 }
6861
6862 EINTERN void
6863 e_client_transient_policy_set(E_Client *ec, E_Transient policy)
6864 {
6865    if (!ec) return;
6866    ec->transient_policy = policy;
6867 }
6868
6869 E_API E_Transient
6870 e_client_transient_policy_get(E_Client *ec)
6871 {
6872    if (!ec) return E_TRANSIENT_ABOVE;
6873    return ec->transient_policy;
6874 }
6875
6876 EINTERN void
6877 e_client_resize_object_create_cb_set(E_Client_Resize_Object_Create_Cb cb)
6878 {
6879    if (_e_client_resize_object_create_cb && cb)
6880      CRI("ATTEMPTING TO OVERWRITE EXISTING CLIENT RESIZE OBJECT CREATE HOOK!!!");
6881    _e_client_resize_object_create_cb = cb;
6882 }
6883
6884 EINTERN void
6885 e_client_resize_unit_size_set(E_Client *ec, unsigned int unit_size)
6886 {
6887    if (!ec) return;
6888
6889    // FYI, we consider 0 and 1 to be the same value as a default unit size.
6890    ec->manage_resize.unit_size = unit_size;
6891 }
6892
6893 EINTERN void
6894 e_client_desk_zoom_enable_set(E_Client *ec, Eina_Bool enable)
6895 {
6896    if (!ec) return;
6897    ec->desk_zoom.enable = enable;
6898 }
6899
6900 EINTERN Eina_Bool
6901 e_client_desk_zoom_enable_get(E_Client *ec)
6902 {
6903    if (!ec) return EINA_FALSE;
6904    return ec->desk_zoom.enable;
6905 }
6906
6907 EINTERN void
6908 e_client_layout_apply(E_Client *ec, Eina_Bool apply)
6909 {
6910    if (!ec) return;
6911    ec->apply_layout = apply;
6912 }
6913
6914 EINTERN Eina_Bool
6915 e_client_is_layout_apply(E_Client *ec)
6916 {
6917    if (!ec) return EINA_FALSE;
6918    return ec->apply_layout;
6919 }
6920
6921 E_API E_Client *
6922 e_client_from_surface_resource(struct wl_resource *surface_resource)
6923 {
6924    EINA_SAFETY_ON_NULL_RETURN_VAL(surface_resource, NULL);
6925
6926    return e_comp_wl_util_client_from_surface_resource(surface_resource);
6927 }
6928
6929 EINTERN void
6930 e_client_fps_update(E_Client *ec)
6931 {
6932    double dt;
6933    double tim;
6934
6935    EINA_SAFETY_ON_NULL_RETURN(ec);
6936
6937    if (!ec->fps.enabled) return;
6938
6939    tim = ecore_time_get();
6940
6941    dt = tim - ec->fps.frametimes[0];
6942
6943    ec->fps.frametimes[0] = tim;
6944    ec->fps.time += dt;
6945    ec->fps.cframes++;
6946
6947    if (ec->fps.lapse == 0.0)
6948      {
6949         ec->fps.lapse = tim;
6950         ec->fps.flapse = ec->fps.cframes;
6951      }
6952    else if ((tim - ec->fps.lapse) >= 0.5)
6953      {
6954         ec->fps.fps = (ec->fps.cframes - ec->fps.flapse) /
6955                       (tim - ec->fps.lapse);
6956         ec->fps.lapse = tim;
6957         ec->fps.flapse = ec->fps.cframes;
6958         ec->fps.time = 0.0;
6959      }
6960 }
6961
6962 EINTERN Eina_Bool
6963 e_client_fps_get(E_Client *ec, double *fps)
6964 {
6965    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6966
6967    if (ec->fps.old_fps == ec->fps.fps)
6968      return EINA_FALSE;
6969
6970    if (ec->fps.fps > 0.0)
6971      {
6972         *fps = ec->fps.fps;
6973         ec->fps.old_fps = ec->fps.fps;
6974         return EINA_TRUE;
6975      }
6976
6977    return EINA_FALSE;
6978 }
6979
6980 EINTERN void
6981 e_client_fps_enable(E_Client *ec, Eina_Bool enable)
6982 {
6983    EINA_SAFETY_ON_NULL_RETURN(ec);
6984
6985    ec->fps.enabled = enable;
6986 }
6987
6988 EINTERN Eina_Bool
6989 e_client_explicit_sync_get(E_Client *ec)
6990 {
6991    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
6992
6993    return ec->explicit_sync;
6994 }
6995
6996 EINTERN Eina_Bool
6997 e_client_explicit_sync_set(E_Client *ec, Eina_Bool enable)
6998 {
6999    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
7000
7001    ec->explicit_sync = enable;
7002
7003    return EINA_TRUE;
7004 }
7005
7006 EINTERN int
7007 e_client_explicit_sync_acquire_fence_fd_get(E_Client *ec)
7008 {
7009    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, -1);
7010
7011    return ec->acquire_fence_fd;
7012 }
7013
7014 EINTERN Eina_Bool
7015 e_client_explicit_sync_acquire_fence_fd_set(E_Client *ec, int fd)
7016 {
7017   EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
7018
7019   ec->acquire_fence_fd = fd;
7020
7021   return EINA_TRUE;
7022 }
7023
7024 EINTERN Eina_Bool
7025 e_client_intercept_hook_auto_placement_call(E_Client *ec)
7026 {
7027   // no need to call the intercept hook if ec is NULL.
7028   if (!ec) return EINA_FALSE;
7029
7030   if (!_e_client_intercept_hook_call(E_CLIENT_INTERCEPT_HOOK_AUTO_PLACEMENT, ec))
7031     {
7032        ELOGF("FOCUS", "E_CLIENT_INTERCEPT_HOOK_AUTO_PLACEMENT Intercepted.", ec);
7033        return EINA_TRUE;
7034     }
7035
7036   return EINA_FALSE;
7037 }
7038
7039 EINTERN void
7040 e_client_iconify_event_send(E_Client *ec)
7041 {
7042    EINA_SAFETY_ON_NULL_RETURN(ec);
7043
7044    _e_client_event_simple(ec, E_EVENT_CLIENT_ICONIFY);
7045 }
7046
7047 EINTERN void
7048 e_client_uniconify_event_send(E_Client *ec)
7049 {
7050    EINA_SAFETY_ON_NULL_RETURN(ec);
7051
7052    _e_client_event_simple(ec, E_EVENT_CLIENT_UNICONIFY);
7053 }
7054
7055 EINTERN void
7056 e_client_stack_transient_for_done_notify(E_Client *ec)
7057 {
7058    EINA_SAFETY_ON_NULL_RETURN(ec);
7059
7060    wl_signal_emit(&PRI(ec)->events.stack_transient_for_done, NULL);
7061 }
7062
7063 #ifdef REFACTOR_DESK_AREA
7064 EINTERN void
7065 e_client_subsurface_stack_update(E_Client *ec)
7066 {
7067    EINA_SAFETY_ON_NULL_RETURN(ec);
7068
7069    wl_signal_emit(&PRI(ec)->events.subsurface_stack_update, ec);
7070 }
7071 #endif
7072
7073 EINTERN void
7074 e_client_eval_pre_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
7075 {
7076    API_ENTRY;
7077    wl_signal_add(&priv->events.eval_pre_fetch, listener);
7078 }
7079
7080 EINTERN void
7081 e_client_eval_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
7082 {
7083    API_ENTRY;
7084    wl_signal_add(&priv->events.eval_fetch, listener);
7085 }
7086
7087 EINTERN void
7088 e_client_eval_pre_post_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
7089 {
7090    API_ENTRY;
7091    wl_signal_add(&priv->events.eval_pre_post_fetch, listener);
7092 }
7093
7094 EINTERN void
7095 e_client_eval_post_fetch_listener_add(E_Client *ec, struct wl_listener *listener)
7096 {
7097    API_ENTRY;
7098    wl_signal_add(&priv->events.eval_post_fetch, listener);
7099 }
7100
7101 EINTERN void
7102 e_client_eval_pre_frame_assign_listener_add(E_Client *ec, struct wl_listener *listener)
7103 {
7104    API_ENTRY;
7105    wl_signal_add(&priv->events.eval_pre_frame_assign, listener);
7106 }
7107
7108 EINTERN void
7109 e_client_eval_post_frame_assign_listener_add(E_Client *ec, struct wl_listener *listener)
7110 {
7111    API_ENTRY;
7112    wl_signal_add(&priv->events.eval_post_frame_assign, listener);
7113 }
7114
7115 EINTERN void
7116 e_client_eval_pre_new_client_listener_add(E_Client *ec, struct wl_listener *listener)
7117 {
7118    API_ENTRY;
7119    wl_signal_add(&priv->events.eval_pre_new_client, listener);
7120 }
7121
7122 EINTERN void
7123 e_client_eval_post_new_client_listener_add(E_Client *ec, struct wl_listener *listener)
7124 {
7125    API_ENTRY;
7126    wl_signal_add(&priv->events.eval_post_new_client, listener);
7127 }
7128
7129 EINTERN void
7130 e_client_eval_visibility_listener_add(E_Client *ec, struct wl_listener *listener)
7131 {
7132    API_ENTRY;
7133    wl_signal_add(&priv->events.eval_visibility, listener);
7134 }
7135
7136 EINTERN void
7137 e_client_eval_visibility_end_listener_add(E_Client *ec, struct wl_listener *listener)
7138 {
7139    API_ENTRY;
7140    wl_signal_add(&priv->events.eval_visibility_end, listener);
7141 }
7142
7143 EINTERN void
7144 e_client_eval_end_listener_add(E_Client *ec, struct wl_listener *listener)
7145 {
7146    API_ENTRY;
7147    wl_signal_add(&priv->events.eval_end, listener);
7148 }
7149
7150 EINTERN void
7151 e_client_move_begin_listener_add(E_Client *ec, struct wl_listener *listener)
7152 {
7153    API_ENTRY;
7154    wl_signal_add(&priv->events.move_begin, listener);
7155 }
7156
7157 EINTERN void
7158 e_client_move_update_listener_add(E_Client *ec, struct wl_listener *listener)
7159 {
7160    API_ENTRY;
7161    wl_signal_add(&priv->events.move_update, listener);
7162 }
7163
7164 EINTERN void
7165 e_client_move_end_listener_add(E_Client *ec, struct wl_listener *listener)
7166 {
7167    API_ENTRY;
7168    wl_signal_add(&priv->events.move_end, listener);
7169 }
7170
7171 EINTERN void
7172 e_client_move_resize_begin_listener_add(E_Client *ec, struct wl_listener *listener)
7173 {
7174    API_ENTRY;
7175    wl_signal_add(&priv->events.move_resize_begin, listener);
7176 }
7177
7178 EINTERN void
7179 e_client_move_resize_update_listener_add(E_Client *ec, struct wl_listener *listener)
7180 {
7181    API_ENTRY;
7182    wl_signal_add(&priv->events.move_resize_update, listener);
7183 }
7184
7185 EINTERN void
7186 e_client_move_resize_end_listener_add(E_Client *ec, struct wl_listener *listener)
7187 {
7188    API_ENTRY;
7189    wl_signal_add(&priv->events.move_resize_end, listener);
7190 }
7191
7192 EINTERN void
7193 e_client_destroy_listener_add(E_Client *ec, struct wl_listener *listener)
7194 {
7195    API_ENTRY;
7196    wl_signal_add(&priv->events.destroy, listener);
7197 }
7198
7199 EINTERN void
7200 e_client_new_client_listener_add(E_Client *ec, struct wl_listener *listener)
7201 {
7202    API_ENTRY;
7203    wl_signal_add(&priv->events.new_client, listener);
7204 }
7205
7206 EINTERN void
7207 e_client_new_client_post_listener_add(E_Client *ec, struct wl_listener *listener)
7208 {
7209    API_ENTRY;
7210    wl_signal_add(&priv->events.new_client_post, listener);
7211 }
7212
7213 EINTERN void
7214 e_client_unredirect_listener_add(E_Client *ec, struct wl_listener *listener)
7215 {
7216    API_ENTRY;
7217    wl_signal_add(&priv->events.unredirect, listener);
7218 }
7219
7220 EINTERN void
7221 e_client_redirect_listener_add(E_Client *ec, struct wl_listener *listener)
7222 {
7223    API_ENTRY;
7224    wl_signal_add(&priv->events.redirect, listener);
7225 }
7226
7227 EINTERN void
7228 e_client_aux_hint_change_listener_add(E_Client *ec, struct wl_listener *listener)
7229 {
7230    API_ENTRY;
7231    wl_signal_add(&priv->events.aux_hint_change, listener);
7232 }
7233
7234 EINTERN void
7235 e_client_window_role_change_listener_add(E_Client *ec, struct wl_listener *listener)
7236 {
7237    API_ENTRY;
7238    wl_signal_add(&priv->events.window_role_change, listener);
7239 }
7240
7241 EINTERN void
7242 e_client_transform_change_listener_add(E_Client *ec, struct wl_listener *listener)
7243 {
7244    API_ENTRY;
7245    wl_signal_add(&priv->events.transform_change, listener);
7246 }
7247
7248 EINTERN void
7249 e_client_activate_done_listener_add(E_Client *ec, struct wl_listener *listener)
7250 {
7251    API_ENTRY;
7252    wl_signal_add(&priv->events.activate_done, listener);
7253 }
7254
7255 EINTERN void
7256 e_client_mouse_in_listener_add(E_Client *ec, struct wl_listener *listener)
7257 {
7258    API_ENTRY;
7259    wl_signal_add(&priv->events.mouse_in, listener);
7260 }
7261
7262 EINTERN void
7263 e_client_mouse_out_listener_add(E_Client *ec, struct wl_listener *listener)
7264 {
7265    API_ENTRY;
7266    wl_signal_add(&priv->events.mouse_out, listener);
7267 }
7268
7269 EINTERN void
7270 e_client_mouse_down_listener_add(E_Client *ec, struct wl_listener *listener)
7271 {
7272    API_ENTRY;
7273    wl_signal_add(&priv->events.mouse_down, listener);
7274 }
7275
7276 EINTERN void
7277 e_client_focus_set_listener_add(E_Client *ec, struct wl_listener *listener)
7278 {
7279    API_ENTRY;
7280    wl_signal_add(&priv->events.focus_set, listener);
7281 }
7282
7283 EINTERN void
7284 e_client_focus_unset_listener_add(E_Client *ec, struct wl_listener *listener)
7285 {
7286    API_ENTRY;
7287    wl_signal_add(&priv->events.focus_unset, listener);
7288 }
7289
7290 EINTERN void
7291 e_client_focus_defer_set_listener_add(E_Client *ec, struct wl_listener *listener)
7292 {
7293    API_ENTRY;
7294    wl_signal_add(&priv->events.focus_defer_set, listener);
7295 }
7296
7297 EINTERN void
7298 e_client_focus_latest_set_listener_add(E_Client *ec, struct wl_listener *listener)
7299 {
7300    API_ENTRY;
7301    wl_signal_add(&priv->events.focus_latest_set, listener);
7302 }
7303
7304 EINTERN void
7305 e_client_iconify_listener_add(E_Client *ec, struct wl_listener *listener)
7306 {
7307    API_ENTRY;
7308    wl_signal_add(&priv->events.iconify, listener);
7309 }
7310
7311 EINTERN void
7312 e_client_uniconify_listener_add(E_Client *ec, struct wl_listener *listener)
7313 {
7314    API_ENTRY;
7315    wl_signal_add(&priv->events.uniconify, listener);
7316 }
7317
7318 EINTERN void
7319 e_client_maximize_listener_add(E_Client *ec, struct wl_listener *listener)
7320 {
7321    API_ENTRY;
7322    wl_signal_add(&priv->events.maximize, listener);
7323 }
7324
7325 EINTERN void
7326 e_client_unmaximize_listener_add(E_Client *ec, struct wl_listener *listener)
7327 {
7328    API_ENTRY;
7329    wl_signal_add(&priv->events.unmaximize, listener);
7330 }
7331
7332 EINTERN void
7333 e_client_fullscreen_pre_listener_add(E_Client *ec, struct wl_listener *listener)
7334 {
7335    API_ENTRY;
7336    wl_signal_add(&priv->events.fullscreen_pre, listener);
7337 }
7338
7339 EINTERN void
7340 e_client_fullscreen_listener_add(E_Client *ec, struct wl_listener *listener)
7341 {
7342    API_ENTRY;
7343    wl_signal_add(&priv->events.fullscreen, listener);
7344 }
7345
7346 EINTERN void
7347 e_client_unfullscreen_listener_add(E_Client *ec, struct wl_listener *listener)
7348 {
7349    API_ENTRY;
7350    wl_signal_add(&priv->events.unfullscreen, listener);
7351 }
7352
7353 EINTERN void
7354 e_client_move_listener_add(E_Client *ec, struct wl_listener *listener)
7355 {
7356    API_ENTRY;
7357    wl_signal_add(&priv->events.move, listener);
7358 }
7359
7360 EINTERN void
7361 e_client_raise_listener_add(E_Client *ec, struct wl_listener *listener)
7362 {
7363    API_ENTRY;
7364    wl_signal_add(&priv->events.raise, listener);
7365 }
7366
7367 EINTERN void
7368 e_client_lower_listener_add(E_Client *ec, struct wl_listener *listener)
7369 {
7370    API_ENTRY;
7371    wl_signal_add(&priv->events.lower, listener);
7372 }
7373
7374 EINTERN void
7375 e_client_stack_below_listener_add(E_Client *ec, struct wl_listener *listener)
7376 {
7377    API_ENTRY;
7378    wl_signal_add(&priv->events.stack_below, listener);
7379 }
7380
7381 EINTERN void
7382 e_client_stack_above_listener_add(E_Client *ec, struct wl_listener *listener)
7383 {
7384    API_ENTRY;
7385    wl_signal_add(&priv->events.stack_above, listener);
7386 }
7387
7388 EINTERN void
7389 e_client_set_layer_listener_add(E_Client *ec, struct wl_listener *listener)
7390 {
7391    API_ENTRY;
7392    wl_signal_add(&priv->events.set_layer, listener);
7393 }
7394
7395 EINTERN void
7396 e_client_stack_transient_for_done_listener_add(E_Client *ec, struct wl_listener *listener)
7397 {
7398    API_ENTRY;
7399    wl_signal_add(&priv->events.stack_transient_for_done, listener);
7400 }
7401
7402 EINTERN void
7403 e_client_stick_listener_add(E_Client *ec, struct wl_listener *listener)
7404 {
7405    API_ENTRY;
7406    wl_signal_add(&priv->events.stick, listener);
7407 }
7408
7409 EINTERN void
7410 e_client_unstick_listener_add(E_Client *ec, struct wl_listener *listener)
7411 {
7412    API_ENTRY;
7413    wl_signal_add(&priv->events.unstick, listener);
7414 }
7415
7416 EINTERN struct wl_listener *
7417 e_client_destroy_listener_get(E_Client *ec, wl_notify_func_t notify)
7418 {
7419    API_ENTRY_VAL(NULL);
7420    return wl_signal_get(&priv->events.destroy, notify);
7421 }
7422
7423 #ifdef REFACTOR_DESK_AREA
7424 EINTERN void
7425 e_client_get_above_listener_add(E_Client *ec, struct wl_listener *listener)
7426 {
7427    API_ENTRY;
7428    wl_signal_add(&priv->events.get_above, listener);
7429 }
7430
7431 EINTERN void
7432 e_client_get_below_listener_add(E_Client *ec, struct wl_listener *listener)
7433 {
7434    API_ENTRY;
7435    wl_signal_add(&priv->events.get_below, listener);
7436 }
7437
7438 EINTERN void
7439 e_client_get_visible_above_listener_add(E_Client *ec, struct wl_listener *listener)
7440 {
7441    API_ENTRY;
7442    wl_signal_add(&priv->events.get_visible_above, listener);
7443 }
7444
7445 EINTERN void
7446 e_client_get_visible_below_listener_add(E_Client *ec, struct wl_listener *listener)
7447 {
7448    API_ENTRY;
7449    wl_signal_add(&priv->events.get_visible_below, listener);
7450 }
7451
7452 EINTERN void
7453 e_client_subsurface_stack_update_listener_add(E_Client *ec, struct wl_listener *listener)
7454 {
7455    API_ENTRY;
7456    wl_signal_add(&priv->events.subsurface_stack_update, listener);
7457 }
7458 #endif
7459
7460 EINTERN void
7461 e_client_shell_configure_send(E_Client *ec, uint32_t edges, int32_t width, int32_t height)
7462 {
7463    EINA_SAFETY_ON_NULL_RETURN(ec);
7464    EINA_SAFETY_ON_NULL_RETURN(ec->comp_data);
7465
7466    if ((!ec->comp_data->shell.surface) ||
7467        (!ec->comp_data->shell.configure_send))
7468      return;
7469
7470    ec->comp_data->shell.configure_send(ec->comp_data->shell.surface, edges, width, height);
7471 }
7472
7473 EINTERN void
7474 e_client_shell_configure(E_Client *ec, Evas_Coord x, Evas_Coord y, Evas_Coord width, Evas_Coord height)
7475 {
7476    EINA_SAFETY_ON_NULL_RETURN(ec);
7477    EINA_SAFETY_ON_NULL_RETURN(ec->comp_data);
7478
7479    if ((!ec->comp_data->shell.surface) ||
7480        (!ec->comp_data->shell.configure))
7481      return;
7482
7483    ec->comp_data->shell.configure(ec->comp_data->shell.surface, x, y, width, height);
7484 }
7485
7486 EINTERN void
7487 e_client_shell_ping(E_Client *ec)
7488 {
7489    EINA_SAFETY_ON_NULL_RETURN(ec);
7490    EINA_SAFETY_ON_NULL_RETURN(ec->comp_data);
7491
7492    if ((!ec->comp_data->shell.surface) ||
7493        (!ec->comp_data->shell.ping))
7494      return;
7495
7496    ec->comp_data->shell.ping(ec->comp_data->shell.surface);
7497 }
7498
7499 static void
7500 _e_input_thread_client_icccm_name_set(void *data)
7501 {
7502    E_Input_Thread_Request_EClient_Data *ec_data = data;
7503    EINA_SAFETY_ON_NULL_RETURN(ec_data);
7504
7505    INF("[input thread|%s] ec(%p), name(%s)\n", __func__, ec_data->ec, ec_data->icccm_name);
7506    e_input_thread_client_icccm_name_set(e_input_thread_client_get(ec_data->ec), ec_data->icccm_name);
7507 }
7508
7509 EINTERN void
7510 e_client_icccm_name_set(E_Client *ec, const char *name)
7511 {
7512    E_Input_Thread_Request_EClient_Data ec_data;
7513    memset(&ec_data, 0, sizeof(E_Input_Thread_Request_EClient_Data));
7514
7515    EINA_SAFETY_ON_NULL_RETURN(ec);
7516
7517    if (eina_stringshare_replace(&ec->icccm.name, name))
7518      {
7519         ec->changes.title = EINA_TRUE;
7520
7521         ec_data.ec = ec;
7522         ec_data.wl_surface = ec->comp_data ? ec->comp_data->wl_surface : NULL;
7523         ec_data.is_video = EINA_FALSE;
7524
7525         if (name)
7526           strncpy(ec_data.icccm_name, name, sizeof(ec_data.icccm_name)-1);
7527
7528         INF("[%s] ec(%p), surface(%p), name(%s)\n", __func__, ec, ec_data.wl_surface, name);
7529         e_input_thread_safe_call(_e_input_thread_client_icccm_name_set, &ec_data, sizeof(E_Input_Thread_Request_EClient_Data));
7530      }
7531 }
7532
7533 E_API Eina_Stringshare *
7534 e_client_icccm_name_get(E_Client *ec)
7535 {
7536    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
7537
7538    return ec->icccm.name;
7539 }
7540
7541 static void
7542 _e_input_thread_client_netwm_name_set(void *data)
7543 {
7544    E_Input_Thread_Request_EClient_Data *ec_data = data;
7545    EINA_SAFETY_ON_NULL_RETURN(ec_data);
7546
7547    INF("[input thread|%s] ec(%p), name(%p)\n", __func__, ec_data->ec, ec_data->netwm_name);
7548    e_input_thread_client_netwm_name_set(e_input_thread_client_get(ec_data->ec), ec_data->netwm_name);
7549 }
7550
7551 EINTERN void
7552 e_client_netwm_name_set(E_Client *ec, const char *name)
7553 {
7554    E_Input_Thread_Request_EClient_Data ec_data = { NULL, NULL, EINA_FALSE, EINA_FALSE };
7555    memset(&ec_data, 0, sizeof(E_Input_Thread_Request_EClient_Data));
7556
7557    EINA_SAFETY_ON_NULL_RETURN(ec);
7558
7559    eina_stringshare_replace(&ec->netwm.name, name);
7560
7561    ec_data.ec = ec;
7562    ec_data.wl_surface = ec->comp_data ? ec->comp_data->wl_surface : NULL;
7563
7564    if (name)
7565      strncpy(ec_data.netwm_name, name, sizeof(ec_data.netwm_name)-1);
7566
7567    INF("[%s] ec(%p), surface(%p), name(%s)\n", __func__, ec, ec_data.wl_surface, ec_data.netwm_name);
7568    e_input_thread_safe_call(_e_input_thread_client_netwm_name_set, &ec_data, sizeof(E_Input_Thread_Request_EClient_Data));
7569 }
7570
7571 E_API Eina_Stringshare *
7572 e_client_netwm_name_get(E_Client *ec)
7573 {
7574    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
7575
7576    return ec->netwm.name;
7577 }
7578
7579 static void
7580 _e_input_thread_client_icccm_title_set(void *data)
7581 {
7582    E_Input_Thread_Request_EClient_Data *ec_data = data;
7583    EINA_SAFETY_ON_NULL_RETURN(ec_data);
7584
7585    INF("[input thread|%s] ec(%p), title(%s)\n", __func__, ec_data->ec, ec_data->icccm_title);
7586    e_input_thread_client_icccm_title_set(e_input_thread_client_get(ec_data->ec), ec_data->icccm_title);
7587 }
7588
7589 EINTERN void
7590 e_client_icccm_title_set(E_Client *ec, const char *title)
7591 {
7592    E_Input_Thread_Request_EClient_Data ec_data;
7593    memset(&ec_data, 0, sizeof(E_Input_Thread_Request_EClient_Data));
7594
7595    EINA_SAFETY_ON_NULL_RETURN(ec);
7596
7597    if (eina_stringshare_replace(&ec->icccm.title, title))
7598      {
7599         ec->changes.title = EINA_TRUE;
7600
7601         ec_data.ec = ec;
7602         ec_data.wl_surface = ec->comp_data ? ec->comp_data->wl_surface : NULL;
7603         if (title)
7604           strncpy(ec_data.icccm_title, title, sizeof(ec_data.icccm_title)-1);
7605
7606         INF("[%s] ec(%p), surface(%p)\n", __func__, ec, ec_data.wl_surface);
7607         e_input_thread_safe_call(_e_input_thread_client_icccm_title_set, &ec_data, sizeof(E_Input_Thread_Request_EClient_Data));
7608      }
7609 }
7610
7611 E_API Eina_Stringshare *
7612 e_client_icccm_title_get(E_Client *ec)
7613 {
7614    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
7615
7616    return ec->icccm.title;
7617 }
7618
7619 static void
7620 _e_client_shell_map(E_Client *ec)
7621 {
7622    EINA_SAFETY_ON_NULL_RETURN(ec);
7623    EINA_SAFETY_ON_NULL_RETURN(ec->comp_data);
7624
7625    if ((!ec->comp_data->shell.surface) ||
7626        (!ec->comp_data->shell.map))
7627      return;
7628
7629    ec->comp_data->shell.map(ec->comp_data->shell.surface);
7630 }
7631
7632 EINTERN void
7633 e_client_shell_unmap(E_Client *ec)
7634 {
7635    EINA_SAFETY_ON_NULL_RETURN(ec);
7636    EINA_SAFETY_ON_NULL_RETURN(ec->comp_data);
7637
7638    if ((!ec->comp_data->shell.surface) ||
7639        (!ec->comp_data->shell.unmap))
7640      return;
7641
7642    ec->comp_data->shell.unmap(ec->comp_data->shell.surface);
7643 }
7644
7645 EINTERN void
7646 e_client_show(E_Client *ec)
7647 {
7648    EINA_SAFETY_ON_NULL_RETURN(ec);
7649    EINA_SAFETY_ON_NULL_RETURN(ec->comp_data);
7650
7651    if (ec->comp_data->mapped)
7652      return;
7653
7654    if ((ec->comp_data->shell.surface) && (ec->comp_data->shell.map) &&
7655        (!ec->ignored))
7656      {
7657         ELOGF("E_CLIENT", "Map.", ec);
7658         _e_client_shell_map(ec);
7659      }
7660    else if (ec->internal || e_comp_wl_subsurface_can_show(ec) ||
7661             (ec == e_comp_wl->drag_client))
7662      {
7663         ELOGF("E_CLIENT", "Map. internal:%d, drag:%d",
7664               ec, ec->internal, (ec == e_comp_wl->drag_client));
7665         ec->visible = EINA_TRUE;
7666         ec->ignored = 0;
7667         evas_object_show(ec->frame);
7668         ec->comp_data->mapped = 1;
7669      }
7670 }
7671
7672 EINTERN void
7673 e_client_hide(E_Client *ec)
7674 {
7675    API_ENTRY;
7676
7677    EINA_SAFETY_ON_NULL_RETURN(ec->comp_data);
7678
7679    if (!ec->comp_data->mapped)
7680      return;
7681
7682    if ((ec->comp_data->shell.surface) && (ec->comp_data->shell.unmap))
7683      {
7684         ELOGF("E_CLIENT", "Unmap", ec);
7685
7686         if (priv->hide_by_request)
7687           ELOGF("COMP", "Currenlty hide_by_request state.", ec);
7688
7689         if (ec->show_pending.count > 0)
7690           {
7691              ELOGF("E_CLIENT", "Reset show_pending!!! (count:%d, run:%d)", ec, ec->show_pending.count, ec->show_pending.running);
7692              ec->show_pending.count = 0;
7693              if (ec->show_pending.running)
7694                {
7695                   // need to send visibility false;
7696                   e_client_visibility_set(ec, E_VISIBILITY_UNOBSCURED);
7697                   ELOGF("POL_VIS", "CLIENT VIS ON (fake).  argb:%d, opaque:%2d", ec, ec->argb, ec->visibility.opaque);
7698                   EC_CHANGED(ec);
7699                }
7700              ec->show_pending.running = EINA_FALSE;
7701           }
7702         e_client_shell_unmap(ec);
7703      }
7704    else if ((ec->internal) || (e_comp_wl_subsurface_check(ec)) ||
7705             (ec == e_comp_wl->drag_client))
7706      {
7707         ELOGF("E_CLIENT", "Unmap. internal:%d, sub:%p, drag:%d",
7708               ec, ec->internal, ec->comp_data->sub.data, (ec == e_comp_wl->drag_client));
7709         ec->visible = EINA_FALSE;
7710         evas_object_hide(ec->frame);
7711         ec->comp_data->mapped = 0;
7712      }
7713 }
7714
7715 static void
7716 _e_input_thread_client_video_mode_set(void *data)
7717 {
7718    E_Input_Thread_Request_EClient_Data *ec_data = data;
7719    EINA_SAFETY_ON_NULL_RETURN(ec_data);
7720
7721    INF("[input thread|%s] ec(%p), is_video(%d)\n", __func__, ec_data->ec, ec_data->is_video);
7722    e_input_thread_client_video_set(e_input_thread_client_get(ec_data->ec), ec_data->is_video);
7723 }
7724
7725 EINTERN void
7726 e_client_video_mode_set(E_Client *ec, Eina_Bool is_video)
7727 {
7728    E_Input_Thread_Request_EClient_Data ec_data;
7729    memset(&ec_data, 0, sizeof(E_Input_Thread_Request_EClient_Data));
7730
7731    EINA_SAFETY_ON_NULL_RETURN(ec);
7732    EINA_SAFETY_ON_NULL_RETURN(ec->hwc_window);
7733
7734    ec->hwc_window->is_video = is_video;
7735
7736    ec_data.ec = ec;
7737    ec_data.is_video = is_video;
7738
7739    INF("[%s] ec(%p), is_video(%d)\n", __func__, ec, is_video);
7740    e_input_thread_safe_call(_e_input_thread_client_video_mode_set, &ec_data, sizeof(E_Input_Thread_Request_EClient_Data));
7741 }