tizen 2.4 release
[framework/uifw/e17-mod-tizen-comp.git] / src / e_mod_comp.c
1 #include "e_mod_comp.h"
2 #include "e_mod_comp_atoms.h"
3 #include "e_mod_comp_debug.h"
4 #include <dlog.h>
5 #include <X11/Xatom.h>
6 #include <X11/extensions/Xrandr.h>
7
8 #define LOG_TAG "E17_EXTRA_MODULES"
9
10 #define OVER_FLOW 2
11
12 //////////////////////////////////////////////////////////////////////////
13 //
14 // TODO (no specific order):
15 //   1. abstract evas object and compwin so we can duplicate the object N times
16 //      in N canvases - for winlist, everything, pager etc. too
17 //   2. implement "unmapped composite cache" -> N pixels worth of unmapped
18 //      windows to be fully composited. only the most active/recent.
19 //   3. for unmapped windows - when window goes out of unmapped comp cache
20 //      make a miniature copy (1/4 width+height?) and set property on window
21 //      with pixmap id
22 //   8. obey transparent property
23 //   9. shortcut lots of stuff to draw inside the compositor - shelf,
24 //      wallpaper, efm - hell even menus and anything else in e (this is what
25 //      e18 was mostly about)
26 //  10. fullscreen windows need to be able to bypass compositing *seems buggy*
27 //
28 //////////////////////////////////////////////////////////////////////////
29
30 /* static global variables */
31 static Eina_List *handlers      = NULL;
32 static Eina_List *handlers_hook = NULL;
33 static Eina_List *compositors   = NULL;
34 static Eina_Hash *windows       = NULL;
35 static Eina_Hash *borders       = NULL;
36 static Eina_Hash *damages       = NULL;
37
38 /* static functions */
39 static void         _e_mod_comp_render_queue(E_Comp *c);
40 static Eina_Bool    _e_mod_comp_effect_init(E_Comp *c);
41 static Eina_Bool    _e_mod_comp_hwcomp_init(E_Comp *c);
42 static void         _e_mod_comp_win_damage(E_Comp_Win *cw, int x, int y, int w, int h, Eina_Bool dmg);
43 static void         _e_mod_comp_win_del(E_Comp_Win *cw);
44 static void         _e_mod_comp_win_real_hide(E_Comp_Win *cw);
45 static void         _e_mod_comp_win_hide(E_Comp_Win *cw);
46 static void         _e_mod_comp_win_configure(E_Comp_Win *cw, int x, int y, int w, int h, int border);
47 static Eina_Bool    _e_mod_comp_win_damage_timeout(void *data);
48 static void         _e_mod_comp_win_raise(E_Comp_Win *cw);
49 static void         _e_mod_comp_win_lower(E_Comp_Win *cw);
50 static E_Comp_Win  *_e_mod_comp_win_find(Ecore_X_Window win);
51 static E_Comp_Win  *_e_mod_comp_border_client_find(Ecore_X_Window win);
52 static Eina_Bool    _e_mod_comp_cb_update(E_Comp *c);
53 static Eina_Bool    _e_mod_comp_win_is_border(E_Comp_Win *cw);
54 static void         _e_mod_comp_cb_pending_after(void *data, E_Manager *man, E_Manager_Comp_Source *src);
55 static E_Comp      *_e_mod_comp_find(Ecore_X_Window root);
56 static void         _e_mod_comp_win_render_queue(E_Comp_Win *cw);
57 static Evas_Object *_e_mod_comp_win_mirror_add(E_Comp_Win *cw);
58 static void         _e_mod_comp_cb_win_mirror_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
59 static void         _e_mod_comp_src_hidden_set_func(void *data, E_Manager *man, E_Manager_Comp_Source *src, Eina_Bool hidden);
60 static Eina_Bool    _e_mod_comp_prop_window_use_dri2_get(Ecore_X_Window win);
61 static Eina_Bool    _e_mod_comp_prop_use_dri2(Ecore_X_Event_Window_Property *ev);
62 static void         _e_mod_comp_composite_mode_set(void *data, E_Manager *man, E_Zone *zone, Eina_Bool set);
63 static void         _e_comp_event_src_visibility_free(void *data, void *event);
64 static void         _e_mod_comp_win_transparent_rect_update(E_Comp_Win *cw);
65 static Eina_Bool    _e_mod_comp_prop_window_role(Ecore_X_Event_Window_Property *ev);
66 static void         _e_mod_comp_window_role_handle(E_Comp_Win *cw);
67 static Eina_Bool    _e_mod_comp_win_rr_output_prop_set(Ecore_X_Window win, unsigned int_mode);
68 static Eina_Bool    _e_mod_comp_prop_3d_win_mode(Ecore_X_Event_Window_Property *ev);
69 static Eina_Bool    _e_mod_comp_win_stereo_layout_set(Ecore_X_Window win, unsigned int mode);
70 static void         _e_mod_comp_active_request_handle(Ecore_X_Event_Client_Message *ev);
71 #ifdef _F_IGNORE_DMG_HIDE_
72 static void         _e_mod_comp_msg_deiconify_approve(Ecore_X_Event_Client_Message *ev);
73 #endif
74 ///////////////////////////////////////////////////////////////////////////////////
75 EAPI void
76 e_comp_event_src_visibility_send(Ecore_X_Window win,
77                                  Eina_Bool      visible)
78 {
79    E_Event_Comp_Source_Visibility *ev;
80    ev = E_NEW(E_Event_Comp_Source_Visibility, 1);
81    if (ev)
82      {
83         ev->win = win;
84         ev->visible = visible;
85         ecore_event_add(E_EVENT_COMP_SOURCE_VISIBILITY, ev, (Ecore_End_Cb)_e_comp_event_src_visibility_free, NULL);
86      }
87 }
88
89 EAPI Eina_Bool
90 e_mod_comp_comp_event_src_visibility_send(E_Comp_Win *cw)
91 {
92    E_CHECK_RETURN(cw, 0);
93    E_CHECK_RETURN(cw->c, 0);
94    E_CHECK_RETURN(cw->c->man, 0);
95
96    cw->pending_count++;
97
98    e_manager_comp_event_src_visibility_send
99      (cw->c->man, (E_Manager_Comp_Source *)cw,
100      _e_mod_comp_cb_pending_after, cw->c);
101
102    return EINA_TRUE;
103 }
104
105 static Eina_Bool
106 _e_mod_comp_win_is_border(E_Comp_Win *cw)
107 {
108    E_CHECK_RETURN(cw, 0);
109    if (cw->bd) return EINA_TRUE;
110    else return EINA_FALSE;
111 }
112
113 EAPI void
114 e_mod_comp_fps_toggle(void)
115 {
116    if (_comp_mod)
117      {
118         Eina_List *l;
119         E_Comp *c;
120
121         if (_comp_mod->conf->fps_show)
122           {
123              _comp_mod->conf->fps_show = 0;
124           }
125         else
126           {
127              _comp_mod->conf->fps_show = 1;
128           }
129         e_config_save_queue();
130         EINA_LIST_FOREACH(compositors, l, c) _e_mod_comp_cb_update(c);
131      }
132 }
133
134 EAPI Eina_Bool
135 e_mod_comp_win_add_damage(E_Comp_Win *cw,
136                           Ecore_X_Damage dmg)
137 {
138    E_CHECK_RETURN(cw, 0);
139    E_CHECK_RETURN(dmg, 0);
140    return eina_hash_add(damages, e_util_winid_str_get(dmg), cw);
141 }
142
143 EAPI Eina_Bool
144 e_mod_comp_win_del_damage(E_Comp_Win *cw,
145                           Ecore_X_Damage dmg)
146 {
147    E_CHECK_RETURN(cw, 0);
148    E_CHECK_RETURN(dmg, 0);
149    return eina_hash_del(damages, e_util_winid_str_get(dmg), cw);
150 }
151
152 EAPI void
153 e_mod_comp_composite_mode_set(E_Zone   *zone,
154                               Eina_Bool set)
155 {
156    _e_mod_comp_composite_mode_set(e_mod_comp_util_get(),
157                                   NULL, zone, set);
158 }
159
160 static void
161 _e_mod_comp_cb_pending_after(void *data __UNUSED__,
162                              E_Manager *man __UNUSED__,
163                              E_Manager_Comp_Source *src)
164 {
165    E_Comp_Win *cw = (E_Comp_Win *)src;
166    E_Comp *c = (E_Comp *)data;
167
168    cw->pending_count--;
169
170    if (!cw->delete_pending) return;
171    if (cw->pending_count == 0)
172      {
173         E_Comp_Canvas *canvas = NULL;
174         Eina_List *l = NULL;
175         if (_comp_mod && _comp_mod->conf->nocomp_fs && c)
176           {
177              EINA_LIST_FOREACH(c->canvases, l, canvas)
178                {
179                   if (canvas->nocomp.end.cw == cw)
180                     {
181                        if (canvas->nocomp.end.timer)
182                          {
183                             ecore_timer_del(canvas->nocomp.end.timer);
184                             canvas->nocomp.end.timer = NULL;
185                          }
186                        e_mod_comp_canvas_nocomp_dispose(canvas);
187                        break;
188                     }
189                }
190           }
191         free(cw);
192      }
193 }
194
195 static Eina_Bool
196 _e_mod_comp_effect_init(E_Comp *c)
197 {
198    if (!(c->effect_handle = dlopen(_comp_mod->conf->effect_file, (RTLD_NOW | RTLD_GLOBAL))))
199      {
200         /* cannot open the .so file, bail out */
201         ELBF(ELBT_COMP, 0, 0,
202             "Cannot open effect so: %s", ecore_file_file_get(_comp_mod->conf->effect_file));
203         return 0;
204      }
205
206    c->effect_funcs.init = dlsym(c->effect_handle, "e_mod_comp_effect_mod_init");
207    c->effect_funcs.shutdown = dlsym(c->effect_handle, "e_mod_comp_effect_mod_shutdown");
208
209    /* check that policy supports needed functions */
210    if ((!c->effect_funcs.init) || (!c->effect_funcs.shutdown))
211      {
212         ELBF(ELBT_COMP, 0, 0,
213             "Effect does not support needed functions: %s", ecore_file_file_get(_comp_mod->conf->effect_file));
214         return 0;
215      }
216
217    /* try to initialize the effect */
218    if (!c->effect_funcs.init(c))
219      {
220         /* init failed, bail out */
221         ELBF(ELBT_COMP, 0, 0,
222             "Effect failed to initialize: %s", ecore_file_file_get(_comp_mod->conf->effect_file));
223         return 0;
224      }
225
226    return EINA_TRUE;
227 }
228
229 static Eina_Bool
230 _e_mod_comp_hwcomp_init(E_Comp *c)
231 {
232    if (!(c->hwcomp_handle = dlopen(_comp_mod->conf->hwcomp_file, (RTLD_NOW | RTLD_GLOBAL))))
233      {
234         /* cannot open the .so file. bail out */
235         ELBF(ELBT_COMP, 0, 0, "Cannot open hwcomp so: %s", _comp_mod->conf->hwcomp_file);
236         printf("Cannot open hwcomp so: %s\n",
237                ecore_file_file_get(_comp_mod->conf->hwcomp_file));
238         return 0;
239      }
240    // function link
241    c->hwcomp_funcs.init = dlsym(c->hwcomp_handle, "e_mod_comp_hwcomp_mod_init");
242    c->hwcomp_funcs.shutdown = dlsym(c->hwcomp_handle, "e_mod_comp_hwcomp_mod_shutdown");
243
244    /* check that policy supports needed functions */
245    if ((!c->hwcomp_funcs.init) || (!c->hwcomp_funcs.shutdown))
246      {
247         ELBF(ELBT_COMP, 0, 0, "HWComp does not support needed functions: %s",
248              ecore_file_file_get(_comp_mod->conf->hwcomp_file));
249         return 0;
250      }
251
252    /* try to initialize the hwcomp */
253    if (!c->hwcomp_funcs.init(c))
254      {
255         ELBF(ELBT_COMP, 0, 0, "HWComp failed to initialize: %s",
256              ecore_file_file_get(_comp_mod->conf->hwcomp_file));
257         return 0;
258
259      }
260
261    return EINA_TRUE;
262 }
263
264 static inline Eina_Bool
265 _e_mod_comp_shaped_check(int                      w,
266                          int                      h,
267                          const Ecore_X_Rectangle *rects,
268                          int                      num)
269 {
270    if ((!rects) || (num < 1)) return EINA_FALSE;
271    if (num > 1) return EINA_TRUE;
272    if ((rects[0].x == 0) && (rects[0].y == 0) &&
273        ((int)rects[0].width == w) && ((int)rects[0].height == h))
274      return EINA_FALSE;
275    return EINA_TRUE;
276 }
277
278 static inline Eina_Bool
279 _e_mod_comp_win_shaped_check(const E_Comp_Win        *cw,
280                              const Ecore_X_Rectangle *rects,
281                              int                      num)
282 {
283    return _e_mod_comp_shaped_check(cw->w, cw->h, rects, num);
284 }
285
286 static void
287 _e_mod_comp_win_shape_rectangles_apply(E_Comp_Win              *cw,
288                                        const Ecore_X_Rectangle *rects,
289                                        int                      num)
290 {
291    Eina_List *l, *ll;
292    Evas_Object *o;
293    E_Comp_Object *co;
294    int i;
295
296    if (!_e_mod_comp_win_shaped_check(cw, rects, num))
297      {
298         rects = NULL;
299      }
300    EINA_LIST_FOREACH(cw->objs, l, co)
301      {
302         if (rects)
303           {
304              unsigned int *pix, *p;
305              unsigned char *spix, *sp;
306              int w, h, px, py;
307
308              evas_object_image_size_get(co->img, &w, &h);
309              if ((w > 0) && (h > 0))
310                {
311                   if (co->native) return;
312                   evas_object_image_native_surface_set(co->img, NULL);
313                   evas_object_image_alpha_set(co->img, 1);
314                   EINA_LIST_FOREACH(co->img_mirror, ll, o)
315                     {
316                        evas_object_image_native_surface_set(o, NULL);
317                        evas_object_image_alpha_set(o, 1);
318                     }
319
320                   pix = evas_object_image_data_get(co->img, 1);
321                   if (pix)
322                     {
323                        spix = calloc(w * h, sizeof(unsigned char));
324                        if (spix)
325                          {
326                             for (i = 0; i < num; i++)
327                               {
328                                  int rx, ry, rw, rh;
329
330                                  rx = rects[i].x; ry = rects[i].y;
331                                  rw = rects[i].width; rh = rects[i].height;
332                                  E_RECTS_CLIP_TO_RECT(rx, ry, rw, rh, 0, 0, w, h);
333                                  sp = spix + (w * ry) + rx;
334                                  for (py = 0; py < rh; py++)
335                                    {
336                                       for (px = 0; px < rw; px++)
337                                         {
338                                            *sp = 0xff; sp++;
339                                         }
340                                       sp += w - rw;
341                                    }
342                               }
343                             sp = spix;
344                             p = pix;
345                             for (py = 0; py < h; py++)
346                               {
347                                  for (px = 0; px < w; px++)
348                                    {
349                                       unsigned int mask, imask;
350                                       mask = ((unsigned int)(*sp)) << 24;
351                                       imask = mask >> 8;
352                                       imask |= imask >> 8;
353                                       imask |= imask >> 8;
354                                       *p = mask | (*p & imask);
355                                       sp++;
356                                       p++;
357                                    }
358                               }
359                             free(spix);
360                          }
361                        evas_object_image_data_set(co->img, pix);
362                        evas_object_image_data_update_add(co->img, 0, 0, w, h);
363                        EINA_LIST_FOREACH(co->img_mirror, ll, o)
364                          {
365                             evas_object_image_data_set(o, pix);
366                             evas_object_image_data_update_add(o, 0, 0, w, h);
367                          }
368                     }
369                }
370           }
371         else
372           {
373              if (cw->shaped)
374                {
375                   unsigned int *pix, *p;
376                   int w, h, px, py;
377
378                   evas_object_image_size_get(co->img, &w, &h);
379                   if ((w > 0) && (h > 0))
380                     {
381                        if (co->native) return;
382                        evas_object_image_alpha_set(co->img, 0);
383                        EINA_LIST_FOREACH(co->img_mirror, l, o)
384                          {
385                             evas_object_image_alpha_set(o, 1);
386                          }
387                        pix = evas_object_image_data_get(co->img, 1);
388                        if (pix)
389                          {
390                             p = pix;
391                             for (py = 0; py < h; py++)
392                               {
393                                  for (px = 0; px < w; px++)
394                                     *p |= 0xff000000;
395                               }
396                          }
397                        evas_object_image_data_set(co->img, pix);
398                        evas_object_image_data_update_add(co->img, 0, 0, w, h);
399                        EINA_LIST_FOREACH(co->img_mirror, ll, o)
400                          {
401                             evas_object_image_data_set(o, pix);
402                             evas_object_image_data_update_add(o, 0, 0, w, h);
403                          }
404                     }
405                }
406              // dont need to fix alpha chanel as blending
407              // should be totally off here regardless of
408              // alpha channel content
409           }
410      }
411 }
412
413 static void
414 _e_mod_comp_win_update(E_Comp_Win *cw)
415 {
416    E_Update_Rect *r;
417    int i;
418    E_Comp_Canvas *canvas = NULL;
419    Eina_List *l = NULL;
420
421    e_mod_comp_x_grab_set(cw->c, EINA_TRUE);
422    cw->update = 0;
423
424    if (cw->argb)
425      {
426         if (cw->rects)
427           {
428              free(cw->rects);
429              cw->rects = NULL;
430              cw->rects_num = 0;
431           }
432      }
433    else
434      {
435         if (cw->shape_changed)
436           {
437              if (cw->rects)
438                {
439                   free(cw->rects);
440                   cw->rects = NULL;
441                   cw->rects_num = 0;
442                }
443              ecore_x_pixmap_geometry_get(cw->win, NULL, NULL, &(cw->w), &(cw->h));
444              cw->rects = ecore_x_window_shape_rectangles_get(cw->win, &(cw->rects_num));
445              if (cw->rects)
446                {
447                   for (i = 0; i < cw->rects_num; i++)
448                     {
449                        E_RECTS_CLIP_TO_RECT(cw->rects[i].x,
450                                             cw->rects[i].y,
451                                             cw->rects[i].width,
452                                             cw->rects[i].height,
453                                             0, 0, cw->w, cw->h);
454                     }
455                }
456              if (!_e_mod_comp_win_shaped_check(cw, cw->rects, cw->rects_num))
457                {
458                   free(cw->rects);
459                   cw->rects = NULL;
460                   cw->rects_num = 0;
461                }
462              if ((cw->rects) && (!cw->shaped))
463                {
464                   cw->shaped = 1;
465                }
466              else if ((!cw->rects) && (cw->shaped))
467                {
468                   cw->shaped = 0;
469                }
470           }
471      }
472
473    if ((cw->needpix) && (cw->dmg_updates <= 0))
474      {
475         e_mod_comp_x_grab_set(cw->c, EINA_FALSE);
476         return;
477      }
478
479    if ((!cw->pixmap) || (cw->needpix))
480      {
481         Ecore_X_Pixmap pm = 0;
482         // named pixmap of the nocomp window will be updated in
483         // nocomp_dispose function after the damage event
484         if (cw->nocomp)
485           {
486              e_mod_comp_x_grab_set(cw->c, EINA_FALSE);
487              return;
488           }
489         pm = ecore_x_composite_name_window_pixmap_get(cw->win);
490         if (pm)
491           {
492              Ecore_X_Pixmap oldpm;
493              cw->needpix = 0;
494              e_mod_comp_win_comp_objs_needxim_set(cw, 1);
495              oldpm = cw->pixmap;
496              cw->pixmap = pm;
497              if (cw->pixmap)
498                {
499                   ecore_x_pixmap_geometry_get(cw->pixmap, NULL, NULL, &(cw->pw), &(cw->ph));
500                   // pixmap's size is not equal with window's size case
501                   if (!((cw->pw == (cw->w + cw->border * 2)) &&
502                        (cw->ph == (cw->h + cw->border *2))))
503                     {
504                        cw->pw = cw->w;
505                        cw->ph = cw->h;
506                        cw->pixmap = oldpm;
507                        cw->needpix = 1;
508                        ecore_x_pixmap_free(pm);
509                        e_mod_comp_x_grab_set(cw->c, EINA_FALSE);
510                        return;
511                     }
512                   if ((cw->pw > 0) && (cw->ph > 0))
513                     e_mod_comp_win_comp_objs_img_resize(cw, cw->pw, cw->ph);
514                }
515              else
516                {
517                   cw->pw = 0;
518                   cw->ph = 0;
519                }
520              if ((cw->pw <= 0) || (cw->ph <= 0))
521                {
522                   e_mod_comp_win_comp_objs_img_deinit(cw);
523                   if (cw->pixmap)
524                     {
525                        ecore_x_pixmap_free(cw->pixmap);
526                        cw->pixmap = 0;
527                     }
528                   cw->pw = 0;
529                   cw->ph = 0;
530                }
531              ecore_x_e_comp_pixmap_set(cw->win, cw->pixmap);
532              e_mod_comp_win_comp_objs_native_set(cw, 0);
533              e_mod_comp_update_resize(cw->up, cw->pw, cw->ph);
534              e_mod_comp_update_add(cw->up, 0, 0, cw->pw, cw->ph);
535              if (oldpm) ecore_x_pixmap_free(oldpm);
536           }
537      }
538
539    if (!((cw->pw > 0) && (cw->ph > 0)))
540      {
541         e_mod_comp_x_grab_set(cw->c, EINA_FALSE);
542         return;
543      }
544
545    e_mod_comp_win_comp_objs_move(cw, cw->x, cw->y);
546    e_mod_comp_win_comp_objs_resize(cw, cw->pw, cw->ph);
547
548    //update old geometry due to finish resize
549    cw->resizing.x = cw->x;
550    cw->resizing.y = cw->y;
551
552    if (((cw->c->gl  && _comp_mod->conf->texture_from_pixmap) || _comp_mod->conf->use_efl_native_surface)
553        && (!cw->shaped)
554        && (!cw->rects))
555      {
556         e_mod_comp_win_comp_objs_img_size_set(cw, cw->pw, cw->ph);
557         e_mod_comp_win_comp_objs_img_init(cw);
558
559         r = e_mod_comp_update_rects_get(cw->up);
560         if (r)
561           {
562              for (i = 0; r[i].w > 0; i++)
563                {
564                   int x, y, w, h;
565                   x = r[i].x; y = r[i].y;
566                   w = r[i].w; h = r[i].h;
567                   e_mod_comp_win_comp_objs_img_data_update_add(cw, x, y, w, h);
568
569                   /* check update region */
570                   if (_comp_mod->conf->use_hwc)
571                     {
572                        if (cw->c->hwcomp_funcs.check_win_update)
573                           cw->c->hwcomp_funcs.check_win_update(cw, w, h);
574                     }
575                }
576              e_mod_comp_update_clear(cw->up);
577              free(r);
578           }
579      }
580    else
581      {
582         Eina_List *l, *ll;
583         E_Comp_Object *co;
584         Evas_Object *o;
585         EINA_LIST_FOREACH(cw->objs, l, co)
586           {
587              if (co->native)
588                {
589                   evas_object_image_native_surface_set(co->img, NULL);
590                   EINA_LIST_FOREACH(co->img_mirror, ll, o)
591                     {
592                        evas_object_image_native_surface_set(o, NULL);
593                     }
594                   co->native = 0;
595                }
596              if (co->needxim)
597                {
598                   co->needxim = 0;
599                   if (co->xim)
600                     {
601                        evas_object_image_size_set(co->img, 1, 1);
602                        evas_object_image_data_set(co->img, NULL);
603                        EINA_LIST_FOREACH(co->img_mirror, ll, o)
604                          {
605                             evas_object_image_size_set(o, 1, 1);
606                             evas_object_image_data_set(o, NULL);
607                          }
608                        ecore_x_image_free(co->xim);
609                        co->xim = NULL;
610                     }
611                }
612              if (!co->xim)
613                {
614                   if ((co->xim = ecore_x_image_new(cw->pw, cw->ph, cw->vis, cw->depth)))
615                     e_mod_comp_update_add(cw->up, 0, 0, cw->pw, cw->ph);
616                }
617           }
618         r = e_mod_comp_update_rects_get(cw->up);
619         if (r)
620           {
621              EINA_LIST_FOREACH(cw->objs, l, co)
622                {
623                   if (co->xim)
624                     {
625                        unsigned int *pix;
626
627                        pix = ecore_x_image_data_get(co->xim, NULL, NULL, NULL);
628                        evas_object_image_data_set(co->img, pix);
629                        evas_object_image_size_set(co->img, cw->pw, cw->ph);
630                        EINA_LIST_FOREACH(co->img_mirror, ll, o)
631                          {
632                             evas_object_image_data_set(o, pix);
633                             evas_object_image_size_set(o, cw->pw, cw->ph);
634                          }
635
636                        e_mod_comp_update_clear(cw->up);
637                        for (i = 0; r[i].w > 0; i++)
638                          {
639                             int x, y, w, h;
640                             x = r[i].x; y = r[i].y;
641                             w = r[i].w; h = r[i].h;
642                             if (!ecore_x_image_get(co->xim, cw->pixmap, x, y, x, y, w, h))
643                               {
644                                  e_mod_comp_update_add(cw->up, x, y, w, h);
645                                  cw->update = 1;
646                               }
647                             else
648                               {
649                                  // why do we neeed these 2? this smells wrong
650                                  pix = ecore_x_image_data_get(co->xim, NULL, NULL, NULL);
651                                  evas_object_image_data_set(co->img, pix);
652                                  evas_object_image_data_update_add(co->img, x, y, w, h);
653                                  EINA_LIST_FOREACH(co->img_mirror, ll, o)
654                                    {
655                                       evas_object_image_data_set(o, pix);
656                                       evas_object_image_data_update_add(o, x, y, w, h);
657                                    }
658                               }
659                          }
660                     }
661                }
662              free(r);
663              if (cw->shaped)
664                {
665                   _e_mod_comp_win_shape_rectangles_apply(cw, cw->rects, cw->rects_num);
666                }
667              else
668                {
669                   if (cw->shape_changed)
670                     _e_mod_comp_win_shape_rectangles_apply(cw, cw->rects, cw->rects_num);
671                }
672              cw->shape_changed = 0;
673           }
674      }
675
676    e_mod_comp_win_comp_objs_show(cw);
677
678    if (_comp_mod->conf->use_hwc)
679      {
680         if ((cw->hwc.set_drawable) && (cw->c->hwcomp_funcs.win_update))
681              cw->c->hwcomp_funcs.win_update(cw);
682      }
683
684    e_mod_comp_x_grab_set(cw->c, EINA_FALSE);
685
686    if (_comp_mod->conf->stand_by_canvas_render_enable)
687      {
688         if ((cw->visible) && (cw->c) && (cw->c->stand_by_canvas_render))
689           {
690              cw->c->stand_by_canvas_render = 0;
691
692              EINA_LIST_FOREACH(cw->c->canvases, l, canvas)
693                {
694                   ELBF(ELBT_COMP, 0, 0, "STAND BY CANVAS RENDER UNSET");
695                   if (ecore_evas_manual_render_get(canvas->ee) == EINA_TRUE)
696                      ecore_evas_manual_render_set(canvas->ee, 0);
697                }
698           }
699      }
700 }
701
702 static void
703 _e_mod_comp_win_transparent_rect_update(E_Comp_Win *cw)
704 {
705    Ecore_X_Window win;
706    unsigned int val[4] = { 0, }; // offset and size
707    int ret = -1;
708
709    win = e_mod_comp_util_client_xid_get(cw);
710
711    ret = ecore_x_window_prop_card32_get
712            (win, ATOM_CM_TRANSPARENT_RECT, val, 4);
713    if (ret <= 0)
714      {
715         cw->transp_rect.use = EINA_FALSE;
716         cw->transp_rect.x = 0;
717         cw->transp_rect.y = 0;
718         cw->transp_rect.w = 0;
719         cw->transp_rect.h = 0;
720      }
721    else
722      {
723         cw->transp_rect.use = EINA_TRUE;
724         cw->transp_rect.x = val[0];
725         cw->transp_rect.y = val[1];
726         cw->transp_rect.w = val[2];
727         cw->transp_rect.h = val[3];
728      }
729
730    e_mod_comp_win_comp_objs_transparent_rect_update(cw);
731 }
732
733 // set XRandr RROutput property according to viewmode
734 static Eina_Bool
735 _e_mod_comp_win_rr_output_prop_set(Ecore_X_Window win, unsigned int mode)
736 {
737    XRRScreenResources *resources = NULL;
738    Atom view_mode;
739    RROutput output = 0;
740    unsigned int op_num;
741    Data_Rrprop prop_data;
742    Ecore_X_Display *x_disp = ecore_x_display_get();
743
744    if (win)
745        resources = XRRGetScreenResources(x_disp, win);
746    else
747        resources = XRRGetScreenResources(x_disp, ecore_x_window_root_first_get());
748    if ((!resources) || (resources->noutput <= 0))
749       return EINA_FALSE;
750
751    for (op_num = 0; op_num < resources->noutput; op_num++)
752     {
753       output = resources->outputs[op_num];
754       view_mode = ATOM_CM_STEREOSCOPIC_MODE;
755       if (view_mode == None)
756         {
757            printf("RR property is not suppported \n");
758            return EINA_FALSE;
759         }
760
761        if (win)
762          {
763            prop_data.win = win;
764          }
765        else
766         {
767           prop_data.win = NULL;
768         }
769
770        prop_data.value = mode;
771        XRRChangeOutputProperty(x_disp, output, view_mode, XA_INTEGER, 32,
772             PropModeReplace, (unsigned char *)&prop_data, 2);
773      }
774     XRRFreeScreenResources(resources);
775     return EINA_TRUE;
776 }
777
778 // interfacing of compositor with stereoscopic mode (3D App, 2D App & Multimedia content)
779 static Eina_Bool
780 _e_mod_comp_win_stereo_layout_set(Ecore_X_Window win, unsigned int mode)
781 {
782    unsigned int view_mode = 0;
783    int ret = -1;
784    E_Comp_Win *cw = NULL;
785    E_Zone *zone = NULL;
786
787    cw = _e_mod_comp_win_find(win);
788    if (!cw)
789      {
790         cw = _e_mod_comp_border_client_find(win);
791         E_CHECK_RETURN(cw, 0);
792      }
793
794    ret = ecore_x_window_prop_card32_get
795       (win, ATOM_CM_3D_APP_WIN, &view_mode , 1);
796    if (ret <= 0)
797      {
798         cw->win3d = EINA_FALSE;
799         if (mode < 4) /*2D app and 3D multimedia content*/
800           {
801              E_Comp *c = (E_Comp *)(cw->c);
802              E_Comp_Canvas *canvas = NULL;
803              Eina_List *l;
804
805              E_CHECK_RETURN(c, NULL);
806
807              zone = cw->bd->zone;
808
809              EINA_LIST_FOREACH(c->canvases, l, canvas)
810               {
811                 if (!canvas) continue;
812
813                 if(canvas->zone == zone) canvas->stereoscopic_mode = mode;
814
815                 e_mod_comp_canvas_stereo_layout_set(canvas);
816               }
817           }
818      }
819    else
820      {
821         if (view_mode > 0)      /*3D application window case */
822           {
823             cw->win3d = EINA_TRUE;
824             //do nothing in case of 3D app, 3D app will take care
825           }
826      }
827    return EINA_TRUE;
828 }
829
830 // added handler for RR Output property notification (instead of API calling from device manager)
831 static int
832 _e_mod_comp_cb_rr_output_prop(void *data, int type, void *ev)
833 {
834    if (type == ECORE_X_EVENT_RANDR_OUTPUT_PROPERTY_NOTIFY)
835     {
836       Ecore_X_Event_Randr_Output_Property_Notify *event = (Ecore_X_Event_Randr_Output_Property_Notify *)ev;
837       /* available information:
838          struct _Ecore_X_Event_Randr_Output_Property_Notify
839          {
840          Ecore_X_Window                win;
841          Ecore_X_Randr_Output          output;
842          Ecore_X_Atom                  property;
843          Ecore_X_Time                  time;
844          Ecore_X_Randr_Property_Change state;
845          };
846        */
847
848       char *atom_name = ecore_x_atom_name_get(event->property);
849
850       // checking and retrieving 3D stereoscopic mode
851       if ((atom_name) && (strcmp(atom_name, "_E_COMP_STEREOSCOPIC_MODE") == 0))
852         {
853           Ecore_X_Display *x_disp = ecore_x_display_get();
854           Atom actual_type;
855           int actual_format;
856           unsigned int value;
857           unsigned long nitems;
858           unsigned long bytes_after;
859           Data_Rrprop *prop_data;
860
861
862           if (XRRGetOutputProperty(x_disp, event->output, ATOM_CM_STEREOSCOPIC_MODE,
863                0, 4, False, False, None, &actual_type, &actual_format,
864                &nitems, &bytes_after, &prop_data) != Success)
865             {
866               fprintf(stderr,"DeviceManager :: stereoMode not valid \n");
867               if (atom_name) free(atom_name);
868               return EINA_FALSE;
869             }
870
871           if ((actual_type != XA_INTEGER) || (nitems != 2) || (actual_format != 32))
872             {
873               fprintf(stderr,"DeviceManager :: stereoMode prop value not correct \n");
874               if (atom_name) free(atom_name);
875               return EINA_FALSE;
876             }
877
878           value = ((Data_Rrprop *)prop_data)->value;
879
880           // taking specific action in compositor based on stereoscopic mode
881           if (((Data_Rrprop *)prop_data)->win != NULL)
882              _e_mod_comp_win_stereo_layout_set(((Data_Rrprop *)prop_data)->win, value);
883        }
884
885       if (atom_name) free(atom_name);
886     }
887    return EINA_TRUE;
888 }
889
890 #ifdef _F_USE_BORDER_TRANSFORM_
891 static Eina_Bool
892 _e_mod_comp_bd_transform_changed(void *data __UNUSED__,
893                                  int type __UNUSED__,
894                                  void *event)
895 {
896    E_Event_Border_Transform_Changed* ev = event;
897    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
898    if (!cw) return ECORE_CALLBACK_PASS_ON;
899    e_mod_comp_win_comp_objs_img_transform_set(cw, EINA_FALSE);
900    //_e_mod_comp_win_damage(cw, 0, 0, cw->w, cw->h, 0);
901    return ECORE_CALLBACK_PASS_ON;
902 }
903 #endif /* End of _F_USE_BORDER_TRANSFORM_ */
904
905 static Eina_Bool
906 _e_mod_comp_cb_delayed_update_timer(void *data)
907 {
908    E_Comp *c = data;
909    _e_mod_comp_render_queue(c);
910    c->new_up_timer = NULL;
911    return ECORE_CALLBACK_CANCEL;
912 }
913
914 static Eina_Bool
915 _e_mod_comp_cb_update(E_Comp *c)
916 {
917    E_Comp_Win *cw;
918    Eina_List *l;
919    E_Comp_Canvas *canvas = NULL;
920    Eina_List *new_updates = NULL;
921    Eina_List *update_done = NULL;
922
923    traceBegin(TTRACE_TAG_WINDOW_MANAGER,"WM:COMP:UPDATE CB");
924
925    c->update_job = NULL;
926
927    if (_comp_mod->conf->nocomp_fs)
928      {
929         EINA_LIST_FOREACH(c->canvases, l, canvas)
930           {
931              if (canvas->nocomp.mode != E_NOCOMP_MODE_RUN) continue;
932              cw = e_mod_comp_canvas_fullscreen_check(canvas);
933              if ((!cw) || (cw != canvas->nocomp.cw) ||
934                  (canvas->nocomp.force_composite))
935                {
936                   ELBF(ELBT_COMP, 0,
937                        cw ? e_mod_comp_util_client_xid_get(cw) : 0,
938                        "NOCOMP_END nocomp.cw:0x%08x canvas:%d",
939                        e_mod_comp_util_client_xid_get(canvas->nocomp.cw),
940                        canvas->num);
941
942                   e_mod_comp_canvas_nocomp_end(canvas);
943                }
944           }
945      }
946
947    e_mod_comp_x_grab_set(c, EINA_TRUE);
948
949    EINA_LIST_FREE(c->updates, cw)
950      {
951         if (!cw) continue;
952         if (_comp_mod->conf->efl_sync)
953           {
954              if ((((cw->counter) && (cw->drawme)) || (!cw->counter)) && (cw->sync_info.version))
955                {
956 #ifdef _F_IGNORE_DMG_HIDE_
957                   if(!cw->ignore_dmg)
958                     {
959                        _e_mod_comp_win_update(cw);
960                     }
961                   else
962                     {
963                        cw->update = 0;
964                        ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw), "%15.15s| skip render", "IGNORE_DMG");
965                     }
966 #else
967                   _e_mod_comp_win_update(cw);
968 #endif
969                   if (cw->drawme)
970                     {
971                        update_done = eina_list_append(update_done, cw);
972                        cw->drawme = 0;
973                     }
974                }
975              else
976                cw->update = 0;
977           }
978         else
979           {
980 #ifdef _F_IGNORE_DMG_HIDE_
981              if(!cw->ignore_dmg)
982                {
983                   _e_mod_comp_win_update(cw);
984                }
985              else
986                {
987                   cw->update = 0;
988                   ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw), "%15.15s| skip render2", "IGNORE_DMG");
989                }
990 #else
991              _e_mod_comp_win_update(cw);
992 #endif
993           }
994
995
996         if (cw->update)
997           new_updates = eina_list_append(new_updates, cw);
998      }
999
1000    if (_comp_mod->conf->efl_sync)
1001      {
1002         EINA_LIST_FREE(update_done, cw)
1003           {
1004              if (!cw) continue;
1005              ecore_x_sync_counter_inc(cw->counter, 1);
1006              cw->sync_info.val++;
1007
1008              ELBF(ELBT_COMP_RENDER, 0, e_mod_comp_util_client_xid_get(cw),
1009                   "%15.15s|done:%d val:%d", "INC",
1010                   cw->sync_info.done_count, cw->sync_info.val);
1011           }
1012      }
1013    e_mod_comp_win_shape_input_update(c);
1014    e_mod_comp_x_grab_set(c, EINA_FALSE);
1015
1016    if (new_updates)
1017      {
1018         if (c->new_up_timer) ecore_timer_del(c->new_up_timer);
1019         c->new_up_timer =
1020           ecore_timer_add(0.001, _e_mod_comp_cb_delayed_update_timer, c);
1021      }
1022    c->updates = new_updates;
1023    if (!c->animating) c->render_overflow--;
1024
1025    c->effect_funcs.signal_flush();
1026
1027    if (_comp_mod->conf->use_hwc)
1028      {
1029         EINA_LIST_FOREACH(c->canvases, l, canvas)
1030           {
1031              if (!canvas->hwcomp) continue;
1032              if (c->hwcomp_funcs.cb_update)
1033                {
1034                   if (!c->hwcomp_funcs.cb_update(canvas->hwcomp))
1035                     {
1036                        traceEnd(TTRACE_TAG_WINDOW_MANAGER);
1037                        return ECORE_CALLBACK_RENEW;
1038                     }
1039                }
1040           }
1041      }
1042
1043    if (c->render_overflow <= 0)
1044      {
1045         c->render_overflow = 0;
1046         if (c->render_animator) c->render_animator = NULL;
1047         traceEnd(TTRACE_TAG_WINDOW_MANAGER);
1048         return ECORE_CALLBACK_CANCEL;
1049      }
1050
1051    traceEnd(TTRACE_TAG_WINDOW_MANAGER);
1052    return ECORE_CALLBACK_RENEW;
1053 }
1054
1055 static void
1056 _e_mod_comp_cb_job(void *data)
1057 {
1058    _e_mod_comp_cb_update(data);
1059 }
1060
1061 static Eina_Bool
1062 _e_mod_comp_cb_animator(void *data)
1063 {
1064    return _e_mod_comp_cb_update(data);
1065 }
1066
1067 static void
1068 _e_comp_event_src_visibility_free(void *data __UNUSED__,
1069                                   void      *event)
1070 {
1071    E_Event_Comp_Source_Visibility *ev = event;
1072    E_FREE(ev);
1073 }
1074
1075 static void
1076 _e_mod_comp_render_queue(E_Comp *c)
1077 {
1078    E_CHECK(c);
1079
1080    if (_comp_mod->conf->lock_fps)
1081      {
1082         if (c->render_animator)
1083           {
1084              c->render_overflow = OVER_FLOW;
1085              return;
1086           }
1087         c->render_animator = ecore_animator_add(_e_mod_comp_cb_animator, c);
1088      }
1089    else
1090      {
1091         if (c->update_job)
1092           {
1093              ecore_job_del(c->update_job);
1094              c->update_job = NULL;
1095              c->render_overflow = 0;
1096           }
1097         c->update_job = ecore_job_add(_e_mod_comp_cb_job, c);
1098      }
1099 }
1100
1101 static void
1102 _e_mod_comp_win_render_queue(E_Comp_Win *cw)
1103 {
1104    E_CHECK(cw);
1105    E_CHECK(cw->c);
1106
1107    _e_mod_comp_render_queue(cw->c);
1108 }
1109
1110 static E_Comp *
1111 _e_mod_comp_find(Ecore_X_Window root)
1112 {
1113    Eina_List *l;
1114    E_Comp *c;
1115    EINA_LIST_FOREACH(compositors, l, c)
1116      {
1117         if (!c) continue;
1118         if (c->man->root == root) return c;
1119      }
1120    return NULL;
1121 }
1122
1123 static E_Comp_Win *
1124 _e_mod_comp_win_find(Ecore_X_Window win)
1125 {
1126    return eina_hash_find(windows, e_util_winid_str_get(win));
1127 }
1128
1129 static E_Comp_Win *
1130 _e_mod_comp_border_client_find(Ecore_X_Window win)
1131 {
1132    return eina_hash_find(borders, e_util_winid_str_get(win));
1133 }
1134
1135 /* wrapper function for external file */
1136 EAPI E_Comp_Win *
1137 e_mod_comp_win_find(Ecore_X_Window win)
1138 {
1139    return _e_mod_comp_win_find(win);
1140 }
1141
1142 EAPI E_Comp_Win *
1143 e_mod_comp_border_client_find(Ecore_X_Window win)
1144 {
1145    return _e_mod_comp_border_client_find(win);
1146 }
1147
1148 EAPI E_Comp *
1149 e_mod_comp_find(Ecore_X_Window win)
1150 {
1151    E_CHECK_RETURN(win, 0);
1152    return _e_mod_comp_find(win);
1153 }
1154
1155 EAPI void
1156 e_mod_comp_render_queue(E_Comp *c)
1157 {
1158     E_CHECK(c);
1159    _e_mod_comp_render_queue(c);
1160 }
1161
1162 EAPI void
1163 e_mod_comp_win_render_queue(E_Comp_Win *cw)
1164 {
1165    E_CHECK(cw);
1166    _e_mod_comp_win_render_queue(cw);
1167 }
1168
1169 EAPI Eina_Bool
1170 e_mod_comp_win_damage_timeout(void *data)
1171 {
1172    E_CHECK_RETURN(data, 0);
1173    return _e_mod_comp_win_damage_timeout(data);
1174 }
1175
1176 EAPI Eina_Bool
1177 e_mod_comp_cb_update(E_Comp *c)
1178 {
1179    E_CHECK_RETURN(c, 0);
1180    return _e_mod_comp_cb_update(c);
1181 }
1182
1183 EAPI Evas_Object *
1184 e_mod_comp_win_mirror_add(E_Comp_Win *cw)
1185 {
1186    E_CHECK_RETURN(cw, 0);
1187    return _e_mod_comp_win_mirror_add(cw);
1188 }
1189
1190 EAPI void
1191 e_mod_comp_cb_win_mirror_del(void        *data,
1192                              Evas        *e,
1193                              Evas_Object *obj,
1194                              void        *event_info)
1195 {
1196    E_CHECK(data);
1197    _e_mod_comp_cb_win_mirror_del(data,
1198                                  e,
1199                                  obj,
1200                                  event_info);
1201 }
1202
1203 EAPI void
1204 e_mod_comp_src_hidden_set_func(void                  *data,
1205                                E_Manager             *man,
1206                                E_Manager_Comp_Source *src,
1207                                Eina_Bool              hidden)
1208 {
1209    _e_mod_comp_src_hidden_set_func(data, man, src, hidden);
1210 }
1211
1212 static E_Comp_Win *
1213 _e_mod_comp_win_damage_find(Ecore_X_Damage damage)
1214 {
1215    return eina_hash_find(damages, e_util_winid_str_get(damage));
1216 }
1217
1218 static Eina_Bool
1219 _e_mod_comp_win_is_borderless(E_Comp_Win *cw)
1220 {
1221    if (!cw->bd) return 1;
1222    if ((cw->bd->client.border.name) &&
1223        (!strcmp(cw->bd->client.border.name, "borderless")))
1224      return 1;
1225    return 0;
1226 }
1227
1228 static Eina_Bool
1229 _e_mod_comp_win_damage_timeout(void *data)
1230 {
1231    E_Comp_Win *cw = data;
1232    E_CHECK_RETURN(cw, 0);
1233
1234    if (!cw->update)
1235      {
1236         if (cw->update_timeout)
1237           {
1238              ecore_timer_del(cw->update_timeout);
1239              cw->update_timeout = NULL;
1240           }
1241 #if 0
1242         // do not render by dmg_timeout.
1243         // only render when received sync_draw_done.
1244         cw->update = 1;
1245         cw->c->updates = eina_list_append(cw->c->updates, cw);
1246 #endif
1247      }
1248
1249    ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
1250         "%15.15s|%dx%d p:%dx%d dmg:%d NO_DRAWDONE", "DMG_TIMEOUT",
1251         cw->w, cw->h, cw->pw, cw->ph, cw->dmg_updates);
1252 #if 0
1253    // do not render by dmg_timeout.
1254    // only render when received sync_draw_done.
1255    cw->drawme = 1;
1256    _e_mod_comp_win_render_queue(cw);
1257 #endif
1258    if (cw->update_timeout)
1259      {
1260         ecore_timer_del(cw->update_timeout);
1261         cw->update_timeout = NULL;
1262      }
1263    return ECORE_CALLBACK_CANCEL;
1264 }
1265
1266 static void
1267 _e_mod_comp_object_del(void *data,
1268                        void *obj)
1269 {
1270    E_Comp_Win *cw = (E_Comp_Win *)data;
1271    E_CHECK(cw);
1272
1273    _e_mod_comp_win_render_queue(cw);
1274
1275    if (obj == cw->bd)
1276      {
1277         ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
1278              "%15.15s|", "OBJECT_DEL");
1279
1280         if (cw->counter)
1281           {
1282              Ecore_X_Window _w = e_mod_comp_util_client_xid_get(cw);
1283              ecore_x_e_comp_sync_cancel_send(_w);
1284              ecore_x_sync_counter_inc(cw->counter, 1);
1285              cw->sync_info.val++;
1286
1287              ELBF(ELBT_COMP, 1, _w, "%15.15s", "SYNC_CANCEL");
1288           }
1289         if (cw->bd) eina_hash_del(borders, e_util_winid_str_get(cw->bd->client.win), cw);
1290         cw->bd = NULL;
1291         e_mod_comp_win_comp_objs_data_del(cw, "border");
1292      }
1293    else if (obj == cw->pop)
1294      {
1295         cw->pop = NULL;
1296         e_mod_comp_win_comp_objs_data_del(cw, "popup");
1297      }
1298    else if (obj == cw->menu)
1299      {
1300         cw->menu = NULL;
1301         e_mod_comp_win_comp_objs_data_del(cw, "menu");
1302      }
1303    if (cw->dfn)
1304      {
1305         e_object_delfn_del(obj, cw->dfn);
1306         cw->dfn = NULL;
1307      }
1308 }
1309
1310 EAPI void
1311 e_mod_comp_done_defer(E_Comp_Win *cw)
1312 {
1313    E_CHECK(cw);
1314    cw->c->effect_funcs.animating_set(cw->c, cw, EINA_FALSE);
1315
1316    cw->force = 1;
1317    if (cw->defer_hide)
1318      {
1319         ELBF(ELBT_COMP, 0,
1320              e_mod_comp_util_client_xid_get(cw),
1321              "EDJ_DONE Force win to hide bd:%d",
1322              cw->bd);
1323
1324         _e_mod_comp_win_hide(cw);
1325      }
1326    cw->force = 1;
1327    if (cw->delete_me)
1328      {
1329         ELBF(ELBT_COMP, 0,
1330              e_mod_comp_util_client_xid_get(cw),
1331              "EDJ_DONE Force win to del bd:%d",
1332              cw->bd);
1333
1334         _e_mod_comp_win_del(cw);
1335      }
1336    else cw->force = 0;
1337 }
1338
1339 static void
1340 _e_mod_comp_show_done(void        *data,
1341                       Evas_Object *obj,
1342                       const char  *emission __UNUSED__,
1343                       const char  *source   __UNUSED__)
1344 {
1345    E_Comp_Win *cw = (E_Comp_Win *)data;
1346    E_CHECK(cw);
1347
1348    SECURE_SLOGD("[e17:Application:Launching:done] win:0x%07x name:%s",
1349                 cw->bd ? cw->bd->client.win : cw->win,
1350                 cw->bd ? cw->bd->client.netwm.name : NULL);
1351
1352    ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
1353         "%15.15s|SHOW_DONE", "SIGNAL");
1354
1355    cw->c->effect_funcs.signal_del(cw, obj, "show,done");
1356
1357    cw->launched = EINA_TRUE;
1358    cw->show_done = EINA_TRUE;
1359    e_mod_comp_done_defer(cw);
1360 }
1361
1362 static void
1363 _e_mod_comp_hide_done(void        *data,
1364                       Evas_Object *obj,
1365                       const char  *emission __UNUSED__,
1366                       const char  *source   __UNUSED__)
1367 {
1368    E_Comp_Win *cw = (E_Comp_Win *)data;
1369    E_CHECK(cw);
1370
1371    ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
1372         "%15.15s|HIDE_DONE", "SIGNAL");
1373
1374    cw->c->effect_funcs.signal_del(cw, obj, "hide,done");
1375
1376    cw->show_done = EINA_FALSE;
1377
1378 #ifdef _F_IGNORE_DMG_HIDE_
1379    if (!cw->visible)
1380      {
1381         cw->ignore_dmg = 1;
1382         ELBF(ELBT_COMP, 0, cw->win, "%15.15s| set 1", "IGNORE_DMG");
1383      }
1384    else
1385      {
1386         ELBF(ELBT_COMP, 0, cw->win, "%15.15s| set 1 BUT Skip. Because this is visible current.", "IGNORE_DMG");
1387      }
1388 #endif
1389
1390    e_mod_comp_done_defer(cw);
1391 }
1392
1393 static void
1394 _e_mod_comp_win_sync_setup(E_Comp_Win *cw,
1395                            Ecore_X_Window win)
1396 {
1397    if (!_comp_mod->conf->efl_sync) return;
1398    if (cw->bd)
1399      {
1400         if (_e_mod_comp_win_is_borderless(cw) ||
1401             (_comp_mod->conf->loose_sync))
1402           {
1403              cw->counter = ecore_x_e_comp_sync_counter_get(win);
1404           }
1405         else
1406           {
1407              ecore_x_e_comp_sync_cancel_send(win);
1408              cw->counter = 0;
1409           }
1410      }
1411    else
1412      cw->counter = ecore_x_e_comp_sync_counter_get(win);
1413
1414    if (cw->counter)
1415      {
1416         if (cw->bd)
1417           {
1418              E_Comp_Win *client_cw = _e_mod_comp_win_find(win);
1419              if (client_cw &&
1420                  client_cw->counter == cw->counter)
1421                {
1422                   ecore_x_sync_counter_inc(cw->counter, 1);
1423                   cw->sync_info.val++;
1424                   return;
1425                }
1426           }
1427
1428         ecore_x_e_comp_sync_begin_send(win);
1429         ecore_x_sync_counter_inc(cw->counter, 1);
1430         cw->sync_info.val++;
1431      }
1432 }
1433
1434 static void
1435 _e_mod_comp_win_shadow_setup_error_get(E_Comp_Win  *cw,
1436                                        Evas_Object *o,
1437                                        const char  *msg,
1438                                        const char  *file)
1439 {
1440    Ecore_X_Window win = e_mod_comp_util_client_xid_get(cw);
1441
1442    fprintf(stdout,
1443            "[E17-comp] EDC file ERROR win:0x%08x o:%p %s FILE:%s\n",
1444            win, o, msg, file);
1445
1446    ELBF(ELBT_COMP, 0, win,
1447         "%15.15s|ERROR o:%p %s",
1448         "EDC", o, msg);
1449
1450    ELBF(ELBT_COMP, 0, win,
1451         "%15.15s|ERROR FILE:%s",
1452         "EDC", file);
1453
1454    e_mod_comp_debug_edje_error_get(o, win);
1455 }
1456
1457 EAPI void
1458 e_mod_comp_win_shadow_setup(E_Comp_Win    *cw,
1459                             E_Comp_Object *co)
1460 {
1461    Evas_Object *o;
1462    int ok = 0;
1463    char buf[PATH_MAX];
1464    Eina_List *l;
1465
1466    evas_object_image_smooth_scale_set(co->img, _comp_mod->conf->smooth_windows);
1467    EINA_LIST_FOREACH(co->img_mirror, l, o)
1468      {
1469         evas_object_image_smooth_scale_set(o, _comp_mod->conf->smooth_windows);
1470      }
1471
1472    if (_comp_mod->conf->shadow_file)
1473      {
1474         ok = edje_object_file_set
1475           (co->shadow, _comp_mod->conf->shadow_file,
1476           e_mod_comp_policy_win_shadow_group_get(cw));
1477
1478         ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
1479              "%15.15s|GROUP:%s", "EDC",
1480              e_mod_comp_policy_win_shadow_group_get(cw));
1481      }
1482
1483    if (!ok)
1484      {
1485         _e_mod_comp_win_shadow_setup_error_get
1486           (cw, co->shadow, "SHADOW_FILE",
1487           _comp_mod->conf->shadow_file);
1488
1489         if (_comp_mod->conf->shadow_style)
1490           {
1491              snprintf(buf, sizeof(buf), "e/comp/%s",
1492                       _comp_mod->conf->shadow_style);
1493
1494              ok = e_theme_edje_object_set(co->shadow,
1495                                           "base/theme/borders",
1496                                           buf);
1497           }
1498         if (!ok)
1499           {
1500              _e_mod_comp_win_shadow_setup_error_get
1501                (cw, co->shadow, "STYLE",
1502                _comp_mod->conf->shadow_style);
1503
1504              ok = e_theme_edje_object_set(co->shadow,
1505                                           "base/theme/borders",
1506                                           "e/comp/default");
1507           }
1508      }
1509    // fallback to local shadow.edj - will go when default theme supports this
1510    if (!ok)
1511      {
1512         _e_mod_comp_win_shadow_setup_error_get
1513           (cw, co->shadow, "STYLE_DEFAULT",
1514           "e/comp/default");
1515
1516         snprintf(buf, sizeof(buf), "%s/shadow.edj",
1517                  e_module_dir_get(_comp_mod->module));
1518         ok = edje_object_file_set(co->shadow, buf, "shadow");
1519
1520         if (!ok)
1521           {
1522              _e_mod_comp_win_shadow_setup_error_get
1523                (cw, co->shadow, "LOCAL", buf);
1524           }
1525      }
1526    if (!edje_object_part_swallow(co->shadow,
1527                                  "e.swallow.content",
1528                                  co->img))
1529      {
1530         fprintf(stdout,
1531                 "[E17-comp] EDC swallow ERROR win:0x%08x %s(%d) o:%p img:%p\n",
1532                 cw->win, __func__, __LINE__, co->shadow, co->img);
1533
1534         ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
1535              "%15.15s|SWALLOW_ERROR o:%p img:%p",
1536              "EDC", co->shadow, co->img);
1537      }
1538    e_mod_comp_debug_edje_error_get
1539      (co->shadow, e_mod_comp_util_client_xid_get(cw));
1540 }
1541
1542 static Eina_Bool
1543 _e_mod_comp_shadow_set(E_Comp_Win *cw,
1544                        Eina_Bool  set)
1545 {
1546 #if USE_SHADOW
1547    Eina_List *l;
1548    E_Comp_Object *co;
1549
1550    if (!cw) return EINA_FALSE;
1551
1552    EINA_LIST_FOREACH(cw->objs, l, co)
1553      {
1554         if (!co) continue;
1555         if ((co->shadow) && (co->img))
1556           {
1557              if (set)
1558                edje_object_signal_emit(co->shadow, "e,state,shadow,on", "e");
1559              else
1560                edje_object_signal_emit(co->shadow, "e,state,shadow,off", "e");
1561           }
1562      }
1563 #endif
1564    return EINA_TRUE;
1565 }
1566
1567 static void
1568 _e_mod_comp_cb_win_mirror_del(void            *data,
1569                               Evas            *e,
1570                               Evas_Object     *obj,
1571                               void *event_info __UNUSED__)
1572 {
1573    E_Comp_Win *cw = (E_Comp_Win *)data;
1574    E_Comp_Object *co;
1575    Eina_List *l;
1576    E_CHECK(cw);
1577
1578    EINA_LIST_FOREACH(cw->objs, l, co)
1579      {
1580         if (co->canvas->evas == e)
1581           {
1582              co->img_mirror = eina_list_remove(co->img_mirror, obj);
1583              break;
1584           }
1585      }
1586 }
1587
1588 static Evas_Object *
1589 _e_mod_comp_win_mirror_add(E_Comp_Win *cw)
1590 {
1591    Evas_Object *o, *smart_parent_obj;
1592    Eina_List *l;
1593    E_Comp_Object *co;
1594    E_Zone *z;
1595
1596    E_CHECK_RETURN(cw->c, 0);
1597
1598    if (cw->bd) z = cw->bd->zone;
1599    else z = e_util_zone_current_get(cw->c->man);
1600    EINA_LIST_FOREACH(cw->objs, l, co)
1601      {
1602         if ((_comp_mod->conf->canvas_per_zone) &&
1603             ((co->zone) != (z)))
1604           continue;
1605
1606         o = evas_object_image_filled_add(co->canvas->evas);
1607         evas_object_image_colorspace_set(o, EVAS_COLORSPACE_ARGB8888);
1608         co->img_mirror = eina_list_append(co->img_mirror, o);
1609         evas_object_image_smooth_scale_set(o, _comp_mod->conf->smooth_windows);
1610
1611         evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
1612                                        _e_mod_comp_cb_win_mirror_del, cw);
1613
1614         if ((cw->pixmap) && (cw->pw > 0) && (cw->ph > 0))
1615           {
1616              unsigned int *pix;
1617              Eina_Bool alpha;
1618              int w, h;
1619
1620              alpha = evas_object_image_alpha_get(co->img);
1621              evas_object_image_size_get(co->img, &w, &h);
1622
1623              evas_object_image_alpha_set(o, alpha);
1624
1625              if (cw->shaped)
1626                {
1627                   pix = evas_object_image_data_get(co->img, 0);
1628                   evas_object_image_data_set(o, pix);
1629                   evas_object_image_size_set(o, w, h);
1630                   evas_object_image_data_set(o, pix);
1631                   evas_object_image_data_update_add(o, 0, 0, w, h);
1632                }
1633              else
1634                {
1635                   if (co->native)
1636                     {
1637                        Evas_Native_Surface ns;
1638
1639                        ns.version = EVAS_NATIVE_SURFACE_VERSION;
1640                        ns.type = EVAS_NATIVE_SURFACE_X11;
1641                        ns.data.x11.visual = cw->vis;
1642                        ns.data.x11.pixmap = cw->pixmap;
1643                        evas_object_image_size_set(o, w, h);
1644                        evas_object_image_native_surface_set(o, &ns);
1645                        evas_object_image_data_update_add(o, 0, 0, w, h);
1646                     }
1647                   else
1648                     {
1649                        if (!co->xim)
1650                          {
1651                             evas_object_del(o);
1652                             return NULL;
1653                          }
1654                        pix = ecore_x_image_data_get(co->xim, NULL, NULL, NULL);
1655                        evas_object_image_data_set(o, pix);
1656                        evas_object_image_size_set(o, w, h);
1657                        evas_object_image_data_set(o, pix);
1658                        evas_object_image_data_update_add(o, 0, 0, w, h);
1659                     }
1660                }
1661              evas_object_image_size_set(o, w, h);
1662              evas_object_image_data_update_add(o, 0, 0, w, h);
1663           }
1664         smart_parent_obj = evas_object_smart_parent_get(co->shadow);
1665         if (!smart_parent_obj)
1666           evas_object_stack_above(o, co->shadow);
1667         else
1668           evas_object_stack_above(o, smart_parent_obj);
1669         return o;
1670      }
1671    return NULL;
1672 }
1673
1674 static E_Comp_Win *
1675 _e_mod_comp_win_add(E_Comp        *c,
1676                     Ecore_X_Window win)
1677 {
1678    Ecore_X_Window_Attributes att;
1679    E_Comp_Win *cw;
1680    Eina_List *l;
1681    E_Comp_Object *co;
1682
1683    cw = E_NEW(E_Comp_Win, 1);
1684    E_CHECK_RETURN(cw, 0);
1685    cw->win = win;
1686    cw->c = c;
1687    cw->opacity = 255.0;
1688    cw->bd = e_border_find_by_window(cw->win);
1689    e_mod_comp_x_grab_set(c, EINA_TRUE);
1690    if (cw->bd)
1691      {
1692         eina_hash_add(borders, e_util_winid_str_get(cw->bd->client.win), cw);
1693         cw->dfn = e_object_delfn_add(E_OBJECT(cw->bd), _e_mod_comp_object_del, cw);
1694      }
1695    else if ((cw->pop = e_popup_find_by_window(cw->win)))
1696      {
1697         cw->dfn = e_object_delfn_add(E_OBJECT(cw->pop),
1698                                      _e_mod_comp_object_del, cw);
1699         cw->show_ready = 1;
1700      }
1701    else if ((cw->menu = e_menu_find_by_window(cw->win)))
1702      {
1703         cw->dfn = e_object_delfn_add(E_OBJECT(cw->menu),
1704                                      _e_mod_comp_object_del, cw);
1705         cw->show_ready = 1;
1706      }
1707    else
1708      {
1709         char *netwm_title = NULL;
1710
1711         cw->title = ecore_x_icccm_title_get(cw->win);
1712         if (ecore_x_netwm_name_get(cw->win, &netwm_title))
1713           {
1714              if (cw->title) free(cw->title);
1715              cw->title = netwm_title;
1716           }
1717         ecore_x_icccm_name_class_get(cw->win, &cw->name, &cw->clas);
1718         cw->role = ecore_x_icccm_window_role_get(cw->win);
1719         if (!ecore_x_netwm_window_type_get(cw->win, &cw->primary_type))
1720           cw->primary_type = ECORE_X_WINDOW_TYPE_UNKNOWN;
1721      }
1722
1723    e_mod_comp_win_type_setup(cw);
1724    memset((&att), 0, sizeof(Ecore_X_Window_Attributes));
1725    if (!ecore_x_window_attributes_get(cw->win, &att))
1726      {
1727         LOGW("[CW Creating Fail!!(Attributes get)] Win:%08x, BD:%p, POP:%p, MENU:%p", e_mod_comp_util_client_xid_get(cw), cw->bd, cw->pop, cw->menu);
1728         if (cw->bd)
1729           {
1730              eina_hash_del(borders, e_util_winid_str_get(cw->bd->client.win), cw);
1731              if (cw->dfn) e_object_delfn_del(E_OBJECT(cw->bd), cw->dfn);
1732           }
1733         else if (cw->pop)
1734           {
1735              if (cw->dfn) e_object_delfn_del(E_OBJECT(cw->pop), cw->dfn);
1736           }
1737         else if (cw->menu)
1738           {
1739              if (cw->dfn) e_object_delfn_del(E_OBJECT(cw->menu), cw->dfn);
1740           }
1741
1742         if (cw->title) free(cw->title);
1743         if (cw->name) free(cw->name);
1744         if (cw->clas) free(cw->clas);
1745         if (cw->role) free(cw->role);
1746         free(cw);
1747
1748         e_mod_comp_x_grab_set(c, EINA_FALSE);
1749         return NULL;
1750      }
1751
1752    if ((!att.input_only) &&
1753        ((att.depth != 24) && (att.depth != 32)))
1754      {
1755         printf("WARNING: window 0x%x not 24/32bpp -> %ibpp\n",
1756                cw->win, att.depth);
1757         cw->invalid = 1;
1758      }
1759    cw->input_only = att.input_only;
1760    cw->override = att.override;
1761    cw->vis = att.visual;
1762    cw->depth = att.depth;
1763    cw->argb = ecore_x_window_argb_get(cw->win);
1764
1765    // supporting sync_draw_done basically.
1766    cw->sync_draw_support = EINA_TRUE;
1767
1768    // setting default value for 3D win and stereoscpic mode
1769    cw->win3d = EINA_FALSE;
1770    //cw->c->stereoscopic_mode = 0;
1771
1772    eina_hash_add(windows, e_util_winid_str_get(cw->win), cw);
1773    cw->inhash = 1;
1774    if ((!cw->input_only) && (!cw->invalid))
1775      {
1776         Ecore_X_Rectangle *rects;
1777         int num;
1778
1779         cw->damage = ecore_x_damage_new
1780           (cw->win, ECORE_X_DAMAGE_REPORT_DELTA_RECTANGLES);
1781         eina_hash_add(damages, e_util_winid_str_get(cw->damage), cw);
1782         cw->objs = e_mod_comp_win_comp_objs_add(cw);
1783         if (!cw->objs)
1784           {
1785              ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
1786                   "%15.15s|ERROR", "OBJECT_ADD");
1787
1788              LOGW("[CW Creating Fail!!(Object Add fail)] Win:%08x, BD:%p, POP:%p, MENU:%p", e_mod_comp_util_client_xid_get(cw), cw->bd, cw->pop, cw->menu);
1789              if (cw->bd)
1790                {
1791                   eina_hash_del(borders, e_util_winid_str_get(cw->bd->client.win), cw);
1792                   if (cw->dfn) e_object_delfn_del(E_OBJECT(cw->bd), cw->dfn);
1793                }
1794              else if (cw->pop)
1795                {
1796                   if (cw->dfn) e_object_delfn_del(E_OBJECT(cw->pop), cw->dfn);
1797                }
1798              else if (cw->menu)
1799                {
1800                   if (cw->dfn) e_object_delfn_del(E_OBJECT(cw->menu), cw->dfn);
1801                }
1802              eina_hash_del(windows, e_util_winid_str_get(cw->win), cw);
1803
1804              if (cw->damage)
1805                {
1806                   eina_hash_del(damages, e_util_winid_str_get(cw->damage), cw);
1807                   ecore_x_damage_free(cw->damage);
1808                   cw->damage = 0;
1809                }
1810
1811              if (cw->title) free(cw->title);
1812              if (cw->name) free(cw->name);
1813              if (cw->clas) free(cw->clas);
1814              if (cw->role) free(cw->role);
1815              free(cw);
1816
1817              e_mod_comp_x_grab_set(c, EINA_FALSE);
1818              return NULL;
1819           }
1820
1821         E_Comp_Canvas *canvas;
1822         EINA_LIST_FOREACH(c->canvases, l, canvas)
1823           {
1824              if (!canvas) continue;
1825              if (canvas->use_bg_img) continue;
1826              evas_object_lower(canvas->bg_img);
1827           }
1828
1829         EINA_LIST_FOREACH(cw->objs, l, co)
1830           {
1831              if (!co) continue;
1832              e_mod_comp_win_shadow_setup(cw, co);
1833              e_mod_comp_win_cb_setup(cw, co);
1834              if (co->img) evas_object_show(co->img);
1835           }
1836
1837         _e_mod_comp_win_transparent_rect_update(cw);
1838
1839         ecore_x_window_shape_events_select(cw->win, 1);
1840         rects = ecore_x_window_shape_rectangles_get(cw->win, &num);
1841         if (rects)
1842           {
1843              int i;
1844              for (i = 0; i < num; i++)
1845                E_RECTS_CLIP_TO_RECT(rects[i].x, rects[i].y,
1846                                     rects[i].width, rects[i].height,
1847                                     0, 0, att.w, att.h);
1848              if (_e_mod_comp_shaped_check(att.w, att.h, rects, num))
1849                cw->shape_changed = 1;
1850
1851              free(rects);
1852           }
1853
1854         if (cw->bd) e_mod_comp_win_comp_objs_data_set(cw, "border", cw->bd);
1855         else if (cw->pop)
1856           e_mod_comp_win_comp_objs_data_set(cw, "popup", cw->pop);
1857         else if (cw->menu)
1858           e_mod_comp_win_comp_objs_data_set(cw, "menu", cw->menu);
1859
1860         e_mod_comp_win_comp_objs_img_pass_events_set(cw, 1);
1861
1862         cw->pending_count++;
1863         e_manager_comp_event_src_add_send
1864           (cw->c->man, (E_Manager_Comp_Source *)cw,
1865           _e_mod_comp_cb_pending_after, cw->c);
1866      }
1867    else
1868      {
1869         cw->objs = e_mod_comp_win_comp_objs_add(cw);
1870         if (!cw->objs)
1871           {
1872              LOGW("[CW Creating Fail!!(Input only Object Add fail)] Win:%08x, BD:%p, POP:%p, MENU:%p", e_mod_comp_util_client_xid_get(cw), cw->bd, cw->pop, cw->menu);
1873              if (cw->bd)
1874                {
1875                   eina_hash_del(borders, e_util_winid_str_get(cw->bd->client.win), cw);
1876                   if (cw->dfn) e_object_delfn_del(E_OBJECT(cw->bd), cw->dfn);
1877                }
1878              else if (cw->pop)
1879                {
1880                   if (cw->dfn) e_object_delfn_del(E_OBJECT(cw->pop), cw->dfn);
1881                }
1882              else if (cw->menu)
1883                {
1884                   if (cw->dfn) e_object_delfn_del(E_OBJECT(cw->menu), cw->dfn);
1885                }
1886              eina_hash_del(windows, e_util_winid_str_get(cw->win), cw);
1887
1888              if (cw->title) free(cw->title);
1889              if (cw->name) free(cw->name);
1890              if (cw->clas) free(cw->clas);
1891              if (cw->role) free(cw->role);
1892              free(cw);
1893
1894              e_mod_comp_x_grab_set(c, EINA_FALSE);
1895              return NULL;
1896           }
1897      }
1898    e_mod_comp_win_comp_objs_pass_events_set(cw, 1);
1899    e_mod_comp_win_comp_objs_data_set(cw, "win",
1900                                (void *)((unsigned long)cw->win));
1901    e_mod_comp_win_comp_objs_data_set(cw, "src", cw);
1902
1903    c->wins_invalid = 1;
1904    c->wins = eina_inlist_append(c->wins, EINA_INLIST_GET(cw));
1905    cw->up = e_mod_comp_update_new();
1906    if (cw->up)
1907      {
1908         e_mod_comp_update_tile_size_set(cw->up, 32, 32);
1909         // for software:
1910         e_mod_comp_update_policy_set
1911            (cw->up, E_UPDATE_POLICY_HALF_WIDTH_OR_MORE_ROUND_UP_TO_FULL_WIDTH);
1912      }
1913    if (((!cw->input_only) && (!cw->invalid)) && (cw->override))
1914      {
1915         cw->redirected = 1;
1916         cw->dmg_updates = 0;
1917      }
1918
1919    cw->eff_type = cw->c->effect_funcs.type_new();
1920    if (cw->eff_type)
1921      {
1922         cw->c->effect_funcs.type_setup
1923           (cw->eff_type,
1924           e_mod_comp_util_client_xid_get(cw));
1925      }
1926    if ((!cw->input_only) && (!cw->invalid))
1927      _e_mod_comp_window_role_handle(cw);
1928
1929    e_mod_comp_x_grab_set(c, EINA_FALSE);
1930    cw->launched = EINA_FALSE;
1931
1932    if (_comp_mod->conf->use_hwc)
1933      {
1934         cw->hwc.set_drawable = EINA_FALSE;
1935      }
1936
1937    return cw;
1938 }
1939
1940 static void
1941 _e_mod_comp_win_del(E_Comp_Win *cw)
1942 {
1943    int pending_count;
1944    E_Comp_Canvas *canvas;
1945    E_Comp_Win *nocomp_cw = NULL;
1946    E_Zone *zone = NULL;
1947
1948    canvas = eina_list_nth(cw->c->canvases, 0);
1949    if (canvas) zone = canvas->zone;
1950
1951    if (zone) nocomp_cw = e_mod_comp_util_win_nocomp_get(cw->c, zone);
1952    if ((canvas) && (nocomp_cw) && (nocomp_cw == cw))
1953      {
1954         e_mod_comp_canvas_nocomp_end(canvas);
1955 #if USE_NOCOMP_DISPOSE
1956         e_mod_comp_canvas_nocomp_dispose(canvas);
1957 #endif
1958      }
1959
1960    if (_comp_mod->conf->use_hwc && (canvas))
1961      {
1962         if (cw->c->hwcomp_funcs.reset_idle_timer)
1963            cw->c->hwcomp_funcs.reset_idle_timer(canvas);
1964         if (cw->c->hwcomp_funcs.win_del)
1965            cw->c->hwcomp_funcs.win_del(cw);
1966      }
1967
1968    if (cw->animating)
1969       cw->c->effect_funcs.animating_set(cw->c, cw, EINA_FALSE);
1970
1971    if (cw->shape_input)
1972      {
1973         e_mod_comp_win_shape_input_free(cw->shape_input);
1974         cw->shape_input = NULL;
1975      }
1976
1977    if ((!cw->input_only) && (!cw->invalid))
1978      {
1979         cw->pending_count++;
1980         e_manager_comp_event_src_del_send
1981           (cw->c->man, (E_Manager_Comp_Source *)cw,
1982           _e_mod_comp_cb_pending_after, cw->c);
1983      }
1984
1985    e_mod_comp_update_free(cw->up);
1986    e_mod_comp_bg_win_handler_release(cw);
1987
1988    if (cw->rects)
1989      {
1990         free(cw->rects);
1991         cw->rects = NULL;
1992      }
1993    if (cw->update_timeout)
1994      {
1995         ecore_timer_del(cw->update_timeout);
1996         cw->update_timeout = NULL;
1997      }
1998    if (cw->dfn)
1999      {
2000         if (cw->bd)
2001           {
2002              eina_hash_del(borders, e_util_winid_str_get(cw->bd->client.win), cw);
2003              e_object_delfn_del(E_OBJECT(cw->bd), cw->dfn);
2004              cw->bd = NULL;
2005           }
2006         else if (cw->pop)
2007           {
2008              e_object_delfn_del(E_OBJECT(cw->pop), cw->dfn);
2009              cw->pop = NULL;
2010           }
2011         else if (cw->menu)
2012           {
2013              e_object_delfn_del(E_OBJECT(cw->menu), cw->dfn);
2014              cw->menu = NULL;
2015           }
2016         cw->dfn = NULL;
2017      }
2018    if (cw->pixmap)
2019      {
2020         e_mod_comp_win_comp_objs_img_deinit(cw);
2021
2022         ecore_x_pixmap_free(cw->pixmap);
2023         cw->pixmap = 0;
2024         cw->pw = 0;
2025         cw->ph = 0;
2026         ecore_x_e_comp_pixmap_set(cw->win, cw->pixmap);
2027         e_mod_comp_win_comp_objs_xim_free(cw);
2028      }
2029    if (cw->redirected)
2030      {
2031         cw->redirected = 0;
2032         cw->pw = 0;
2033         cw->ph = 0;
2034      }
2035    if (cw->update)
2036      {
2037         cw->update = 0;
2038         cw->c->updates = eina_list_remove(cw->c->updates, cw);
2039      }
2040    e_mod_comp_win_comp_objs_del(cw, cw->objs);
2041    if (cw->inhash)
2042      eina_hash_del(windows, e_util_winid_str_get(cw->win), cw);
2043    if (cw->damage)
2044      {
2045         Ecore_X_Region parts;
2046         eina_hash_del(damages, e_util_winid_str_get(cw->damage), cw);
2047         parts = ecore_x_region_new(NULL, 0);
2048         ecore_x_damage_subtract(cw->damage, 0, parts);
2049         ecore_x_region_free(parts);
2050         ecore_x_damage_free(cw->damage);
2051         cw->damage = 0;
2052      }
2053    if (cw->title) free(cw->title);
2054    if (cw->name) free(cw->name);
2055    if (cw->clas) free(cw->clas);
2056    if (cw->role) free(cw->role);
2057    if (cw->eff_type)
2058      {
2059         cw->c->effect_funcs.type_free(cw->eff_type);
2060         cw->eff_type = NULL;
2061      }
2062    if (cw->ov_obj)
2063      {
2064         evas_object_hide(cw->ov_obj);
2065         evas_object_del(cw->ov_obj);
2066         cw->ov_obj = NULL;
2067      }
2068    if (cw->ov_xim)
2069      {
2070         ecore_x_image_free(cw->ov_xim);
2071         cw->ov_xim = NULL;
2072      }
2073    cw->c->wins_invalid = 1;
2074    cw->c->wins = eina_inlist_remove(cw->c->wins, EINA_INLIST_GET(cw));
2075    pending_count = cw->pending_count;
2076    memset(cw, 0, sizeof(E_Comp_Win));
2077    cw->pending_count = pending_count;
2078    cw->delete_pending = 1;
2079    if (cw->pending_count > 0) return;
2080    free(cw);
2081 }
2082
2083 static void
2084 _e_mod_comp_win_prop_check(E_Comp_Win *cw)
2085 {
2086    Ecore_X_Window win;
2087    Ecore_X_Sync_Counter counter;
2088
2089    E_CHECK(cw);
2090    win = e_mod_comp_util_client_xid_get(cw);
2091
2092    // ECORE_X_ATOM_E_COMP_SYNC_COUNTER
2093    counter = ecore_x_e_comp_sync_counter_get(win);
2094    if (cw->counter != counter)
2095      {
2096         if (cw->counter)
2097           {
2098              ecore_x_e_comp_sync_cancel_send(win);
2099              ecore_x_sync_counter_inc(cw->counter, 1);
2100              cw->sync_info.val++;
2101           }
2102         cw->counter = counter;
2103         if (cw->counter)
2104           {
2105              ecore_x_sync_counter_inc(cw->counter, 1);
2106              ecore_x_e_comp_sync_begin_send(win);
2107              cw->sync_info.val = 1;
2108           }
2109      }
2110 }
2111
2112 static void
2113 _e_mod_comp_win_show(E_Comp_Win *cw)
2114 {
2115    Ecore_X_Window win;
2116
2117    // if win_hide was showed then immediatly win_show() function is called. case.
2118    if (cw->defer_hide == 1) cw->defer_hide = 0;
2119    if (cw->visible) return;
2120    cw->visible = 1;
2121 #ifdef _F_IGNORE_DMG_HIDE_
2122    cw->ignore_dmg = 0;
2123    ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw), "%15.15s| set 0", "IGNORE_DMG");
2124 #endif
2125    _e_mod_comp_win_configure(cw,
2126                              cw->hidden.x, cw->hidden.y,
2127                              cw->w, cw->h,
2128                              cw->border);
2129    if ((cw->input_only) || (cw->invalid)) return;
2130
2131    if (cw->bd)
2132      {
2133         e_mod_comp_aux_hint_eval(NULL, cw->bd);
2134         _e_mod_comp_win_sync_setup(cw, cw->bd->client.win);
2135      }
2136    else
2137      _e_mod_comp_win_sync_setup(cw, cw->win);
2138
2139    if (cw->real_hid)
2140      {
2141         cw->real_hid = 0;
2142         e_mod_comp_win_comp_objs_img_deinit(cw);
2143         if (cw->pixmap)
2144           {
2145              ecore_x_pixmap_free(cw->pixmap);
2146              cw->pixmap = 0;
2147              cw->pw = 0;
2148              cw->ph = 0;
2149              ecore_x_e_comp_pixmap_set(cw->win, cw->pixmap);
2150           }
2151         e_mod_comp_win_comp_objs_xim_free(cw);
2152         if (cw->redirected)
2153           {
2154              cw->redirected = 0;
2155              cw->pw = 0;
2156              cw->ph = 0;
2157           }
2158      }
2159
2160    if ((!cw->redirected) || (!cw->pixmap))
2161      {
2162         if (!cw->pixmap)
2163           cw->pixmap = ecore_x_composite_name_window_pixmap_get(cw->win);
2164         if (cw->pixmap)
2165           ecore_x_pixmap_geometry_get(cw->pixmap, NULL, NULL, &(cw->pw), &(cw->ph));
2166         else
2167           {
2168              cw->pw = 0;
2169              cw->ph = 0;
2170           }
2171         if ((cw->pw <= 0) || (cw->ph <= 0))
2172           {
2173              if (cw->pixmap)
2174                {
2175                   ecore_x_pixmap_free(cw->pixmap);
2176                   cw->pixmap = 0;
2177                   cw->needpix = 1;
2178                }
2179           }
2180         cw->redirected = 1;
2181
2182         e_mod_comp_update_resize(cw->up, cw->pw, cw->ph);
2183         e_mod_comp_update_add(cw->up, 0, 0, cw->pw, cw->ph);
2184
2185         e_mod_comp_win_comp_objs_img_size_set(cw, cw->pw, cw->ph);
2186         ecore_x_e_comp_pixmap_set(cw->win, cw->pixmap);
2187      }
2188
2189    if (cw->dmg_updates >= 1)
2190      {
2191         if ((cw->c->gl  && _comp_mod->conf->texture_from_pixmap) || _comp_mod->conf->use_efl_native_surface)
2192           {
2193              if (!cw->pixmap)
2194                cw->pixmap = ecore_x_composite_name_window_pixmap_get(cw->win);
2195
2196              if (cw->pixmap)
2197                {
2198                   ecore_x_pixmap_geometry_get(cw->pixmap,
2199                                               NULL, NULL,
2200                                               &(cw->pw), &(cw->ph));
2201                }
2202              else
2203                {
2204                   cw->pw = 0;
2205                   cw->ph = 0;
2206                }
2207
2208              if ((cw->pw <= 0) || (cw->ph <= 0))
2209                {
2210                   if (cw->pixmap)
2211                     ecore_x_pixmap_free(cw->pixmap);
2212                   cw->pixmap = 0;
2213                   cw->needpix = 1;
2214                }
2215              else
2216                {
2217                   ecore_x_e_comp_pixmap_set(cw->win, cw->pixmap);
2218                   e_mod_comp_win_comp_objs_img_size_set(cw, cw->pw, cw->ph);
2219                   e_mod_comp_win_comp_objs_img_init(cw);
2220                }
2221             }
2222
2223         if (cw->pixmap)
2224           {
2225              cw->defer_hide = 0;
2226              if (!cw->hidden_override)
2227                {
2228                   e_mod_comp_win_comp_objs_force_show(cw);
2229                }
2230           }
2231      }
2232    e_mod_comp_bg_win_handler_show(cw);
2233
2234    win = e_mod_comp_util_client_xid_get(cw);
2235    cw->use_dri2 = _e_mod_comp_prop_window_use_dri2_get(win);
2236
2237    e_mod_comp_win_shape_input_invalid_set(cw->c, 1);
2238    _e_mod_comp_win_render_queue(cw);
2239
2240    if (!cw->sync_draw_support)
2241      {
2242         ELBF(ELBT_COMP, 0, 0, "not sync_draw_support. sync_info.version force set");
2243         cw->sync_info.version = 1;
2244      }
2245 }
2246
2247 static void
2248 _e_mod_comp_win_real_hide(E_Comp_Win *cw)
2249 {
2250    if (cw->bd)
2251      {
2252         _e_mod_comp_win_hide(cw);
2253         return;
2254      }
2255    cw->real_hid = 1;
2256    _e_mod_comp_win_hide(cw);
2257 }
2258
2259 static void
2260 _e_mod_comp_win_hide(E_Comp_Win *cw)
2261 {
2262    Ecore_X_Window _w;
2263
2264    if ((!cw->visible) && (!cw->defer_hide)) return;
2265
2266    e_mod_comp_win_shape_input_invalid_set(cw->c, 1);
2267
2268    if ((cw->input_only) || (cw->invalid)) return;
2269
2270    if (!cw->force)
2271      {
2272         cw->defer_hide = 1;
2273         if (cw->bd)
2274           {
2275              if (cw->bd->client.illume.win_state.state != ECORE_X_ILLUME_WINDOW_STATE_NORMAL)
2276                _e_mod_comp_shadow_set(cw, EINA_FALSE);
2277           }
2278         cw->c->effect_funcs.win_hide(cw);
2279         cw->visible = 0;
2280         return;
2281      }
2282
2283    cw->visible = 0;
2284    Eina_List *l;
2285    E_Comp_Object *co;
2286    EINA_LIST_FOREACH(cw->objs, l, co)
2287      {
2288         if (!co) continue;
2289         cw->c->effect_funcs.signal_del(cw,
2290                                      co->shadow,
2291                                      "hide,done");
2292      }
2293
2294    cw->defer_hide = 0;
2295    cw->force = 0;
2296    e_mod_comp_win_comp_objs_hide(cw);
2297
2298    if (cw->update_timeout)
2299      {
2300         ecore_timer_del(cw->update_timeout);
2301         cw->update_timeout = NULL;
2302      }
2303    if (_comp_mod->conf->keep_unmapped)
2304      {
2305         goto finish;
2306      }
2307
2308    e_mod_comp_win_comp_objs_img_deinit(cw);
2309    if (cw->pixmap)
2310      {
2311         ecore_x_pixmap_free(cw->pixmap);
2312         cw->pixmap = 0;
2313         cw->pw = 0;
2314         cw->ph = 0;
2315         ecore_x_e_comp_pixmap_set(cw->win, cw->pixmap);
2316      }
2317
2318    e_mod_comp_win_comp_objs_xim_free(cw);
2319
2320    if (cw->redirected)
2321      {
2322         cw->redirected = 0;
2323         cw->pw = 0;
2324         cw->ph = 0;
2325      }
2326
2327 finish:
2328    _e_mod_comp_win_render_queue(cw);
2329    _w = e_mod_comp_util_client_xid_get(cw);
2330    if (_comp_mod->conf->send_flush) ecore_x_e_comp_flush_send(_w);
2331    if (_comp_mod->conf->send_dump) ecore_x_e_comp_dump_send(_w);
2332 }
2333
2334 static void
2335 _e_mod_comp_win_raise_above(E_Comp_Win *cw,
2336                             E_Comp_Win *cw2)
2337 {
2338    Eina_Bool v1, v2;
2339
2340    v1 = e_mod_comp_util_win_visible_get(cw, EINA_TRUE);
2341
2342    cw->c->wins_invalid = 1;
2343    cw->c->wins = eina_inlist_remove(cw->c->wins, EINA_INLIST_GET(cw));
2344    cw->c->wins = eina_inlist_append_relative(cw->c->wins,
2345                                              EINA_INLIST_GET(cw),
2346                                              EINA_INLIST_GET(cw2));
2347
2348    v2 = e_mod_comp_util_win_visible_get(cw, EINA_TRUE);
2349    cw->c->effect_funcs.win_restack(cw, v1, v2);
2350
2351    e_mod_comp_win_comp_objs_stack_above(cw, cw2);
2352
2353    _e_mod_comp_win_render_queue(cw);
2354    cw->pending_count++;
2355    e_manager_comp_event_src_config_send
2356      (cw->c->man, (E_Manager_Comp_Source *)cw,
2357      _e_mod_comp_cb_pending_after, cw->c);
2358 }
2359
2360 static void
2361 _e_mod_comp_win_raise(E_Comp_Win *cw)
2362 {
2363    cw->c->wins = eina_inlist_remove(cw->c->wins, EINA_INLIST_GET(cw));
2364    cw->c->wins = eina_inlist_append(cw->c->wins, EINA_INLIST_GET(cw));
2365
2366    e_mod_comp_win_comp_objs_raise(cw);
2367    _e_mod_comp_win_render_queue(cw);
2368 }
2369
2370 static void
2371 _e_mod_comp_win_lower(E_Comp_Win *cw)
2372 {
2373    cw->c->wins_invalid = 1;
2374    cw->c->wins = eina_inlist_remove(cw->c->wins, EINA_INLIST_GET(cw));
2375    cw->c->wins = eina_inlist_prepend(cw->c->wins, EINA_INLIST_GET(cw));
2376
2377    e_mod_comp_win_comp_objs_lower(cw);
2378    _e_mod_comp_win_render_queue(cw);
2379    cw->pending_count++;
2380    e_manager_comp_event_src_config_send
2381      (cw->c->man, (E_Manager_Comp_Source *)cw,
2382      _e_mod_comp_cb_pending_after, cw->c);
2383 }
2384
2385 static void
2386 _e_mod_comp_win_configure(E_Comp_Win *cw,
2387                           int x, int y,
2388                           int w, int h,
2389                           int border)
2390 {
2391    Eina_Bool geo_changed = EINA_FALSE;
2392    Eina_List *l = NULL;
2393    E_Comp_Canvas *canvas = NULL;
2394
2395    if (!((w == cw->w) && (h == cw->h)))
2396      {
2397         cw->w = w;
2398         cw->h = h;
2399         cw->needpix = 1;
2400         cw->dmg_updates = 0;
2401         geo_changed = EINA_TRUE;
2402
2403         /* reset dmg_updates of canvas.nocomp.end if this window
2404          * is waiting for damage events before it is running with
2405                  * the comp mode. (E_NOCOMP_MODE_DISPOSE exactly)
2406          */
2407 #if USE_NOCOMP_DISPOSE
2408         if (_comp_mod->conf->nocomp_fs)
2409           {
2410              EINA_LIST_FOREACH(cw->c->canvases, l, canvas)
2411                {
2412                   if ((canvas->nocomp.mode == E_NOCOMP_MODE_END) &&
2413                       (canvas->nocomp.end.cw == cw))
2414                     {
2415                        ELBF(ELBT_COMP, 0,
2416                             e_mod_comp_util_client_xid_get(cw),
2417                             "NOCOMP dmg:%d nocomp.end.dmg_updates:%d->2",
2418                             canvas->num, cw->dmg_updates,
2419                             canvas->nocomp.end.dmg_updates);
2420
2421                        canvas->nocomp.end.dmg_updates = 2;
2422                     }
2423                }
2424           }
2425 #endif
2426
2427         if ((_comp_mod->conf->use_hwc) && (cw->c->hwcomp_funcs.set_resize))
2428           {
2429              cw->c->hwcomp_funcs.set_resize(cw);
2430           }
2431      }
2432
2433    if (!cw->visible)
2434      {
2435         cw->hidden.x = x;
2436         cw->hidden.y = y;
2437         cw->border = border;
2438      }
2439    else
2440      {
2441         if (!((x == cw->x) && (y == cw->y)))
2442           {
2443              if (cw->needpix)
2444                {
2445                   cw->resizing.x = cw->x;
2446                   cw->resizing.y = cw->y;
2447                }
2448
2449              cw->x = x;
2450              cw->y = y;
2451              geo_changed = EINA_TRUE;
2452              if (!cw->needpix)
2453                e_mod_comp_win_comp_objs_move(cw, cw->x, cw->y);
2454           }
2455         cw->hidden.x = x;
2456         cw->hidden.y = y;
2457      }
2458
2459    if (cw->border != border)
2460      {
2461         cw->border = border;
2462         geo_changed = EINA_TRUE;
2463         e_mod_comp_win_comp_objs_resize(cw,
2464                                   cw->pw + (cw->border * 2),
2465                                   cw->ph + (cw->border * 2));
2466      }
2467    cw->hidden.w = cw->w;
2468    cw->hidden.h = cw->h;
2469    if (geo_changed)
2470      {
2471         e_mod_comp_win_shape_input_invalid_set(cw->c, 1);
2472
2473         if (_comp_mod->conf->nocomp_fs)
2474           {
2475              EINA_LIST_FOREACH(cw->c->canvases, l, canvas)
2476                {
2477                   if ((canvas->nocomp.mode == E_NOCOMP_MODE_RUN) &&
2478                       (canvas->nocomp.cw == cw))
2479                     {
2480                        ELBF(ELBT_COMP, 0,
2481                             e_mod_comp_util_client_xid_get(cw),
2482                             "NOCOMP_END RESIZE canvas:%d dmg:%d",
2483                             canvas->num, cw->dmg_updates);
2484
2485                        e_mod_comp_canvas_nocomp_end(canvas);
2486                     }
2487                }
2488           }
2489      }
2490    if ((cw->input_only) || (cw->invalid) || (cw->needpix)) return;
2491    _e_mod_comp_win_render_queue(cw);
2492    cw->pending_count++;
2493    e_manager_comp_event_src_config_send
2494      (cw->c->man, (E_Manager_Comp_Source *)cw,
2495      _e_mod_comp_cb_pending_after, cw->c);
2496 }
2497
2498 static void
2499 _e_mod_comp_win_damage(E_Comp_Win *cw,
2500                        int         x,
2501                        int         y,
2502                        int         w,
2503                        int         h,
2504                        Eina_Bool   dmg)
2505 {
2506    if ((cw->input_only) || (cw->invalid)) return;
2507    if ((dmg) && (cw->damage))
2508      {
2509         Ecore_X_Region parts;
2510         parts = ecore_x_region_new(NULL, 0);
2511         ecore_x_damage_subtract(cw->damage, 0, parts);
2512         ecore_x_region_free(parts);
2513         cw->dmg_updates++;
2514      }
2515
2516 #if USE_NOCOMP_DISPOSE
2517    if ((_comp_mod->conf->nocomp_fs) &&
2518        (cw->nocomp))
2519      {
2520         EINA_LIST_FOREACH(cw->c->canvases, l, canvas)
2521           {
2522              if (canvas->nocomp.mode != E_NOCOMP_MODE_END) continue;
2523              if (canvas->nocomp.end.cw != cw) continue;
2524              if (canvas->nocomp.end.dmg_updates > cw->dmg_updates) continue;
2525              e_mod_comp_canvas_nocomp_dispose(canvas);
2526           }
2527      }
2528 #endif
2529
2530    e_mod_comp_update_add(cw->up, x, y, w, h);
2531    if (dmg)
2532      {
2533         if (cw->counter)
2534           {
2535 #ifdef _F_IGNORE_DMG_HIDE_
2536              if (!cw->update_timeout &&
2537                  !cw->ignore_dmg)
2538 #else
2539              if (!cw->update_timeout)
2540 #endif
2541                {
2542                   cw->update_timeout = ecore_timer_add
2543                       (_comp_mod->conf->damage_timeout,
2544                       _e_mod_comp_win_damage_timeout, cw);
2545                }
2546              return;
2547           }
2548      }
2549
2550    if ((dmg) &&
2551        (cw->dmg_updates <= 1))
2552      {
2553         if (!(cw->needpix))
2554           {
2555              ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
2556                   "%15.15s|SKIP FIRST DMG. bd:%s", "DMG",
2557                   cw->bd ? "O" : "X");
2558              return;
2559           }
2560      }
2561 #ifdef _F_IGNORE_DMG_HIDE_
2562    if (cw->ignore_dmg)
2563      {
2564         ELBF(ELBT_COMP, 0, cw->win, "%15.15s| skip damage!", "IGNORE_DMG");
2565         return;
2566      }
2567 #endif
2568    if (!cw->update)
2569      {
2570         cw->update = 1;
2571         cw->c->updates = eina_list_append(cw->c->updates, cw);
2572      }
2573    _e_mod_comp_win_render_queue(cw);
2574 }
2575
2576 static void
2577 _e_mod_comp_win_reshape(E_Comp_Win *cw)
2578 {
2579    if (cw->shape_changed) return;
2580    cw->shape_changed = 1;
2581    if (!cw->update)
2582      {
2583         cw->update = 1;
2584         cw->c->updates = eina_list_append(cw->c->updates, cw);
2585      }
2586    e_mod_comp_update_add(cw->up, 0, 0, cw->w, cw->h);
2587    _e_mod_comp_win_render_queue(cw);
2588 }
2589
2590 static Eina_Bool
2591 _e_mod_comp_create(void *data __UNUSED__,
2592                    int type   __UNUSED__,
2593                    void      *event)
2594 {
2595    Ecore_X_Event_Window_Create *ev = event;
2596    Eina_List *l;
2597    E_Comp_Win *cw;
2598    E_Comp_Canvas *canvas;
2599    E_Comp *c = _e_mod_comp_find(ev->parent);
2600    if (!c) return ECORE_CALLBACK_PASS_ON;
2601    if (_e_mod_comp_win_find(ev->win)) return ECORE_CALLBACK_PASS_ON;
2602    if (c->win == ev->win) return ECORE_CALLBACK_PASS_ON;
2603    EINA_LIST_FOREACH(c->canvases, l, canvas)
2604      {
2605         if (canvas->ee_win == ev->win) return ECORE_CALLBACK_PASS_ON;
2606      }
2607    ELBF(ELBT_COMP, 0, ev->win, "%15.15s|", "X_CREATE");
2608    cw = _e_mod_comp_win_add(c, ev->win);
2609    if (cw)
2610      {
2611         _e_mod_comp_win_configure(cw,
2612                                   ev->x, ev->y,
2613                                   ev->w, ev->h,
2614                                   ev->border);
2615
2616         if (cw->bd)
2617           {
2618              if (cw->bd->internal && cw->bd->visible)
2619                 _e_mod_comp_win_show(cw);
2620           }
2621      }
2622    return ECORE_CALLBACK_PASS_ON;
2623 }
2624
2625 static Eina_Bool
2626 _e_mod_comp_destroy(void *data __UNUSED__,
2627                     int type   __UNUSED__,
2628                     void      *event)
2629 {
2630    Ecore_X_Event_Window_Destroy *ev = event;
2631    E_Comp_Win *cw = _e_mod_comp_win_find(ev->win);
2632    if (!cw) return ECORE_CALLBACK_PASS_ON;
2633    ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
2634         "%15.15s|w:0x%08x|bd:%d cw:%p", "X_DESTROY",
2635         ev->win, _e_mod_comp_win_is_border(cw), cw);
2636    if (!cw->c->nocomp && cw->animating) cw->delete_me = 1;
2637    else _e_mod_comp_win_del(cw);
2638    return ECORE_CALLBACK_PASS_ON;
2639 }
2640
2641 /* Compositor must check the client window's property that want to be shown.
2642  * TODO:Compositor will check the property of ECORE_X_ATOM_E_COMP_SYNC_COUNTER for now,
2643  * but the other properties may also need to check later.
2644  */
2645 static Eina_Bool
2646 _e_mod_comp_show_request(void *data __UNUSED__,
2647                          int type   __UNUSED__,
2648                          void       *event)
2649 {
2650    Ecore_X_Event_Window_Show_Request *ev = event;
2651    E_Comp_Win *cw = _e_mod_comp_win_find(ev->win);
2652    if (!cw) return ECORE_CALLBACK_PASS_ON;
2653    ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
2654         "%15.15s|w:0x%08x|bd:%d cw:%p", "X_SHOW_REQUEST",
2655         ev->win, _e_mod_comp_win_is_border(cw), cw);
2656    _e_mod_comp_win_prop_check(cw);
2657    return ECORE_CALLBACK_PASS_ON;
2658 }
2659
2660 static Eina_Bool
2661 _e_mod_comp_show(void *data __UNUSED__,
2662                  int type   __UNUSED__,
2663                  void      *event)
2664 {
2665    Ecore_X_Event_Window_Show *ev = event;
2666    E_Comp_Win *cw = _e_mod_comp_win_find(ev->win);
2667    if (!cw) return ECORE_CALLBACK_PASS_ON;
2668    if (cw->visible) return ECORE_CALLBACK_PASS_ON;
2669    if (_e_mod_comp_win_is_border(cw)) return ECORE_CALLBACK_PASS_ON;
2670    ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
2671         "%15.15s|w:0x%08x|bd:%d cw:%p", "X_SHOW",
2672         ev->win, _e_mod_comp_win_is_border(cw), cw);
2673    _e_mod_comp_win_show(cw);
2674    return ECORE_CALLBACK_PASS_ON;
2675 }
2676
2677 static Eina_Bool
2678 _e_mod_comp_hide(void *data __UNUSED__,
2679                  int type   __UNUSED__,
2680                  void      *event)
2681 {
2682    Ecore_X_Event_Window_Hide *ev = event;
2683    E_Comp_Win *cw = _e_mod_comp_win_find(ev->win);
2684    if (!cw) return ECORE_CALLBACK_PASS_ON;
2685    if (!cw->visible) return ECORE_CALLBACK_PASS_ON;
2686    if (_e_mod_comp_win_is_border(cw)) return ECORE_CALLBACK_PASS_ON;
2687    ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
2688         "%15.15s|w:0x%08x|bd:%d cw:%p", "X_HIDE",
2689         ev->win, _e_mod_comp_win_is_border(cw), cw);
2690    _e_mod_comp_win_real_hide(cw);
2691    return ECORE_CALLBACK_PASS_ON;
2692 }
2693
2694 static Eina_Bool
2695 _e_mod_comp_reparent(void *data __UNUSED__,
2696                      int   type __UNUSED__,
2697                      void *event)
2698 {
2699    Ecore_X_Event_Window_Reparent *ev = event;
2700    E_Comp_Win *cw = _e_mod_comp_win_find(ev->win);
2701    if (!cw) return ECORE_CALLBACK_PASS_ON;
2702    ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
2703         "%15.15s|w:0x%08x|bd:%d cw:%p TO parent:0x%08x", "X_REPARENT",
2704         ev->win, _e_mod_comp_win_is_border(cw), cw, ev->parent);
2705    if (ev->parent != cw->c->man->root)
2706      {
2707         ELBF(ELBT_COMP, 1, e_mod_comp_util_client_xid_get(cw),
2708              "DEL 0x%08x", ev->win);
2709         _e_mod_comp_win_del(cw);
2710      }
2711    return ECORE_CALLBACK_PASS_ON;
2712 }
2713
2714 static Eina_Bool
2715 _e_mod_comp_configure(void *data __UNUSED__,
2716                       int   type __UNUSED__,
2717                       void *event)
2718 {
2719    Ecore_X_Event_Window_Configure *ev = event;
2720    E_Comp_Win *cw = _e_mod_comp_win_find(ev->win);
2721    Eina_Bool need_shape_merge = EINA_FALSE;
2722    if (!cw) return ECORE_CALLBACK_PASS_ON;
2723
2724    ELBF(ELBT_COMP_RENDER, 0, e_mod_comp_util_client_xid_get(cw),
2725         "%15.15s|%4d %4d %3dx%3d", "X_CONFIGURE",
2726         ev->x, ev->y, ev->w, ev->h);
2727
2728    if (ev->abovewin == 0)
2729      {
2730         if (EINA_INLIST_GET(cw)->prev)
2731           {
2732              ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
2733                   "%15.15s|", "LOWER");
2734              SLOGI("%15.15s|0x%08x", "LOWER", e_mod_comp_util_client_xid_get(cw));
2735
2736              _e_mod_comp_win_lower(cw);
2737              need_shape_merge = EINA_TRUE;
2738           }
2739      }
2740    else
2741      {
2742         E_Comp_Win *cw2 = _e_mod_comp_win_find(ev->abovewin);
2743         if (cw2)
2744           {
2745              E_Comp_Win *cw3 = (E_Comp_Win *)(EINA_INLIST_GET(cw)->prev);
2746              if (cw3 != cw2)
2747                {
2748                   ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
2749                        "%15.15s|above:0x%08x", "RAISE_ABOVE",
2750                        e_mod_comp_util_client_xid_get(cw2));
2751                   SLOGI("(0x%08x)%15.15s|above:0x%08x", e_mod_comp_util_client_xid_get(cw), "RAISE_ABOVE",
2752                        e_mod_comp_util_client_xid_get(cw2));
2753
2754                   _e_mod_comp_win_raise_above(cw, cw2);
2755                   need_shape_merge = EINA_TRUE;
2756                }
2757           }
2758      }
2759
2760    if (need_shape_merge)
2761      {
2762         e_mod_comp_win_shape_input_invalid_set(cw->c, 1);
2763         _e_mod_comp_win_render_queue(cw);
2764      }
2765
2766 #if OPTIMIZED_HWC_MOBILE
2767    if (_comp_mod->conf->use_hwc && cw->hwc.resize_pending)
2768      {
2769         cw->hwc.resize_pending = 0;
2770      }
2771 #endif
2772
2773   if (!((cw->x == ev->x) && (cw->y == ev->y)) &&
2774       ((cw->w == ev->w) && (cw->h == ev->h)) &&
2775       _e_mod_comp_win_is_border(cw))
2776     {
2777        return ECORE_CALLBACK_PASS_ON;
2778     }
2779
2780    if (!((cw->x == ev->x) && (cw->y == ev->y) &&
2781          (cw->w == ev->w) && (cw->h == ev->h) &&
2782          (cw->border == ev->border)))
2783      {
2784         _e_mod_comp_win_configure(cw,
2785                                   ev->x, ev->y,
2786                                   ev->w, ev->h,
2787                                   ev->border);
2788      }
2789    return ECORE_CALLBACK_PASS_ON;
2790 }
2791
2792 static Eina_Bool
2793 _e_mod_comp_stack(void *data __UNUSED__,
2794                   int type __UNUSED__,
2795                   void *event)
2796 {
2797    Ecore_X_Event_Window_Stack *ev = event;
2798    E_Comp_Win *cw = _e_mod_comp_win_find(ev->win);
2799    if (!cw) return ECORE_CALLBACK_PASS_ON;
2800    if (ev->detail == ECORE_X_WINDOW_STACK_ABOVE) _e_mod_comp_win_raise(cw);
2801    else _e_mod_comp_win_lower(cw);
2802    return ECORE_CALLBACK_PASS_ON;
2803 }
2804
2805 static Eina_Bool
2806 _e_mod_comp_prop_effect_state(Ecore_X_Event_Window_Property *ev __UNUSED__)
2807 {
2808    E_Comp *c;
2809    unsigned int val;
2810    int ret;
2811
2812    c = e_mod_comp_util_get();
2813    E_CHECK_RETURN(c, 0);
2814
2815    ret = ecore_x_window_prop_card32_get
2816            (c->man->root, ATOM_EFFECT_ENABLE, &val, 1);
2817    E_CHECK_RETURN((ret >= 0), 0);
2818
2819    if (val != 0)
2820      {
2821         c->animatable = EINA_TRUE;
2822         c->keyboard_effect = EINA_TRUE;
2823         if (_comp_mod->conf->default_window_effect != 1)
2824           {
2825              _comp_mod->conf->default_window_effect = 1;
2826              e_config_domain_save("module.e17-mod-tizen-comp",
2827                                   _comp_mod->conf_edd,
2828                                   _comp_mod->conf);
2829
2830           }
2831      }
2832    else
2833      {
2834         c->animatable = EINA_FALSE;
2835         c->keyboard_effect = EINA_FALSE;
2836         if (_comp_mod->conf->default_window_effect != 0)
2837           {
2838              _comp_mod->conf->default_window_effect = 0;
2839              e_config_domain_save("module.e17-mod-tizen-comp",
2840                                   _comp_mod->conf_edd,
2841                                   _comp_mod->conf);
2842           }
2843      }
2844
2845    return EINA_TRUE;
2846 }
2847
2848 static Eina_Bool
2849 _e_mod_comp_prop_window_effect_state(Ecore_X_Event_Window_Property *ev)
2850 {
2851    E_Comp_Win *cw = NULL;
2852    Ecore_X_Window w = 0;
2853    E_CHECK_RETURN(ev, 0);
2854
2855    cw = _e_mod_comp_win_find(ev->win);
2856    if (!cw)
2857      {
2858         cw = _e_mod_comp_border_client_find(ev->win);
2859         E_CHECK_RETURN(cw, 0);
2860      }
2861
2862    E_CHECK_RETURN(cw->eff_type, 0);
2863
2864    w = e_mod_comp_util_client_xid_get(cw);
2865    cw->c->effect_funcs.state_setup(cw->eff_type, w);
2866
2867    return EINA_TRUE;
2868 }
2869
2870 static Eina_Bool
2871 _e_mod_comp_prop_effect_style(Ecore_X_Event_Window_Property *ev)
2872 {
2873    E_Comp_Win *cw = NULL;
2874    Ecore_X_Window w = 0;
2875    E_CHECK_RETURN(ev, 0);
2876
2877    cw = _e_mod_comp_win_find(ev->win);
2878    if (!cw)
2879      {
2880         cw = _e_mod_comp_border_client_find(ev->win);
2881         E_CHECK_RETURN(cw, 0);
2882      }
2883
2884    E_CHECK_RETURN(cw->eff_type, 0);
2885
2886    w = e_mod_comp_util_client_xid_get(cw);
2887    cw->c->effect_funcs.style_setup(cw->eff_type, w);
2888
2889    return EINA_TRUE;
2890 }
2891
2892 static Eina_Bool
2893 _e_mod_comp_prop_opacity(Ecore_X_Event_Window_Property *ev)
2894 {
2895    E_Comp_Win *cw = NULL;
2896    unsigned int val = 0;
2897    int ret = -1;
2898
2899    cw = _e_mod_comp_win_find(ev->win);
2900    if (!cw)
2901      {
2902         cw = _e_mod_comp_border_client_find(ev->win);
2903         E_CHECK_RETURN(cw, 0);
2904      }
2905
2906    ret = ecore_x_window_prop_card32_get
2907            (ev->win, ECORE_X_ATOM_NET_WM_WINDOW_OPACITY, &val, 1);
2908    E_CHECK_RETURN((ret > 0), 0);
2909
2910    cw->opacity = (val >> 24);
2911
2912    Eina_List *l;
2913    E_Comp_Object *co;
2914    EINA_LIST_FOREACH(cw->objs, l, co)
2915      {
2916         evas_object_color_set(co->shadow,
2917                               cw->opacity,
2918                               cw->opacity,
2919                               cw->opacity,
2920                               cw->opacity);
2921      }
2922    return EINA_TRUE;
2923 }
2924
2925 static Eina_Bool
2926 _e_mod_comp_prop_sync_counter(Ecore_X_Event_Window_Property *ev)
2927 {
2928    E_Comp_Win *cw = NULL;
2929    cw = _e_mod_comp_win_find(ev->win);
2930    if (!cw) cw = _e_mod_comp_border_client_find(ev->win);
2931
2932    Ecore_X_Sync_Counter counter = ecore_x_e_comp_sync_counter_get(ev->win);
2933    if (cw)
2934      {
2935         if (cw->counter != counter)
2936           {
2937              Ecore_X_Window _w = e_mod_comp_util_client_xid_get(cw);
2938              if (cw->counter)
2939                {
2940                   ecore_x_e_comp_sync_cancel_send(_w);
2941                   ecore_x_sync_counter_inc(cw->counter, 1);
2942                   cw->sync_info.val++;
2943                }
2944              cw->counter = counter;
2945              if (cw->counter)
2946                {
2947                   ecore_x_sync_counter_inc(cw->counter, 1);
2948                   ecore_x_e_comp_sync_begin_send(_w);
2949                   cw->sync_info.val = 1;
2950                }
2951           }
2952      }
2953    else
2954      {
2955         if (counter) ecore_x_sync_counter_inc(counter, 1);
2956      }
2957    return EINA_TRUE;
2958 }
2959
2960 static Eina_Bool
2961 _e_mod_comp_prop_window_use_dri2_get(Ecore_X_Window win)
2962 {
2963    unsigned int val = 0;
2964    int ret = ecore_x_window_prop_card32_get(win,
2965                                             ATOM_X_WIN_USE_DRI2,
2966                                             &val,
2967                                             1);
2968    if (ret == -1) return EINA_FALSE;
2969
2970    return val ? EINA_TRUE : EINA_FALSE;
2971 }
2972
2973 static Eina_Bool
2974 _e_mod_comp_prop_use_dri2(Ecore_X_Event_Window_Property *ev)
2975 {
2976    E_Comp_Win *cw = NULL;
2977    Ecore_X_Window win;
2978    cw = _e_mod_comp_win_find(ev->win);
2979    if (!cw)
2980      {
2981         cw = _e_mod_comp_border_client_find(ev->win);
2982         E_CHECK_RETURN(cw, 0);
2983      }
2984
2985    win = e_mod_comp_util_client_xid_get(cw);
2986    cw->use_dri2 = _e_mod_comp_prop_window_use_dri2_get(win);
2987
2988    return EINA_TRUE;
2989 }
2990
2991 /* TODO: change getting x prop code to e border event */
2992 static void
2993 _e_mod_comp_prop_illume_win_state(Ecore_X_Event_Window_Property *ev)
2994 {
2995    E_Comp_Win *cw = _e_mod_comp_border_client_find(ev->win);
2996    E_CHECK(cw);
2997
2998    unsigned int state = ecore_x_e_illume_window_state_get(ev->win);
2999
3000    if (state == ECORE_X_ILLUME_WINDOW_STATE_NORMAL)
3001      {
3002         _e_mod_comp_shadow_set(cw, EINA_FALSE);
3003
3004         if ((_comp_mod->conf->use_hwc) && (cw->c->hwcomp_funcs.set_resize))
3005            cw->c->hwcomp_funcs.set_resize(cw);
3006      }
3007    else if ((state == ECORE_X_ILLUME_WINDOW_STATE_FLOATING) ||
3008             (state == ECORE_X_ILLUME_WINDOW_STATE_ASSISTANT_MENU))
3009      {
3010         _e_mod_comp_shadow_set(cw, EINA_TRUE);
3011        
3012         if ((_comp_mod->conf->use_hwc) && (cw->c->hwcomp_funcs.set_resize))
3013            cw->c->hwcomp_funcs.set_resize(cw);
3014      }
3015 }
3016
3017 static Eina_Bool
3018 _e_mod_comp_prop_transparent_rect(Ecore_X_Event_Window_Property *ev)
3019 {
3020    E_Comp_Win *cw = NULL;
3021    cw = _e_mod_comp_win_find(ev->win);
3022    if (!cw)
3023      {
3024         cw = _e_mod_comp_border_client_find(ev->win);
3025         E_CHECK_RETURN(cw, 0);
3026      }
3027
3028    _e_mod_comp_win_transparent_rect_update(cw);
3029
3030    return EINA_TRUE;
3031 }
3032
3033 // for interfacing of 3D setreoscopic mode with compositor
3034 /* one can change the property as below
3035    unsigned int view_mode;
3036    Atom StereoMode;
3037    StereoMode = XInternAtom(disp, "_E_COMP_3D_APP_WIN", False);
3038    if (StereoMode == None)
3039       return ;
3040    XChangeProperty(disp, win, StereoMode, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&view_mode, 1);
3041 */
3042 static Eina_Bool
3043 _e_mod_comp_prop_3d_win_mode(Ecore_X_Event_Window_Property *ev)
3044 {
3045    E_Comp_Win *cw = NULL;
3046    unsigned int view_mode = 0;
3047    int ret = 0;
3048
3049    cw = _e_mod_comp_win_find(ev->win);
3050    if (!cw)
3051      {
3052        cw = _e_mod_comp_border_client_find(ev->win);
3053        E_CHECK_RETURN(cw, 0);
3054      }
3055
3056    //retrieving view mode
3057    ret = ecore_x_window_prop_card32_get
3058                 (ev->win, ATOM_CM_3D_APP_WIN, &view_mode , 1);
3059    if (view_mode < 4)
3060      {
3061        cw->win3d = EINA_TRUE;
3062        // set XRandr RROutput property according to viewmode
3063        _e_mod_comp_win_rr_output_prop_set(ev->win, view_mode);
3064      }
3065
3066    return EINA_TRUE;
3067 }
3068
3069 #ifdef _F_IGNORE_DMG_HIDE_
3070 static void
3071 _e_mod_comp_msg_deiconify_approve(Ecore_X_Event_Client_Message *ev)
3072 {
3073    if (!e_config->deiconify_approve) return;
3074
3075    E_Comp_Win *cw = NULL;
3076    cw = _e_mod_comp_border_client_find(ev->win);
3077    if (!cw) return;
3078    if (ev->data.l[1] != 1) return;
3079    cw->ignore_dmg = 0;
3080    ELBF(ELBT_COMP, 0, ev->win, "%15.15s| set 0 via DEICONIFY APPROVE", "IGNORE_DMG");
3081 }
3082 #endif
3083
3084 //X client message handling for stereo mode change (from 2D Apps)
3085 static void
3086 _e_mod_comp_msg_stereo_mode_changed(Ecore_X_Event_Client_Message *ev)
3087 {
3088    unsigned int res = 0, view_mode = 0;
3089    Ecore_X_Window win;
3090
3091    res = ev->data.l[0];
3092    win = ev->data.l[1];
3093
3094    switch(res)
3095      {
3096        case 0:
3097          view_mode = E_COMP_STEREO_MONO;
3098          break;
3099
3100        case 1:
3101          view_mode = E_COMP_STEREO_INTERLACED;
3102          break;
3103
3104        case 2:
3105          view_mode = E_COMP_STEREO_VERTICAL;
3106          break;
3107
3108        case 3:
3109          view_mode = E_COMP_STEREO_HORIZONTAL;
3110          break;
3111
3112        default:
3113          break;
3114      }
3115
3116    if (view_mode < 4)
3117      {
3118        // set XRandr RROutput property according to viewmode
3119        _e_mod_comp_win_rr_output_prop_set(win, view_mode);
3120      }
3121 }
3122
3123 static void
3124 _e_mod_comp_window_role_handle(E_Comp_Win *cw)
3125 {
3126    E_CHECK(cw);
3127    Ecore_X_Window win;
3128    E_Comp_Object *co;
3129    Eina_List *l;
3130    char *hints = NULL;
3131    char *token = NULL;
3132
3133    win = e_mod_comp_util_client_xid_get(cw);
3134
3135    hints = ecore_x_window_prop_string_get(win, ECORE_X_ATOM_WM_WINDOW_ROLE);
3136
3137    if (hints)
3138      token = strtok(hints, " ,");
3139    while (token != NULL)
3140      {
3141         if (!strncmp (token, "no-effect", strlen("no-effect")))
3142           {
3143              cw->c->effect_funcs.state_set(cw->eff_type, 0);
3144           }
3145         else if (!strncmp(token, "no-dim", strlen("no-dim")))
3146           {
3147              char* group = e_mod_comp_policy_win_shadow_group_get(cw);
3148              if (group && !strcmp(group, "dialog"))
3149                {
3150                   EINA_LIST_FOREACH(cw->objs, l, co)
3151                     {
3152                        if (!co) continue;
3153                        if ((co->shadow) && (co->img))
3154                          {
3155                             edje_object_signal_emit(co->shadow, "e,state,dim,off", "e");
3156                          }
3157                     }
3158                }
3159           }
3160         token = strtok (NULL, " ,");
3161      }
3162
3163    free(hints);
3164 }
3165
3166
3167 static Eina_Bool
3168 _e_mod_comp_prop_window_role(Ecore_X_Event_Window_Property *ev)
3169 {
3170
3171    E_Comp_Win *cw = NULL;
3172    cw = _e_mod_comp_win_find(ev->win);
3173    if (!cw)
3174      {
3175         cw = _e_mod_comp_border_client_find(ev->win);
3176         E_CHECK_RETURN(cw, 0);
3177      }
3178
3179    _e_mod_comp_window_role_handle(cw);
3180
3181    return EINA_TRUE;
3182 }
3183
3184 static Eina_Bool
3185 _e_mod_comp_property(void *data __UNUSED__,
3186                      int type __UNUSED__,
3187                      void *event __UNUSED__)
3188 {
3189    Ecore_X_Event_Window_Property *ev = event;
3190    Ecore_X_Atom a = 0;
3191    if (!ev) return ECORE_CALLBACK_PASS_ON;
3192    if (!ev->atom) return ECORE_CALLBACK_PASS_ON;
3193    if (!e_mod_comp_atoms_name_get(ev->atom)) return ECORE_CALLBACK_PASS_ON;
3194    a = ev->atom;
3195
3196    ELBF(ELBT_COMP_RENDER, 0, ev->win,
3197         "%15.15s|atom:%s", "X_PROP",
3198         e_mod_comp_atoms_name_get(a));
3199
3200    if      (a == ECORE_X_ATOM_E_COMP_SYNC_COUNTER  ) _e_mod_comp_prop_sync_counter(ev);
3201    else if (a == ATOM_X_WIN_USE_DRI2               ) _e_mod_comp_prop_use_dri2(ev);
3202    else if (a == ATOM_EFFECT_ENABLE                ) _e_mod_comp_prop_effect_state(ev);
3203    else if (a == ATOM_WINDOW_EFFECT_ENABLE         ) _e_mod_comp_prop_window_effect_state(ev);
3204    else if (a == ATOM_WINDOW_EFFECT_TYPE           ) _e_mod_comp_prop_effect_style(ev);
3205    else if (a == ECORE_X_ATOM_NET_WM_WINDOW_OPACITY) _e_mod_comp_prop_opacity(ev);
3206    else if (a == ECORE_X_ATOM_WM_CLASS             ) e_mod_comp_win_type_handler_prop(ev);
3207    else if (a == ATOM_NET_CM_WINDOW_BACKGROUND     ) e_mod_comp_bg_win_handler_prop(ev);
3208    else if (a == ATOM_CM_LOG                       ) e_mod_comp_debug_prop_handle(ev);
3209    else if (a == ECORE_X_ATOM_E_ILLUME_WINDOW_STATE) _e_mod_comp_prop_illume_win_state(ev);
3210    else if (a == ATOM_CM_TRANSPARENT_RECT          ) _e_mod_comp_prop_transparent_rect(ev);
3211    else if (a == ECORE_X_ATOM_WM_WINDOW_ROLE       ) _e_mod_comp_prop_window_role(ev);
3212    else if (a == ATOM_CM_3D_APP_WIN                       ) _e_mod_comp_prop_3d_win_mode(ev);
3213
3214    return ECORE_CALLBACK_PASS_ON;
3215 }
3216
3217 static Eina_Bool
3218 _e_mod_comp_msg_sync_draw_done(Ecore_X_Event_Client_Message *ev)
3219 {
3220    E_Comp_Win *cw = NULL;
3221    int v = 0, w = 0, h = 0;
3222    cw = _e_mod_comp_border_client_find(ev->data.l[0]);
3223    v = ev->data.l[1];
3224    w = ev->data.l[2];
3225    h = ev->data.l[3];
3226    if (cw)
3227      {
3228         cw->sync_info.version = v;
3229         if (!cw->bd)
3230           {
3231              ELBF(ELBT_COMP_RENDER, 0, e_mod_comp_util_client_xid_get(cw),
3232                   "%15.15s|v:%d %dx%d ERR NO cw->bd", "DRAW_DONE", v, w, h);
3233              return EINA_FALSE;
3234           }
3235         if ((Ecore_X_Window)(ev->data.l[0]) != cw->bd->client.win)
3236           {
3237              ELBF(ELBT_COMP_RENDER, 0, e_mod_comp_util_client_xid_get(cw),
3238                   "%15.15s|v:%d %dx%d ERR != 0x%08x", "DRAW_DONE",
3239                   v, w, h, ev->data.l[0]);
3240              return EINA_FALSE;
3241           }
3242      }
3243    else
3244      {
3245         cw = _e_mod_comp_win_find(ev->data.l[0]);
3246         if (!cw || (ev->data.l[0] != (int)cw->win))
3247           {
3248              Eina_List *l, *ll;
3249              E_Comp *c;
3250              E_Comp_Canvas *canvas;
3251
3252              EINA_LIST_FOREACH (compositors, l, c)
3253                {
3254                   if (!c) return EINA_FALSE;
3255                   EINA_LIST_FOREACH (c->canvases, ll, canvas)
3256                     {
3257                        if (!canvas) return EINA_FALSE;
3258
3259                        if ((ev->win) && (ev->data.l[0] != canvas->ee_win))
3260                          {
3261                             Ecore_X_Sync_Counter counter = ecore_x_e_comp_sync_counter_get(ev->win);
3262                             ecore_x_e_comp_sync_cancel_send(ev->win);
3263                             if (counter) ecore_x_sync_counter_inc(counter, 1);
3264                          }
3265                     }
3266                }
3267
3268              /*
3269               * FIXME : Is that a right aproach?
3270               */
3271              if (_comp_mod->conf->use_hwc)
3272                {
3273                   E_Comp_HWComp *hwcomp;
3274
3275                   EINA_LIST_FOREACH (compositors, l, c)
3276                     {
3277                        if (!c) return EINA_FALSE;
3278                        EINA_LIST_FOREACH (c->canvases, ll, canvas)
3279                          {
3280                             if (!canvas) return EINA_FALSE;
3281                             if (!canvas->hwcomp) return EINA_FALSE;
3282
3283                             hwcomp = canvas->hwcomp;
3284                             if (ev->data.l[0] == canvas->ee_win)
3285                               {
3286                                  if (c->lock.locked)
3287                                    {
3288                                       if (ecore_evas_manual_render_get(canvas->ee) == EINA_FALSE)
3289                                          ecore_evas_manual_render_set(canvas->ee, 1);
3290                                    }
3291                                  else if (c->hwcomp_funcs.update_composite)
3292                                     c->hwcomp_funcs.update_composite(hwcomp);
3293                               }
3294                          }
3295                     }
3296                }
3297
3298              ELBF(ELBT_COMP_RENDER, 0, ev->data.l[0],
3299                   "%15.15s|v:%d %dx%d ERR NO cw", "DRAW_DONE", v, w, h);
3300              return EINA_FALSE;
3301           }
3302      }
3303
3304    cw->sync_info.version = v;
3305
3306 #ifdef _F_USE_ICONIFY_RESIZE_
3307    if ((cw) && (cw->bd))
3308      {
3309         if (cw->bd->iconify_resize.support)
3310           {
3311              if ((cw->bd->iconify_resize.need_draw)
3312                  && (w == cw->bd->iconify_resize.w)
3313                  && (h == cw->bd->iconify_resize.h))
3314                {
3315                   cw->bd->iconify_resize.need_draw = 0;
3316                   ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
3317                        "%15.15s| set %d - SYNC DRAW DONE received", "NEED_DRAW",
3318                        cw->bd->iconify_resize.need_draw);
3319
3320                   SECURE_SLOGE("[NEED_DRAW|set 0 - SYNC DRAW DONE received] win:0x%07x name:%s",
3321                                cw->bd ? cw->bd->client.win : cw->win,
3322                                cw->bd ? cw->bd->client.netwm.name : NULL);
3323                }
3324           }
3325      }
3326 #endif
3327
3328    if (!cw->counter)
3329      {
3330         cw->counter = ecore_x_e_comp_sync_counter_get(e_mod_comp_util_client_xid_get(cw));
3331         if (cw->counter)
3332           {
3333              ecore_x_sync_counter_inc(cw->counter, 1);
3334              ecore_x_e_comp_sync_begin_send(e_mod_comp_util_client_xid_get(cw));
3335              cw->sync_info.val = 1;
3336              cw->sync_info.done_count = 1;
3337           }
3338         ELBF(ELBT_COMP_RENDER, 0, e_mod_comp_util_client_xid_get(cw),
3339              "%15.15s|v:%d %dx%d WARN NO counter", "DRAW_DONE", v, w, h);
3340         // Add exception for application that don't use sync_counter
3341         if (!cw->update)
3342           {
3343              if (cw->update_timeout)
3344                {
3345                   ecore_timer_del(cw->update_timeout);
3346                   cw->update_timeout = NULL;
3347                }
3348              cw->update = 1;
3349              cw->c->updates = eina_list_append(cw->c->updates, cw);
3350           }
3351         cw->drawme = 1;
3352         _e_mod_comp_win_render_queue(cw);
3353
3354         return EINA_FALSE;
3355      }
3356
3357    if ((_comp_mod->conf->efl_sync) &&
3358        (_comp_mod->conf->nocomp_fs) &&
3359        (cw->nocomp))
3360      {
3361         ecore_x_sync_counter_inc(cw->counter, 1);
3362         cw->update = 0;
3363         cw->drawme = 0;
3364         cw->sync_info.done_count++;
3365         cw->sync_info.val++;
3366         ELBF(ELBT_COMP_RENDER, 0, e_mod_comp_util_client_xid_get(cw),
3367              "%15.15s|v:%d %dx%d NOCOMP INC", "DRAW_DONE", v, w, h);
3368         return EINA_TRUE;
3369      }
3370
3371    if (!cw->update)
3372      {
3373         if (cw->update_timeout)
3374           {
3375              ecore_timer_del(cw->update_timeout);
3376              cw->update_timeout = NULL;
3377           }
3378         cw->update = 1;
3379         cw->c->updates = eina_list_append(cw->c->updates, cw);
3380      }
3381
3382    cw->drawme = 1;
3383    cw->sync_info.done_count++;
3384    ELBF(ELBT_COMP_RENDER, 0, e_mod_comp_util_client_xid_get(cw),
3385         "%15.15s|v:%d %dx%d", "DRAW_DONE", v, w, h);
3386    _e_mod_comp_win_render_queue(cw);
3387    return EINA_TRUE;
3388 }
3389
3390 static void
3391 _e_mod_comp_active_request_handle(Ecore_X_Event_Client_Message *ev)
3392 {
3393    E_Comp_Win *cw = NULL;
3394    cw = _e_mod_comp_win_find(ev->win);
3395    if (!cw) cw = _e_mod_comp_border_client_find(ev->win);
3396
3397    if (!cw) return;
3398    if (!cw->c->animatable) return;
3399
3400    if (TYPE_HOME_CHECK(cw))
3401      {
3402         ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
3403         "%15.15s|", "HOME ACTIVE");
3404
3405         cw->activate = EINA_TRUE;
3406      }
3407 }
3408
3409 static Eina_Bool
3410 _e_mod_comp_hib_leave(Ecore_X_Event_Client_Message *ev)
3411 {
3412    E_Comp *c;
3413    Config *cfg;
3414
3415    E_CHECK_RETURN(ev, 0);
3416    E_CHECK_RETURN((ev->data.l[0] == 0), 0);
3417    E_CHECK_RETURN(_comp_mod, 0);
3418
3419    c = _e_mod_comp_find(ev->win);
3420    E_CHECK_RETURN(c, 0);
3421
3422    cfg = e_config_domain_load("module.e17-mod-tizen-comp",
3423                               _comp_mod->conf_edd);
3424    E_CHECK_RETURN(cfg, 0);
3425
3426    if (cfg->default_window_effect != c->animatable)
3427      {
3428         if (cfg->default_window_effect)
3429           {
3430              c->animatable = EINA_TRUE;
3431              _comp_mod->conf->default_window_effect = 1;
3432           }
3433         else
3434           {
3435              c->animatable = EINA_FALSE;
3436              _comp_mod->conf->default_window_effect = 0;
3437           }
3438         ecore_x_window_prop_card32_set
3439            (c->man->root, ATOM_EFFECT_ENABLE,
3440            (unsigned int *)(&(_comp_mod->conf->default_window_effect)), 1);
3441      }
3442
3443    if (cfg->shadow_file) eina_stringshare_del(cfg->shadow_file);
3444    if (cfg->shadow_style) eina_stringshare_del(cfg->shadow_style);
3445    if (cfg->effect_file) eina_stringshare_del(cfg->effect_file);
3446
3447    if (cfg->effect_policy_unknown) eina_stringshare_del(cfg->effect_policy_unknown);
3448    if (cfg->effect_policy_desktop) eina_stringshare_del(cfg->effect_policy_desktop);
3449    if (cfg->effect_policy_dock) eina_stringshare_del(cfg->effect_policy_dock);
3450    if (cfg->effect_policy_toolbar) eina_stringshare_del(cfg->effect_policy_toolbar);
3451    if (cfg->effect_policy_menu) eina_stringshare_del(cfg->effect_policy_menu);
3452    if (cfg->effect_policy_utility) eina_stringshare_del(cfg->effect_policy_utility);
3453    if (cfg->effect_policy_splash) eina_stringshare_del(cfg->effect_policy_splash);
3454    if (cfg->effect_policy_dialog) eina_stringshare_del(cfg->effect_policy_dialog);
3455    if (cfg->effect_policy_normal) eina_stringshare_del(cfg->effect_policy_normal);
3456    if (cfg->effect_policy_videocall) eina_stringshare_del(cfg->effect_policy_videocall);
3457    if (cfg->effect_policy_dropdown_menu) eina_stringshare_del(cfg->effect_policy_dropdown_menu);
3458    if (cfg->effect_policy_popup_menu) eina_stringshare_del(cfg->effect_policy_popup_menu);
3459    if (cfg->effect_policy_tooltip) eina_stringshare_del(cfg->effect_policy_tooltip);
3460    if (cfg->effect_policy_notification) eina_stringshare_del(cfg->effect_policy_notification);
3461    if (cfg->effect_policy_combo) eina_stringshare_del(cfg->effect_policy_combo);
3462    if (cfg->effect_policy_dnd) eina_stringshare_del(cfg->effect_policy_dnd);
3463    if (cfg->effect_policy_menuscreen) eina_stringshare_del(cfg->effect_policy_menuscreen);
3464    if (cfg->effect_policy_quickpanel_base) eina_stringshare_del(cfg->effect_policy_quickpanel_base);
3465    if (cfg->effect_policy_quickpanel) eina_stringshare_del(cfg->effect_policy_quickpanel);
3466    if (cfg->effect_policy_taskmanager) eina_stringshare_del(cfg->effect_policy_taskmanager);
3467    if (cfg->effect_policy_livemagazine) eina_stringshare_del(cfg->effect_policy_livemagazine);
3468    if (cfg->effect_policy_lockscreen) eina_stringshare_del(cfg->effect_policy_lockscreen);
3469    if (cfg->effect_policy_indicator) eina_stringshare_del(cfg->effect_policy_indicator);
3470    if (cfg->effect_policy_tickernoti) eina_stringshare_del(cfg->effect_policy_tickernoti);
3471    if (cfg->effect_policy_debugging_info) eina_stringshare_del(cfg->effect_policy_debugging_info);
3472    if (cfg->effect_policy_apptray) eina_stringshare_del(cfg->effect_policy_apptray);
3473    if (cfg->effect_policy_mini_apptray) eina_stringshare_del(cfg->effect_policy_mini_apptray);
3474    if (cfg->effect_policy_volume) eina_stringshare_del(cfg->effect_policy_volume);
3475    if (cfg->effect_policy_background) eina_stringshare_del(cfg->effect_policy_background);
3476    if (cfg->effect_policy_isf_keyboard) eina_stringshare_del(cfg->effect_policy_isf_keyboard);
3477    if (cfg->effect_policy_isf_sub) eina_stringshare_del(cfg->effect_policy_isf_sub);
3478    if (cfg->effect_policy_setup_wizard) eina_stringshare_del(cfg->effect_policy_setup_wizard);
3479    if (cfg->effect_policy_toast) eina_stringshare_del(cfg->effect_policy_toast);
3480    if (cfg->effect_policy_app_popup) eina_stringshare_del(cfg->effect_policy_app_popup);
3481
3482    free(cfg);
3483    return EINA_TRUE;
3484 }
3485
3486 static Eina_Bool
3487 _e_mod_comp_xv_rot_begin(Ecore_X_Event_Client_Message* ev)
3488 {
3489    Eina_List *l, *ll;
3490    E_Comp *c;
3491    E_Comp_Canvas *canvas;
3492
3493    E_CHECK_RETURN(ev, 0);
3494
3495    EINA_LIST_FOREACH(compositors, l, c)
3496      {
3497         if (!c) continue;
3498         EINA_LIST_FOREACH(c->canvases, ll, canvas)
3499           {
3500              if (!canvas) continue;
3501              if ((canvas->zr) && (canvas->xv_ready[0]))
3502                canvas->comp->effect_funcs.zone_rotation_begin(canvas->zr);
3503              break;
3504           }
3505      }
3506
3507    return ECORE_CALLBACK_PASS_ON;
3508 }
3509
3510 static Eina_Bool
3511 _e_mod_comp_xv_rot_end(Ecore_X_Event_Client_Message *ev)
3512 {
3513    Eina_List *l, *ll;
3514    E_Comp *c;
3515    E_Comp_Canvas *canvas;
3516
3517    E_CHECK_RETURN(ev, 0);
3518
3519    EINA_LIST_FOREACH(compositors, l, c)
3520      {
3521         if (!c) continue;
3522         EINA_LIST_FOREACH(c->canvases, ll, canvas)
3523           {
3524              if (!canvas) continue;
3525              if (canvas->zr)
3526                {
3527                   if (canvas->xv_ready[0])
3528                     {
3529                        canvas->xv_ready[2] = EINA_TRUE;
3530                        if (!canvas->xv_ready[1])
3531                          break;
3532                     }
3533                   Eina_Bool res = canvas->comp->effect_funcs.zone_rotation_end(canvas->zr);
3534                   if (res)
3535                     canvas->comp->effect_funcs.zone_rotation_do(canvas->zr);
3536                   else
3537                     canvas->comp->effect_funcs.zone_rotation_clear(canvas->zr);
3538                }
3539              break;
3540           }
3541      }
3542    return ECORE_CALLBACK_PASS_ON;
3543 }
3544
3545 static Eina_Bool
3546 _e_mod_comp_message(void *data __UNUSED__,
3547                     int   type __UNUSED__,
3548                     void *event)
3549 {
3550    Ecore_X_Event_Client_Message *ev;
3551    Ecore_X_Atom t;
3552    E_Comp *c;
3553    ev = (Ecore_X_Event_Client_Message *)event;
3554    c = e_mod_comp_util_get();
3555
3556    E_CHECK_RETURN(c, 0);
3557    E_CHECK_RETURN(ev, 0);
3558    E_CHECK_RETURN((ev->format == 32), 0);
3559
3560    t = ev->message_type;
3561
3562    if      (t == ECORE_X_ATOM_E_COMP_SYNC_DRAW_DONE         ) _e_mod_comp_msg_sync_draw_done(ev);
3563    else if (t == ECORE_X_ATOM_NET_ACTIVE_WINDOW            ) _e_mod_comp_active_request_handle(ev);
3564    else if (t == ATOM_CM_LOCK_SCREEN                        ) e_mod_comp_screen_lock_handler_message(ev);
3565    else if (t == ATOM_X_HIBERNATION_STATE                   ) _e_mod_comp_hib_leave(ev);
3566    else if (t == ATOM_IMAGE_LAUNCH_FILE                     ) c->effect_funcs.image_launch_handler_message(ev);
3567    else if (t == ATOM_XV_BYPASS_DONE0                       ) _e_mod_comp_xv_rot_begin(ev);
3568    else if (t == ATOM_XV_BYPASS_DONE1                       ) _e_mod_comp_xv_rot_end(ev);
3569    else if (t == ATOM_CM_MSG_STEREO_MODE           ) _e_mod_comp_msg_stereo_mode_changed(ev);
3570 #ifdef _F_IGNORE_DMG_HIDE_
3571    else if (t == ECORE_X_ATOM_E_DEICONIFY_APPROVE           ) _e_mod_comp_msg_deiconify_approve(ev);
3572 #endif
3573    return ECORE_CALLBACK_PASS_ON;
3574 }
3575
3576 static Eina_Bool
3577 _e_mod_comp_shape(void *data __UNUSED__,
3578                   int type __UNUSED__,
3579                   void *event)
3580 {
3581    Ecore_X_Event_Window_Shape *ev = event;
3582    E_Comp_Win *cw = _e_mod_comp_win_find(ev->win);
3583    if (!cw) return ECORE_CALLBACK_PASS_ON;
3584    if (ev->type != ECORE_X_SHAPE_BOUNDING) return ECORE_CALLBACK_PASS_ON;
3585    _e_mod_comp_win_reshape(cw);
3586    return ECORE_CALLBACK_PASS_ON;
3587 }
3588
3589 static Eina_Bool
3590 _e_mod_comp_damage(void *data __UNUSED__,
3591                    int type __UNUSED__,
3592                    void *event)
3593 {
3594    Ecore_X_Event_Damage *ev = event;
3595    E_Comp_Win *cw = _e_mod_comp_win_damage_find(ev->damage);
3596
3597    if (!cw)
3598      {
3599         ELBF(ELBT_COMP_RENDER, 0, ev->drawable,
3600              "%15.15s|%4d %4d %3dx%3d ERR NO cw (ev->damage)", "DMG",
3601              ev->area.x, ev->area.y, ev->area.width, ev->area.height);
3602         cw = _e_mod_comp_border_client_find(ev->drawable);
3603
3604         if (!cw)
3605           {
3606              ELBF(ELBT_COMP_RENDER, 0, ev->drawable,
3607                   "%15.15s|%4d %4d %3dx%3d ERR NO cw (ev->drawable)", "DMG",
3608                   ev->area.x, ev->area.y, ev->area.width, ev->area.height);
3609              return ECORE_CALLBACK_PASS_ON;
3610           }
3611      }
3612
3613    ELBF(ELBT_COMP_RENDER, 0, e_mod_comp_util_client_xid_get(cw),
3614         "%15.15s|%4d %4d %3dx%3d", "DMG",
3615         ev->area.x, ev->area.y, ev->area.width, ev->area.height);
3616
3617    _e_mod_comp_win_damage(cw,
3618                           ev->area.x, ev->area.y,
3619                           ev->area.width, ev->area.height, 1);
3620    return ECORE_CALLBACK_PASS_ON;
3621 }
3622
3623 static Eina_Bool
3624 _e_mod_comp_damage_win(void *data __UNUSED__,
3625                        int   type __UNUSED__,
3626                        void *event)
3627 {
3628    Ecore_X_Event_Window_Damage *ev = event;
3629    Eina_List *l, *ll;
3630    E_Comp *c;
3631    E_Comp_Canvas *canvas;
3632
3633    // fixme: use hash if compositors list > 4
3634    EINA_LIST_FOREACH(compositors, l, c)
3635      {
3636         if (!c) continue;
3637         EINA_LIST_FOREACH(c->canvases, ll, canvas)
3638           {
3639              if (!canvas) continue;
3640              if (ev->win == canvas->ee_win)
3641                {
3642                   // expose on comp win - init win or some other bypass win did it
3643                   _e_mod_comp_render_queue(c);
3644                   break;
3645                }
3646           }
3647      }
3648    return ECORE_CALLBACK_PASS_ON;
3649 }
3650
3651 static Eina_Bool
3652 _e_mod_comp_randr(void *data  __UNUSED__,
3653                   int type    __UNUSED__,
3654                   void *event __UNUSED__)
3655 {
3656    Eina_List *l;
3657    E_Comp *c;
3658    E_Comp_Canvas *canvas;
3659
3660    ELB(ELBT_COMP, "E_CONTNR_RESIZE", 0);
3661
3662    if (_comp_mod->conf->canvas_per_zone)
3663      return ECORE_CALLBACK_PASS_ON;
3664
3665    EINA_LIST_FOREACH(compositors, l, c)
3666      {
3667         if (!c) continue;
3668         canvas = eina_list_data_get(c->canvases);
3669         if (!canvas) continue;
3670         ecore_evas_resize(canvas->ee,
3671                           c->man->w,
3672                           c->man->h);
3673      }
3674    return ECORE_CALLBACK_PASS_ON;
3675 }
3676
3677 static Eina_Bool
3678 _e_mod_comp_bd_add(void *data __UNUSED__,
3679                    int type   __UNUSED__,
3680                    void      *event)
3681 {
3682    E_Event_Border_Add *ev = event;
3683    Eina_List *l;
3684    E_Comp_Win *cw;
3685    E_Comp_Canvas *canvas;
3686    E_Comp* c = _e_mod_comp_find(ev->border->zone->container->manager->root);
3687
3688    ELBF(ELBT_COMP, 0, ev->border->client.win,
3689         "%15.15s|bd:0x%08x", "BD_ADD", ev->border->win);
3690
3691    if (!c) return ECORE_CALLBACK_PASS_ON;
3692    if (_e_mod_comp_win_find(ev->border->win)) return ECORE_CALLBACK_PASS_ON;
3693    if (c->win == ev->border->win) return ECORE_CALLBACK_PASS_ON;
3694    EINA_LIST_FOREACH(c->canvases, l, canvas)
3695      {
3696         if (canvas->ee_win == ev->border->win) return ECORE_CALLBACK_PASS_ON;
3697      }
3698    traceBegin(TTRACE_TAG_WINDOW_MANAGER,"WM:COMP:BORDER ADD");
3699    cw = _e_mod_comp_win_add(c, ev->border->win);
3700    if (!cw)
3701      {
3702         traceEnd(TTRACE_TAG_WINDOW_MANAGER);
3703         return ECORE_CALLBACK_PASS_ON;
3704      }
3705
3706    _e_mod_comp_win_configure
3707       (cw, ev->border->x, ev->border->y,
3708       ev->border->w, ev->border->h,
3709       ev->border->client.initial_attributes.border);
3710
3711    if (ev->border->internal && ev->border->visible)
3712      _e_mod_comp_win_show(cw);
3713
3714    traceEnd(TTRACE_TAG_WINDOW_MANAGER);
3715    return ECORE_CALLBACK_PASS_ON;
3716 }
3717
3718 static Eina_Bool
3719 _e_mod_comp_bd_del(void *data __UNUSED__,
3720                    int type   __UNUSED__,
3721                    void      *event)
3722 {
3723    E_Event_Border_Remove *ev = event;
3724    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
3725
3726    ELBF(ELBT_COMP, 0, ev->border->client.win,
3727         "%15.15s|bd:0x%08x cw:%p", "BD_DEL", ev->border->win, cw);
3728
3729    if (!cw) return ECORE_CALLBACK_PASS_ON;
3730    traceBegin(TTRACE_TAG_WINDOW_MANAGER,"WM:COMP:BORDER DEL");
3731    if (cw->bd == ev->border)
3732      {
3733         if (e_mod_comp_policy_app_close_check(cw))
3734           cw->c->effect_funcs.signal_add(cw, NULL, "e,state,visible,off,noeffect", "e");
3735
3736         _e_mod_comp_object_del(cw, ev->border);
3737      }
3738    traceEnd(TTRACE_TAG_WINDOW_MANAGER);
3739    return ECORE_CALLBACK_PASS_ON;
3740 }
3741
3742 static Eina_Bool
3743 _e_mod_comp_bd_show(void *data __UNUSED__,
3744                     int type   __UNUSED__,
3745                     void      *event)
3746 {
3747    E_Event_Border_Show *ev = event;
3748    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
3749
3750    ELBF(ELBT_COMP, 0, ev->border->client.win,
3751         "%15.15s|bd:0x%08x cw:%p", "BD_SHOW", ev->border->win, cw);
3752
3753    if (!cw) return ECORE_CALLBACK_PASS_ON;
3754    if (cw->visible) return ECORE_CALLBACK_PASS_ON;
3755    traceBegin(TTRACE_TAG_WINDOW_MANAGER,"WM:COMP:BORDER SHOW");
3756    _e_mod_comp_win_show(cw);
3757
3758    unsigned int state = ev->border->client.illume.win_state.state;
3759    if (state == ECORE_X_ILLUME_WINDOW_STATE_NORMAL)
3760      _e_mod_comp_shadow_set(cw, EINA_FALSE);
3761    else if ((state == ECORE_X_ILLUME_WINDOW_STATE_FLOATING) ||
3762             (state == ECORE_X_ILLUME_WINDOW_STATE_ASSISTANT_MENU))
3763      _e_mod_comp_shadow_set(cw, EINA_TRUE);
3764
3765    traceEnd(TTRACE_TAG_WINDOW_MANAGER);
3766    return ECORE_CALLBACK_PASS_ON;
3767 }
3768
3769 static Eina_Bool
3770 _e_mod_comp_bd_hide(void *data __UNUSED__,
3771                     int type   __UNUSED__,
3772                     void      *event)
3773 {
3774    E_Event_Border_Hide *ev = event;
3775    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
3776
3777    ELBF(ELBT_COMP, 0, ev->border->client.win,
3778         "%15.15s|bd:0x%08x cw:%p", "BD_HIDE", ev->border->win, cw);
3779
3780    if (!cw) return ECORE_CALLBACK_PASS_ON;
3781    if (!cw->visible) return ECORE_CALLBACK_PASS_ON;
3782    traceBegin(TTRACE_TAG_WINDOW_MANAGER,"WM:COMP:BORDER HIDE");
3783    _e_mod_comp_win_hide(cw);
3784    traceEnd(TTRACE_TAG_WINDOW_MANAGER);
3785    return ECORE_CALLBACK_PASS_ON;
3786 }
3787
3788 static Eina_Bool
3789 _e_mod_comp_bd_move(void *data __UNUSED__,
3790                     int type   __UNUSED__,
3791                     void      *event)
3792 {
3793    E_Event_Border_Move *ev = event;
3794    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
3795    if (!cw) return ECORE_CALLBACK_PASS_ON;
3796
3797    ELBF(ELBT_COMP, 0, ev->border->client.win,
3798         "%15.15s|cw[%dx%d] hidden[%d,%d] ev[%d,%d]", "BD_MOVE",
3799         cw->x, cw->y, cw->hidden.x, cw->hidden.y,
3800         ev->border->x, ev->border->y);
3801    SLOGI("%15.15s|(0x%08x)cw[%dx%d] hidden[%d,%d] ev[%d,%d]", "BD_MOVE", ev->border->client.win,
3802         cw->x, cw->y, cw->hidden.x, cw->hidden.y,
3803         ev->border->x, ev->border->y);
3804
3805    if (_comp_mod->conf->use_hwc)
3806      {
3807         if ((STATE_INSET_CHECK(cw)) ||
3808              CLASS_ICONIC_CHECK(cw))
3809           cw->hwc.geo_changed = 3;
3810      }
3811
3812    if (!((cw->x == ev->border->x) &&
3813          (cw->y == ev->border->y)) &&
3814        (cw->visible))
3815      {
3816         _e_mod_comp_win_configure
3817           (cw, ev->border->x, ev->border->y,
3818            ev->border->w, ev->border->h, 0);
3819 #if OPTIMIZED_HWC_MOBILE
3820         if (_comp_mod->conf->use_hwc && !cw->hwc.resize_pending)
3821           {
3822              cw->hwc.resize_pending = 1;
3823           }
3824 #endif
3825      }
3826    else if (!((cw->hidden.x == ev->border->x) &&
3827               (cw->hidden.y == ev->border->y)) &&
3828             (!cw->visible))
3829      {
3830         _e_mod_comp_win_configure
3831           (cw, ev->border->x, ev->border->y,
3832           ev->border->w, ev->border->h, 0);
3833      }
3834    return ECORE_CALLBACK_PASS_ON;
3835 }
3836
3837 static Eina_Bool
3838 _e_mod_comp_bd_resize(void *data __UNUSED__,
3839                       int type   __UNUSED__,
3840                       void      *event)
3841 {
3842    E_Event_Border_Resize *ev = event;
3843    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
3844
3845    ELBF(ELBT_COMP, 0, ev->border->client.win,
3846         "%15.15s|%4dx%4d", "BD_RESIZE",
3847         ev->border->w, ev->border->h);
3848
3849    if (!cw) return ECORE_CALLBACK_PASS_ON;
3850    if ((cw->w == ev->border->w) && (cw->h == ev->border->h))
3851      return ECORE_CALLBACK_PASS_ON;
3852    traceBegin(TTRACE_TAG_WINDOW_MANAGER,"WM:COMP:BORDER RESIZE");
3853    _e_mod_comp_win_configure
3854      (cw, ev->border->x, ev->border->y,
3855      ev->border->w, ev->border->h, cw->border);
3856
3857 #if OPTIMIZED_HWC_MOBILE
3858    if (_comp_mod->conf->use_hwc)
3859      {
3860         cw->hwc.resize_pending =  1;
3861      }
3862 #endif
3863
3864    traceEnd(TTRACE_TAG_WINDOW_MANAGER);
3865    return ECORE_CALLBACK_PASS_ON;
3866 }
3867
3868 static Eina_Bool
3869 _e_mod_comp_bd_iconify(void *data __UNUSED__,
3870                        int type   __UNUSED__,
3871                        void      *event)
3872 {
3873    E_Event_Border_Iconify *ev = event;
3874    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
3875
3876    ELBF(ELBT_COMP, 0, ev->border->client.win,
3877         "%15.15s|bd:0x%08x", "BD_ICONIFY", ev->border->win);
3878
3879    if (!cw) return ECORE_CALLBACK_PASS_ON;
3880    return ECORE_CALLBACK_PASS_ON;
3881 }
3882
3883 static Eina_Bool
3884 _e_mod_comp_bd_uniconify(void *data __UNUSED__,
3885                          int type   __UNUSED__,
3886                          void      *event)
3887 {
3888    E_Event_Border_Uniconify *ev = event;
3889    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
3890
3891    ELBF(ELBT_COMP, 0, ev->border->client.win,
3892         "%15.15s|bd:0x%08x", "BD_UNICONIFY", ev->border->win);
3893
3894    if (!cw) return ECORE_CALLBACK_PASS_ON;
3895    return ECORE_CALLBACK_PASS_ON;
3896 }
3897
3898 static Eina_Bool
3899 _e_mod_comp_bd_focus_in(void *data __UNUSED__,
3900                         int type   __UNUSED__,
3901                         void      *event)
3902 {
3903    E_Event_Border_Focus_In *ev = event;
3904    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
3905
3906    ELBF(ELBT_COMP, 0, ev->border->client.win,
3907         "%15.15s|bd:0x%08x", "BD_FOCUS_IN", ev->border->win);
3908
3909    if (!cw) return ECORE_CALLBACK_PASS_ON;
3910    return ECORE_CALLBACK_PASS_ON;
3911 }
3912
3913 static Eina_Bool
3914 _e_mod_comp_bd_focus_out(void *data __UNUSED__,
3915                          int type   __UNUSED__,
3916                          void      *event)
3917 {
3918    E_Event_Border_Focus_Out *ev = event;
3919    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
3920
3921    ELBF(ELBT_COMP, 0, ev->border->client.win,
3922         "%15.15s|bd:0x%08x", "BD_FOCUS_OUT", ev->border->win);
3923
3924    if (!cw) return ECORE_CALLBACK_PASS_ON;
3925    return ECORE_CALLBACK_PASS_ON;
3926 }
3927
3928 static Eina_Bool
3929 _e_mod_comp_bd_stack(void *data __UNUSED__,
3930                      int type   __UNUSED__,
3931                      void      *event)
3932 {
3933    E_Event_Border_Stack *ev = event;
3934    E_Comp_Win *cw, *cw2 = NULL;
3935    if (!ev->border) return ECORE_CALLBACK_PASS_ON;
3936
3937    cw = _e_mod_comp_win_find(ev->border->win);
3938    if (!cw) return ECORE_CALLBACK_PASS_ON;
3939    traceBegin(TTRACE_TAG_WINDOW_MANAGER,"WM:COMP:BORDER STACK");
3940
3941    if (ev->stack)
3942      {
3943         cw2 = _e_mod_comp_win_find(ev->stack->win);
3944         /* there is no cw yet, thus put off doing it. */
3945         if (!cw2) return ECORE_CALLBACK_PASS_ON;
3946      }
3947
3948    if (ev->type == E_STACKING_BELOW)
3949      {
3950         if (cw2)
3951           {
3952              /* LOWER BELOW
3953               * if user selects back icon of the application, then this event
3954               * is occured first. thus we use this event for showing application
3955               * hide effect.
3956               * visible -> invisible
3957               */
3958
3959              /* check visibility of cw before and after */
3960              Eina_Bool v1 = EINA_FALSE, v2 = EINA_FALSE;
3961              E_Comp *c = cw->c;
3962              E_Comp_Win *cw3 = NULL;
3963
3964              v1 = e_mod_comp_util_win_visible_get(cw, EINA_TRUE);
3965              if (v1)
3966                {
3967                   cw3 = (E_Comp_Win *)(EINA_INLIST_GET(cw)->prev);
3968
3969                   c->wins = eina_inlist_remove(c->wins, EINA_INLIST_GET(cw));
3970                   c->wins = eina_inlist_prepend_relative(c->wins,
3971                                                          EINA_INLIST_GET(cw),
3972                                                          EINA_INLIST_GET(cw2));
3973
3974                   v2 = e_mod_comp_util_win_visible_get(cw, EINA_TRUE);
3975
3976                   /* restore c->wins */
3977                   if (cw3)
3978                     {
3979                        c->wins = eina_inlist_remove(c->wins, EINA_INLIST_GET(cw));
3980                        c->wins = eina_inlist_append_relative(c->wins,
3981                                                              EINA_INLIST_GET(cw),
3982                                                              EINA_INLIST_GET(cw3));
3983                     }
3984                   else
3985                     {
3986                        c->wins = eina_inlist_remove(c->wins, EINA_INLIST_GET(cw));
3987                        c->wins = eina_inlist_prepend(c->wins, EINA_INLIST_GET(cw));
3988                     }
3989                }
3990
3991              /* TODO: try to check visibility of cw without changing c->wins */
3992              //v2 = e_mod_comp_util_win_visible_below_get(cw, cw2);
3993
3994              ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
3995                   "%15.15s|LOWER_BELOW 0x%08x v:%d->%d", "BD_STACK",
3996                   e_mod_comp_util_client_xid_get(cw2), v1, v2);
3997
3998              /* do hide effect if visibility of cw will be changed to invisible from visible */
3999              if ((v1) && (!v2))
4000                cw->c->effect_funcs.win_restack(cw, EINA_TRUE, EINA_FALSE);
4001           }
4002      }
4003    traceEnd(TTRACE_TAG_WINDOW_MANAGER);
4004    return ECORE_CALLBACK_PASS_ON;
4005 }
4006
4007 static Eina_Bool
4008 _e_mod_comp_key_down(void *data __UNUSED__,
4009                      int type   __UNUSED__,
4010                      void      *event)
4011 {
4012    Ecore_Event_Key *ev = (Ecore_Event_Key *)event;
4013    E_CHECK_RETURN(ev, 0);
4014
4015    if ((!strcmp(ev->keyname, "Home")) &&
4016        (ev->modifiers & ECORE_EVENT_MODIFIER_SHIFT) &&
4017        (ev->modifiers & ECORE_EVENT_MODIFIER_CTRL) &&
4018        (ev->modifiers & ECORE_EVENT_MODIFIER_ALT))
4019      {
4020         if (_comp_mod)
4021           {
4022              _e_mod_config_free(_comp_mod->module);
4023              _e_mod_config_new(_comp_mod->module);
4024              e_config_save();
4025              e_module_disable(_comp_mod->module);
4026              e_config_save();
4027              e_sys_action_do(E_SYS_RESTART, NULL);
4028           }
4029      }
4030    return ECORE_CALLBACK_PASS_ON;
4031 }
4032
4033 //////////////////////////////////////////////////////////////////////////
4034 static Evas *
4035 _e_mod_comp_evas_get_func(void          *data,
4036                           E_Manager *man __UNUSED__)
4037 {
4038    E_Comp *c = (E_Comp *)data;
4039    Eina_List *l;
4040    E_Comp_Canvas *canvas;
4041    E_Zone *z;
4042    E_CHECK_RETURN(c, 0);
4043
4044    z = e_util_zone_current_get(c->man);
4045    EINA_LIST_FOREACH(c->canvases, l, canvas)
4046      {
4047         if (!_comp_mod->conf->canvas_per_zone)
4048           return canvas->evas;
4049         else if ((canvas->zone) && (canvas->zone == z))
4050           return canvas->evas;
4051      }
4052    return NULL;
4053 }
4054
4055 static void
4056 _e_mod_comp_update_func(void          *data,
4057                         E_Manager *man __UNUSED__)
4058 {
4059    E_Comp *c = (E_Comp *)data;
4060    E_CHECK(c);
4061    _e_mod_comp_render_queue(c);
4062 }
4063
4064 static E_Manager_Comp_Source *
4065 _e_mod_comp_src_get_func(void           *data __UNUSED__,
4066                          E_Manager      *man __UNUSED__,
4067                          Ecore_X_Window  win)
4068 {
4069    return (E_Manager_Comp_Source *)_e_mod_comp_win_find(win);
4070 }
4071
4072 static const Eina_List *
4073 _e_mod_comp_src_list_get_func(void          *data,
4074                               E_Manager *man __UNUSED__)
4075 {
4076    E_Comp *c = (E_Comp *)data;
4077    E_Comp_Win *cw;
4078    Eina_List *l;
4079    E_Comp_Object *co;
4080    E_CHECK_RETURN(c, 0);
4081    E_CHECK_RETURN(c->wins, 0);
4082
4083    // source list should always be updated if multi-canvas is enabled.
4084    if (_comp_mod->conf->canvas_per_zone)
4085      {
4086         if (c->wins_invalid) c->wins_invalid = 0;
4087         if (c->wins_list)
4088           {
4089              eina_list_free(c->wins_list);
4090              c->wins_list = NULL;
4091           }
4092         E_Zone *z = e_util_zone_current_get(c->man);
4093         EINA_INLIST_FOREACH(c->wins, cw)
4094           {
4095              EINA_LIST_FOREACH(cw->objs, l, co)
4096                {
4097                   if ((co->shadow) && (co->img) && (z == co->zone))
4098                     c->wins_list = eina_list_append(c->wins_list, cw);
4099                }
4100           }
4101      }
4102    else
4103      {
4104         if (c->wins_invalid)
4105           {
4106              c->wins_invalid = 0;
4107              if (c->wins_list)
4108                {
4109                   eina_list_free(c->wins_list);
4110                   c->wins_list = NULL;
4111                }
4112              EINA_INLIST_FOREACH(c->wins, cw)
4113                {
4114                   EINA_LIST_FOREACH(cw->objs, l, co)
4115                     {
4116                        if ((co->shadow) && (co->img))
4117                          c->wins_list = eina_list_append(c->wins_list, cw);
4118                     }
4119                }
4120           }
4121      }
4122    return c->wins_list;
4123 }
4124
4125 static Evas_Object *
4126 _e_mod_comp_src_image_get_func(void                  *data,
4127                                E_Manager *man         __UNUSED__,
4128                                E_Manager_Comp_Source *src)
4129 {
4130    E_Comp *c = (E_Comp *)data;
4131    E_Comp_Win *cw = (E_Comp_Win *)src;
4132    Eina_List *l;
4133    E_Comp_Object *co;
4134    E_Zone *z;
4135    E_CHECK_RETURN(cw, 0);
4136    E_CHECK_RETURN(cw->c, 0);
4137
4138    if (cw->bd) z = cw->bd->zone;
4139    else z = e_util_zone_current_get(c->man);
4140    EINA_LIST_FOREACH(cw->objs, l, co)
4141      {
4142         if (!_comp_mod->conf->canvas_per_zone)
4143           return co->img;
4144         else if ((co->zone) && (co->zone == z))
4145           return co->img;
4146      }
4147    return NULL;
4148 }
4149
4150 static Evas_Object *
4151 _e_mod_comp_src_shadow_get_func(void                  *data,
4152                                 E_Manager *man         __UNUSED__,
4153                                 E_Manager_Comp_Source *src)
4154 {
4155    E_Comp *c = (E_Comp *)data;
4156    E_Comp_Win *cw = (E_Comp_Win *)src;
4157    Eina_List *l;
4158    E_Comp_Object *co;
4159    E_Zone *z;
4160    E_CHECK_RETURN(cw, 0);
4161    E_CHECK_RETURN(cw->c, 0);
4162
4163    if (cw->bd) z = cw->bd->zone;
4164    else z = e_util_zone_current_get(c->man);
4165    EINA_LIST_FOREACH(cw->objs, l, co)
4166      {
4167         if (!_comp_mod->conf->canvas_per_zone)
4168           return co->shadow;
4169         else if ((co->zone) && (co->zone == z))
4170           return co->shadow;
4171      }
4172    return NULL;
4173 }
4174
4175 static Evas_Object *
4176 _e_mod_comp_src_image_mirror_add_func(void *data             __UNUSED__,
4177                                       E_Manager *man         __UNUSED__,
4178                                       E_Manager_Comp_Source *src)
4179 {
4180    E_Comp_Win *cw = (E_Comp_Win *)src;
4181    Eina_List *l = NULL;
4182    E_Comp_Canvas *canvas = NULL;
4183    E_CHECK_RETURN(cw, 0);
4184    E_CHECK_RETURN(cw->c, 0);
4185    E_CHECK_GOTO(_comp_mod->conf->nocomp_fs, end);
4186
4187    EINA_LIST_FOREACH(cw->c->canvases, l, canvas)
4188      {
4189         if (canvas->nocomp.mode != E_NOCOMP_MODE_RUN) continue;
4190         if (cw != canvas->nocomp.cw) continue;
4191
4192         ELBF(ELBT_COMP, 0, e_mod_comp_util_client_xid_get(cw),
4193              "%15.15s| END MIRROR_ADD", "NOCOMP");
4194
4195         e_mod_comp_canvas_nocomp_end(canvas);
4196      }
4197 end:
4198    return _e_mod_comp_win_mirror_add(cw);
4199 }
4200
4201 static Eina_Bool
4202 _e_mod_comp_src_visible_get_func(void *data             __UNUSED__,
4203                                  E_Manager *man         __UNUSED__,
4204                                  E_Manager_Comp_Source *src)
4205 {
4206    E_Comp_Win *cw = (E_Comp_Win *)src;
4207    E_CHECK_RETURN(cw, 0);
4208    E_CHECK_RETURN(cw->c, 0);
4209    return cw->visible;
4210 }
4211
4212 static void
4213 _e_mod_comp_src_hidden_set_func(void *data             __UNUSED__,
4214                                 E_Manager *man         __UNUSED__,
4215                                 E_Manager_Comp_Source *src,
4216                                 Eina_Bool              hidden)
4217 {
4218    E_Comp_Win *cw = (E_Comp_Win *)src;
4219    Eina_List *l;
4220    E_Comp_Object *co;
4221    E_CHECK(cw);
4222    E_CHECK(cw->c);
4223    if (cw->hidden_override == hidden) return;
4224    cw->hidden_override = hidden;
4225    if (cw->bd)
4226      e_border_comp_hidden_set(cw->bd,
4227                               cw->hidden_override);
4228    EINA_LIST_FOREACH(cw->objs, l, co)
4229      {
4230         if (cw->visible)
4231           {
4232              if (cw->hidden_override)
4233                evas_object_hide(co->shadow);
4234              else if (!cw->bd ||
4235                       (cw->bd->visible && cw->show_done))
4236                evas_object_show(co->shadow);
4237           }
4238         else
4239           {
4240              if (cw->hidden_override)
4241                evas_object_hide(co->shadow);
4242           }
4243      }
4244 }
4245
4246 static Eina_Bool
4247 _e_mod_comp_src_hidden_get_func(void *data             __UNUSED__,
4248                                 E_Manager *man         __UNUSED__,
4249                                 E_Manager_Comp_Source *src)
4250 {
4251    E_Comp_Win *cw = (E_Comp_Win *)src;
4252    E_CHECK_RETURN(cw, 0);
4253    E_CHECK_RETURN(cw->c, 0);
4254    return cw->hidden_override;
4255 }
4256
4257 static E_Popup *
4258 _e_mod_comp_src_popup_get_func(void *data             __UNUSED__,
4259                                E_Manager *man         __UNUSED__,
4260                                E_Manager_Comp_Source *src)
4261 {
4262    E_Comp_Win *cw = (E_Comp_Win *)src;
4263    E_CHECK_RETURN(cw, 0);
4264    E_CHECK_RETURN(cw->c, 0);
4265    return cw->pop;
4266 }
4267
4268 static E_Border *
4269 _e_mod_comp_src_border_get_func(void *data             __UNUSED__,
4270                                 E_Manager *man         __UNUSED__,
4271                                 E_Manager_Comp_Source *src)
4272 {
4273    E_Comp_Win *cw = (E_Comp_Win *)src;
4274    E_CHECK_RETURN(cw, 0);
4275    E_CHECK_RETURN(cw->c, 0);
4276    return cw->bd;
4277 }
4278
4279 static Ecore_X_Window
4280 _e_mod_comp_src_window_get_func(void *data             __UNUSED__,
4281                                 E_Manager *man         __UNUSED__,
4282                                 E_Manager_Comp_Source *src)
4283 {
4284    E_Comp_Win *cw = (E_Comp_Win *)src;
4285    E_CHECK_RETURN(cw, 0);
4286    E_CHECK_RETURN(cw->c, 0);
4287    return cw->win;
4288 }
4289
4290 static Eina_Bool
4291 _e_mod_comp_src_input_region_set_func(void *data             __UNUSED__,
4292                                       E_Manager *man         __UNUSED__,
4293                                       E_Manager_Comp_Source *src,
4294                                       int                    x,
4295                                       int                    y,
4296                                       int                    w,
4297                                       int                    h)
4298 {
4299    E_Comp_Win *cw = (E_Comp_Win *)src;
4300    Eina_Bool res = EINA_FALSE;
4301    E_CHECK_RETURN(cw, 0);
4302    E_CHECK_RETURN(cw->c, 0);
4303
4304    if (!cw->shape_input)
4305      cw->shape_input = e_mod_comp_win_shape_input_new(cw);
4306    E_CHECK_RETURN(cw->shape_input, 0);
4307
4308    res = e_mod_comp_win_shape_input_rect_set(cw->shape_input, x, y, w, h);
4309    E_CHECK_RETURN(res, 0);
4310
4311    e_mod_comp_win_shape_input_invalid_set(cw->c, 1);
4312    _e_mod_comp_win_render_queue(cw);
4313    return EINA_TRUE;
4314 }
4315
4316 static int
4317 _e_mod_comp_input_region_new_func(void *data     __UNUSED__,
4318                                   E_Manager *man __UNUSED__)
4319 {
4320    E_Comp *c = e_mod_comp_util_get();
4321    E_CHECK_RETURN(c, 0);
4322
4323    return e_mod_comp_shape_input_new(c);
4324 }
4325
4326 static Eina_Bool
4327 _e_mod_comp_input_region_set_func(void *data     __UNUSED__,
4328                                   E_Manager *man __UNUSED__,
4329                                   int            id,
4330                                   int            x,
4331                                   int            y,
4332                                   int            w,
4333                                   int            h)
4334 {
4335    E_Comp *c = e_mod_comp_util_get();
4336    Eina_Bool res = EINA_FALSE;
4337    E_CHECK_RETURN(c, EINA_FALSE);
4338
4339    if (id <= 0) return EINA_FALSE;
4340
4341    res = e_mod_comp_shape_input_set(c, id, x, y, w, h);
4342    if (res)
4343      {
4344         e_mod_comp_win_shape_input_invalid_set(c, 1);
4345         _e_mod_comp_render_queue(c);
4346      }
4347
4348    return res;
4349 }
4350
4351 static Eina_Bool
4352 _e_mod_comp_input_region_managed_set_func(void *data          __UNUSED__,
4353                                           E_Manager *man      __UNUSED__,
4354                                           int                 id,
4355                                           Evas_Object        *obj,
4356                                           Eina_Bool           set)
4357 {
4358    E_Comp *c = e_mod_comp_util_get();
4359    Eina_Bool res = EINA_FALSE;
4360    E_CHECK_RETURN(c, EINA_FALSE);
4361
4362    if (id <= 0) return EINA_FALSE;
4363
4364    res = e_mod_comp_shape_input_managed_set(c, id, obj, set);
4365    if (res)
4366      {
4367         e_mod_comp_win_shape_input_invalid_set(c, 1);
4368         _e_mod_comp_render_queue(c);
4369      }
4370
4371    return EINA_TRUE;
4372 }
4373
4374 static Eina_Bool
4375 _e_mod_comp_input_region_del_func(void *data     __UNUSED__,
4376                                   E_Manager *man __UNUSED__,
4377                                   int id)
4378 {
4379    E_Comp *c = e_mod_comp_util_get();
4380    Eina_Bool res = EINA_FALSE;
4381    E_CHECK_RETURN(c, 0);
4382
4383    if (id <= 0) return EINA_FALSE;
4384
4385    res = e_mod_comp_shape_input_del(c, id);
4386    if (res)
4387      {
4388         e_mod_comp_win_shape_input_invalid_set(c, 1);
4389         _e_mod_comp_render_queue(c);
4390      }
4391    return res;
4392 }
4393
4394 static void
4395 _e_mod_comp_composite_mode_set(void           *data,
4396                                E_Manager *man __UNUSED__,
4397                                E_Zone        *zone,
4398                                Eina_Bool      set)
4399 {
4400    E_Comp *c = (E_Comp *)data;
4401    E_Comp_Canvas *canvas;
4402    Eina_List *l;
4403    E_CHECK(c);
4404
4405    if (_comp_mod->conf->use_hwc)
4406      {
4407         EINA_LIST_FOREACH(c->canvases, l, canvas)
4408          {
4409             if (!canvas) continue;
4410             if (canvas->zone != zone) continue;
4411
4412             if ((canvas->hwcomp) && (c->hwcomp_funcs.force_composite_set))
4413                c->hwcomp_funcs.force_composite_set(canvas->hwcomp, set);
4414
4415             if (set)
4416                _e_mod_comp_render_queue(c);
4417          }
4418      }
4419
4420    E_CHECK(_comp_mod->conf->nocomp_fs);
4421
4422    EINA_LIST_FOREACH(c->canvases, l, canvas)
4423      {
4424         if (!canvas) continue;
4425         if (canvas->zone == zone)
4426           {
4427              if (set)
4428                {
4429                   canvas->nocomp.comp_ref++;
4430
4431                   e_mod_comp_hw_ov_win_msg_show
4432                     (E_COMP_LOG_TYPE_NOCOMP,
4433                     ">> %d COMP REQUEST ref:%d", canvas->num,
4434                     canvas->nocomp.comp_ref);
4435
4436                   if (!canvas->nocomp.force_composite)
4437                     {
4438                        canvas->nocomp.force_composite = set;
4439                        e_mod_comp_hw_ov_win_msg_show
4440                          (E_COMP_LOG_TYPE_NOCOMP,
4441                          ">> %d COMP REQUEST", canvas->num);
4442
4443                        if (canvas->nocomp.cw)
4444                          {
4445                             canvas->nocomp.cw->update = 1;
4446                             c->updates = eina_list_append(c->updates, canvas->nocomp.cw);
4447                             _e_mod_comp_win_render_queue(canvas->nocomp.cw);
4448                          }
4449                        else
4450                          {
4451                             _e_mod_comp_render_queue(c);
4452                          }
4453                     }
4454                }
4455              else
4456                {
4457                   canvas->nocomp.comp_ref--;
4458                   if (canvas->nocomp.comp_ref < 0)
4459                     canvas->nocomp.comp_ref = 0;
4460
4461                   e_mod_comp_hw_ov_win_msg_show
4462                     (E_COMP_LOG_TYPE_NOCOMP,
4463                     ">> %d NOCOMP REQUEST ref:%d", canvas->num,
4464                     canvas->nocomp.comp_ref);
4465
4466                   if ((canvas->nocomp.comp_ref == 0) &&
4467                       (canvas->nocomp.force_composite))
4468                     {
4469                        canvas->nocomp.force_composite = EINA_FALSE;
4470                        e_mod_comp_hw_ov_win_msg_show
4471                          (E_COMP_LOG_TYPE_NOCOMP,
4472                          ">> %d NOCOMP REQUEST", canvas->num);
4473                     }
4474                }
4475              break;
4476           }
4477      }
4478 }
4479
4480 static Eina_Bool
4481 _e_mod_comp_composite_mode_get(void          *data,
4482                                E_Manager *man __UNUSED__,
4483                                E_Zone        *zone)
4484 {
4485    E_Comp *c = (E_Comp *)data;
4486    E_Comp_Canvas *canvas;
4487    Eina_List *l;
4488
4489    E_CHECK_RETURN(_comp_mod->conf->nocomp_fs, 1);
4490    E_CHECK_RETURN(c, 1);
4491
4492    EINA_LIST_FOREACH(c->canvases, l, canvas)
4493      {
4494         if (!canvas) continue;
4495         if (canvas->zone == zone)
4496           {
4497              if (canvas->nocomp.mode == E_NOCOMP_MODE_RUN)
4498                return EINA_FALSE;
4499              else
4500                return EINA_TRUE;
4501           }
4502      }
4503    return EINA_TRUE;
4504 }
4505
4506 static void
4507 _e_mod_comp_src_shadow_show_func(void                  *data,
4508                                  E_Manager *man         __UNUSED__,
4509                                  E_Manager_Comp_Source *src)
4510 {
4511    E_Comp_Win *cw = (E_Comp_Win *)src;
4512    E_CHECK(cw);
4513    E_CHECK(cw->c);
4514
4515    _e_mod_comp_win_show(cw);
4516 }
4517
4518 static void
4519 _e_mod_comp_src_shadow_hide_func(void                  *data,
4520                                  E_Manager *man         __UNUSED__,
4521                                  E_Manager_Comp_Source *src)
4522 {
4523    E_Comp_Win *cw = (E_Comp_Win *)src;
4524    E_CHECK(cw);
4525    E_CHECK(cw->c);
4526
4527    _e_mod_comp_win_hide(cw);
4528 }
4529
4530 static Evas_Object *
4531 _e_mod_comp_layer_get_func(void           *data,
4532                            E_Manager *man __UNUSED__,
4533                            E_Zone        *zone,
4534                            const char    *name)
4535 {
4536    E_Comp *c = (E_Comp *)data;
4537    E_Comp_Canvas *canvas = NULL;
4538    E_Comp_Layer *ly = NULL;
4539    Eina_List *l;
4540
4541    E_CHECK_RETURN(c, NULL);
4542
4543    EINA_LIST_FOREACH(c->canvases, l, canvas)
4544      {
4545         if (!canvas) continue;
4546         if (canvas->zone == zone)
4547           {
4548              ly = e_mod_comp_canvas_layer_get(canvas, name);
4549              if ((ly) && (!strcmp(name, "ly-ctrl")) && (ly->need_init))
4550                {
4551                   E_Comp_Layer *comp_ly = e_mod_comp_canvas_layer_get(canvas, "comp");
4552                   if (comp_ly)
4553                     {
4554                        ly->need_init = EINA_FALSE;
4555
4556                        e_layout_pack(comp_ly->layout, ly->layout);
4557                        e_mod_comp_layer_populate_above_normal(comp_ly, ly->layout);
4558                        e_mod_comp_layer_bg_adjust(ly);
4559                     }
4560                }
4561
4562              if (ly) return ly->layout;
4563              break;
4564           }
4565      }
4566
4567    return NULL;
4568 }
4569
4570 static void
4571 _e_mod_comp_layer_raise_above_func(void          *data,
4572                                    E_Manager     *man __UNUSED__,
4573                                    E_Zone        *zone,
4574                                    const char    *name,
4575                                    E_Border      *bd)
4576 {
4577    E_Comp *c = (E_Comp *)data;
4578    E_Comp_Canvas *canvas = NULL;
4579    E_Comp_Layer *ly = NULL;
4580    Eina_List *l;
4581
4582    E_CHECK(c);
4583
4584    EINA_LIST_FOREACH(c->canvases, l, canvas)
4585      {
4586         if (!canvas) continue;
4587         if (canvas->zone == zone)
4588           {
4589              ly = e_mod_comp_canvas_layer_get(canvas, name);
4590              if (!ly) return;
4591              e_mod_comp_layer_raise_above(canvas, ly->layout, bd);
4592           }
4593      }
4594 }
4595
4596 static void
4597 _e_mod_comp_layer_lower_below_func(void          *data,
4598                                    E_Manager     *man __UNUSED__,
4599                                    E_Zone        *zone,
4600                                    const char    *name,
4601                                    E_Border      *bd)
4602 {
4603    E_Comp *c = (E_Comp *)data;
4604    E_Comp_Canvas *canvas = NULL;
4605    E_Comp_Layer *ly = NULL;
4606    Eina_List *l;
4607
4608    E_CHECK(c);
4609
4610    EINA_LIST_FOREACH(c->canvases, l, canvas)
4611      {
4612         if (!canvas) continue;
4613         if (canvas->zone == zone)
4614           {
4615              ly = e_mod_comp_canvas_layer_get(canvas, name);
4616              if (!ly) return;
4617              e_mod_comp_layer_lower_below(canvas, ly->layout, bd);
4618           }
4619      }
4620 }
4621
4622 static E_Comp *
4623 _e_mod_comp_add(E_Manager *man)
4624 {
4625    E_Comp *c;
4626    Ecore_X_Window *wins;
4627    Ecore_X_Window_Attributes att;
4628    Eina_Bool res;
4629    int i, num;
4630
4631    E_Container *con;
4632    E_Zone *zone;
4633    E_Comp_Canvas *canvas;
4634    Eina_List *l, *ll;
4635
4636    c = E_NEW(E_Comp, 1);
4637    E_CHECK_RETURN(c, NULL);
4638
4639    res = ecore_x_screen_is_composited(man->num);
4640    if (res)
4641      {
4642         e_util_dialog_internal
4643            (_("Compositor Error"),
4644            _("Another compositor is already running<br>"
4645              "on your screen."));
4646         free(c);
4647         return NULL;
4648      }
4649
4650    c->cm_selection = ecore_x_window_input_new(man->root, 0, 0, 1, 1);
4651    if (!c->cm_selection)
4652      {
4653         free(c);
4654         return NULL;
4655      }
4656    ecore_x_screen_is_composited_set(man->num, c->cm_selection);
4657
4658    ecore_x_e_comp_sync_supported_set(man->root, _comp_mod->conf->efl_sync);
4659
4660    c->man = man;
4661    c->win = ecore_x_composite_render_window_enable(man->root);
4662    if (!c->win)
4663      {
4664         e_util_dialog_internal
4665           (_("Compositor Error"),
4666           _("Your screen does not support the compositor<br>"
4667             "overlay window. This is needed for it to<br>"
4668             "function."));
4669         E_FREE(c);
4670         return NULL;
4671      }
4672
4673    memset((&att), 0, sizeof(Ecore_X_Window_Attributes));
4674    ecore_x_window_attributes_get(c->win, &att);
4675
4676    if ((att.depth != 24) && (att.depth != 32))
4677      {
4678         e_util_dialog_internal
4679           (_("Compositor Error"),
4680           _("Your screen is not in 24/32bit display mode.<br>"
4681             "This is required to be your default depth<br>"
4682             "setting for the compositor to work properly."));
4683         ecore_x_composite_render_window_disable(c->win);
4684         E_FREE(c);
4685         return NULL;
4686      }
4687
4688    if (c->man->num == 0) e_alert_composite_win = c->win;
4689
4690    e_mod_comp_screen_lock_init(&(c->lock));
4691
4692    if (!_e_mod_comp_effect_init(c))
4693      {
4694         e_util_dialog_internal
4695           (_("Compositor Error"),
4696           _(" Effect failed to initialize."));
4697         ecore_x_composite_render_window_disable(c->win);
4698         E_FREE(c);
4699         return NULL;
4700      }
4701
4702    if (!_e_mod_comp_hwcomp_init(c))
4703      {
4704             ELBF(ELBT_COMP, 0, 0, "HWComp INIT FAIL: %s",
4705                         ecore_file_file_get(_comp_mod->conf->hwcomp_file));
4706      }
4707
4708    if (_comp_mod->conf->canvas_per_zone)
4709      {
4710         EINA_LIST_FOREACH(man->containers, l, con)
4711           {
4712              EINA_LIST_FOREACH(con->zones, ll, zone)
4713                {
4714                   if (!zone) continue;
4715                   canvas = e_mod_comp_canvas_add(c, zone);
4716                   if (!canvas)
4717                     {
4718                        ecore_x_composite_render_window_disable(c->win);
4719                        E_FREE(c);
4720                        return NULL;
4721                     }
4722                   else
4723                     {
4724                        if (_comp_mod->conf->stand_by_canvas_render_enable)
4725                          {
4726                             ELBF(ELBT_COMP, 0, 0, "STAND BY CANVAS RENDER");
4727                             c->stand_by_canvas_render = 1;
4728                             ecore_evas_manual_render_set(canvas->ee, 1);
4729                          }
4730                     }
4731
4732                }
4733           }
4734      }
4735    else
4736      {
4737         canvas = e_mod_comp_canvas_add(c, NULL);
4738         if (!canvas)
4739           {
4740              ecore_x_composite_render_window_disable(c->win);
4741              E_FREE(c);
4742              return NULL;
4743           }
4744         else
4745           {
4746              if (_comp_mod->conf->stand_by_canvas_render_enable)
4747                {
4748                   ELBF(ELBT_COMP, 0, 0, "STAND BY CANVAS RENDER");
4749                   c->stand_by_canvas_render = 1;
4750                   ecore_evas_manual_render_set(canvas->ee, 1);
4751                }
4752           }
4753      }
4754
4755    if (_comp_mod->conf->keyboard_effect) c->keyboard_effect = EINA_TRUE;
4756    if (_comp_mod->conf->defer_raise_effect) c->defer_raise_effect = EINA_TRUE;
4757    if (_comp_mod->conf->fake_image_launch) c->fake_image_launch = EINA_TRUE;
4758
4759    ecore_x_composite_redirect_subwindows
4760      (c->man->root, ECORE_X_COMPOSITE_UPDATE_MANUAL);
4761
4762    wins = ecore_x_window_children_get(c->man->root, &num);
4763    if (wins)
4764      {
4765         for (i = 0; i < num; i++)
4766           {
4767              E_Comp_Win *cw;
4768              int x, y, w, h, border;
4769              char *wname = NULL, *wclass = NULL;
4770
4771              ecore_x_icccm_name_class_get(wins[i], &wname, &wclass);
4772              if ((man->initwin == wins[i]) ||
4773                  ((wname) && (wclass) && (!strcmp(wname, "E")) &&
4774                   (!strcmp(wclass, "Init_Window"))))
4775                {
4776                   free(wname);
4777                   free(wclass);
4778                   ecore_x_window_reparent(wins[i], c->win, 0, 0);
4779                   ecore_x_sync();
4780                   continue;
4781                }
4782              if (wname) free(wname);
4783              if (wclass) free(wclass);
4784              wname = wclass = NULL;
4785              cw = _e_mod_comp_win_add(c, wins[i]);
4786              if (!cw) continue;
4787              if (i == _comp_mod->conf->lower_layer)
4788                c->lower_win = cw;
4789              ecore_x_window_geometry_get(cw->win, &x, &y, &w, &h);
4790              border = ecore_x_window_border_width_get(cw->win);
4791              if (wins[i] == c->win) continue;
4792              _e_mod_comp_win_configure(cw, x, y, w, h, border);
4793              if (ecore_x_window_visible_get(wins[i]))
4794                _e_mod_comp_win_show(cw);
4795           }
4796         free(wins);
4797      }
4798
4799    ecore_x_window_key_grab
4800      (c->man->root, "Home",
4801      ECORE_EVENT_MODIFIER_SHIFT |
4802      ECORE_EVENT_MODIFIER_CTRL |
4803      ECORE_EVENT_MODIFIER_ALT, 0);
4804    ecore_x_window_key_grab
4805      (c->man->root, "F",
4806      ECORE_EVENT_MODIFIER_SHIFT |
4807      ECORE_EVENT_MODIFIER_CTRL |
4808      ECORE_EVENT_MODIFIER_ALT, 0);
4809
4810    c->comp.data                      = c;
4811    c->comp.func.evas_get             = _e_mod_comp_evas_get_func;
4812    c->comp.func.update               = _e_mod_comp_update_func;
4813    c->comp.func.src_get              = _e_mod_comp_src_get_func;
4814    c->comp.func.src_list_get         = _e_mod_comp_src_list_get_func;
4815    c->comp.func.src_image_get        = _e_mod_comp_src_image_get_func;
4816    c->comp.func.src_shadow_get       = _e_mod_comp_src_shadow_get_func;
4817    c->comp.func.src_image_mirror_add = _e_mod_comp_src_image_mirror_add_func;
4818    c->comp.func.src_visible_get      = _e_mod_comp_src_visible_get_func;
4819    c->comp.func.src_hidden_set       = _e_mod_comp_src_hidden_set_func;
4820    c->comp.func.src_hidden_get       = _e_mod_comp_src_hidden_get_func;
4821    c->comp.func.src_window_get       = _e_mod_comp_src_window_get_func;
4822    c->comp.func.src_border_get       = _e_mod_comp_src_border_get_func;
4823    c->comp.func.src_popup_get        = _e_mod_comp_src_popup_get_func;
4824    c->comp.func.screen_lock          = e_mod_comp_screen_lock_func;
4825    c->comp.func.screen_unlock        = e_mod_comp_screen_unlock_func;
4826    c->comp.func.src_input_region_set = _e_mod_comp_src_input_region_set_func;
4827    c->comp.func.input_region_new     = _e_mod_comp_input_region_new_func;
4828    c->comp.func.input_region_set     = _e_mod_comp_input_region_set_func;
4829    c->comp.func.input_region_managed_set = _e_mod_comp_input_region_managed_set_func;
4830    c->comp.func.input_region_del         = _e_mod_comp_input_region_del_func;
4831    c->comp.func.src_move_lock            = NULL; /* deprecated */
4832    c->comp.func.src_move_unlock          = NULL; /* deprecated */
4833    c->comp.func.composite_mode_set       = _e_mod_comp_composite_mode_set;
4834    c->comp.func.composite_mode_get       = _e_mod_comp_composite_mode_get;
4835    c->comp.func.src_shadow_show          = _e_mod_comp_src_shadow_show_func;
4836    c->comp.func.src_shadow_hide          = _e_mod_comp_src_shadow_hide_func;
4837    c->comp.func.layer_get            = _e_mod_comp_layer_get_func;
4838    c->comp.func.layer_raise_above    = _e_mod_comp_layer_raise_above_func;
4839    c->comp.func.layer_lower_below    = _e_mod_comp_layer_lower_below_func;
4840
4841    e_manager_comp_set(c->man, &(c->comp));
4842    return c;
4843 }
4844
4845 static void
4846 _e_mod_comp_del(E_Comp *c)
4847 {
4848    E_Comp_Win *cw;
4849    E_Comp_Canvas *canvas;
4850
4851    e_manager_comp_set(c->man, NULL);
4852
4853    ecore_x_window_key_ungrab
4854      (c->man->root, "F",
4855      ECORE_EVENT_MODIFIER_SHIFT |
4856      ECORE_EVENT_MODIFIER_CTRL |
4857      ECORE_EVENT_MODIFIER_ALT, 0);
4858    ecore_x_window_key_ungrab
4859      (c->man->root, "Home",
4860      ECORE_EVENT_MODIFIER_SHIFT |
4861      ECORE_EVENT_MODIFIER_CTRL |
4862      ECORE_EVENT_MODIFIER_ALT, 0);
4863
4864    e_mod_comp_x_grab_set(c, EINA_FALSE);
4865
4866    if((c->fake_image_launch) && (c->eff_img))
4867      c->effect_funcs.image_launch_free(c->eff_img);
4868
4869    while (c->wins)
4870      {
4871         cw = (E_Comp_Win *)(c->wins);
4872         if (cw->counter)
4873           {
4874              ecore_x_sync_counter_free(cw->counter);
4875              cw->counter = 0;
4876              cw->sync_info.val = 0;
4877           }
4878         cw->force = 1;
4879         _e_mod_comp_win_hide(cw);
4880         cw->force = 1;
4881         _e_mod_comp_win_del(cw);
4882      }
4883
4884    EINA_LIST_FREE(c->canvases, canvas) e_mod_comp_canvas_del(canvas);
4885    c->canvases = NULL;
4886
4887    ecore_x_composite_unredirect_subwindows
4888      (c->man->root, ECORE_X_COMPOSITE_UPDATE_MANUAL);
4889    ecore_x_composite_render_window_disable(c->win);
4890    if (c->man->num == 0) e_alert_composite_win = 0;
4891    if (c->render_animator) ecore_animator_del(c->render_animator);
4892    if (c->new_up_timer) ecore_timer_del(c->new_up_timer);
4893    if (c->update_job) ecore_job_del(c->update_job);
4894    if (c->wins_list) eina_list_free(c->wins_list);
4895
4896    ecore_x_window_free(c->cm_selection);
4897    ecore_x_e_comp_sync_supported_set(c->man->root, 0);
4898    ecore_x_screen_is_composited_set(c->man->num, 0);
4899
4900    if (c->shape_inputs) eina_list_free(c->shape_inputs);
4901    if (c->shape_inputs_mo) eina_list_free(c->shape_inputs_mo);
4902
4903    c->effect_funcs.shutdown(c);
4904
4905    free(c);
4906 }
4907
4908 ///////////////////////////////////////////////////////////////////////////////////////////
4909 static Eina_Bool
4910 _e_mod_comp_zone_move_resize(void *data __UNUSED__,
4911                              int type   __UNUSED__,
4912                              void      *event)
4913 {
4914    E_Event_Zone_Move_Resize *ev = (E_Event_Zone_Move_Resize *)event;
4915    Eina_List *l, *ll;
4916    E_Comp *c;
4917    E_Comp_Canvas *canvas;
4918    if (!(ev && ev->zone))
4919      return ECORE_CALLBACK_PASS_ON;
4920
4921    if (!_comp_mod->conf->canvas_per_zone)
4922      return ECORE_CALLBACK_PASS_ON;
4923
4924    ELB(ELBT_COMP, "E_ZONE_MOVE_RESIZE", ev->zone->id);
4925
4926    EINA_LIST_FOREACH(compositors, l, c)
4927      {
4928         if (!c) continue;
4929         EINA_LIST_FOREACH(c->canvases, ll, canvas)
4930           {
4931              if (!canvas) continue;
4932              if (canvas->zone != ev->zone) continue;
4933              if (!((ev->zone->x == canvas->x) &&
4934                    (ev->zone->y == canvas->y)))
4935                {
4936                   canvas->x = ev->zone->x;
4937                   canvas->y = ev->zone->y;
4938                   ecore_evas_move(canvas->ee,
4939                                   canvas->x,
4940                                   canvas->y);
4941                }
4942              if (!((ev->zone->w == canvas->w) &&
4943                    (ev->zone->h == canvas->h)))
4944                {
4945                   canvas->w = ev->zone->w;
4946                   canvas->h = ev->zone->h;
4947                   ecore_evas_resize(canvas->ee,
4948                                     canvas->w,
4949                                     canvas->h);
4950                }
4951              break;
4952           }
4953      }
4954    return ECORE_CALLBACK_PASS_ON;
4955 }
4956
4957 static Eina_Bool
4958 _e_mod_comp_zone_add(void *data __UNUSED__,
4959                      int type   __UNUSED__,
4960                      void      *event)
4961 {
4962    E_Event_Zone_Add *ev = (E_Event_Zone_Add *)event;
4963    Eina_List *l, *ll;
4964    E_Comp *c;
4965    E_Comp_Canvas *canvas;
4966    E_Comp_Win *cw;
4967    E_Comp_Object *co;
4968    Eina_Bool found = EINA_FALSE;
4969    if ((!ev) || (!ev->zone) ||
4970        (!ev->zone->container))
4971      {
4972         return ECORE_CALLBACK_PASS_ON;
4973      }
4974    if (!_comp_mod->conf->canvas_per_zone)
4975      {
4976         return ECORE_CALLBACK_PASS_ON;
4977      }
4978
4979    EINA_LIST_FOREACH(compositors, l, c)
4980      {
4981         EINA_LIST_FOREACH(c->canvases, ll, canvas)
4982           {
4983              if (canvas->zone == ev->zone)
4984                {
4985                   found = EINA_TRUE;
4986                   break;
4987                }
4988           }
4989      }
4990
4991    if (found) return ECORE_CALLBACK_PASS_ON;
4992
4993    ELB(ELBT_COMP, "E_ZONE_ADD", ev->zone->id);
4994
4995    EINA_LIST_FOREACH(compositors, l, c)
4996      {
4997         if ((!c) || (c->man != ev->zone->container->manager))
4998           {
4999              continue;
5000           }
5001
5002         canvas = e_mod_comp_canvas_add(c, ev->zone);
5003         if (!canvas) return ECORE_CALLBACK_PASS_ON;
5004
5005         ecore_x_window_shape_rectangle_add(c->win,
5006                                            canvas->zone->x,
5007                                            canvas->zone->y,
5008                                            canvas->zone->w,
5009                                            canvas->zone->h);
5010         ecore_x_sync();
5011
5012         EINA_INLIST_FOREACH(c->wins, cw)
5013           {
5014              Eina_Bool found = EINA_FALSE;
5015              Eina_List *lll;
5016              E_Comp_Canvas *_canvas;
5017              EINA_LIST_FOREACH(c->canvases, lll, _canvas)
5018                {
5019                   if (_canvas->ee_win == cw->win)
5020                     {
5021                        found = 1;
5022                        break;
5023                     }
5024                }
5025
5026              co = e_mod_comp_obj_add(cw, canvas);
5027              if (!co) continue;
5028
5029              cw->objs = eina_list_append(cw->objs, co);
5030
5031              if ((!cw->input_only) && (!cw->invalid))
5032                {
5033                   e_mod_comp_win_shadow_setup(cw, co);
5034                   e_mod_comp_win_cb_setup(cw, co);
5035                   evas_object_show(co->img);
5036
5037                   _e_mod_comp_win_transparent_rect_update(cw);
5038
5039                   if (cw->bd) evas_object_data_set(co->shadow, "border", cw->bd);
5040                   else if (cw->pop)
5041                     evas_object_data_set(co->shadow, "popup", cw->pop);
5042                   else if (cw->menu)
5043                     evas_object_data_set(co->shadow, "menu", cw->menu);
5044
5045                   evas_object_pass_events_set(co->img, 1);
5046                }
5047
5048              evas_object_pass_events_set(co->shadow, 1);
5049              evas_object_data_set(co->shadow, "win",
5050                                   (void *)((unsigned long)cw->win));
5051              evas_object_data_set(co->shadow, "src", cw);
5052
5053              int zx = 0, zy = 0;
5054              zx = co->zone->x;
5055              zy = co->zone->y;
5056              evas_object_move(co->shadow, cw->x - zx, cw->y - zy);
5057              evas_object_resize(co->shadow, cw->pw, cw->ph);
5058
5059              if (cw->visible)
5060                {
5061                   evas_object_image_size_set(co->img, cw->pw, cw->ph);
5062                   Evas_Object *o;
5063                   EINA_LIST_FOREACH(co->img_mirror, ll, o)
5064                     {
5065                        evas_object_image_size_set(o, cw->pw, cw->ph);
5066                     }
5067                   if ((cw->dmg_updates >= 1))
5068                     {
5069                        cw->defer_hide = 0;
5070                        if (!cw->hidden_override)
5071                          evas_object_show(co->shadow);
5072                        edje_object_signal_emit(co->shadow, "e,state,visible,on", "e");
5073                        if (!cw->animating)
5074                          {
5075                             cw->c->animating++;
5076                          }
5077                        cw->animating = 1;
5078                        _e_mod_comp_win_render_queue(cw);
5079
5080                        cw->pending_count++;
5081                        e_manager_comp_event_src_visibility_send
5082                          (cw->c->man, (E_Manager_Comp_Source *)cw,
5083                          _e_mod_comp_cb_pending_after, cw->c);
5084                     }
5085                }
5086           } // end of eina_inlist
5087      }
5088    return ECORE_CALLBACK_PASS_ON;
5089 }
5090
5091 static Eina_Bool
5092 _e_mod_comp_zone_del(void *data __UNUSED__,
5093                      int type   __UNUSED__,
5094                      void      *event)
5095 {
5096    E_Event_Zone_Del *ev = (E_Event_Zone_Del *)event;
5097    Eina_List *l, *ll, *lll;
5098    E_Comp *c;
5099    E_Comp_Canvas *canvas;
5100    E_Comp_Win *cw;
5101    E_Comp_Object *co;
5102    if (!ev || !ev->zone)
5103      {
5104         return ECORE_CALLBACK_PASS_ON;
5105      }
5106    if (!_comp_mod->conf->canvas_per_zone)
5107      {
5108         return ECORE_CALLBACK_PASS_ON;
5109      }
5110
5111    ELB(ELBT_COMP, "E_ZONE_DEL", ev->zone->id);
5112
5113    EINA_LIST_FOREACH(compositors, l, c)
5114      {
5115         EINA_LIST_FOREACH(c->canvases, ll, canvas)
5116           {
5117              if (canvas->zone != ev->zone) continue;
5118              EINA_INLIST_REVERSE_FOREACH(c->wins, cw)
5119                {
5120                   EINA_LIST_FOREACH(cw->objs, lll, co)
5121                     {
5122                        if (co->zone != ev->zone) continue;
5123                        cw->objs = eina_list_remove(cw->objs, co);
5124                        e_mod_comp_obj_del(co);
5125                     }
5126                }
5127
5128              ecore_x_window_shape_rectangle_subtract(c->win,
5129                                                      canvas->zone->x,
5130                                                      canvas->zone->y,
5131                                                      canvas->zone->w,
5132                                                      canvas->zone->h);
5133              ecore_x_sync();
5134
5135              c->canvases = eina_list_remove(c->canvases, canvas);
5136              e_mod_comp_canvas_del(canvas);
5137              break;
5138           }
5139      }
5140    return ECORE_CALLBACK_PASS_ON;
5141 }
5142
5143 static Eina_Bool
5144 _e_mod_comp_zone_rot_begin(void *data __UNUSED__,
5145                            int type   __UNUSED__,
5146                            void      *event)
5147 {
5148    E_Event_Zone_Rotation_Change_Begin *ev = (E_Event_Zone_Rotation_Change_Begin *)event;
5149    Eina_List *l, *ll;
5150    E_Comp *c;
5151    E_Comp_Canvas *canvas;
5152
5153    if (!(ev && ev->zone))
5154      return ECORE_CALLBACK_PASS_ON;
5155
5156    ELBF(ELBT_COMP, 0, ev->zone->num, "%15.15s|", "ZONE_ROT_BEGIN");
5157
5158    EINA_LIST_FOREACH(compositors, l, c)
5159      {
5160         if (!c) continue;
5161         EINA_LIST_FOREACH(c->canvases, ll, canvas)
5162           {
5163              if (!canvas) continue;
5164              if (canvas->zone != ev->zone) continue;
5165              if (canvas->zr)
5166                {
5167 #if HWC_ROTATION_PATCH
5168                   if ((_comp_mod->conf->use_hwc) && (c->hwcomp_funcs.cb_rotation_begin))
5169                      c->hwcomp_funcs.cb_rotation_begin(canvas->hwcomp);
5170 #endif
5171                   c->effect_funcs.zone_rotation_begin(canvas->zr);
5172                   break;
5173                }
5174           }
5175      }
5176    return ECORE_CALLBACK_PASS_ON;
5177 }
5178
5179 static Eina_Bool
5180 _e_mod_comp_zone_rot_cancel(void *data __UNUSED__,
5181                             int type   __UNUSED__,
5182                             void      *event)
5183 {
5184    E_Event_Zone_Rotation_Change_Cancel *ev = (E_Event_Zone_Rotation_Change_Cancel *)event;
5185    Eina_List *l, *ll;
5186    E_Comp *c;
5187    E_Comp_Canvas *canvas;
5188
5189    if (!(ev && ev->zone))
5190      return ECORE_CALLBACK_PASS_ON;
5191
5192    ELBF(ELBT_COMP, 0, ev->zone->num, "%15.15s|", "ZONE_ROT_CANCEL");
5193
5194    EINA_LIST_FOREACH(compositors, l, c)
5195      {
5196         if (!c) continue;
5197         EINA_LIST_FOREACH(c->canvases, ll, canvas)
5198           {
5199              if (!canvas) continue;
5200              if (canvas->zone != ev->zone) continue;
5201              if (canvas->zr)
5202                {
5203 #if HWC_ROTATION_PATCH
5204                   if ((_comp_mod->conf->use_hwc) && (c->hwcomp_funcs.cb_rotation_end))
5205                      c->hwcomp_funcs.cb_rotation_end(canvas->hwcomp);
5206 #endif
5207                   canvas->xv_ready[0] = EINA_FALSE;
5208                   c->effect_funcs.zone_rotation_cancel(canvas->zr);
5209                }
5210              break;
5211           }
5212      }
5213    return ECORE_CALLBACK_PASS_ON;
5214 }
5215
5216 static Eina_Bool
5217 _e_mod_comp_zone_rot_end(void *data __UNUSED__,
5218                          int type   __UNUSED__,
5219                          void      *event)
5220 {
5221    E_Event_Zone_Rotation_Change_End *ev = (E_Event_Zone_Rotation_Change_End *)event;
5222    Eina_List *l, *ll;
5223    E_Comp *c;
5224    E_Comp_Canvas *canvas;
5225
5226    if (!(ev && ev->zone))
5227      return ECORE_CALLBACK_PASS_ON;
5228
5229    ELBF(ELBT_COMP, 0, ev->zone->num, "%15.15s|", "ZONE_ROT_END");
5230
5231    EINA_LIST_FOREACH(compositors, l, c)
5232      {
5233         if (!c) continue;
5234         EINA_LIST_FOREACH(c->canvases, ll, canvas)
5235           {
5236              if (!canvas) continue;
5237              if (canvas->zone != ev->zone) continue;
5238              if (canvas->zr)
5239                {
5240 #if HWC_ROTATION_PATCH
5241                   if ((_comp_mod->conf->use_hwc) && (c->hwcomp_funcs.cb_rotation_end))
5242                      c->hwcomp_funcs.cb_rotation_end(canvas->hwcomp);
5243 #endif
5244                   if (canvas->xv_ready[0])
5245                     {
5246                        canvas->xv_ready[1] = EINA_TRUE;
5247                        if (!canvas->xv_ready[2])
5248                           break;
5249                     }
5250                   Eina_Bool res = c->effect_funcs.zone_rotation_end(canvas->zr);
5251                   if (res)
5252                      c->effect_funcs.zone_rotation_do(canvas->zr);
5253                   else
5254                      c->effect_funcs.zone_rotation_clear(canvas->zr);
5255
5256                }
5257              break;
5258           }
5259      }
5260    return ECORE_CALLBACK_PASS_ON;
5261 }
5262
5263 //////////////////////////////////////////////////////////////////////////
5264
5265 static Eina_Bool
5266 _e_mod_comp_hwc_configure(void *data __UNUSED__,
5267                           int ev_type   __UNUSED__,
5268                           void *event)
5269 {
5270    Ecore_X_Event_Generic *e = (Ecore_X_Event_Generic *)event;
5271    Eina_List *l = NULL;
5272    E_Comp *c = NULL;
5273
5274    if (!e) return ECORE_CALLBACK_PASS_ON;
5275
5276    /* FIXME : No problem regarding timing issue??? */
5277    if (_comp_mod->conf->use_hwc)
5278      {
5279         EINA_LIST_FOREACH(compositors, l, c)
5280           {
5281              if (!c) continue;
5282              if (c->hwcomp_funcs.process_event)
5283                 c->hwcomp_funcs.process_event(c, e);
5284           }
5285      }
5286
5287    return ECORE_CALLBACK_PASS_ON;
5288 }
5289
5290 //////////////////////////////////////////////////////////////////////////
5291
5292 Eina_Bool
5293 e_mod_comp_init(void)
5294 {
5295    Eina_List *l;
5296    E_Manager *man;
5297    unsigned int effect = 0;
5298    int res = 0;
5299
5300    windows = eina_hash_string_superfast_new(NULL);
5301    borders = eina_hash_string_superfast_new(NULL);
5302    damages = eina_hash_string_superfast_new(NULL);
5303
5304    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_CREATE,         _e_mod_comp_create,           NULL));
5305    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_DESTROY,        _e_mod_comp_destroy,          NULL));
5306    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHOW_REQUEST,   _e_mod_comp_show_request,     NULL));
5307    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHOW,           _e_mod_comp_show,             NULL));
5308    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_HIDE,           _e_mod_comp_hide,             NULL));
5309    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_REPARENT,       _e_mod_comp_reparent,         NULL));
5310    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_CONFIGURE,      _e_mod_comp_configure,        NULL));
5311    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_STACK,          _e_mod_comp_stack,            NULL));
5312    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY,       _e_mod_comp_property,         NULL));
5313    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,        _e_mod_comp_message,          NULL));
5314    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHAPE,          _e_mod_comp_shape,            NULL));
5315    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_DAMAGE_NOTIFY,         _e_mod_comp_damage,           NULL));
5316    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_DAMAGE,         _e_mod_comp_damage_win,       NULL));
5317    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,                _e_mod_comp_key_down,         NULL));
5318    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_CONTAINER_RESIZE,            _e_mod_comp_randr,            NULL));
5319    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_ADD,                  _e_mod_comp_bd_add,           NULL));
5320    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_REMOVE,               _e_mod_comp_bd_del,           NULL));
5321    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_SHOW,                 _e_mod_comp_bd_show,          NULL));
5322    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_HIDE,                 _e_mod_comp_bd_hide,          NULL));
5323    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_MOVE,                 _e_mod_comp_bd_move,          NULL));
5324    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_RESIZE,               _e_mod_comp_bd_resize,        NULL));
5325    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_ICONIFY,              _e_mod_comp_bd_iconify,       NULL));
5326    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_UNICONIFY,            _e_mod_comp_bd_uniconify,     NULL));
5327    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_FOCUS_IN,             _e_mod_comp_bd_focus_in,      NULL));
5328    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_FOCUS_OUT,            _e_mod_comp_bd_focus_out,     NULL));
5329    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_STACK,                _e_mod_comp_bd_stack,         NULL));
5330    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_ZONE_MOVE_RESIZE,            _e_mod_comp_zone_move_resize, NULL));
5331    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_ZONE_ADD,                    _e_mod_comp_zone_add,         NULL));
5332    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_ZONE_DEL,                    _e_mod_comp_zone_del,         NULL));
5333    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_ZONE_ROTATION_CHANGE_BEGIN,  _e_mod_comp_zone_rot_begin,   NULL));
5334    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_ZONE_ROTATION_CHANGE_CANCEL, _e_mod_comp_zone_rot_cancel,  NULL));
5335    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_ZONE_ROTATION_CHANGE_END,    _e_mod_comp_zone_rot_end,     NULL));
5336    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_GENERIC,               _e_mod_comp_hwc_configure,    NULL));
5337    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_RANDR_OUTPUT_PROPERTY_NOTIFY, _e_mod_comp_cb_rr_output_prop, NULL));
5338 #ifdef _F_USE_BORDER_TRANSFORM_
5339    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_TRANSFORM_CHANGED, _e_mod_comp_bd_transform_changed, NULL));
5340 #endif /* end of _F_USE_BORDER_TRANSFORM_ */
5341    handlers_hook = eina_list_append(handlers_hook, e_border_hook_add(E_BORDER_HOOK_AUX_HINT_EVAL,     e_mod_comp_aux_hint_eval,     NULL));
5342
5343    res = e_mod_comp_atoms_init();
5344    E_CHECK_RETURN(res, 0);
5345
5346    res = e_mod_comp_win_type_init();
5347    E_CHECK_RETURN(res, 0);
5348
5349    res = e_mod_comp_policy_init();
5350    E_CHECK_RETURN(res, 0);
5351
5352    if (!ecore_x_composite_query())
5353      {
5354         e_util_dialog_internal
5355           (_("Compositor Error"),
5356           _("Your X Display does not support the XComposite extension<br>"
5357             "or Ecore was built without XComposite support.<br>"
5358             "Note that for composite support you will also need<br>"
5359             "XRender and XFixes support in X11 and Ecore."));
5360         return 0;
5361      }
5362    if (!ecore_x_damage_query())
5363      {
5364         e_util_dialog_internal
5365           (_("Compositor Error"),
5366           _("Your screen does not support the XDamage extension<br>"
5367             "or Ecore was built without XDamage support."));
5368         return 0;
5369      }
5370
5371    EINA_LIST_FOREACH(e_manager_list(), l, man)
5372      {
5373         E_Comp *c;
5374         if (!man) continue;
5375         c = _e_mod_comp_add(man);
5376         if (c)
5377           {
5378              int w, h;
5379              if (c->fake_image_launch)
5380                {
5381                   c->evas = _e_mod_comp_evas_get_func(c, c->man);
5382                   ecore_x_window_size_get(c->win, &w, &h);
5383                   c->eff_img = c->effect_funcs.image_launch_new(c->evas, w, h);
5384                }
5385
5386              compositors = eina_list_append(compositors, c);
5387              e_mod_comp_util_set(c, man);
5388              ecore_animator_frametime_set(1.0f/60.0f);
5389
5390              if (_comp_mod->conf->default_window_effect) effect = 1;
5391              ecore_x_window_prop_card32_set
5392                (c->man->root, ATOM_EFFECT_ENABLE,
5393                &effect, 1);
5394              ecore_x_window_prop_property_set
5395                (c->man->root, ATOM_OVERAY_WINDOW,
5396                ECORE_X_ATOM_WINDOW, 32, &c->win, 1);
5397           }
5398      }
5399    ecore_x_sync();
5400
5401    res = e_mod_comp_aux_hint_init();
5402    E_CHECK_RETURN(res, 0);
5403
5404    return 1;
5405 }
5406
5407 void
5408 e_mod_comp_shutdown(void)
5409 {
5410    E_Comp *c;
5411
5412    EINA_LIST_FREE(compositors, c) _e_mod_comp_del(c);
5413
5414    E_FREE_LIST(handlers, ecore_event_handler_del);
5415
5416    E_FREE_LIST(handlers_hook, e_border_hook_del);
5417
5418    if (damages) eina_hash_free(damages);
5419    if (windows) eina_hash_free(windows);
5420    if (borders) eina_hash_free(borders);
5421    damages = NULL;
5422    windows = NULL;
5423    borders = NULL;
5424
5425    e_mod_comp_aux_hint_shutdown();;
5426    e_mod_comp_policy_shutdown();
5427    e_mod_comp_win_type_shutdown();
5428    e_mod_comp_atoms_shutdown();
5429
5430    e_mod_comp_util_set(NULL, NULL);
5431 }
5432
5433 void
5434 e_mod_comp_shadow_set(void)
5435 {
5436    Eina_List *l, *ll;
5437    E_Comp *c;
5438    E_Comp_Win *cw;
5439    E_Comp_Object *co;
5440
5441    EINA_LIST_FOREACH(compositors, l, c)
5442      {
5443         if (!c) continue;
5444         EINA_INLIST_FOREACH(c->wins, cw)
5445           {
5446              e_mod_comp_win_type_setup(cw);
5447              EINA_LIST_FOREACH(cw->objs, ll, co)
5448                {
5449                   if (!co) continue;
5450                   if ((co->shadow) && (co->img))
5451                     e_mod_comp_win_shadow_setup(cw, co);
5452                }
5453              c->effect_funcs.win_show(cw);
5454              _e_mod_comp_win_transparent_rect_update(cw);
5455           }
5456      }
5457 }
5458
5459 EAPI void
5460 e_mod_comp_win_cb_setup(E_Comp_Win    *cw,
5461                         E_Comp_Object *co)
5462 {
5463    edje_object_signal_callback_add(co->shadow, "e,action,show,done", "e", _e_mod_comp_show_done, cw);
5464    edje_object_signal_callback_add(co->shadow, "e,action,hide,done", "e", _e_mod_comp_hide_done, cw);
5465 }
5466
5467 EAPI void
5468 e_mod_comp_x_grab_set(E_Comp *c,
5469                       Eina_Bool grab)
5470 {
5471    E_CHECK(_comp_mod->conf->grab);
5472    E_CHECK(c);
5473    E_CHECK((c->grabbed != grab));
5474    if (grab)
5475      ecore_x_grab();
5476    else
5477      ecore_x_ungrab();
5478    c->grabbed = grab;
5479 }