Git init
[framework/uifw/e17-extra-modules.git] / comp-slp / src / e_mod_comp.c
1 //////////////////////////////////////////////////////////////////////////
2 //
3 // TODO (no specific order):
4 //   1. abstract evas object and compwin so we can duplicate the object N times
5 //      in N canvases - for winlist, everything, pager etc. too
6 //   2. implement "unmapped composite cache" -> N pixels worth of unmapped
7 //      windows to be fully composited. only the most active/recent.
8 //   3. for unmapped windows - when window goes out of unmapped comp cachew
9 //      make a miniature copy (1/4 width+height?) and set property on window
10 //      with pixmap id
11 //   8. obey transparent property
12 //   9. shortcut lots of stuff to draw inside the compositor - shelf,
13 //      wallpaper, efm - hell even menus and anything else in e (this is what
14 //      e18 was mostly about)
15 //  10. fullscreen windows need to be able to bypass compositing *seems buggy*
16 //
17 //////////////////////////////////////////////////////////////////////////
18
19 /* Local Include */
20 #include "e.h"
21 #include "e_mod_main.h"
22 #include "e_mod_comp.h"
23 #include "e_mod_comp_update.h"
24 #include "e_mod_comp_rotation.h"
25 #include "e_mod_comp_data.h"
26 #include "e_mod_comp_animation.h"
27 #include "config.h"
28
29 /* Global Include */
30 #include <utilX.h>
31 #include <X11/Xlib.h>
32 #include <dlog.h>
33
34 /* debug infos */
35 #if COMP_LOGGER_BUILD_ENABLE
36 typedef struct _Comp_Logger Comp_Logger;
37 struct _Comp_Logger
38 {
39     int logger_type;
40     char logger_dump_file[256];
41 };
42 int comp_logger_type                              = LT_NOTHING;
43 #define STR_ATOM_CM_LOG                           "_E_COMP_LOG"
44 Ecore_X_Atom ATOM_CM_LOG                          = 0;
45 #define STR_ATOM_CM_LOG_DUMP_DONE                 "_E_COMP_LOG_DUMP_DONE"
46 Ecore_X_Atom ATOM_CM_LOG_DUMP_DONE                = 0;
47 #endif
48
49 /* Macros */
50 #define OVER_FLOW 4
51 #define _WND_REQUEST_ANGLE_IDX 0
52 #define _WND_CURR_ANGLE_IDX    1
53 #define STR_ATOM_FAKE_LAUNCH_IMAGE                 "_E_COMP_FAKE_LAUNCH_IMAGE"
54 #define STR_ATOM_FAKE_LAUNCH                       "_E_COMP_FAKE_LAUNCH"
55 #define STR_ATOM_NET_CM_EFFECT_ENABLE              "_NET_CM_EFFECT_ENABLE"
56 #define STR_ATOM_NET_CM_WINDOW_EFFECT_ENABLE       "_NET_CM_WINDOW_EFFECT_ENABLE"
57 #define STR_ATOM_NET_CM_WINDOW_EFFECT_CLIENT_STATE "_NET_CM_WINDOW_EFFECT_CLIENT_STATE"
58 #define STR_ATOM_NET_CM_WINDOW_EFFECT_STATE        "_NET_CM_WINDOW_EFFECT_STATE"
59 #define STR_ATOM_NET_CM_WINDOW_EFFECT_TYPE         "_NET_CM_WINDOW_EFFECT_TYPE"
60 #define STR_ATOM_NET_CM_EFFECT_DEFAULT             "_NET_CM_EFFECT_DEFAULT"
61 #define STR_ATOM_NET_CM_EFFECT_NONE                "_NET_CM_EFFECT_NONE"
62 #define STR_ATOM_NET_CM_EFFECT_CUSTOM0             "_NET_CM_EFFECT_CUSTOM0"
63 #define STR_ATOM_NET_CM_EFFECT_CUSTOM1             "_NET_CM_EFFECT_CUSTOM1"
64 #define STR_ATOM_NET_CM_EFFECT_CUSTOM2             "_NET_CM_EFFECT_CUSTOM2"
65 #define STR_ATOM_NET_CM_EFFECT_CUSTOM3             "_NET_CM_EFFECT_CUSTOM3"
66 #define STR_ATOM_NET_CM_EFFECT_CUSTOM4             "_NET_CM_EFFECT_CUSTOM4"
67 #define STR_ATOM_NET_CM_EFFECT_CUSTOM5             "_NET_CM_EFFECT_CUSTOM5"
68 #define STR_ATOM_NET_CM_EFFECT_CUSTOM6             "_NET_CM_EFFECT_CUSTOM6"
69 #define STR_ATOM_NET_CM_EFFECT_CUSTOM7             "_NET_CM_EFFECT_CUSTOM7"
70 #define STR_ATOM_NET_CM_EFFECT_CUSTOM8             "_NET_CM_EFFECT_CUSTOM8"
71 #define STR_ATOM_NET_CM_EFFECT_CUSTOM9             "_NET_CM_EFFECT_CUSTOM9"
72 #define STR_ATOM_OVERAY_WINDOW                     "_E_COMP_OVERAY_WINDOW"
73 #define STR_ATOM_X_HIBERNATION_STATE               "X_HIBERNATION_STATE"
74 #define STR_ATOM_X_SCREEN_ROTATION                 "X_SCREEN_ROTATION"
75 #define STR_ATOM_CM_LOCK_SCREEN                    "_E_COMP_LOCK_SCREEN"
76 #define STR_ATOM_CM_PIXMAP_ROTATION_SUPPORTED      "_E_COMP_PIXMAP_ROTATION_SUPPORTED"
77 #define STR_ATOM_CM_PIXMAP_ROTATION_STATE          "_E_COMP_PIXMAP_ROTATION_STATE"
78 #define STR_ATOM_CM_PIXMAP_ROTATION_BEGIN          "_E_COMP_PIXMAP_ROTATION_BEGIN"
79 #define STR_ATOM_CM_PIXMAP_ROTATION_BEGIN_DONE     "_E_COMP_PIXMAP_ROTATION_BEGIN_DONE"
80 #define STR_ATOM_CM_PIXMAP_ROTATION_END            "_E_COMP_PIXMAP_ROTATION_END"
81 #define STR_ATOM_CM_PIXMAP_ROTATION_END_DONE       "_E_COMP_PIXMAP_ROTATION_END_DONE"
82 #define STR_ATOM_CM_PIXMAP_ROTATION_REQUEST        "_E_COMP_PIXMAP_ROTATION_REQUEST"
83 #define STR_ATOM_CM_PIXMAP_ROTATION_REQUEST_DONE   "_E_COMP_PIXMAP_ROTATION_REQUEST_DONE"
84 #define STR_ATOM_CM_PIXMAP_ROTATION_RESIZE_PIXMAP  "_E_COMP_PIXMAP_ROTATION_RESIZE_PIXMAP"
85 #define STR_ATOM_CAPTURE_EFFECT                    "_E_COMP_CAPTURE_EFFECT"
86
87 /* static global variables */
88 static Eina_List *handlers = NULL;
89 static Eina_List *compositors = NULL;
90 static Eina_Hash *windows = NULL;
91 static Eina_Hash *borders = NULL;
92 static Eina_Hash *damages = NULL;
93 static E_Comp    *_comp = NULL;
94
95 /* global variables */
96 Ecore_X_Atom ATOM_FAKE_LAUNCH                     = 0;
97 Ecore_X_Atom ATOM_FAKE_LAUNCH_IMAGE               = 0;
98 Ecore_X_Atom ATOM_EFFECT_ENABLE                   = 0;
99 Ecore_X_Atom ATOM_WINDOW_EFFECT_ENABLE            = 0;
100 Ecore_X_Atom ATOM_WINDOW_EFFECT_CLIENT_STATE      = 0;
101 Ecore_X_Atom ATOM_WINDOW_EFFECT_STATE             = 0;
102 Ecore_X_Atom ATOM_WINDOW_EFFECT_TYPE              = 0;
103 Ecore_X_Atom ATOM_EFFECT_DEFAULT                  = 0;
104 Ecore_X_Atom ATOM_EFFECT_NONE                     = 0;
105 Ecore_X_Atom ATOM_EFFECT_CUSTOM0                  = 0;
106 Ecore_X_Atom ATOM_EFFECT_CUSTOM1                  = 0;
107 Ecore_X_Atom ATOM_EFFECT_CUSTOM2                  = 0;
108 Ecore_X_Atom ATOM_EFFECT_CUSTOM3                  = 0;
109 Ecore_X_Atom ATOM_EFFECT_CUSTOM4                  = 0;
110 Ecore_X_Atom ATOM_EFFECT_CUSTOM5                  = 0;
111 Ecore_X_Atom ATOM_EFFECT_CUSTOM6                  = 0;
112 Ecore_X_Atom ATOM_EFFECT_CUSTOM7                  = 0;
113 Ecore_X_Atom ATOM_EFFECT_CUSTOM8                  = 0;
114 Ecore_X_Atom ATOM_EFFECT_CUSTOM9                  = 0;
115 Ecore_X_Atom ATOM_OVERAY_WINDOW                   = 0;
116 Ecore_X_Atom ATOM_X_HIBERNATION_STATE             = 0;
117 Ecore_X_Atom ATOM_X_SCREEN_ROTATION               = 0;
118 Ecore_X_Atom ATOM_CM_LOCK_SCREEN                  = 0;
119 Ecore_X_Atom ATOM_CM_PIXMAP_ROTATION_SUPPORTED    = 0;
120 Ecore_X_Atom ATOM_CM_PIXMAP_ROTATION_STATE        = 0;
121 Ecore_X_Atom ATOM_CM_PIXMAP_ROTATION_BEGIN        = 0;
122 Ecore_X_Atom ATOM_CM_PIXMAP_ROTATION_BEGIN_DONE   = 0;
123 Ecore_X_Atom ATOM_CM_PIXMAP_ROTATION_END          = 0;
124 Ecore_X_Atom ATOM_CM_PIXMAP_ROTATION_END_DONE     = 0;
125 Ecore_X_Atom ATOM_CM_PIXMAP_ROTATION_REQUEST      = 0;
126 Ecore_X_Atom ATOM_CM_PIXMAP_ROTATION_REQUEST_DONE = 0;
127 Ecore_X_Atom ATOM_CM_PIXMAP_ROTATION_RESIZE_PIXMAP= 0;
128 Ecore_X_Atom ATOM_CAPTURE_EFFECT                  = 0;
129
130 /* static functions */
131 static void               _e_mod_comp_set                             (E_Comp *c);
132 E_Comp                  * _e_mod_comp_get                             (void);
133 static void               _e_mod_comp_render_queue                    (E_Comp *c);
134 static void               _e_mod_comp_win_damage                      (E_Comp_Win *cw, int x, int y, int w, int h, Eina_Bool dmg);
135 static void               _e_mod_comp_win_del                         (E_Comp_Win *cw);
136 static void               _e_mod_comp_win_real_hide                   (E_Comp_Win *cw);
137 static void               _e_mod_comp_win_hide                        (E_Comp_Win *cw);
138 static void               _e_mod_comp_win_configure                   (E_Comp_Win *cw, int x, int y, int w, int h, int border);
139 static void               _e_mod_comp_screen_lock                     (E_Comp *c);
140 static void               _e_mod_comp_screen_unlock                   (E_Comp *c);
141 static Eina_Bool          _e_mod_comp_screen_lock_timeout             (void *data);
142 static void               _e_mod_comp_screen_lock_func                (void *data, E_Manager *man __UNUSED__);
143 static void               _e_mod_comp_screen_unlock_func              (void *data, E_Manager *man __UNUSED__);
144 static Eina_Bool          _e_mod_comp_win_rotation_begin_timeout      (void *data);
145 static Eina_Bool          _e_mod_comp_win_rotation_end_timeout        (void *data);
146 static Eina_Bool          _e_mod_comp_win_damage_timeout              (void *data);
147 static void               _e_mod_comp_win_raise                       (E_Comp_Win *cw);
148 static void               _e_mod_comp_win_lower                       (E_Comp_Win *cw);
149 static void               _e_mod_comp_win_unredirect                  (E_Comp_Win *cw);
150 static E_Comp_Win       * _e_mod_comp_win_find                        (Ecore_X_Window win);
151 static Eina_Bool          _e_mod_comp_win_add_damage                  (E_Comp_Win *cw, Ecore_X_Damage damage);
152 static Eina_Bool          _e_mod_comp_win_del_damage                  (E_Comp_Win *cw, Ecore_X_Damage damage);
153 static E_Comp_Win       * _e_mod_comp_border_client_find              (Ecore_X_Window win);
154 static void               _e_mod_comp_win_recreate_shobj              (E_Comp_Win *cw);
155 static void               _e_mod_comp_win_cb_setup                    (E_Comp_Win *cw);
156 static Eina_Bool          _e_mod_comp_is_next_win_stack               (E_Comp_Win *cw, E_Comp_Win *cw2);
157 static Eina_Bool          _e_mod_comp_get_edje_error                  (E_Comp_Win *cw);
158 static void               _e_mod_comp_atom_init                       (void);
159 static Eina_Bool          _e_mod_comp_cb_update                       (E_Comp *c);
160 static Ecore_X_Window     _e_mod_comp_win_get_client_xid              (E_Comp_Win *cw);
161 static Eina_Bool          _e_mod_comp_win_is_border                   (E_Comp_Win *cw);
162
163 /* non-static functions */
164 void                      _e_mod_comp_done_defer                      (E_Comp_Win *cw);
165 void                      _e_mod_comp_cb_pending_after                (void *data __UNUSED__, E_Manager *man __UNUSED__, E_Manager_Comp_Source *src);
166 E_Comp                  * _e_mod_comp_find                            (Ecore_X_Window root);
167 Eina_Bool                 _e_mod_comp_fake_launch_timeout             (void *data);
168 void                      _e_mod_comp_win_render_queue                (E_Comp_Win *cw);
169 void                      _e_mod_comp_send_window_effect_client_state (E_Comp_Win *cw, Eina_Bool effect_state);
170 Eina_Bool                 _e_mod_comp_win_check_visible               (E_Comp_Win *cw);
171 Eina_Bool                 _e_mod_comp_win_check_visible3              (E_Comp_Win *cw);
172 E_Comp_Win              * _e_mod_comp_win_transient_parent_find       (E_Comp_Win * cw);
173 E_Comp_Win              * _e_mod_comp_win_find_background_win         (E_Comp_Win * cw);
174 E_Comp_Win              * _e_mod_comp_win_find_by_indicator           (E_Comp *c);
175 E_Comp_Win              * _e_mod_comp_win_find_fake_background_win    (E_Comp *c);
176 void                      _e_mod_comp_disable_touch_event_block       (E_Comp *c);
177 void                      _e_mod_comp_enable_touch_event_block        (E_Comp *c);
178 void                      _e_mod_comp_win_inc_animating               (E_Comp_Win *cw);
179 void                      _e_mod_comp_win_dec_animating               (E_Comp_Win *cw);
180 void                      ecore_x_e_comp_dri_buff_flip_supported_set  (Ecore_X_Window root, Eina_Bool enabled); // TODO
181
182 /* extern functions */
183 extern Eina_Bool          _e_mod_comp_is_quickpanel_window            (E_Border *bd);
184 extern Eina_Bool          _e_mod_comp_is_task_manager_window          (E_Border *bd);
185 extern Eina_Bool          _e_mod_comp_is_live_magazine_window         (E_Border *bd);
186 extern Eina_Bool          _e_mod_comp_is_lock_screen_window           (E_Border *bd);
187 extern Eina_Bool          _e_mod_comp_is_indicator_window             (E_Border *bd);
188 extern Eina_Bool          _e_mod_comp_is_isf_main_window              (E_Border *bd);
189 extern Eina_Bool          _e_mod_comp_is_isf_sub_window               (E_Border *bd);
190 extern Eina_Bool          _e_mod_comp_is_normal_window                (E_Border *bd);
191 extern Eina_Bool          _e_mod_comp_is_tooltip_window               (E_Border *bd);
192 extern Eina_Bool          _e_mod_comp_is_combo_window                 (E_Border *bd);
193 extern Eina_Bool          _e_mod_comp_is_dnd_window                   (E_Border *bd);
194 extern Eina_Bool          _e_mod_comp_is_desktop_window               (E_Border *bd);
195 extern Eina_Bool          _e_mod_comp_is_toolbar_window               (E_Border *bd);
196 extern Eina_Bool          _e_mod_comp_is_menu_window                  (E_Border *bd);
197 extern Eina_Bool          _e_mod_comp_is_splash_window                (E_Border *bd);
198 extern Eina_Bool          _e_mod_comp_is_drop_down_menu_window        (E_Border *bd);
199 extern Eina_Bool          _e_mod_comp_is_notification_window          (E_Border *bd);
200 extern Eina_Bool          _e_mod_comp_is_utility_window               (E_Border *bd);
201 extern Eina_Bool          _e_mod_comp_is_popup_menu_window            (E_Border *bd);
202 extern Eina_Bool          _e_mod_comp_is_dialog_window                (E_Border *bd);
203 extern void               _e_mod_comp_window_effect_policy            (E_Comp_Win *cw);
204 extern Eina_Bool          _e_mod_comp_window_restack_policy           (E_Comp_Win *cw, E_Comp_Win *cw2);
205 extern Eina_Bool          _e_mod_comp_window_rotation_policy          (E_Comp_Win *cw);
206 extern int                _e_mod_comp_shadow_policy                   (E_Comp_Win *cw);
207 extern void               _e_mod_comp_window_show_effect              (E_Comp_Win *cw);
208 extern void               _e_mod_comp_window_hide_effect              (E_Comp_Win *cw);
209 extern void               _e_mod_comp_window_restack_effect           (E_Comp_Win *cw, E_Comp_Win *cw2);
210 extern void               _e_mod_comp_disable_effect_stage            (E_Comp *c);
211 extern Eina_Bool          _e_mod_comp_fake_show                       (Ecore_X_Event_Client_Message *ev);
212 extern Eina_Bool          _e_mod_comp_fake_hide                       (Ecore_X_Event_Client_Message *ev);
213 extern void               _e_mod_comp_disable_fake_launch             (E_Comp *c);
214 extern E_Comp_Effect_Type _e_mod_comp_get_effect_type                 (Ecore_X_Atom *atom);
215 extern void               _e_mod_comp_window_lower_effect             (E_Comp_Win *cw, E_Comp_Win *cw2);
216
217 Eina_Bool
218 _e_mod_comp_capture_effect( Ecore_X_Event_Client_Message *ev )
219 {
220    E_Comp *c = NULL;
221
222    if ( ev == NULL ) return ECORE_CALLBACK_PASS_ON;
223    c = _e_mod_comp_find(ev->win);
224    if (!c) return ECORE_CALLBACK_PASS_ON;
225
226    evas_object_show(c->capture_effect_obj);
227    evas_object_raise(c->capture_effect_obj);
228    edje_object_signal_emit(c->capture_effect_obj, "img,state,capture,on", "img");
229
230    return ECORE_CALLBACK_PASS_ON;
231 }
232
233 static void
234 _e_mod_comp_capture_effect_show_done(void *data,
235                                      Evas_Object *obj __UNUSED__,
236                                      const char *emission __UNUSED__,
237                                      const char *source __UNUSED__)
238 {
239    E_Comp *c = (E_Comp*)data;
240    if ( !c ) return;
241    evas_object_hide(c->capture_effect_obj);
242 }
243
244 static Eina_Bool
245 _e_mod_comp_get_edje_error(E_Comp_Win *cw)
246 {
247    int error = EDJE_LOAD_ERROR_NONE;
248
249    if ((error = edje_object_load_error_get(cw->shobj)) != EDJE_LOAD_ERROR_NONE)
250      {
251         Ecore_X_Window win = _e_mod_comp_win_get_client_xid(cw);
252         switch(error)
253           {
254            case EDJE_LOAD_ERROR_GENERIC:                    fprintf(stderr, "[E17-comp] EDJE_LOAD_ERROR_GENERIC! win:0x%08x\n",                    win); break;
255            case EDJE_LOAD_ERROR_DOES_NOT_EXIST:             fprintf(stderr, "[E17-comp] EDJE_LOAD_ERROR_DOES_NOT_EXIST! win:0x%08x\n",             win); break;
256            case EDJE_LOAD_ERROR_PERMISSION_DENIED:          fprintf(stderr, "[E17-comp] EDJE_LOAD_ERROR_PERMISSION_DENIED! win:0x%08x\n",          win); break;
257            case EDJE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED: fprintf(stderr, "[E17-comp] EDJE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED! win:0x%08x\n", win); break;
258            case EDJE_LOAD_ERROR_CORRUPT_FILE:               fprintf(stderr, "[E17-comp] EDJE_LOAD_ERROR_CORRUPT_FILE! win:0x%08x\n",               win); break;
259            case EDJE_LOAD_ERROR_UNKNOWN_FORMAT:             fprintf(stderr, "[E17-comp] EDJE_LOAD_ERROR_UNKNOWN_FORMAT! win:0x%08x\n",             win); break;
260            case EDJE_LOAD_ERROR_INCOMPATIBLE_FILE:          fprintf(stderr, "[E17-comp] EDJE_LOAD_ERROR_INCOMPATIBLE_FILE! win:0x%08x\n",          win); break;
261            case EDJE_LOAD_ERROR_UNKNOWN_COLLECTION:         fprintf(stderr, "[E17-comp] EDJE_LOAD_ERROR_UNKNOWN_COLLECTION! win:0x%08x\n",         win); break;
262            case EDJE_LOAD_ERROR_RECURSIVE_REFERENCE:        fprintf(stderr, "[E17-comp] EDJE_LOAD_ERROR_RECURSIVE_REFERENCE! win:0x%08x\n",        win); break;
263            default:
264               break;
265           }
266         return EINA_FALSE;
267      }
268
269    return EINA_TRUE;
270 }
271
272 static Ecore_X_Window
273 _e_mod_comp_win_get_client_xid(E_Comp_Win *cw)
274 {
275    if (!cw) return 0;
276    if (cw->bd) return cw->bd->client.win;
277    else return cw->win;
278 }
279
280 static Eina_Bool
281 _e_mod_comp_win_is_border(E_Comp_Win *cw)
282 {
283    if (!cw) return EINA_FALSE;
284    if (cw->bd) return EINA_TRUE;
285    else return EINA_FALSE;
286 }
287
288 static void
289 _e_mod_comp_fps_update(E_Comp *c)
290 {
291    if (_comp_mod->conf->fps_show)
292      {
293         if (!c->fps_bg)
294           {
295              c->fps_bg = evas_object_rectangle_add(c->evas);
296              evas_object_color_set(c->fps_bg, 0, 0, 0, 128);
297              evas_object_layer_set(c->fps_bg, EVAS_LAYER_MAX);
298              evas_object_show(c->fps_bg);
299
300              c->fps_fg = evas_object_text_add(c->evas);
301              evas_object_text_font_set(c->fps_fg, "Sans", 10);
302              evas_object_text_text_set(c->fps_fg, "???");
303              evas_object_color_set(c->fps_fg, 255, 255, 255, 255);
304              evas_object_layer_set(c->fps_fg, EVAS_LAYER_MAX);
305              evas_object_show(c->fps_fg);
306           }
307      }
308    else
309      {
310         if (c->fps_fg)
311           {
312              evas_object_del(c->fps_fg);
313              c->fps_fg = NULL;
314           }
315         if (c->fps_bg)
316           {
317              evas_object_del(c->fps_bg);
318              c->fps_bg = NULL;
319           }
320      }
321 }
322
323 static void
324 _e_mod_comp_fps_toggle(void)
325 {
326    if (_comp_mod)
327      {
328         Eina_List *l;
329         E_Comp *c;
330
331         if (_comp_mod->conf->fps_show)
332           {
333              _comp_mod->conf->fps_show = 0;
334              e_config_save_queue();
335           }
336          else
337           {
338              _comp_mod->conf->fps_show = 1;
339              e_config_save_queue();
340           }
341          EINA_LIST_FOREACH(compositors, l, c) _e_mod_comp_cb_update(c);
342       }
343 }
344
345 char*
346 _e_mod_comp_get_atom_name(Ecore_X_Atom a)
347 {
348    if (!a) return NULL;
349
350    if      (ECORE_X_ATOM_E_COMP_SYNC_DRAW_DONE        && a == ECORE_X_ATOM_E_COMP_SYNC_DRAW_DONE       ) return "SYNC_DRAW_DONE";
351    else if (ECORE_X_ATOM_E_COMP_SYNC_COUNTER          && a == ECORE_X_ATOM_E_COMP_SYNC_COUNTER         ) return "SYNC_COUNTER";
352    else if (ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE && a == ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE) return "WIN_ROT_ANGLE";
353    else if (ECORE_X_ATOM_NET_WM_WINDOW_OPACITY        && a == ECORE_X_ATOM_NET_WM_WINDOW_OPACITY       ) return "WM_WINDOW_OPACITY";
354    else if (ATOM_EFFECT_ENABLE                        && a == ATOM_EFFECT_ENABLE                       ) return "CM_EFFECT_ENABLE";
355    else if (ATOM_WINDOW_EFFECT_ENABLE                 && a == ATOM_WINDOW_EFFECT_ENABLE                ) return "WINDOW_EFFECT_ENABLE";
356    else if (ATOM_WINDOW_EFFECT_CLIENT_STATE           && a == ATOM_WINDOW_EFFECT_CLIENT_STATE          ) return "EFFECT_CLIENT_STATE";
357    else if (ATOM_WINDOW_EFFECT_STATE                  && a == ATOM_WINDOW_EFFECT_STATE                 ) return "EFFECT_STATE";
358    else if (ATOM_WINDOW_EFFECT_TYPE                   && a == ATOM_WINDOW_EFFECT_TYPE                  ) return "EFFECT_TYPE";
359    else if (ATOM_EFFECT_DEFAULT                       && a == ATOM_EFFECT_DEFAULT                      ) return "EFFECT_DEFAULT";
360    else if (ATOM_EFFECT_NONE                          && a == ATOM_EFFECT_NONE                         ) return "EFFECT_NONE";
361    else if (ATOM_EFFECT_CUSTOM0                       && a == ATOM_EFFECT_CUSTOM0                      ) return "EFFECT_CUSTOM0";
362    else if (ATOM_EFFECT_CUSTOM1                       && a == ATOM_EFFECT_CUSTOM1                      ) return "EFFECT_CUSTOM1";
363    else if (ATOM_EFFECT_CUSTOM2                       && a == ATOM_EFFECT_CUSTOM2                      ) return "EFFECT_CUSTOM2";
364    else if (ATOM_EFFECT_CUSTOM3                       && a == ATOM_EFFECT_CUSTOM3                      ) return "EFFECT_CUSTOM3";
365    else if (ATOM_EFFECT_CUSTOM4                       && a == ATOM_EFFECT_CUSTOM4                      ) return "EFFECT_CUSTOM4";
366    else if (ATOM_EFFECT_CUSTOM5                       && a == ATOM_EFFECT_CUSTOM5                      ) return "EFFECT_CUSTOM5";
367    else if (ATOM_EFFECT_CUSTOM6                       && a == ATOM_EFFECT_CUSTOM6                      ) return "EFFECT_CUSTOM6";
368    else if (ATOM_EFFECT_CUSTOM7                       && a == ATOM_EFFECT_CUSTOM7                      ) return "EFFECT_CUSTOM7";
369    else if (ATOM_EFFECT_CUSTOM8                       && a == ATOM_EFFECT_CUSTOM8                      ) return "EFFECT_CUSTOM8";
370    else if (ATOM_EFFECT_CUSTOM9                       && a == ATOM_EFFECT_CUSTOM9                      ) return "EFFECT_CUSTOM9";
371    else if (ATOM_FAKE_LAUNCH_IMAGE                    && a == ATOM_FAKE_LAUNCH_IMAGE                   ) return "FAKE_LAUNCH_IMAGE";
372    else if (ATOM_FAKE_LAUNCH                          && a == ATOM_FAKE_LAUNCH                         ) return "FAKE_LAUNCH";
373    else if (ATOM_CM_LOCK_SCREEN                       && a == ATOM_CM_LOCK_SCREEN                      ) return "LOCK_SCREEN";
374    else if (ATOM_CM_PIXMAP_ROTATION_SUPPORTED         && a == ATOM_CM_PIXMAP_ROTATION_SUPPORTED        ) return "PIX_ROT_SUPPORTED";
375    else if (ATOM_CM_PIXMAP_ROTATION_STATE             && a == ATOM_CM_PIXMAP_ROTATION_STATE            ) return "PIX_ROT_STATE";
376    else if (ATOM_CM_PIXMAP_ROTATION_BEGIN             && a == ATOM_CM_PIXMAP_ROTATION_BEGIN            ) return "PIX_ROT_BEGIN";
377    else if (ATOM_CM_PIXMAP_ROTATION_BEGIN_DONE        && a == ATOM_CM_PIXMAP_ROTATION_BEGIN_DONE       ) return "PIX_ROT_BEGIN_DONE";
378    else if (ATOM_CM_PIXMAP_ROTATION_END               && a == ATOM_CM_PIXMAP_ROTATION_END              ) return "PIX_ROT_END";
379    else if (ATOM_CM_PIXMAP_ROTATION_END_DONE          && a == ATOM_CM_PIXMAP_ROTATION_END_DONE         ) return "PIX_ROT_END_DONE";
380    else if (ATOM_CM_PIXMAP_ROTATION_REQUEST           && a == ATOM_CM_PIXMAP_ROTATION_REQUEST          ) return "PIX_ROT_REQUEST";
381    else if (ATOM_CM_PIXMAP_ROTATION_REQUEST_DONE      && a == ATOM_CM_PIXMAP_ROTATION_REQUEST_DONE     ) return "PIX_ROT_REQUEST_DONE";
382    else if (ATOM_CM_PIXMAP_ROTATION_RESIZE_PIXMAP     && a == ATOM_CM_PIXMAP_ROTATION_RESIZE_PIXMAP    ) return "PIX_ROT_RESIZE_PIXMAP";
383    else if (ATOM_OVERAY_WINDOW                        && a == ATOM_OVERAY_WINDOW                       ) return "OVERAY_WINDOW";
384    else if (ATOM_X_HIBERNATION_STATE                  && a == ATOM_X_HIBERNATION_STATE                 ) return "HIBERNATION_STATE";
385    else if (ATOM_X_SCREEN_ROTATION                    && a == ATOM_X_SCREEN_ROTATION                   ) return "SCREEN_ROTATION";
386 #if COMP_LOGGER_BUILD_ENABLE
387    else if (ATOM_CM_LOG                               && a == ATOM_CM_LOG                              ) return "CM_LOG";
388    else if (ATOM_CM_LOG_DUMP_DONE                     && a == ATOM_CM_LOG_DUMP_DONE                    ) return "CM_LOG_DUMP_DONE";
389 #endif /* COMP_LOGGER_BUILD_ENABLE */
390
391    return NULL;
392 }
393
394 Eina_Bool
395 _e_mod_comp_rotation_release(E_Comp_Win *cw)
396 {
397    if (!cw || !cw->rotating || !cw->rotobj) return EINA_FALSE;
398
399    L(LT_EVENT_X,
400      "[COMP] %31s w:0x%08x bd:%s release rotobj. animating:%d\n",
401      "PIX_ROT", _e_mod_comp_win_get_client_xid(cw),
402      cw->bd ? "O" : "X", cw->animating);
403
404    if (cw->animating)
405      {
406         cw->delete_me = 1;
407         return EINA_TRUE;
408      }
409
410    cw->rotating = EINA_FALSE;
411
412    Ecore_X_Damage damage;
413    damage = e_mod_comp_rotation_get_damage(cw->rotobj);
414    if (damage) _e_mod_comp_win_del_damage(cw, damage);
415
416    e_mod_comp_rotation_end(cw->rotobj);
417    e_mod_comp_rotation_free(cw->rotobj);
418    cw->rotobj = NULL;
419
420    e_mod_comp_rotation_done_send
421       (_e_mod_comp_win_get_client_xid(cw),
422        ATOM_CM_PIXMAP_ROTATION_END_DONE);
423
424    L(LT_EVENT_X,
425      "[COMP] %31s w:0x%08x send END_DONE.\n",
426      "PIX_ROT", _e_mod_comp_win_get_client_xid(cw));
427
428    return EINA_TRUE;
429 }
430
431 static int
432 _e_mod_comp_rotation_handle_message(Ecore_X_Event_Client_Message *ev)
433 {
434    Ecore_X_Atom type = ev->message_type;
435    Ecore_X_Window win;
436    E_Comp_Win *cw = NULL;
437
438    cw = _e_mod_comp_border_client_find(ev->win);
439    if (!cw)
440      {
441         cw = _e_mod_comp_win_find(ev->win);
442         if (!cw) return 0;
443      }
444
445    win = ev->win;
446
447    if (type == ATOM_CM_PIXMAP_ROTATION_BEGIN)
448      {
449         L(LT_EVENT_X,
450           "[COMP] %31s w:0x%08x bd:%d c:0x%08x cw:%p\n",
451           "PIX_ROT", win, _e_mod_comp_win_is_border(cw),
452           _e_mod_comp_win_get_client_xid(cw), cw);
453
454         if (cw->rotating || cw->rotobj)
455           {
456              L(LT_EVENT_X,
457                "[COMP] %31s w:0x%08x invalid BEGIN_REQUEST. rotating:%d rotobj:%p\n",
458                "PIX_ROT", ev->win, cw->rotating, cw->rotobj);
459              return 0;
460           }
461
462         L(LT_EVENT_X,
463           "[COMP] %31s w:0x%08x BEGIN_REQUEST.\n",
464           "PIX_ROT", ev->win);
465
466         cw->rotobj = e_mod_comp_rotation_new();
467         if (!cw->rotobj) return 0;
468
469         cw->rotating = EINA_TRUE;
470
471         edje_object_part_unswallow(cw->shobj, cw->obj);
472         _e_mod_comp_win_unredirect(cw);
473
474         e_mod_comp_rotation_done_send
475            (win, ATOM_CM_PIXMAP_ROTATION_BEGIN_DONE);
476
477         L(LT_EVENT_X,
478           "[COMP] %31s w:0x%08x send BEGIN_DONE.\n",
479           "PIX_ROT", ev->win);
480      }
481    else if (type == ATOM_CM_PIXMAP_ROTATION_END)
482      {
483         L(LT_EVENT_X,
484           "[COMP] %31s w:0x%08x bd:%d c:0x%08x cw:%p\n",
485           "PIX_ROT", win, _e_mod_comp_win_is_border(cw),
486           _e_mod_comp_win_get_client_xid(cw), cw);
487
488         if (!cw->rotating || !cw->rotobj)
489           {
490              L(LT_EVENT_X,
491                "[COMP] %31s w:0x%08x invalid END_REQUEST. rotating:%d rotobj:%p\n",
492                "PIX_ROT", ev->win, cw->rotating, cw->rotobj);
493              return 0;
494           }
495
496         _e_mod_comp_win_dec_animating(cw);
497
498         L(LT_EVENT_X,
499           "[COMP] %31s w:0x%08x end END_REQUEST. release rotobj.\n",
500           "PIX_ROT", ev->win);
501
502         _e_mod_comp_rotation_release(cw);
503      }
504    else if (type == ATOM_CM_PIXMAP_ROTATION_REQUEST)
505      {
506         L(LT_EVENT_X,
507           "[COMP] %31s w:0x%08x bd:%d c:0x%08x cw:%p\n",
508           "PIX_ROT", win, _e_mod_comp_win_is_border(cw),
509           _e_mod_comp_win_get_client_xid(cw), cw);
510
511         if (!cw->rotating || !cw->rotobj)
512           {
513              L(LT_EVENT_X,
514                "[COMP] %31s w:0x%08x invalid ROTATION_REQUEST. rotating:%d rotobj:%p\n",
515                "PIX_ROT", ev->win, cw->rotating, cw->rotobj);
516              return 0;
517           }
518
519         L(LT_EVENT_X,
520           "[COMP] %31s w:0x%08x ROTATION_REQUEST.\n",
521           "PIX_ROT", ev->win);
522
523         Ecore_X_Damage damage;
524         damage = e_mod_comp_rotation_get_damage(cw->rotobj);
525         if (damage) _e_mod_comp_win_del_damage(cw, damage);
526
527         if (cw->obj)
528           edje_object_part_unswallow(cw->shobj, cw->obj);
529         else
530           {
531              if (!cw->c)
532                {
533                   L(LT_EVENT_X,
534                     "[COMP] %31s w:0x%08x can't create cw->obj. cw->c:NULL\n",
535                     "PIX_ROT", ev->win);
536                   return 0;
537                }
538
539              cw->obj = evas_object_image_filled_add(cw->c->evas);
540              evas_object_image_colorspace_set(cw->obj, EVAS_COLORSPACE_ARGB8888);
541
542              if (cw->argb)
543                evas_object_image_alpha_set(cw->obj, 1);
544              else
545                evas_object_image_alpha_set(cw->obj, 0);
546
547              evas_object_show(cw->obj);
548              evas_object_pass_events_set(cw->obj, 1);
549
550              L(LT_EVENT_X,
551                "[COMP] %31s w:0x%08x create cw->obj:%p (alpha:%d).\n",
552                "PIX_ROT", ev->win, cw->obj, cw->argb);
553           }
554
555         if (!e_mod_comp_rotation_request(cw->rotobj,
556                                          ev,
557                                          cw->c->evas,
558                                          cw->shobj,
559                                          cw->obj,
560                                          cw->vis,
561                                          cw->x, cw->y, cw->w, cw->h))
562           {
563              L(LT_EVENT_X,
564                "[COMP] %31s w:0x%08x e_mod_comp_rotation_request() failed.\n",
565                "PIX_ROT", ev->win);
566              return 0;
567           }
568
569         e_mod_comp_update_resize(cw->up, cw->w, cw->h);
570         e_mod_comp_update_add(cw->up, 0, 0, cw->w, cw->h);
571
572         cw->native = 1;
573
574         damage = e_mod_comp_rotation_get_damage(cw->rotobj);
575         if (!damage) return 0;
576         _e_mod_comp_win_add_damage(cw, damage);
577         e_mod_comp_rotation_done_send(win, ATOM_CM_PIXMAP_ROTATION_REQUEST_DONE);
578
579         L(LT_EVENT_X,
580           "[COMP] %31s w:0x%08x send ROTATION_DONE.\n",
581           "PIX_ROT", ev->win);
582      }
583    else
584      return 0;
585
586    return 1;
587 }
588
589 static Eina_Bool
590 _e_mod_comp_win_add_damage(E_Comp_Win *cw,
591                            Ecore_X_Damage damage)
592 {
593    return eina_hash_add(damages, e_util_winid_str_get(damage), cw);
594 }
595
596 static Eina_Bool
597 _e_mod_comp_win_del_damage(E_Comp_Win *cw,
598                            Ecore_X_Damage damage)
599 {
600    return eina_hash_del(damages, e_util_winid_str_get(damage), cw);
601 }
602
603 static Eina_Bool
604 _e_mod_comp_win_get_prop_angle(Ecore_X_Window win,
605                                int *req,
606                                int *curr)
607 {
608    Eina_Bool res = EINA_FALSE;
609    int ret, count;
610    int angle[2] = {-1, -1};
611    unsigned char* prop_data = NULL;
612
613    ret = ecore_x_window_prop_property_get(win,
614                                           ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE,
615                                           ECORE_X_ATOM_CARDINAL,
616                                           32,
617                                           &prop_data,
618                                           &count);
619    if (ret <= 0)
620      {
621         if (prop_data) free(prop_data);
622         return res;
623      }
624    if (ret && prop_data)
625      {
626         memcpy (&angle, prop_data, sizeof (int)*count);
627         if (count == 2) res = EINA_TRUE;
628      }
629
630    if (prop_data) free(prop_data);
631
632    *req  = angle[_WND_REQUEST_ANGLE_IDX];
633    *curr = angle[_WND_CURR_ANGLE_IDX];
634
635    if (angle[0] == -1 && angle[1] == -1) res = EINA_FALSE;
636
637    L(LT_EVENT_X, "[COMP] %31s %d=>%d count:%d res:%s\n", \
638      "rot_prop_get", \
639      angle[_WND_CURR_ANGLE_IDX], \
640      angle[_WND_REQUEST_ANGLE_IDX], \
641      count,
642      res ? "Ture" : "False");
643
644    return res;
645 }
646
647 Eina_Bool
648 _e_mod_comp_win_check_visible(E_Comp_Win *cw)
649 {
650    Eina_Bool visible = EINA_FALSE;
651    E_Comp_Win *check_cw = NULL;
652
653    EINA_INLIST_REVERSE_FOREACH(cw->c->wins, check_cw)
654      {
655         if (check_cw->x == 0 &&
656             check_cw->y == 0 &&
657             check_cw->w == cw->c->man->w &&
658             check_cw->h == cw->c->man->h)
659           {
660              if (check_cw == cw)
661                {
662                   visible = EINA_TRUE;
663                   break;
664                }
665              if (!check_cw->visible   ) continue;
666              if ( check_cw->defer_hide) continue;
667              if ( check_cw->invalid   ) continue;
668              if ( check_cw->input_only) continue;
669              if ( check_cw->argb      ) continue;
670              break;
671           }
672      }
673    return visible;
674 }
675
676 Eina_Bool
677 _e_mod_comp_win_check_visible2(E_Comp_Win *cw)
678 {
679    E_Comp_Win *find_cw = NULL;
680    E_Comp *c = NULL;
681
682    Ecore_X_Region VisibleRegion = 0;
683    Ecore_X_Region CurrentRegion = 0;
684    Ecore_X_Region ResultRegion = 0;
685
686    Ecore_X_Rectangle *rects = NULL;
687    Ecore_X_Rectangle bounds = { 0, 0, 0, 0 };
688
689    int num_rects = 0;
690
691    Ecore_X_Rectangle screen_rect = { 0, 0, cw->c->man->w, cw->c->man->h };
692    Ecore_X_Rectangle window_rect;
693
694    Eina_Bool visible = EINA_FALSE;
695
696    c = cw->c;
697
698    if (((!cw->visible)
699         || (cw->defer_hide)
700         || (cw->invalid)
701         || (cw->input_only)
702         || (!E_INTERSECTS(0, 0, c->man->w, c->man->h,
703                           cw->x, cw->y, cw->w, cw->h))))
704      {
705         return visible;
706      }
707
708    VisibleRegion = ecore_x_region_new(&screen_rect, 1);
709
710    EINA_INLIST_REVERSE_FOREACH(cw->c->wins, find_cw)
711      {
712         if (cw == find_cw)
713           {
714              rects = NULL;
715              num_rects = 0;
716
717              window_rect.x = find_cw->x;
718              window_rect.y = find_cw->y;
719              window_rect.width = find_cw->w;
720              window_rect.height = find_cw->h;
721              CurrentRegion = ecore_x_region_new(&window_rect, 1);
722
723              ResultRegion = ecore_x_region_new(&screen_rect, 1);
724              // result = visible intersect current
725              ecore_x_region_intersect(ResultRegion, VisibleRegion, CurrentRegion);
726              rects = ecore_x_region_fetch(ResultRegion, &num_rects, &bounds);
727
728              if (num_rects > 0)
729                {
730                   visible = EINA_TRUE;
731                   break;
732                }
733              else
734                {
735                   visible = EINA_FALSE;
736                   break;
737                }
738           }
739         else if (((!find_cw->visible)
740                   || (find_cw->defer_hide)
741                   || (find_cw->invalid)
742                   || (find_cw->input_only)
743                   || (find_cw->argb) // this code may cause bug.
744                   || (!E_INTERSECTS(0, 0, c->man->w, c->man->h,
745                                     cw->x, cw->y, cw->w, cw->h))))
746           {
747              continue;
748           }
749         else
750           {
751              rects = NULL;
752              num_rects = 0;
753
754              window_rect.x = find_cw->x;
755              window_rect.y = find_cw->y;
756              window_rect.width = find_cw->w;
757              window_rect.height = find_cw->h;
758
759              CurrentRegion = ecore_x_region_new(&window_rect, 1);
760              ResultRegion = ecore_x_region_new(&screen_rect, 1);
761
762              // result = visible - current
763              ecore_x_region_subtract (ResultRegion, VisibleRegion, CurrentRegion);
764              rects = ecore_x_region_fetch (ResultRegion, &num_rects, &bounds);
765
766              if (num_rects == 0)
767                {
768                   visible = EINA_FALSE;
769                   break;
770                }
771              else
772                {
773                   ecore_x_region_copy(VisibleRegion, ResultRegion);
774                   if (rects) free(rects);
775                   ecore_x_region_free(ResultRegion);
776                   ecore_x_region_free(CurrentRegion);
777                }
778           }
779      }
780
781      if (rects) free(rects);
782      ecore_x_region_free(ResultRegion);
783      ecore_x_region_free(CurrentRegion);
784      ecore_x_region_free(VisibleRegion);
785
786      return visible;
787 }
788
789 Eina_Bool
790 _e_mod_comp_win_check_visible3(E_Comp_Win *cw)
791 {
792    Eina_Bool visible = EINA_FALSE;
793    E_Comp_Win *check_cw = NULL;
794
795    EINA_INLIST_REVERSE_FOREACH(cw->c->wins, check_cw)
796      {
797         if (check_cw->x == 0 &&
798             check_cw->y == 0 &&
799             check_cw->w == cw->c->man->w &&
800             check_cw->h == cw->c->man->h &&
801             !check_cw->input_only &&
802             !check_cw->invalid )
803           {
804              if (check_cw == cw)
805                {
806                   visible = EINA_TRUE;
807                   break;
808                }
809           }
810      }
811    return visible;
812 }
813
814 static Eina_Bool
815 _e_mod_comp_prop_window_rotation(Ecore_X_Event_Window_Property *ev)
816 {
817    E_Comp_Win *cw = NULL;
818    int req_angle = -1;
819    int cur_angle = -1;
820
821    L(LT_EVENT_X,
822      "[COMP] %31s\n", "PROP_ILLUME_ROT_WND_ANG");
823
824    cw = _e_mod_comp_border_client_find(ev->win);
825    if (!cw)
826      {
827         cw = _e_mod_comp_win_find(ev->win);
828         if (!cw)
829           {
830              Ecore_X_Sync_Counter counter = ecore_x_e_comp_sync_counter_get(ev->win);
831              ecore_x_e_comp_sync_cancel_send(ev->win);
832              if (counter) ecore_x_sync_counter_inc(counter, 1);
833              return EINA_FALSE;
834           }
835      }
836
837    // if window's rotation effect type is NONE,
838    // then do not show rotation effect.
839    // just return from here
840    if (cw->rotation_effect == COMP_EFFECT_NONE)
841      {
842         if (cw->counter)
843           ecore_x_sync_counter_inc(cw->counter, 1);
844         else
845           {
846              cw->counter = ecore_x_e_comp_sync_counter_get(_e_mod_comp_win_get_client_xid(cw));
847              if (cw->counter) ecore_x_sync_counter_inc(cw->counter, 1);
848           }
849         return EINA_FALSE;
850      }
851
852    if (!_e_mod_comp_win_get_prop_angle(_e_mod_comp_win_get_client_xid(cw),
853                                        &req_angle,
854                                        &cur_angle))
855      {
856         if (cw->counter)
857           ecore_x_sync_counter_inc(cw->counter, 1);
858         else
859           {
860              cw->counter = ecore_x_e_comp_sync_counter_get(_e_mod_comp_win_get_client_xid(cw));
861              if (cw->counter) ecore_x_sync_counter_inc(cw->counter, 1);
862           }
863         return EINA_FALSE;
864      }
865
866    if (req_angle == cur_angle)
867      {
868         // candidate window of keypad requests rotation with same angles.
869         if (cw->counter)
870           ecore_x_sync_counter_inc(cw->counter, 1);
871         else
872           {
873              cw->counter = ecore_x_e_comp_sync_counter_get(_e_mod_comp_win_get_client_xid(cw));
874              if (cw->counter) ecore_x_sync_counter_inc(cw->counter, 1);
875           }
876         return EINA_FALSE;
877      }
878
879    if (_e_mod_comp_window_rotation_policy(cw))
880      {
881        cw->req_ang = req_angle;
882        cw->cur_ang = cur_angle;
883        cw->ready_win_rot_effect = EINA_TRUE;
884        if (cw->win_rot_timeout)
885          {
886             ecore_timer_del(cw->win_rot_timeout);
887             cw->win_rot_timeout = NULL;
888          }
889        cw->win_rot_timeout = ecore_timer_add(4.0f,
890                                              _e_mod_comp_win_rotation_begin_timeout,
891                                              cw);
892        if (cw->counter)
893          ecore_x_sync_counter_inc(cw->counter, 1);
894        else
895          {
896             cw->counter = ecore_x_e_comp_sync_counter_get(_e_mod_comp_win_get_client_xid(cw));
897             if (cw->counter) ecore_x_sync_counter_inc(cw->counter, 1);
898          }
899
900        L(LT_EVENT_X,
901          "[COMP] %31s:%p\n",
902          "win_rot_timeout",
903          cw->win_rot_timeout);
904       }
905     else
906       {
907          cw->req_ang = req_angle;
908          cw->cur_ang = req_angle;
909          cw->ready_win_rot_effect = EINA_FALSE;
910          if (cw->counter)
911            ecore_x_sync_counter_inc(cw->counter, 1);
912          else
913            {
914               cw->counter = ecore_x_e_comp_sync_counter_get(_e_mod_comp_win_get_client_xid(cw));
915               if (cw->counter) ecore_x_sync_counter_inc(cw->counter, 1);
916            }
917       }
918
919    L(LT_EVENT_X,
920      "[COMP] %31s %d\n",
921      "ready_effect",
922      cw->ready_win_rot_effect);
923
924    return EINA_TRUE;
925 }
926
927 static Eina_Bool
928 _e_mod_comp_win_rotation_begin(E_Comp_Win *cw, Eina_Bool timeout)
929 {
930    cw->ready_win_rot_effect = EINA_FALSE;
931
932    L(LT_EVENT_X,
933      "[COMP] %31s timeout:%d\n",
934      "win_rot_begin", timeout);
935
936    if (cw->win_rot_timeout)
937      {
938         ecore_timer_del(cw->win_rot_timeout);
939         cw->win_rot_timeout = NULL;
940      }
941
942    if (cw->rotation_effect == COMP_EFFECT_NONE) return EINA_TRUE;
943    else
944      {
945         switch (cw->req_ang - cw->cur_ang)
946           {
947              case -270: edje_object_signal_emit(cw->shobj, "e,state,window,rotation,90",   "e"); break;
948              case -180: edje_object_signal_emit(cw->shobj, "e,state,window,rotation,180",  "e"); break;
949              case  -90: edje_object_signal_emit(cw->shobj, "e,state,window,rotation,-90",  "e"); break;
950              case    0: edje_object_signal_emit(cw->shobj, "e,state,window,rotation,0",    "e"); break;
951              case   90: edje_object_signal_emit(cw->shobj, "e,state,window,rotation,90",   "e"); break;
952              case  180: edje_object_signal_emit(cw->shobj, "e,state,window,rotation,-180", "e"); break;
953              case  270: edje_object_signal_emit(cw->shobj, "e,state,window,rotation,-90",  "e"); break;
954              default  : edje_object_signal_emit(cw->shobj, "e,state,window,rotation,0",    "e"); break;
955           }
956      }
957    cw->win_rot_effect = 1;
958    _e_mod_comp_win_inc_animating(cw);
959
960    if (timeout)
961      {
962         if (!cw->update)
963           {
964              if (cw->update_timeout)
965                {
966                   ecore_timer_del(cw->update_timeout);
967                   cw->update_timeout = NULL;
968                }
969              cw->update = 1;
970              cw->c->updates = eina_list_append(cw->c->updates, cw);
971           }
972         cw->drawme = 1;
973         _e_mod_comp_win_render_queue(cw);
974         if (cw->counter)
975           ecore_x_sync_counter_inc(cw->counter, 1);
976         else
977           {
978              cw->counter = ecore_x_e_comp_sync_counter_get(_e_mod_comp_win_get_client_xid(cw));
979              if (cw->counter) ecore_x_sync_counter_inc(cw->counter, 1);
980           }
981      }
982
983    // TODO: remove argb check code for the ticker window
984    if (!cw->argb)
985      {
986         evas_object_stack_below(cw->c->bg_img, cw->shobj);
987         cw->c->use_bg_img = 1;
988      }
989
990    cw->win_rot_timeout = ecore_timer_add(4.0f,
991                                          _e_mod_comp_win_rotation_end_timeout,
992                                          cw);
993
994    return EINA_TRUE;
995 }
996
997 static void
998 _e_mod_comp_win_rotation_done(void *data,
999                               Evas_Object *obj __UNUSED__,
1000                               const char *emission __UNUSED__,
1001                               const char *source __UNUSED__)
1002 {
1003    E_Comp_Win *cw = (E_Comp_Win*)data;
1004    if (!cw) return;
1005
1006    if (cw->win_rot_timeout)
1007      {
1008         ecore_timer_del(cw->win_rot_timeout);
1009         cw->win_rot_timeout = NULL;
1010      }
1011
1012    if ( !cw->show_done ) cw->show_done = EINA_TRUE;
1013    evas_object_stack_below(cw->c->bg_img, evas_object_bottom_get(cw->c->evas));
1014    cw->c->use_bg_img = 0;
1015    cw->win_rot_effect = 0;
1016
1017    L(LT_EVENT_X,
1018      "[COMP] %31s %s w:0x%08x\n",
1019      "EFFECT", "WIN_ROT_DONE",
1020      _e_mod_comp_win_get_client_xid(cw));
1021
1022    _e_mod_comp_done_defer(cw);
1023 }
1024
1025 static Eina_Bool
1026 _e_mod_comp_win_rotation_release(E_Comp_Win *cw)
1027 {
1028    cw->ready_win_rot_effect = EINA_FALSE;
1029    cw->req_ang = 0;
1030    cw->cur_ang = 0;
1031
1032    if (cw->win_rot_timeout)
1033      {
1034         ecore_timer_del(cw->win_rot_timeout);
1035         cw->win_rot_timeout = NULL;
1036      }
1037    return EINA_TRUE;
1038 }
1039
1040 void
1041 _e_mod_comp_send_window_effect_client_state(E_Comp_Win *cw,
1042                                             Eina_Bool state)
1043 {
1044    Ecore_X_Window win = 0;
1045    long d[5] = { 0L, 0L, 0L, 0L, 0L };
1046    if (!cw) return;
1047
1048    win = _e_mod_comp_win_get_client_xid(cw);
1049    if (!win) return;
1050
1051    if (state) d[0] = 1L;
1052    else d[1] = 1L;
1053
1054    ecore_x_client_message32_send
1055       (win, ATOM_WINDOW_EFFECT_CLIENT_STATE,
1056           StructureNotifyMask, d[0], d[1], d[2], d[3], d[4]);
1057 }
1058
1059 static Eina_Bool
1060 _e_mod_comp_is_next_win_stack(E_Comp_Win *cw,
1061                               E_Comp_Win *cw2)
1062 {
1063    Eina_Inlist *wins_list;
1064    if (!cw || !cw2) return EINA_FALSE;
1065
1066    while ((wins_list = EINA_INLIST_GET(cw)->prev) != NULL)
1067      {
1068         cw = _EINA_INLIST_CONTAINER(cw, wins_list);
1069         if (cw == cw2)
1070           {
1071              return EINA_TRUE;
1072           }
1073      }
1074    return EINA_FALSE;
1075 }
1076
1077 E_Comp_Win *
1078 _e_mod_comp_win_find_by_indicator(E_Comp *c)
1079 {
1080    E_Comp_Win *cw;
1081    EINA_INLIST_FOREACH(c->wins, cw)
1082      {
1083         if (_e_mod_comp_is_indicator_window(cw->bd)) return cw;
1084      }
1085    return NULL;
1086 }
1087
1088 #ifdef  _MAKE_ATOM
1089 # undef _MAKE_ATOM
1090 #endif
1091
1092 #define _MAKE_ATOM(a, s)                              \
1093    do {                                               \
1094         a = ecore_x_atom_get(s);                      \
1095         if (!a)                                       \
1096           fprintf(stderr,                             \
1097                   "[E-comp] ##s creation failed.\n"); \
1098    } while(0)
1099
1100 static void
1101 _e_mod_comp_atom_init(void)
1102 {
1103    _MAKE_ATOM(ATOM_FAKE_LAUNCH_IMAGE,                STR_ATOM_FAKE_LAUNCH_IMAGE                );
1104    _MAKE_ATOM(ATOM_FAKE_LAUNCH,                      STR_ATOM_FAKE_LAUNCH                      );
1105    _MAKE_ATOM(ATOM_EFFECT_ENABLE,                    STR_ATOM_NET_CM_EFFECT_ENABLE             );
1106    _MAKE_ATOM(ATOM_WINDOW_EFFECT_ENABLE,             STR_ATOM_NET_CM_WINDOW_EFFECT_ENABLE      );
1107    _MAKE_ATOM(ATOM_WINDOW_EFFECT_CLIENT_STATE,       STR_ATOM_NET_CM_WINDOW_EFFECT_CLIENT_STATE);
1108    _MAKE_ATOM(ATOM_WINDOW_EFFECT_STATE,              STR_ATOM_NET_CM_WINDOW_EFFECT_STATE       );
1109    _MAKE_ATOM(ATOM_WINDOW_EFFECT_TYPE,               STR_ATOM_NET_CM_WINDOW_EFFECT_TYPE        );
1110    _MAKE_ATOM(ATOM_EFFECT_DEFAULT,                   STR_ATOM_NET_CM_EFFECT_DEFAULT            );
1111    _MAKE_ATOM(ATOM_EFFECT_NONE,                      STR_ATOM_NET_CM_EFFECT_NONE               );
1112    _MAKE_ATOM(ATOM_EFFECT_CUSTOM0,                   STR_ATOM_NET_CM_EFFECT_CUSTOM0            );
1113    _MAKE_ATOM(ATOM_EFFECT_CUSTOM1,                   STR_ATOM_NET_CM_EFFECT_CUSTOM1            );
1114    _MAKE_ATOM(ATOM_EFFECT_CUSTOM2,                   STR_ATOM_NET_CM_EFFECT_CUSTOM2            );
1115    _MAKE_ATOM(ATOM_EFFECT_CUSTOM3,                   STR_ATOM_NET_CM_EFFECT_CUSTOM3            );
1116    _MAKE_ATOM(ATOM_EFFECT_CUSTOM4,                   STR_ATOM_NET_CM_EFFECT_CUSTOM4            );
1117    _MAKE_ATOM(ATOM_EFFECT_CUSTOM5,                   STR_ATOM_NET_CM_EFFECT_CUSTOM5            );
1118    _MAKE_ATOM(ATOM_EFFECT_CUSTOM6,                   STR_ATOM_NET_CM_EFFECT_CUSTOM6            );
1119    _MAKE_ATOM(ATOM_EFFECT_CUSTOM7,                   STR_ATOM_NET_CM_EFFECT_CUSTOM7            );
1120    _MAKE_ATOM(ATOM_EFFECT_CUSTOM8,                   STR_ATOM_NET_CM_EFFECT_CUSTOM8            );
1121    _MAKE_ATOM(ATOM_EFFECT_CUSTOM9,                   STR_ATOM_NET_CM_EFFECT_CUSTOM9            );
1122    _MAKE_ATOM(ATOM_OVERAY_WINDOW,                    STR_ATOM_OVERAY_WINDOW                    );
1123    _MAKE_ATOM(ATOM_X_HIBERNATION_STATE,              STR_ATOM_X_HIBERNATION_STATE              );
1124    _MAKE_ATOM(ATOM_CM_LOCK_SCREEN,                   STR_ATOM_CM_LOCK_SCREEN                   );
1125    _MAKE_ATOM(ATOM_CM_PIXMAP_ROTATION_SUPPORTED,     STR_ATOM_CM_PIXMAP_ROTATION_SUPPORTED     );
1126    _MAKE_ATOM(ATOM_CM_PIXMAP_ROTATION_STATE,         STR_ATOM_CM_PIXMAP_ROTATION_STATE         );
1127    _MAKE_ATOM(ATOM_CM_PIXMAP_ROTATION_BEGIN,         STR_ATOM_CM_PIXMAP_ROTATION_BEGIN         );
1128    _MAKE_ATOM(ATOM_CM_PIXMAP_ROTATION_BEGIN_DONE,    STR_ATOM_CM_PIXMAP_ROTATION_BEGIN_DONE    );
1129    _MAKE_ATOM(ATOM_CM_PIXMAP_ROTATION_END,           STR_ATOM_CM_PIXMAP_ROTATION_END           );
1130    _MAKE_ATOM(ATOM_CM_PIXMAP_ROTATION_END_DONE,      STR_ATOM_CM_PIXMAP_ROTATION_END_DONE      );
1131    _MAKE_ATOM(ATOM_CM_PIXMAP_ROTATION_REQUEST,       STR_ATOM_CM_PIXMAP_ROTATION_REQUEST       );
1132    _MAKE_ATOM(ATOM_CM_PIXMAP_ROTATION_REQUEST_DONE,  STR_ATOM_CM_PIXMAP_ROTATION_REQUEST_DONE  );
1133    _MAKE_ATOM(ATOM_CM_PIXMAP_ROTATION_RESIZE_PIXMAP, STR_ATOM_CM_PIXMAP_ROTATION_RESIZE_PIXMAP );
1134    _MAKE_ATOM(ATOM_X_SCREEN_ROTATION,                STR_ATOM_X_SCREEN_ROTATION                );
1135    _MAKE_ATOM(ATOM_CAPTURE_EFFECT,                   STR_ATOM_CAPTURE_EFFECT                   );
1136 #if COMP_LOGGER_BUILD_ENABLE
1137    _MAKE_ATOM(ATOM_CM_LOG,                           STR_ATOM_CM_LOG                           );
1138    _MAKE_ATOM(ATOM_CM_LOG_DUMP_DONE,                 STR_ATOM_CM_LOG_DUMP_DONE                 );
1139 #endif
1140 }
1141
1142 void
1143 _e_mod_comp_cb_pending_after(void *data __UNUSED__,
1144                              E_Manager *man __UNUSED__,
1145                              E_Manager_Comp_Source *src)
1146 {
1147    E_Comp_Win *cw = (E_Comp_Win *)src;
1148    cw->pending_count--;
1149    if (!cw->delete_pending) return;
1150    if (cw->pending_count == 0)
1151      {
1152         free(cw);
1153      }
1154 }
1155
1156 static void
1157 _e_mod_comp_set(E_Comp *c)
1158 {
1159    if (_comp)
1160      {
1161         fprintf(stderr,
1162                 "[E17-comp] %s(%d) E_Comp setup failed.\n",
1163                 __func__, __LINE__);
1164         return;
1165      }
1166    _comp = c;
1167 }
1168
1169 E_Comp *
1170 _e_mod_comp_get(void)
1171 {
1172    return _comp;
1173 }
1174
1175 static void
1176 _e_mod_comp_dump_cw_stack(Eina_Bool to_file,
1177                           const char *name)
1178 {
1179    E_Comp *c;
1180    E_Comp_Win *cw;
1181    double val;
1182    const char *file, *group;
1183    int x, y, w, h, i = 1;
1184    FILE *fs = stderr;
1185
1186    c = _e_mod_comp_get();
1187    if (!c) return;
1188
1189    if ((to_file) && (name))
1190      {
1191         fs = fopen(name, "w");
1192         if (!fs)
1193           {
1194              fprintf(stderr, "can't open %s file.\n", name);
1195              fs = stderr;
1196              to_file = EINA_FALSE;
1197           }
1198      }
1199
1200    fprintf(fs, "B-------------------------------------------------------------------------------------------------------------------------------------\n");
1201    fprintf(fs, " No   WinID        shobj    x    y    w    h   ex   ey   ew   eh W S O    clipper         shower        swallow         group      st \n");
1202    fprintf(fs, "--------------------------------------------------------------------------------------------------------------------------------------\n");
1203    fprintf(fs, " c->bg_img : %s 0x%08x\n", evas_object_visible_get(c->bg_img) ? "O" : "X", (unsigned int)c->bg_img);
1204    fprintf(fs, "--------------------------------------------------------------------------------------------------------------------------------------\n");
1205
1206    EINA_INLIST_REVERSE_FOREACH(c->wins, cw)
1207      {
1208         edje_object_file_get(cw->shobj, &file, &group);
1209         evas_object_geometry_get(cw->shobj, &x, &y, &w, &h);
1210         fprintf(fs,
1211                 " %2d 0x%07x 0x%08x %4d %4d %4d %4d %4d %4d %4d %4d %s %s %s %10.10s %.1f %10.10s %.1f %10.10s %.1f %15.15s %d\n",
1212                 i,
1213                 _e_mod_comp_win_get_client_xid(cw),
1214                 (unsigned int)cw->shobj,
1215                 cw->x, cw->y, cw->w, cw->h,
1216                 x, y, w, h,
1217                 cw->visible ? "O" : "X",
1218                 evas_object_visible_get(cw->shobj) ? "O" : "X",
1219                 evas_object_visible_get(cw->obj) ? "O" : "X",
1220                 edje_object_part_state_get(cw->shobj, "clipper", &val), val,
1221                 edje_object_part_state_get(cw->shobj, "shower", &val), val,
1222                 edje_object_part_state_get(cw->shobj, "e.swallow.content", &val), val,
1223                 group, cw->effect_stage);
1224         i++;
1225      }
1226
1227    i = 1;
1228    fprintf(fs, "--------------------------------------------------------------------------------------------------------------------------------------\n");
1229    EINA_INLIST_REVERSE_FOREACH(c->wins, cw)
1230      {
1231         if (!cw) break;
1232         file = group = NULL;
1233         edje_object_file_get(cw->shobj,
1234                              &file, &group);
1235         fprintf(fs,
1236                 " %2d 0x%07x %s\n",
1237                 i, _e_mod_comp_win_get_client_xid(cw),
1238                 file);
1239         i++;
1240      }
1241
1242    i = 1;
1243    fprintf(fs, "--------------------------------------------------------------------------------------------------------------------------------------\n");
1244    fprintf(fs, " No     WinID      shobj        obj    found_o    x    y    w    h   ex   ey   ew   eh | W S O\n");
1245    fprintf(fs, "--------------------------------------------------------------------------------------------------------------------------------------\n");
1246    Evas_Object *o = evas_object_top_get(c->evas);
1247    Eina_Bool found = 0;
1248    Ecore_X_Window cid = 0;
1249    char *wname = NULL, *wclas = NULL;
1250    int pid = 0;
1251    while (o)
1252      {
1253         EINA_INLIST_REVERSE_FOREACH(c->wins, cw)
1254           {
1255              if (!cw) break;
1256              if (cw->shobj == o)
1257                {
1258                   found = 1;
1259                   cid = _e_mod_comp_win_get_client_xid(cw);
1260                   ecore_x_icccm_name_class_get(cid, &wname, &wclas);
1261                   ecore_x_netwm_pid_get(cid, &pid);
1262                   break;
1263                }
1264           }
1265
1266         evas_object_geometry_get(o, &x, &y, &w, &h);
1267
1268         if (found && cw->visible)
1269           {
1270              fprintf(fs,
1271                      " %2d 0x%07x 0x%08x 0x%08x 0x%08x %4d,%4d %4dx%4d %4d,%4d %4dx%4d | %s %s %s %4d, %s, %s\n",
1272                      i,
1273                      _e_mod_comp_win_get_client_xid(cw),
1274                      (unsigned int)cw->shobj,
1275                      (unsigned int)cw->obj,
1276                      (unsigned int)o,
1277                      cw->x, cw->y, cw->w, cw->h,
1278                      x, y, w, h,
1279                      cw->visible ? "O" : "X",
1280                      evas_object_visible_get(cw->shobj) ? "O" : "X",
1281                      evas_object_visible_get(o) ? "O" : "X",
1282                      pid, wname, wclas);
1283           }
1284         else if (o == c->bg_img)
1285           {
1286              fprintf(fs,
1287                      " %2d %31.31s 0x%08x %19.19s %4d,%4d %4dx%4d |     %s <-- bg_img\n",
1288                      i, " ", (unsigned int)o, " ", x, y, w, h, evas_object_visible_get(o) ? "O" : "X");
1289           }
1290         else if (evas_object_visible_get(o))
1291           {
1292              if (found)
1293                {
1294                   fprintf(fs,
1295                           " %2d 0x%07x 0x%08x 0x%08x 0x%08x %4d,%4d %4dx%4d %4d,%4d %4dx%4d | %s %s %s %4d, %s, %s\n",
1296                           i,
1297                           _e_mod_comp_win_get_client_xid(cw),
1298                           (unsigned int)cw->shobj,
1299                           (unsigned int)cw->obj,
1300                           (unsigned int)o,
1301                           cw->x, cw->y, cw->w, cw->h,
1302                           x, y, w, h,
1303                           cw->visible ? "O" : "X",
1304                           evas_object_visible_get(cw->shobj) ? "O" : "X",
1305                           evas_object_visible_get(o) ? "O" : "X",
1306                           pid, wname, wclas);
1307                }
1308              else
1309                {
1310                   fprintf(fs,
1311                           " %2d %31.31s 0x%08x %19.19s %4d,%4d %4dx%4d |     %s\n",
1312                           i, " ", (unsigned int)o, " ", x, y, w, h,
1313                           evas_object_visible_get(o) ? "O" : "X");
1314                }
1315           }
1316
1317         o = evas_object_below_get(o);
1318
1319         if (wname) free(wname);
1320         if (wclas) free(wclas);
1321         wname = wclas = NULL;
1322         pid = cid = 0;
1323         found = 0;
1324         i++;
1325      }
1326    fprintf(fs, "E-------------------------------------------------------------------------------------------------------------------------------------\n");
1327    fflush(fs);
1328
1329    if (to_file) fclose(fs);
1330 }
1331
1332 static E_Comp_Win *
1333 _e_mod_comp_fullscreen_check(E_Comp *c)
1334 {
1335    E_Comp_Win *cw;
1336    if (!c->wins) return NULL;
1337    EINA_INLIST_REVERSE_FOREACH(c->wins, cw)
1338      {
1339         if ((!cw->visible) || (cw->input_only) || (cw->invalid))
1340           continue;
1341         if ((cw->x == 0) && (cw->y == 0)
1342             && ((cw->x + cw->w) >= c->man->w)
1343             && ((cw->y + cw->h) >= c->man->h)
1344             && (!cw->argb) && (!cw->shaped))
1345           {
1346              return cw;
1347           }
1348         return NULL;
1349      }
1350    return NULL;
1351 }
1352
1353 static inline Eina_Bool
1354 _e_mod_comp_shaped_check(int w,
1355                          int h,
1356                          const Ecore_X_Rectangle *rects,
1357                          int num)
1358 {
1359    if ((!rects) || (num < 1)) return EINA_FALSE;
1360    if (num > 1) return EINA_TRUE;
1361    if ((rects[0].x == 0) && (rects[0].y == 0) &&
1362        ((int)(rects[0].width) == w) && ((int)(rects[0].height) == h))
1363      return EINA_FALSE;
1364    return EINA_TRUE;
1365 }
1366
1367 static inline Eina_Bool
1368 _e_mod_comp_win_shaped_check(const E_Comp_Win *cw,
1369                              const Ecore_X_Rectangle *rects,
1370                              int num)
1371 {
1372    return _e_mod_comp_shaped_check(cw->w, cw->h, rects, num);
1373 }
1374
1375 static void
1376 _e_mod_comp_win_shape_rectangles_apply(E_Comp_Win *cw,
1377                                        const Ecore_X_Rectangle *rects,
1378                                        int num)
1379 {
1380    Eina_List *l;
1381    Evas_Object *o;
1382    int i;
1383
1384    if (!_e_mod_comp_win_shaped_check(cw, rects, num))
1385      {
1386         rects = NULL;
1387      }
1388    if (rects)
1389      {
1390         unsigned int *pix, *p;
1391         unsigned char *spix, *sp;
1392         int w, h, px, py;
1393
1394         evas_object_image_size_get(cw->obj, &w, &h);
1395         if ((w > 0) && (h > 0))
1396           {
1397              if (cw->native)
1398                {
1399                   fprintf(stderr,
1400                           "BUGGER: shape with native surface. cw=%p\n",
1401                           cw);
1402                   return;
1403                }
1404
1405              evas_object_image_native_surface_set(cw->obj, NULL);
1406              evas_object_image_alpha_set(cw->obj, 1);
1407              EINA_LIST_FOREACH(cw->obj_mirror, l, o)
1408                {
1409                   evas_object_image_native_surface_set(o, NULL);
1410                   evas_object_image_alpha_set(o, 1);
1411                }
1412              pix = evas_object_image_data_get(cw->obj, 1);
1413              if (pix)
1414                {
1415                   spix = calloc(w * h, sizeof(unsigned char));
1416                   if (spix)
1417                     {
1418                        for (i = 0; i < num; i++)
1419                          {
1420                             int rx, ry, rw, rh;
1421
1422                             rx = rects[i].x; ry = rects[i].y;
1423                             rw = rects[i].width; rh = rects[i].height;
1424                             E_RECTS_CLIP_TO_RECT(rx, ry, rw, rh, 0, 0, w, h);
1425                             sp = spix + (w * ry) + rx;
1426                             for (py = 0; py < rh; py++)
1427                               {
1428                                  for (px = 0; px < rw; px++)
1429                                    {
1430                                       *sp = 0xff; sp++;
1431                                    }
1432                                  sp += w - rw;
1433                               }
1434                          }
1435                        sp = spix;
1436                        p = pix;
1437                        for (py = 0; py < h; py++)
1438                          {
1439                             for (px = 0; px < w; px++)
1440                               {
1441                                  unsigned int mask, imask;
1442                                  mask = ((unsigned int)(*sp)) << 24;
1443                                  imask = mask >> 8;
1444                                  imask |= imask >> 8;
1445                                  imask |= imask >> 8;
1446                                  *p = mask | (*p & imask);
1447                                  sp++;
1448                                  p++;
1449                               }
1450                          }
1451                        free(spix);
1452                     }
1453                   evas_object_image_data_set(cw->obj, pix);
1454                   evas_object_image_data_update_add(cw->obj, 0, 0, w, h);
1455                   EINA_LIST_FOREACH(cw->obj_mirror, l, o)
1456                     {
1457                        evas_object_image_data_set(o, pix);
1458                        evas_object_image_data_update_add(o, 0, 0, w, h);
1459                     }
1460                }
1461           }
1462      }
1463    else
1464      {
1465         if (cw->shaped)
1466           {
1467              unsigned int *pix, *p;
1468              int w, h, px, py;
1469
1470              evas_object_image_size_get(cw->obj, &w, &h);
1471              if ((w > 0) && (h > 0))
1472                {
1473                   if (cw->native)
1474                     {
1475                        fprintf(stderr,
1476                                "BUGGER: shape with native surface? cw=%p\n",
1477                                cw);
1478                        return;
1479                     }
1480
1481                   evas_object_image_alpha_set(cw->obj, 0);
1482                   EINA_LIST_FOREACH(cw->obj_mirror, l, o)
1483                     {
1484                        evas_object_image_alpha_set(o, 1);
1485                     }
1486                   pix = evas_object_image_data_get(cw->obj, 1);
1487                   if (pix)
1488                     {
1489                        p = pix;
1490                        for (py = 0; py < h; py++)
1491                          {
1492                             for (px = 0; px < w; px++)
1493                               *p |= 0xff000000;
1494                          }
1495                     }
1496                   evas_object_image_data_set(cw->obj, pix);
1497                   evas_object_image_data_update_add(cw->obj, 0, 0, w, h);
1498                   EINA_LIST_FOREACH(cw->obj_mirror, l, o)
1499                     {
1500                        evas_object_image_data_set(o, pix);
1501                        evas_object_image_data_update_add(o, 0, 0, w, h);
1502                     }
1503
1504                }
1505           }
1506         // dont need to fix alpha chanel as blending
1507         // should be totally off here regardless of
1508         // alpha channel content
1509      }
1510 }
1511
1512 static void
1513 _e_mod_comp_win_free_xim(E_Comp_Win *cw)
1514 {
1515    if (cw->xim)
1516      {
1517         evas_object_image_data_set(cw->obj, NULL);
1518         ecore_x_image_free(cw->xim);
1519         cw->xim = NULL;
1520      }
1521 }
1522
1523 static void
1524 _e_mod_comp_win_update(E_Comp_Win *cw)
1525 {
1526    Eina_List *l;
1527    Evas_Object *o;
1528    E_Update_Rect *r;
1529    int i;
1530
1531    if (_comp_mod->conf->grab) ecore_x_grab();
1532    cw->update = 0;
1533
1534    if (cw->rotating)
1535      {
1536         if (cw->needpix)
1537           {
1538              cw->needpix = 0;
1539              cw->pw = cw->w;
1540              cw->ph = cw->h;
1541           }
1542
1543         if (cw->resize_hide) cw->resize_hide = EINA_FALSE;
1544
1545         Eina_Bool res;
1546         res = e_mod_comp_rotation_update(cw->rotobj,
1547                                          cw->up,
1548                                          cw->x, cw->y,
1549                                          cw->w, cw->h,
1550                                          cw->border);
1551         if (res)
1552           {
1553              if ((cw->visible) && (cw->dmg_updates > 0))
1554                {
1555                   Evas_Object *shobj = e_mod_comp_rotation_get_shobj(cw->rotobj);
1556                   if (shobj)
1557                     {
1558                        if (!evas_object_visible_get(shobj))
1559                          {
1560                             evas_object_show(cw->obj);
1561                             evas_object_show(shobj);
1562                             e_mod_comp_rotation_show_effect(cw->rotobj);
1563                             _e_mod_comp_win_inc_animating(cw);
1564
1565                          }
1566                        else if(e_mod_comp_rotation_angle_is_changed(cw->rotobj))
1567                          {
1568                             e_mod_comp_rotation_request_effect(cw->rotobj);
1569                             _e_mod_comp_win_inc_animating(cw);
1570                          }
1571                     }
1572                }
1573           }
1574         if (_comp_mod->conf->grab) ecore_x_ungrab();
1575         return;
1576      }
1577
1578    if (cw->argb)
1579      {
1580         if (cw->rects)
1581           {
1582              free(cw->rects);
1583              cw->rects = NULL;
1584              cw->rects_num = 0;
1585           }
1586      }
1587    else
1588      {
1589         if (cw->shape_changed)
1590           {
1591              if (cw->rects)
1592                {
1593                   free(cw->rects);
1594                   cw->rects = NULL;
1595                   cw->rects_num = 0;
1596                }
1597              ecore_x_pixmap_geometry_get(cw->win, NULL, NULL, &(cw->w), &(cw->h));
1598              cw->rects = ecore_x_window_shape_rectangles_get(cw->win, &(cw->rects_num));
1599              if (cw->rects)
1600                {
1601                   int int_w, int_h;
1602                   for (i = 0; i < cw->rects_num; i++)
1603                     {
1604                        int_w = (int)cw->rects[i].width;
1605                        int_h = (int)cw->rects[i].height;
1606                        E_RECTS_CLIP_TO_RECT(cw->rects[i].x,
1607                                             cw->rects[i].y,
1608                                             int_w,
1609                                             int_h,
1610                                             0, 0, cw->w, cw->h);
1611                        cw->rects[i].width = (unsigned int)int_w;
1612                        cw->rects[i].height = (unsigned int)int_h;
1613                     }
1614                }
1615              if (!_e_mod_comp_win_shaped_check(cw, cw->rects, cw->rects_num))
1616                {
1617                   free(cw->rects);
1618                   cw->rects = NULL;
1619                   cw->rects_num = 0;
1620                }
1621              if ((cw->rects) && (!cw->shaped)) cw->shaped = 1;
1622              else if ((!cw->rects) && (cw->shaped)) cw->shaped = 0;
1623           }
1624      }
1625
1626    if ((cw->needpix) && (cw->dmg_updates <= 0))
1627      {
1628         if (_comp_mod->conf->grab) ecore_x_ungrab();
1629         return;
1630      }
1631
1632    if ((!cw->pixmap) || (cw->needpix))
1633      {
1634         Ecore_X_Pixmap pm;
1635         pm = ecore_x_composite_name_window_pixmap_get(cw->win);
1636         if (pm)
1637           {
1638              Ecore_X_Pixmap oldpm;
1639
1640              cw->needpix = 0;
1641              if (cw->xim) cw->needxim = 1;
1642              oldpm = cw->pixmap;
1643              cw->pixmap = pm;
1644
1645              if (cw->pixmap)
1646                {
1647                   ecore_x_pixmap_geometry_get(cw->pixmap, NULL, NULL, &(cw->pw), &(cw->ph));
1648                   // pixmap's size is not equal with window's size case
1649                   if (!((cw->pw == cw->w) && (cw->ph == cw->h)))
1650                     {
1651                         L(LT_EFFECT,
1652                           "[COMP] pixmap is not prepared yet!! win: 0x%07x \n",
1653                           cw->win);
1654                         cw->pw = cw->w;
1655                         cw->ph = cw->h;
1656                         cw->pixmap = oldpm;
1657                         cw->needpix = 1;
1658                         ecore_x_pixmap_free(pm);
1659                         if (_comp_mod->conf->grab) ecore_x_ungrab();
1660                         return;
1661                     }
1662                }
1663              else
1664                {
1665                   cw->pw = 0;
1666                   cw->ph = 0;
1667                }
1668              if ((cw->pw <= 0) || (cw->ph <= 0))
1669                {
1670                   if (cw->native)
1671                     {
1672                        evas_object_image_native_surface_set(cw->obj, NULL);
1673                        cw->native = 0;
1674                        EINA_LIST_FOREACH(cw->obj_mirror, l, o)
1675                          {
1676                             evas_object_image_native_surface_set(o, NULL);
1677                          }
1678                     }
1679                   if (cw->pixmap)
1680                     {
1681                        ecore_x_pixmap_free(cw->pixmap);
1682                        cw->pixmap = 0;
1683                     }
1684                   cw->pw = 0;
1685                   cw->ph = 0;
1686                }
1687              ecore_x_e_comp_pixmap_set(cw->win, cw->pixmap);
1688              cw->native = 0;
1689              e_mod_comp_update_resize(cw->up, cw->pw, cw->ph);
1690              e_mod_comp_update_add(cw->up, 0, 0, cw->pw, cw->ph);
1691              if (oldpm)
1692                {
1693                   if (cw->native)
1694                     {
1695                        cw->native = 0;
1696                        if (!((cw->pw > 0) && (cw->ph > 0)))
1697                          {
1698                             evas_object_image_native_surface_set(cw->obj, NULL);
1699                             EINA_LIST_FOREACH(cw->obj_mirror, l, o)
1700                               {
1701                                  evas_object_image_native_surface_set(o, NULL);
1702                               }
1703                          }
1704                     }
1705                   ecore_x_pixmap_free(oldpm);
1706                }
1707           }
1708      }
1709
1710    if (!((cw->pw > 0) && (cw->ph > 0)))
1711      {
1712         if (_comp_mod->conf->grab) ecore_x_ungrab();
1713         return;
1714      }
1715
1716    // update obj geometry when task switcher is not open
1717    // or task switcher is open and new window is added
1718    cw->defer_move_resize = EINA_FALSE;
1719    if ( !cw->c->switcher_animating ||
1720         !cw->c->switcher ||
1721        (cw->c->switcher && !cw->first_show_worked) ||
1722        (cw->c->switcher && cw->win_type == WIN_INDICATOR))
1723      {
1724         evas_object_move(cw->shobj, cw->x, cw->y);
1725         evas_object_resize(cw->shobj,
1726                       cw->pw + (cw->border * 2),
1727                       cw->ph + (cw->border * 2));
1728      }
1729    else
1730      {
1731         cw->defer_move_resize = EINA_TRUE;
1732      }
1733
1734    if ((cw->c->gl)
1735        && (_comp_mod->conf->texture_from_pixmap)
1736        && (!cw->shaped)
1737        && (!cw->rects))
1738      {
1739         evas_object_image_size_set(cw->obj, cw->pw, cw->ph);
1740         EINA_LIST_FOREACH(cw->obj_mirror, l, o)
1741           {
1742              evas_object_image_size_set(o, cw->pw, cw->ph);
1743           }
1744         if (!cw->native)
1745           {
1746              Evas_Native_Surface ns;
1747
1748              ns.version = EVAS_NATIVE_SURFACE_VERSION;
1749              ns.type = EVAS_NATIVE_SURFACE_X11;
1750              ns.data.x11.visual = cw->vis;
1751              ns.data.x11.pixmap = cw->pixmap;
1752              evas_object_image_native_surface_set(cw->obj, &ns);
1753              cw->native = 1;
1754              EINA_LIST_FOREACH(cw->obj_mirror, l, o)
1755                {
1756                   evas_object_image_native_surface_set(o, &ns);
1757                }
1758           }
1759
1760         r = e_mod_comp_update_rects_get(cw->up);
1761         if (r)
1762           {
1763              e_mod_comp_update_clear(cw->up);
1764              for (i = 0; r[i].w > 0; i++)
1765                {
1766                   int x, y, w, h;
1767                   x = r[i].x; y = r[i].y;
1768                   w = r[i].w; h = r[i].h;
1769                   evas_object_image_data_update_add(cw->obj, x, y, w, h);
1770                   EINA_LIST_FOREACH(cw->obj_mirror, l, o)
1771                     {
1772                        evas_object_image_data_update_add(o, x, y, w, h);
1773                     }
1774
1775                }
1776              free(r);
1777           }
1778         else
1779           cw->update = 1;
1780      }
1781    else
1782      {
1783         if (cw->native)
1784           {
1785              evas_object_image_native_surface_set(cw->obj, NULL);
1786              EINA_LIST_FOREACH(cw->obj_mirror, l, o)
1787                {
1788                   evas_object_image_native_surface_set(o, NULL);
1789                }
1790              cw->native = 0;
1791           }
1792         if (cw->needxim)
1793           {
1794              cw->needxim = 0;
1795              if (cw->xim)
1796                {
1797                   evas_object_image_size_set(cw->obj, 1, 1);
1798                   evas_object_image_data_set(cw->obj, NULL);
1799                   EINA_LIST_FOREACH(cw->obj_mirror, l, o)
1800                     {
1801                        evas_object_image_size_set(o, 1, 1);
1802                        evas_object_image_data_set(o, NULL);
1803                     }
1804                   ecore_x_image_free(cw->xim);
1805                   cw->xim = NULL;
1806                }
1807           }
1808         if (!cw->xim)
1809           {
1810              if ((cw->xim = ecore_x_image_new(cw->pw, cw->ph, cw->vis, cw->depth)))
1811                e_mod_comp_update_add(cw->up, 0, 0, cw->pw, cw->ph);
1812           }
1813         r = e_mod_comp_update_rects_get(cw->up);
1814         if (r)
1815           {
1816              Eina_Bool get_image_failed = 0;
1817              if (cw->xim)
1818                {
1819                   unsigned int *pix;
1820                   pix = ecore_x_image_data_get(cw->xim, NULL, NULL, NULL);
1821                   evas_object_image_data_set(cw->obj, pix);
1822                   evas_object_image_size_set(cw->obj, cw->pw, cw->ph);
1823                   EINA_LIST_FOREACH(cw->obj_mirror, l, o)
1824                     {
1825                        evas_object_image_data_set(o, pix);
1826                        evas_object_image_size_set(o, cw->pw, cw->ph);
1827                     }
1828
1829                   e_mod_comp_update_clear(cw->up);
1830                   for (i = 0; r[i].w > 0; i++)
1831                     {
1832                        int x, y, w, h;
1833                        x = r[i].x; y = r[i].y;
1834                        w = r[i].w; h = r[i].h;
1835                        if (!ecore_x_image_get(cw->xim, cw->pixmap, x, y, x, y, w, h))
1836                          {
1837                             e_mod_comp_update_add(cw->up, x, y, w, h);
1838                             cw->update = 1;
1839                             get_image_failed = 1;
1840                          }
1841                        else
1842                          {
1843                             pix = ecore_x_image_data_get(cw->xim, NULL, NULL, NULL);
1844                             evas_object_image_data_set(cw->obj, pix);
1845                             evas_object_image_data_update_add(cw->obj, x, y, w, h);
1846                             EINA_LIST_FOREACH(cw->obj_mirror, l, o)
1847                               {
1848                                  evas_object_image_data_set(o, pix);
1849                                  evas_object_image_data_update_add(o, x, y, w, h);
1850                               }
1851                          }
1852                     }
1853                }
1854              free(r);
1855
1856              if (!get_image_failed)
1857                {
1858                   if (cw->shaped)
1859                     _e_mod_comp_win_shape_rectangles_apply(cw,
1860                                                            cw->rects,
1861                                                            cw->rects_num);
1862                   else
1863                     {
1864                        if (cw->shape_changed)
1865                          _e_mod_comp_win_shape_rectangles_apply(cw,
1866                                                                 cw->rects,
1867                                                                 cw->rects_num);
1868                     }
1869                }
1870              cw->shape_changed = 0;
1871           }
1872         else
1873           cw->update = 1;
1874      }
1875
1876    if (cw->resize_hide)
1877      {
1878         evas_object_show(cw->shobj);
1879         cw->resize_hide = EINA_FALSE;
1880      }
1881
1882    if ((!cw->rotating)
1883        && (!cw->update)
1884        && (cw->visible)
1885        && (cw->dmg_updates >= 1))
1886      {
1887         if (!evas_object_visible_get(cw->shobj)
1888             && !(cw->animate_hide))
1889           {
1890              if (!cw->hidden_override)
1891                evas_object_show(cw->shobj);
1892
1893              L(LT_EFFECT,
1894                "[COMP] WIN_EFFECT : Show signal Emit -> win:0x%08x\n",
1895                cw->win);
1896
1897              _e_mod_comp_window_show_effect(cw);
1898           }
1899      }
1900
1901    if (cw->ready_win_rot_effect)
1902      _e_mod_comp_win_rotation_begin(cw, EINA_FALSE);
1903
1904    if (_comp_mod->conf->grab) ecore_x_ungrab();
1905 }
1906
1907 static void
1908 _e_mod_comp_pre_swap(void *data,
1909                      Evas *e __UNUSED__)
1910 {
1911    E_Comp *c = data;
1912    L(LT_EVENT_X, "[COMP]    %15.15s\n", "SWAP");
1913    if (_comp_mod->conf->grab)
1914      {
1915         if (c->grabbed)
1916           {
1917              ecore_x_ungrab();
1918              c->grabbed = 0;
1919           }
1920      }
1921 }
1922
1923 static Eina_Bool
1924 _e_mod_comp_cb_delayed_update_timer(void *data)
1925 {
1926    E_Comp *c = data;
1927    _e_mod_comp_render_queue(c);
1928    c->new_up_timer = NULL;
1929    return ECORE_CALLBACK_CANCEL;
1930 }
1931
1932 static Eina_Bool
1933 _e_mod_comp_cb_update(E_Comp *c)
1934 {
1935    Eina_List *l;
1936    Evas_Object *o;
1937    E_Comp_Win *cw;
1938    Eina_List *new_updates = NULL; // for failed pixmap fetches - get them next frame
1939    Eina_List *update_done = NULL;
1940
1941    c->update_job = NULL;
1942    if (c->nocomp) goto nocomp;
1943    if (_comp_mod->conf->grab)
1944      {
1945         ecore_x_grab();
1946         ecore_x_sync();
1947         c->grabbed = 1;
1948      }
1949    EINA_LIST_FREE(c->updates, cw)
1950      {
1951         if (!cw) continue;
1952         if (_comp_mod->conf->efl_sync)
1953           {
1954              if (((cw->counter) && (cw->drawme)) || (!cw->counter))
1955                {
1956                   _e_mod_comp_win_update(cw);
1957                   if (cw->drawme)
1958                     update_done = eina_list_append(update_done, cw);
1959                   cw->drawme = 0;
1960                }
1961              else
1962                cw->update = 0;
1963           }
1964         else
1965           _e_mod_comp_win_update(cw);
1966         if (cw->update)
1967           new_updates = eina_list_append(new_updates, cw);
1968      }
1969
1970    _e_mod_comp_fps_update(c);
1971    if (_comp_mod->conf->fps_show)
1972      {
1973         char buf[128];
1974         double fps = 0.0, t, dt;
1975         int i;
1976         Evas_Coord x = 0, y = 0, w = 0, h = 0;
1977         E_Zone *z;
1978
1979         t = ecore_time_get();
1980
1981         if (_comp_mod->conf->fps_average_range < 1)
1982           _comp_mod->conf->fps_average_range = 30;
1983         else if (_comp_mod->conf->fps_average_range > 120)
1984           _comp_mod->conf->fps_average_range = 120;
1985
1986         dt = t - c->frametimes[_comp_mod->conf->fps_average_range - 1];
1987
1988         if (dt > 0.0) fps = (double)_comp_mod->conf->fps_average_range / dt;
1989         else fps = 0.0;
1990
1991         if (fps > 0.0) snprintf(buf, sizeof(buf), "FPS: %1.1f", fps);
1992         else snprintf(buf, sizeof(buf), "N/A");
1993
1994         for (i = 121; i >= 1; i--) c->frametimes[i] = c->frametimes[i - 1];
1995         c->frametimes[0] = t;
1996         c->frameskip++;
1997
1998         if (c->frameskip >= _comp_mod->conf->fps_average_range)
1999           {
2000              c->frameskip = 0;
2001              evas_object_text_text_set(c->fps_fg, buf);
2002           }
2003
2004         evas_object_geometry_get(c->fps_fg, NULL, NULL, &w, &h);
2005
2006         w += 8;
2007         h += 8;
2008         z = e_util_zone_current_get(c->man);
2009
2010         if (z)
2011           {
2012             switch (_comp_mod->conf->fps_corner)
2013              {
2014               case 3: // bottom-right
2015                x = z->x + z->w - w;
2016                y = z->y + z->h - h;
2017                break;
2018               case 2: // bottom-left
2019                x = z->x;
2020                y = z->y + z->h - h;
2021                break;
2022               case 1: // top-right
2023                x = z->x + z->w - w;
2024                y = z->y;
2025                break;
2026               default: // 0 // top-left
2027                x = z->x;
2028                y = z->y;
2029                break;
2030              }
2031           }
2032         evas_object_move(c->fps_bg, x, y);
2033         evas_object_resize(c->fps_bg, w, h);
2034         evas_object_move(c->fps_fg, x + 4, y + 4);
2035      }
2036
2037    if (_comp_mod->conf->lock_fps)
2038      {
2039         ecore_evas_manual_render(c->ee);
2040      }
2041    if (_comp_mod->conf->efl_sync)
2042      {
2043         EINA_LIST_FREE(update_done, cw)
2044           {
2045              if (!cw) continue;
2046              ecore_x_sync_counter_inc(cw->counter, 1);
2047           }
2048      }
2049    if (_comp_mod->conf->grab)
2050      {
2051         if (c->grabbed)
2052           {
2053              c->grabbed = 0;
2054              ecore_x_ungrab();
2055           }
2056      }
2057    if (new_updates)
2058      {
2059         if (c->new_up_timer) ecore_timer_del(c->new_up_timer);
2060         c->new_up_timer =
2061           ecore_timer_add(0.001, _e_mod_comp_cb_delayed_update_timer, c);
2062      }
2063    c->updates = new_updates;
2064    if (!c->animating) c->render_overflow--;
2065
2066 nocomp:
2067    cw = _e_mod_comp_fullscreen_check(c);
2068    if (cw)
2069      {
2070         if (_comp_mod->conf->nocomp_fs)
2071           {
2072              if (!c->nocomp)
2073                {
2074                   printf("NOCOMP!\n");
2075                   printf("kill comp %x\n", cw->win);
2076                   c->nocomp = 1;
2077                   c->render_overflow = OVER_FLOW;
2078                   ecore_x_window_hide(c->win);
2079                   cw->nocomp = 1;
2080                   if (cw->redirected)
2081                     {
2082                        printf("^^^^ undirect1 %x\n", cw->win);
2083                        ecore_x_composite_unredirect_window(cw->win, ECORE_X_COMPOSITE_UPDATE_MANUAL);
2084                        cw->redirected = 0;
2085                        cw->pw = 0;
2086                        cw->ph = 0;
2087                     }
2088                   if (cw->pixmap)
2089                     {
2090                        ecore_x_pixmap_free(cw->pixmap);
2091                        cw->pixmap = 0;
2092                        cw->pw = 0;
2093                        cw->ph = 0;
2094                        ecore_x_e_comp_pixmap_set(cw->win, cw->pixmap);
2095                     }
2096                   if (cw->xim)
2097                     {
2098                        evas_object_image_size_set(cw->obj, 1, 1);
2099                        evas_object_image_data_set(cw->obj, NULL);
2100                        EINA_LIST_FOREACH(cw->obj_mirror, l, o)
2101                          {
2102                             evas_object_image_size_set(o, 1, 1);
2103                             evas_object_image_data_set(o, NULL);
2104                          }
2105                        ecore_x_image_free(cw->xim);
2106                        cw->xim = NULL;
2107                     }
2108                   if (cw->damage)
2109                     {
2110                        Ecore_X_Region parts;
2111
2112                        eina_hash_del(damages, e_util_winid_str_get(cw->damage), cw);
2113                        parts = ecore_x_region_new(NULL, 0);
2114                        ecore_x_damage_subtract(cw->damage, 0, parts);
2115                        ecore_x_region_free(parts);
2116                        ecore_x_damage_free(cw->damage);
2117                        cw->damage = 0;
2118                     }
2119                   if (cw->update_timeout)
2120                     {
2121                        ecore_timer_del(cw->update_timeout);
2122                        cw->update_timeout = NULL;
2123                     }
2124                   if (cw->update)
2125                     {
2126                        cw->update = 0;
2127                        cw->c->updates = eina_list_remove(cw->c->updates, cw);
2128                     }
2129                   if (cw->counter)
2130                     {
2131                        printf("nosync\n");
2132                        Ecore_X_Window _win = _e_mod_comp_win_get_client_xid(cw);
2133                        ecore_x_e_comp_sync_cancel_send(_win);
2134                        ecore_x_sync_counter_inc(cw->counter, 1);
2135                     }
2136                   _e_mod_comp_render_queue(c);
2137                }
2138           }
2139      }
2140    else
2141      {
2142         if (c->nocomp)
2143           {
2144              printf("COMP!\n");
2145              c->nocomp = 0;
2146              c->render_overflow = OVER_FLOW;
2147              ecore_x_window_show(c->win);
2148              EINA_INLIST_FOREACH(c->wins, cw)
2149                {
2150                   if (!cw->nocomp) continue;
2151                   cw->nocomp = 0;
2152                   printf("restore comp %x --- %x\n", cw->win, cw->pixmap);
2153                   if (cw->pixmap) ecore_x_pixmap_free(cw->pixmap);
2154                   cw->pixmap = 0;
2155                   cw->pw = 0;
2156                   cw->ph = 0;
2157                   cw->native = 0;
2158                   if (!cw->damage)
2159                     {
2160                        cw->damage = ecore_x_damage_new
2161                          (cw->win, ECORE_X_DAMAGE_REPORT_DELTA_RECTANGLES);
2162                        eina_hash_add(damages, e_util_winid_str_get(cw->damage), cw);
2163                     }
2164                   if (!cw->redirected)
2165                     {
2166                        printf("^^^^ redirect2 %x\n", cw->win);
2167                        printf("  redr\n");
2168                        ecore_x_composite_redirect_window(cw->win, ECORE_X_COMPOSITE_UPDATE_MANUAL);
2169                        cw->pixmap = ecore_x_composite_name_window_pixmap_get(cw->win);
2170                        if (cw->pixmap)
2171                          ecore_x_pixmap_geometry_get(cw->pixmap, NULL, NULL, &(cw->pw), &(cw->ph));
2172                        else
2173                          {
2174                             cw->pw = 0;
2175                             cw->ph = 0;
2176                          }
2177                        printf("  %x %ix%i\n", cw->pixmap, cw->pw, cw->ph);
2178                        if ((cw->pw <= 0) || (cw->ph <= 0))
2179                          {
2180                             ecore_x_pixmap_free(cw->pixmap);
2181                             cw->pixmap = 0;
2182                          }
2183                        ecore_x_e_comp_pixmap_set(cw->win, cw->pixmap);
2184                        cw->redirected = 1;
2185                        cw->dmg_updates = 0;
2186                        e_mod_comp_update_resize(cw->up, cw->pw, cw->ph);
2187                        e_mod_comp_update_add(cw->up, 0, 0, cw->pw, cw->ph);
2188                     }
2189                   if (cw->visible)
2190                     {
2191                        if (!cw->hidden_override) evas_object_show(cw->shobj);
2192                        // no need for effect
2193                        cw->pending_count++;
2194                        e_manager_comp_event_src_visibility_send
2195                           (cw->c->man, (E_Manager_Comp_Source *)cw,
2196                               _e_mod_comp_cb_pending_after, cw->c);
2197
2198                     }
2199                   _e_mod_comp_win_render_queue(cw);
2200                   if (cw->counter)
2201                     {
2202                        Ecore_X_Window _win = _e_mod_comp_win_get_client_xid(cw);
2203                        ecore_x_e_comp_sync_begin_send(_win);
2204                     }
2205                }
2206           }
2207      }
2208
2209    if (c->render_overflow <= 0)
2210      {
2211         c->render_overflow = 0;
2212         if (c->render_animator) c->render_animator = NULL;
2213         return ECORE_CALLBACK_CANCEL;
2214      }
2215    return ECORE_CALLBACK_RENEW;
2216 }
2217
2218 static void
2219 _e_mod_comp_cb_job(void *data)
2220 {
2221    _e_mod_comp_cb_update(data);
2222 }
2223
2224 static Eina_Bool
2225 _e_mod_comp_cb_animator(void *data)
2226 {
2227    return _e_mod_comp_cb_update(data);
2228 }
2229
2230 static void
2231 _e_mod_comp_render_queue(E_Comp *c)
2232 {
2233    if (_comp_mod->conf->lock_fps)
2234      {
2235         if (c->render_animator)
2236           {
2237              c->render_overflow = OVER_FLOW;
2238              return;
2239           }
2240         c->render_animator = ecore_animator_add(_e_mod_comp_cb_animator, c);
2241      }
2242    else
2243      {
2244         if (c->update_job)
2245           {
2246              ecore_job_del(c->update_job);
2247              c->update_job = NULL;
2248              c->render_overflow = 0;
2249           }
2250         c->update_job = ecore_job_add(_e_mod_comp_cb_job, c);
2251      }
2252 }
2253
2254 void
2255 _e_mod_comp_win_render_queue(E_Comp_Win *cw)
2256 {
2257    _e_mod_comp_render_queue(cw->c);
2258 }
2259
2260 E_Comp *
2261 _e_mod_comp_find(Ecore_X_Window root)
2262 {
2263    Eina_List *l;
2264    E_Comp *c;
2265
2266    // fixme: use hash if compositors list > 4
2267    EINA_LIST_FOREACH(compositors, l, c)
2268      {
2269         if (!c) continue;
2270         if (c->man->root == root) return c;
2271      }
2272    return NULL;
2273 }
2274
2275 static E_Comp_Win *
2276 _e_mod_comp_win_find(Ecore_X_Window win)
2277 {
2278    return eina_hash_find(windows, e_util_winid_str_get(win));
2279 }
2280
2281 static E_Comp_Win *
2282 _e_mod_comp_border_client_find(Ecore_X_Window win)
2283 {
2284    return eina_hash_find(borders, e_util_winid_str_get(win));
2285 }
2286
2287 static E_Comp_Win *
2288 _e_mod_comp_win_damage_find(Ecore_X_Damage damage)
2289 {
2290    return eina_hash_find(damages, e_util_winid_str_get(damage));
2291 }
2292
2293 static Eina_Bool
2294 _e_mod_comp_win_is_borderless(E_Comp_Win *cw)
2295 {
2296    if (!cw->bd) return 1;
2297    if ((cw->bd->client.border.name) &&
2298        (!strcmp(cw->bd->client.border.name, "borderless")))
2299      return 1;
2300    return 0;
2301 }
2302
2303 Eina_Bool
2304 _e_mod_comp_fake_launch_timeout(void *data)
2305 {
2306    E_Comp *c = (E_Comp*)data;
2307    E_Comp_Win *background_cw = NULL;
2308    E_Comp_Win *find_cw = NULL;
2309
2310    if (!c->fake_launch_state) return 0;
2311
2312    if (c->fake_launch_timeout)
2313      {
2314         ecore_timer_del(c->fake_launch_timeout);
2315         c->fake_launch_timeout  = NULL;
2316      }
2317
2318    c->fake_launch_state = EINA_FALSE;
2319    c->fake_win = 0;
2320    c->fake_launch_done = EINA_FALSE;
2321
2322    // background hide effect
2323    background_cw = _e_mod_comp_win_find_fake_background_win(c);
2324    if (background_cw)
2325      {
2326         EINA_INLIST_FOREACH(c->wins, find_cw)
2327           {
2328              if ((find_cw->invalid)
2329                  || (find_cw->input_only)
2330                  || (find_cw->win == background_cw->win)
2331                  || _e_mod_comp_is_indicator_window(find_cw->bd))
2332                {
2333                  continue;
2334                }
2335              else
2336                {
2337                  if (evas_object_visible_get(find_cw->shobj))
2338                    {
2339                       // do hide window which is not related window animation effect.
2340                       find_cw->animate_hide = EINA_TRUE;
2341                       evas_object_hide(find_cw->shobj);
2342                    }
2343                }
2344           }
2345
2346         //show background image when background show animation is emitted.
2347         evas_object_stack_below(c->bg_img, evas_object_bottom_get(c->evas));
2348
2349         background_cw->animate_hide = EINA_FALSE;
2350
2351         edje_object_signal_emit(background_cw->shobj,
2352                                 "e,state,background,visible,off",
2353                                 "e");
2354         L(LT_EFFECT,
2355           "[COMP] WIN_EFFECT : Background Show Effect signal Emit -> win:0x%08x\n",
2356           background_cw->win);
2357
2358         _e_mod_comp_win_inc_animating(background_cw);
2359      }
2360
2361    // background show effect
2362    edje_object_signal_emit(c->fake_img_shobj,
2363                            "fake,state,visible,off",
2364                            "fake");
2365    L(LT_EFFECT,
2366      "[COMP] WIN_EFFECT : Fake Hide signal Emit\n");
2367
2368    return 0;
2369 }
2370
2371 static void
2372 _e_mod_comp_screen_lock(E_Comp *c)
2373 {
2374    if (!_comp_mod || !c) return;
2375    if (!_comp_mod->conf->use_lock_screen) return;
2376    if (c->lock_screen == 1) return;
2377    if (c->lock_screen_timeout) return;
2378
2379    if (!_comp_mod->conf->lock_fps)
2380      ecore_evas_manual_render_set(c->ee, 1);
2381
2382    c->lock_screen_timeout = ecore_timer_add(_comp_mod->conf->max_lock_screen_time,
2383                                             _e_mod_comp_screen_lock_timeout,
2384                                             c);
2385    c->lock_screen = 1;
2386 }
2387
2388 static void
2389 _e_mod_comp_screen_unlock(E_Comp *c)
2390 {
2391    E_Comp_Win *cw;
2392
2393    if (!_comp_mod || !c) return;
2394    if (!_comp_mod->conf->use_lock_screen) return;
2395    if (c->lock_screen == 0) return;
2396    if (c->lock_screen_timeout)
2397      {
2398         ecore_timer_del(c->lock_screen_timeout);
2399         c->lock_screen_timeout = NULL;
2400      }
2401
2402    /////////////////////////////////////////////////////////
2403    // To ensure the correct screen appearance
2404    // 1. remove all cw->update_timeout
2405    // 2. clear c->update_job
2406    // 3. clear c->updates using _e_mod_comp_cb_update()
2407    // 4. swap buffer
2408    /////////////////////////////////////////////////////////
2409
2410    // remove all cw->update_timeout
2411    EINA_INLIST_REVERSE_FOREACH(c->wins, cw)
2412      {
2413         if ((!cw->visible) || (cw->input_only) || (cw->invalid))
2414            continue;
2415         if (cw->counter && cw->update_timeout)
2416           {
2417              cw->update = 0;
2418              _e_mod_comp_win_damage_timeout((void*)cw);
2419           }
2420      }
2421
2422    // clear c->update_job
2423    if (c->update_job)
2424      {
2425         ecore_job_del(c->update_job);
2426         c->update_job = NULL;
2427         c->render_overflow = 0;
2428      }
2429
2430    // clear c->updates
2431    if (c->updates) _e_mod_comp_cb_update(c);
2432
2433    ecore_evas_manual_render(c->ee);
2434
2435    if (!_comp_mod->conf->lock_fps)
2436      ecore_evas_manual_render_set(c->ee, 0);
2437
2438    c->lock_screen = 0;
2439 }
2440
2441 static Eina_Bool
2442 _e_mod_comp_screen_lock_timeout(void *data)
2443 {
2444    E_Comp *c = (E_Comp*)data;
2445    _e_mod_comp_screen_unlock(c);
2446    return ECORE_CALLBACK_CANCEL;
2447 }
2448
2449 static Eina_Bool
2450 _e_mod_comp_win_rotation_begin_timeout(void *data)
2451 {
2452    E_Comp_Win *cw = (E_Comp_Win*)data;
2453    if (!cw) return EINA_FALSE;
2454
2455    fprintf(stderr, "[E17-comp] %s(%d) w:0x%08x\n",
2456            __func__, __LINE__,
2457            _e_mod_comp_win_get_client_xid(cw));
2458
2459    _e_mod_comp_win_rotation_begin(cw, EINA_TRUE);
2460
2461    return ECORE_CALLBACK_CANCEL;
2462 }
2463
2464 static Eina_Bool
2465 _e_mod_comp_win_rotation_end_timeout(void *data)
2466 {
2467    E_Comp_Win *cw = (E_Comp_Win*)data;
2468    if (!cw) return EINA_FALSE;
2469
2470    fprintf(stderr,"[E17-comp] %s(%d) w:0x%08x\n",
2471            __func__, __LINE__,
2472            _e_mod_comp_win_get_client_xid(cw));
2473
2474    _e_mod_comp_win_rotation_done((void*)cw,
2475                                  NULL,
2476                                  NULL,
2477                                  NULL);
2478
2479    return ECORE_CALLBACK_CANCEL;
2480 }
2481
2482 static Eina_Bool
2483 _e_mod_comp_win_damage_timeout(void *data)
2484 {
2485    E_Comp_Win *cw = data;
2486
2487    if (!cw->update)
2488      {
2489         if (cw->update_timeout)
2490           {
2491              ecore_timer_del(cw->update_timeout);
2492              cw->update_timeout = NULL;
2493           }
2494         cw->update = 1;
2495         cw->c->updates = eina_list_append(cw->c->updates, cw);
2496      }
2497    cw->drawme = 1;
2498    _e_mod_comp_win_render_queue(cw);
2499    if (cw->update_timeout)
2500      {
2501         ecore_timer_del(cw->update_timeout);
2502         cw->update_timeout = NULL;
2503      }
2504    return ECORE_CALLBACK_CANCEL;
2505 }
2506
2507 static void
2508 _e_mod_comp_object_del(void *data,
2509                        void *obj)
2510 {
2511    E_Comp_Win *cw = data;
2512
2513    _e_mod_comp_win_render_queue(cw);
2514
2515    _e_mod_comp_rotation_release(cw);
2516
2517    if (obj == cw->bd)
2518      {
2519         if (cw->counter)
2520           {
2521              Ecore_X_Window _w = _e_mod_comp_win_get_client_xid(cw);
2522              ecore_x_e_comp_sync_cancel_send(_w);
2523              ecore_x_sync_counter_inc(cw->counter, 1);
2524           }
2525         if (cw->bd) eina_hash_del(borders, e_util_winid_str_get(cw->bd->client.win), cw);
2526         cw->bd = NULL;
2527         evas_object_data_del(cw->shobj, "border");
2528      }
2529    else if (obj == cw->pop)
2530      {
2531         cw->pop = NULL;
2532         evas_object_data_del(cw->shobj, "popup");
2533      }
2534    else if (obj == cw->menu)
2535      {
2536         cw->menu = NULL;
2537         evas_object_data_del(cw->shobj, "menu");
2538      }
2539    if (cw->dfn)
2540      {
2541         e_object_delfn_del(obj, cw->dfn);
2542         cw->dfn = NULL;
2543      }
2544 }
2545
2546 void
2547 _e_mod_comp_done_defer(E_Comp_Win *cw)
2548 {
2549    _e_mod_comp_win_dec_animating(cw);
2550
2551    if (cw->defer_raise == EINA_TRUE)
2552      {
2553         L(LT_EFFECT,
2554           "[COMP] w:0x%08x force win to raise. bd:%s\n",
2555           _e_mod_comp_win_get_client_xid(cw),
2556           cw->bd ? "O" : "X");
2557
2558         E_Comp_Win *_cw;
2559         EINA_INLIST_FOREACH(cw->c->wins, _cw)
2560           {
2561              evas_object_raise(_cw->shobj);
2562              if (cw->c->use_bg_img && _cw->win_rot_effect)
2563                {
2564                   evas_object_stack_below(cw->c->bg_img, _cw->shobj);
2565                }
2566           }
2567         cw->defer_raise = EINA_FALSE;
2568         edje_object_signal_emit(cw->shobj,
2569                                 "e,state,raise_above_post,on",
2570                                 "e");
2571      }
2572    cw->force = 1;
2573    if (cw->defer_hide)
2574      {
2575         L(LT_EVENT_X,
2576           "[COMP] %31s w:0x%08x force win to hide. bd:%s\n",
2577           "EDJ_DONE", _e_mod_comp_win_get_client_xid(cw),
2578           cw->bd ? "O" : "X");
2579
2580         _e_mod_comp_win_hide(cw);
2581      }
2582    cw->force = 1;
2583    if (cw->delete_me)
2584      {
2585         L(LT_EVENT_X,
2586           "[COMP] %31s w:0x%08x force win to delete. bd:%s\n",
2587           "EDJ_DONE", _e_mod_comp_win_get_client_xid(cw),
2588           cw->bd ? "O" : "X");
2589
2590         _e_mod_comp_win_del(cw);
2591      }
2592    else cw->force = 0;
2593 }
2594
2595 static void
2596 _e_mod_comp_show_done(void *data,
2597                       Evas_Object *obj __UNUSED__,
2598                       const char *emission __UNUSED__,
2599                       const char *source __UNUSED__)
2600 {
2601    E_Comp_Win *cw = data;
2602
2603    LOG(LOG_DEBUG, "LAUNCH", "[e17:Application:Launching:done]");
2604    L(LT_EFFECT,
2605      "[COMP] WIN_EFFECT : Show done -> win:0x%08x\n",
2606      cw->win);
2607
2608    if ((cw->win_type == WIN_TASK_MANAGER)
2609        && (cw->c->switcher == EINA_TRUE))
2610      {
2611         int i = 0;
2612         Evas_Coord x, y, w, h;
2613         E_Comp_Win *_cw;
2614         cw->c->switcher_animating = EINA_FALSE;
2615         EINA_INLIST_REVERSE_FOREACH(cw->c->wins, _cw)
2616           {
2617              if ((_cw->visible == 1)
2618                  && evas_object_visible_get(_cw->shobj)
2619                  && evas_object_visible_get(_cw->obj)
2620                  && !_e_mod_comp_is_indicator_window(_cw->bd))
2621                {
2622                   evas_object_geometry_get(_cw->shobj,
2623                                            &x, &y, &w, &h);
2624                   if (w == _cw->c->screen_w
2625                       && h == _cw->c->screen_h)
2626                     {
2627                        i++;
2628                        // return all windows to original position
2629                        evas_object_move(_cw->shobj, 0, 0);
2630                     }
2631                   if ( _cw->defer_move_resize )
2632                     {
2633                        evas_object_move(_cw->shobj, _cw->x, _cw->y );
2634                        evas_object_resize(_cw->shobj, _cw->pw + (_cw->border * 2),
2635                                                       _cw->ph + (_cw->border * 2));
2636                        _cw->defer_move_resize = EINA_FALSE;
2637                     }
2638                }
2639           }
2640         _e_mod_comp_disable_effect_stage(_e_mod_comp_get());
2641      }
2642    cw->show_done = EINA_TRUE;
2643    _e_mod_comp_done_defer(cw);
2644 }
2645
2646 static void
2647 _e_mod_comp_hide_done(void *data,
2648                       Evas_Object *obj __UNUSED__,
2649                       const char *emission __UNUSED__,
2650                       const char *source __UNUSED__)
2651 {
2652    E_Comp_Win *cw = data;
2653
2654    L(LT_EFFECT,
2655      "[COMP] WIN_EFFECT : Hide done -> win:0x%08x\n",
2656      cw->win);
2657
2658    if ((cw->win_type == WIN_TASK_MANAGER)
2659        && (cw->c->switcher))
2660      {
2661         E_Comp_Win *_cw;
2662         cw->c->switcher_animating = EINA_FALSE;
2663         if (cw->c->selected_pos > 0) cw->c->selected_pos = 0;
2664         // task switcher is closed
2665         cw->c->switcher = EINA_FALSE;
2666         _e_mod_comp_disable_effect_stage(_e_mod_comp_get());
2667
2668         EINA_INLIST_REVERSE_FOREACH(cw->c->wins, _cw)
2669           {
2670              if ( (_cw->visible == 1)
2671                   && evas_object_visible_get(_cw->shobj)
2672                   && !_e_mod_comp_is_indicator_window(_cw->bd)
2673                   && (_cw->defer_move_resize == EINA_TRUE) )
2674                {
2675                    evas_object_move(_cw->shobj, _cw->x, _cw->y );
2676                    evas_object_resize(_cw->shobj, _cw->pw + (_cw->border * 2),
2677                                                   _cw->ph + (_cw->border * 2));
2678                    _cw->defer_move_resize = EINA_FALSE;
2679                }
2680           }
2681      }
2682
2683    cw->show_done = EINA_FALSE;
2684    _e_mod_comp_done_defer(cw);
2685 }
2686
2687 static void
2688 _e_mod_comp_raise_above_hide_done(void *data,
2689                                   Evas_Object *obj __UNUSED__,
2690                                   const char *emission __UNUSED__,
2691                                   const char *source __UNUSED__)
2692 {
2693    E_Comp_Win *cw = data;
2694    L(LT_EFFECT,
2695      "[COMP] WIN_EFFECT : Raise Above Hide done -> win:0x%08x\n",
2696      cw->win);
2697    if (!cw) return;
2698    _e_mod_comp_disable_effect_stage(_e_mod_comp_get());
2699    _e_mod_comp_done_defer(cw);
2700 }
2701
2702 static void
2703 _e_mod_comp_fake_show_done(void *data,
2704                            Evas_Object *obj __UNUSED__,
2705                            const char *emission __UNUSED__,
2706                            const char *source __UNUSED__)
2707 {
2708    E_Comp *c = data;
2709    E_Comp_Win* cw = NULL;
2710
2711    L(LT_EFFECT,
2712      "[COMP] FAKE_EFFECT : FAKE Show done\n");
2713
2714    c->fake_launch_done = EINA_TRUE;
2715    if ((c->fake_win != 0)
2716        && (c->fake_launch_state))
2717      {
2718         cw = _e_mod_comp_win_find(c->fake_win);
2719         if (cw)
2720           {
2721              // send_noeffect_signal
2722              edje_object_signal_emit(cw->shobj,
2723                                      "e,state,visible,on,noeffect",
2724                                      "e");
2725              _e_mod_comp_disable_fake_launch(cw->c);
2726           }
2727       }
2728 }
2729
2730 static void
2731 _e_mod_comp_fake_hide_done(void *data,
2732                            Evas_Object *obj __UNUSED__,
2733                            const char *emission __UNUSED__,
2734                            const char *source __UNUSED__)
2735 {
2736    E_Comp *c = data;
2737
2738    L(LT_EFFECT,
2739      "[COMP] FAKE_EFFECT : Hide done \n");
2740
2741    _e_mod_comp_disable_touch_event_block(c);
2742
2743    evas_object_hide(c->fake_img_shobj);
2744    edje_object_part_unswallow(c->fake_img_shobj, c->fake_img_obj);
2745    evas_object_del(c->fake_img_obj);
2746
2747    utilx_ungrab_key(ecore_x_display_get(), c->win, KEY_SELECT);
2748    utilx_ungrab_key(ecore_x_display_get(), c->win, KEY_VOLUMEUP);
2749    utilx_ungrab_key(ecore_x_display_get(), c->win, KEY_VOLUMEDOWN);
2750    utilx_ungrab_key(ecore_x_display_get(), c->win, KEY_CAMERA);
2751 }
2752
2753 static void
2754 _e_mod_comp_background_show_done(void *data,
2755                                  Evas_Object *obj __UNUSED__,
2756                                  const char *emission __UNUSED__,
2757                                  const char *source __UNUSED__)
2758 {
2759    E_Comp_Win *cw = data;
2760
2761    L(LT_EFFECT,
2762      "[COMP] WIN_EFFECT : Background Show done -> win:0x%08x\n",
2763      cw->win);
2764
2765    cw->effect_stage = EINA_FALSE;
2766    _e_mod_comp_disable_effect_stage(cw->c);
2767
2768    L(LT_EFFECT,
2769      "[COMP] WIN_EFFECT : Background Show done (Background show animate_hide window) -> win:0x%08x\n",
2770      cw->win);
2771
2772    _e_mod_comp_done_defer(cw);
2773 }
2774
2775 static void
2776 _e_mod_comp_background_hide_done(void *data,
2777                                  Evas_Object *obj __UNUSED__,
2778                                  const char *emission __UNUSED__,
2779                                  const char *source __UNUSED__)
2780 {
2781    E_Comp_Win *cw = data;
2782
2783    L(LT_EFFECT,
2784      "[COMP] WIN_EFFECT : Background Hide done -> win:0x%08x\n",
2785      cw->win);
2786
2787    cw->effect_stage = EINA_FALSE;
2788    _e_mod_comp_disable_effect_stage(cw->c);
2789
2790    L(LT_EFFECT,
2791      "[COMP] WIN_EFFECT : Background Hide done (Background hide animate_hide window) -> win:0x%08x\n",
2792      cw->win);
2793
2794    _e_mod_comp_done_defer(cw);
2795 }
2796
2797 // if Border is not existed then, return itself.
2798 // otherwise, return itself or parent.
2799 E_Comp_Win *
2800 _e_mod_comp_win_transient_parent_find(E_Comp_Win *cw)
2801 {
2802    Ecore_X_Window transient_parent;
2803    E_Comp_Win *parent_cw = NULL;
2804    E_Border *bd = NULL;
2805    if (cw->bd)
2806      {
2807         bd = cw->bd;
2808         do {
2809              transient_parent = bd->win;
2810              bd = bd->parent;
2811         } while (bd);
2812
2813         parent_cw = _e_mod_comp_win_find(transient_parent);
2814         return parent_cw;
2815      }
2816    return cw;
2817 }
2818
2819 E_Comp_Win *
2820 _e_mod_comp_win_find_background_win(E_Comp_Win *cw)
2821 {
2822    Eina_Inlist *wins_list;
2823    E_Comp_Win *find_cw = cw;
2824    if (!find_cw) return NULL;
2825
2826    while ((wins_list = EINA_INLIST_GET(find_cw)->prev) != NULL)
2827      {
2828         find_cw = _EINA_INLIST_CONTAINER(find_cw, wins_list);
2829         if ((find_cw->w == find_cw->c->man->w) &&
2830             (find_cw->h == find_cw->c->man->h) &&
2831             (find_cw->x == 0) &&
2832             (find_cw->y == 0) &&
2833             (find_cw->visible) &&
2834             (find_cw->invalid == EINA_FALSE) &&
2835             (find_cw->input_only == EINA_FALSE))
2836           {
2837              return find_cw;
2838           }
2839      }
2840    return NULL;
2841 }
2842
2843 E_Comp_Win *
2844 _e_mod_comp_win_find_fake_background_win(E_Comp *c)
2845 {
2846    E_Comp_Win *find_cw = NULL;
2847    if (!c) return NULL;
2848
2849    EINA_INLIST_REVERSE_FOREACH(c->wins, find_cw)
2850      {
2851         if ((find_cw->w == c->man->w) &&
2852             (find_cw->h == c->man->h) &&
2853             (find_cw->x == 0) &&
2854             (find_cw->y == 0) &&
2855             (find_cw->visible) &&
2856             (find_cw->invalid == EINA_FALSE) &&
2857             (find_cw->input_only == EINA_FALSE))
2858           {
2859              return find_cw;
2860           }
2861      }
2862    return NULL;
2863 }
2864
2865 static void
2866 _e_mod_comp_win_sync_setup(E_Comp_Win *cw,
2867                            Ecore_X_Window win)
2868 {
2869    if (!_comp_mod->conf->efl_sync) return;
2870    if (cw->bd)
2871      {
2872         if (_e_mod_comp_win_is_borderless(cw)
2873             || (_comp_mod->conf->loose_sync))
2874           cw->counter = ecore_x_e_comp_sync_counter_get(win);
2875         else
2876           {
2877              ecore_x_e_comp_sync_cancel_send(win);
2878              cw->counter = 0;
2879           }
2880      }
2881    else
2882      cw->counter = ecore_x_e_comp_sync_counter_get(win);
2883
2884    if (cw->counter)
2885      {
2886         if (cw->bd)
2887           {
2888              E_Comp_Win *client_cw = _e_mod_comp_win_find(win);
2889              if (client_cw &&
2890                  client_cw->counter == cw->counter)
2891                {
2892                   ecore_x_sync_counter_inc(cw->counter, 1);
2893                   return;
2894                }
2895           }
2896
2897         ecore_x_e_comp_sync_begin_send(win);
2898         ecore_x_sync_counter_inc(cw->counter, 1);
2899      }
2900 }
2901
2902 static void
2903 _e_mod_comp_win_shadow_setup(E_Comp_Win *cw)
2904 {
2905    Evas_Object *o;
2906    Eina_List *l;
2907    int ok = 0;
2908    char buf[PATH_MAX];
2909
2910    evas_object_image_smooth_scale_set(cw->obj, _comp_mod->conf->smooth_windows);
2911    EINA_LIST_FOREACH(cw->obj_mirror, l, o)
2912      {
2913         evas_object_image_smooth_scale_set(o, _comp_mod->conf->smooth_windows);
2914      }
2915
2916    if (_comp_mod->conf->shadow_file)
2917      {
2918         ok = _e_mod_comp_shadow_policy(cw);
2919      }
2920
2921    if (!ok)
2922      {
2923         fprintf(stdout,
2924                 "[E17-comp] EDC Animation isn't loaded! win:0x%08x %s(%d) file:%s\n",
2925                 cw->win, __func__, __LINE__, _comp_mod->conf->shadow_file);
2926
2927         _e_mod_comp_get_edje_error(cw);
2928
2929         if (_comp_mod->conf->shadow_style)
2930           {
2931              snprintf(buf, sizeof(buf), "e/comp/%s", _comp_mod->conf->shadow_style);
2932              ok = e_theme_edje_object_set(cw->shobj,
2933                                           "base/theme/borders",
2934                                           buf);
2935           }
2936         if (!ok)
2937           {
2938              ok = e_theme_edje_object_set(cw->shobj,
2939                                           "base/theme/borders",
2940                                           "e/comp/default");
2941           }
2942      }
2943    // fallback to local shadow.edj - will go when default theme supports this
2944    if (!ok)
2945      {
2946         fprintf(stdout,
2947                 "[E17-comp] EDC Animation isn't loaded! win:0x%08x %s(%d)\n",
2948                 cw->win, __func__, __LINE__);
2949         _e_mod_comp_get_edje_error(cw);
2950         snprintf(buf, sizeof(buf), "%s/shadow.edj", e_module_dir_get(_comp_mod->module));
2951         ok = edje_object_file_set(cw->shobj, buf, "shadow");
2952      }
2953    if (!edje_object_part_swallow(cw->shobj,
2954                                  "e.swallow.content",
2955                                  cw->obj))
2956      {
2957         fprintf(stdout,
2958                 "[E17-comp] Window pixmap didn't swalloed! win:0x%08x %s(%d)\n",
2959                 cw->win, __func__, __LINE__);
2960      }
2961
2962    _e_mod_comp_get_edje_error(cw);
2963    edje_object_signal_emit(cw->shobj,
2964                            "e,state,shadow,off",
2965                            "e");
2966
2967    if (cw->bd)
2968      {
2969         if (cw->bd->focused)
2970           edje_object_signal_emit(cw->shobj,
2971                                   "e,state,focus,on",
2972                                   "e");
2973         if (cw->bd->client.icccm.urgent)
2974           edje_object_signal_emit(cw->shobj,
2975                                   "e,state,urgent,on",
2976                                   "e");
2977      }
2978 }
2979
2980 static Evas_Object *
2981 _e_mod_comp_win_mirror_add(E_Comp_Win *cw)
2982 {
2983    Evas_Object *o;
2984
2985    if (!cw->c) return NULL;
2986
2987    o = evas_object_image_filled_add(cw->c->evas);
2988    evas_object_image_colorspace_set(o, EVAS_COLORSPACE_ARGB8888);
2989    cw->obj_mirror = eina_list_append(cw->obj_mirror, o);
2990
2991    if ((cw->pixmap) && (cw->pw > 0) && (cw->ph > 0))
2992      {
2993         unsigned int *pix;
2994         Eina_Bool alpha;
2995         int w, h;
2996
2997         alpha = evas_object_image_alpha_get(cw->obj);
2998         evas_object_image_size_get(cw->obj, &w, &h);
2999
3000         evas_object_image_alpha_set(o, alpha);
3001
3002         if (cw->shaped)
3003           {
3004              pix = evas_object_image_data_get(cw->obj, 0);
3005              evas_object_image_data_set(o, pix);
3006              evas_object_image_size_set(o, w, h);
3007              evas_object_image_data_set(o, pix);
3008              evas_object_image_data_update_add(o, 0, 0, w, h);
3009           }
3010         else
3011           {
3012              if (cw->native)
3013                {
3014                   Evas_Native_Surface ns;
3015
3016                   ns.version = EVAS_NATIVE_SURFACE_VERSION;
3017                   ns.type = EVAS_NATIVE_SURFACE_X11;
3018                   ns.data.x11.visual = cw->vis;
3019                   ns.data.x11.pixmap = cw->pixmap;
3020                   evas_object_image_size_set(o, w, h);
3021                   evas_object_image_native_surface_set(o, &ns);
3022                   evas_object_image_data_update_add(o, 0, 0, w, h);
3023                }
3024              else
3025                {
3026                   pix = ecore_x_image_data_get(cw->xim, NULL, NULL, NULL);
3027                   evas_object_image_data_set(o, pix);
3028                   evas_object_image_size_set(o, w, h);
3029                   evas_object_image_data_set(o, pix);
3030                   evas_object_image_data_update_add(o, 0, 0, w, h);
3031                }
3032           }
3033         evas_object_image_size_set(o, w, h);
3034         evas_object_image_data_update_add(o, 0, 0, w, h);
3035     }
3036
3037    return o;
3038 }
3039
3040
3041 static E_Comp_Win *
3042 _e_mod_comp_win_add(E_Comp *c,
3043                     Ecore_X_Window win)
3044 {
3045    Ecore_X_Window_Attributes att;
3046    E_Comp_Win *cw;
3047
3048    cw = calloc(1, sizeof(E_Comp_Win));
3049    if (!cw) return NULL;
3050
3051    cw->win = win;
3052    cw->c = c;
3053    cw->bd = e_border_find_by_window(cw->win);
3054    cw->resize_hide = EINA_FALSE;
3055    cw->animate_hide = EINA_FALSE;
3056    cw->animatable = EINA_TRUE;
3057    cw->first_show_worked = EINA_FALSE;
3058    cw->show_done = EINA_FALSE;
3059    cw->effect_stage = EINA_FALSE;
3060    cw->win_type = WIN_NORMAL;
3061    cw->defer_move_resize = EINA_FALSE;
3062    //cw->ready_hide_effect = EINA_FALSE;
3063
3064    _e_mod_comp_window_effect_policy(cw);
3065
3066    if (_comp_mod->conf->grab) ecore_x_grab();
3067    if (cw->bd)
3068      {
3069         eina_hash_add(borders, e_util_winid_str_get(cw->bd->client.win), cw);
3070         cw->dfn = e_object_delfn_add(E_OBJECT(cw->bd),
3071                                      _e_mod_comp_object_del, cw);
3072
3073         if      (_e_mod_comp_is_normal_window(cw->bd)        ) cw->win_type = WIN_NORMAL;
3074         else if (_e_mod_comp_is_quickpanel_window(cw->bd)    ) cw->win_type = WIN_QUICKPANEL;
3075         else if (_e_mod_comp_is_task_manager_window(cw->bd)  ) cw->win_type = WIN_TASK_MANAGER;
3076         else if (_e_mod_comp_is_live_magazine_window(cw->bd) ) cw->win_type = WIN_LIVE_MAGAZINE;
3077         else if (_e_mod_comp_is_lock_screen_window(cw->bd)   ) cw->win_type = WIN_LOCK_SCREEN;
3078         else if (_e_mod_comp_is_indicator_window(cw->bd)     ) cw->win_type = WIN_INDICATOR;
3079         else if (_e_mod_comp_is_isf_main_window(cw->bd)      ) cw->win_type = WIN_ISF_MAIN;
3080         else if (_e_mod_comp_is_isf_sub_window(cw->bd)       ) cw->win_type = WIN_ISF_SUB;
3081         else if (_e_mod_comp_is_tooltip_window(cw->bd)       ) cw->win_type = WIN_TOOLTIP;
3082         else if (_e_mod_comp_is_combo_window(cw->bd)         ) cw->win_type = WIN_COMBO;
3083         else if (_e_mod_comp_is_dnd_window(cw->bd)           ) cw->win_type = WIN_DND;
3084         else if (_e_mod_comp_is_desktop_window(cw->bd)       ) cw->win_type = WIN_DESKTOP;
3085         else if (_e_mod_comp_is_toolbar_window(cw->bd)       ) cw->win_type = WIN_TOOLBAR;
3086         else if (_e_mod_comp_is_menu_window(cw->bd)          ) cw->win_type = WIN_MENU;
3087         else if (_e_mod_comp_is_splash_window(cw->bd)        ) cw->win_type = WIN_SPLASH;
3088         else if (_e_mod_comp_is_drop_down_menu_window(cw->bd)) cw->win_type = WIN_DROP_DOWN_MENU;
3089         else if (_e_mod_comp_is_notification_window(cw->bd)  ) cw->win_type = WIN_NOTIFICATION;
3090         else if (_e_mod_comp_is_utility_window(cw->bd)       ) cw->win_type = WIN_UTILITY;
3091         else if (_e_mod_comp_is_popup_menu_window(cw->bd)    ) cw->win_type = WIN_POPUP_MENU;
3092         else if (_e_mod_comp_is_dialog_window(cw->bd)        ) cw->win_type = WIN_DIALOG;
3093      }
3094    else
3095      {
3096         cw->pop = e_popup_find_by_window(cw->win);
3097         if (cw->pop)
3098           cw->dfn = e_object_delfn_add(E_OBJECT(cw->pop),
3099                                        _e_mod_comp_object_del, cw);
3100         else
3101           {
3102              cw->menu = e_menu_find_by_window(cw->win);
3103              if (cw->menu)
3104                cw->dfn = e_object_delfn_add(E_OBJECT(cw->menu),
3105                                             _e_mod_comp_object_del, cw);
3106              else
3107                {
3108                   char *netwm_title = NULL;
3109                   cw->title = ecore_x_icccm_title_get(cw->win);
3110                   if (ecore_x_netwm_name_get(cw->win, &netwm_title))
3111                     {
3112                        if (cw->title) free(cw->title);
3113                        cw->title = netwm_title;
3114                     }
3115                   ecore_x_icccm_name_class_get(cw->win, &cw->name, &cw->clas);
3116                   cw->role = ecore_x_icccm_window_role_get(cw->win);
3117                   if (!ecore_x_netwm_window_type_get(cw->win, &cw->primary_type))
3118                     cw->primary_type = ECORE_X_WINDOW_TYPE_UNKNOWN;
3119                }
3120           }
3121      }
3122    // fixme: could use bd/pop/menu for this too
3123    memset((&att), 0, sizeof(Ecore_X_Window_Attributes));
3124    if (!ecore_x_window_attributes_get(cw->win, &att))
3125      {
3126         free(cw);
3127         if (_comp_mod->conf->grab) ecore_x_ungrab();
3128         return NULL;
3129      }
3130
3131    if ((!att.input_only) &&
3132        ((att.depth != 24) && (att.depth != 32)))
3133      {
3134         printf("WARNING: window 0x%x not 24/32bpp -> %ibpp\n",
3135                cw->win, att.depth);
3136         cw->invalid = 1;
3137      }
3138    cw->input_only = att.input_only;
3139    cw->override = att.override;
3140    cw->vis = att.visual;
3141    cw->depth = att.depth;
3142    cw->argb = ecore_x_window_argb_get(cw->win);
3143
3144    eina_hash_add(windows, e_util_winid_str_get(cw->win), cw);
3145    cw->inhash = 1;
3146    if ((!cw->input_only) && (!cw->invalid))
3147      {
3148         Ecore_X_Rectangle *rects;
3149         int num;
3150
3151         cw->damage = ecore_x_damage_new
3152           (cw->win, ECORE_X_DAMAGE_REPORT_DELTA_RECTANGLES);
3153         eina_hash_add(damages, e_util_winid_str_get(cw->damage), cw);
3154         cw->shobj = edje_object_add(c->evas);
3155         if (!cw->c->use_bg_img)
3156           {
3157              evas_object_stack_below(cw->c->bg_img, evas_object_bottom_get(cw->c->evas));
3158           }
3159         cw->obj = evas_object_image_filled_add(c->evas);
3160         evas_object_image_colorspace_set(cw->obj, EVAS_COLORSPACE_ARGB8888);
3161
3162         if (cw->argb) evas_object_image_alpha_set(cw->obj, 1);
3163         else evas_object_image_alpha_set(cw->obj, 0);
3164
3165         _e_mod_comp_win_shadow_setup(cw);
3166         _e_mod_comp_win_cb_setup(cw);
3167
3168         evas_object_show(cw->obj);
3169         ecore_x_window_shape_events_select(cw->win, 1);
3170         rects = ecore_x_window_shape_rectangles_get(cw->win, &num);
3171         if (rects)
3172           {
3173              int i;
3174              if (rects)
3175                {
3176                   int int_w, int_h;
3177                   for (i = 0; i < num; i++)
3178                     {
3179                        int_w = (int)rects[i].width;
3180                        int_h = (int)rects[i].height;
3181                        E_RECTS_CLIP_TO_RECT(rects[i].x, rects[i].y,
3182                                             int_w, int_h,
3183                                             0, 0, att.w, att.h);
3184                        rects[i].width = (unsigned int)int_w;
3185                        rects[i].height = (unsigned int)int_h;
3186                     }
3187                }
3188              if (!_e_mod_comp_shaped_check(att.w, att.h, rects, num))
3189                {
3190                   free(rects);
3191                   rects = NULL;
3192                }
3193              if (rects)
3194                {
3195                   cw->shape_changed = 1;
3196                   free(rects);
3197                }
3198           }
3199         if (cw->bd) evas_object_data_set(cw->shobj, "border", cw->bd);
3200         else if (cw->pop) evas_object_data_set(cw->shobj, "popup", cw->pop);
3201         else if (cw->menu) evas_object_data_set(cw->shobj, "menu", cw->menu);
3202
3203         evas_object_pass_events_set(cw->obj, 1);
3204
3205         cw->pending_count++;
3206         e_manager_comp_event_src_add_send
3207            (cw->c->man, (E_Manager_Comp_Source *)cw,
3208                _e_mod_comp_cb_pending_after, cw->c);
3209      }
3210    else
3211      {
3212         cw->shobj = evas_object_rectangle_add(c->evas);
3213         evas_object_color_set(cw->shobj, 0, 0, 0, 0);
3214      }
3215    evas_object_pass_events_set(cw->shobj, 1);
3216    evas_object_data_set(cw->shobj, "win",
3217                         (void *)((unsigned long)cw->win));
3218    evas_object_data_set(cw->shobj, "src", cw);
3219
3220    c->wins_invalid = 1;
3221    c->wins = eina_inlist_append(c->wins, EINA_INLIST_GET(cw));
3222    cw->up = e_mod_comp_update_new();
3223    e_mod_comp_update_tile_size_set(cw->up, 32, 32);
3224    // for software:
3225    e_mod_comp_update_policy_set
3226      (cw->up, E_UPDATE_POLICY_HALF_WIDTH_OR_MORE_ROUND_UP_TO_FULL_WIDTH);
3227    if (((!cw->input_only) && (!cw->invalid)) && (cw->override))
3228      {
3229         cw->redirected = 1;
3230         cw->dmg_updates = 0;
3231      }
3232    if (_comp_mod->conf->grab) ecore_x_ungrab();
3233    return cw;
3234 }
3235
3236 static void
3237 _e_mod_comp_win_del(E_Comp_Win *cw)
3238 {
3239    int pending_count;
3240    Eina_List *l;
3241    Evas_Object *o;
3242
3243    // while win_hide animation is progressing, at that time win_del is called,
3244    // background window effect is may not work fully.
3245    // so, explicit call disable effect stage function.
3246    if (cw->effect_stage)
3247      _e_mod_comp_disable_effect_stage(cw->c);
3248
3249    if (cw->animating)
3250      {
3251         cw->c->animating--;
3252         cw->animating = 0;
3253         _e_mod_comp_send_window_effect_client_state(cw, EINA_FALSE);
3254      }
3255
3256    if ((!cw->input_only) && (!cw->invalid))
3257      {
3258         cw->pending_count++;
3259         e_manager_comp_event_src_del_send
3260            (cw->c->man, (E_Manager_Comp_Source *)cw,
3261                _e_mod_comp_cb_pending_after, cw->c);
3262      }
3263
3264    e_mod_comp_update_free(cw->up);
3265    _e_mod_comp_rotation_release(cw);
3266
3267    // release window rotation stuffs
3268    _e_mod_comp_win_rotation_release(cw);
3269
3270    if (cw->rects)
3271      {
3272         free(cw->rects);
3273         cw->rects = NULL;
3274      }
3275    if (cw->update_timeout)
3276      {
3277         ecore_timer_del(cw->update_timeout);
3278         cw->update_timeout = NULL;
3279      }
3280    if (cw->dfn)
3281      {
3282         if (cw->bd)
3283           {
3284              eina_hash_del(borders, e_util_winid_str_get(cw->bd->client.win), cw);
3285              e_object_delfn_del(E_OBJECT(cw->bd), cw->dfn);
3286              cw->bd = NULL;
3287           }
3288         else if (cw->pop)
3289           {
3290              e_object_delfn_del(E_OBJECT(cw->pop), cw->dfn);
3291              cw->pop = NULL;
3292           }
3293         else if (cw->menu)
3294           {
3295              e_object_delfn_del(E_OBJECT(cw->menu), cw->dfn);
3296              cw->menu = NULL;
3297           }
3298         cw->dfn = NULL;
3299      }
3300    if (cw->pixmap)
3301      {
3302         if (cw->native)
3303           {
3304              cw->native = 0;
3305              evas_object_image_native_surface_set(cw->obj, NULL);
3306              EINA_LIST_FOREACH(cw->obj_mirror, l, o)
3307                {
3308                   evas_object_image_native_surface_set(o, NULL);
3309                }
3310           }
3311
3312         ecore_x_pixmap_free(cw->pixmap);
3313         cw->pixmap = 0;
3314         cw->pw = 0;
3315         cw->ph = 0;
3316         ecore_x_e_comp_pixmap_set(cw->win, cw->pixmap);
3317         _e_mod_comp_win_free_xim(cw);
3318      }
3319    if (cw->redirected)
3320      {
3321         cw->redirected = 0;
3322         cw->pw = 0;
3323         cw->ph = 0;
3324      }
3325    if (cw->update)
3326      {
3327         cw->update = 0;
3328         cw->c->updates = eina_list_remove(cw->c->updates, cw);
3329      }
3330    if (cw->obj_mirror)
3331      {
3332         Evas_Object *_o;
3333         EINA_LIST_FREE(cw->obj_mirror, _o)
3334           {
3335              if (!_o) continue;
3336              if (cw->xim) evas_object_image_data_set(_o, NULL);
3337              evas_object_del(_o);
3338           }
3339      }
3340    if (cw->xim)
3341      {
3342         evas_object_image_data_set(cw->obj, NULL);
3343         ecore_x_image_free(cw->xim);
3344         cw->xim = NULL;
3345      }
3346    if (cw->obj)
3347      {
3348         evas_object_del(cw->obj);
3349         cw->obj = NULL;
3350      }
3351    if (cw->shobj)
3352      {
3353         evas_object_del(cw->shobj);
3354         cw->shobj = NULL;
3355      }
3356    if (cw->inhash)
3357      eina_hash_del(windows, e_util_winid_str_get(cw->win), cw);
3358    if (cw->damage)
3359      {
3360         Ecore_X_Region parts;
3361
3362         eina_hash_del(damages, e_util_winid_str_get(cw->damage), cw);
3363         parts = ecore_x_region_new(NULL, 0);
3364         ecore_x_damage_subtract(cw->damage, 0, parts);
3365         ecore_x_region_free(parts);
3366         ecore_x_damage_free(cw->damage);
3367         cw->damage = 0;
3368      }
3369    if (cw->title) free(cw->title);
3370    if (cw->name) free(cw->name);
3371    if (cw->clas) free(cw->clas);
3372    if (cw->role) free(cw->role);
3373    cw->c->wins_invalid = 1;
3374    cw->c->wins = eina_inlist_remove(cw->c->wins, EINA_INLIST_GET(cw));
3375    pending_count = cw->pending_count;
3376    memset(cw, 0, sizeof(E_Comp_Win));
3377    cw->pending_count = pending_count;
3378    cw->delete_pending = 1;
3379    if (cw->pending_count > 0) return;
3380    free(cw);
3381 }
3382
3383 static void
3384 _e_mod_comp_win_show(E_Comp_Win *cw)
3385 {
3386    Eina_List *l;
3387    Evas_Object *o;
3388
3389    // if win_hide was showed then immediatly win_show() function is called. case.
3390    if (cw->defer_hide == 1) cw->defer_hide = 0;
3391    if (cw->visible) return;
3392    cw->visible = 1;
3393    _e_mod_comp_win_configure(cw,
3394                              cw->hidden.x, cw->hidden.y,
3395                              cw->w, cw->h,
3396                              cw->border);
3397    if ((cw->input_only) || (cw->invalid)) return;
3398
3399    if (cw->bd)
3400      _e_mod_comp_win_sync_setup(cw, cw->bd->client.win);
3401    else
3402      _e_mod_comp_win_sync_setup(cw, cw->win);
3403
3404    if (cw->real_hid)
3405      {
3406         cw->real_hid = 0;
3407         if (cw->native)
3408           {
3409              evas_object_image_native_surface_set(cw->obj, NULL);
3410              cw->native = 0;
3411              EINA_LIST_FOREACH(cw->obj_mirror, l, o)
3412                {
3413                   evas_object_image_native_surface_set(o, NULL);
3414                }
3415           }
3416         if (cw->pixmap)
3417           {
3418              ecore_x_pixmap_free(cw->pixmap);
3419              cw->pixmap = 0;
3420              cw->pw = 0;
3421              cw->ph = 0;
3422              ecore_x_e_comp_pixmap_set(cw->win, cw->pixmap);
3423           }
3424         if (cw->xim)
3425           {
3426              evas_object_image_size_set(cw->obj, 1, 1);
3427              evas_object_image_data_set(cw->obj, NULL);
3428              ecore_x_image_free(cw->xim);
3429              cw->xim = NULL;
3430              _e_mod_comp_win_free_xim(cw);
3431              EINA_LIST_FOREACH(cw->obj_mirror, l, o)
3432                {
3433                   evas_object_image_size_set(o, 1, 1);
3434                   evas_object_image_data_set(o, NULL);
3435                }
3436           }
3437         if (cw->redirected)
3438           {
3439              cw->redirected = 0;
3440              cw->pw = 0;
3441              cw->ph = 0;
3442           }
3443      }
3444
3445    if ((!cw->redirected) || (!cw->pixmap))
3446      {
3447         if (!cw->pixmap) cw->pixmap = ecore_x_composite_name_window_pixmap_get(cw->win);
3448         L(LT_EVENT_X,
3449           "[COMP]\t\tSHOW ecore_x_composite_name_window_pixmap_get() pixmap:0x%08x after redirect\n",
3450           cw->pixmap);
3451         if (cw->pixmap)
3452           ecore_x_pixmap_geometry_get(cw->pixmap, NULL, NULL, &(cw->pw), &(cw->ph));
3453         else
3454           {
3455              cw->pw = 0;
3456              cw->ph = 0;
3457           }
3458         if ((cw->pw <= 0) || (cw->ph <= 0))
3459           {
3460              if (cw->pixmap)
3461                {
3462                   ecore_x_pixmap_free(cw->pixmap);
3463                   cw->pixmap = 0;
3464                   cw->needpix = 1;
3465                   L(LT_EVENT_X,
3466                     "[COMP]\t\tSHOW free pixmap: 0x%08x invalid pixmap size.\n",
3467                     cw->pixmap);
3468                }
3469           }
3470         cw->redirected = 1;
3471
3472         e_mod_comp_update_resize(cw->up, cw->pw, cw->ph);
3473         e_mod_comp_update_add(cw->up, 0, 0, cw->pw, cw->ph);
3474
3475         evas_object_image_size_set(cw->obj, cw->pw, cw->ph);
3476         EINA_LIST_FOREACH(cw->obj_mirror, l, o)
3477           {
3478              evas_object_image_size_set(o, cw->pw, cw->ph);
3479           }
3480
3481         L(LT_EVENT_X,
3482           "[COMP]\t\tSHOW redirect win pixmap:0x%08x %3dx%3d\n",
3483           cw->pixmap, cw->pw, cw->ph);
3484
3485         ecore_x_e_comp_pixmap_set(cw->win, cw->pixmap);
3486      }
3487
3488    if (cw->dmg_updates >= 1)
3489      {
3490         if ((cw->c->gl) && (_comp_mod->conf->texture_from_pixmap))
3491           {
3492              if (!cw->pixmap)
3493                cw->pixmap = ecore_x_composite_name_window_pixmap_get(cw->win);
3494
3495              if (cw->pixmap)
3496                {
3497                   ecore_x_pixmap_geometry_get(cw->pixmap,
3498                                               NULL, NULL,
3499                                               &(cw->pw), &(cw->ph));
3500                }
3501              else
3502                {
3503                   cw->pw = 0;
3504                   cw->ph = 0;
3505                }
3506
3507              if ((cw->pw <= 0) || (cw->ph <= 0))
3508                {
3509                   if (cw->pixmap)
3510                   ecore_x_pixmap_free(cw->pixmap);
3511                   cw->pixmap = 0;
3512                   cw->needpix = 1;
3513                   L(LT_EVENT_X,
3514                     "[COMP]\t\tSHOW free pixmap: 0x%08x invalid pixmap size.\n",
3515                     cw->pixmap);
3516                }
3517              else
3518                {
3519                   ecore_x_e_comp_pixmap_set(cw->win, cw->pixmap);
3520                   evas_object_image_size_set(cw->obj, cw->pw, cw->ph);
3521                   EINA_LIST_FOREACH(cw->obj_mirror, l, o)
3522                     {
3523                        evas_object_image_size_set(o, cw->pw, cw->ph);
3524                     }
3525                   if (!cw->native)
3526                     {
3527                        Evas_Native_Surface ns;
3528                        ns.version = EVAS_NATIVE_SURFACE_VERSION;
3529                        ns.type = EVAS_NATIVE_SURFACE_X11;
3530                        ns.data.x11.visual = cw->vis;
3531                        ns.data.x11.pixmap = cw->pixmap;
3532                        evas_object_image_native_surface_set(cw->obj, &ns);
3533
3534                        EINA_LIST_FOREACH(cw->obj_mirror, l, o)
3535                          {
3536                             evas_object_image_native_surface_set(o, &ns);
3537                          }
3538
3539                        evas_object_image_data_update_add(cw->obj, 0, 0, cw->pw, cw->ph);
3540                        cw->native = 1;
3541                     }
3542                }
3543             }
3544
3545           if (cw->pixmap)
3546             {
3547                   cw->defer_hide = 0;
3548                   if (!cw->hidden_override)
3549                     {
3550                        if ( cw->defer_move_resize )
3551                          {
3552                             evas_object_move(cw->shobj, cw->x, cw->y );
3553                             evas_object_resize(cw->shobj, cw->pw + (cw->border * 2),
3554                                                           cw->ph + (cw->border * 2));
3555                             cw->defer_move_resize = EINA_FALSE;
3556                          }
3557                        evas_object_show(cw->shobj);
3558                     }
3559                   L(LT_EVENT_X,
3560                     "[COMP]\t\tSHOW evas_object_show()\n");
3561                   L(LT_EFFECT,
3562                     "[COMP] WIN_EFFECT : Show signal Emit -> win:0x%08x\n",
3563                     cw->win);
3564                   _e_mod_comp_window_show_effect(cw);
3565             }
3566      }
3567    _e_mod_comp_win_render_queue(cw);
3568 }
3569
3570 static void
3571 _e_mod_comp_win_unredirect(E_Comp_Win *cw)
3572 {
3573    if (!cw->visible) return;
3574    if ((cw->input_only) || (cw->invalid)) return;
3575
3576    if (cw->obj)
3577      {
3578         evas_object_hide(cw->obj);
3579         evas_object_del(cw->obj);
3580         cw->obj = NULL;
3581      }
3582    if (cw->update_timeout)
3583      {
3584         ecore_timer_del(cw->update_timeout);
3585         cw->update_timeout = NULL;
3586      }
3587    if (cw->native)
3588      {
3589         evas_object_image_native_surface_set(cw->obj, NULL);
3590         cw->native = 0;
3591      }
3592    if (cw->pixmap)
3593      {
3594         ecore_x_pixmap_free(cw->pixmap);
3595         cw->pixmap = 0;
3596         cw->pw = 0;
3597         cw->ph = 0;
3598      }
3599    if (cw->xim)
3600      {
3601         evas_object_image_size_set(cw->obj, 1, 1);
3602         evas_object_image_data_set(cw->obj, NULL);
3603         ecore_x_image_free(cw->xim);
3604         cw->xim = NULL;
3605      }
3606    if (cw->redirected)
3607      {
3608         ecore_x_composite_unredirect_window(cw->win, ECORE_X_COMPOSITE_UPDATE_MANUAL);
3609         cw->redirected = 0;
3610      }
3611    if (cw->damage)
3612      {
3613         _e_mod_comp_win_del_damage(cw, cw->damage);
3614         ecore_x_damage_subtract(cw->damage, 0, 0);
3615         ecore_x_damage_free(cw->damage);
3616         cw->damage = 0;
3617      }
3618 }
3619
3620 static void
3621 _e_mod_comp_win_real_hide(E_Comp_Win *cw)
3622 {
3623    if (cw->bd)
3624      {
3625         _e_mod_comp_win_hide(cw);
3626         return;
3627      }
3628    cw->real_hid = 1;
3629    _e_mod_comp_win_hide(cw);
3630 }
3631
3632 static void
3633 _e_mod_comp_win_hide(E_Comp_Win *cw)
3634 {
3635    Eina_List *l;
3636    Evas_Object *o;
3637
3638    if ((!cw->visible) && (!cw->defer_hide)) return;
3639    cw->visible = 0;
3640    if ((cw->input_only) || (cw->invalid)) return;
3641
3642    /* release window rotation stuffs */
3643    _e_mod_comp_win_rotation_release(cw);
3644
3645    if (cw->rotating)
3646      {
3647         if (!cw->force)
3648           {
3649              cw->defer_hide = 1;
3650              e_mod_comp_rotation_end_effect(cw->rotobj);
3651
3652              _e_mod_comp_win_inc_animating(cw);
3653
3654              cw->pending_count++;
3655
3656              L(LT_EVENT_X,
3657                "[COMP] %31s w:0x%08x hide rotobj. bd:%s force:%d defer_hide:%d\n",
3658                "PIX_ROT", _e_mod_comp_win_get_client_xid(cw),
3659                cw->bd ? "O" : "X", cw->force, cw->defer_hide);
3660              return;
3661           }
3662         else
3663           {
3664              cw->animating = 0;
3665              cw->defer_hide = 0;
3666              _e_mod_comp_rotation_release(cw);
3667           }
3668      }
3669
3670    if (cw->force == 0)
3671      {
3672         cw->defer_hide = 1;
3673         _e_mod_comp_window_hide_effect(cw);
3674         return;
3675      }
3676    cw->defer_hide = 0;
3677    cw->force = 0;
3678    evas_object_hide(cw->shobj);
3679
3680    Ecore_X_Window _w = _e_mod_comp_win_get_client_xid(cw);
3681    if (cw->update_timeout)
3682      {
3683         ecore_timer_del(cw->update_timeout);
3684         cw->update_timeout = NULL;
3685      }
3686    if (_comp_mod->conf->keep_unmapped)
3687      {
3688         if (_comp_mod->conf->send_flush) ecore_x_e_comp_flush_send(_w);
3689         if (_comp_mod->conf->send_dump) ecore_x_e_comp_dump_send(_w);
3690         return;
3691      }
3692
3693    if (cw->native)
3694      {
3695         evas_object_image_native_surface_set(cw->obj, NULL);
3696         cw->native = 0;
3697         EINA_LIST_FOREACH(cw->obj_mirror, l, o)
3698           {
3699              evas_object_image_native_surface_set(o, NULL);
3700           }
3701      }
3702    if (cw->pixmap)
3703      {
3704         ecore_x_pixmap_free(cw->pixmap);
3705         cw->pixmap = 0;
3706         cw->pw = 0;
3707         cw->ph = 0;
3708         ecore_x_e_comp_pixmap_set(cw->win, cw->pixmap);
3709      }
3710    if (cw->xim)
3711      {
3712         evas_object_image_size_set(cw->obj, 1, 1);
3713         evas_object_image_data_set(cw->obj, NULL);
3714         ecore_x_image_free(cw->xim);
3715         cw->xim = NULL;
3716         EINA_LIST_FOREACH(cw->obj_mirror, l, o)
3717           {
3718              evas_object_image_size_set(o, 1, 1);
3719              evas_object_image_data_set(o, NULL);
3720           }
3721      }
3722    if (cw->redirected)
3723      {
3724         cw->redirected = 0;
3725         cw->pw = 0;
3726         cw->ph = 0;
3727      }
3728    _e_mod_comp_win_render_queue(cw);
3729    if (_comp_mod->conf->send_flush) ecore_x_e_comp_flush_send(_w);
3730    if (_comp_mod->conf->send_dump) ecore_x_e_comp_dump_send(_w);
3731 }
3732
3733 static void
3734 _e_mod_comp_win_raise_above(E_Comp_Win *cw,
3735                             E_Comp_Win *cw2)
3736 {
3737    Eina_Bool show_stack_before = EINA_FALSE;
3738    Eina_Bool show_stack_after = EINA_FALSE;
3739    Eina_Bool real_show_stack_effect = EINA_TRUE;
3740
3741    E_Comp_Win *lower_background = NULL;
3742
3743    L(LT_EFFECT,
3744      "[COMP] WIN_EFFECT : Raise Above [0x%x] <- [0x%x]\n",
3745      _e_mod_comp_win_get_client_xid(cw),
3746      _e_mod_comp_win_get_client_xid(cw2));
3747
3748    if (cw->c->switcher)
3749      {
3750         int i = 0;
3751         Evas_Coord x, y, w, h;
3752         E_Comp_Win *find_cw;
3753         EINA_INLIST_REVERSE_FOREACH(cw->c->wins, find_cw)
3754           {
3755              if (find_cw->visible
3756                  && evas_object_visible_get(find_cw->shobj)
3757                  && evas_object_visible_get(find_cw->obj)
3758                  && (find_cw->win_type != WIN_INDICATOR)
3759                  && (find_cw->win_type != WIN_TASK_MANAGER))
3760                {
3761                   evas_object_geometry_get( find_cw->shobj, &x, &y, &w, &h );
3762                   if ( w == find_cw->c->screen_w && h == find_cw->c->screen_h )
3763                     {
3764                        i++;
3765                        if (find_cw == cw)
3766                          {
3767                             cw->c->selected_pos = i;
3768                             break;
3769                          }
3770                     }
3771                }
3772           }
3773      }
3774
3775    cw->c->wins_invalid = 1;
3776
3777    lower_background = _e_mod_comp_win_find_background_win(cw);
3778    //real show effect check 1
3779    show_stack_before = _e_mod_comp_is_next_win_stack(cw, cw2);
3780
3781    cw->c->wins = eina_inlist_remove(cw->c->wins,
3782                                     EINA_INLIST_GET(cw));
3783    cw->c->wins = eina_inlist_append_relative(cw->c->wins,
3784                                              EINA_INLIST_GET(cw),
3785                                              EINA_INLIST_GET(cw2));
3786    //real show effect check 2
3787    show_stack_after = _e_mod_comp_is_next_win_stack(cw, cw2);
3788
3789    if (show_stack_before == show_stack_after)
3790      real_show_stack_effect = EINA_FALSE;
3791
3792    // indicate slide up and down, save current position, size, color
3793    if ( ( _e_mod_comp_window_restack_policy(cw, cw2) == EINA_TRUE)
3794        && ( real_show_stack_effect == EINA_TRUE)
3795        && ( cw->first_show_worked == EINA_TRUE) )
3796      {
3797         _e_mod_comp_window_restack_effect(cw, cw2);
3798      }
3799    else if ( ( _e_mod_comp_window_restack_policy(cw, lower_background) == EINA_TRUE )
3800        && ( real_show_stack_effect == EINA_FALSE)
3801        && ( cw->show_done == EINA_TRUE)
3802        && ( _e_mod_comp_win_check_visible2(cw) == EINA_FALSE ) )
3803   //     && ( cw->ready_hide_effect == EINA_TRUE) )
3804      {
3805         _e_mod_comp_window_lower_effect(cw, lower_background);
3806      }
3807    else
3808      {
3809         evas_object_stack_above(cw->shobj, cw2->shobj);
3810
3811         // for no-effect window
3812         if ( (cw->visible == EINA_TRUE)
3813              && (cw->first_show_worked == EINA_TRUE ) )
3814           {
3815              edje_object_signal_emit(cw->shobj,
3816                                      "e,state,visible,on,noeffect",
3817                                      "e");
3818              L(LT_EFFECT,
3819                "[COMP] WIN_EFFECT : Raise above(for no-effect window) signal Emit -> win:0x%08x\n",
3820                cw->win);
3821              _e_mod_comp_win_inc_animating(cw);
3822           }
3823      }
3824
3825    _e_mod_comp_win_render_queue(cw);
3826    cw->pending_count++;
3827    e_manager_comp_event_src_config_send
3828       (cw->c->man, (E_Manager_Comp_Source *)cw,
3829        _e_mod_comp_cb_pending_after, cw->c);
3830 }
3831
3832 static void
3833 _e_mod_comp_win_raise(E_Comp_Win *cw)
3834 {
3835    cw->c->wins = eina_inlist_remove(cw->c->wins, EINA_INLIST_GET(cw));
3836    cw->c->wins = eina_inlist_append(cw->c->wins, EINA_INLIST_GET(cw));
3837
3838    evas_object_raise(cw->shobj);
3839    _e_mod_comp_win_render_queue(cw);
3840 }
3841
3842 static void
3843 _e_mod_comp_win_lower(E_Comp_Win *cw)
3844 {
3845    cw->c->wins_invalid = 1;
3846    cw->c->wins = eina_inlist_remove(cw->c->wins, EINA_INLIST_GET(cw));
3847    cw->c->wins = eina_inlist_prepend(cw->c->wins, EINA_INLIST_GET(cw));
3848
3849    evas_object_lower(cw->shobj);
3850    _e_mod_comp_win_render_queue(cw);
3851    cw->pending_count++;
3852    e_manager_comp_event_src_config_send
3853       (cw->c->man, (E_Manager_Comp_Source *)cw,
3854           _e_mod_comp_cb_pending_after, cw->c);
3855 }
3856
3857 static void
3858 _e_mod_comp_win_configure(E_Comp_Win *cw,
3859                           int x, int y,
3860                           int w, int h,
3861                           int border)
3862 {
3863    if (cw->rotating && cw->rotobj)
3864      {
3865         if (!((w == cw->w) && (h == cw->h)))
3866           {
3867              Ecore_X_Window win = _e_mod_comp_win_get_client_xid(cw);
3868
3869              L(LT_EVENT_X,
3870                "[COMP] %31s w:0x%08x bd:%s resize.\n",
3871                "PIX_ROT", win, cw->bd ? "O" : "X");
3872
3873              _e_mod_comp_win_recreate_shobj(cw);
3874              e_mod_comp_rotation_done_send(win, ATOM_CM_PIXMAP_ROTATION_RESIZE_PIXMAP);
3875
3876              L(LT_EVENT_X,
3877                "[COMP] %31s w:0x%08x send ROTATION_RESIZE_PIXMAP.\n",
3878                "PIX_ROT", win);
3879           }
3880      }
3881
3882    if (!((w == cw->w) && (h == cw->h)))
3883      {
3884         cw->w = w;
3885         cw->h = h;
3886         cw->needpix = 1;
3887         cw->dmg_updates = 0;
3888      }
3889
3890    if (!cw->visible)
3891      {
3892         cw->hidden.x = x;
3893         cw->hidden.y = y;
3894         cw->border = border;
3895      }
3896    else
3897      {
3898         if (!((x == cw->x) && (y == cw->y)))
3899           {
3900              cw->x = x;
3901              cw->y = y;
3902              if (!cw->needpix)
3903                evas_object_move(cw->shobj, cw->x, cw->y);
3904           }
3905         cw->hidden.x = x;
3906         cw->hidden.y = y;
3907      }
3908
3909    if (cw->border != border)
3910      {
3911         cw->border = border;
3912         evas_object_resize(cw->shobj,
3913                            cw->pw + (cw->border * 2),
3914                            cw->ph + (cw->border * 2));
3915      }
3916    cw->hidden.w = cw->w;
3917    cw->hidden.h = cw->h;
3918    if ((cw->input_only) || (cw->invalid) || (cw->needpix)) return;
3919    _e_mod_comp_win_render_queue(cw);
3920    cw->pending_count++;
3921    e_manager_comp_event_src_config_send
3922       (cw->c->man, (E_Manager_Comp_Source *)cw,
3923           _e_mod_comp_cb_pending_after, cw->c);
3924 }
3925
3926 static void
3927 _e_mod_comp_win_damage(E_Comp_Win *cw,
3928                        int x, int y,
3929                        int w, int h,
3930                        Eina_Bool dmg)
3931 {
3932    if ((cw->input_only) || (cw->invalid)) return;
3933    if ((dmg) && (cw->rotating))
3934      {
3935         e_mod_comp_rotation_damage(cw->rotobj);
3936         cw->dmg_updates++;
3937      }
3938    else if ((dmg) && (cw->damage))
3939      {
3940         Ecore_X_Region parts;
3941         parts = ecore_x_region_new(NULL, 0);
3942         ecore_x_damage_subtract(cw->damage, 0, parts);
3943         ecore_x_region_free(parts);
3944         cw->dmg_updates++;
3945      }
3946    e_mod_comp_update_add(cw->up, x, y, w, h);
3947    if (dmg)
3948      {
3949         if (cw->counter)
3950           {
3951              if (!cw->update_timeout)
3952                cw->update_timeout = ecore_timer_add
3953                    (ecore_animator_frametime_get() * 600,
3954                     _e_mod_comp_win_damage_timeout, cw);
3955              return;
3956           }
3957      }
3958
3959    /* to fix noise window appearing when non-EFL's window is showing,
3960     * add a check code that checks and skips first damage.
3961     * first damage is generated by the X server when copying image of the
3962     * root window. - gl77.lee 110208
3963     */
3964    if ((dmg)
3965        && !(cw->rotating)
3966        && (cw->dmg_updates <= 1))
3967      {
3968         if (!(cw->needpix))
3969           {
3970              L(LT_EVENT_X,
3971                "[COMP] %31s w:0x%08x bd:%s skip first damage.\n",
3972                "X_DAMAGE", _e_mod_comp_win_get_client_xid(cw),
3973                cw->bd ? "O" : "X");
3974              return;
3975           }
3976      }
3977
3978    if (!cw->update)
3979      {
3980         cw->update = 1;
3981         cw->c->updates = eina_list_append(cw->c->updates, cw);
3982      }
3983    _e_mod_comp_win_render_queue(cw);
3984 }
3985
3986 static void
3987 _e_mod_comp_win_reshape(E_Comp_Win *cw)
3988 {
3989    if (cw->shape_changed) return;
3990    cw->shape_changed = 1;
3991    if (!cw->update)
3992      {
3993         cw->update = 1;
3994         cw->c->updates = eina_list_append(cw->c->updates, cw);
3995      }
3996    e_mod_comp_update_add(cw->up, 0, 0, cw->w, cw->h);
3997    _e_mod_comp_win_render_queue(cw);
3998 }
3999
4000 static Eina_Bool
4001 _e_mod_comp_create(void *data __UNUSED__,
4002                    int type __UNUSED__,
4003                    void *event)
4004 {
4005    Ecore_X_Event_Window_Create *ev = event;
4006    E_Comp_Win *cw;
4007    E_Comp *c = _e_mod_comp_find(ev->parent);
4008    if (!c) return ECORE_CALLBACK_PASS_ON;
4009    if (_e_mod_comp_win_find(ev->win)) return ECORE_CALLBACK_PASS_ON;
4010    if (c->win == ev->win) return ECORE_CALLBACK_PASS_ON;
4011    if (c->ee_win == ev->win) return ECORE_CALLBACK_PASS_ON;
4012    L(LT_EVENT_X,
4013      "[COMP] ev:%15.15s w:0x%08x\n",
4014      "X_CREATE", ev->win);
4015    cw = _e_mod_comp_win_add(c, ev->win);
4016    if (cw)
4017      _e_mod_comp_win_configure(cw,
4018                                ev->x, ev->y,
4019                                ev->w, ev->h,
4020                                ev->border);
4021    return ECORE_CALLBACK_PASS_ON;
4022 }
4023
4024 static Eina_Bool
4025 _e_mod_comp_destroy(void *data __UNUSED__,
4026                     int type __UNUSED__,
4027                     void *event)
4028 {
4029    Ecore_X_Event_Window_Destroy *ev = event;
4030    E_Comp_Win *cw = _e_mod_comp_win_find(ev->win);
4031    if (!cw) return ECORE_CALLBACK_PASS_ON;
4032    if (_e_mod_comp_win_is_border(cw)) return ECORE_CALLBACK_PASS_ON;
4033    L(LT_EVENT_X,
4034      "[COMP] ev:%15.15s w:0x%08x bd:%d c:0x%08x cw:%p\n",
4035      "X_DESTROY", ev->win, _e_mod_comp_win_is_border(cw),
4036      _e_mod_comp_win_get_client_xid(cw), cw);
4037    if (cw->animating) cw->delete_me = 1;
4038    else _e_mod_comp_win_del(cw);
4039    return ECORE_CALLBACK_PASS_ON;
4040 }
4041
4042 static Eina_Bool
4043 _e_mod_comp_show(void *data __UNUSED__,
4044                  int type __UNUSED__,
4045                  void *event)
4046 {
4047    Ecore_X_Event_Window_Show *ev = event;
4048    E_Comp_Win *cw = _e_mod_comp_win_find(ev->win);
4049    if (!cw) return ECORE_CALLBACK_PASS_ON;
4050    if (cw->visible) return ECORE_CALLBACK_PASS_ON;
4051    if (_e_mod_comp_win_is_border(cw)) return ECORE_CALLBACK_PASS_ON;
4052    L(LT_EVENT_X,
4053      "[COMP] ev:%15.15s w:0x%08x bd:%d c:0x%08x cw:%p\n",
4054      "X_SHOW", ev->win, _e_mod_comp_win_is_border(cw),
4055      _e_mod_comp_win_get_client_xid(cw), cw);
4056    _e_mod_comp_win_show(cw);
4057    return ECORE_CALLBACK_PASS_ON;
4058 }
4059
4060 static Eina_Bool
4061 _e_mod_comp_hide(void *data __UNUSED__,
4062                  int type __UNUSED__,
4063                  void *event)
4064 {
4065    Ecore_X_Event_Window_Hide *ev = event;
4066    E_Comp_Win *cw = _e_mod_comp_win_find(ev->win);
4067    if (!cw) return ECORE_CALLBACK_PASS_ON;
4068    if (!cw->visible) return ECORE_CALLBACK_PASS_ON;
4069    if (_e_mod_comp_win_is_border(cw)) return ECORE_CALLBACK_PASS_ON;
4070    L(LT_EVENT_X,
4071      "[COMP] ev:%15.15s w:0x%08x bd:%d c:0x%08x cw:%p\n",
4072      "X_HIDE", ev->win, _e_mod_comp_win_is_border(cw),
4073      _e_mod_comp_win_get_client_xid(cw), cw);
4074    _e_mod_comp_win_real_hide(cw);
4075    return ECORE_CALLBACK_PASS_ON;
4076 }
4077
4078 static Eina_Bool
4079 _e_mod_comp_reparent(void *data __UNUSED__,
4080                      int type __UNUSED__,
4081                      void *event)
4082 {
4083    Ecore_X_Event_Window_Reparent *ev = event;
4084    E_Comp_Win *cw = _e_mod_comp_win_find(ev->win);
4085    if (!cw) return ECORE_CALLBACK_PASS_ON;
4086    L(LT_EVENT_X,
4087      "[COMP] ev:%15.15s w:0x%08x bd:%d c:0x%08x cw:%p TO rw:0x%08x\n",
4088      "X_REPARENT", ev->win, _e_mod_comp_win_is_border(cw),
4089      _e_mod_comp_win_get_client_xid(cw), cw, ev->parent);
4090    if (ev->parent != cw->c->man->root)
4091      {
4092         L(LT_EVENT_X, "[COMP] %31s w:0x%08x\n", "DEL", ev->win);
4093         _e_mod_comp_win_del(cw);
4094      }
4095
4096    return ECORE_CALLBACK_PASS_ON;
4097 }
4098
4099 static Eina_Bool
4100 _e_mod_comp_configure(void *data __UNUSED__,
4101                       int type __UNUSED__,
4102                       void *event)
4103 {
4104    Ecore_X_Event_Window_Configure *ev = event;
4105    E_Comp_Win *cw = _e_mod_comp_win_find(ev->win);
4106    if (!cw) return ECORE_CALLBACK_PASS_ON;
4107    L(LT_EVENT_X,
4108      "[COMP] ev:%15.15s w:0x%08x bd:%d c:0x%08x cw:%p %4d %4d %3dx%3d\n",
4109      "X_CONFIGURE", ev->win, _e_mod_comp_win_is_border(cw),
4110      _e_mod_comp_win_get_client_xid(cw), cw, ev->x, ev->y, ev->w, ev->h);
4111    if (ev->abovewin == 0)
4112      {
4113         if (EINA_INLIST_GET(cw)->prev)
4114           {
4115              L(LT_EVENT_X,
4116                "[COMP] %31s w:0x%08x\n",
4117                "LOWER", ev->win);
4118
4119              _e_mod_comp_win_lower(cw);
4120           }
4121      }
4122    else
4123      {
4124         E_Comp_Win *cw2 = _e_mod_comp_win_find(ev->abovewin);
4125         if (cw2)
4126           {
4127              E_Comp_Win *cw3 = (E_Comp_Win *)(EINA_INLIST_GET(cw)->prev);
4128              if (cw3 != cw2)
4129                {
4130                   L(LT_EVENT_X,
4131                     "[COMP] %31s above_w:0x%08x\n",
4132                     "RAISE_ABOVE", ev->abovewin);
4133
4134                   _e_mod_comp_win_raise_above(cw, cw2);
4135                }
4136           }
4137      }
4138
4139   if (!((cw->x == ev->x) && (cw->y == ev->y)) &&
4140       ((cw->w == ev->w) && (cw->h == ev->h)) &&
4141       _e_mod_comp_win_is_border(cw))
4142     {
4143        return ECORE_CALLBACK_PASS_ON;
4144     }
4145
4146    if (!((cw->x == ev->x) && (cw->y == ev->y) &&
4147          (cw->w == ev->w) && (cw->h == ev->h) &&
4148          (cw->border == ev->border)))
4149      {
4150         _e_mod_comp_win_configure(cw,
4151                                   ev->x, ev->y,
4152                                   ev->w, ev->h,
4153                                   ev->border);
4154      }
4155    return ECORE_CALLBACK_PASS_ON;
4156 }
4157
4158 static Eina_Bool
4159 _e_mod_comp_stack(void *data __UNUSED__,
4160                   int type __UNUSED__,
4161                   void *event)
4162 {
4163    Ecore_X_Event_Window_Stack *ev = event;
4164    E_Comp_Win *cw = _e_mod_comp_win_find(ev->win);
4165    L(LT_EVENT_X,
4166      "[COMP] ev:%15.15s w:0x%08x bd:%d c:0x%08x cw:%p\n",
4167      "X_STACK", ev->win, _e_mod_comp_win_is_border(cw), _e_mod_comp_win_get_client_xid(cw), cw);
4168    if (!cw) return ECORE_CALLBACK_PASS_ON;
4169    if (ev->detail == ECORE_X_WINDOW_STACK_ABOVE) _e_mod_comp_win_raise(cw);
4170    else _e_mod_comp_win_lower(cw);
4171    return ECORE_CALLBACK_PASS_ON;
4172 }
4173
4174 static Eina_Bool
4175 _e_mod_comp_prop_effect_state(Ecore_X_Event_Window_Property *ev __UNUSED__)
4176 {
4177    E_Comp *c;
4178    unsigned int val = 0;
4179    int ret = -1;
4180
4181    c = _e_mod_comp_get();
4182    if (!c)
4183      {
4184         fprintf(stderr,
4185                 "[E17-comp] _e_mod_comp_prop_effect_state failed.\n");
4186         return EINA_FALSE;
4187      }
4188
4189    ret = ecore_x_window_prop_card32_get(c->man->root,
4190                                         ATOM_EFFECT_ENABLE,
4191                                         &val, 1);
4192    if (ret == -1) return EINA_FALSE;
4193
4194    L(LT_EVENT_X,
4195      "[COMP] %31s propval:%d\n",
4196      "PROP_COMP_EFFECT_STATE", val);
4197
4198    if (val != 0)
4199      {
4200         c->animatable = EINA_TRUE;
4201         _comp_mod->conf->default_window_effect = 1;
4202         e_config_domain_save("module.comp-slp",
4203                              _comp_mod->conf_edd,
4204                              _comp_mod->conf);
4205      }
4206    else
4207      {
4208         c->animatable = EINA_FALSE;
4209         _comp_mod->conf->default_window_effect = 0;
4210         e_config_domain_save("module.comp-slp",
4211                              _comp_mod->conf_edd,
4212                              _comp_mod->conf);
4213      }
4214
4215    L(LT_EVENT_X,
4216      "[COMP] %31s c->animatable:%d\n",
4217      "ATOM_WINDOW_EFFECT_ENABLE",
4218      c->animatable);
4219
4220    return EINA_TRUE;
4221 }
4222
4223 static Eina_Bool
4224 _e_mod_comp_prop_window_effect_state(Ecore_X_Event_Window_Property *ev)
4225 {
4226    E_Comp_Win *cw = NULL;
4227    unsigned int val = 0;
4228    int ret = -1;
4229
4230    ret = ecore_x_window_prop_card32_get(ev->win,
4231                                         ATOM_WINDOW_EFFECT_ENABLE,
4232                                         &val,
4233                                         1);
4234    if (ret == -1) return EINA_FALSE;
4235
4236    L(LT_EVENT_X,
4237      "[COMP] %31s propval:%d\n",
4238      "PROP_COMP_EFFECT_STATE", val);
4239
4240    cw = _e_mod_comp_win_find(ev->win);
4241    if (cw) cw->animatable = val;
4242    else
4243      {
4244         cw = _e_mod_comp_border_client_find(ev->win);
4245         if (!cw) return EINA_FALSE;
4246         cw->animatable = val;
4247      }
4248
4249    L(LT_EVENT_X,
4250      "[COMP] %31s cw->animatable:%d\n",
4251      "ATOM_WINDOW_EFFECT_ENABLE",
4252      cw->animatable);
4253
4254    return EINA_TRUE;
4255 }
4256
4257 static Eina_Bool
4258 _e_mod_comp_prop_effect_style(Ecore_X_Event_Window_Property *ev)
4259 {
4260    E_Comp_Win *cw = NULL;
4261    Ecore_X_Atom *atoms = NULL;
4262    int num = 0;
4263
4264    num = ecore_x_window_prop_atom_list_get(ev->win,
4265                                            ATOM_WINDOW_EFFECT_TYPE,
4266                                            &atoms);
4267
4268    if (num != 6)
4269      {
4270         if (num > 0) free(atoms);
4271         return EINA_FALSE;
4272      }
4273
4274    L(LT_EVENT_X,
4275      "[COMP] %31s \n",
4276      "PROP_COMP_EFFECT_STYLE");
4277
4278    cw = _e_mod_comp_win_find(ev->win);
4279    if (cw)
4280      {
4281         cw->show_effect     = _e_mod_comp_get_effect_type(&atoms[0]);
4282         cw->hide_effect     = _e_mod_comp_get_effect_type(&atoms[1]);
4283         cw->restack_effect  = _e_mod_comp_get_effect_type(&atoms[2]);
4284         cw->rotation_effect = _e_mod_comp_get_effect_type(&atoms[3]);
4285         cw->focusin_effect  = _e_mod_comp_get_effect_type(&atoms[4]);
4286         cw->focusout_effect = _e_mod_comp_get_effect_type(&atoms[5]);
4287      }
4288    else
4289      {
4290         cw = _e_mod_comp_border_client_find(ev->win);
4291         if (!cw)
4292           {
4293              if (num > 0) free(atoms);
4294              return EINA_FALSE;
4295           }
4296         cw->show_effect     = _e_mod_comp_get_effect_type(&atoms[0]);
4297         cw->hide_effect     = _e_mod_comp_get_effect_type(&atoms[1]);
4298         cw->restack_effect  = _e_mod_comp_get_effect_type(&atoms[2]);
4299         cw->rotation_effect = _e_mod_comp_get_effect_type(&atoms[3]);
4300         cw->focusin_effect  = _e_mod_comp_get_effect_type(&atoms[4]);
4301         cw->focusout_effect = _e_mod_comp_get_effect_type(&atoms[5]);
4302      }
4303
4304    if (num > 0) free(atoms);
4305
4306    return EINA_TRUE;
4307 }
4308
4309
4310 #if COMP_LOGGER_BUILD_ENABLE
4311 static Eina_Bool
4312 _e_mod_comp_prop_log(Ecore_X_Event_Window_Property *ev)
4313 {
4314    int ret = -1;
4315    int count;
4316    unsigned char* prop_data = NULL;
4317    Comp_Logger comp_log_info;
4318
4319    comp_log_info.logger_type = 0;
4320    memset(comp_log_info.logger_dump_file, '\0', 256 * sizeof(char) );
4321
4322    ret = ecore_x_window_prop_property_get(ev->win,
4323                                           ATOM_CM_LOG,
4324                                           ECORE_X_ATOM_CARDINAL,
4325                                           32,
4326                                           &prop_data,
4327                                           &count);
4328    if (ret == -1)
4329      {
4330         if (prop_data) free(prop_data);
4331         return EINA_FALSE;
4332      }
4333    if ((ret > 0) && prop_data)
4334      {
4335         fprintf(stdout,
4336                 "[E17-comp] %s(%d) comp_logger_type: ",
4337                 __func__, __LINE__);
4338
4339         if      (comp_logger_type == LT_NOTHING) fprintf(stdout, "LT_NOTHING ");
4340         else if (comp_logger_type == LT_ALL    ) fprintf(stdout, "LT_ALL "    );
4341         else                                     fprintf(stdout, "%d ", comp_logger_type);
4342
4343         fprintf(stdout, "-> ");
4344
4345         memcpy(&comp_log_info, prop_data, sizeof(Comp_Logger) );
4346         comp_logger_type = comp_log_info.logger_type;
4347
4348         if      (comp_logger_type == LT_NOTHING ) fprintf(stdout, "LT_NOTHING\n");
4349         else if (comp_logger_type == LT_ALL     ) fprintf(stdout, "LT_ALL\n"    );
4350         else                                      fprintf(stdout, "%d\n", comp_logger_type);
4351
4352         if (comp_logger_type == LT_CREATE)
4353           {
4354             _e_mod_comp_dump_cw_stack(EINA_FALSE, NULL);
4355             _e_mod_comp_fps_toggle();
4356           }
4357         if ( ( comp_logger_type == LT_DUMP )
4358              && ( strlen(comp_log_info.logger_dump_file) > 0 ) )
4359           {
4360             _e_mod_comp_dump_cw_stack(EINA_TRUE, comp_log_info.logger_dump_file);
4361
4362             ecore_x_client_message32_send (ecore_x_window_root_first_get(),
4363                                            ATOM_CM_LOG_DUMP_DONE,
4364                                            ECORE_X_EVENT_MASK_WINDOW_CONFIGURE,
4365                                            0, 0, 0, 0, 0);
4366           }
4367         if(prop_data) free(prop_data);
4368         return EINA_TRUE;
4369      }
4370    return EINA_FALSE;
4371 }
4372 #endif /* COMP_LOGGER_BUILD_ENABLE */
4373
4374 static Eina_Bool
4375 _e_mod_comp_prop_opacity(Ecore_X_Event_Window_Property *ev)
4376 {
4377    E_Comp_Win *cw = NULL;
4378    unsigned int val = 0;
4379    int ret = -1;
4380
4381    cw = _e_mod_comp_win_find(ev->win);
4382    if (!cw)
4383      {
4384         cw = _e_mod_comp_border_client_find(ev->win);
4385         if (!cw) return EINA_FALSE;
4386      }
4387
4388    ret = ecore_x_window_prop_card32_get(cw->win,
4389                                         ECORE_X_ATOM_NET_WM_WINDOW_OPACITY,
4390                                         &val, 1);
4391    if (ret == -1) return EINA_FALSE;
4392
4393    cw->use_opacity = EINA_TRUE;
4394    cw->opacity = (val >> 24);
4395    evas_object_color_set(cw->shobj,
4396                          cw->opacity,
4397                          cw->opacity,
4398                          cw->opacity,
4399                          cw->opacity);
4400    return EINA_TRUE;
4401
4402 }
4403
4404 static Eina_Bool
4405 _e_mod_comp_prop_sync_counter(Ecore_X_Event_Window_Property *ev)
4406 {
4407    E_Comp_Win *cw = NULL;
4408    cw = _e_mod_comp_win_find(ev->win);
4409    if (!cw) cw = _e_mod_comp_border_client_find(ev->win);
4410
4411    Ecore_X_Sync_Counter counter = ecore_x_e_comp_sync_counter_get(ev->win);
4412    if (cw)
4413      {
4414         if (cw->counter != counter)
4415           {
4416              Ecore_X_Window _w = _e_mod_comp_win_get_client_xid(cw);
4417              if (cw->counter)
4418                {
4419                   ecore_x_e_comp_sync_cancel_send(_w);
4420                   ecore_x_sync_counter_inc(cw->counter, 1);
4421                }
4422              cw->counter = counter;
4423              if (cw->counter)
4424                {
4425                   ecore_x_sync_counter_inc(cw->counter, 1);
4426                   ecore_x_e_comp_sync_begin_send(_w);
4427                }
4428           }
4429      }
4430    else
4431      {
4432         if (counter) ecore_x_sync_counter_inc(counter, 1);
4433      }
4434    return EINA_TRUE;
4435 }
4436
4437 static Eina_Bool
4438 _e_mod_comp_property(void *data __UNUSED__,
4439                      int type __UNUSED__,
4440                      void *event __UNUSED__)
4441 {
4442    Ecore_X_Event_Window_Property *ev = event;
4443    Ecore_X_Atom a = 0;
4444    if (!ev) return ECORE_CALLBACK_PASS_ON;
4445    if (!ev->atom) return ECORE_CALLBACK_PASS_ON;
4446    if (!_e_mod_comp_get_atom_name(ev->atom)) return ECORE_CALLBACK_PASS_ON;
4447    a = ev->atom;
4448
4449    L(LT_EVENT_X,
4450      "[COMP] ev:%15.15s w:0x%08x atom:%s\n",
4451      "X_PROPERTY", ev->win,
4452      _e_mod_comp_get_atom_name(a));
4453
4454    if      (a == ECORE_X_ATOM_E_COMP_SYNC_COUNTER         ) _e_mod_comp_prop_sync_counter(ev);
4455    else if (a == ATOM_EFFECT_ENABLE                       ) _e_mod_comp_prop_effect_state(ev);
4456    else if (a == ATOM_WINDOW_EFFECT_ENABLE                ) _e_mod_comp_prop_window_effect_state(ev);
4457    else if (a == ATOM_WINDOW_EFFECT_TYPE                  ) _e_mod_comp_prop_effect_style(ev);
4458    else if (a == ECORE_X_ATOM_NET_WM_WINDOW_OPACITY       ) _e_mod_comp_prop_opacity(ev);
4459    else if (a == ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE) _e_mod_comp_prop_window_rotation(ev);
4460 #if COMP_LOGGER_BUILD_ENABLE
4461    else if (a == ATOM_CM_LOG                              ) _e_mod_comp_prop_log(ev);
4462 #endif /* COMP_LOGGER_BUILD_ENABLE */
4463
4464    return ECORE_CALLBACK_PASS_ON;
4465 }
4466
4467 static Eina_Bool
4468 _e_mod_comp_msg_sync_draw_done(Ecore_X_Event_Client_Message *ev)
4469 {
4470    E_Comp_Win *cw = NULL;
4471    int v = 0, w = 0, h = 0;
4472    cw = _e_mod_comp_border_client_find(ev->data.l[0]);
4473    v = ev->data.l[1];
4474    w = ev->data.l[2];
4475    h = ev->data.l[3];
4476    if (cw)
4477      {
4478         if (!cw->bd) return EINA_FALSE;
4479         if ((Ecore_X_Window)(ev->data.l[0]) != cw->bd->client.win) return EINA_FALSE;
4480      }
4481    else
4482      {
4483         cw = _e_mod_comp_win_find(ev->data.l[0]);
4484         if (!cw || (ev->data.l[0] != (int)cw->win))
4485           {
4486              Ecore_X_Sync_Counter counter = ecore_x_e_comp_sync_counter_get(ev->win);
4487              ecore_x_e_comp_sync_cancel_send(ev->win);
4488              if (counter) ecore_x_sync_counter_inc(counter, 1);
4489              L(LT_EVENT_X,
4490                "[COMP] ev:%15.15s w:0x%08x type:%s !cw v%d %03dx%03d\n",
4491                "X_CLIENT_MSG", ev->win, "SYNC_DRAW_DONE", v, w, h);
4492              return EINA_FALSE;
4493           }
4494      }
4495    if (!cw->counter)
4496      {
4497         cw->counter = ecore_x_e_comp_sync_counter_get(_e_mod_comp_win_get_client_xid(cw));
4498         if (cw->counter)
4499           {
4500              ecore_x_sync_counter_inc(cw->counter, 1);
4501              ecore_x_e_comp_sync_begin_send(_e_mod_comp_win_get_client_xid(cw));
4502           }
4503         L(LT_EVENT_X,
4504           "[COMP] ev:%15.15s w:0x%08x type:%s !cw->counter v%d %03dx%03d\n",
4505           "X_CLIENT_MSG", _e_mod_comp_win_get_client_xid(cw),
4506           "SYNC_DRAW_DONE", v, w, h);
4507         return EINA_FALSE;
4508      }
4509
4510    if (!cw->update)
4511      {
4512         if (cw->update_timeout)
4513           {
4514              ecore_timer_del(cw->update_timeout);
4515              cw->update_timeout = NULL;
4516           }
4517         cw->update = 1;
4518         cw->c->updates = eina_list_append(cw->c->updates, cw);
4519      }
4520    cw->drawme = 1;
4521
4522    L(LT_EVENT_X,
4523      "[COMP] ev:%15.15s w:0x%08x type:%s v%d %03dx%03d\n",
4524      "X_CLIENT_MSG", _e_mod_comp_win_get_client_xid(cw),
4525      "SYNC_DRAW_DONE", v, w, h);
4526
4527    _e_mod_comp_win_render_queue(cw);
4528    return EINA_TRUE;
4529 }
4530
4531 Eina_Bool
4532 _e_mod_comp_hib_leave(void)
4533 {
4534    E_Comp *c = _e_mod_comp_get();
4535    Config *cfg = NULL;
4536
4537    if (!c || !_comp_mod)
4538      {
4539         fprintf(stderr,
4540                 "[E17-comp] _e_mod_comp_hib_leave failed.\n");
4541         return ECORE_CALLBACK_PASS_ON;
4542      }
4543
4544    cfg = e_config_domain_load("module.comp-slp",
4545                               _comp_mod->conf_edd);
4546    if (!cfg)
4547      return ECORE_CALLBACK_PASS_ON;
4548
4549    if (cfg->default_window_effect != c->animatable)
4550      {
4551         if (cfg->default_window_effect)
4552           {
4553              c->animatable = EINA_TRUE;
4554              _comp_mod->conf->default_window_effect = 1;
4555           }
4556         else
4557           {
4558              c->animatable = EINA_FALSE;
4559              _comp_mod->conf->default_window_effect = 0;
4560           }
4561         ecore_x_window_prop_card32_set
4562            (c->man->root, ATOM_EFFECT_ENABLE,
4563            (unsigned int *)(&(_comp_mod->conf->default_window_effect)), 1);
4564      }
4565
4566    if (cfg->shadow_file)
4567      eina_stringshare_del(cfg->shadow_file);
4568    if (cfg->shadow_style)
4569      eina_stringshare_del(cfg->shadow_style);
4570
4571    free(cfg);
4572    return ECORE_CALLBACK_PASS_ON;
4573 }
4574
4575 static Eina_Bool
4576 _e_mod_comp_message(void *data __UNUSED__,
4577                     int type __UNUSED__,
4578                     void *event)
4579 {
4580    Ecore_X_Event_Client_Message *ev = event;
4581
4582    if (ev->format != 32)
4583      return ECORE_CALLBACK_PASS_ON;
4584
4585    if (ev->message_type == ECORE_X_ATOM_E_COMP_SYNC_DRAW_DONE)
4586      {
4587         _e_mod_comp_msg_sync_draw_done(ev);
4588         return ECORE_CALLBACK_PASS_ON;
4589      }
4590
4591    if (_e_mod_comp_rotation_handle_message(ev))
4592      {
4593         return ECORE_CALLBACK_PASS_ON;
4594      }
4595
4596    if (_comp_mod->conf->use_lock_screen)
4597      {
4598         if (ev->message_type == ATOM_CM_LOCK_SCREEN)
4599           {
4600              E_Comp *c = _e_mod_comp_find(ev->win);
4601              if (!c)
4602                return ECORE_CALLBACK_PASS_ON;
4603              if (ev->data.l[0] == 1)
4604                _e_mod_comp_screen_lock(c);
4605              else if (ev->data.l[0] == 0)
4606                _e_mod_comp_screen_unlock(c);
4607              return ECORE_CALLBACK_PASS_ON;
4608           }
4609      }
4610
4611    if ((ev->message_type == ATOM_FAKE_LAUNCH)
4612        && (ev->data.l[0] == 1))
4613      {
4614         return _e_mod_comp_fake_show(ev);
4615      }
4616
4617    if ((ev->message_type == ATOM_FAKE_LAUNCH)
4618        && (ev->data.l[0] == 0))
4619      {
4620         return _e_mod_comp_fake_hide(ev);
4621      }
4622
4623    if ((ev->message_type == ATOM_X_HIBERNATION_STATE)
4624        && (ev->data.l[0] == 0))
4625      {
4626         return _e_mod_comp_hib_leave();
4627      }
4628
4629    if (ev->message_type == ATOM_CAPTURE_EFFECT)
4630      {
4631         return _e_mod_comp_capture_effect(ev);
4632      }
4633
4634    return ECORE_CALLBACK_PASS_ON;
4635 }
4636
4637 static Eina_Bool
4638 _e_mod_comp_shape(void *data __UNUSED__,
4639                   int type __UNUSED__,
4640                   void *event)
4641 {
4642    Ecore_X_Event_Window_Shape *ev = event;
4643    E_Comp_Win *cw = _e_mod_comp_win_find(ev->win);
4644    if (!cw) return ECORE_CALLBACK_PASS_ON;
4645    if (ev->type != ECORE_X_SHAPE_BOUNDING) return ECORE_CALLBACK_PASS_ON;
4646    L(LT_EVENT_X,
4647      "[COMP] ev:%15.15s w:0x%08x bd:%d c:0x%08x cw:%p\n",
4648      "X_SHAPE", ev->win, _e_mod_comp_win_is_border(cw), _e_mod_comp_win_get_client_xid(cw), cw);
4649    _e_mod_comp_win_reshape(cw);
4650    return ECORE_CALLBACK_PASS_ON;
4651 }
4652
4653 static Eina_Bool
4654 _e_mod_comp_damage(void *data __UNUSED__,
4655                    int type __UNUSED__,
4656                    void *event)
4657 {
4658    Ecore_X_Event_Damage *ev = event;
4659    E_Comp_Win *cw = _e_mod_comp_win_damage_find(ev->damage);
4660
4661    L(LT_EVENT_X,
4662      "[COMP] ev:%15.15s w:0x%08x bd:%d c:0x%08x cw:%p %4d %4d %3dx%3d\n",
4663      "X_DAMAGE", ev->drawable, _e_mod_comp_win_is_border(cw),
4664      _e_mod_comp_win_get_client_xid(cw), cw,
4665      ev->area.x, ev->area.y, ev->area.width, ev->area.height);
4666
4667    if (!cw)
4668      {
4669         L(LT_EVENT_X,
4670           "[COMP] ev:%15.15s w:0x%08x bd:%d c:0x%08x cw:%p %4d %4d %3dx%3d ERR1\n",
4671           "X_DAMAGE", ev->drawable, _e_mod_comp_win_is_border(cw),
4672           _e_mod_comp_win_get_client_xid(cw), cw,
4673           ev->area.x, ev->area.y, ev->area.width, ev->area.height);
4674
4675         cw = _e_mod_comp_border_client_find(ev->drawable);
4676
4677         if (!cw)
4678           {
4679              L(LT_EVENT_X,"[COMP] ev:%15.15s w:0x%08x bd:%d c:0x%08x cw:%p %4d %4d %3dx%3d ERR2\n",
4680                "X_DAMAGE", ev->drawable, _e_mod_comp_win_is_border(cw),
4681                _e_mod_comp_win_get_client_xid(cw), cw,
4682                ev->area.x, ev->area.y, ev->area.width, ev->area.height);
4683              return ECORE_CALLBACK_PASS_ON;
4684           }
4685      }
4686
4687    _e_mod_comp_win_damage(cw,
4688                           ev->area.x, ev->area.y,
4689                           ev->area.width, ev->area.height, 1);
4690    return ECORE_CALLBACK_PASS_ON;
4691 }
4692
4693 static Eina_Bool
4694 _e_mod_comp_damage_win(void *data __UNUSED__,
4695                        int type __UNUSED__,
4696                        void *event)
4697 {
4698    Ecore_X_Event_Window_Damage *ev = event;
4699    Eina_List *l;
4700    E_Comp *c;
4701
4702    // fixme: use hash if compositors list > 4
4703    EINA_LIST_FOREACH(compositors, l, c)
4704      {
4705         if (!c) continue;
4706         if (ev->win == c->ee_win)
4707           {
4708              // expose on comp win - init win or some other bypass win did it
4709              _e_mod_comp_render_queue(c);
4710              break;
4711           }
4712      }
4713    return ECORE_CALLBACK_PASS_ON;
4714 }
4715
4716 static Eina_Bool
4717 _e_mod_comp_randr(void *data __UNUSED__,
4718                   int type __UNUSED__,
4719                   __UNUSED__ void *event)
4720 {
4721    Eina_List *l;
4722    E_Comp *c;
4723
4724    L(LT_EVENT_X,
4725      "[COMP] ev:%15.15s\n",
4726      "E_CONTNR_RESIZE");
4727
4728    EINA_LIST_FOREACH(compositors, l, c)
4729      {
4730         if (!c) continue;
4731         ecore_evas_resize(c->ee,
4732                           c->man->w,
4733                           c->man->h);
4734      }
4735    return ECORE_CALLBACK_PASS_ON;
4736 }
4737
4738 static Eina_Bool
4739 _e_mod_comp_bd_add(void *data __UNUSED__,
4740                    int type __UNUSED__,
4741                    void *event)
4742 {
4743    E_Event_Border_Add *ev = event;
4744    E_Comp_Win *cw;
4745    E_Comp* c = _e_mod_comp_find(ev->border->zone->container->manager->root);
4746    L(LT_EVENT_X,
4747      "[COMP] ev:%15.15s w:0x%08x\n",
4748      "BD_ADD", ev->border->win);
4749    if (!c) return ECORE_CALLBACK_PASS_ON;
4750    if (_e_mod_comp_win_find(ev->border->win)) return ECORE_CALLBACK_PASS_ON;
4751    if (c->win == ev->border->win) return ECORE_CALLBACK_PASS_ON;
4752    if (c->ee_win == ev->border->win) return ECORE_CALLBACK_PASS_ON;
4753    cw = _e_mod_comp_win_add(c, ev->border->win);
4754    if (cw)
4755      _e_mod_comp_win_configure(cw,
4756                                ev->border->x,
4757                                ev->border->y,
4758                                ev->border->w,
4759                                ev->border->h,
4760                                ev->border->client.initial_attributes.border);
4761
4762    if ( ev->border->internal && ev->border->visible )
4763      _e_mod_comp_win_show(cw);
4764
4765    return ECORE_CALLBACK_PASS_ON;
4766 }
4767
4768 static Eina_Bool
4769 _e_mod_comp_bd_del(void *data __UNUSED__,
4770                    int type __UNUSED__,
4771                    void *event)
4772 {
4773    E_Event_Border_Remove *ev = event;
4774    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
4775    L(LT_EVENT_X,
4776      "[COMP] ev:%15.15s w:0x%08x\n",
4777      "BD_DEL", ev->border->win);
4778    if (!cw) return ECORE_CALLBACK_PASS_ON;
4779    if (cw->bd == ev->border) _e_mod_comp_object_del(cw, ev->border);
4780    if (cw->animating) cw->delete_me = 1;
4781    else _e_mod_comp_win_del(cw);
4782    return ECORE_CALLBACK_PASS_ON;
4783 }
4784
4785 static Eina_Bool
4786 _e_mod_comp_bd_show(void *data __UNUSED__,
4787                     int type __UNUSED__,
4788                     void *event)
4789 {
4790    E_Event_Border_Show *ev = event;
4791    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
4792    L(LT_EVENT_X,
4793      "[COMP] ev:%15.15s w:0x%08x\n",
4794      "BD_SHOW", ev->border->win);
4795    if (!cw) return ECORE_CALLBACK_PASS_ON;
4796    if (cw->visible) return ECORE_CALLBACK_PASS_ON;
4797    _e_mod_comp_win_show(cw);
4798    return ECORE_CALLBACK_PASS_ON;
4799 }
4800
4801 static Eina_Bool
4802 _e_mod_comp_bd_hide(void *data __UNUSED__,
4803                     int type __UNUSED__,
4804                     void *event)
4805 {
4806    E_Event_Border_Hide *ev = event;
4807    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
4808    L(LT_EVENT_X,
4809      "[COMP] ev:%15.15s w:0x%08x\n",
4810      "BD_HIDE", ev->border->win);
4811    if (!cw) return ECORE_CALLBACK_PASS_ON;
4812    if (!cw->visible) return ECORE_CALLBACK_PASS_ON;
4813    _e_mod_comp_win_hide(cw);
4814    return ECORE_CALLBACK_PASS_ON;
4815 }
4816
4817 static Eina_Bool
4818 _e_mod_comp_bd_move(void *data __UNUSED__,
4819                     int type __UNUSED__,
4820                     void *event)
4821 {
4822    E_Event_Border_Move *ev = event;
4823    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
4824    if (!cw) return ECORE_CALLBACK_PASS_ON;
4825
4826    L(LT_EVENT_X,
4827      "[COMP] ev:%15.15s w:0x%08x   cw->x: %d, cw->y: %d, cw->visible: %d, \
4828      cw->hidden.x: %d, cw->hidden.y: %d, ev->x: %d,  ev->y: %d\n",
4829      "BD_MOVE", ev->border->win, cw->x, cw->y, cw->visible,
4830      cw->hidden.x, cw->hidden.y, ev->border->x, ev->border->y);
4831
4832    if (!((cw->x == ev->border->x) && (cw->y == ev->border->y))
4833        && cw->visible)
4834      {
4835         _e_mod_comp_win_configure(cw,
4836                                   ev->border->x,
4837                                   ev->border->y,
4838                                   ev->border->w,
4839                                   ev->border->h,
4840                                   0);
4841      }
4842    else if (!((cw->hidden.x == ev->border->x) && (cw->hidden.y == ev->border->y))
4843             && !cw->visible)
4844      {
4845         _e_mod_comp_win_configure(cw,
4846                                   ev->border->x,
4847                                   ev->border->y,
4848                                   ev->border->w,
4849                                   ev->border->h,
4850                                   0);
4851      }
4852    return ECORE_CALLBACK_PASS_ON;
4853 }
4854
4855 static Eina_Bool
4856 _e_mod_comp_bd_resize(void *data __UNUSED__,
4857                       int type __UNUSED__,
4858                       void *event)
4859 {
4860    E_Event_Border_Resize *ev = event;
4861    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
4862    L(LT_EVENT_X,
4863      "[COMP] ev:%15.15s w:0x%08x\n",
4864      "BD_RESIZE", ev->border->win);
4865    if (!cw) return ECORE_CALLBACK_PASS_ON;
4866    if ((cw->w == ev->border->w) && (cw->h == ev->border->h))
4867      return ECORE_CALLBACK_PASS_ON;
4868    _e_mod_comp_win_configure(cw,
4869                              cw->x, cw->y,
4870                              ev->border->w, ev->border->h,
4871                              cw->border);
4872    return ECORE_CALLBACK_PASS_ON;
4873 }
4874
4875 static Eina_Bool
4876 _e_mod_comp_bd_iconify(void *data __UNUSED__,
4877                        int type __UNUSED__,
4878                        void *event)
4879 {
4880    E_Event_Border_Iconify *ev = event;
4881    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
4882    L(LT_EVENT_BD,
4883      "[COMP] ev:%15.15s w:0x%08x\n",
4884      "BD_ICONIFY", ev->border->win);
4885    if (!cw) return ECORE_CALLBACK_PASS_ON;
4886    // fimxe: special iconfiy anim
4887    return ECORE_CALLBACK_PASS_ON;
4888 }
4889
4890 static Eina_Bool
4891 _e_mod_comp_bd_uniconify(void *data __UNUSED__,
4892                          int type __UNUSED__,
4893                          void *event)
4894 {
4895    E_Event_Border_Uniconify *ev = event;
4896    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
4897    L(LT_EVENT_BD,
4898      "[COMP] ev:%15.15s w:0x%08x\n",
4899      "BD_UNICONIFY", ev->border->win);
4900    if (!cw) return ECORE_CALLBACK_PASS_ON;
4901    // fimxe: special uniconfiy anim
4902    return ECORE_CALLBACK_PASS_ON;
4903 }
4904
4905 static Eina_Bool
4906 _e_mod_comp_bd_urgent_change(void *data __UNUSED__,
4907                              int type __UNUSED__,
4908                              void *event)
4909 {
4910    E_Event_Border_Urgent_Change *ev = event;
4911    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
4912    L(LT_EVENT_BD,
4913      "[COMP] ev:%15.15s w:0x%08x\n",
4914      "BD_URGENTCHANGE", ev->border->win);
4915    if (!cw) return ECORE_CALLBACK_PASS_ON;
4916    if (cw->bd->client.icccm.urgent)
4917      edje_object_signal_emit(cw->shobj, "e,state,urgent,on", "e");
4918    else
4919      edje_object_signal_emit(cw->shobj, "e,state,urgent,off", "e");
4920    return ECORE_CALLBACK_PASS_ON;
4921 }
4922
4923 static Eina_Bool
4924 _e_mod_comp_bd_focus_in(void *data __UNUSED__,
4925                         int type __UNUSED__,
4926                         void *event)
4927 {
4928    E_Event_Border_Focus_In *ev = event;
4929    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
4930    L(LT_EVENT_BD,
4931      "[COMP] ev:%15.15s w:0x%08x\n",
4932      "BD_FOCUS_IN", ev->border->win);
4933    if (!cw) return ECORE_CALLBACK_PASS_ON;
4934    edje_object_signal_emit(cw->shobj, "e,state,focus,on", "e");
4935    return ECORE_CALLBACK_PASS_ON;
4936 }
4937
4938 static Eina_Bool
4939 _e_mod_comp_bd_focus_out(void *data __UNUSED__,
4940                          int type __UNUSED__,
4941                          void *event)
4942 {
4943    E_Event_Border_Focus_Out *ev = event;
4944    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
4945    L(LT_EVENT_BD,
4946      "[COMP] ev:%15.15s w:0x%08x\n",
4947      "BD_FOCUS_OUT", ev->border->win);
4948    if (!cw) return ECORE_CALLBACK_PASS_ON;
4949    edje_object_signal_emit(cw->shobj, "e,state,focus,off", "e");
4950    return ECORE_CALLBACK_PASS_ON;
4951 }
4952
4953 static Eina_Bool
4954 _e_mod_comp_bd_property(void *data __UNUSED__,
4955                         int type __UNUSED__,
4956                         void *event)
4957 {
4958    E_Event_Border_Property *ev = event;
4959    E_Comp_Win *cw = _e_mod_comp_win_find(ev->border->win);
4960    L(LT_EVENT_BD,
4961      "[COMP] ev:%15.15s w:0x%08x\n",
4962      "BD_PROPERTY", ev->border->win);
4963    if (!cw) return ECORE_CALLBACK_PASS_ON;
4964    // fimxe: other properties?
4965    return ECORE_CALLBACK_PASS_ON;
4966 }
4967
4968 static Eina_Bool
4969 _e_mod_comp_key_down(void *data __UNUSED__,
4970                      int type __UNUSED__,
4971                      void *event)
4972 {
4973    Ecore_Event_Key *ev = event;
4974
4975    if ((!strcmp(ev->keyname, "Home")) &&
4976        (ev->modifiers & ECORE_EVENT_MODIFIER_SHIFT) &&
4977        (ev->modifiers & ECORE_EVENT_MODIFIER_CTRL) &&
4978        (ev->modifiers & ECORE_EVENT_MODIFIER_ALT))
4979      {
4980         if (_comp_mod)
4981           {
4982              _e_mod_config_free(_comp_mod->module);
4983              _e_mod_config_new(_comp_mod->module);
4984              e_config_save();
4985              e_module_disable(_comp_mod->module);
4986              e_config_save();
4987              e_sys_action_do(E_SYS_RESTART, NULL);
4988           }
4989      }
4990    return ECORE_CALLBACK_PASS_ON;
4991 }
4992
4993 static Evas *
4994 _e_mod_comp_evas_get_func(void *data,
4995                           E_Manager *man __UNUSED__)
4996 {
4997    E_Comp *c = data;
4998    return c->evas;
4999 }
5000
5001 static void
5002 _e_mod_comp_update_func(void *data,
5003                         E_Manager *man __UNUSED__)
5004 {
5005    E_Comp *c = data;
5006    _e_mod_comp_render_queue(c);
5007 }
5008
5009 static const Eina_List *
5010 _e_mod_comp_src_list_get_func(void *data,
5011                               E_Manager *man __UNUSED__)
5012 {
5013    E_Comp *c = data;
5014    E_Comp_Win *cw;
5015
5016    if (!c->wins) return NULL;
5017    if (c->wins_invalid)
5018      {
5019         c->wins_invalid = 0;
5020         if (c->wins_list) eina_list_free(c->wins_list);
5021         c->wins_list = NULL;
5022         EINA_INLIST_FOREACH(c->wins, cw)
5023           {
5024              if ((cw->shobj) && (cw->obj))
5025                 c->wins_list = eina_list_append(c->wins_list, cw);
5026           }
5027      }
5028    return c->wins_list;
5029 }
5030
5031 static Evas_Object *
5032 _e_mod_comp_src_image_get_func(void *data __UNUSED__,
5033                                E_Manager *man __UNUSED__,
5034                                E_Manager_Comp_Source *src)
5035 {
5036    E_Comp_Win *cw = (E_Comp_Win *)src;
5037    if (!cw->c) return NULL;
5038    return cw->obj;
5039 }
5040
5041 static Evas_Object *
5042 _e_mod_comp_src_shadow_get_func(void *data __UNUSED__,
5043                                 E_Manager *man __UNUSED__,
5044                                 E_Manager_Comp_Source *src)
5045 {
5046    E_Comp_Win *cw = (E_Comp_Win *)src;
5047    if (!cw->c) return NULL;
5048    return cw->shobj;
5049 }
5050
5051 static Evas_Object *
5052 _e_mod_comp_src_image_mirror_add_func(void *data __UNUSED__,
5053                                       E_Manager *man __UNUSED__,
5054                                       E_Manager_Comp_Source *src)
5055 {
5056    E_Comp_Win *cw = (E_Comp_Win *)src;
5057    if (!cw->c) return NULL;
5058    return _e_mod_comp_win_mirror_add(cw);
5059 }
5060
5061 static Eina_Bool
5062 _e_mod_comp_src_visible_get_func(void *data __UNUSED__,
5063                                  E_Manager *man __UNUSED__,
5064                                  E_Manager_Comp_Source *src)
5065 {
5066    E_Comp_Win *cw = (E_Comp_Win *)src;
5067    if (!cw->c) return 0;
5068    return cw->visible;
5069 }
5070
5071 static void
5072 _e_mod_comp_src_hidden_set_func(void *data __UNUSED__,
5073                                 E_Manager *man __UNUSED__,
5074                                 E_Manager_Comp_Source *src,
5075                                 Eina_Bool hidden)
5076 {
5077    E_Comp_Win *cw = (E_Comp_Win *)src;
5078    if (!cw->c) return;
5079    if (cw->hidden_override == hidden) return;
5080    cw->hidden_override = hidden;
5081    if (cw->bd)
5082      e_border_comp_hidden_set(cw->bd,
5083                               cw->hidden_override);
5084    if (cw->visible)
5085      {
5086         if (cw->hidden_override)
5087           evas_object_hide(cw->shobj);
5088         else
5089           evas_object_show(cw->shobj);
5090      }
5091    else
5092      {
5093         if (cw->hidden_override)
5094           evas_object_hide(cw->shobj);
5095      }
5096 }
5097
5098 static Eina_Bool
5099 _e_mod_comp_src_hidden_get_func(void *data __UNUSED__,
5100                                 E_Manager *man __UNUSED__,
5101                                 E_Manager_Comp_Source *src)
5102 {
5103    E_Comp_Win *cw = (E_Comp_Win *)src;
5104    if (!cw->c) return 0;
5105    return cw->hidden_override;
5106 }
5107
5108 static void
5109 _e_mod_comp_screen_lock_func(void *data,
5110                              E_Manager *man __UNUSED__)
5111 {
5112    E_Comp *c = data;
5113    _e_mod_comp_screen_lock(c);
5114 }
5115
5116 static void
5117 _e_mod_comp_screen_unlock_func(void *data,
5118                                E_Manager *man __UNUSED__)
5119 {
5120    E_Comp *c = data;
5121    _e_mod_comp_screen_unlock(c);
5122 }
5123
5124 static int
5125 _e_mod_comp_get_screen_angle(Ecore_X_Window root)
5126 {
5127    int ret = -1, ang = 0;
5128    unsigned int val = 0;
5129    Ecore_X_Display* dpy = ecore_x_display_get();
5130    if (!dpy) return 0;
5131    if (!ATOM_X_SCREEN_ROTATION) return 0;
5132
5133    ret = ecore_x_window_prop_card32_get(root, ATOM_X_SCREEN_ROTATION, &val, 1);
5134    if (ret == -1) return 0;
5135
5136    switch (val)
5137      {
5138       case  1: ang =   0; break;
5139       case  2: ang =  90; break;
5140       case  4: ang = 180; break;
5141       case  8: ang = 270; break;
5142       default: ang =   0; break;
5143      }
5144
5145    return ang;
5146 }
5147
5148 static E_Comp *
5149 _e_mod_comp_add(E_Manager *man)
5150 {
5151    E_Comp *c;
5152    Ecore_X_Window *wins;
5153    Ecore_X_Window_Attributes att;
5154    int i, num;
5155    int ok = 0;
5156
5157    c = calloc(1, sizeof(E_Comp));
5158    if (!c) return NULL;
5159
5160    if (_comp_mod->conf->vsync)
5161      {
5162         e_util_env_set("__GL_SYNC_TO_VBLANK", "1");
5163      }
5164    else
5165      {
5166         e_util_env_set("__GL_SYNC_TO_VBLANK", NULL);
5167      }
5168
5169    ecore_x_e_comp_sync_supported_set(man->root, _comp_mod->conf->efl_sync);
5170
5171    c->man = man;
5172    c->win = ecore_x_composite_render_window_enable(man->root);
5173    if (!c->win)
5174      {
5175         e_util_dialog_internal
5176           (_("Compositor Error"),
5177            _("Your screen does not support the compositor<br>"
5178              "overlay window. This is needed for it to<br>"
5179              "function."));
5180         free(c);
5181         return NULL;
5182      }
5183
5184    memset((&att), 0, sizeof(Ecore_X_Window_Attributes));
5185    ecore_x_window_attributes_get(c->win, &att);
5186
5187    if ((att.depth != 24) && (att.depth != 32))
5188      {
5189         e_util_dialog_internal
5190           (_("Compositor Error"),
5191            _("Your screen is not in 24/32bit display mode.<br>"
5192              "This is required to be your default depth<br>"
5193              "setting for the compositor to work properly."));
5194         ecore_x_composite_render_window_disable(c->win);
5195         free(c);
5196         return NULL;
5197      }
5198
5199    if (c->man->num == 0) e_alert_composite_win = c->win;
5200
5201    if (_comp_mod->conf->engine == E_EVAS_ENGINE_GL_X11)
5202      {
5203         int opt[20];
5204         int opt_i = 0;
5205
5206         c->screen_w = man->w;
5207         c->screen_h = man->h;
5208         c->screen_ang = _e_mod_comp_get_screen_angle(c->man->root);
5209
5210         if (0 != c->screen_ang)
5211           {
5212              c->screen_rotation = EINA_TRUE;
5213              if (0 != (c->screen_ang % 180))
5214                {
5215                   c->screen_w = man->h;
5216                   c->screen_h = man->w;
5217                }
5218           }
5219
5220         if (_comp_mod->conf->indirect)
5221           {
5222              opt[opt_i] = ECORE_EVAS_GL_X11_OPT_INDIRECT;
5223              opt_i++;
5224              opt[opt_i] = 1;
5225              opt_i++;
5226           }
5227         if (_comp_mod->conf->vsync)
5228           {
5229              opt[opt_i] = ECORE_EVAS_GL_X11_OPT_VSYNC;
5230              opt_i++;
5231              opt[opt_i] = 1;
5232              opt_i++;
5233           }
5234         if (opt_i > 0)
5235           {
5236              opt[opt_i] = ECORE_EVAS_GL_X11_OPT_NONE;
5237              c->ee = ecore_evas_gl_x11_options_new
5238                (NULL, c->win, 0, 0, c->screen_w, c->screen_h, opt);
5239           }
5240         if (!c->ee)
5241           c->ee = ecore_evas_gl_x11_new(NULL, c->win, 0, 0, c->screen_w, c->screen_h);
5242         if (c->ee)
5243           {
5244              c->gl = 1;
5245              ecore_evas_gl_x11_pre_post_swap_callback_set
5246                (c->ee, c, _e_mod_comp_pre_swap, NULL);
5247           }
5248      }
5249    if (!c->ee)
5250      c->ee = ecore_evas_software_x11_new(NULL, c->win, 0, 0, man->w, man->h);
5251
5252    ecore_evas_comp_sync_set(c->ee, 0);
5253    ecore_evas_manual_render_set(c->ee, _comp_mod->conf->lock_fps);
5254    c->evas = ecore_evas_get(c->ee);
5255    ecore_evas_show(c->ee);
5256
5257    if (c->screen_rotation)
5258      ecore_evas_rotation_with_resize_set(c->ee, c->screen_ang);
5259
5260    c->ee_win = ecore_evas_window_get(c->ee);
5261    ecore_x_screen_is_composited_set(c->man->num, c->ee_win);
5262
5263    ecore_x_e_comp_dri_buff_flip_supported_set
5264      (c->man->root, _comp_mod->conf->dri_buff_flip);
5265
5266    ecore_x_composite_redirect_subwindows
5267       (c->man->root, ECORE_X_COMPOSITE_UPDATE_MANUAL);
5268
5269    wins = ecore_x_window_children_get(c->man->root, &num);
5270    if (wins)
5271      {
5272         for (i = 0; i < num; i++)
5273           {
5274              E_Comp_Win *cw;
5275              int x, y, w, h, border;
5276              char *wname = NULL, *wclass = NULL;
5277
5278              ecore_x_icccm_name_class_get(wins[i], &wname, &wclass);
5279              if ((man->initwin == wins[i]) ||
5280                  ((wname) && (wclass) && (!strcmp(wname, "E")) &&
5281                   (!strcmp(wclass, "Init_Window"))))
5282                {
5283                   free(wname);
5284                   free(wclass);
5285                   ecore_x_window_reparent(wins[i], c->win, 0, 0);
5286                   ecore_x_sync();
5287                   continue;
5288                }
5289              if (wname) free(wname);
5290              if (wclass) free(wclass);
5291              wname = wclass = NULL;
5292              cw = _e_mod_comp_win_add(c, wins[i]);
5293              if (!cw) continue;
5294              ecore_x_window_geometry_get(cw->win, &x, &y, &w, &h);
5295              border = ecore_x_window_border_width_get(cw->win);
5296              if (wins[i] == c->win) continue;
5297              _e_mod_comp_win_configure(cw, x, y, w, h, border);
5298              if (ecore_x_window_visible_get(wins[i]))
5299                _e_mod_comp_win_show(cw);
5300           }
5301         free(wins);
5302      }
5303
5304    ecore_x_window_key_grab(c->man->root,
5305                            "Home",
5306                            ECORE_EVENT_MODIFIER_SHIFT |
5307                            ECORE_EVENT_MODIFIER_CTRL |
5308                            ECORE_EVENT_MODIFIER_ALT, 0);
5309
5310
5311    c->bg_img = evas_object_rectangle_add(c->evas);
5312    evas_object_color_set(c->bg_img, 0, 0, 0, 255);
5313
5314    evas_object_stack_below(c->bg_img, evas_object_bottom_get(c->evas));
5315    evas_object_show(c->bg_img);
5316    evas_object_move(c->bg_img, 0, 0);
5317    evas_object_resize(c->bg_img, c->man->w, c->man->h); // resize to root window's width, height
5318
5319    c->fake_img_shobj = NULL;
5320    c->fake_img_shobj = edje_object_add(c->evas);
5321    ok = edje_object_file_set(c->fake_img_shobj, _comp_mod->conf->shadow_file, "fake_effect_twist");
5322    if (!ok)
5323      {
5324         fprintf(stdout,
5325                 "[E17-comp] FAKE IMG EDC Animation isn't loaded!\n");
5326      }
5327
5328    edje_object_signal_callback_add(c->fake_img_shobj,
5329                                    "fake,action,hide,done",
5330                                    "fake",
5331                                    _e_mod_comp_fake_hide_done, c);
5332
5333    evas_object_move(c->fake_img_shobj, 0, 0);
5334    evas_object_resize(c->fake_img_shobj, c->man->w, c->man->h);
5335    c->fake_launch_state = EINA_FALSE;
5336
5337    c->fake_launch_timeout  = NULL;
5338    c->fake_win = 0;
5339    c->fake_launch_done = EINA_FALSE;
5340
5341    edje_object_signal_callback_add(c->fake_img_shobj,
5342                                    "fake,action,show,done",
5343                                    "fake",
5344                                    _e_mod_comp_fake_show_done, c);
5345
5346    c->capture_effect_obj = NULL;
5347    c->capture_effect_obj = edje_object_add(c->evas);
5348    ok = edje_object_file_set(c->capture_effect_obj, _comp_mod->conf->shadow_file, "capture_effect");
5349    if (!ok)
5350      {
5351         fprintf(stdout,
5352                 "[E17-comp] CAPTURE EFFECT EDC Animation isn't loaded!\n");
5353      }
5354    edje_object_signal_callback_add(c->capture_effect_obj,
5355                                    "img,capture,show,done",
5356                                    "img",
5357                                    _e_mod_comp_capture_effect_show_done, c);
5358
5359    evas_object_move(c->capture_effect_obj, 0, 0);
5360    evas_object_resize(c->capture_effect_obj, c->man->w, c->man->h);
5361
5362    c->switcher_animating = EINA_FALSE;
5363
5364    c->comp.data                      = c;
5365    c->comp.func.evas_get             = _e_mod_comp_evas_get_func;
5366    c->comp.func.update               = _e_mod_comp_update_func;
5367    c->comp.func.src_list_get         = _e_mod_comp_src_list_get_func;
5368    c->comp.func.src_image_get        = _e_mod_comp_src_image_get_func;
5369    c->comp.func.src_shadow_get       = _e_mod_comp_src_shadow_get_func;
5370    c->comp.func.src_image_mirror_add = _e_mod_comp_src_image_mirror_add_func;
5371    c->comp.func.src_visible_get      = _e_mod_comp_src_visible_get_func;
5372    c->comp.func.src_hidden_set       = _e_mod_comp_src_hidden_set_func;
5373    c->comp.func.src_hidden_get       = _e_mod_comp_src_hidden_get_func;
5374    c->comp.func.screen_lock          = _e_mod_comp_screen_lock_func;
5375    c->comp.func.screen_unlock        = _e_mod_comp_screen_unlock_func;
5376
5377    e_manager_comp_set(c->man, &(c->comp));
5378
5379    return c;
5380 }
5381
5382 static void
5383 _e_mod_comp_del(E_Comp *c)
5384 {
5385    E_Comp_Win *cw;
5386
5387    e_manager_comp_set(c->man, NULL);
5388
5389    ecore_x_window_key_ungrab(c->man->root,
5390                              "Home",
5391                              ECORE_EVENT_MODIFIER_SHIFT |
5392                              ECORE_EVENT_MODIFIER_CTRL |
5393                              ECORE_EVENT_MODIFIER_ALT, 0);
5394    if (c->grabbed)
5395      {
5396         c->grabbed = 0;
5397         ecore_x_ungrab();
5398      }
5399    if (c->fps_fg)
5400      {
5401         evas_object_del(c->fps_fg);
5402         c->fps_fg = NULL;
5403      }
5404    if (c->fps_bg)
5405      {
5406         evas_object_del(c->fps_bg);
5407         c->fps_bg = NULL;
5408      }
5409    ecore_x_screen_is_composited_set(c->man->num, 0);
5410    while (c->wins)
5411      {
5412         cw = (E_Comp_Win *)(c->wins);
5413         if (cw->counter)
5414           {
5415              ecore_x_sync_counter_free(cw->counter);
5416              cw->counter = 0;
5417           }
5418         cw->force = 1;
5419         _e_mod_comp_win_hide(cw);
5420         cw->force = 1;
5421         _e_mod_comp_win_del(cw);
5422      }
5423    ecore_evas_free(c->ee);
5424    ecore_x_composite_unredirect_subwindows
5425      (c->man->root, ECORE_X_COMPOSITE_UPDATE_MANUAL);
5426    ecore_x_composite_render_window_disable(c->win);
5427    if (c->man->num == 0) e_alert_composite_win = 0;
5428    if (c->render_animator) ecore_animator_del(c->render_animator);
5429    if (c->new_up_timer) ecore_timer_del(c->new_up_timer);
5430    if (c->update_job) ecore_job_del(c->update_job);
5431    if (c->wins_list) eina_list_free(c->wins_list);
5432
5433    ecore_x_e_comp_dri_buff_flip_supported_set(c->man->root, 0);
5434
5435    ecore_x_e_comp_sync_supported_set(c->man->root, 0);
5436    free(c);
5437 }
5438
5439 Eina_Bool
5440 e_mod_comp_init(void)
5441 {
5442    Eina_List *l;
5443    E_Manager *man;
5444    E_Comp    *comp = NULL;
5445    unsigned int effect_enable = 0;
5446    unsigned int window_effect_state = 0;
5447
5448    windows = eina_hash_string_superfast_new(NULL);
5449    borders = eina_hash_string_superfast_new(NULL);
5450    damages = eina_hash_string_superfast_new(NULL);
5451
5452    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_CREATE,    _e_mod_comp_create,           NULL));
5453    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_DESTROY,   _e_mod_comp_destroy,          NULL));
5454    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHOW,      _e_mod_comp_show,             NULL));
5455    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_HIDE,      _e_mod_comp_hide,             NULL));
5456    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_REPARENT,  _e_mod_comp_reparent,         NULL));
5457    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_CONFIGURE, _e_mod_comp_configure,        NULL));
5458    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_STACK,     _e_mod_comp_stack,            NULL));
5459    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY,  _e_mod_comp_property,         NULL));
5460    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,   _e_mod_comp_message,          NULL));
5461    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHAPE,     _e_mod_comp_shape,            NULL));
5462    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_DAMAGE_NOTIFY,    _e_mod_comp_damage,           NULL));
5463    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_X_EVENT_WINDOW_DAMAGE,    _e_mod_comp_damage_win,       NULL));
5464    handlers = eina_list_append(handlers, ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,           _e_mod_comp_key_down,         NULL));
5465    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_CONTAINER_RESIZE,       _e_mod_comp_randr,            NULL));
5466    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_ADD,             _e_mod_comp_bd_add,           NULL));
5467    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_REMOVE,          _e_mod_comp_bd_del,           NULL));
5468    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_SHOW,            _e_mod_comp_bd_show,          NULL));
5469    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_HIDE,            _e_mod_comp_bd_hide,          NULL));
5470    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_MOVE,            _e_mod_comp_bd_move,          NULL));
5471    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_RESIZE,          _e_mod_comp_bd_resize,        NULL));
5472    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_ICONIFY,         _e_mod_comp_bd_iconify,       NULL));
5473    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_UNICONIFY,       _e_mod_comp_bd_uniconify,     NULL));
5474    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_URGENT_CHANGE,   _e_mod_comp_bd_urgent_change, NULL));
5475    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_FOCUS_IN,        _e_mod_comp_bd_focus_in,      NULL));
5476    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_FOCUS_OUT,       _e_mod_comp_bd_focus_out,     NULL));
5477    handlers = eina_list_append(handlers, ecore_event_handler_add(E_EVENT_BORDER_PROPERTY,        _e_mod_comp_bd_property,      NULL));
5478
5479    _e_mod_comp_atom_init();
5480
5481    EINA_LIST_FOREACH(e_manager_list(), l, man)
5482      {
5483         E_Comp *c;
5484         c = _e_mod_comp_add(man);
5485         if (c) compositors = eina_list_append(compositors, c);
5486         if (c) _e_mod_comp_set(c);
5487      }
5488
5489    comp = _e_mod_comp_get();
5490    if (comp)
5491      {
5492         if (_comp_mod->conf->default_window_effect)
5493           effect_enable = 1;
5494         else
5495           effect_enable = 0;
5496
5497         ecore_x_window_prop_card32_set(comp->man->root,
5498                                        ATOM_EFFECT_ENABLE,
5499                                        &effect_enable, 1);
5500         ecore_x_window_prop_card32_set(comp->man->root,
5501                                        ATOM_WINDOW_EFFECT_STATE,
5502                                        &window_effect_state, 1);
5503         ecore_x_window_prop_property_set(comp->man->root,
5504                                          ATOM_OVERAY_WINDOW,
5505                                          ECORE_X_ATOM_WINDOW,
5506                                          32, &comp->win, 1);
5507      }
5508
5509    ecore_animator_frametime_set(1.0f/60.0f);
5510    ecore_x_sync();
5511    return 1;
5512 }
5513
5514 void
5515 e_mod_comp_shutdown(void)
5516 {
5517    E_Comp *c;
5518
5519    EINA_LIST_FREE(compositors, c) _e_mod_comp_del(c);
5520
5521    E_FREE_LIST(handlers, ecore_event_handler_del);
5522
5523    eina_hash_free(damages);
5524    eina_hash_free(windows);
5525    eina_hash_free(borders);
5526
5527    _e_mod_comp_set(NULL);
5528 }
5529
5530 void
5531 e_mod_comp_shadow_set(void)
5532 {
5533    Eina_List *l;
5534    E_Comp *c;
5535
5536    EINA_LIST_FOREACH(compositors, l, c)
5537      {
5538         E_Comp_Win *cw;
5539         if (!c) continue;
5540         ecore_evas_manual_render_set(c->ee, _comp_mod->conf->lock_fps);
5541         EINA_INLIST_FOREACH(c->wins, cw)
5542           {
5543              if ((cw->shobj) && (cw->obj))
5544                {
5545                   _e_mod_comp_win_shadow_setup(cw);
5546                   if (cw->visible)
5547                     {
5548                        L(LT_EFFECT,
5549                          "[COMP] WIN_EFFECT : Show signal Emit (e_mod_comp_shadow_set()) -> win:0x%08x\n",
5550                          cw->win);
5551
5552                        if (cw->animatable)
5553                          edje_object_signal_emit(cw->shobj,
5554                                                  "e,state,visible,on",
5555                                                  "e");
5556                        else
5557                          edje_object_signal_emit(cw->shobj,
5558                                                  "e,state,visible,on,noeffect",
5559                                                  "e");
5560
5561                        _e_mod_comp_win_inc_animating(cw);
5562                        cw->pending_count++;
5563                        e_manager_comp_event_src_visibility_send
5564                          (cw->c->man, (E_Manager_Comp_Source *)cw,
5565                          _e_mod_comp_cb_pending_after, cw->c);
5566                     }
5567                }
5568           }
5569      }
5570 }
5571
5572 E_Comp *
5573 e_mod_comp_manager_get(E_Manager *man)
5574 {
5575    return _e_mod_comp_find(man->root);
5576 }
5577
5578 E_Comp_Win *
5579 e_mod_comp_win_find_by_window(E_Comp *c,
5580                               Ecore_X_Window win)
5581 {
5582    E_Comp_Win *cw;
5583
5584    EINA_INLIST_FOREACH(c->wins, cw)
5585      {
5586         if (cw->win == win) return cw;
5587      }
5588    return NULL;
5589 }
5590
5591 E_Comp_Win *
5592 e_mod_comp_win_find_by_border(E_Comp *c,
5593                               E_Border *bd)
5594 {
5595    E_Comp_Win *cw;
5596
5597    EINA_INLIST_FOREACH(c->wins, cw)
5598      {
5599         if (cw->bd == bd) return cw;
5600      }
5601    return NULL;
5602 }
5603
5604 E_Comp_Win *
5605 e_mod_comp_win_find_by_popup(E_Comp *c,
5606                              E_Popup *pop)
5607 {
5608    E_Comp_Win *cw;
5609
5610    EINA_INLIST_FOREACH(c->wins, cw)
5611      {
5612         if (cw->pop == pop) return cw;
5613      }
5614    return NULL;
5615 }
5616
5617 E_Comp_Win *
5618 e_mod_comp_win_find_by_menu(E_Comp *c,
5619                             E_Menu *menu)
5620 {
5621    E_Comp_Win *cw;
5622
5623    EINA_INLIST_FOREACH(c->wins, cw)
5624      {
5625         if (cw->menu == menu) return cw;
5626      }
5627    return NULL;
5628 }
5629
5630 Evas_Object *
5631 e_mod_comp_win_evas_object_get(E_Comp_Win *cw)
5632 {
5633    if (!cw) return NULL;
5634    return cw->obj;
5635 }
5636
5637 Evas_Object *
5638 e_mod_comp_win_mirror_object_add(Evas *e __UNUSED__,
5639                                  E_Comp_Win *cw __UNUSED__)
5640 {
5641    return NULL;
5642 }
5643
5644 static void
5645 _e_mod_comp_win_cb_setup(E_Comp_Win *cw)
5646 {
5647    edje_object_signal_callback_add(cw->shobj, "e,action,show,done",            "e", _e_mod_comp_show_done,            cw);
5648    edje_object_signal_callback_add(cw->shobj, "e,action,hide,done",            "e", _e_mod_comp_hide_done,            cw);
5649    edje_object_signal_callback_add(cw->shobj, "e,action,background,show,done", "e", _e_mod_comp_background_show_done, cw);
5650    edje_object_signal_callback_add(cw->shobj, "e,action,background,hide,done", "e", _e_mod_comp_background_hide_done, cw);
5651    edje_object_signal_callback_add(cw->shobj, "e,action,window,rotation,done", "e", _e_mod_comp_win_rotation_done,    cw);
5652    edje_object_signal_callback_add(cw->shobj, "e,action,raise_above_hide,done","e", _e_mod_comp_raise_above_hide_done,cw);
5653 }
5654
5655 static void
5656 _e_mod_comp_win_recreate_shobj(E_Comp_Win *cw)
5657 {
5658    /* backup below obj */
5659    Eina_Bool bottom = EINA_FALSE;
5660
5661    Evas_Object *below_obj = evas_object_below_get(cw->shobj);
5662    if (!below_obj)
5663      {
5664         if (evas_object_bottom_get(cw->c->evas) == cw->shobj)
5665           {
5666              L(LT_EVENT_X,
5667                "[COMP] %31s w:0x%08x bd:%s shobj is bottom.\n",
5668                "PIX_ROT", _e_mod_comp_win_get_client_xid(cw),
5669                cw->bd ? "O" : "X");
5670              bottom = EINA_TRUE;
5671           }
5672      }
5673
5674    if (cw->obj)
5675      {
5676         evas_object_hide(cw->obj);
5677         evas_object_del(cw->obj);
5678         cw->obj = NULL;
5679      }
5680    if (cw->shobj)
5681      {
5682         evas_object_hide(cw->obj);
5683         evas_object_del(cw->shobj);
5684         cw->shobj = NULL;
5685      }
5686
5687    cw->shobj = edje_object_add(cw->c->evas);
5688    cw->obj = evas_object_image_filled_add(cw->c->evas);
5689    evas_object_image_colorspace_set(cw->obj, EVAS_COLORSPACE_ARGB8888);
5690
5691    if (cw->argb)
5692      evas_object_image_alpha_set(cw->obj, 1);
5693    else
5694      evas_object_image_alpha_set(cw->obj, 0);
5695
5696    _e_mod_comp_win_shadow_setup(cw);
5697    _e_mod_comp_win_cb_setup(cw);
5698
5699    evas_object_show(cw->obj);
5700    evas_object_pass_events_set(cw->obj, 1);
5701    evas_object_pass_events_set(cw->shobj, 1);
5702
5703    /* restore stack */
5704    if (bottom)
5705      below_obj = evas_object_below_get(cw->shobj);
5706
5707    evas_object_stack_above(cw->shobj, below_obj);
5708    L(LT_EVENT_X,
5709      "[COMP] %31s w:0x%08x bd:%s shobj restore stack.\n",
5710      "PIX_ROT", _e_mod_comp_win_get_client_xid(cw),
5711      cw->bd ? "O" : "X");
5712 }
5713
5714 void
5715 _e_mod_comp_enable_touch_event_block(E_Comp *c)
5716 {
5717    if (!c) return;
5718    if (!c->win) return;
5719
5720    ecore_x_window_shape_input_rectangle_set(c->win, 0, 0, c->man->w, c->man->h );
5721 }
5722
5723 void
5724 _e_mod_comp_disable_touch_event_block(E_Comp *c)
5725 {
5726    if (!c) return;
5727    if (!c->win) return;
5728
5729    ecore_x_window_shape_input_rectangle_set(c->win, -1, -1, 1, 1 );
5730 }
5731
5732 void
5733 _e_mod_comp_win_inc_animating(E_Comp_Win *cw)
5734 {
5735    if (!cw->animating)
5736      {
5737         cw->c->animating++;
5738         // send current effect status is starting.
5739         _e_mod_comp_send_window_effect_client_state(cw, EINA_TRUE);
5740         cw->animating = 1;
5741      }
5742    else
5743      {
5744         // if previous effect is not done case
5745         cw->c->animating--;
5746         cw->animating = 0;
5747         // send previous effect status is done
5748         _e_mod_comp_send_window_effect_client_state(cw, EINA_FALSE);
5749         cw->c->animating++;
5750         cw->animating = 1;
5751         // send current effect status is starting.
5752         _e_mod_comp_send_window_effect_client_state(cw, EINA_TRUE);
5753      }
5754    _e_mod_comp_win_render_queue(cw);
5755 }
5756
5757 void
5758 _e_mod_comp_win_dec_animating(E_Comp_Win *cw)
5759 {
5760    if (cw->animating) cw->c->animating--;
5761    cw->animating = 0;
5762
5763    _e_mod_comp_send_window_effect_client_state(cw, EINA_FALSE);
5764    _e_mod_comp_win_render_queue(cw);
5765 }