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