Merged with devel
[platform/core/uifw/e17-extra-modules.git] / illume2-tizen / src / policies / illume / policy.c
1 #include "e_illume_private.h"
2 #include "policy_util.h"
3 #include "policy.h"
4
5 #if 1 // for visibility
6 #include <X11/Xlib.h>
7 #endif
8
9 #ifdef USE_DLOG
10 #include "dlog.h"
11 #undef LOG_TAG
12 #define LOG_TAG "E17_EXTRA_MODULES"
13 #endif
14
15 /* NB: DIALOG_USES_PIXEL_BORDER is an experiment in setting dialog windows
16  * to use the 'pixel' type border. This is done because some dialogs,
17  * when shown, blend into other windows too much. Pixel border adds a
18  * little distinction between the dialog window and an app window.
19  * Disable if this is not wanted */
20 //#define DIALOG_USES_PIXEL_BORDER 1
21
22 /* for debugging */
23 #define ILLUME2_DEBUG  0
24 #if ILLUME2_DEBUG
25 #define ILLUME2_TRACE  printf
26 #else
27 #define ILLUME2_TRACE(...)
28 #endif
29
30 typedef struct _E_Illume_Print_Info
31 {
32    unsigned int type;
33    char file_name[256];
34 } E_Illume_Print_Info;
35
36
37 #define COMP_MODULE_CONTROL
38 #define BACKKEY_MODULE_CONTROL
39 #define DEVMODE_MODULE_CONTROL
40
41
42 /*****************************/
43 /* local function prototypes */
44 /*****************************/
45 static void _policy_border_set_focus(E_Border *bd);
46 static void _policy_border_move(E_Border *bd, int x, int y);
47 static void _policy_border_resize(E_Border *bd, int w, int h);
48 static void _policy_border_show_below(E_Border *bd);
49 static void _policy_zone_layout_update(E_Zone *zone);
50 static void _policy_zone_layout_indicator(E_Border *bd, E_Illume_Config_Zone *cz);
51 static void _policy_zone_layout_quickpanel(E_Border *bd);
52 static void _policy_zone_layout_quickpanel_popup(E_Border *bd);
53 static void _policy_zone_layout_keyboard(E_Border *bd, E_Illume_Config_Zone *cz);
54 static void _policy_zone_layout_fullscreen(E_Border *bd);
55 static void _policy_zone_layout_dialog(E_Border *bd, E_Illume_Config_Zone *cz);
56 static void _policy_zone_layout_splash(E_Border *bd, E_Illume_Config_Zone *cz);
57 static void _policy_zone_layout_clipboard(E_Border *bd, E_Illume_Config_Zone *cz);
58 static void _policy_zone_layout_apptray(E_Border *bd);
59
60 static int _policy_window_rotation_angle_get(Ecore_X_Window win);
61 static Ecore_X_Window _policy_active_window_get(Ecore_X_Window root);
62 static int _policy_border_indicator_state_get(E_Border *bd);
63
64 static void _policy_layout_quickpanel_rotate (E_Illume_Quickpanel* qp, int angle);
65
66 static E_Illume_Border_Info* _policy_get_border_info (E_Border* bd);
67 static E_Illume_Border_Info* _policy_add_border_info_list (E_Border* bd);
68 static void _policy_delete_border_info_list (E_Border* bd);
69 static int _policy_compare_cb_border (E_Illume_Border_Info* data1, E_Illume_Border_Info* data2);
70
71 static void _policy_zone_layout_app_single_new (E_Illume_Border_Info* bd_info, E_Illume_Config_Zone* cz);
72 static void _policy_zone_layout_app_dual_top_new (E_Illume_Border_Info* bd_info, E_Illume_Config_Zone* cz);
73 static void _policy_zone_layout_app_dual_left_new (E_Illume_Border_Info* bd_info, E_Illume_Config_Zone* cz);
74 static void _policy_zone_layout_app_dual_custom_new (E_Illume_Border_Info* bd_info, E_Illume_Config_Zone* cz);
75
76 static int _policy_border_get_notification_level (Ecore_X_Window win);
77 static int _policy_notification_level_map(int level);
78
79 static void _policy_change_quickpanel_layer (E_Illume_Quickpanel* qp, E_Border* indi_bd, int layer, int level);
80 static void _policy_change_indicator_layer(E_Border *indi_bd, E_Border *bd, int layer, int level);
81
82 /* for property change */
83 static void _policy_property_window_state_change (Ecore_X_Event_Window_Property *event);
84 static void _policy_property_indicator_geometry_change (Ecore_X_Event_Window_Property *event);
85 static void _policy_property_clipboard_geometry_change (Ecore_X_Event_Window_Property *event);
86 static void _policy_property_clipboard_state_change (Ecore_X_Event_Window_Property *event);
87 static void _policy_property_indicator_geometry_change (Ecore_X_Event_Window_Property *event);
88 static void _policy_property_enlightenment_scale_change (Ecore_X_Event_Window_Property *event);
89 static void _policy_property_rotate_win_angle_change (Ecore_X_Event_Window_Property *event);
90 static void _policy_property_indicator_state_change (Ecore_X_Event_Window_Property *event);
91 static void _policy_property_indicator_opacity_change(Ecore_X_Event_Window_Property *event);
92 static void _policy_property_active_win_change (Ecore_X_Event_Window_Property *event);
93 static void _policy_property_win_type_change (Ecore_X_Event_Window_Property *event);
94 static void _policy_property_rotate_root_angle_change (Ecore_X_Event_Window_Property *event);
95 static void _policy_property_notification_level_change (Ecore_X_Event_Window_Property *event);
96 static void _policy_property_overlay_win_change (Ecore_X_Event_Window_Property *event);
97 static void _policy_property_window_opaque_change (Ecore_X_Event_Window_Property *event);
98 static void _policy_property_illume_window_state_change(Ecore_X_Event_Window_Property *event);
99 static void _policy_property_indicator_cmd_win_change(Ecore_X_Event_Window_Property *event);
100 static void _policy_property_active_indicator_win_change(Ecore_X_Event_Window_Property *event);
101
102 static void _policy_border_illume_window_state_change(E_Border *bd, unsigned int state);
103
104 static Eina_Bool _policy_border_cb_mouse_down(void *data, int type __UNUSED__, void *event);
105 static Eina_Bool _policy_border_cb_mouse_up(void *data, int type __UNUSED__, void *event);
106 static Eina_Bool _policy_border_cb_mouse_move(void *data, int type __UNUSED__, void *event);
107
108 static int _policy_property_window_opaque_get (Ecore_X_Window win);
109
110 static void _policy_border_focus_top_stack_set(E_Border *bd);
111
112 /* for debugging */
113 void _policy_border_list_print (Ecore_X_Window win);
114
115 #ifdef COMP_MODULE_CONTROL
116 static void _policy_property_composite_module_change (Ecore_X_Event_Window_Property *ev);
117 #endif
118 #ifdef BACKKEY_MODULE_CONTROL
119 static void _policy_property_backkey_module_change (Ecore_X_Event_Window_Property *ev);
120 #endif
121 #ifdef DEVMODE_MODULE_CONTROL
122 static void _policy_property_devmode_module_change (Ecore_X_Event_Window_Property *ev);
123 #endif
124
125 #if 1 // for visibility
126 static void _policy_manage_xwins (E_Manager* man);
127 static E_Illume_XWin_Info* _policy_xwin_info_find (Ecore_X_Window win);
128 static Eina_Bool _policy_xwin_info_add (Ecore_X_Window win);
129 static Eina_Bool _policy_xwin_info_delete (Ecore_X_Window win);
130
131 static void _policy_send_visibility_notify (Ecore_X_Window win, int visibility);
132 static void _policy_calculate_visibility (void);
133 #endif // visibility
134
135 static Eina_Bool _policy_root_angle_set(E_Border *bd);
136 static void _policy_change_root_angle_by_border_angle (E_Border* bd);
137 static void _policy_indicator_angle_change (E_Border* indi_bd, int angle);
138
139 static void _policy_border_transient_for_group_make(E_Border *bd, Eina_List** list);
140 static E_Border* _policy_border_transient_for_border_top_get(E_Border *bd);
141 static void _policy_border_transient_for_layer_set(E_Border *bd, E_Border *parent_bd, int layer);
142
143 /* for desktop mode */
144 static void _policy_zone_layout_app_single_monitor(E_Illume_Border_Info *bd_info, E_Illume_Config_Zone *cz);
145
146 /* for controling indicator */
147 static void _policy_border_indicator_control(E_Border *indi_bd);
148 static Eina_Bool _policy_border_indicator_state_change(E_Border *indi_bd, E_Border *bd);
149 static Ecore_X_Window _policy_indicator_cmd_win_get(Ecore_X_Window win);
150 static Ecore_X_Window _policy_active_indicator_win_get(Ecore_X_Window win);
151
152 static void _policy_resize_start(E_Illume_Border_Info *bd_info);
153 static void _policy_resize_end(E_Illume_Border_Info *bd_info);
154 static void _policy_border_illume_handlers_add(E_Illume_Border_Info *bd_info);
155 static void _policy_border_illume_handlers_remove(E_Illume_Border_Info *bd_info);
156
157 static void _policy_border_root_angle_control(E_Zone *zone);
158 static int _policy_border_layer_map(int layer);
159
160 /* for visibility */
161 static void _policy_msg_handler(void *data, const char *name, const char *info, int val, E_Object *obj, void *msgdata);
162
163 /* for iconify */
164 static void _policy_border_force_iconify(E_Border *bd);
165 static void _policy_border_force_uniconify(E_Border *bd);
166 static void _policy_border_iconify_by_illume(E_Illume_XWin_Info *xwin_info);
167 static void _policy_border_uniconify_below_borders_by_illume(E_Illume_XWin_Info *xwin_info);
168 static E_Border* _policy_border_find_below(E_Border *bd);
169 static void _policy_border_uniconify_below_borders(E_Border *bd);
170 static void _policy_border_uniconify_top_border(E_Border *bd);
171
172 /* for supporting rotation */
173 static void       _policy_border_dependent_rotation(E_Border *bd, int rotation);
174 static Eina_Bool _policy_dependent_rotation_check(E_Border *bd, int rotation);
175 static int _prev_angle_get(Ecore_X_Window win);
176
177
178 /*******************/
179 /* local variables */
180 /*******************/
181
182 /* for active/deactive message */
183 static Ecore_X_Window g_active_win = 0;
184 static Ecore_X_Window g_active_pid = 0;
185
186 /* for rotation */
187 int g_root_angle = 0;
188 Ecore_X_Window g_rotated_win = 0;
189
190 /* for focus stack */
191 static Eina_List *_pol_focus_stack;
192
193 /* for border information */
194 static Eina_List* e_border_info_list = NULL;
195
196 /* for notification level */
197 static Ecore_X_Atom E_ILLUME_ATOM_NOTIFICATION_LEVEL;
198
199 /* for active/deactive message */
200 static Ecore_X_Atom E_ILLUME_ATOM_ACTIVATE_WINDOW;
201 static Ecore_X_Atom E_ILLUME_ATOM_DEACTIVATE_WINDOW;
202
203 /* for visibility */
204 static Ecore_X_Atom E_ILLUME_ATOM_OVERAY_WINDOW;
205 static Ecore_X_Atom E_ILLUME_ATOM_WINDOW_OPAQUE;
206
207 /* for debugging */
208 static Ecore_X_Atom E_ILLUME_ATOM_STACK_DISPLAY;
209 static Ecore_X_Atom E_ILLUME_ATOM_STACK_DISPLAY_DONE;
210
211 /* for indicator */
212 static Ecore_X_Window g_indi_control_win;
213
214  #ifdef COMP_MODULE_CONTROL
215 static Ecore_X_Atom E_ILLUME_ATOM_COMP_MODULE_ENABLED;
216 #endif
217 #ifdef BACKKEY_MODULE_CONTROL
218 static Ecore_X_Atom E_ILLUME_ATOM_BACKKEY_MODULE_ENABLED;
219 #endif
220 #ifdef DEVMODE_MODULE_CONTROL
221 static Ecore_X_Atom E_ILLUME_ATOM_DEVMODE_MODULE_ENABLED;
222 #endif
223
224 /* for supporting rotation */
225 static Ecore_X_Atom E_INDICATOR_CMD_WIN;
226 static Ecore_X_Atom E_ACTIVE_INDICATOR_WIN;
227
228 #if 1 // for visibility
229 static Eina_Hash* _e_illume_xwin_info_hash = NULL;
230 static Eina_Inlist* _e_illume_xwin_info_list = NULL;
231 static Ecore_X_Window _e_overlay_win = 0;
232 static int _g_root_width;
233 static int _g_root_height;
234 #endif
235
236 /* for visibility */
237 static E_Msg_Handler *_e_illume_msg_handler = NULL;
238 static Eina_Bool _e_use_comp = EINA_FALSE;
239 static Eina_Bool _g_visibility_changed = EINA_FALSE;
240
241 /* for supporing rotation */
242 typedef struct _E_Policy_Rotation_Dependent  E_Policy_Rotation_Dependent;
243
244 struct _E_Policy_Rotation_Dependent
245 {
246    Eina_List *list;
247    Ecore_X_Window root;
248
249    struct
250      {
251         Ecore_X_Window cmd_win;
252         Ecore_X_Window active_win;
253      } refer;
254
255    int ang;
256 };
257
258 static E_Policy_Rotation_Dependent dep_rot =
259 {
260    NULL,
261    NULL,
262    {NULL, NULL},
263    -1
264 };
265
266 typedef struct _E_Resizable_Area_Info
267 {
268    int x_dist;
269    int y_dist;
270    int min_width;
271    int min_height;
272    int max_width;
273    int max_height;
274 } E_Resizable_Area_Info;
275
276 /* local functions */
277 static void
278 _policy_border_set_focus(E_Border *bd)
279 {
280    if (!bd) return;
281
282    /* if focus is locked out then get out */
283    if (bd->lock_focus_out) return;
284
285    /* make sure the border can accept or take focus */
286    if ((bd->client.icccm.accepts_focus) || (bd->client.icccm.take_focus))
287      {
288         /* check E's focus settings */
289         if ((e_config->focus_setting == E_FOCUS_NEW_WINDOW) ||
290             ((bd->parent) &&
291              ((e_config->focus_setting == E_FOCUS_NEW_DIALOG) ||
292               ((bd->parent->focused) &&
293                (e_config->focus_setting == E_FOCUS_NEW_DIALOG_IF_OWNER_FOCUSED)))))
294           {
295              /* if the border was hidden due to layout, we need to unhide */
296              if (!bd->visible) e_illume_border_show(bd);
297
298              /* if the border is iconified then uniconify */
299              if (bd->iconic)
300                {
301                   /* if the user is allowed to uniconify, then do it */
302                   if (!bd->lock_user_iconify) e_border_uniconify(bd);
303                }
304
305              /* if we can raise the border do it */
306              if (!bd->lock_user_stacking) e_border_raise(bd);
307
308              /* focus the border */
309              e_border_focus_set(bd, 1, 1);
310
311              /* NB: since we skip needless border evals when container layout
312               * is called (to save cpu cycles), we need to
313               * signal this border that it's focused so that the edj gets
314               * updated.
315               *
316               * This is potentially useless as THIS policy
317               * makes all windows borderless anyway, but it's in here for
318               * completeness
319               e_border_focus_latest_set(bd);
320               if (bd->bg_object)
321               edje_object_signal_emit(bd->bg_object, "e,state,focused", "e");
322               if (bd->icon_object)
323               edje_object_signal_emit(bd->icon_object, "e,state,focused", "e");
324               e_focus_event_focus_in(bd);
325               */
326           }
327      }
328 }
329
330 static void
331 _policy_border_move(E_Border *bd, int x, int y)
332 {
333    if (!bd) return;
334
335    /* NB: Qt uses a weird window type called 'VCLSalFrame' that needs to
336     * have bd->placed set else it doesn't position correctly...
337     * this could be a result of E honoring the icccm request position,
338     * not sure */
339
340    e_border_move (bd, x, y);
341 }
342
343 static void
344 _policy_border_resize(E_Border *bd, int w, int h)
345 {
346    if (!bd) return;
347
348    e_border_resize (bd, w, h);
349 }
350
351 static void
352 _policy_border_show_below(E_Border *bd)
353 {
354    Eina_List *l;
355    E_Border *prev;
356    int pos = 0, i;
357
358    //   printf("Show Borders Below: %s %d %d\n",
359    //          bd->client.icccm.class, bd->x, bd->y);
360
361    if (!bd) return;
362
363    if (bd->client.icccm.transient_for)
364      {
365         if ((prev = e_border_find_by_client_window(bd->client.icccm.transient_for)))
366           {
367              _policy_border_set_focus(prev);
368              return;
369           }
370      }
371
372    /* determine layering position */
373    pos = _policy_border_layer_map(bd->layer);
374
375    /* Find the windows below this one */
376    for (i = pos; i >= 2; i--)
377      {
378         E_Border *b;
379
380         EINA_LIST_REVERSE_FOREACH(bd->zone->container->layers[i].clients, l, b)
381           {
382              if (!b) continue;
383
384              /* skip if it's the same border */
385              if (b == bd) continue;
386
387              /* skip if it's not on this zone */
388              if (b->zone != bd->zone) continue;
389
390              /* skip special borders */
391              if (e_illume_border_is_indicator(b)) continue;
392              if (e_illume_border_is_keyboard(b)) continue;
393              if (e_illume_border_is_keyboard_sub(b)) continue;
394              if (e_illume_border_is_quickpanel(b)) continue;
395              if (e_illume_border_is_quickpanel_popup(b)) continue;
396              if (e_illume_border_is_clipboard(b)) continue;
397
398              if ((bd->fullscreen) || (bd->need_fullscreen))
399                {
400                   _policy_border_set_focus(b);
401                   return;
402                }
403              else
404                {
405                   /* need to check x/y position */
406                   if (E_CONTAINS(bd->x, bd->y, bd->w, bd->h,
407                                  b->x, b->y, b->w, b->h))
408                     {
409                        _policy_border_set_focus(b);
410                        return;
411                     }
412                }
413           }
414      }
415
416    /* if we reach here, then there is a problem with showing a window below
417     * this one, so show previous window in stack */
418    EINA_LIST_REVERSE_FOREACH(_pol_focus_stack, l, prev)
419      {
420         if (!prev) continue;
421         if (prev->zone != bd->zone) continue;
422         _policy_border_set_focus(prev);
423         return;
424      }
425 }
426
427 static void
428 _policy_zone_layout_update(E_Zone *zone)
429 {
430    Eina_List *l;
431    E_Border *bd;
432
433    if (!zone) return;
434
435    EINA_LIST_FOREACH(e_border_client_list(), l, bd)
436      {
437         if (!bd) continue;
438
439         /* skip borders not on this zone */
440         if (bd->zone != zone) continue;
441
442         /* skip special windows */
443         if (e_illume_border_is_keyboard(bd)) continue;
444         if (e_illume_border_is_keyboard_sub(bd)) continue;
445         if (e_illume_border_is_quickpanel(bd)) continue;
446         if (e_illume_border_is_quickpanel_popup(bd)) continue;
447
448         /* signal a changed pos here so layout gets updated */
449         bd->changes.pos = 1;
450         bd->changed = 1;
451      }
452 }
453
454 static void
455 _policy_zone_layout_indicator(E_Border *bd, E_Illume_Config_Zone *cz)
456 {
457    ILLUME2_TRACE ("[ILLUME2] %s (%d) win = 0x%07x\n", __func__, __LINE__, bd->client.win);
458
459    if ((!bd) || (!cz)) return;
460
461    /* grab minimum indicator size */
462    //e_illume_border_min_get(bd, NULL, &cz->indicator.size);
463
464    /* no point in doing anything here if indicator is hidden */
465    if ((!bd->new_client) && (!bd->visible)) return;
466
467    /* if we are dragging, then skip it for now */
468    if (bd->client.illume.drag.drag)
469      {
470         /* when dragging indicator, we need to trigger a layout update */
471         _policy_zone_layout_update(bd->zone);
472         return;
473      }
474
475    /* lock indicator window from dragging if we need to */
476    if ((cz->mode.dual == 1) && (cz->mode.side == 0))
477       ecore_x_e_illume_drag_locked_set(bd->client.win, 0);
478    else
479       ecore_x_e_illume_drag_locked_set(bd->client.win, 1);
480
481    /* make sure it's the required width & height */
482    int rotation = _policy_window_rotation_angle_get(bd->client.win);
483    if(rotation == -1) return;
484
485    ILLUME2_TRACE ("ILLUME2] INDICATOR'S ANGLE = %d\n", rotation);
486
487    // check indicator's rotation info and then set it's geometry
488    if (rotation == 0 || rotation == 180)
489      {
490         ecore_x_e_illume_indicator_geometry_set(bd->zone->black_win, bd->x, bd->y, bd->w, bd->h);
491         ecore_x_e_illume_indicator_geometry_set(bd->zone->container->manager->root, bd->x, bd->y, bd->w, bd->h);
492      }
493    else
494      {
495         ecore_x_e_illume_indicator_geometry_set(bd->zone->black_win, bd->zone->x, bd->zone->y, bd->h, bd->w);
496         ecore_x_e_illume_indicator_geometry_set(bd->zone->container->manager->root, bd->zone->x, bd->zone->y, bd->h, bd->w);
497      }
498 }
499
500 static void
501 _policy_zone_layout_quickpanel(E_Border *bd)
502 {
503    if (!bd) return;
504
505    if (E_ILLUME_BORDER_IS_IN_MOBILE(bd))
506      {
507         if ((bd->w != bd->zone->w) || (bd->h != bd->zone->h))
508           _policy_border_resize(bd, bd->zone->w, bd->zone->h);
509      }
510
511 /*
512    int rotation;
513    rotation = _policy_window_rotation_angle_get (bd->client.win);
514    ILLUME2_TRACE ("[ILLUME2-QUICKPANEL] _policy_zone_layout_quickpanel..(%d) rotation angle = %d\n", __LINE__, rotation);
515
516    if (rotation == 0 || rotation == 180)
517      {
518         if ((bd->w != bd->zone->w))
519           {
520              ILLUME2_TRACE ("[ILLUME2-QUICKPANEL] CHANGE QUICK-PANEL SIZE to Portrait..(%d) old (%d, %d)  new (%d, %d)\n", __LINE__, bd->w, bd->h, bd->zone->w, bd->h);
521              _policy_border_resize(bd, bd->zone->w, bd->h);
522           }
523      }
524    else
525      {
526         if ((bd->h != bd->zone->h))
527           {
528              ILLUME2_TRACE ("[ILLUME2-QUICKPANEL] CHANGE QUICK-PANEL SIZE to Landscape..(%d) old (%d, %d)  new (%d, %d)\n", __LINE__, bd->w, bd->h, bd->w, bd->zone->h);
529              _policy_border_resize(bd, bd->w, bd->zone->h);
530           }
531      }
532 */
533 }
534
535 static void _policy_zone_layout_quickpanel_popup(E_Border *bd)
536 {
537    if (!bd) return;
538
539    // Do something
540 }
541
542 static void
543 _policy_zone_layout_keyboard(E_Border *bd, E_Illume_Config_Zone *cz)
544 {
545    if ((!bd) || (!cz)) return;
546
547    /* no point in adjusting size or position if it's not visible */
548    if (!bd->visible) return;
549
550    /* set layer if needed */
551    if (bd->client.icccm.transient_for == 0)
552      {
553         if (bd->layer != POL_KEYBOARD_LAYER)
554            e_border_layer_set(bd, POL_KEYBOARD_LAYER);
555      }
556 }
557
558
559 static void
560 _policy_zone_layout_fullscreen(E_Border *bd)
561 {
562    //   printf("\tLayout Fullscreen: %s\n", bd->client.icccm.name);
563
564    if (!bd) return;
565
566    /* make sure it's the required width & height */
567    if ((bd->w != bd->zone->w) || (bd->h != bd->zone->h))
568       _policy_border_resize(bd, bd->zone->w, bd->zone->h);
569
570    /* set layer if needed */
571    if (bd->layer != POL_FULLSCREEN_LAYER)
572       e_border_layer_set(bd, POL_FULLSCREEN_LAYER);
573 }
574
575 static void
576 _policy_zone_layout_dialog(E_Border *bd, E_Illume_Config_Zone *cz)
577 {
578    E_Border *parent;
579    int mw, mh, nx, ny;
580    Eina_Bool resize = EINA_FALSE;
581    Eina_Bool move = EINA_FALSE;
582
583    //   printf("\tLayout Dialog: %s\n", bd->client.icccm.name);
584
585    /* NB: This policy ignores any ICCCM requested positions and centers the
586     * dialog on it's parent (if it exists) or on the zone */
587
588    if ((!bd) || (!cz)) return;
589
590    /* no point in adjusting size or position if it's not visible */
591    if (!bd->visible) return;
592
593    /* grab minimum size */
594    e_illume_border_min_get(bd, &mw, &mh);
595
596    /* make sure it fits in this zone */
597    if (mw > bd->zone->w) mw = bd->zone->w;
598    if (mh > bd->zone->h) mh = bd->zone->h;
599
600    if (mw < bd->w) mw = bd->w;
601    if (mh < bd->h) mh = bd->h;
602
603    /* try to get this dialog's parent if it exists */
604    parent = e_illume_border_parent_get(bd);
605
606    /* if we have no parent, or we are in dual mode, then center on zone */
607    /* NB: we check dual mode because if we are in dual mode, dialogs tend to
608     * be too small to be useful when positioned on the parent, so center
609     * on zone. We could check their size first here tho */
610    if ((!parent) || (cz->mode.dual == 1))
611      {
612         /* no parent or dual mode, center on screen */
613         nx = (bd->zone->x + ((bd->zone->w - mw) / 2));
614         ny = (bd->zone->y + ((bd->zone->h - mh) / 2));
615      }
616    else
617      {
618         /* NB: there is an assumption here that the parent has already been
619          * layed out on screen. This could be bad. Needs Testing */
620
621         /* make sure we are not larger than the parent window */
622         if (mw > parent->w) mw = parent->w;
623         if (mh > parent->h) mh = parent->h;
624
625         /* center on parent */
626         nx = (parent->x + ((parent->w - mw) / 2));
627         ny = (parent->y + ((parent->h - mh) / 2));
628      }
629
630    /* make sure it's the required width & height */
631    if ((bd->w != mw) || (bd->h != mh))
632      resize = EINA_TRUE;
633
634    /* make sure it's in the correct position */
635    if ((bd->x != nx) || (bd->y != ny))
636      move = EINA_TRUE;
637
638    if (resize && move)
639      e_border_move_resize(bd, nx, ny, mw, mh);
640    else if (resize)
641      _policy_border_resize(bd, mw, mh);
642    else if (move)
643      _policy_border_move(bd, nx, ny);
644
645    /* set layer if needed */
646    if (bd->layer != POL_DIALOG_LAYER) e_border_layer_set(bd, POL_DIALOG_LAYER);
647 }
648
649 static void
650 _policy_zone_layout_splash(E_Border *bd, E_Illume_Config_Zone *cz)
651 {
652    int mw, mh, nx, ny;
653    Eina_Bool resize = EINA_FALSE;
654    Eina_Bool move = EINA_FALSE;
655
656    if ((!bd) || (!cz)) return;
657
658    /* no point in adjusting size or position if it's not visible */
659    if ((!bd->new_client) && (!bd->visible)) return;
660
661    /* grab minimum size */
662    e_illume_border_min_get(bd, &mw, &mh);
663
664    /* make sure it fits in this zone */
665    if (mw > bd->zone->w) mw = bd->zone->w;
666    if (mh > bd->zone->h) mh = bd->zone->h;
667
668    if (mw < bd->w) mw = bd->w;
669    if (mh < bd->h) mh = bd->h;
670
671    nx = (bd->zone->x + ((bd->zone->w - mw) / 2));
672    ny = (bd->zone->y + ((bd->zone->h - mh) / 2));
673
674    if ((bd->w != mw) || (bd->h != mh))
675      resize = EINA_TRUE;
676
677    if ((bd->x != nx) || (bd->y != ny))
678      move = EINA_TRUE;
679
680    if (resize && move)
681      e_border_move_resize(bd, nx, ny, mw, mh);
682    else if (resize)
683      _policy_border_resize(bd, mw, mh);
684    else if (move)
685      _policy_border_move(bd, nx, ny);
686 }
687
688 static void
689 _policy_zone_layout_clipboard(E_Border *bd, E_Illume_Config_Zone *cz)
690 {
691    /* no point in adjusting size or position if it's not visible */
692    if (!bd->visible) return;
693
694    /* set layer if needed */
695    if (bd->layer != POL_CLIPBOARD_LAYER)
696       e_border_layer_set(bd, POL_CLIPBOARD_LAYER);
697 }
698
699 static void
700 _policy_zone_layout_apptray(E_Border *bd)
701 {
702    if (!bd) return;
703
704    if (E_ILLUME_BORDER_IS_IN_MOBILE(bd))
705      {
706         if ((bd->w != bd->zone->w) || (bd->h != bd->zone->h))
707           _policy_border_resize(bd, bd->zone->w, bd->zone->h);
708      }
709
710    /* set layer if needed */
711    if (bd->layer != POL_APPTRAY_LAYER)
712       e_border_layer_set(bd, POL_APPTRAY_LAYER);
713 }
714
715 static void
716 _policy_zone_layout_miniapptray(E_Border *bd)
717 {
718    if (!bd) return;
719
720    if (E_ILLUME_BORDER_IS_IN_MOBILE(bd))
721      {
722         if ((bd->w != bd->zone->w) || (bd->h != bd->zone->h))
723           _policy_border_resize(bd, bd->zone->w, bd->zone->h);
724      }
725
726    /* set layer if needed */
727    if (bd->layer != POL_APPTRAY_LAYER)
728       e_border_layer_set(bd, POL_APPTRAY_LAYER);
729 }
730
731 /* policy functions */
732 void
733 _policy_border_add(E_Border *bd)
734 {
735    //   printf("Border added: %s\n", bd->client.icccm.class);
736
737    if (!bd) return;
738
739    /* NB: this call sets an atom on the window that specifices the zone.
740     * the logic here is that any new windows created can access the zone
741     * window by a 'get' call. This is useful for elementary apps as they
742     * normally would not have access to the zone window. Typical use case
743     * is for indicator & softkey windows so that they can send messages
744     * that apply to their respective zone only. Example: softkey sends close
745     * messages (or back messages to cycle focus) that should pertain just
746     * to it's current zone */
747    ecore_x_e_illume_zone_set(bd->client.win, bd->zone->black_win);
748
749    ILLUME2_TRACE ("[ILLUME2-NEW] %s(%d)... bd = 0x%07x\n", __func__, __LINE__, bd->client.win);
750
751    /* ignore stolen borders. These are typically quickpanel or keyboards */
752    if (bd->stolen)
753      {
754         if (e_illume_border_is_quickpanel(bd) ||
755             e_illume_border_is_quickpanel_popup(bd))
756           {
757              E_Border* indi_bd;
758              E_Illume_Border_Info* bd_info = NULL;
759              E_Illume_Border_Info* indi_bd_info = NULL;
760
761              /* try to get the Indicator on this zone */
762              if ((indi_bd = e_illume_border_indicator_get(bd->zone)))
763                {
764                   if ((indi_bd_info = _policy_get_border_info(indi_bd)))
765                     {
766                        if ((bd_info = _policy_get_border_info(bd)))
767                           bd_info->level = indi_bd_info->level;
768                     }
769                }
770           }
771         return;
772      }
773
774    /* Add this border to our focus stack if it can accept or take focus */
775    if ((bd->client.icccm.accepts_focus) || (bd->client.icccm.take_focus))
776       _pol_focus_stack = eina_list_append(_pol_focus_stack, bd);
777
778    if (e_illume_border_is_indicator(bd))
779       _policy_zone_layout_update(bd->zone);
780    else
781      {
782         /* set focus on new border if we can */
783         _policy_border_set_focus(bd);
784      }
785
786    if (e_illume_border_is_indicator (bd))
787      {
788         E_Illume_Config_Zone *cz;
789         cz = e_illume_zone_config_get(bd->zone->id);
790         if (cz)
791           {
792              ILLUME2_TRACE ("[ILLUME2] ADD INDICATOR WINDOW... win = 0x%07x, Save indicator's size = %d!!!\n", bd->client.win, bd->h);
793              cz->indicator.size = bd->h;
794           }
795
796         if (_e_illume_cfg->use_indicator_widget)
797           {
798              L(LT_ANGLE, "[ILLUME2][ANGLE] %s(%d)... Control Root Angle.\n", __func__, __LINE__);
799              _policy_border_root_angle_control(bd->zone);
800           }
801         else
802           {
803              L(LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... win = 0x%07x..  Control Indicator.\n", __func__, __LINE__, bd->client.win);
804              _policy_border_indicator_control(bd);
805           }
806      }
807 }
808
809 void
810 _policy_border_del(E_Border *bd)
811 {
812    //   printf("Border deleted: %s\n", bd->client.icccm.class);
813    E_Illume_XWin_Info* xwin_info;
814    Eina_Bool is_rotated_win = EINA_FALSE;
815
816    if (!bd) return;
817
818    /* if this is a fullscreen window, than we need to show indicator window */
819    /* NB: we could use the e_illume_border_is_fullscreen function here
820     * but we save ourselves a function call this way */
821    if ((bd->fullscreen) || (bd->need_fullscreen))
822      {
823         E_Border *indi_bd;
824
825         /* try to get the Indicator on this zone */
826         if ((indi_bd = e_illume_border_indicator_get(bd->zone)))
827           {
828              /* we have the indicator, show it if needed */
829              if (!indi_bd->visible)
830                {
831                   L(LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... Show Indicator (by win: 0x%07x)\n", __func__, __LINE__, bd->client.win);
832                   e_illume_border_show(indi_bd);
833                }
834           }
835      }
836
837    if (e_illume_border_is_clipboard(bd))
838      {
839         ecore_x_e_illume_clipboard_state_set(bd->zone->black_win, ECORE_X_ILLUME_CLIPBOARD_STATE_OFF);
840      }
841
842    /* remove from our focus stack */
843    if ((bd->client.icccm.accepts_focus) || (bd->client.icccm.take_focus))
844       _pol_focus_stack = eina_list_remove(_pol_focus_stack, bd);
845
846    if (g_rotated_win == bd->client.win)
847      {
848         is_rotated_win = EINA_TRUE;
849         g_rotated_win = 0;
850      }
851
852    xwin_info = _policy_xwin_info_find (bd->win);
853    if (xwin_info)
854      {
855         if (_e_illume_cfg->use_force_iconify)
856           {
857              L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d)... DELETE win:0x%07x\n", __func__, __LINE__, bd->client.win);
858              if (!(e_illume_border_is_indicator(bd) ||
859                    e_illume_border_is_keyboard(bd) ||
860                    e_illume_border_is_keyboard_sub(bd) ||
861                    e_illume_border_is_quickpanel(bd) ||
862                    e_illume_border_is_quickpanel_popup(bd) ||
863                    e_illume_border_is_clipboard(bd) ||
864                    e_illume_border_is_app_tray(bd) ||
865                    e_illume_border_is_miniapp_tray(bd)))
866                {
867                   _policy_border_uniconify_below_borders_by_illume(xwin_info);
868                }
869           }
870
871         if (xwin_info->visibility != E_ILLUME_VISIBILITY_FULLY_OBSCURED)
872           {
873              if (_e_illume_cfg->use_indicator_widget)
874                {
875                   if ((bd->w == bd->zone->w) && (bd->h == bd->zone->h))
876                     {
877                        L(LT_ANGLE, "[ILLUME2][ANGLE] %s(%d)... Deleted win:0x%07x. Control Root Angle.\n", __func__, __LINE__, bd->client.win);
878                        _policy_border_root_angle_control(bd->zone);
879                     }
880                }
881              else
882                {
883                   E_Border *indi_bd;
884                   indi_bd = e_illume_border_indicator_get(bd->zone);
885                   if (indi_bd)
886                     {
887                        L(LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... win = 0x%07x..  Control Indicator.\n", __func__, __LINE__, bd->client.win);
888                        _policy_border_indicator_control(indi_bd);
889                     }
890                }
891           }
892         xwin_info->bd_info = NULL;
893         xwin_info->attr.visible = 0;
894         xwin_info->viewable = EINA_FALSE;
895         xwin_info->is_drawed = EINA_FALSE;
896      }
897
898    E_Illume_Border_Info* bd_info = _policy_get_border_info(bd);
899    if (bd_info)
900      {
901         if (bd_info->resize_req.mouse.down)
902           {
903              e_grabinput_release(bd->event_win, bd->event_win);
904
905              if (bd_info->resize_req.mouse.resize)
906                {
907                   Evas_Object *o = (Evas_Object *)e_object_data_get(E_OBJECT(bd));
908                   if (o) evas_object_del(o);
909                }
910
911              /* set property on zone window that a drag is finished */
912              ecore_x_e_illume_drag_set(bd->zone->black_win, 0);
913
914              _policy_border_illume_handlers_remove(bd_info);
915           }
916      }
917
918    _policy_delete_border_info_list (bd);
919
920    if (e_illume_border_is_indicator(bd))
921      {
922         E_Illume_Config_Zone *cz;
923
924         /* get the config for this zone */
925         cz = e_illume_zone_config_get(bd->zone->id);
926         if (cz) cz->indicator.size = 0;
927         _policy_zone_layout_update(bd->zone);
928      }
929    else
930      {
931         /* show the border below this one */
932         _policy_border_show_below(bd);
933      }
934
935    if (e_illume_border_is_lock_screen(bd))
936      {
937         if (_e_illume_cfg->use_mem_trim)
938           {
939              /* heap and stack trim */
940              e_illume_util_mem_trim();
941           }
942      }
943
944    // for supporting rotation such as quickpanel
945    if (e_illume_border_is_quickpanel(bd) ||
946        e_illume_border_is_miniapp_tray(bd) ||
947        (bd->client.illume.win_state.state == ECORE_X_ILLUME_WINDOW_STATE_FLOATING) ||
948        e_illume_border_is_syspopup(bd) ||
949        e_illume_border_is_app_selector(bd))
950      dep_rot.list = eina_list_remove(dep_rot.list, bd);
951 }
952
953 void
954 _policy_border_focus_in(E_Border *bd __UNUSED__)
955 {
956    //   printf("Border focus in: %s\n", bd->client.icccm.name);
957 }
958
959 void
960 _policy_border_focus_out(E_Border *bd)
961 {
962    //   printf("Border focus out: %s\n", bd->client.icccm.name);
963
964    if (!bd) return;
965
966    /* NB: if we got this focus_out event on a deleted border, we check if
967     * it is a transient (child) of another window. If it is, then we
968     * transfer focus back to the parent window */
969    if (e_object_is_del(E_OBJECT(bd)))
970      {
971         if (e_illume_border_is_dialog(bd))
972           {
973              E_Border *parent;
974
975              if ((parent = e_illume_border_parent_get(bd)))
976                 _policy_border_set_focus(parent);
977           }
978      }
979 }
980
981 void
982 _policy_border_activate(E_Border *bd)
983 {
984    //   printf("Border Activate: %s\n", bd->client.icccm.name);
985    if (!bd) return;
986
987    /* NB: stolen borders may or may not need focus call...have to test */
988    if (bd->stolen) return;
989
990    /* NB: We cannot use our set_focus function here because it does,
991     * occasionally fall through wrt E's focus policy, so cherry pick the good
992     * parts and use here :) */
993
994    /* if the border is iconified then uniconify if allowed */
995    if ((bd->iconic) && (!bd->lock_user_iconify))
996       e_border_uniconify(bd);
997
998    ILLUME2_TRACE ("[ILLUME2] _policy_border_activate.. (%d) ACTIVE WIN = 0x%07x\n", __LINE__, bd->client.win);
999
1000    /* NB: since we skip needless border evals when container layout
1001     * is called (to save cpu cycles), we need to
1002     * signal this border that it's focused so that the edj gets
1003     * updated.
1004     *
1005     * This is potentially useless as THIS policy
1006     * makes all windows borderless anyway, but it's in here for
1007     * completeness
1008     e_border_focus_latest_set(bd);
1009     if (bd->bg_object)
1010     edje_object_signal_emit(bd->bg_object, "e,state,focused", "e");
1011     if (bd->icon_object)
1012     edje_object_signal_emit(bd->icon_object, "e,state,focused", "e");
1013     e_focus_event_focus_in(bd);
1014     */
1015 }
1016
1017 void
1018 _policy_border_post_fetch(E_Border *bd)
1019 {
1020    //   printf("Border post fetch\n");
1021
1022    if (!bd) return;
1023
1024    /* NB: for this policy we disable all remembers set on a border */
1025    if (bd->remember) e_remember_del(bd->remember);
1026    bd->remember = NULL;
1027
1028    /* set this border to borderless */
1029 #ifdef DIALOG_USES_PIXEL_BORDER
1030    if ((e_illume_border_is_dialog(bd)) && (e_illume_border_parent_get(bd)))
1031       eina_stringshare_replace(&bd->bordername, "pixel");
1032    else
1033       bd->borderless = 1;
1034 #else
1035    /* for desktop mode */
1036    if (E_ILLUME_BORDER_IS_IN_MOBILE(bd))
1037      bd->borderless = 1;
1038    else if (E_ILLUME_BORDER_IS_IN_DESKTOP(bd))
1039      {
1040         if (!bd->client.illume.win_state.state)
1041           {
1042              bd->borderless = 0;
1043           }
1044      }
1045 #endif
1046
1047    // for supporting rotation such as quickpanel
1048    if (e_illume_border_is_quickpanel(bd) ||
1049        e_illume_border_is_miniapp_tray(bd) ||
1050        (bd->client.illume.win_state.state == ECORE_X_ILLUME_WINDOW_STATE_FLOATING) ||
1051        e_illume_border_is_syspopup(bd) ||
1052        e_illume_border_is_app_selector(bd))
1053      {
1054         bd->client.e.state.rot.type = E_BORDER_ROTATION_TYPE_DEPENDENT;
1055         if (!eina_list_data_find(dep_rot.list, bd))
1056           {
1057              int prev_ang = -1;
1058
1059              dep_rot.list = eina_list_append(dep_rot.list, bd);
1060
1061              if (_prev_angle_get(bd->client.win) != -1)
1062                bd->client.e.state.rot.curr = prev_ang;
1063
1064              if (dep_rot.ang != bd->client.e.state.rot.curr)
1065                e_border_rotation_set(bd, dep_rot.ang);
1066           }
1067      }
1068
1069    /* tell E the border has changed */
1070    bd->client.border.changed = 1;
1071 }
1072
1073
1074 void
1075 _policy_border_post_new_border(E_Border *bd)
1076 {
1077    int layer = 0;
1078    E_Illume_Border_Info* bd_info = NULL;
1079
1080    if (bd->new_client)
1081      {
1082         bd_info = _policy_get_border_info(bd);
1083         if (!bd_info) return;
1084
1085         bd_info->win_type = bd->client.netwm.type;
1086
1087         if (e_illume_border_is_notification(bd))
1088           {
1089              bd_info->level = _policy_border_get_notification_level(bd->client.win);
1090              layer = _policy_notification_level_map(bd_info->level);
1091              e_border_layer_set(bd, layer);
1092              L (LT_NOTIFICATION, "[ILLUME2][NOTIFICATION] %s(%d)... win (0x%07x) is notification window... level = %d\n",
1093                 __func__, __LINE__, bd->client.win, bd_info->level);
1094           }
1095      }
1096 }
1097
1098 static Eina_Bool
1099 _check_parent_in_transient_for_tree(E_Border *bd, E_Border *parent_bd)
1100 {
1101    E_Border *ancestor;
1102
1103    if (!bd || !parent_bd) return EINA_FALSE;
1104
1105    ancestor = parent_bd;
1106    while (ancestor->parent)
1107      {
1108         if (ancestor->parent == bd)
1109           {
1110              // This is very bad. bd and parent_bd are transient_for each other
1111 #ifdef USE_DLOG
1112              SECURE_SLOGD("[WM] Transient_for Error!!! Win:0x%07x and Parent:0x%07x are transient_for each other.", bd->client.win, parent_bd->client.win);
1113 #endif
1114              ELBF(ELBT_ILLUME, 0, bd->client.win, "BAD. Transient_for Error. Parent:0x%07x is descendant", parent_bd->client.win);
1115              return EINA_TRUE;
1116           }
1117         ancestor = ancestor->parent;
1118      }
1119
1120    return EINA_FALSE;
1121 }
1122
1123 void
1124 _policy_border_pre_fetch(E_Border *bd)
1125 {
1126 #ifdef _F_DEICONIFY_APPROVE_
1127    Eina_Bool change_parent = EINA_TRUE;
1128 #endif
1129
1130    if (!bd) return;
1131
1132    if (bd->new_client)
1133      {
1134         unsigned int state;
1135         state = ecore_x_e_illume_window_state_get(bd->client.win);
1136         _policy_border_illume_window_state_change(bd, state);
1137      }
1138
1139    /* Below code are same to _e_border_eval0 in e_border.c.
1140       But we added code to handle notification window */
1141    if (bd->client.icccm.fetch.transient_for)
1142      {
1143         /* TODO: What do to if the transient for isn't mapped yet? */
1144         E_Border *bd_parent = NULL;
1145         E_Illume_XWin_Info *xwin_info = NULL;
1146         Eina_Bool transient_each_other;
1147         Ecore_X_Window transient_for_win;
1148
1149         if (_e_illume_cfg->use_force_iconify)
1150           xwin_info = _policy_xwin_info_find(bd->win);
1151
1152         transient_for_win = ecore_x_icccm_transient_for_get(bd->client.win);
1153         if (bd->client.icccm.transient_for == transient_for_win)
1154           {
1155              ELBF(ELBT_ILLUME, 0, bd->client.win, "Same transient_for:0x%07x. SKIP...", transient_for_win);
1156              goto transient_fetch_done;
1157           }
1158
1159         bd->client.icccm.transient_for = transient_for_win;
1160         if (bd->client.icccm.transient_for)
1161           {
1162              bd_parent = e_border_find_by_client_window(bd->client.icccm.transient_for);
1163           }
1164
1165         /* If we already have a parent, remove it */
1166         if (bd->parent)
1167           {
1168 #ifdef _F_DEICONIFY_APPROVE_
1169              if (bd_parent == bd->parent) change_parent = EINA_FALSE;
1170 #endif
1171              bd->parent->transients = eina_list_remove(bd->parent->transients, bd);
1172              if (bd->parent->modal == bd) bd->parent->modal = NULL;
1173              bd->parent = NULL;
1174           }
1175
1176         L(LT_TRANSIENT_FOR, "[ILLUME2][TRANSIENT_FOR] %s(%d)... win:0x%07x, parent:0x%07x\n", __func__, __LINE__, bd->client.win, bd->client.icccm.transient_for);
1177         if (bd_parent)
1178           {
1179              transient_each_other = _check_parent_in_transient_for_tree(bd, bd_parent);
1180              if (!transient_each_other)
1181                {
1182                   L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d).. win:0x%07x(iconic:%d, by_wm:%d), parent:0x%07x(iconic:%d)\n", __func__, __LINE__, bd->client.win, bd->iconic, xwin_info ? xwin_info->iconify_by_wm : -100, bd_parent->client.win, bd_parent->iconic);
1183                   if (_e_illume_cfg->use_force_iconify)
1184                     {
1185                        if (!bd_parent->iconic)
1186                          {
1187                             if (xwin_info && xwin_info->iconify_by_wm)
1188                               {
1189                                  if (bd->iconic)
1190                                    {
1191                                       L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d).. FORCE UNICONIFY... win:0x%07x\n", __func__, __LINE__, bd->client.win);
1192                                       _policy_border_force_uniconify(bd);
1193                                    }
1194                               }
1195                          }
1196                     }
1197
1198                   if (bd_parent != bd)
1199                     {
1200                        bd->parent = bd_parent;
1201                        _policy_border_transient_for_layer_set(bd, bd->parent, bd->parent->layer);
1202                        bd_parent->transients = eina_list_append(bd_parent->transients, bd);
1203
1204                        if ((e_config->modal_windows) && (bd->client.netwm.state.modal))
1205                          bd->parent->modal = bd;
1206
1207                        if (e_config->focus_setting == E_FOCUS_NEW_DIALOG ||
1208                            (bd->parent->focused && (e_config->focus_setting == E_FOCUS_NEW_DIALOG_IF_OWNER_FOCUSED)))
1209                          bd->take_focus = 1;
1210                     }
1211                }
1212           }
1213
1214 #ifdef _F_DEICONIFY_APPROVE_
1215         if (change_parent)
1216           {
1217              E_Border *ancestor_bd;
1218              bd->client.e.state.deiconify_approve.render_done = 0;
1219
1220              ancestor_bd = bd->client.e.state.deiconify_approve.ancestor;
1221              if ((ancestor_bd) &&
1222                  (!e_object_is_del(E_OBJECT(ancestor_bd))))
1223                {
1224                   ancestor_bd->client.e.state.deiconify_approve.req_list = eina_list_remove(ancestor_bd->client.e.state.deiconify_approve.req_list, bd);
1225                   bd->client.e.state.deiconify_approve.ancestor = NULL;
1226
1227                   if ((ancestor_bd->client.e.state.deiconify_approve.req_list == NULL) &&
1228                       (ancestor_bd->client.e.state.deiconify_approve.render_done))
1229                     {
1230                        if (ancestor_bd->client.e.state.deiconify_approve.wait_timer)
1231                          {
1232                             ecore_timer_del(ancestor_bd->client.e.state.deiconify_approve.wait_timer);
1233                             ancestor_bd->client.e.state.deiconify_approve.wait_timer = NULL;
1234                             e_border_uniconify(ancestor_bd);
1235                          }
1236                     }
1237                }
1238           }
1239 #endif
1240
1241 transient_fetch_done:
1242         bd->client.icccm.fetch.transient_for = 0;
1243      }
1244 }
1245
1246 void
1247 _policy_border_new_border(E_Border *bd)
1248 {
1249    if (!bd) return;
1250
1251    if (bd->zone)
1252      ecore_x_e_illume_zone_set(bd->client.win, bd->zone->black_win);
1253
1254    _policy_add_border_info_list(bd);
1255 }
1256
1257 #ifdef _F_BORDER_HOOK_PATCH_
1258 void
1259 _policy_border_del_border(E_Border *bd)
1260 {
1261    if (!bd) return;
1262
1263    if (bd->new_client)
1264      {
1265         _policy_border_del(bd);
1266      }
1267 }
1268 #endif
1269
1270 void
1271 _policy_border_post_assign(E_Border *bd)
1272 {
1273    //   printf("Border post assign\n");
1274
1275    if (!bd) return;
1276    if (!bd->new_client) return;
1277
1278    bd->internal_no_remember = 1;
1279
1280    /* do not allow client to change these properties */
1281    bd->lock_client_shade = 1;
1282
1283    if (e_illume_border_is_utility (bd))
1284      {
1285         ILLUME2_TRACE ("[ILLUME2-NEW] %s(%d)... win(0x%07x) is UTILITY type.. SET REQUEST_POS!!!\n", __func__, __LINE__, bd->client.win);
1286         bd->client.icccm.request_pos = 1;
1287      }
1288
1289    /* do not allow the user to change these properties */
1290    /* for desktop mode */
1291    if (E_ILLUME_BORDER_IS_IN_MOBILE(bd))
1292      {
1293         if (bd->client.illume.win_state.state)
1294           {
1295              bd->lock_user_location = 0;
1296              bd->lock_user_size = 0;
1297           }
1298         else
1299           {
1300              bd->lock_user_location = 1;
1301              bd->lock_user_size = 1;
1302           }
1303         bd->lock_user_shade = 1;
1304         if (bd->client.icccm.request_pos == 0)
1305           {
1306              bd->placed = 1;
1307              bd->changes.pos = 1;
1308           }
1309      }
1310
1311    bd->lock_user_shade = 1;
1312
1313    /* clear any centered states */
1314    /* NB: this is mainly needed for E's main config dialog */
1315    bd->client.e.state.centered = 0;
1316
1317    /* lock the border type so user/client cannot change */
1318    bd->lock_border = 1;
1319 }
1320
1321 void
1322 _policy_border_show(E_Border *bd)
1323 {
1324    if (!bd) return;
1325
1326    /* make sure we have a name so that we don't handle windows like E's root */
1327    if (!bd->client.icccm.name) return;
1328
1329    //   printf("Border Show: %s\n", bd->client.icccm.class);
1330
1331    /* trap for special windows so we can ignore hides below them */
1332    if (e_illume_border_is_indicator(bd)) return;
1333    if (e_illume_border_is_quickpanel(bd)) return;
1334    if (e_illume_border_is_quickpanel_popup(bd)) return;
1335
1336    if (e_illume_border_is_keyboard(bd))
1337      {
1338         int angle;
1339         angle = _policy_window_rotation_angle_get(bd->client.win);
1340         if (angle != -1)
1341           {
1342              if (angle != g_root_angle)
1343                {
1344                   L(LT_ANGLE, "[ILLUME2][ANGLE] %s(%d)... win = 0x%07x..  SEND client Event with angle = %d\n", __func__, __LINE__, bd->client.win, g_root_angle);
1345                   ecore_x_client_message32_send(bd->client.win, ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE,
1346                                                 ECORE_X_EVENT_MASK_WINDOW_CONFIGURE, g_root_angle, g_active_win, 0, 0, 0);
1347                }
1348           }
1349
1350         return;
1351      }
1352
1353    if (e_illume_border_is_clipboard(bd))
1354      {
1355         ecore_x_e_illume_clipboard_state_set(bd->zone->black_win, ECORE_X_ILLUME_CLIPBOARD_STATE_ON);
1356         ecore_x_e_illume_clipboard_geometry_set(bd->zone->black_win, bd->x, bd->y, bd->w, bd->h);
1357         return;
1358      }
1359
1360    if (eina_list_data_find(dep_rot.list, bd) == bd)
1361      e_border_rotation_set(bd, dep_rot.ang);
1362 }
1363
1364 void
1365 _policy_border_cb_move(E_Border *bd)
1366 {
1367    if (!bd) return;
1368
1369    if (e_illume_border_is_app_tray(bd) ||
1370        e_illume_border_is_miniapp_tray(bd))
1371      {
1372         _policy_border_focus_top_stack_set(bd);
1373      }
1374
1375    return;
1376 }
1377
1378 void
1379 _policy_zone_layout(E_Zone *zone)
1380 {
1381    E_Illume_Config_Zone *cz;
1382    Eina_List *l;
1383    E_Border *bd;
1384
1385    //   printf("Zone Layout: %d\n", zone->id);
1386
1387    if (!zone) return;
1388
1389    /* get the config for this zone */
1390    cz = e_illume_zone_config_get(zone->id);
1391    if (!cz) return;
1392
1393    /* loop through border list and update layout */
1394    E_Illume_Border_Info* bd_info;
1395    EINA_LIST_FOREACH(e_border_info_list, l, bd_info)
1396      {
1397         if (!bd_info) continue;
1398
1399         bd = bd_info->border;
1400
1401         /* skip borders that are being deleted */
1402         if (e_object_is_del(E_OBJECT(bd))) continue;
1403
1404         /* skip borders not on this zone */
1405         if (bd->zone != zone) continue;
1406
1407         /* only update layout for this border if it really needs it */
1408         if ((!bd->new_client) && (!bd->changes.pos) && (!bd->changes.size) &&
1409             (!bd->changes.visible) && (!bd->pending_move_resize) &&
1410             (!bd->need_shape_export) && (!bd->need_shape_merge)) continue;
1411
1412         /* are we laying out an indicator ? */
1413         if (e_illume_border_is_indicator(bd))
1414            _policy_zone_layout_indicator(bd, cz);
1415
1416         /* are we layout out a quickpanel ? */
1417         else if (e_illume_border_is_quickpanel(bd))
1418            _policy_zone_layout_quickpanel(bd);
1419
1420         else if (e_illume_border_is_quickpanel_popup(bd))
1421            _policy_zone_layout_quickpanel_popup(bd);
1422
1423         /* are we laying out a keyboard ? */
1424         else if (e_illume_border_is_keyboard(bd))
1425            _policy_zone_layout_keyboard(bd, cz);
1426
1427         else if (e_illume_border_is_keyboard_sub(bd))
1428            _policy_zone_layout_keyboard(bd, cz);
1429
1430         /* are we laying out a fullscreen window ? */
1431         /* NB: we could use the e_illume_border_is_fullscreen function here
1432          * but we save ourselves a function call this way. */
1433         else if ((bd->fullscreen) || (bd->need_fullscreen))
1434            _policy_zone_layout_fullscreen(bd);
1435
1436         /* are we laying out a dialog ? */
1437         else if (e_illume_border_is_dialog(bd))
1438            _policy_zone_layout_dialog(bd, cz);
1439
1440         else if (e_illume_border_is_splash(bd))
1441            _policy_zone_layout_splash(bd, cz);
1442
1443         else if (e_illume_border_is_clipboard(bd))
1444            _policy_zone_layout_clipboard(bd, cz);
1445
1446         else if (e_illume_border_is_app_tray(bd))
1447            _policy_zone_layout_apptray(bd);
1448
1449         else if (e_illume_border_is_miniapp_tray(bd))
1450            _policy_zone_layout_miniapptray(bd);
1451
1452         /* must be an app */
1453         else
1454           {
1455              /* are we in single mode ? */
1456              if (!cz->mode.dual)
1457                {
1458                   /* for desktop mode */
1459                   if (E_ILLUME_BORDER_IS_IN_MOBILE(bd))
1460                     _policy_zone_layout_app_single_new(bd_info, cz);
1461                   else if (E_ILLUME_BORDER_IS_IN_DESKTOP(bd))
1462                     _policy_zone_layout_app_single_monitor(bd_info, cz);
1463                   else
1464                     _policy_zone_layout_app_single_new(bd_info, cz);
1465                }
1466              else
1467                {
1468                   /* we are in dual-mode, check orientation */
1469                   if (cz->mode.side == 0)
1470                     {
1471                        int ty;
1472
1473                        /* grab the indicator position so we can tell if it
1474                         * is in a custom position or not (user dragged it) */
1475                        e_illume_border_indicator_pos_get(bd->zone, NULL, &ty);
1476                        if (ty <= bd->zone->y)
1477                           _policy_zone_layout_app_dual_top_new (bd_info, cz);
1478                        else
1479                           _policy_zone_layout_app_dual_custom_new (bd_info, cz);
1480                     }
1481                   else
1482                      _policy_zone_layout_app_dual_left_new (bd_info, cz);
1483                }
1484           }
1485      }
1486 }
1487
1488 void
1489 _policy_zone_move_resize(E_Zone *zone)
1490 {
1491    Eina_List *l;
1492    E_Border *bd;
1493
1494    //   printf("Zone move resize\n");
1495
1496    if (!zone) return;
1497
1498    ecore_x_window_size_get (zone->container->manager->root, &_g_root_width, &_g_root_height);
1499
1500    EINA_LIST_FOREACH(e_border_client_list(), l, bd)
1501      {
1502         if (!bd) continue;
1503         /* skip borders not on this zone */
1504         if (bd->zone != zone) continue;
1505
1506         /* signal a changed pos here so layout gets updated */
1507         bd->changes.pos = 1;
1508         bd->changed = 1;
1509      }
1510 }
1511
1512 void
1513 _policy_zone_mode_change(E_Zone *zone, Ecore_X_Atom mode)
1514 {
1515    E_Illume_Config_Zone *cz;
1516    E_Border *bd;
1517
1518    //   printf("Zone mode change: %d\n", zone->id);
1519
1520    if (!zone) return;
1521
1522    /* get the config for this zone */
1523    cz = e_illume_zone_config_get(zone->id);
1524    if (!cz) return;
1525
1526    /* update config with new mode */
1527    if (mode == ECORE_X_ATOM_E_ILLUME_MODE_SINGLE)
1528       cz->mode.dual = 0;
1529    else
1530      {
1531         cz->mode.dual = 1;
1532         if (mode == ECORE_X_ATOM_E_ILLUME_MODE_DUAL_TOP)
1533            cz->mode.side = 0;
1534         else if (mode == ECORE_X_ATOM_E_ILLUME_MODE_DUAL_LEFT)
1535            cz->mode.side = 1;
1536      }
1537    e_config_save_queue();
1538
1539    /* lock indicator window from dragging if we need to */
1540    bd = e_illume_border_indicator_get(zone);
1541    if (bd)
1542      {
1543         /* only dual-top mode can drag */
1544         if ((cz->mode.dual == 1) && (cz->mode.side == 0))
1545           {
1546              /* only set locked if we need to */
1547              if (bd->client.illume.drag.locked != 0)
1548                 ecore_x_e_illume_drag_locked_set(bd->client.win, 0);
1549           }
1550         else
1551           {
1552              /* only set locked if we need to */
1553              if (bd->client.illume.drag.locked != 1)
1554                 ecore_x_e_illume_drag_locked_set(bd->client.win, 1);
1555           }
1556      }
1557
1558    /* Need to trigger a layout update here */
1559    _policy_zone_layout_update(zone);
1560 }
1561
1562 void
1563 _policy_zone_close(E_Zone *zone)
1564 {
1565    E_Border *bd;
1566
1567    //   printf("Zone close\n");
1568
1569    if (!zone) return;
1570
1571    /* make sure we have a focused border */
1572    if (!(bd = e_border_focused_get())) return;
1573
1574    /* make sure focused border is on this zone */
1575    if (bd->zone != zone) return;
1576
1577    /* close this border */
1578    e_border_act_close_begin(bd);
1579 }
1580
1581 void
1582 _policy_drag_start(E_Border *bd)
1583 {
1584    //   printf("Drag start\n");
1585
1586    if (!bd) return;
1587
1588    /* ignore stolen borders */
1589    if (bd->stolen) return;
1590
1591    if (!bd->visible) return;
1592
1593    /* set property on this border to say we are dragging */
1594    ecore_x_e_illume_drag_set(bd->client.win, 1);
1595
1596    /* set property on zone window that a drag is happening */
1597    ecore_x_e_illume_drag_set(bd->zone->black_win, 1);
1598 }
1599
1600 void
1601 _policy_drag_end(E_Border *bd)
1602 {
1603    //   printf("Drag end\n");
1604
1605    if (!bd) return;
1606
1607    /* ignore stolen borders */
1608    if (bd->stolen) return;
1609
1610    /* set property on this border to say we are done dragging */
1611    ecore_x_e_illume_drag_set(bd->client.win, 0);
1612
1613    /* set property on zone window that a drag is finished */
1614    ecore_x_e_illume_drag_set(bd->zone->black_win, 0);
1615 }
1616
1617 static void
1618 _policy_resize_start(E_Illume_Border_Info *bd_info)
1619 {
1620    E_Manager *m;
1621    Evas *canvas;
1622    Evas_Object *o;
1623    E_Border *bd;
1624    int nx, ny;
1625    const char buf[PATH_MAX];
1626
1627    bd = bd_info->border;
1628
1629    if (!bd) return;
1630    if (bd->stolen) return;
1631    if (!bd->client.illume.win_state.state) return;
1632    if (!bd_info->resize_req.mouse.down) return;
1633
1634    bd_info->resize_req.need_change = 0;
1635    bd_info->resize_req.mouse.locked = 1;
1636    bd_info->resize_req.mouse.resize = 1;
1637    int ang = _policy_window_rotation_angle_get(bd->client.win);
1638    if (ang == -1) ang = 0;
1639    bd_info->resize_req.angle = ang;
1640
1641    m = e_manager_current_get();
1642    if (!m) return;
1643    canvas = e_manager_comp_evas_get(m);
1644    if (!canvas) return;
1645
1646    o = edje_object_add(canvas);
1647    snprintf(buf, sizeof(buf), "%s/e-module-illume2-tizen.edj", _e_illume_mod_dir);
1648    evas_object_image_border_center_fill_set(o, EVAS_BORDER_FILL_NONE);
1649    if(!(edje_object_file_set(o, buf, "new_shadow"))
1650       || !(bd->client.illume.win_state.state == ECORE_X_ILLUME_WINDOW_STATE_FLOATING))
1651      {
1652          o = evas_object_rectangle_add(canvas);                                 
1653          evas_object_color_set(o, 100, 100, 100, 100);
1654      }
1655
1656    nx = bd->x - bd->zone->x;
1657    ny = bd->y - bd->zone->y;
1658    evas_object_move(o, nx, ny);
1659    evas_object_resize(o, bd->w, bd->h);
1660    e_object_data_set(E_OBJECT(bd), o);
1661    evas_object_show(o);
1662 }
1663
1664 static void
1665 _policy_resize_end(E_Illume_Border_Info *bd_info)
1666 {
1667    E_Border *bd;
1668    bd = bd_info->border;
1669
1670    if (!bd) return;
1671
1672    Evas_Object *o = (Evas_Object *)e_object_data_get(E_OBJECT(bd));
1673    if (o) evas_object_del(o);
1674
1675    if (bd->stolen) return;
1676    if (!bd->client.illume.win_state.state) return;
1677    if (!bd_info->resize_req.mouse.down) return;
1678
1679    bd_info->resize_req.mouse.locked = 0;
1680    bd_info->resize_req.mouse.resize = 0;
1681 }
1682
1683 void
1684 _policy_focus_back(E_Zone *zone)
1685 {
1686    Eina_List *l, *fl = NULL;
1687    E_Border *bd, *fbd;
1688
1689    if (!zone) return;
1690    if (eina_list_count(_pol_focus_stack) < 1) return;
1691
1692    //   printf("Focus back\n");
1693
1694    EINA_LIST_FOREACH(_pol_focus_stack, l, bd)
1695      {
1696         if (!bd) continue;
1697         if (bd->zone != zone) continue;
1698         fl = eina_list_append(fl, bd);
1699      }
1700
1701    if (!(fbd = e_border_focused_get())) return;
1702    if (fbd->parent) return;
1703
1704    EINA_LIST_REVERSE_FOREACH(fl, l, bd)
1705      {
1706         if ((fbd) && (bd == fbd))
1707           {
1708              E_Border *b;
1709
1710              if ((l->next) && (b = l->next->data))
1711                {
1712                   _policy_border_set_focus(b);
1713                   break;
1714                }
1715              else
1716                {
1717                   /* we've reached the end of the list. Set focus to first */
1718                   if ((b = eina_list_nth(fl, 0)))
1719                     {
1720                        _policy_border_set_focus(b);
1721                        break;
1722                     }
1723                }
1724           }
1725      }
1726    eina_list_free(fl);
1727 }
1728
1729 void
1730 _policy_focus_forward(E_Zone *zone)
1731 {
1732    Eina_List *l, *fl = NULL;
1733    E_Border *bd, *fbd;
1734
1735    if (!zone) return;
1736    if (eina_list_count(_pol_focus_stack) < 1) return;
1737
1738    //   printf("Focus forward\n");
1739
1740    EINA_LIST_FOREACH(_pol_focus_stack, l, bd)
1741      {
1742         if (!bd) continue;
1743         if (bd->zone != zone) continue;
1744         fl = eina_list_append(fl, bd);
1745      }
1746
1747    if (!(fbd = e_border_focused_get())) return;
1748    if (fbd->parent) return;
1749
1750    EINA_LIST_FOREACH(fl, l, bd)
1751      {
1752         if ((fbd) && (bd == fbd))
1753           {
1754              E_Border *b;
1755
1756              if ((l->next) && (b = l->next->data))
1757                {
1758                   _policy_border_set_focus(b);
1759                   break;
1760                }
1761              else
1762                {
1763                   /* we've reached the end of the list. Set focus to first */
1764                   if ((b = eina_list_nth(fl, 0)))
1765                     {
1766                        _policy_border_set_focus(b);
1767                        break;
1768                     }
1769                }
1770           }
1771      }
1772    eina_list_free(fl);
1773 }
1774
1775 /* enable/disable composite module - 100320 yigl */
1776 #ifdef COMP_MODULE_CONTROL
1777 static void
1778 _policy_property_composite_module_change(Ecore_X_Event_Window_Property *ev)
1779 {
1780    int ret, count;
1781    int enable = 0;
1782    int current_enabled = 0;
1783    unsigned char* prop_data = NULL;
1784    E_Module* comp = NULL;
1785
1786    ret = ecore_x_window_prop_property_get (ev->win, E_ILLUME_ATOM_COMP_MODULE_ENABLED, ECORE_X_ATOM_CARDINAL, 32, &prop_data, &count);
1787    if( ret && prop_data )
1788      {
1789         memcpy (&enable, prop_data, sizeof (int));
1790         fprintf( stdout, "[E17-illume2-tizen] %s(%d) enable: %s ", __func__, __LINE__, enable ? "true" : "false" );
1791
1792         comp = e_module_find ("comp-tizen");
1793         if( comp )
1794           {
1795              current_enabled = e_module_enabled_get(comp);
1796              fprintf( stdout, "current: %s ", current_enabled ? "true" : "false" );
1797
1798              if( current_enabled && !enable )
1799                {
1800                   fprintf( stdout, "e_module_disable(comp-tizen) " );
1801                   e_module_disable(comp);
1802                }
1803              else if( !current_enabled && enable )
1804                {
1805                   fprintf( stdout, "e_module_enable(comp-tizen) " );
1806                   e_module_enable(comp);
1807                }
1808              else
1809                {
1810                   fprintf( stdout, "skip... " );
1811                }
1812
1813              fprintf( stdout, "\n" );
1814           }
1815         else
1816           {
1817              fprintf( stderr, "\n[E17-illume2-tizen] %s(%d) can't find comp module.\n", __func__, __LINE__ );
1818           }
1819      }
1820
1821    if (prop_data) free (prop_data);
1822
1823 }
1824 #endif
1825
1826 /* enable/disable backkey module - 130610 seongwon1.cho */
1827 #ifdef BACKKEY_MODULE_CONTROL
1828 static void
1829 _policy_property_backkey_module_change(Ecore_X_Event_Window_Property *ev)
1830 {
1831    int ret, count;
1832    int enable = 0;
1833    int current_enabled = 0;
1834    unsigned char* prop_data = NULL;
1835    E_Module* backkey = NULL;
1836
1837    ret = ecore_x_window_prop_property_get (ev->win, E_ILLUME_ATOM_BACKKEY_MODULE_ENABLED, ECORE_X_ATOM_CARDINAL, 32, &prop_data, &count);
1838    if( ret && prop_data )
1839      {
1840         memcpy (&enable, prop_data, sizeof (int));
1841         fprintf( stdout, "[E17-illume2-tizen] %s(%d) enable: %s ", __func__, __LINE__, enable ? "true" : "false" );
1842
1843         backkey = e_module_find ("backkey-tizen");
1844         if( backkey )
1845           {
1846              current_enabled = e_module_enabled_get(backkey);
1847              fprintf( stdout, "current: %s ", current_enabled ? "true" : "false" );
1848
1849              if( current_enabled && !enable )
1850                {
1851                   fprintf( stdout, "e_module_disable(backkey-tizen) " );
1852                   e_module_disable(backkey);
1853                }
1854              else if( !current_enabled && enable )
1855                {
1856                   fprintf( stdout, "e_module_enable(backkey-tizen) " );
1857                   e_module_enable(backkey);
1858                }
1859              else
1860                {
1861                   fprintf( stdout, "skip... " );
1862                }
1863
1864              fprintf( stdout, "\n" );
1865           }
1866         else
1867           {
1868              fprintf( stderr, "\n[E17-illume2-tizen] %s(%d) can't find backkey module.\n", __func__, __LINE__ );
1869              backkey = e_module_new("backkey-tizen");
1870              if (backkey) e_module_enable(backkey);
1871           }
1872      }
1873
1874    if (prop_data) free (prop_data);
1875
1876 }
1877 #endif
1878
1879
1880 /* enable/disable devmode module - 130610 seongwon1.cho */
1881 #ifdef DEVMODE_MODULE_CONTROL
1882 static void
1883 _policy_property_devmode_module_change(Ecore_X_Event_Window_Property *ev)
1884 {
1885    int ret, count;
1886    int enable = 0;
1887    int current_enabled = 0;
1888    unsigned char* prop_data = NULL;
1889    E_Module* devmode = NULL;
1890
1891    ret = ecore_x_window_prop_property_get (ev->win, E_ILLUME_ATOM_DEVMODE_MODULE_ENABLED, ECORE_X_ATOM_CARDINAL, 32, &prop_data, &count);
1892    if( ret && prop_data )
1893      {
1894         memcpy (&enable, prop_data, sizeof (int));
1895         fprintf( stdout, "[E17-illume2-tizen] %s(%d) enable: %s ", __func__, __LINE__, enable ? "true" : "false" );
1896
1897         devmode = e_module_find ("devmode-tizen");
1898         if( devmode )
1899           {
1900              current_enabled = e_module_enabled_get(devmode);
1901              fprintf( stdout, "current: %s ", current_enabled ? "true" : "false" );
1902
1903              if( current_enabled && !enable )
1904                {
1905                   fprintf( stdout, "e_module_disable(devmode-tizen) " );
1906                   e_module_disable(devmode);
1907                }
1908              else if( !current_enabled && enable )
1909                {
1910                   fprintf( stdout, "e_module_enable(devmode-tizen) " );
1911                   e_module_enable(devmode);
1912                }
1913              else
1914                {
1915                   fprintf( stdout, "skip... " );
1916                }
1917
1918              fprintf( stdout, "\n" );
1919           }
1920         else
1921           {
1922              fprintf( stderr, "\n[E17-illume2-tizen] %s(%d) can't find devmode module.\n", __func__, __LINE__ );
1923              devmode = e_module_new("devmode-tizen");
1924              if (devmode) e_module_enable(devmode);
1925           }
1926      }
1927
1928    if (prop_data) free (prop_data);
1929
1930 }
1931 #endif
1932
1933
1934 static void _policy_property_window_state_change (Ecore_X_Event_Window_Property *event)
1935 {
1936    E_Border *bd, *indi_bd;
1937
1938    if (!(bd = e_border_find_by_client_window(event->win))) return;
1939
1940    /* not interested in stolen or invisible borders */
1941    if ((bd->stolen) || (!bd->visible)) return;
1942
1943    /* make sure the border has a name or class */
1944    /* NB: this check is here because some E borders get State Changes
1945     * but do not have a name/class associated with them. Not entirely sure
1946     * which ones they are, but I would guess Managers, Containers, or Zones.
1947     * At any rate, we're not interested in those types of borders */
1948    if ((!bd->client.icccm.name) || (!bd->client.icccm.class)) return;
1949
1950    /* NB: If we have reached this point, then it should be a fullscreen
1951     * border that has toggled fullscreen on/off */
1952
1953    /* if the window is not active window, then it doesn't need to hande indicator */
1954    if (g_active_win != bd->client.win) return;
1955
1956    /* try to get the Indicator on this zone */
1957    if (!(indi_bd = e_illume_border_indicator_get(bd->zone))) return;
1958
1959    /* if we are fullscreen, hide the indicator...else we show it */
1960    /* NB: we could use the e_illume_border_is_fullscreen function here
1961     * but we save ourselves a function call this way */
1962    if ((bd->fullscreen) || (bd->need_fullscreen))
1963      {
1964         if (indi_bd->visible)
1965           {
1966              L(LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... Hide Indicator (by win: 0x%07x)\n", __func__, __LINE__, bd->client.win);
1967              e_border_hide(indi_bd, 2);
1968           }
1969      }
1970    else
1971      {
1972         int indi_show = _policy_border_indicator_state_get(bd);
1973         if (indi_show == 1)
1974           {
1975              if (!indi_bd->visible)
1976                {
1977                   L(LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... Show Indicator (by win: 0x%07x)\n", __func__, __LINE__, bd->client.win);
1978                   e_border_show(indi_bd);
1979                }
1980           }
1981      }
1982
1983 }
1984
1985 static void _policy_property_indicator_geometry_change (Ecore_X_Event_Window_Property *event)
1986 {
1987    Eina_List *l;
1988    E_Zone *zone;
1989    E_Border *bd;
1990    int x, y, w, h;
1991
1992    /* make sure this property changed on a zone */
1993    if (!(zone = e_util_zone_window_find(event->win))) return;
1994
1995    /* get the geometry */
1996    if (!(bd = e_illume_border_indicator_get(zone))) return;
1997    x = bd->x;
1998    y = bd->y;
1999    w = bd->w;
2000    h = bd->h;
2001
2002    /* look for conformant borders */
2003    EINA_LIST_FOREACH(e_border_client_list(), l, bd)
2004      {
2005         if (!bd) continue;
2006         if (bd->zone != zone) continue;
2007         if (!e_illume_border_is_conformant(bd)) continue;
2008         /* set indicator geometry on conformant window */
2009         /* NB: This is needed so that conformant apps get told about
2010          * the indicator size/position...else they have no way of
2011          * knowing that the geometry has been updated */
2012         ecore_x_e_illume_indicator_geometry_set(bd->client.win, x, y, w, h);
2013      }
2014 }
2015
2016 static void _policy_property_clipboard_geometry_change (Ecore_X_Event_Window_Property *event)
2017 {
2018    Eina_List *l;
2019    E_Zone *zone;
2020    E_Border *bd;
2021    int x, y, w, h;
2022
2023    /* make sure this property changed on a zone */
2024    if (!(zone = e_util_zone_window_find(event->win))) return;
2025
2026    ecore_x_e_illume_clipboard_geometry_get(zone->black_win, &x, &y, &w, &h);
2027
2028    /* look for conformant borders */
2029    EINA_LIST_FOREACH(e_border_client_list(), l, bd)
2030      {
2031         if (!bd) continue;
2032         if (bd->zone != zone) continue;
2033         if (e_illume_border_is_indicator(bd)) continue;
2034         if (e_illume_border_is_keyboard(bd)) continue;
2035         if (e_illume_border_is_keyboard_sub(bd)) continue;
2036         if (e_illume_border_is_quickpanel(bd)) continue;
2037         if (e_illume_border_is_quickpanel_popup(bd)) continue;
2038
2039 #ifdef USE_DLOG
2040         SECURE_SLOGD("[WM] Clipboard geometry set. win:0x%07x, geo(%d,%d,%d,%d)", bd->client.win, x, y, w, h);
2041 #endif
2042         ecore_x_e_illume_clipboard_geometry_set(bd->client.win, x, y, w, h);
2043      }
2044 }
2045
2046 static void _policy_property_clipboard_state_change (Ecore_X_Event_Window_Property *event)
2047 {
2048    Eina_List *l;
2049    E_Zone *zone;
2050    E_Border *bd;
2051    Ecore_X_Illume_Clipboard_State state;
2052
2053    /* make sure this property changed on a zone */
2054    if (!(zone = e_util_zone_window_find(event->win))) return;
2055
2056    state = ecore_x_e_illume_clipboard_state_get(zone->black_win);
2057
2058    /* look for conformant borders */
2059    EINA_LIST_FOREACH(e_border_client_list(), l, bd)
2060      {
2061         if (!bd) continue;
2062         if (bd->zone != zone) continue;
2063         if (e_illume_border_is_indicator(bd)) continue;
2064         if (e_illume_border_is_keyboard(bd)) continue;
2065         if (e_illume_border_is_keyboard_sub(bd)) continue;
2066         if (e_illume_border_is_quickpanel(bd)) continue;
2067         if (e_illume_border_is_quickpanel_popup(bd)) continue;
2068
2069 #ifdef USE_DLOG
2070         SECURE_SLOGD("[WM] Clipboard state set. win:0x%07x, state:%d", bd->client.win, state);
2071 #endif
2072         ecore_x_e_illume_clipboard_state_set(bd->client.win, state);
2073      }
2074 }
2075
2076 static void _policy_property_enlightenment_scale_change (Ecore_X_Event_Window_Property *event)
2077 {
2078    Eina_List *ml;
2079    E_Manager *man;
2080
2081    EINA_LIST_FOREACH(e_manager_list(), ml, man)
2082      {
2083         Eina_List *cl;
2084         E_Container *con;
2085
2086         if (!man) continue;
2087         if (event->win != man->root) continue;
2088         EINA_LIST_FOREACH(man->containers, cl, con)
2089           {
2090              Eina_List *zl;
2091              E_Zone *zone;
2092
2093              if (!con) continue;
2094              EINA_LIST_FOREACH(con->zones, zl, zone)
2095                 _policy_zone_layout_update(zone);
2096           }
2097      }
2098 }
2099
2100 static void _policy_property_rotate_win_angle_change (Ecore_X_Event_Window_Property *event)
2101 {
2102    E_Border* bd;
2103    E_Illume_XWin_Info* xwin_info;
2104
2105    L (LT_ANGLE, "[ILLUME2][ANGLE] %s(%d).. win:0x%07x\n", __func__, __LINE__, event->win);
2106
2107    if (!(bd = e_border_find_by_client_window(event->win))) return;
2108
2109    xwin_info = _policy_xwin_info_find (bd->win);
2110    if (xwin_info)
2111      {
2112         if (xwin_info->visibility == E_ILLUME_VISIBILITY_UNOBSCURED)
2113           {
2114              L (LT_ANGLE, "[ILLUME2][ANGLE] %s(%d).. CALL _policy_change_root_angle_by_border_angle!!! win:0x%07x\n", __func__, __LINE__, bd->client.win);
2115              _policy_change_root_angle_by_border_angle (bd);
2116           }
2117      }
2118
2119    bd->changes.pos = 1;
2120    bd->changed = 1;
2121 }
2122
2123 static void _policy_property_indicator_state_change (Ecore_X_Event_Window_Property *event)
2124 {
2125    E_Border *bd, *indi_bd;
2126
2127    if (!(bd = e_border_find_by_client_window(event->win))) return;
2128
2129    indi_bd = e_illume_border_indicator_get(bd->zone);
2130    if (!indi_bd) return;
2131
2132    L(LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... win = 0x%07x..  Control Indicator.\n", __func__, __LINE__, bd->client.win);
2133    _policy_border_indicator_control(indi_bd);
2134 }
2135
2136 static void _policy_property_indicator_opacity_change(Ecore_X_Event_Window_Property *event)
2137 {
2138    E_Border *bd, *indi_bd;
2139    Ecore_X_Window active_win;
2140    Ecore_X_Illume_Indicator_Opacity_Mode mode;
2141
2142    if (!(bd = e_border_find_by_client_window(event->win))) return;
2143
2144    indi_bd = e_illume_border_indicator_get(bd->zone);
2145    if (!indi_bd) return;
2146
2147    active_win = _policy_active_window_get(bd->zone->container->manager->root);
2148    if (active_win == bd->client.win)
2149      {
2150         mode = ecore_x_e_illume_indicator_opacity_get(bd->client.win);
2151         ecore_x_e_illume_indicator_opacity_send(indi_bd->client.win, mode);
2152      }
2153 }
2154
2155 static void _policy_active_win_change(E_Illume_XWin_Info *xwin_info, Ecore_X_Window active_win)
2156 {
2157    E_Border *active_bd = NULL;
2158    int active_pid;
2159
2160    if (!xwin_info) return;
2161    if (!xwin_info->comp_vis) return;
2162
2163    active_bd = e_border_find_by_client_window(active_win);
2164
2165    /* for active/deactive message */
2166    if (active_win != g_active_win)
2167      {
2168         if (active_bd)
2169           active_pid = active_bd->client.netwm.pid;
2170         else
2171           active_pid = 0;
2172
2173         // 1. send deactive event to g_active_win
2174         ecore_x_client_message32_send(g_active_win, E_ILLUME_ATOM_DEACTIVATE_WINDOW,
2175                                       ECORE_X_EVENT_MASK_WINDOW_CONFIGURE, active_win, active_pid, g_active_win, g_active_pid, 0);
2176
2177         // 2. send active event to active_win
2178         ecore_x_client_message32_send(active_win, E_ILLUME_ATOM_ACTIVATE_WINDOW,
2179                                       ECORE_X_EVENT_MASK_WINDOW_CONFIGURE, active_win, active_pid, g_active_win, g_active_pid, 0);
2180
2181         // for debug...
2182         if (active_bd)
2183           {
2184 #ifdef USE_DLOG
2185              SECURE_SLOGD("[WM] ACT WIN 0x%07x(%d) -> 0x%07x(%d)", g_active_win, g_active_pid, active_win, active_pid);
2186 #endif
2187              if ((E_ILLUME_BORDER_IS_IN_DESKTOP(active_bd)) ||
2188                  (active_bd->client.illume.win_state.state == ECORE_X_ILLUME_WINDOW_STATE_FLOATING))
2189                {
2190                   e_border_raise(active_bd);
2191                }
2192           }
2193         else
2194           {
2195 #ifdef USE_DLOG
2196              SECURE_SLOGD("[WM] ACT WIN 0x%07x(%d) -> 0x%07x(%d)", g_active_win, g_active_pid, active_win, active_pid);
2197 #endif
2198           }
2199         g_active_win = active_win;
2200         g_active_pid = active_pid;
2201      }
2202
2203    if (active_bd)
2204      {
2205         if (_e_illume_cfg->use_indicator_widget)
2206           {
2207              L(LT_ANGLE, "[ILLUME2][ANGLE] %s(%d)... Control Root Angle.\n", __func__, __LINE__);
2208              _policy_border_root_angle_control(active_bd->zone);
2209           }
2210         else
2211           {
2212              E_Border *indi_bd;
2213              indi_bd = e_illume_border_indicator_get(active_bd->zone);
2214              if (indi_bd)
2215                {
2216                   L(LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... win = 0x%07x..  Control Indicator.\n", __func__, __LINE__, active_bd->client.win);
2217                   _policy_border_indicator_control(indi_bd);
2218                }
2219           }
2220
2221         ILLUME2_TRACE ("[ILLUME2] ACTIVE WINDOW... (%d) active win = 0x%07x HIDE quickpanel\n", __LINE__, active_win);
2222         e_illume_quickpanel_hide(active_bd->zone, 0);
2223      }
2224 }
2225
2226 static void _policy_property_active_win_change (Ecore_X_Event_Window_Property *event)
2227 {
2228    Ecore_X_Window active_win;
2229    E_Border* active_bd;
2230    E_Illume_XWin_Info *xwin_info;
2231
2232    active_win = _policy_active_window_get(event->win);
2233    active_bd = e_border_find_by_client_window(active_win);
2234    if (active_bd)
2235      {
2236         xwin_info = _policy_xwin_info_find(active_bd->win);
2237      }
2238    else
2239      {
2240         xwin_info = _policy_xwin_info_find(active_win);
2241      }
2242
2243    _policy_active_win_change(xwin_info, active_win);
2244 }
2245
2246 static void _policy_property_win_type_change (Ecore_X_Event_Window_Property *event)
2247 {
2248    E_Border *bd;
2249    E_Border *indi_bd;
2250    E_Illume_Border_Info* bd_info = NULL;
2251    int layer = 0;
2252
2253    if (!(bd = e_border_find_by_client_window(event->win))) return;
2254
2255    bd_info = _policy_get_border_info(bd);
2256    if (!bd_info) return;
2257
2258    e_hints_window_type_get (bd);
2259
2260    if (bd_info->win_type == bd->client.netwm.type) return;
2261    bd_info->win_type = bd->client.netwm.type;
2262
2263    if (bd->client.netwm.type == ECORE_X_WINDOW_TYPE_NOTIFICATION)
2264      {
2265         ILLUME2_TRACE ("[ILLUME2-NEW] %s(%d)... WINDOW TYPE is CHANGED to NOTIFICATION!!!!! win = 0x%07x\n", __func__, __LINE__, bd->client.win);
2266         bd_info->level = _policy_border_get_notification_level(bd->client.win);
2267         layer = _policy_notification_level_map(bd_info->level);
2268         e_border_layer_set(bd, layer);
2269
2270         L (LT_NOTIFICATION, "[ILLUME2][NOTIFICATION] %s(%d)... win (0x%07x) is notification window... level = %d\n", __func__, __LINE__, bd->client.win, bd_info->level);
2271
2272         indi_bd = e_illume_border_indicator_get(bd->zone);
2273         if (indi_bd)
2274           {
2275              L(LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... win = 0x%07x..  Control Indicator.\n", __func__, __LINE__, bd->client.win);
2276              _policy_border_indicator_control(indi_bd);
2277           }
2278
2279         L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d).. ICONIFY win:0x%07x And UN-ICONIFY Top win...\n", __func__, __LINE__, bd->client.win);
2280         _policy_border_uniconify_top_border(bd);
2281      }
2282    else if (bd->client.netwm.type == ECORE_X_WINDOW_TYPE_NORMAL)
2283      {
2284         ILLUME2_TRACE ("[ILLUME2-NEW] %s(%d)... WINDOW TYPE is CHANGED to NORMAL!!!!! win = 0x%07x\n", __func__, __LINE__, bd->client.win);
2285         if (bd->layer != POL_APP_LAYER)
2286           {
2287              if ( (!e_illume_border_is_quickpanel(bd)) &&
2288                   (!e_illume_border_is_quickpanel_popup(bd)) &&
2289                   (!e_illume_border_is_keyboard(bd)) &&
2290                   (!e_illume_border_is_keyboard_sub(bd)))
2291                {
2292                   e_border_layer_set(bd, POL_APP_LAYER);
2293                }
2294           }
2295
2296         indi_bd = e_illume_border_indicator_get(bd->zone);
2297         if (indi_bd)
2298           {
2299              L(LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... win = 0x%07x..  Control Indicator.\n", __func__, __LINE__, bd->client.win);
2300              _policy_border_indicator_control(indi_bd);
2301           }
2302
2303         L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d).. ICONIFY win:0x%07x And UN-ICONIFY Top win...\n", __func__, __LINE__, bd->client.win);
2304         _policy_border_uniconify_top_border(bd);
2305      }
2306    else if (bd->client.netwm.type == ECORE_X_WINDOW_TYPE_UTILITY)
2307      {
2308         bd->client.icccm.request_pos = 1;
2309
2310         if (bd->layer != POL_APP_LAYER)
2311            e_border_layer_set(bd, POL_APP_LAYER);
2312      }
2313
2314 }
2315
2316 static void _policy_property_rotate_root_angle_change (Ecore_X_Event_Window_Property *event)
2317 {
2318    E_Border* bd;
2319    E_Border* indi_bd;
2320    int ret;
2321    int count;
2322    int angle = 0;
2323    unsigned char *prop_data = NULL;
2324    E_Zone* zone;
2325
2326    ret = ecore_x_window_prop_property_get (event->win, ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE, ECORE_X_ATOM_CARDINAL, 32, &prop_data, &count);
2327    if( ret && prop_data )
2328       memcpy (&angle, prop_data, sizeof (int));
2329
2330    if (prop_data) free (prop_data);
2331
2332    L (LT_ANGLE, "[ILLUME2][ANGLE] %s(%d).. ROOT ANGLE CHANGED... angle = %d. control_win:0x%07x\n", __func__, __LINE__, angle, g_indi_control_win);
2333    bd = e_border_find_by_client_window(g_indi_control_win);
2334
2335    if (bd) zone = bd->zone;
2336    else zone = e_util_container_zone_number_get (0, 0);
2337
2338    if (zone)
2339      {
2340         // send client message to all visible windows
2341         if (g_root_angle != angle)
2342           {
2343              indi_bd = e_illume_border_indicator_get(zone);
2344              if (indi_bd)
2345                {
2346                   _policy_indicator_angle_change (indi_bd, angle);
2347                }
2348
2349              Eina_List *l;
2350              E_Border* bd_temp;
2351
2352              EINA_LIST_FOREACH(e_border_client_list(), l, bd_temp)
2353                {
2354                   if (!bd_temp) continue;
2355                   if (!bd_temp->visible && !bd_temp->iconic)
2356                     {
2357                        if (!e_illume_border_is_keyboard(bd_temp))
2358                          continue;
2359                     }
2360
2361                   L (LT_ANGLE, "[ILLUME2][ANGLE] %s(%d)... win = 0x%07x..  SEND client Event with angle = %d\n", __func__, __LINE__, bd_temp->client.win, angle);
2362                   ecore_x_client_message32_send (bd_temp->client.win, ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE,
2363                                                  ECORE_X_EVENT_MASK_WINDOW_CONFIGURE, angle, g_indi_control_win, 0, 0, 0);
2364                }
2365
2366              if (_e_illume_cfg->use_indicator_widget)
2367                {
2368                   E_Illume_Quickpanel *qp;
2369                   qp = e_illume_quickpanel_by_zone_get(zone);
2370                   if (qp)
2371                     _policy_layout_quickpanel_rotate(qp, angle);
2372                }
2373
2374              e_illume_util_hdmi_rotation (event->win, angle);
2375           }
2376      }
2377
2378    g_root_angle = angle;
2379 }
2380
2381 static void _policy_property_notification_level_change (Ecore_X_Event_Window_Property *event)
2382 {
2383    /*
2384       0. Check if border is exist or not
2385       1. Check if a window is notification or not
2386       2. Get and Set level
2387       3. Change Stack
2388     */
2389    L (LT_NOTIFICATION, "[ILLUME2][NOTIFICATION] %s(%d)... E_ILLUME_ATOM_NOTIFICATION_LEVEL property!!!  win = 0x%07x\n", __func__, __LINE__, event->win);
2390
2391    E_Border* bd;
2392    E_Border *indi_bd;
2393    E_Illume_Border_Info *bd_info = NULL;
2394    int layer = 0;
2395
2396    // 0.
2397    if (!(bd = e_border_find_by_client_window(event->win)))
2398      {
2399         L (LT_NOTIFICATION, "[ILLUME2][NOTIFICATION] %s(%d)... Win (0x%07x) doesn't have border... So return..\n", __func__, __LINE__, event->win);
2400         return;
2401      }
2402
2403    bd_info = _policy_get_border_info(bd);
2404    if (!bd_info) return;
2405
2406    // 1.
2407    if (!e_illume_border_is_notification (bd))
2408      {
2409         L (LT_NOTIFICATION, "[ILLUME2][NOTIFICATION] %s(%d)... Win (0x%07x) gets NOTIFICATION_LEVEL notifiy... But this is NOT notification window... IGNORE!!!!!\n", __func__, __LINE__, bd->client.win);
2410         return;
2411      }
2412
2413    // 2.
2414    bd_info->level = _policy_border_get_notification_level(bd->client.win);
2415    layer = _policy_notification_level_map(bd_info->level);
2416
2417    // 3.
2418    e_border_layer_set(bd, layer);
2419    L (LT_NOTIFICATION, "[ILLUME2][NOTIFICATION] %s(%d)... win (0x%07x) is notification window... level = %d\n",
2420       __func__, __LINE__, bd->client.win, bd_info->level);
2421
2422    // 4.
2423    indi_bd = e_illume_border_indicator_get(bd->zone);
2424    if (indi_bd)
2425      {
2426         L(LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... win = 0x%07x..  Control Indicator.\n", __func__, __LINE__, bd->client.win);
2427         _policy_border_indicator_control(indi_bd);
2428      }
2429
2430    L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d).. ICONIFY win:0x%07x And UN-ICONIFY Top win...\n", __func__, __LINE__, bd->client.win);
2431    _policy_border_uniconify_top_border(bd);
2432 }
2433
2434 static void _policy_property_overlay_win_change (Ecore_X_Event_Window_Property *event)
2435 {
2436    int ret;
2437    int count;
2438    unsigned char* prop_data = NULL;
2439
2440    ret = ecore_x_window_prop_property_get (event->win, E_ILLUME_ATOM_OVERAY_WINDOW, ECORE_X_ATOM_WINDOW, 32, &prop_data, &count);
2441    if( ret && prop_data )
2442       memcpy (&_e_overlay_win, prop_data, sizeof (ECORE_X_ATOM_WINDOW));
2443
2444    if (prop_data) free (prop_data);
2445
2446    L (LT_XWIN, "[ILLUME2][XWIN] %s(%d)... OVERAY_WINDOW:0x%07x\n", __func__, __LINE__, _e_overlay_win);
2447    _policy_xwin_info_delete (_e_overlay_win);
2448 }
2449
2450 static int _policy_property_window_opaque_get (Ecore_X_Window win)
2451 {
2452    int ret;
2453    int count;
2454    int is_opaque = 0;
2455    unsigned char* prop_data = NULL;
2456
2457    ret = ecore_x_window_prop_property_get (win, E_ILLUME_ATOM_WINDOW_OPAQUE, ECORE_X_ATOM_CARDINAL, 32, &prop_data, &count);
2458    if( ret && prop_data )
2459       memcpy (&is_opaque, prop_data, sizeof (ECORE_X_ATOM_CARDINAL));
2460
2461    if (prop_data) free (prop_data);
2462
2463    return is_opaque;
2464 }
2465
2466 static void _policy_property_window_opaque_change (Ecore_X_Event_Window_Property *event)
2467 {
2468    E_Border* bd;
2469    E_Illume_Border_Info* bd_info;
2470
2471    if (!(bd = e_border_find_by_client_window(event->win))) return;
2472
2473    // get border info
2474    bd_info = _policy_get_border_info (bd);
2475    if (!bd_info) return;
2476
2477    // set current property
2478    bd_info->opaque = _policy_property_window_opaque_get (event->win);
2479
2480    // visibility is changed
2481    L(LT_VISIBILITY, "[ILLUME2][VISIBILITY] %s(%d).. visibility is changed... win:0x%07x\n",  __func__, __LINE__, event->win);
2482    _g_visibility_changed = EINA_TRUE;
2483 }
2484
2485 static void
2486 _policy_property_illume_window_state_change(Ecore_X_Event_Window_Property *event)
2487 {
2488    E_Border *bd;
2489
2490    if (!(bd = e_border_find_by_client_window(event->win))) return;
2491    if (bd->stolen) return;
2492
2493    unsigned int state = ecore_x_e_illume_window_state_get(event->win);
2494    _policy_border_illume_window_state_change(bd, state);
2495 }
2496
2497 static void
2498 _policy_border_illume_window_state_change(E_Border *bd, unsigned int state)
2499 {
2500    E_Border* indi_bd;
2501
2502    if (!bd) return;
2503    if (bd->client.illume.win_state.state == state) return;
2504
2505    ELBF(ELBT_ILLUME, 0, bd->client.win, "SET WIN_STATE %d->%d",
2506         bd->client.illume.win_state.state, state);
2507
2508    bd->client.illume.win_state.state = state;
2509    switch (state)
2510      {
2511       case ECORE_X_ILLUME_WINDOW_STATE_FLOATING:
2512          e_hints_window_state_update(bd, ECORE_X_WINDOW_STATE_ABOVE, ECORE_X_WINDOW_STATE_ACTION_ADD);
2513
2514          if (_e_illume_cfg->use_force_iconify)
2515            _policy_border_uniconify_below_borders(bd);
2516
2517          bd->client.icccm.request_pos = EINA_TRUE;
2518          bd->lock_user_size = 0;
2519          bd->lock_user_location = 0;
2520          bd->borderless = 0;
2521
2522          if (bd->maximized)
2523            e_border_unmaximize(bd, E_MAXIMIZE_BOTH);
2524
2525          indi_bd = e_illume_border_indicator_get(bd->zone);
2526          if (indi_bd)
2527            {
2528               L(LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... win = 0x%07x..  Control Indicator.\n", __func__, __LINE__, bd->client.win);
2529               _policy_border_indicator_control(indi_bd);
2530            }
2531
2532         if (!eina_list_data_find(dep_rot.list, bd))
2533           {
2534              int prev_ang = _prev_angle_get(bd->client.win);
2535
2536              bd->client.e.state.rot.type = E_BORDER_ROTATION_TYPE_DEPENDENT;
2537
2538              dep_rot.list = eina_list_append(dep_rot.list, bd);
2539
2540              if (prev_ang != -1)
2541                bd->client.e.state.rot.curr = prev_ang;
2542
2543              if (dep_rot.ang != bd->client.e.state.rot.curr)
2544                e_border_rotation_set(bd, dep_rot.ang);
2545           }
2546          break;
2547
2548       case ECORE_X_ILLUME_WINDOW_STATE_NORMAL:
2549          e_hints_window_state_update(bd, ECORE_X_WINDOW_STATE_ABOVE, ECORE_X_WINDOW_STATE_ACTION_REMOVE);
2550
2551          if (E_ILLUME_BORDER_IS_IN_MOBILE(bd))
2552            {
2553               bd->lock_user_size = 1;
2554               bd->lock_user_location = 1;
2555            }
2556          else if (E_ILLUME_BORDER_IS_IN_DESKTOP(bd))
2557            {
2558              bd->borderless = 0;
2559            }
2560
2561          bd->client.icccm.request_pos = EINA_FALSE;
2562
2563          indi_bd = e_illume_border_indicator_get(bd->zone);
2564          if (indi_bd)
2565            {
2566               L(LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... win = 0x%07x..  Control Indicator.\n", __func__, __LINE__, bd->client.win);
2567               _policy_border_indicator_control(indi_bd);
2568            }
2569
2570          if (eina_list_data_find(dep_rot.list, bd) == bd)
2571            {
2572               bd->client.e.state.rot.type = E_BORDER_ROTATION_TYPE_NORMAL;
2573               dep_rot.list = eina_list_remove(dep_rot.list, bd);
2574            }
2575          break;
2576      }
2577    bd->changes.size = 1;
2578    bd->changes.pos = 1;
2579    bd->changed = 1;
2580 }
2581
2582 static void
2583 _policy_border_illume_handlers_add(E_Illume_Border_Info *bd_info)
2584 {
2585    if (!bd_info) return;
2586    if (bd_info->handlers) return;
2587
2588    bd_info->handlers = eina_list_append(bd_info->handlers,
2589                                                  ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP,
2590                                                                          _policy_border_cb_mouse_up, bd_info));
2591    bd_info->handlers = eina_list_append(bd_info->handlers,
2592                                                  ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE,
2593                                                                          _policy_border_cb_mouse_move, bd_info));
2594 }
2595
2596 static void
2597 _policy_border_illume_handlers_remove(E_Illume_Border_Info *bd_info)
2598 {
2599    Ecore_Event_Handler *hdl;
2600
2601    if (!bd_info) return;
2602    if (!bd_info->handlers) return;
2603
2604    EINA_LIST_FREE(bd_info->handlers, hdl)
2605      ecore_event_handler_del(hdl);
2606 }
2607
2608 static Eina_Bool
2609 _policy_border_cb_mouse_down(void *data,
2610                              int   type __UNUSED__,
2611                              void *event)
2612 {
2613    Ecore_Event_Mouse_Button *ev;
2614    E_Illume_Border_Info *bd_info;
2615    E_Border *bd;
2616
2617    L(LT_AIA, "[ILLUME2][AIA] %s(%d)... \n", __func__, __LINE__);
2618    ev = event;
2619    bd_info = data;
2620    bd = bd_info->border;
2621
2622    if (ev->window != bd->event_win &&
2623        ev->event_window != bd->event_win)
2624      return ECORE_CALLBACK_PASS_ON;
2625
2626    if (bd_info->resize_req.mouse.down)
2627      return ECORE_CALLBACK_PASS_ON;
2628
2629    bd_info->resize_req.mouse.down = 1;
2630
2631    bd_info->resize_req.mouse.dx = bd->x - ev->root.x;
2632    bd_info->resize_req.mouse.dy = bd->y - ev->root.y;
2633
2634    bd_info->resize_req.mouse.x = bd->x;
2635    bd_info->resize_req.mouse.y = bd->y;
2636
2637    e_border_raise(bd);
2638    ecore_x_mouse_down_send(bd->client.win, ev->x, ev->y, ev->buttons);
2639
2640    return ECORE_CALLBACK_PASS_ON;
2641 }
2642
2643 static void
2644 _resize_rect_geometry_get(E_Illume_Border_Info *bd_info,
2645                           Evas_Coord_Rectangle *r,
2646                           int                   ev_x,
2647                           int                   ev_y,
2648                           int                   direction,
2649                           E_Resizable_Area_Info *area)
2650 {
2651    E_Border *bd;
2652    int x = 0, y = 0, w = 0, h = 0;
2653    int mw = 0, mh = 0;
2654    int cx = 0, cy = 0;
2655    int max_size = 0;
2656    int min_size = 200;
2657
2658    bd = bd_info->border;
2659
2660    e_illume_border_min_get(bd, &mw, &mh);
2661    // min_size is workaround adjustement due to some window's wrong w h after rotation is changed.
2662    if(mw < min_size) mw = min_size;
2663    if(mh < min_size) mh = min_size;
2664
2665    if (direction == ECORE_X_NETWM_DIRECTION_SIZE_BR)
2666      {
2667         switch (bd_info->resize_req.angle)
2668           {
2669            case 0:
2670               cx = bd->x;               cy = bd->y;
2671               x = bd->x;                 y = bd->y;
2672               w = ev_x - bd->x;          h = ev_y - bd->y;
2673               break;
2674            case 90:
2675               cx = bd->x;               cy = bd->y + bd->h;
2676               x = bd->x;                 y = ev_y;
2677               w = ev_x - x;              h = (bd->y + bd->h) - y;
2678               break;
2679            case 180:
2680               cx = bd->x + bd->w;       cy = bd->y + bd->h;
2681               x = ev_x;                  y = ev_y;
2682               w = (bd->x + bd->w) - x;   h = (bd->y + bd->h) - y;
2683               break;
2684            case 270:
2685               cx = bd->x + bd->w;       cy = bd->y;
2686               x  = ev_x;                 y = bd->y;
2687               w  = (bd->x + bd->w) - x;  h = ev_y - y;
2688               break;
2689            default:
2690               break;
2691           }
2692      }
2693    else if (direction == ECORE_X_NETWM_DIRECTION_SIZE_TL)
2694      {
2695         switch (bd_info->resize_req.angle)
2696           {
2697            case 0:
2698               cx = bd->x + bd->w;       cy = bd->y + bd->h;
2699               x = ev_x;                  y = ev_y;
2700               w = (bd->x + bd->w) - x;   h = (bd->y + bd->h) - y;
2701               break;
2702            case 90:
2703               cx = bd->x + bd->w;       cy = bd->y;
2704               x  = ev_x;                 y = bd->y;
2705               w  = (bd->x + bd->w) - x;  h = ev_y - y;
2706               break;
2707            case 180:
2708               cx = bd->x;               cy = bd->y;
2709               x = bd->x;                 y = bd->y;
2710               w = ev_x - bd->x;          h = ev_y - bd->y;
2711               break;
2712            case 270:
2713               cx = bd->x;               cy = bd->y + bd->h;
2714               x = bd->x;                 y = ev_y;
2715               w = ev_x - x;              h = (bd->y + bd->h) - y;
2716               break;
2717            default:
2718               break;
2719           }
2720      }
2721    else if (direction == ECORE_X_NETWM_DIRECTION_SIZE_TR)
2722      {
2723         switch (bd_info->resize_req.angle)
2724           {
2725            case 0:
2726               cx = bd->x;               cy = bd->y + bd->h;
2727               x = bd->x;                 y = ev_y;
2728               w = ev_x - x;              h = (bd->y + bd->h) - y;
2729               break;
2730            case 90:
2731               cx = bd->x + bd->w;       cy = bd->y + bd->h;
2732               x = ev_x;                  y = ev_y;
2733               w = (bd->x + bd->w) - x;   h = (bd->y + bd->h) - y;
2734               break;
2735            case 180:
2736               cx = bd->x + bd->w;       cy = bd->y;
2737               x  = ev_x;                 y = bd->y;
2738               w  = (bd->x + bd->w) - x;  h = ev_y - y;
2739               break;
2740            case 270:
2741               cx = bd->x;               cy = bd->y;
2742               x = bd->x;                 y = bd->y;
2743               w = ev_x - bd->x;          h = ev_y - bd->y;
2744               break;
2745            default:
2746               break;
2747           }
2748      }
2749    else if (direction == ECORE_X_NETWM_DIRECTION_SIZE_BL)
2750      {
2751         switch (bd_info->resize_req.angle)
2752           {
2753            case 0:
2754               cx = bd->x + bd->w;       cy = bd->y;
2755               x  = ev_x;                 y = bd->y;
2756               w  = (bd->x + bd->w) - x;  h = ev_y - y;
2757               break;
2758            case 90:
2759               cx = bd->x;               cy = bd->y;
2760               x = bd->x;                 y = bd->y;
2761               w = ev_x - bd->x;          h = ev_y - bd->y;
2762               break;
2763            case 180:
2764               cx = bd->x;               cy = bd->y + bd->h;
2765               x = bd->x;                 y = ev_y;
2766               w = ev_x - x;              h = (bd->y + bd->h) - y;
2767               break;
2768            case 270:
2769               cx = bd->x + bd->w;       cy = bd->y + bd->h;
2770               x = ev_x;                  y = ev_y;
2771               w = (bd->x + bd->w) - x;   h = (bd->y + bd->h) - y;
2772               break;
2773            default:
2774               break;
2775           }
2776      }
2777    else if (direction == ECORE_X_NETWM_DIRECTION_SIZE_R)
2778      {
2779         switch (bd_info->resize_req.angle)
2780           {
2781            case 0:
2782               cx = bd->x;               cy = bd->y;
2783               x = bd->x;                 y = bd->y;
2784               w = ev_x - bd->x;          h = bd->h;
2785               break;
2786            case 90:
2787               cx = bd->x;               cy = bd->y + bd->h;
2788               x = bd->x;                 y = ev_y;
2789               w = bd->w;              h = (bd->y + bd->h) - y;
2790               break;
2791            case 180:
2792               cx = bd->x + bd->w;       cy = bd->y + bd->h;
2793               x = ev_x;                  y = ev_y;
2794               w = (bd->x + bd->w) - x;   h = bd->h;
2795               break;
2796            case 270:
2797               cx = bd->x + bd->w;       cy = bd->y;
2798               x  = ev_x;                 y = bd->y;
2799               w  = bd->w;  h = ev_y - y;
2800               break;
2801            default:
2802               break;
2803           }
2804      }
2805    else if (direction == ECORE_X_NETWM_DIRECTION_SIZE_L)
2806      {
2807         switch (bd_info->resize_req.angle)
2808           {
2809            case 0:
2810               cx = bd->x + bd->w;       cy = bd->y + bd->h;
2811               x = ev_x;                  y = bd->y;
2812               w = (bd->x + bd->w) - x;   h = bd->h;
2813               break;
2814            case 90:
2815               cx = bd->x + bd->w;       cy = bd->y;
2816               x  = ev_x;                 y = bd->y;
2817               w  = bd->w;  h = ev_y - y;
2818               break;
2819            case 180:
2820               cx = bd->x;               cy = bd->y;
2821               x = bd->x;                 y = bd->y;
2822               w = ev_x - bd->x;          h = bd->h;
2823               break;
2824            case 270:
2825               cx = bd->x;               cy = bd->y + bd->h;
2826               x = bd->x;                 y = ev_y;
2827               w = bd->w;              h = (bd->y + bd->h) - y;
2828               break;
2829            default:
2830               break;
2831           }
2832      }
2833    else if (direction == ECORE_X_NETWM_DIRECTION_SIZE_T)
2834      {
2835         switch (bd_info->resize_req.angle)
2836           {
2837            case 0:
2838               cx = bd->x + bd->w;       cy = bd->y + bd->h;
2839               x = bd->x;                  y = ev_y;
2840               w = bd->w;   h = (bd->y + bd->h) - y;
2841               break;
2842            case 90:
2843               cx = bd->x + bd->w;               cy = bd->y;
2844               x = ev_x;                 y = bd->y;
2845               w = (bd->x + bd->w) - x;              h = bd->h;
2846               break;
2847            case 180:
2848               cx = bd->x;               cy = bd->y;
2849               x = bd->x;                 y = bd->y;
2850               w = bd->w;          h = ev_y - bd->y;
2851               break;
2852            case 270:
2853               cx = bd->x + bd->w;       cy = bd->y;
2854               x  = bd->x;                 y = bd->y;
2855               w  = ev_x - bd->x;  h = bd->h;
2856               break;
2857            default:
2858               break;
2859           }
2860      }
2861    else if (direction == ECORE_X_NETWM_DIRECTION_SIZE_B)
2862      {
2863         switch (bd_info->resize_req.angle)
2864           {
2865            case 0:
2866               cx = bd->x;               cy = bd->y;
2867               x = bd->x;                 y = bd->y;
2868               w = bd->w;          h = ev_y - bd->y;
2869               break;
2870            case 90:
2871               cx = bd->x + bd->w;       cy = bd->y;
2872               x  = bd->x;                 y = bd->y;
2873               w  = ev_x - bd->x;  h = bd->h;
2874               break;
2875            case 180:
2876               cx = bd->x + bd->w;       cy = bd->y + bd->h;
2877               x = bd->x;                  y = ev_y;
2878               w = bd->w;   h = (bd->y + bd->h) - y;
2879               break;
2880            case 270:
2881               cx = bd->x + bd->w;               cy = bd->y;
2882               x = ev_x;                 y = bd->y;
2883               w = (bd->x + bd->w) - x;              h = bd->h;
2884               break;
2885            default:
2886               break;
2887           }
2888      }
2889    else
2890      {
2891         //error
2892         L(LT_AIA, "[ILLUME2][AIA] %s(%d)... ERROR... direction(%d) is not defined!!!\n", __func__, __LINE__, direction);
2893         return;
2894      }
2895
2896    if (bd->zone->w > bd->zone->h)
2897      max_size = bd->zone->h;
2898    else
2899      max_size = bd->zone->w;
2900
2901    if(area)
2902      {
2903         area->x_dist = w;
2904         area->y_dist = h;
2905         area->min_width = mw;
2906         area->min_height = mh;
2907         area->max_width = max_size;
2908         area->max_height = max_size;
2909     }
2910
2911    if (w < mw) w = mw;
2912    if (h < mh) h = mh;
2913    if (w > max_size) w = max_size;
2914    if (h > max_size) h = max_size;
2915
2916    if ((x + w) > (bd->x + w)) x = cx - w;
2917    if ((y + h) > (bd->y + h)) y = cy - h;
2918
2919    if ((cx - x) > max_size)
2920      x = cx - max_size;
2921    if ((cy - y) > max_size)
2922      y = cy - max_size;
2923
2924    x = x - bd->zone->x;
2925    y = y - bd->zone->y;
2926
2927    r->x = x;
2928    r->y = y;
2929    r->w = w;
2930    r->h = h;
2931 }
2932
2933 static Eina_Bool
2934 _policy_border_cb_mouse_up(void *data,
2935                            int   type __UNUSED__,
2936                            void *event)
2937 {
2938    Ecore_Event_Mouse_Button *ev;
2939    E_Illume_Border_Info *bd_info;
2940    E_Border *bd;
2941
2942    L(LT_AIA, "[ILLUME2][AIA] %s(%d)... \n", __func__, __LINE__);
2943    ev = event;
2944    bd_info = data;
2945    bd = bd_info->border;
2946
2947    if (ev->window != bd->event_win &&
2948        ev->event_window != bd->event_win)
2949      return ECORE_CALLBACK_PASS_ON;
2950
2951    if (!bd_info->resize_req.mouse.down)
2952      return ECORE_CALLBACK_PASS_ON;
2953
2954    bd->lock_user_location = 0;
2955    e_grabinput_release(bd->event_win, bd->event_win);
2956
2957    if (bd_info->resize_req.mouse.resize)
2958      {
2959         L(LT_AIA, "[ILLUME2][AIA] %s(%d)... \n", __func__, __LINE__);
2960         Evas_Coord_Rectangle r;
2961         _resize_rect_geometry_get(bd_info, &r, ev->root.x, ev->root.y, bd_info->resize_req.direction, NULL);
2962
2963         bd_info->resize_req.direction = ECORE_X_NETWM_DIRECTION_CANCEL;
2964         bd_info->resize_req.mouse.x = r.x + bd->zone->x;
2965         bd_info->resize_req.mouse.y = r.y + bd->zone->y;
2966         bd_info->resize_req.mouse.w = r.w;
2967         bd_info->resize_req.mouse.h = r.h;
2968         bd_info->resize_req.need_change = 1;
2969         bd->changes.pos = 1;
2970         bd->changes.size = 1;
2971         bd->changed = 1;
2972         Evas_Object *o = (Evas_Object *)e_object_data_get(E_OBJECT(bd));
2973         if (o)
2974           {
2975              evas_object_del(o);
2976              printf("[IL2] DEL OBJ in UP\n");
2977           }
2978      }
2979    else
2980      {
2981         L(LT_AIA, "[ILLUME2][AIA] %s(%d)... \n", __func__, __LINE__);
2982         bd_info->resize_req.mouse.x = ev->root.x + bd_info->resize_req.mouse.dx;
2983         bd_info->resize_req.mouse.y = ev->root.y + bd_info->resize_req.mouse.dy;
2984      }
2985
2986    bd_info->resize_req.mouse.down = 0;
2987    bd_info->resize_req.mouse.resize = 0;
2988    bd_info->resize_req.mouse.locked = 0;
2989
2990    /* set property on this border to say we are done dragging */
2991    ecore_x_e_illume_drag_set(bd->client.win, 0);
2992
2993    /* set property on zone window that a drag is finished */
2994    ecore_x_e_illume_drag_set(bd->zone->black_win, 0);
2995
2996    ecore_x_window_raise(bd->client.shell_win);
2997    _policy_border_illume_handlers_remove(bd_info);
2998
2999    return ECORE_CALLBACK_PASS_ON;
3000 }
3001
3002 static Eina_Bool
3003 _policy_border_cb_mouse_move(void *data,
3004                              int   type __UNUSED__,
3005                              void *event)
3006 {
3007    Ecore_Event_Mouse_Move *ev;
3008    E_Illume_Border_Info *bd_info;
3009    E_Border *bd;
3010    Evas_Object *rect;
3011
3012    L(LT_AIA, "[ILLUME2][AIA] %s(%d)... \n", __func__, __LINE__);
3013    ev = event;
3014    bd_info = data;
3015    bd = bd_info->border;
3016
3017    if (ev->window != bd->event_win &&
3018        ev->event_window != bd->event_win)
3019      return ECORE_CALLBACK_PASS_ON;
3020
3021    if (!bd_info->resize_req.mouse.down)
3022      return ECORE_CALLBACK_PASS_ON;
3023
3024    if (bd_info->resize_req.mouse.resize)
3025      {
3026         L(LT_AIA, "[ILLUME2][AIA] %s(%d)... event (x:%d, y:%d, root_x:%d, root_y:%d)\n", __func__, __LINE__, ev->x, ev->y, ev->root.x, ev->root.y);
3027         Evas_Object *o = (Evas_Object *)e_object_data_get(E_OBJECT(bd));
3028         if (!o) return ECORE_CALLBACK_PASS_ON;
3029
3030         Evas_Coord_Rectangle r;
3031         E_Resizable_Area_Info area;
3032
3033         _resize_rect_geometry_get(bd_info, &r, ev->root.x, ev->root.y, bd_info->resize_req.direction, &area);
3034         L(LT_AIA, "[ILLUME2][AIA] %s(%d)... x:%d, y:%d, w:%d, h:%d\n", __func__, __LINE__, r.x, r.y, r.w, r.h);
3035
3036         rect = edje_object_part_object_get(o, "opacity_rect");
3037
3038         if((r.w <= area.min_width && r.h <= area.min_height)
3039            || (r.w >= area.max_width && r.h >= area.max_height))
3040           {
3041             edje_object_signal_emit(o, "resize,notavail", "illume2");
3042             evas_object_color_set(rect, 64, 64, 64, 64);
3043           }
3044         else
3045           {
3046             edje_object_signal_emit(o, "resize,normal", "illume2");
3047             evas_object_color_set(rect, 255, 255, 255, 255);
3048           }
3049         if(area.x_dist < area.min_width && area.y_dist < area.min_height)
3050           {
3051             int tmp = 0;
3052             tmp = ((area.min_width-area.x_dist)>= (area.min_height-area.y_dist))? area.min_width - area.x_dist : area.min_height - area.y_dist;
3053             if( tmp >= 200)
3054                 tmp = 200;
3055             tmp /= 20;
3056             tmp %= 11;
3057             tmp --;
3058             tmp = (int)(128*( (double)tmp/10 + 1));
3059             evas_object_color_set(rect, tmp, tmp, tmp, tmp);
3060           }
3061         if (area.x_dist > area.max_width && area.y_dist > area.max_height)
3062           {
3063             int tmp = 0;
3064             tmp = ((area.x_dist - area.max_width) >= (area.y_dist - area.max_height))? area.x_dist - area.max_width : area.y_dist - area.max_height;
3065             if( tmp >= 200)
3066                tmp = 200;
3067             tmp /= 20;
3068             tmp %= 11;
3069             tmp --;
3070             tmp = (int)(128*( (double)tmp/10 + 1));
3071             evas_object_color_set(rect, tmp, tmp, tmp, tmp);
3072           }
3073
3074         evas_object_move(o, r.x, r.y);
3075         evas_object_resize(o, r.w, r.h);
3076      }
3077    else
3078      {
3079         L(LT_AIA, "[ILLUME2][AIA] %s(%d)... \n", __func__, __LINE__);
3080         bd_info->resize_req.mouse.x = ev->root.x + bd_info->resize_req.mouse.dx;
3081         bd_info->resize_req.mouse.y = ev->root.y + bd_info->resize_req.mouse.dy;
3082         bd->changes.pos = 1;
3083         bd->changed = EINA_TRUE;
3084      }
3085
3086    return ECORE_CALLBACK_PASS_ON;
3087 }
3088
3089 void
3090 _policy_property_change(Ecore_X_Event_Window_Property *event)
3091 {
3092    //   printf("Property Change\n");
3093
3094    /* we are interested in state changes here */
3095    if (event->atom == ECORE_X_ATOM_NET_WM_STATE)
3096      {
3097         _policy_property_window_state_change (event);
3098      }
3099    else if (event->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_GEOMETRY)
3100      {
3101         _policy_property_indicator_geometry_change (event);
3102      }
3103    else if (event->atom == ECORE_X_ATOM_E_ILLUME_CLIPBOARD_GEOMETRY)
3104      {
3105         _policy_property_clipboard_geometry_change (event);
3106      }
3107    else if (event->atom == ECORE_X_ATOM_E_ILLUME_CLIPBOARD_STATE)
3108      {
3109         _policy_property_clipboard_state_change (event);
3110      }
3111    else if (event->atom == ATM_ENLIGHTENMENT_SCALE)
3112      {
3113         _policy_property_enlightenment_scale_change (event);
3114      }
3115    else if (event->atom == ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE)
3116      {
3117         _policy_property_rotate_win_angle_change (event);
3118      }
3119    else if (event->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_STATE)
3120      {
3121         _policy_property_indicator_state_change (event);
3122      }
3123    else if (event->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_OPACITY_MODE)
3124      {
3125         _policy_property_indicator_opacity_change(event);
3126      }
3127    else if (event->atom == ECORE_X_ATOM_NET_ACTIVE_WINDOW)
3128      {
3129         _policy_property_active_win_change (event);
3130      }
3131    else if (event->atom == ECORE_X_ATOM_NET_WM_WINDOW_TYPE)
3132      {
3133         _policy_property_win_type_change (event);
3134      }
3135    else if (event->atom == E_ILLUME_ATOM_STACK_DISPLAY)
3136      {
3137         _policy_border_list_print (event->win);
3138      }
3139    else if (event->atom == ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE)
3140      {
3141         _policy_property_rotate_root_angle_change (event);
3142      }
3143    else if (event->atom == E_ILLUME_ATOM_NOTIFICATION_LEVEL)
3144      {
3145         _policy_property_notification_level_change (event);
3146      }
3147    /* for visibility */
3148    else if (event->atom == E_ILLUME_ATOM_OVERAY_WINDOW)
3149      {
3150         _policy_property_overlay_win_change (event);
3151      }
3152    else if (event->atom == E_ILLUME_ATOM_WINDOW_OPAQUE)
3153      {
3154         _policy_property_window_opaque_change (event);
3155      }
3156    else if (event->atom == ECORE_X_ATOM_E_ILLUME_WINDOW_STATE)
3157      {
3158         _policy_property_illume_window_state_change(event);
3159      }
3160    /* enable/disable composite module - 100320 yigl */
3161 #ifdef COMP_MODULE_CONTROL
3162    else if (event->atom == E_ILLUME_ATOM_COMP_MODULE_ENABLED)
3163      {
3164         _policy_property_composite_module_change (event);
3165      }
3166 #endif
3167 /* enable/disable backkey module - 130610 seongwon1.cho */
3168 #ifdef BACKKEY_MODULE_CONTROL
3169    else if (event->atom == E_ILLUME_ATOM_BACKKEY_MODULE_ENABLED)
3170      {
3171         _policy_property_backkey_module_change (event);
3172      }
3173 #endif
3174 /* enable/disable devmode module - 130610 seongwon1.cho */
3175 #ifdef DEVMODE_MODULE_CONTROL
3176    else if (event->atom == E_ILLUME_ATOM_DEVMODE_MODULE_ENABLED)
3177      {
3178         _policy_property_devmode_module_change (event);
3179      }
3180 #endif
3181    else if (event->atom == E_INDICATOR_CMD_WIN)
3182      {
3183         _policy_property_indicator_cmd_win_change(event);
3184      }
3185    else if (event->atom == E_ACTIVE_INDICATOR_WIN)
3186      {
3187         _policy_property_active_indicator_win_change(event);
3188      }
3189 }
3190
3191
3192 void
3193 _policy_border_list_print (Ecore_X_Window win)
3194 {
3195    Eina_List* border_list;
3196    Eina_List *l;
3197    E_Border *bd;
3198    E_Border* temp_bd = NULL;
3199    int i, ret, count;
3200    E_Illume_Print_Info info;
3201    unsigned char* prop_data = NULL;
3202    FILE* out;
3203
3204    info.type = 0;
3205    memset (info.file_name, 0, 256);
3206
3207    ret = ecore_x_window_prop_property_get (win, E_ILLUME_ATOM_STACK_DISPLAY, ECORE_X_ATOM_CARDINAL, 32, &prop_data, &count);
3208    if( ret && prop_data )
3209       memcpy (&info, prop_data, sizeof (E_Illume_Print_Info));
3210
3211    if (prop_data) free (prop_data);
3212
3213    out = fopen (info.file_name, "w+");
3214    if (out == NULL) out = stderr;
3215
3216    if ((info.type & PT_STACK) == PT_STACK)
3217      {
3218         border_list = e_border_client_list();
3219         if (border_list)
3220           {
3221              i = 1;
3222              fprintf (out, "--------------------------------BORDER INFO--------------------------------------------------\n" );
3223              fprintf (out, " No  Border     ClientWin     w     h       x       y   layer  visible  WinName\n" );
3224              fprintf (out, "---------------------------------------------------------------------------------------------\n" );
3225
3226              EINA_LIST_FOREACH(border_list, l, bd)
3227                {
3228                   if (!bd) continue;
3229                   if (temp_bd == NULL) temp_bd = bd;
3230
3231                   fprintf (out, "%3i  0x%07x  0x%07x  %4i  %4i  %6i  %6i  %5i  %5i     %-30s \n",
3232                           i++, bd->win, bd->client.win, bd->w, bd->h, bd->x, bd->y, bd->layer, bd->visible, bd->client.netwm.name);
3233                }
3234              fprintf (out, "---------------------------------------------------------------------------------------------\n" );
3235           }
3236         ecore_x_flush();
3237
3238         E_Illume_Border_Info* bd_info;
3239         if (e_border_info_list)
3240           {
3241              i = 1;
3242              fprintf (out, "--------------------------------ILLUME BORDER INFO------------------------------------------------------------------\n" );
3243              fprintf (out, " No  Border     ClientWin     w     h       x       y   isKBD layer level desk   WinName\n" );
3244              fprintf (out, "--------------------------------------------------------------------------------------------------------------------\n" );
3245
3246              EINA_LIST_FOREACH(e_border_info_list, l, bd_info)
3247                {
3248                   E_Zone *zone;
3249                   E_Border *bd;
3250                   int x, y;
3251                   int desk_x=0, desk_y=0;
3252                   if (!bd_info) continue;
3253
3254                   bd = bd_info->border;
3255                   zone = bd->zone;
3256
3257                   for (x = 0; x < zone->desk_x_count; x++)
3258                     {
3259                        for (y = 0; y < zone->desk_y_count; y++)
3260                          {
3261                             if (bd->desk == zone->desks[x + zone->desk_x_count * y])
3262                               {
3263                                  desk_x = x;
3264                                  desk_y = y;
3265                                  break;
3266                               }
3267                          }
3268                     }
3269                   fprintf (out, "%3i  0x%07x  0x%07x  %4i  %4i  %6i  %6i  %3i  %5i %5i   (%d,%d)  %-30s \n",
3270                           i++, bd_info->border->win, bd_info->border->client.win, bd_info->border->w, bd_info->border->h, bd_info->border->x, bd_info->border->y,
3271                           bd_info->border->client.vkbd.vkbd, bd_info->border->layer, bd_info->level, desk_x, desk_y, bd_info->border->client.netwm.name);
3272                }
3273              fprintf (out, "--------------------------------------------------------------------------------------------------------------------\n" );
3274           }
3275         ecore_x_flush();
3276
3277         if (temp_bd == NULL) goto finish;
3278
3279         E_Border_List *bl;
3280
3281         fprintf (out, "-------------------------------- E17 STACK INFO--------------------------------------------\n" );
3282         fprintf (out, " No  Border     ClientWin     w     h       x       y   layer  visible  WinName\n" );
3283         fprintf (out, "---------------------------------------------------------------------------------------------\n" );
3284
3285         i = 1;
3286         bl = e_container_border_list_last(temp_bd->zone->container);
3287         while ((bd = e_container_border_list_prev(bl)))
3288           {
3289              fprintf (out, "%3i  0x%07x  0x%07x  %4i  %4i  %6i  %6i  %5i  %5i     %-30s \n",
3290                      i++, bd->win, bd->client.win, bd->w, bd->h, bd->x, bd->y, bd->layer, bd->visible, bd->client.netwm.name);
3291           }
3292         e_container_border_list_free(bl);
3293         fprintf (out, "---------------------------------------------------------------------------------------------\n\n" );
3294      }
3295
3296    /* for visibility */
3297    if ((info.type & PT_VISIBILITY) == PT_VISIBILITY)
3298      {
3299         Eina_Inlist* xwin_info_list;
3300         E_Illume_XWin_Info *xwin_info;
3301
3302         xwin_info_list = _e_illume_xwin_info_list;
3303         if (xwin_info_list)
3304           {
3305              i = 1;
3306              fprintf (out, "--------------------------------BORDER INFO--------------------------------------------------\n" );
3307              fprintf (out, " No  Win          w     h       x       y   depth  viewable  visibility comp_vis iconify by_wm is_border(Client Win)\n" );
3308              fprintf (out, "---------------------------------------------------------------------------------------------\n" );
3309
3310              EINA_INLIST_REVERSE_FOREACH (xwin_info_list, xwin_info)
3311                {
3312                   if (xwin_info->bd_info)
3313                     {
3314                        if (xwin_info->bd_info->border)
3315                          {
3316                             fprintf (out, "%3i  0x%07x  %4i  %4i  %6i  %6i  %5i   %5i     %5i      %5i   %5i  %5i    yes(0x%07x)\n",
3317                                     i++, xwin_info->id, xwin_info->attr.w, xwin_info->attr.h, xwin_info->attr.x, xwin_info->attr.y, xwin_info->attr.depth,
3318                                     xwin_info->viewable, xwin_info->visibility, xwin_info->comp_vis, xwin_info->bd_info->border->iconic, xwin_info->iconify_by_wm, xwin_info->bd_info->border->client.win);
3319                          }
3320                        else
3321                          {
3322                             fprintf (out, "%3i  0x%07x  %4i  %4i  %6i  %6i  %5i   %5i     %5i      %5i       0    %3i        no(NULL)\n",
3323                                     i++, xwin_info->id, xwin_info->attr.w, xwin_info->attr.h, xwin_info->attr.x, xwin_info->attr.y, xwin_info->attr.depth,
3324                                     xwin_info->viewable, xwin_info->visibility, xwin_info->comp_vis, xwin_info->iconify_by_wm);
3325                          }
3326                     }
3327                   else
3328                     {
3329                        fprintf (out, "%3i  0x%07x  %4i  %4i  %6i  %6i  %5i   %5i      %5i     %5i       0    %3i        no(NULL)\n",
3330                                i++, xwin_info->id, xwin_info->attr.w, xwin_info->attr.h, xwin_info->attr.x, xwin_info->attr.y, xwin_info->attr.depth,
3331                                xwin_info->viewable, xwin_info->visibility, xwin_info->comp_vis, xwin_info->iconify_by_wm);
3332                     }
3333                }
3334              fprintf (out, "---------------------------------------------------------------------------------------------\n" );
3335           }
3336
3337         ecore_x_flush();
3338      }
3339
3340 finish:
3341
3342    fprintf (out, "--------------------------------GLOBAL INFO--------------------------------------------------\n" );
3343    fprintf (out, "g_rotated_win:0x%07x (g_root_angle:%d)\n", g_rotated_win, g_root_angle);
3344    fprintf (out, "g_active_win:0x%07x (pid:%d, angle:%d)\n", g_active_win, g_active_pid, _policy_window_rotation_angle_get(g_active_win));
3345    fprintf (out, "g_indi_control_win:0x%07x\n", g_indi_control_win);
3346    fprintf (out, "---------------------------------------------------------------------------------------------\n" );
3347
3348    if (out != stderr)
3349      {
3350         fflush (out);
3351         fclose (out);
3352      }
3353
3354    ecore_x_client_message32_send (ecore_x_window_root_first_get(), E_ILLUME_ATOM_STACK_DISPLAY_DONE,
3355                                   ECORE_X_EVENT_MASK_WINDOW_CONFIGURE,
3356                                   0, 0, 0, 0, 0);
3357 }
3358
3359
3360 static int
3361 _policy_window_rotation_angle_get(Ecore_X_Window win)
3362 {
3363    Atom type_ret = 0;
3364    int ret, size_ret = 0;
3365    unsigned long num_ret = 0, bytes = 0;
3366    unsigned char *prop_ret = NULL;
3367    Ecore_X_Display *dpy;
3368    int angle;
3369
3370    dpy = ecore_x_display_get();
3371
3372    if (!win)
3373      win = ecore_x_window_root_first_get();
3374
3375    ret = XGetWindowProperty(dpy, win, ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE, 0, LONG_MAX,
3376                             False, ECORE_X_ATOM_CARDINAL, &type_ret, &size_ret,
3377                             &num_ret, &bytes, &prop_ret);
3378
3379    if (ret == ECORE_X_ERROR_CODE_SUCCESS)
3380      {
3381         if (prop_ret && num_ret)
3382           {
3383              angle = ((int *)prop_ret)[0];
3384              if (angle % 90) angle = -1;
3385           }
3386         else
3387           angle = 0;
3388      }
3389    else
3390      {
3391         angle = -1;
3392      }
3393
3394    if (prop_ret) XFree(prop_ret);
3395
3396    return angle;
3397 }
3398
3399
3400 static Ecore_X_Window
3401 _policy_active_window_get(Ecore_X_Window root)
3402 {
3403    Ecore_X_Window win;
3404    int ret;
3405
3406    ret = ecore_x_window_prop_xid_get(root,
3407                                      ECORE_X_ATOM_NET_ACTIVE_WINDOW,
3408                                      ECORE_X_ATOM_WINDOW,
3409                                      &win, 1);
3410
3411    if ((ret == 1) && win)
3412       return win;
3413    else
3414       return 0;
3415 }
3416
3417 static int
3418 _policy_border_indicator_state_get(E_Border *bd)
3419 {
3420    Ecore_X_Illume_Indicator_State state;
3421    int show;
3422
3423    state = ecore_x_e_illume_indicator_state_get(bd->client.win);
3424    if (state == ECORE_X_ILLUME_INDICATOR_STATE_ON)
3425      show = 1;
3426    else if (state == ECORE_X_ILLUME_INDICATOR_STATE_OFF)
3427      show = 0;
3428    else
3429      show = -1;
3430
3431    return show;
3432 }
3433
3434 static void _policy_layout_quickpanel_rotate (E_Illume_Quickpanel* qp, int angle)
3435 {
3436    E_Border* bd;
3437    Eina_List *bd_list;
3438    E_Illume_Quickpanel_Info *panel;
3439
3440    if (!qp) return;
3441
3442    int diff, temp;
3443
3444    // pass 1 - resize window
3445    // It caused abnormal size of quickpanel window and abnormal rotation state.
3446    // disable it for now.
3447 #if 0
3448    EINA_LIST_FOREACH(qp->borders, bd_list, panel)
3449      {
3450         if (!panel) continue;
3451         if (panel->angle == angle) continue;
3452
3453         if (panel->angle > angle) diff = panel->angle - angle;
3454         else diff = angle - panel->angle;
3455
3456         bd = panel->bd;
3457
3458         if (angle == 0 || angle == 180)
3459           {
3460              if (diff == 90 || diff == 270)
3461                {
3462                   temp = bd->w;
3463                   ILLUME2_TRACE ("[ILLUME2-QUICKPANEL] Portrait quick panel...(%d) quick win = 0x%07x  old (%d, %d)  new (%d, %d)\n", __LINE__, bd->client.win, bd->w, bd->h, bd->zone->w, temp);
3464                   _policy_border_resize (bd, bd->zone->w, temp);
3465                }
3466              else
3467                 ILLUME2_TRACE ("[ILLUME2-QUICKPANEL] Portrait quick panel...(%d) quick win = 0x%07x..  But size is not change\n", __LINE__, bd->client.win);
3468           }
3469         else
3470           {
3471              if (diff == 90 || diff == 270)
3472                {
3473                   temp = bd->h;
3474                   ILLUME2_TRACE ("[ILLUME2-QUICKPANEL] Landscape quick panel...(%d) quick win = 0x%07x  old (%d, %d)  new (%d, %d)\n", __LINE__, bd->client.win, bd->w, bd->h, temp, bd->zone->h);
3475                   _policy_border_resize (bd, temp, bd->zone->h);
3476                }
3477              else
3478                 ILLUME2_TRACE ("[ILLUME2-QUICKPANEL] Landscape quick panel...(%d) quick win = 0x%07x..  But size is not change\n", __LINE__, bd->client.win);
3479           }
3480      }
3481 #endif
3482
3483    // pass 2 - send client message
3484    EINA_LIST_FOREACH(qp->borders, bd_list, panel)
3485      {
3486         if (!panel) continue;
3487         if (panel->angle == angle) continue;
3488
3489         if (panel->angle > angle) diff = panel->angle - angle;
3490         else diff = angle - panel->angle;
3491
3492         bd = panel->bd;
3493
3494         ILLUME2_TRACE ("[ILLUME2-QUICKPANEL] SEND CLIENT MESSAGE TO QUICKPANEL!!!!(%d)  win:0x%07x, angle = %d\n", __LINE__, bd->client.win, angle);
3495         ecore_x_client_message32_send (bd->client.win, ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE,
3496                                        ECORE_X_EVENT_MASK_WINDOW_CONFIGURE,
3497                                        angle, 0, 0, 0, 0);
3498
3499         panel->angle = angle;
3500      }
3501 }
3502
3503 void
3504 _policy_window_focus_in(Ecore_X_Event_Window_Focus_In *event)
3505 {
3506    ILLUME2_TRACE("[ILLUME2-FOCUS] _policy_window_focus_in... win = 0x%07x\n", event->win);
3507
3508    E_Border *bd;
3509
3510    if (e_config->focus_policy == E_FOCUS_CLICK) return;
3511
3512    if (!(bd = e_border_find_by_client_window(event->win))) return;
3513
3514    if (e_illume_border_is_indicator (bd))
3515      {
3516         Eina_List *ml, *cl;
3517         E_Manager *man;
3518         E_Container *con;
3519
3520         EINA_LIST_FOREACH(e_manager_list(), ml, man)
3521           {
3522              if (!man) continue;
3523              EINA_LIST_FOREACH(man->containers, cl, con)
3524                {
3525                   E_Border_List *bl;
3526                   E_Border *temp_bd;
3527
3528                   // send focus to top-level window.
3529                   bl = e_container_border_list_last(con);
3530                   while ((temp_bd = e_container_border_list_prev(bl)))
3531                     {
3532                        if (temp_bd->client.icccm.accepts_focus && temp_bd->visible)
3533                          {
3534                             /* focus the border */
3535                             e_border_focus_set(temp_bd, 1, 1);
3536                             e_container_border_list_free(bl);
3537                             return;
3538                          }
3539                     }
3540                   e_container_border_list_free(bl);
3541                }
3542           }
3543      }
3544 }
3545
3546
3547 void _policy_border_stack_change (E_Border* bd, E_Border* sibling, int stack_mode)
3548 {
3549    L (LT_STACK, "[ILLUME2][STACK] %s(%d)... win = 0x%07x, sibling = 0x%07x, stack mode = %d\n", __func__, __LINE__, bd->client.win, sibling->client.win, stack_mode);
3550
3551    if (bd->layer != sibling->layer)
3552      {
3553         L (LT_STACK, "[ILLUME2][STACK] %s(%d)... Sibling layer is different!!! win = 0x%07x (layer = %d), sibling = 0x%07x (layer = %d)\n", __func__, __LINE__, bd->client.win, bd->layer, sibling->client.win, sibling->layer);
3554         return;
3555      }
3556
3557    L (LT_STACK, "[ILLUME2][STACK] %s(%d)... Restack Window.. win = 0x%07x,  sibling = 0x%07x, stack_mode = %d\n", __func__, __LINE__, bd->win, sibling->win, stack_mode);
3558    if (stack_mode == E_ILLUME_STACK_ABOVE)
3559      {
3560         L (LT_STACK, "[ILLUME2][STACK] %s(%d)... STACK CHANGE with ABOVE... win:0x%07x, above_win:0x%07x\n", __func__, __LINE__, bd->client.win, sibling->client.win);
3561         e_border_stack_above (bd, sibling);
3562      }
3563    else if (stack_mode == E_ILLUME_STACK_BELOW)
3564      {
3565         L (LT_STACK, "[ILLUME2][STACK] %s(%d)... STACK CHANGE with BELOW... win:0x%07x, below_win:0x%07x\n", __func__, __LINE__, bd->client.win, sibling->client.win);
3566         e_border_stack_below (bd, sibling);
3567      }
3568 }
3569
3570
3571 int _policy_atom_init (void)
3572 {
3573    /* Notification Level Atom */
3574    E_ILLUME_ATOM_NOTIFICATION_LEVEL = ecore_x_atom_get ("_E_ILLUME_NOTIFICATION_LEVEL");
3575    if (!E_ILLUME_ATOM_NOTIFICATION_LEVEL)
3576      {
3577         fprintf (stderr, "[ILLUME2] Critical Error!!! Cannot create _E_ILLUME_NOTIFICATION_LEVEL Atom...\n");
3578         return 0;
3579      }
3580
3581    /* for active/deactive message */
3582    E_ILLUME_ATOM_ACTIVATE_WINDOW = ecore_x_atom_get ("_X_ILLUME_ACTIVATE_WINDOW");
3583    if (!E_ILLUME_ATOM_ACTIVATE_WINDOW)
3584      {
3585         fprintf (stderr, "[ILLUME2] Critical Error!!! Cannot create _X_ILLUME_ACTIVATE_WINDOW Atom...\n");
3586         return 0;
3587      }
3588
3589    E_ILLUME_ATOM_DEACTIVATE_WINDOW = ecore_x_atom_get ("_X_ILLUME_DEACTIVATE_WINDOW");
3590    if (!E_ILLUME_ATOM_DEACTIVATE_WINDOW)
3591      {
3592         fprintf (stderr, "[ILLUME2] Critical Error!!! Cannot create _X_ILLUME_DEACTIVATE_WINDOW Atom...\n");
3593         return 0;
3594      }
3595
3596    /* for visibility */
3597    E_ILLUME_ATOM_OVERAY_WINDOW = ecore_x_atom_get ("_E_COMP_OVERAY_WINDOW");
3598    if (!E_ILLUME_ATOM_OVERAY_WINDOW)
3599      {
3600         fprintf (stderr, "[ILLUME2] Critical Error!!! Cannot create _E_COMP_OVERAY_WINDOW Atom...\n");
3601         return 0;
3602      }
3603
3604    E_ILLUME_ATOM_STACK_DISPLAY = ecore_x_atom_get ("_E_ILLUME_PRINT_BORDER_WIN_STACK");
3605    if (!E_ILLUME_ATOM_STACK_DISPLAY)
3606      {
3607         fprintf (stderr, "[ILLUME2] Critical Error!!! Cannot create _E_ILLUME_PRINT_BORDER_WIN_STACK Atom...\n");
3608         return 0;
3609      }
3610
3611    E_ILLUME_ATOM_STACK_DISPLAY_DONE = ecore_x_atom_get ("_E_ILLUME_PRINT_BORDER_WIN_STACK_DONE");
3612    if (!E_ILLUME_ATOM_STACK_DISPLAY_DONE)
3613      {
3614         fprintf (stderr, "[ILLUME2] Critical Error!!! Cannot create _E_ILLUME_PRINT_BORDER_WIN_STACK_DONE Atom...\n");
3615         return 0;
3616      }
3617
3618    E_ILLUME_ATOM_WINDOW_OPAQUE = ecore_x_atom_get ("_E_ILLUME_WINDOW_REGION_OPAQUE");
3619    if (!E_ILLUME_ATOM_WINDOW_OPAQUE)
3620      {
3621         fprintf (stderr, "[ILLUME2] Critical Error!!! Cannot create _E_ILLUME_WINDOW_REGION_OPAQUE Atom...\n");
3622         return 0;
3623      }
3624
3625 #ifdef COMP_MODULE_CONTROL
3626    E_ILLUME_ATOM_COMP_MODULE_ENABLED = ecore_x_atom_get ("_E_COMP_ENABLE");
3627    if(!E_ILLUME_ATOM_COMP_MODULE_ENABLED)
3628      {
3629         fprintf (stderr, "[ILLUME2] Critical Error!!! Cannot create _E_COMP_ENABLE Atom...\n");
3630         return 0;
3631      }
3632 #endif
3633
3634 #ifdef BACKKEY_MODULE_CONTROL
3635    E_ILLUME_ATOM_BACKKEY_MODULE_ENABLED = ecore_x_atom_get ("_E_BACKKEY_ENABLE");
3636    if(!E_ILLUME_ATOM_BACKKEY_MODULE_ENABLED)
3637      {
3638         fprintf (stderr, "[ILLUME2] Critical Error!!! Cannot create _E_BACKKEY_ENABLE Atom...\n");
3639         return 0;
3640      }
3641 #endif
3642
3643 #ifdef DEVMODE_MODULE_CONTROL
3644    E_ILLUME_ATOM_DEVMODE_MODULE_ENABLED = ecore_x_atom_get ("_E_DEVMODE_ENABLE");
3645    if(!E_ILLUME_ATOM_DEVMODE_MODULE_ENABLED)
3646      {
3647         fprintf (stderr, "[ILLUME2] Critical Error!!! Cannot create _E_DEVMODE_ENABLE Atom...\n");
3648         return 0;
3649      }
3650 #endif
3651
3652    E_INDICATOR_CMD_WIN = ecore_x_atom_get("_E_INDICATOR_CMD_WIN");
3653    if (!E_INDICATOR_CMD_WIN)
3654      {
3655         fprintf (stderr, "[ILLUME2] Critical Error!!! Cannot create _E_INDICATOR_CMD_WIN Atom...\n");
3656         return 0;
3657      }
3658
3659    E_ACTIVE_INDICATOR_WIN = ecore_x_atom_get("_E_ACTIVE_INDICATOR_WIN");
3660    if (!E_ACTIVE_INDICATOR_WIN)
3661      {
3662         fprintf (stderr, "[ILLUME2] Critical Error!!! Cannot create _E_ACTIVE_INDICATOR_WIN Atom...\n");
3663         return 0;
3664      }
3665
3666    return 1;
3667 }
3668
3669
3670 int _policy_init (void)
3671 {
3672    Eina_List *ml;
3673    E_Manager *man;
3674
3675    /* for visibility */
3676    _e_illume_xwin_info_hash = eina_hash_string_superfast_new(NULL);
3677    EINA_LIST_FOREACH(e_manager_list(), ml, man)
3678      {
3679         _policy_manage_xwins (man);
3680
3681         dep_rot.root = man->root;
3682         dep_rot.refer.cmd_win = _policy_indicator_cmd_win_get(dep_rot.root);
3683         if (dep_rot.refer.cmd_win)
3684           dep_rot.refer.active_win = _policy_active_indicator_win_get(dep_rot.refer.cmd_win);
3685      }
3686
3687    // initialize atom
3688    if (!_policy_atom_init())
3689      {
3690         eina_hash_free (_e_illume_xwin_info_hash);
3691         return 0;
3692      }
3693
3694    /* for visibility */
3695    _e_illume_msg_handler = e_msg_handler_add(_policy_msg_handler, NULL);
3696
3697    return 1;
3698 }
3699
3700
3701 void _policy_fin (void)
3702 {
3703    /* for visibility */
3704    if (_e_illume_msg_handler) e_msg_handler_del(_e_illume_msg_handler);
3705    eina_hash_free (_e_illume_xwin_info_hash);
3706 }
3707
3708 static int
3709 _policy_compare_cb_border (E_Illume_Border_Info* data1, E_Illume_Border_Info* data2)
3710 {
3711    if (data1 && data2)
3712      {
3713         if (data1->border == data2->border)
3714            return 0;
3715      }
3716
3717    return 1;
3718 }
3719
3720
3721 static E_Illume_Border_Info*
3722 _policy_get_border_info (E_Border* bd)
3723 {
3724    ILLUME2_TRACE ("[ILLUME2-NEW] %s(%d)... bd = %x, bd's client = 0x%07x\n", __func__, __LINE__, bd, bd->client.win);
3725    E_Illume_Border_Info tmp_win;
3726    tmp_win.border = bd;
3727    return (E_Illume_Border_Info*) eina_list_search_unsorted (
3728       e_border_info_list, EINA_COMPARE_CB(_policy_compare_cb_border), &tmp_win);
3729 }
3730
3731
3732 static E_Illume_Border_Info* _policy_add_border_info_list (E_Border* bd)
3733 {
3734    ILLUME2_TRACE ("[ILLUME2-NEW] %s(%d)... bd = %x, bd's client = 0x%07x\n", __func__, __LINE__, bd, bd->client.win);
3735
3736    if (e_object_is_del(E_OBJECT(bd))) return NULL;
3737
3738    E_Illume_Border_Info* bd_info = (E_Illume_Border_Info*) calloc (1, sizeof (E_Illume_Border_Info));
3739    if (!bd_info)
3740      {
3741         fprintf (stderr, "[ILLUME2] Critical Error... Fail to create memory... (%s:%d)\n", __func__, __LINE__);
3742         return NULL;
3743      }
3744    bd_info->pid = bd->client.netwm.pid;
3745    bd_info->border = bd;
3746    // set level
3747    bd_info->level = 50;
3748    // set opaque
3749    bd_info->opaque = _policy_property_window_opaque_get(bd->client.win);
3750
3751    // could find bd_info of ev->stack.. there is no bd_info yet...
3752    Eina_List *l = NULL;
3753    E_Illume_Border_Info *temp_bd_info = NULL;
3754
3755    EINA_LIST_FOREACH(e_border_info_list, l, temp_bd_info)
3756      {
3757         if (!temp_bd_info) continue;
3758         if (bd_info->border->layer >= temp_bd_info->border->layer)
3759         break;
3760      }
3761
3762    if (temp_bd_info)
3763      {
3764         e_border_info_list = eina_list_prepend_relative(e_border_info_list, bd_info, temp_bd_info);
3765         L (LT_STACK, "[ILLUME2][STACK] %s(%d)... changed to [ bd(win:0x%07x) -> other(win:0x%07x) ]\n", __func__, __LINE__, bd->client.win, temp_bd_info->border->client.win);
3766      }
3767    else
3768      {
3769         e_border_info_list = eina_list_append (e_border_info_list, bd_info);
3770         L (LT_STACK, "[ILLUME2][STACK] %s(%d)... changed to [ ---> bd(win:0x%07x) ]\n", __func__, __LINE__, bd->client.win);
3771      }
3772
3773    return bd_info;
3774 }
3775
3776
3777 static void _policy_delete_border_info_list (E_Border* bd)
3778 {
3779    ILLUME2_TRACE ("[ILLUME2-NEW] %s(%d)...  bd = %x, bd's client = 0x%07x\n", __func__, __LINE__, bd, bd->client.win);
3780    E_Illume_Border_Info* bd_info = _policy_get_border_info (bd);
3781
3782    if (bd_info == NULL)
3783      {
3784         ILLUME2_TRACE ("[ILLUME2-NEW] %s(%d)... There is no border in the list... bd = %x, bd's client = 0x%07x\n", __func__, __LINE__, bd, bd->client.win);
3785         return;
3786      }
3787
3788    _policy_border_illume_handlers_remove(bd_info);
3789
3790    e_border_info_list = eina_list_remove (e_border_info_list, bd_info);
3791    L (LT_STACK, "[ILLUME2][STACK] %s(%d)... remove bd(win:0x%07x)\n", __func__, __LINE__, bd->client.win);
3792    free (bd_info);
3793 }
3794
3795
3796 static int
3797 _policy_zone_layout_app_layer_check (E_Border* bd)
3798 {
3799    Ecore_X_Window_Type *types = NULL;
3800    E_Illume_Border_Info *bd_info;
3801    int num, i, layer;
3802
3803    if (!bd) return POL_APP_LAYER;
3804
3805    bd_info = _policy_get_border_info(bd);
3806    if (!bd_info) return POL_APP_LAYER;
3807
3808    layer = POL_APP_LAYER;
3809
3810    num = ecore_x_netwm_window_types_get(bd->client.win, &types);
3811    if (num)
3812      {
3813         i = 0;
3814         for (i=0; i< num; i++)
3815           {
3816              if (types[i] == ECORE_X_WINDOW_TYPE_NOTIFICATION)
3817                layer = _policy_notification_level_map(bd_info->level);
3818           }
3819
3820         free (types);
3821      }
3822
3823    if (bd->client.netwm.state.stacking == E_STACKING_BELOW)
3824      {
3825         ILLUME2_TRACE ("[ILLUME2-NEW] %s(%d)... WIN:0x%07x  is BELOW state.. Change layer to 50\n", __func__, __LINE__, bd->client.win);
3826         layer = POL_STATE_BELOW_LAYER;
3827      }
3828    else if (bd->client.netwm.state.stacking == E_STACKING_ABOVE)
3829      {
3830         ILLUME2_TRACE ("[ILLUME2-NEW] %s(%d)... WIN:0x%07x  is ABOVE state.. Change layer to 150\n", __func__, __LINE__, bd->client.win);
3831         layer = POL_STATE_ABOVE_LAYER;
3832      }
3833
3834    return layer;
3835 }
3836
3837
3838 static void
3839 _policy_zone_layout_app_layer_set (E_Border* bd, int new_layer)
3840 {
3841    if (!bd) return;
3842
3843    /* if a window sets transient_for property, it sets same layer to parent window */
3844    if (bd->client.icccm.transient_for != 0)
3845      {
3846         E_Border *bd_parent = NULL;
3847         bd_parent = e_border_find_by_client_window (bd->client.icccm.transient_for);
3848         if (bd_parent)
3849           {
3850              if (bd->layer != bd_parent->layer)
3851                 e_border_layer_set (bd, bd_parent->layer);
3852           }
3853      }
3854    else
3855      {
3856         if (bd->layer != new_layer)
3857            e_border_layer_set(bd, new_layer);
3858      }
3859 }
3860
3861 static void
3862 _policy_zone_layout_app_single_new (E_Illume_Border_Info* bd_info, E_Illume_Config_Zone *cz)
3863 {
3864    E_Border* bd;
3865    int layer;
3866    Eina_Bool resize = EINA_FALSE;
3867    Eina_Bool move = EINA_FALSE;
3868
3869    ILLUME2_TRACE ("[ILLUME2-NEW] %s(%d)... LAYOUT_SINGLE... bd_info's border = %x, client win = 0x%07x\n", __func__, __LINE__, bd_info->border, bd_info->border->client.win);
3870
3871    bd = bd_info->border;
3872    if (!bd)
3873      {
3874         fprintf (stderr, "[ILLUME2] fatal error! (%s)  There is no border!\n", __func__);
3875         return;
3876      }
3877
3878    if (bd->moving && !bd->client.illume.win_state.state)
3879      {
3880         L(LT_AIA, "[ILLUME2][AIA] %s(%d)... Cancel moving... win:0x%07x, bd->moving:%d\n", __func__, __LINE__, bd->client.win, bd->moving);
3881         e_border_move_cancel();
3882      }
3883
3884    if ((!bd->new_client) && (!bd->visible)) return;
3885
3886    layer = _policy_zone_layout_app_layer_check (bd);
3887
3888    /* check if user defined position */
3889    if (bd->client.icccm.request_pos)
3890      {
3891         if (bd->client.illume.win_state.state)
3892           {
3893              if (bd_info->resize_req.need_change)
3894                {
3895                   if ((bd->x != bd_info->resize_req.mouse.x) ||
3896                       (bd->y != bd_info->resize_req.mouse.y))
3897                     move = EINA_TRUE;
3898
3899                   if ((bd->w != bd_info->resize_req.mouse.w) ||
3900                       (bd->h != bd_info->resize_req.mouse.h))
3901                     resize = EINA_TRUE;
3902
3903                   if (move && resize)
3904                     {
3905                        e_border_move_resize(bd,
3906                                             bd_info->resize_req.mouse.x,
3907                                             bd_info->resize_req.mouse.y,
3908                                             bd_info->resize_req.mouse.w,
3909                                             bd_info->resize_req.mouse.h);
3910                     }
3911                   else if (move)
3912                     {
3913                        _policy_border_move(bd,
3914                                            bd_info->resize_req.mouse.x,
3915                                            bd_info->resize_req.mouse.y);
3916                     }
3917                   else if (resize)
3918                     {
3919                        _policy_border_resize(bd,
3920                                              bd_info->resize_req.mouse.w,
3921                                              bd_info->resize_req.mouse.h);
3922                     }
3923
3924                   bd_info->resize_req.need_change = 0;
3925                   L(LT_AIA, "[ILLUME2][AIA] %s(%d)... bd move resize... (%d, %d, %d, %d)\n", __func__, __LINE__, bd->x, bd->y, bd->w, bd->h);
3926                }
3927
3928              if (bd_info->resize_req.mouse.down &&
3929                  bd_info->resize_req.mouse.locked)
3930                {
3931                   if ((bd->x != bd_info->resize_req.mouse.x) ||
3932                       (bd->y != bd_info->resize_req.mouse.y))
3933                     _policy_border_move(bd,
3934                                         bd_info->resize_req.mouse.x,
3935                                         bd_info->resize_req.mouse.y);
3936                   L(LT_AIA, "[ILLUME2][AIA] %s(%d)... bd move resize... (%d, %d, %d, %d)\n", __func__, __LINE__, bd->x, bd->y, bd->w, bd->h);
3937                }
3938           }
3939
3940         _policy_zone_layout_app_layer_set (bd, layer);
3941         return;
3942      }
3943
3944    /* resize & move if needed */
3945    if (bd->client.illume.win_state.state)
3946      {
3947         if (bd_info->resize_req.need_change)
3948           {
3949              if ((bd->x != bd_info->resize_req.mouse.x) ||
3950                  (bd->y != bd_info->resize_req.mouse.y))
3951                move = EINA_TRUE;
3952
3953              if ((bd->w != bd_info->resize_req.mouse.w) ||
3954                  (bd->h != bd_info->resize_req.mouse.h))
3955                resize = EINA_TRUE;
3956
3957              if (move && resize)
3958                {
3959                   e_border_move_resize(bd,
3960                                        bd_info->resize_req.mouse.x,
3961                                        bd_info->resize_req.mouse.y,
3962                                        bd_info->resize_req.mouse.w,
3963                                        bd_info->resize_req.mouse.h);
3964                }
3965              else if (move)
3966                {
3967                   _policy_border_move(bd,
3968                                       bd_info->resize_req.mouse.x,
3969                                       bd_info->resize_req.mouse.y);
3970                }
3971              else if (resize)
3972                {
3973                   _policy_border_resize(bd,
3974                                         bd_info->resize_req.mouse.w,
3975                                         bd_info->resize_req.mouse.h);
3976                }
3977
3978              L(LT_AIA, "[ILLUME2][AIA] %s(%d)... bd move resize... (%d, %d, %d, %d)\n", __func__, __LINE__, bd->x, bd->y, bd->w, bd->h);
3979              bd_info->resize_req.need_change = 0;
3980           }
3981
3982         if (bd_info->resize_req.mouse.down &&
3983             bd_info->resize_req.mouse.locked)
3984           {
3985              if ((bd->x != bd_info->resize_req.mouse.x) ||
3986                  (bd->y != bd_info->resize_req.mouse.y))
3987                _policy_border_move(bd,
3988                                    bd_info->resize_req.mouse.x,
3989                                    bd_info->resize_req.mouse.y);
3990              L(LT_AIA, "[ILLUME2][AIA] %s(%d)... bd move resize... (%d, %d, %d, %d)\n", __func__, __LINE__, bd->x, bd->y, bd->w, bd->h);
3991           }
3992      }
3993    else
3994      {
3995         if ((bd->w != bd->zone->w) || (bd->h != bd->zone->h))
3996           resize = EINA_TRUE;
3997
3998         if ((bd->x != bd->zone->x) || (bd->y != bd->zone->y))
3999           move = EINA_TRUE;
4000
4001         if (resize && move)
4002           e_border_move_resize(bd, bd->zone->x, bd->zone->y, bd->zone->w, bd->zone->h);
4003         else if (resize)
4004           _policy_border_resize(bd, bd->zone->w, bd->zone->h);
4005         else if (move)
4006           _policy_border_move(bd, bd->zone->x, bd->zone->y);
4007      }
4008
4009    /* set layer if needed */
4010    _policy_zone_layout_app_layer_set (bd, layer);
4011 }
4012
4013
4014 static void
4015 _policy_zone_layout_app_dual_top_new (E_Illume_Border_Info* bd_info, E_Illume_Config_Zone *cz)
4016 {
4017    E_Border* bd;
4018    E_Border* temp_bd;
4019    int ny, nh;
4020    int layer;
4021    Eina_Bool resize = EINA_FALSE;
4022    Eina_Bool move = EINA_FALSE;
4023
4024    ILLUME2_TRACE ("[ILLUME2-NEW] %s(%d)... LAYOUT_DUAL_TOP... bd_info's border = %x, client win = 0x%07x\n", __func__, __LINE__, bd_info->border, bd_info->border->client.win);
4025
4026    bd = bd_info->border;
4027
4028    if (!bd || !cz) return;
4029    if ((!bd->new_client) && (!bd->visible)) return;
4030
4031    layer = _policy_zone_layout_app_layer_check (bd);
4032
4033    // check if user defined position
4034    if (bd->client.icccm.request_pos)
4035      {
4036         _policy_zone_layout_app_layer_set (bd, layer);
4037         return;
4038      }
4039
4040    /* set a default Y position */
4041    ny = (bd->zone->y + cz->indicator.size);
4042    nh = ((bd->zone->h - cz->indicator.size - cz->softkey.size) / 2);
4043
4044    /* see if there is a border already there. if so, check placement based on
4045     * virtual keyboard usage */
4046    temp_bd = e_illume_border_at_xy_get(bd->zone, bd->zone->x, ny);
4047    if ((temp_bd) && (temp_bd != bd)) ny = temp_bd->y + nh;
4048
4049    /* resize if needed */
4050    if ((bd->w != bd->zone->w) || (bd->h != nh))
4051      resize = EINA_TRUE;
4052
4053    /* move to correct position (relative to zone) if needed */
4054    if ((bd->x != bd->zone->x) || (bd->y != ny))
4055      move = EINA_TRUE;
4056
4057    if (resize && move)
4058      e_border_move_resize(bd, bd->zone->x, ny, bd->zone->w, nh);
4059    else if (resize)
4060      _policy_border_resize(bd, bd->zone->w, nh);
4061    else if (move)
4062      _policy_border_move(bd, bd->zone->x, ny);
4063
4064    /* set layer if needed */
4065    _policy_zone_layout_app_layer_set (bd, layer);
4066 }
4067
4068 static void
4069 _policy_zone_layout_app_dual_left_new (E_Illume_Border_Info* bd_info, E_Illume_Config_Zone *cz)
4070 {
4071    E_Border* bd;
4072    E_Border* temp_bd;
4073    int ky, kh, nx, nw;
4074    int layer;
4075    Eina_Bool resize = EINA_FALSE;
4076    Eina_Bool move = EINA_FALSE;
4077
4078    ILLUME2_TRACE ("[ILLUME2-NEW] %s(%d)... LAYOUT_DUAL_LEFT... bd_info's border = %x, client win = 0x%07x\n", __func__, __LINE__, bd_info->border, bd_info->border->client.win);
4079
4080    bd = bd_info->border;
4081
4082    if (!bd || !cz) return;
4083    if ((!bd->new_client) && (!bd->visible)) return;
4084
4085    layer = _policy_zone_layout_app_layer_check (bd);
4086
4087    // check if user defined position
4088    if (bd->client.icccm.request_pos)
4089      {
4090         _policy_zone_layout_app_layer_set (bd, layer);
4091         return;
4092      }
4093
4094    /* set some defaults */
4095    nx = bd->zone->x;
4096    nw = (bd->zone->w / 2);
4097
4098    ky = bd->zone->y + cz->indicator.size;
4099    kh = bd->zone->h - cz->indicator.size - cz->softkey.size;
4100
4101    /* see if there is a border already there. if so, place at right */
4102    temp_bd = e_illume_border_at_xy_get(bd->zone, nx, (ky + bd->zone->h / 2));
4103    if ((temp_bd) && (bd != temp_bd)) nx = temp_bd->x + nw;
4104
4105    /* resize if needed */
4106    if ((bd->w != nw) || (bd->h != kh))
4107      resize = EINA_TRUE;
4108
4109    /* move to correct position (relative to zone) if needed */
4110    if ((bd->x != nx) || (bd->y != ky))
4111      move = EINA_TRUE;
4112
4113    if (resize && move)
4114      e_border_move_resize(bd, nx, ky, nw, kh);
4115    else if (resize)
4116      _policy_border_resize(bd, nw, kh);
4117    else if (move)
4118      _policy_border_move(bd, nx, ky);
4119
4120    /* set layer if needed */
4121    _policy_zone_layout_app_layer_set (bd, layer);
4122 }
4123
4124
4125 static void
4126 _policy_zone_layout_app_dual_custom_new (E_Illume_Border_Info* bd_info, E_Illume_Config_Zone *cz)
4127 {
4128    E_Border* bd;
4129    E_Border *app;
4130    int iy, ny, nh;
4131    Eina_Bool resize = EINA_FALSE;
4132    Eina_Bool move = EINA_FALSE;
4133
4134    ILLUME2_TRACE ("[ILLUME2-NEW] %s(%d)... LAYOUT_DUAL_CUSTOM... bd_info's border = %x, client win = 0x%07x\n", __func__, __LINE__, bd_info->border, bd_info->border->client.win);
4135
4136    bd = bd_info->border;
4137    if (!bd)
4138      {
4139         fprintf (stderr, "[ILLUME2] fatal error! (%s)  There is no border!\n", __func__);
4140         return;
4141      }
4142
4143    if ((!bd->new_client) && (!bd->visible)) return;
4144
4145    /* grab indicator position */
4146    e_illume_border_indicator_pos_get(bd->zone, NULL, &iy);
4147
4148    /* set a default position */
4149    ny = bd->zone->y;
4150    nh = iy;
4151
4152    app = e_illume_border_at_xy_get(bd->zone, bd->zone->x, bd->zone->y);
4153    if (app)
4154      {
4155         if (bd != app)
4156           {
4157              ny = (iy + cz->indicator.size);
4158              nh = ((bd->zone->y + bd->zone->h) - ny - cz->softkey.size);
4159           }
4160      }
4161
4162    /* make sure it's the required width & height */
4163    if ((bd->w != bd->zone->w) || (bd->h != nh))
4164      resize = EINA_TRUE;
4165
4166    /* move to correct position (relative to zone) if needed */
4167    if ((bd->x != bd->zone->x) || (bd->y != ny))
4168      move = EINA_TRUE;
4169
4170    if (resize && move)
4171      e_border_move_resize(bd, bd->zone->x, ny, bd->zone->w, nh);
4172    else if (resize)
4173      _policy_border_resize(bd, bd->zone->w, nh);
4174    else if (move)
4175      _policy_border_move(bd, bd->zone->x, ny);
4176
4177    /* set layer if needed */
4178    if (bd->layer != POL_APP_LAYER)
4179       e_border_layer_set(bd, POL_APP_LAYER);
4180 }
4181
4182 static int _policy_border_get_notification_level (Ecore_X_Window win)
4183 {
4184    int ret;
4185    int num;
4186    int level = 50;
4187    unsigned char* prop_data = NULL;
4188
4189    ret = ecore_x_window_prop_property_get (win, E_ILLUME_ATOM_NOTIFICATION_LEVEL, ECORE_X_ATOM_CARDINAL, 32, &prop_data, &num);
4190    if( ret && prop_data )
4191       memcpy (&level, prop_data, sizeof (int));
4192
4193    if (prop_data) free (prop_data);
4194
4195    return level;
4196 }
4197
4198 static int
4199 _policy_notification_level_map(int level)
4200 {
4201    switch (level)
4202      {
4203       case E_ILLUME_NOTIFICATION_LEVEL_LOW:     return POL_NOTIFICATION_LAYER_LOW;
4204       case E_ILLUME_NOTIFICATION_LEVEL_NORMAL:  return POL_NOTIFICATION_LAYER_NORMAL;
4205       case E_ILLUME_NOTIFICATION_LEVEL_HIGH:    return POL_NOTIFICATION_LAYER_HIGH;
4206       default:                                  return POL_NOTIFICATION_LAYER_LOW;
4207      }
4208 }
4209
4210 /* find new focus window */
4211 static void
4212 _policy_border_focus_top_stack_set (E_Border* bd)
4213 {
4214    E_Border *temp_bd;
4215    E_Border *cur_focus;
4216    E_Border_List *bl;
4217    int root_w, root_h;
4218
4219    root_w = bd->zone->w;
4220    root_h = bd->zone->h;
4221
4222    cur_focus = e_border_focused_get();
4223
4224    bl = e_container_border_list_last(bd->zone->container);
4225    while ((temp_bd = e_container_border_list_prev(bl)))
4226      {
4227         if (temp_bd == cur_focus) break;
4228
4229         if ((temp_bd->x >= root_w) || (temp_bd->y >= root_h)) continue;
4230         if (((temp_bd->x + temp_bd->w) <= 0) || ((temp_bd->y + temp_bd->h) <= 0)) continue;
4231         if ((temp_bd != bd) &&
4232             (temp_bd->client.illume.win_state.state == ECORE_X_ILLUME_WINDOW_STATE_FLOATING)) continue;
4233
4234         if ((!temp_bd->iconic) && (temp_bd->visible) && (temp_bd->desk == bd->desk) &&
4235             (temp_bd->client.icccm.accepts_focus || temp_bd->client.icccm.take_focus) &&
4236             (temp_bd->client.netwm.type != ECORE_X_WINDOW_TYPE_DOCK) &&
4237             (temp_bd->client.netwm.type != ECORE_X_WINDOW_TYPE_TOOLBAR) &&
4238             (temp_bd->client.netwm.type != ECORE_X_WINDOW_TYPE_MENU) &&
4239             (temp_bd->client.netwm.type != ECORE_X_WINDOW_TYPE_SPLASH) &&
4240             (temp_bd->client.netwm.type != ECORE_X_WINDOW_TYPE_DESKTOP))
4241           {
4242              if (!temp_bd->focused)
4243                {
4244                   /* this border is the top of the latest stack */
4245                   e_border_focus_set (temp_bd, 1, 1);
4246                }
4247              break;
4248           }
4249      }
4250    e_container_border_list_free(bl);
4251 }
4252
4253 void _policy_border_stack (E_Event_Border_Stack *event)
4254 {
4255    E_Event_Border_Stack* ev;
4256    E_Illume_Border_Info* bd_info;
4257    E_Illume_Border_Info* stack_bd_info;
4258
4259    ev = event;
4260
4261    L (LT_STACK, "[ILLUME2][STACK] %s(%d)... bd(win:0x%07x), stack(win:0x%07x), stack type: %d\n", __func__, __LINE__, ev->border->client.win, ev->stack ? (unsigned int)ev->stack->client.win:(unsigned int)NULL, ev->type);
4262
4263    bd_info = _policy_get_border_info(ev->border);
4264    if (!bd_info) return;
4265
4266    if (ev->stack)
4267      {
4268         stack_bd_info = _policy_get_border_info(ev->stack);
4269      }
4270    else
4271      {
4272         stack_bd_info = NULL;
4273      }
4274
4275    if (ev->type == E_STACKING_ABOVE)
4276      {
4277         if (ev->stack)
4278           {
4279              if (stack_bd_info)
4280                {
4281                   e_border_info_list = eina_list_remove (e_border_info_list, bd_info);
4282                   e_border_info_list = eina_list_prepend_relative (e_border_info_list, bd_info, stack_bd_info);
4283                   L (LT_STACK, "[ILLUME2][STACK] %s(%d)... changed to [ bd(win:0x%07x) -> stack(win:0x%07x) ]\n", __func__, __LINE__, ev->border->client.win, ev->stack->client.win);
4284                }
4285              else
4286                {
4287                   // could find bd_info of ev->stack.. there is no bd_info yet...
4288                   Eina_List *l = NULL;
4289                   E_Illume_Border_Info *temp_bd_info;
4290
4291                   EINA_LIST_FOREACH(e_border_info_list, l, temp_bd_info)
4292                     {
4293                        if (!temp_bd_info) continue;
4294                        if (bd_info->border->layer >= temp_bd_info->border->layer)
4295                           break;
4296                     }
4297
4298                   if (bd_info != temp_bd_info)
4299                     {
4300                        e_border_info_list = eina_list_remove (e_border_info_list, bd_info);
4301                        e_border_info_list = eina_list_prepend_relative(e_border_info_list, bd_info, temp_bd_info);
4302                        L (LT_STACK, "[ILLUME2][STACK] %s(%d)... changed to [ bd(win:0x%07x) -> other(win:0x%07x).. No stack(win:0x%07x) info ]\n", __func__, __LINE__, ev->border->client.win, temp_bd_info ? (unsigned int)temp_bd_info->border->client.win:(unsigned int)NULL, ev->stack->client.win);
4303                     }
4304                }
4305           }
4306         else
4307           {
4308              e_border_info_list = eina_list_remove (e_border_info_list, bd_info);
4309              e_border_info_list = eina_list_append (e_border_info_list, bd_info);
4310              L (LT_STACK, "[ILLUME2][STACK] %s(%d)... changed to [ ---> bd(win:0x%07x) ]\n", __func__, __LINE__, ev->border->client.win);
4311           }
4312      }
4313    else if (ev->type == E_STACKING_BELOW)
4314      {
4315         if (ev->stack)
4316           {
4317              if (stack_bd_info)
4318                {
4319                   e_border_info_list = eina_list_remove (e_border_info_list, bd_info);
4320                   e_border_info_list = eina_list_append_relative (e_border_info_list, bd_info, stack_bd_info);
4321                   L (LT_STACK, "[ILLUME2][STACK] %s(%d)... changed to [ stack(win:0x%07x) -> bd(win:0x%07x) ]\n", __func__, __LINE__, ev->stack->client.win, ev->border->client.win);
4322                }
4323              else
4324                {
4325                   // could find bd_info of ev->stack.. there is no bd_info yet...
4326                   Eina_List *l = NULL;
4327                   E_Illume_Border_Info *temp_bd_info;
4328
4329                   EINA_LIST_FOREACH(e_border_info_list, l, temp_bd_info)
4330                     {
4331                        if (!temp_bd_info) continue;
4332                        if (bd_info->border->layer >= temp_bd_info->border->layer)
4333                           break;
4334                     }
4335
4336                   if (bd_info != temp_bd_info)
4337                     {
4338                        e_border_info_list = eina_list_remove (e_border_info_list, bd_info);
4339                        e_border_info_list = eina_list_prepend_relative(e_border_info_list, bd_info, temp_bd_info);
4340                        L (LT_STACK, "[ILLUME2][STACK] %s(%d)... changed to [ bd(win:0x%07x) -> other(win:0x%07x).. No stack(win:0x%07x) info ]\n", __func__, __LINE__, ev->border->client.win, temp_bd_info ? (unsigned int)temp_bd_info->border->client.win:(unsigned int)NULL, ev->stack->client.win);
4341                     }
4342                }
4343           }
4344         else
4345           {
4346              e_border_info_list = eina_list_remove (e_border_info_list, bd_info);
4347              e_border_info_list = eina_list_prepend (e_border_info_list, bd_info);
4348              L (LT_STACK, "[ILLUME2][STACK] %s(%d)... changed to [ bd(win:0x%07x) ---> ]\n", __func__, __LINE__, ev->border->client.win);
4349           }
4350      }
4351    else
4352      {
4353         ILLUME2_TRACE ("[ILLUME2-NEW] %s(%d)... Unknown type... border (0x%07x), win (0x%07x), type = %d\n", __func__, __LINE__, ev->border, ev->border->client.win, ev->type);
4354      }
4355
4356    /* restack indicator when a active window stack is changed */
4357    if ((ev->border->client.win == g_active_win) &&
4358        (ev->border->layer == POL_NOTIFICATION_LAYER))
4359      {
4360         E_Border* indi_bd;
4361         indi_bd = e_illume_border_indicator_get(ev->border->zone);
4362         if (indi_bd)
4363           {
4364              L(LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... win = 0x%07x..  Control Indicator.\n", __func__, __LINE__, ev->border->client.win);
4365              _policy_border_indicator_control(indi_bd);
4366           }
4367      }
4368
4369    ev->border->changes.pos = 1;
4370    ev->border->changed = 1;
4371
4372    return;
4373 }
4374
4375 void _policy_border_zone_set(E_Event_Border_Zone_Set *event)
4376 {
4377    E_Event_Border_Zone_Set* ev;
4378    E_Border *bd;
4379
4380    ev = event;
4381
4382    bd = event->border;
4383    if (!bd) return;
4384
4385    ecore_x_e_illume_zone_set(bd->client.win, bd->zone->black_win);
4386 }
4387
4388 static void _policy_change_quickpanel_layer (E_Illume_Quickpanel* qp, E_Border* indi_bd, int layer, int level)
4389 {
4390    Eina_List *bd_list;
4391    E_Illume_Quickpanel_Info *panel;
4392    E_Illume_Border_Info* bd_info;
4393
4394    if (!qp) return;
4395
4396    if (qp->popup)
4397      {
4398         bd_info = _policy_get_border_info(qp->popup->border);
4399         if (bd_info)
4400           {
4401              bd_info->level = level;
4402              e_border_stack_below (qp->popup->border, indi_bd);
4403           }
4404      }
4405
4406    EINA_LIST_FOREACH(qp->hidden_mini_controllers, bd_list, panel)
4407      {
4408         if (!panel) continue;
4409         if (e_object_is_del(E_OBJECT(panel->bd))) continue;
4410
4411         bd_info = _policy_get_border_info(panel->bd);
4412         if (bd_info)
4413           {
4414              bd_info->level = level;
4415              e_border_stack_below (panel->bd, indi_bd);
4416           }
4417      }
4418
4419    EINA_LIST_FOREACH(qp->borders, bd_list, panel)
4420      {
4421         if (!panel) continue;
4422         if (e_object_is_del(E_OBJECT(panel->bd))) continue;
4423
4424         bd_info = _policy_get_border_info(panel->bd);
4425         if (bd_info)
4426           {
4427              bd_info->level = level;
4428              e_border_stack_below (panel->bd, indi_bd);
4429           }
4430      }
4431 }
4432
4433 static void _policy_change_indicator_layer(E_Border *indi_bd, E_Border *bd, int layer, int level)
4434 {
4435    // the indicator's layer is changed to layer with level
4436    E_Illume_Border_Info *indi_bd_info;
4437    E_Illume_Quickpanel *qp;
4438    int new_noti_layer = 0;
4439
4440    indi_bd_info = _policy_get_border_info(indi_bd);
4441    if (indi_bd_info)
4442      {
4443         indi_bd_info->level = level;
4444      }
4445
4446    if (layer == POL_NOTIFICATION_LAYER)
4447      {
4448         new_noti_layer = _policy_notification_level_map(level);
4449
4450         if (indi_bd->layer != new_noti_layer)
4451           e_border_layer_set(indi_bd, new_noti_layer);
4452      }
4453    else if (indi_bd->layer != layer)
4454      e_border_layer_set(indi_bd, layer);
4455
4456    if (bd)
4457      {
4458         E_Border *top_bd;
4459         E_Illume_Border_Info *top_bd_info;
4460
4461         // check transient_for window
4462         top_bd = _policy_border_transient_for_border_top_get(bd);
4463         if (!top_bd) top_bd = bd;
4464
4465         top_bd_info = _policy_get_border_info(top_bd);
4466         if (!top_bd_info)
4467           {
4468              if ((qp = e_illume_quickpanel_by_zone_get(indi_bd->zone)))
4469                {
4470                   _policy_change_quickpanel_layer(qp, indi_bd, layer, level);
4471                }
4472              return;
4473           }
4474
4475         L (LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... indicator's below win:0x%07x\n", __func__, __LINE__, top_bd->client.win);
4476         _policy_border_stack_change(indi_bd, top_bd, E_ILLUME_STACK_ABOVE);
4477
4478         e_border_info_list = eina_list_remove(e_border_info_list, indi_bd_info);
4479         e_border_info_list = eina_list_prepend_relative(e_border_info_list, indi_bd_info, top_bd_info);
4480         L (LT_STACK, "[ILLUME2][STACK] %s(%d)... changed to [ bd(win:0x%07x) -> other(win:0x%07x) ]\n", __func__, __LINE__, indi_bd->client.win, top_bd->client.win);
4481      }
4482
4483    if ((qp = e_illume_quickpanel_by_zone_get(indi_bd->zone)))
4484      {
4485         _policy_change_quickpanel_layer(qp, indi_bd, layer, level);
4486      }
4487 }
4488
4489 static Eina_Bool _policy_border_indicator_state_change(E_Border *indi_bd, E_Border *bd)
4490 {
4491    E_Illume_Border_Info *bd_info;
4492    int indi_show;
4493    int level;
4494
4495    if (!indi_bd || !bd) return EINA_FALSE;
4496
4497    indi_show = _policy_border_indicator_state_get(bd);
4498    if (indi_show == 1)
4499      {
4500         L(LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... Show Indicator (by win: 0x%07x)\n", __func__, __LINE__, bd->client.win);
4501         e_border_show(indi_bd);
4502
4503         if ((e_illume_border_is_notification(bd)) ||
4504             (bd->layer == POL_NOTIFICATION_LAYER))
4505           {
4506              bd_info = _policy_get_border_info(bd);
4507              if (bd_info)
4508                level = bd_info->level;
4509              else
4510                level = 150;
4511
4512              L(LT_NOTIFICATION, "[ILLUME2][NOTIFICATION]  %s(%d)... Notification Win:0x%07x, Update Indicator's layer to NOTIFICATION.. level = %d\n", __func__, __LINE__, bd->client.win, level);
4513              _policy_change_indicator_layer(indi_bd, bd, POL_NOTIFICATION_LAYER, level);
4514           }
4515         else
4516           {
4517              _policy_change_indicator_layer(indi_bd, NULL, POL_NOTIFICATION_LAYER, 50);
4518           }
4519
4520         return EINA_TRUE;
4521      }
4522    else if (indi_show == 0)
4523      {
4524         L(LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... Hide Indicator (by win: 0x%07x)\n", __func__, __LINE__, bd->client.win);
4525         e_border_hide(indi_bd, 2);
4526         return EINA_TRUE;
4527      }
4528    else
4529      {
4530         return EINA_FALSE;
4531      }
4532 }
4533
4534 static void
4535 _policy_border_indicator_control(E_Border *indi_bd)
4536 {
4537    Eina_Inlist *xwin_info_list;
4538    E_Illume_XWin_Info *xwin_info;
4539    E_Border *bd;
4540    Ecore_X_Illume_Indicator_Opacity_Mode mode;
4541
4542    if (!indi_bd) return;
4543
4544    xwin_info = NULL;
4545    xwin_info_list = _e_illume_xwin_info_list;
4546
4547    if (xwin_info_list)
4548      {
4549         EINA_INLIST_REVERSE_FOREACH (xwin_info_list, xwin_info)
4550           {
4551              if (xwin_info->visibility != E_ILLUME_VISIBILITY_FULLY_OBSCURED)
4552                {
4553                   if (xwin_info->bd_info)
4554                     {
4555                        bd = xwin_info->bd_info->border;
4556
4557                        if (!bd) continue;
4558                        if (!bd->visible) continue;
4559                        if (indi_bd == bd) continue;
4560                        if (indi_bd->zone != bd->zone) continue;
4561                        if (e_illume_border_is_indicator(bd)) continue;
4562                        if (e_illume_border_is_keyboard(bd)) continue;
4563                        if (bd->client.illume.win_state.state == ECORE_X_ILLUME_WINDOW_STATE_FLOATING) continue;
4564
4565                        if (!_policy_border_indicator_state_change(indi_bd, bd))
4566                          continue;
4567
4568                        mode = ecore_x_e_illume_indicator_opacity_get(bd->client.win);
4569                        ecore_x_e_illume_indicator_opacity_send(indi_bd->client.win, mode);
4570
4571                        _policy_root_angle_set(bd);
4572
4573                        L(LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... indicator_control_win = 0x%07x...\n", __func__, __LINE__, bd->client.win);
4574                        g_indi_control_win = bd->client.win;
4575                        break;
4576                     }
4577                }
4578           }
4579      }
4580 }
4581
4582 /* for visibility */
4583 static void
4584 _policy_send_visibility_notify (Ecore_X_Window win, int visibility)
4585 {
4586    XEvent event;
4587
4588    event.type = VisibilityNotify;
4589    event.xvisibility.display = ecore_x_display_get();
4590    event.xvisibility.send_event = EINA_TRUE;
4591    event.xvisibility.state = visibility;
4592    event.xvisibility.window = win;
4593
4594    XSendEvent(event.xvisibility.display
4595       , event.xvisibility.window
4596       , False
4597       , VisibilityChangeMask, &event);
4598 }
4599
4600 static Eina_Bool
4601 _policy_check_transient_child_visible(E_Border *bd)
4602 {
4603    Eina_Bool ret = EINA_FALSE;
4604    E_Illume_XWin_Info *child_xwin_info = NULL;
4605    Eina_List *l;
4606    E_Border *child = NULL;
4607
4608    EINA_LIST_FOREACH(bd->transients, l, child)
4609      {
4610         if (!child) continue;
4611         if (ret) return ret;
4612
4613         child_xwin_info = _policy_xwin_info_find(child->win);
4614         if ((child_xwin_info) &&
4615             (child_xwin_info->visibility == E_ILLUME_VISIBILITY_UNOBSCURED))
4616           {
4617              return EINA_TRUE;
4618           }
4619
4620         ret = _policy_check_transient_child_visible(child);
4621      }
4622
4623    return ret;
4624 }
4625
4626 static void
4627 _policy_calculate_visibility(void)
4628 {
4629    // 1. CALCULATES window's region and decide it's visibility.
4630    // 2. DO (UN)ICONIFY if it's needed.
4631    // 3. SEND notify about visibility.
4632    //
4633    E_Zone *zone = NULL;
4634    E_Border *bd = NULL, *indi_bd = NULL;
4635    Eina_Inlist *xwin_info_list = NULL;
4636    E_Illume_XWin_Info *xwin_info = NULL;
4637    E_Illume_Border_Info *bd_info = NULL;
4638    Ecore_X_XRegion *visible_region = NULL;
4639    Ecore_X_XRegion *win_region = NULL;
4640    Ecore_X_Rectangle visible_rect, win_rect;
4641    Eina_Bool is_fully_obscured = EINA_FALSE;
4642    Eina_Bool is_opaque_win = EINA_FALSE;
4643    Eina_Bool do_not_iconify = EINA_FALSE;
4644    Eina_Bool alpha_opaque = EINA_FALSE;
4645    Eina_Bool obscured_by_alpha_opaque = EINA_FALSE;
4646    int old_vis = 0;
4647    int set_root_angle = 0;
4648    int control_indi = 0;
4649
4650    if (!_g_visibility_changed) return;
4651    _g_visibility_changed = EINA_FALSE;
4652
4653    L(LT_VISIBILITY, "[ILLUME2][VISIBILITY] %s(%d).. BEGIN calculate visibility ...\n",  __func__, __LINE__);
4654    xwin_info_list = _e_illume_xwin_info_list;
4655    if (!xwin_info_list) return;
4656
4657    // set the entire visible region as a root geometry
4658    visible_rect.x = 0;
4659    visible_rect.y = 0;
4660    visible_rect.width = _g_root_width;
4661    visible_rect.height = _g_root_height;
4662
4663    visible_region = ecore_x_xregion_new();
4664    if (!visible_region)
4665      {
4666         L (LT_VISIBILITY_DETAIL,
4667            "[ILLUME2][VISIBILITY] BAD.... Creating visible region is failed.\n");
4668         return;
4669      }
4670
4671    ecore_x_xregion_union_rect(visible_region, visible_region, &visible_rect);
4672
4673    EINA_INLIST_REVERSE_FOREACH (xwin_info_list, xwin_info)
4674      {
4675         // skip "input only" window
4676         if (xwin_info->attr.input_only) continue;
4677
4678         // skip "unmap" window
4679         if ((xwin_info->viewable == 0) &&
4680             (xwin_info->iconify_by_wm == 0)) continue;
4681
4682         if (!xwin_info->is_drawed) continue;
4683
4684         // initializing variable
4685         bd_info = NULL;
4686         bd = NULL;
4687         is_opaque_win   = EINA_TRUE;
4688         do_not_iconify = EINA_FALSE;
4689         old_vis = xwin_info->visibility;
4690
4691         bd_info = xwin_info->bd_info;
4692         if (bd_info) bd = bd_info->border;
4693
4694         // 1. calculates window's region and decide it's visibility.
4695         if (is_fully_obscured == EINA_FALSE)
4696           {
4697              win_rect.x = xwin_info->attr.x;
4698              win_rect.y = xwin_info->attr.y;
4699              win_rect.width = xwin_info->attr.w;
4700              win_rect.height = xwin_info->attr.h;
4701
4702              // if it stick out or is bigger than the entire visible region,
4703              // clip it by the entire visible's geometry.
4704              E_RECTS_CLIP_TO_RECT(win_rect.x, win_rect.y,
4705                                   win_rect.width, win_rect.height,
4706                                   visible_rect.x, visible_rect.y,
4707                                   (int)(visible_rect.width), (int)(visible_rect.height));
4708
4709              if (ecore_x_xregion_rect_contain(visible_region, &win_rect))
4710                {
4711                   L(LT_VISIBILITY_DETAIL, "[ILLUME2][VISIBILITY] %s(%d)... win:0x%07x Un-OBSCURED.. \n", __func__, __LINE__, xwin_info->id);
4712                   xwin_info->visibility = E_ILLUME_VISIBILITY_UNOBSCURED;
4713
4714                   if (bd)
4715                     {
4716                        if (bd->client.argb)
4717                          {
4718                             if (bd_info && bd_info->opaque)
4719                               {
4720                                  alpha_opaque = EINA_TRUE;
4721                               }
4722                             else
4723                               {
4724                                  is_opaque_win = EINA_FALSE;
4725                               }
4726                          }
4727
4728                        if (bd->client.illume.win_state.state ==
4729                            ECORE_X_ILLUME_WINDOW_STATE_FLOATING)
4730                          {
4731                             is_opaque_win = EINA_FALSE;
4732                          }
4733                     }
4734                   else
4735                     {
4736                        if (xwin_info->argb)
4737                          is_opaque_win = EINA_FALSE;
4738                     }
4739
4740                   if (is_opaque_win)
4741                     {
4742                        win_region = ecore_x_xregion_new();
4743                        if (win_region)
4744                          {
4745                             ecore_x_xregion_union_rect(win_region, win_region, &win_rect);
4746                             ecore_x_xregion_subtract(visible_region, visible_region, win_region);
4747                             ecore_x_xregion_free(win_region);
4748                             win_region = NULL;
4749
4750                             if (ecore_x_xregion_is_empty(visible_region))
4751                               {
4752                                  is_fully_obscured = EINA_TRUE;
4753                                  if (alpha_opaque)
4754                                    {
4755                                       L(LT_VISIBILITY_DETAIL, "[ILLUME2][VISIBILITY] %s(%d)... OBSCURED by alpha opaque win:0x%07x\n", __func__, __LINE__, xwin_info->id);
4756                                       obscured_by_alpha_opaque = EINA_TRUE;
4757                                       alpha_opaque = EINA_FALSE;
4758                                    }
4759                               }
4760                          }
4761                     }
4762                }
4763              else
4764                {
4765                   L(LT_VISIBILITY_DETAIL, "[ILLUME2][VISIBILITY] %s(%d)... win:0x%07x Fully OBSCURED.. place on OUTSIDE\n", __func__, __LINE__, xwin_info->id);
4766                   xwin_info->visibility = E_ILLUME_VISIBILITY_FULLY_OBSCURED;
4767                }
4768           }
4769         else
4770           {
4771              L(LT_VISIBILITY_DETAIL, "[ILLUME2][VISIBILITY] %s(%d)... win:0x%07x Fully OBSCURED.. \n", __func__, __LINE__, xwin_info->id);
4772              xwin_info->visibility = E_ILLUME_VISIBILITY_FULLY_OBSCURED;
4773           }
4774
4775         if (!bd) continue;
4776         if (!E_ILLUME_BORDER_IS_IN_MOBILE(bd)) continue;
4777
4778         // decide if it's the border that DO NOT iconify.
4779         if (obscured_by_alpha_opaque)
4780           {
4781              do_not_iconify = EINA_TRUE;
4782           }
4783         // when this border has transient windows,
4784         // check out this child's visibility.
4785         // if there is any child window that is UNOBSCURED,
4786         // DO NOT iconify this border.
4787         else if (bd->transients)
4788           {
4789              do_not_iconify = _policy_check_transient_child_visible(bd);
4790           }
4791
4792         // 2. DO (UN)ICONIFY and send visibility notify if it's needed.
4793         if (old_vis != xwin_info->visibility)
4794           {
4795 #ifdef USE_DLOG
4796              SECURE_SLOGD("[WM] SEND VISIBILITY. win:0x%07x (old:%d -> new:%d)", xwin_info->bd_info->border->client.win, old_vis, xwin_info->visibility);
4797 #endif
4798              L(LT_VISIBILITY, "[ILLUME2][VISIBILITY] SEND VISIBILITY NOTIFY (Line:%d)... win:0x%07x (old:%d -> new:%d)\n", __LINE__, bd->client.win, old_vis, xwin_info->visibility);
4799              _policy_send_visibility_notify(bd->client.win, xwin_info->visibility);
4800
4801              if (xwin_info->visibility == E_ILLUME_VISIBILITY_UNOBSCURED)
4802                {
4803                   L (LT_ANGLE, "[ILLUME2][ANGLE] %s(%d).. CALL _policy_change_root_angle_by_border_angle!!! win:0x%07x\n", __func__, __LINE__, xwin_info->bd_info->border->client.win);
4804                   set_root_angle = 1;
4805
4806                   if (_e_illume_cfg->use_force_iconify)
4807                     {
4808                        if (bd->iconic)
4809                          {
4810                             L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d).. Uniconify by illume.. win:0x%07x (parent:0x%07x)\n", __func__, __LINE__, xwin_info->bd_info->border->client.win, xwin_info->bd_info->border->parent ? xwin_info->bd_info->border->parent->client.win:(unsigned int)NULL);
4811                             _policy_border_force_uniconify(bd);
4812                          }
4813                     }
4814                }
4815              else if (xwin_info->visibility == E_ILLUME_VISIBILITY_FULLY_OBSCURED)
4816                {
4817                   if (bd->client.win == g_rotated_win)
4818                     {
4819                        L(LT_ANGLE, "[ILLUME2][ANGLE] %s(%d).. g_rotated_win(0x%07x) is obscured.\n", __func__, __LINE__, xwin_info->bd_info->border->client.win);
4820                        set_root_angle = 1;
4821                     }
4822
4823                   if (_e_illume_cfg->use_force_iconify)
4824                     {
4825                        if ((!bd->iconic) && (!do_not_iconify))
4826                          {
4827                             L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d).. Iconify by illume.. win:0x%07x (parent:0x%07x)\n", __func__, __LINE__, xwin_info->bd_info->border->client.win, xwin_info->bd_info->border->parent ? xwin_info->bd_info->border->parent->client.win:(unsigned int)NULL);
4828                             _policy_border_iconify_by_illume(xwin_info);
4829                          }
4830                     }
4831                }
4832
4833              control_indi = 1;
4834              zone = xwin_info->bd_info->border->zone;
4835           }
4836         else
4837           {
4838              if (xwin_info->visibility == E_ILLUME_VISIBILITY_FULLY_OBSCURED)
4839                {
4840                   if (_e_illume_cfg->use_force_iconify)
4841                     {
4842                        if (bd->parent && bd->parent->iconic)
4843                          {
4844                             if ((!bd->iconic) && (!do_not_iconify))
4845                               {
4846                                  L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d).. Iconify by illume.. win:0x%07x (parent:0x%07x)\n", __func__, __LINE__, xwin_info->bd_info->border->client.win, xwin_info->bd_info->border->parent ? xwin_info->bd_info->border->parent->client.win:(unsigned int)NULL);
4847                                  _policy_border_iconify_by_illume(xwin_info);
4848                               }
4849                          }
4850                        else if (bd->iconic && do_not_iconify)
4851                          {
4852                             L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d).. Uniconify by illume.. win:0x%07x\n", __func__, __LINE__, xwin_info->bd_info->border->client.win);
4853                             _policy_border_force_uniconify(bd);
4854                          }
4855                     }
4856                }
4857           }
4858
4859         // 3. check if opaque window is ocupied the screen.
4860         // then we reset the obscured_by_alpha_opaque flag
4861         if (xwin_info->visibility == E_ILLUME_VISIBILITY_FULLY_OBSCURED)
4862           {
4863              if (obscured_by_alpha_opaque && is_opaque_win)
4864                {
4865                   if (E_CONTAINS(xwin_info->attr.x, xwin_info->attr.y, xwin_info->attr.w, xwin_info->attr.h,
4866                                  0, 0, _g_root_width, _g_root_height))
4867                     {
4868                        L(LT_VISIBILITY_DETAIL, "[ILLUME2][VISIBILITY] %s(%d)... unset obscured_by_alpha_opaque  win:%x\n", __func__, __LINE__, xwin_info->id);
4869                        obscured_by_alpha_opaque = EINA_FALSE;
4870                     }
4871                }
4872           }
4873      }
4874
4875    if (control_indi)
4876      {
4877         if (_e_illume_cfg->use_indicator_widget)
4878           {
4879              L(LT_ANGLE, "[ILLUME2][ANGLE] %s(%d)... Control Root Angle.\n", __func__, __LINE__);
4880              _policy_border_root_angle_control(zone);
4881           }
4882         else
4883           {
4884              indi_bd = e_illume_border_indicator_get(zone);
4885              if (indi_bd)
4886                {
4887                   L(LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... Control Indicator.\n", __func__, __LINE__);
4888                   _policy_border_indicator_control(indi_bd);
4889                }
4890           }
4891      }
4892
4893    L(LT_VISIBILITY, "[ILLUME2][VISIBILITY] %s(%d).. END calculate visibility ...\n",  __func__, __LINE__);
4894
4895    if (visible_region) ecore_x_xregion_free(visible_region);
4896 }
4897
4898 static E_Illume_XWin_Info*
4899 _policy_xwin_info_find (Ecore_X_Window win)
4900 {
4901    return eina_hash_find(_e_illume_xwin_info_hash, e_util_winid_str_get(win));
4902 }
4903
4904
4905 static void
4906 _policy_manage_xwins (E_Manager* man)
4907 {
4908    Ecore_X_Window *windows;
4909    int wnum;
4910    int i;
4911
4912    windows = ecore_x_window_children_get(man->root, &wnum);
4913    if (windows)
4914      {
4915         for (i = 0; i < wnum; i++)
4916            _policy_xwin_info_add(windows[i]);
4917
4918         free(windows);
4919      }
4920
4921    ecore_x_window_size_get (man->root, &_g_root_width, &_g_root_height);
4922 }
4923
4924
4925 static Eina_Bool
4926 _policy_xwin_info_add (Ecore_X_Window win)
4927 {
4928    E_Border* bd;
4929
4930    if (win == _e_overlay_win) return EINA_FALSE;
4931
4932    E_Illume_XWin_Info* xwin_info = _policy_xwin_info_find (win);
4933    if (xwin_info)
4934      {
4935         L (LT_XWIN, "[ILLUME2][XWIN] %s(%d).. win:0x%07x EXIST in the list...\n", __func__, __LINE__, win);
4936         return EINA_FALSE;
4937      }
4938
4939    xwin_info = (E_Illume_XWin_Info*) calloc (1, sizeof (E_Illume_XWin_Info));
4940    if (!xwin_info)
4941      {
4942         L (LT_XWIN, "[ILLUME2][XWIN] (%s:%d).. Critical Error... Fail to create memory... \n", __func__, __LINE__);
4943         return EINA_FALSE;
4944      }
4945
4946    xwin_info->id = win;
4947    xwin_info->visibility = E_ILLUME_VISIBILITY_FULLY_OBSCURED;
4948
4949    if (!ecore_x_window_attributes_get(win, &xwin_info->attr))
4950      {
4951         free (xwin_info);
4952         return EINA_FALSE;
4953      }
4954
4955    xwin_info->viewable = xwin_info->attr.viewable;
4956
4957    bd = e_border_find_by_window (win);
4958    xwin_info->bd_info = _policy_get_border_info(bd);
4959    xwin_info->argb = ecore_x_window_argb_get (win);
4960
4961    if (_e_use_comp) xwin_info->comp_vis = 0;
4962    else xwin_info->comp_vis = 1;
4963
4964    eina_hash_add(_e_illume_xwin_info_hash, e_util_winid_str_get(xwin_info->id), xwin_info);
4965    _e_illume_xwin_info_list = eina_inlist_append(_e_illume_xwin_info_list, EINA_INLIST_GET(xwin_info));
4966
4967    return EINA_TRUE;
4968 }
4969
4970
4971 static Eina_Bool
4972 _policy_xwin_info_delete (Ecore_X_Window win)
4973 {
4974    E_Illume_XWin_Info* xwin_info = _policy_xwin_info_find (win);
4975    if (xwin_info == NULL)
4976      {
4977         L (LT_XWIN, "[ILLUME2][XWIN] %s(%d).. No win:0x%07x in the list...\n", __func__, __LINE__, win);
4978         return EINA_FALSE;
4979      }
4980
4981    _e_illume_xwin_info_list = eina_inlist_remove(_e_illume_xwin_info_list, EINA_INLIST_GET(xwin_info));
4982    eina_hash_del(_e_illume_xwin_info_hash, e_util_winid_str_get(xwin_info->id), xwin_info);
4983
4984    free (xwin_info);
4985
4986    return EINA_TRUE;
4987 }
4988
4989
4990 void _policy_window_create (Ecore_X_Event_Window_Create *event)
4991 {
4992    Ecore_X_Window parent;
4993
4994    parent = ecore_x_window_parent_get(event->win);
4995    if (parent != ecore_x_window_root_get(event->win))
4996      return;
4997
4998    L (LT_XWIN, "[ILLUME2][XWIN] %s(%d).. win:0x%07x...\n", __func__, __LINE__, event->win);
4999
5000    _policy_xwin_info_add (event->win);
5001 }
5002
5003
5004 void _policy_window_destroy (Ecore_X_Event_Window_Destroy *event)
5005 {
5006    L (LT_XWIN, "[ILLUME2][XWIN] %s(%d).. win:0x%07x...\n", __func__, __LINE__, event->win);
5007
5008    _policy_xwin_info_delete (event->win);
5009 }
5010
5011
5012 void _policy_window_reparent (Ecore_X_Event_Window_Reparent *event)
5013 {
5014    L (LT_XWIN, "[ILLUME2][XWIN] %s(%d).. win:0x%07x...\n", __func__, __LINE__, event->win);
5015
5016    if (event->parent == ecore_x_window_root_first_get())
5017       _policy_xwin_info_add (event->win);
5018    else
5019       _policy_xwin_info_delete (event->win);
5020 }
5021
5022
5023 void _policy_window_show (Ecore_X_Event_Window_Show *event)
5024 {
5025    L (LT_XWIN, "[ILLUME2][XWIN] %s(%d).. win:0x%07x...\n", __func__, __LINE__, event->win);
5026
5027    E_Illume_XWin_Info* xwin_info = _policy_xwin_info_find (event->win);
5028    if (xwin_info == NULL)
5029      {
5030         L (LT_XWIN, "[ILLUME2][XWIN] %s(%d).. No win:0x%07x in the list...\n", __func__, __LINE__, event->win);
5031         return ;
5032      }
5033
5034    xwin_info->viewable = EINA_TRUE;
5035
5036    if (xwin_info->comp_vis)
5037      {
5038         L(LT_VISIBILITY, "[ILLUME2][VISIBILITY] %s(%d).. visibility is changed... win:0x%07x\n",  __func__, __LINE__, event->win);
5039         _g_visibility_changed = EINA_TRUE;
5040      }
5041 }
5042
5043
5044 void _policy_window_hide (Ecore_X_Event_Window_Hide *event)
5045 {
5046    L (LT_XWIN, "[ILLUME2][XWIN] %s(%d).. win:0x%07x...\n", __func__, __LINE__, event->win);
5047
5048    E_Illume_XWin_Info* xwin_info = _policy_xwin_info_find (event->win);
5049    if (xwin_info == NULL)
5050      {
5051         L (LT_XWIN, "[ILLUME2][XWIN] %s(%d).. No win:0x%07x in the list...\n", __func__, __LINE__, event->win);
5052         return;
5053      }
5054
5055    xwin_info->viewable = EINA_FALSE;
5056
5057    L(LT_VISIBILITY, "[ILLUME2][VISIBILITY] %s(%d).. visibility is changed... win:0x%07x\n",  __func__, __LINE__, event->win);
5058    _g_visibility_changed = EINA_TRUE;
5059 }
5060
5061
5062 void _policy_window_configure (Ecore_X_Event_Window_Configure *event)
5063 {
5064    Eina_Inlist* l;
5065    E_Illume_XWin_Info* xwin_info;
5066    E_Illume_XWin_Info* old_above_xwin_info;
5067    E_Illume_XWin_Info* new_above_xwin_info;
5068    E_Illume_XWin_Info* temp_xwin_info;
5069    E_Illume_XWin_Info* target_xwin_info;
5070    int check_visibility;
5071    int changed_size;
5072    Ecore_X_Window target_win;
5073
5074    L (LT_XWIN, "[ILLUME2][XWIN] %s(%d).. win:0x%07x...\n", __func__, __LINE__, event->win);
5075
5076    xwin_info = NULL;
5077    old_above_xwin_info = NULL;
5078    new_above_xwin_info = NULL;
5079    check_visibility = 0;
5080    changed_size = 0;
5081    target_win = event->win;
5082
5083    xwin_info = _policy_xwin_info_find (event->win);
5084    if (xwin_info == NULL)
5085      {
5086         L (LT_XWIN, "[ILLUME2][XWIN] %s(%d).. No win:0x%07x in the list...\n", __func__, __LINE__, event->win);
5087         return;
5088      }
5089    target_xwin_info = xwin_info;
5090
5091    if ((xwin_info->attr.x != event->x) ||
5092        (xwin_info->attr.y != event->y))
5093      {
5094         check_visibility = 1;
5095      }
5096
5097    if ((xwin_info->attr.w != event->w) ||
5098        (xwin_info->attr.h != event->h))
5099      {
5100         changed_size = 1;
5101         check_visibility = 1;
5102      }
5103
5104    xwin_info->attr.x = event->x;
5105    xwin_info->attr.y = event->y;
5106    xwin_info->attr.w = event->w;
5107    xwin_info->attr.h = event->h;
5108
5109    if ((l = EINA_INLIST_GET(xwin_info)->prev) != NULL)
5110      {
5111         old_above_xwin_info = EINA_INLIST_CONTAINER_GET (l, E_Illume_XWin_Info);
5112      }
5113
5114    new_above_xwin_info = _policy_xwin_info_find (event->abovewin);
5115
5116    if (old_above_xwin_info != new_above_xwin_info)
5117      {
5118         // find target win
5119         if (old_above_xwin_info)
5120           {
5121              temp_xwin_info = old_above_xwin_info;
5122              for (; temp_xwin_info; temp_xwin_info = (EINA_INLIST_GET(temp_xwin_info)->prev ? _EINA_INLIST_CONTAINER(temp_xwin_info, EINA_INLIST_GET(temp_xwin_info)->prev) : NULL))
5123                {
5124                   if (temp_xwin_info == new_above_xwin_info)
5125                     {
5126                        target_win = old_above_xwin_info->id;
5127                        target_xwin_info = old_above_xwin_info;
5128                        break;
5129                     }
5130                }
5131           }
5132         check_visibility = 1;
5133      }
5134
5135    _e_illume_xwin_info_list = eina_inlist_remove (_e_illume_xwin_info_list, EINA_INLIST_GET(xwin_info));
5136    if (new_above_xwin_info)
5137      _e_illume_xwin_info_list = eina_inlist_append_relative (_e_illume_xwin_info_list, EINA_INLIST_GET(xwin_info), EINA_INLIST_GET(new_above_xwin_info));
5138    else
5139      _e_illume_xwin_info_list = eina_inlist_prepend (_e_illume_xwin_info_list, EINA_INLIST_GET(xwin_info));
5140
5141    if (check_visibility == 1)
5142      {
5143         if (target_xwin_info->viewable)
5144           {
5145              if (target_xwin_info->comp_vis)
5146                {
5147                   if (changed_size)
5148                     {
5149                        L(LT_VISIBILITY, "[ILLUME2][VISIBILITY] %s(%d).. SIZE is changed... target win:0x%07x\n",  __func__, __LINE__, target_xwin_info->id);
5150                        target_xwin_info->is_drawed = EINA_FALSE;
5151                        return;
5152                     }
5153
5154                   L(LT_VISIBILITY, "[ILLUME2][VISIBILITY] %s(%d).. visibility is changed... win:0x%07x\n",  __func__, __LINE__, event->win);
5155                   _g_visibility_changed = EINA_TRUE;
5156                }
5157              else if (target_xwin_info->iconify_by_wm)
5158                {
5159                   L(LT_VISIBILITY, "[ILLUME2][VISIBILITY] %s(%d).. visibility is changed... win:0x%07x\n",  __func__, __LINE__, event->win);
5160                   _g_visibility_changed = EINA_TRUE;
5161                }
5162           }
5163      }
5164 }
5165
5166
5167 void _policy_window_configure_request (Ecore_X_Event_Window_Configure_Request *event)
5168 {
5169    E_Border *bd;
5170    Ecore_X_Event_Window_Configure_Request *e;
5171
5172    e = event;
5173    bd = e_border_find_by_client_window(e->win);
5174    if (!bd) return;
5175
5176    if (!bd->lock_client_stacking)
5177      {
5178         if ((e->value_mask & ECORE_X_WINDOW_CONFIGURE_MASK_STACK_MODE) &&
5179             (e->value_mask & ECORE_X_WINDOW_CONFIGURE_MASK_SIBLING))
5180           {
5181              if (e_config->focus_setting == E_FOCUS_NEW_WINDOW_IF_TOP_STACK)
5182                {
5183                   if (bd->visible && (bd->client.icccm.accepts_focus || bd->client.icccm.take_focus))
5184                      _policy_border_focus_top_stack_set (bd);
5185                }
5186           }
5187         else if (e->value_mask & ECORE_X_WINDOW_CONFIGURE_MASK_STACK_MODE)
5188           {
5189              if (_e_illume_cfg->use_force_iconify)
5190                {
5191                   if (e->detail == ECORE_X_WINDOW_STACK_BELOW && !e->abovewin)
5192                     {
5193                        L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d).. Request Lower window... win:0x%07x\n", __func__, __LINE__, e->win);
5194                        E_Illume_XWin_Info *xwin_info = _policy_xwin_info_find(bd->win);
5195                        if (xwin_info)
5196                          {
5197                             L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d).. ICONIFY win:0x%07x And UN-ICONIFY Top win...\n", __func__, __LINE__, bd->client.win);
5198                             _policy_border_uniconify_top_border(bd);
5199                          }
5200                     }
5201                }
5202
5203              if (e_config->focus_setting == E_FOCUS_NEW_WINDOW_IF_TOP_STACK)
5204                {
5205                   if (bd->visible && (bd->client.icccm.accepts_focus || bd->client.icccm.take_focus))
5206                      _policy_border_focus_top_stack_set(bd);
5207                }
5208           }
5209      }
5210 }
5211
5212 void _policy_window_sync_draw_done(Ecore_X_Event_Client_Message* event)
5213 {
5214    E_Border* bd;
5215    E_Illume_XWin_Info *xwin_info;
5216    Ecore_X_Window win;
5217
5218    win = event->data.l[0];
5219    bd = e_border_find_by_client_window(win);
5220    if (!bd) return;
5221
5222    xwin_info = _policy_xwin_info_find(bd->win);
5223    if (!xwin_info) return;
5224
5225    if (!xwin_info->is_drawed)
5226      {
5227         if (xwin_info->comp_vis)
5228           {
5229              xwin_info->is_drawed = EINA_TRUE;
5230              L(LT_VISIBILITY, "[ILLUME2][VISIBILITY] %s(%d).. visibility is changed... win:0x%07x\n",  __func__, __LINE__, event->win);
5231              _g_visibility_changed = EINA_TRUE;
5232           }
5233         else if (xwin_info->iconify_by_wm)
5234           {
5235              xwin_info->is_drawed = EINA_TRUE;
5236              L(LT_VISIBILITY, "[ILLUME2][VISIBILITY] %s(%d).. visibility is changed... win:0x%07x\n",  __func__, __LINE__, event->win);
5237              _g_visibility_changed = EINA_TRUE;
5238           }
5239      }
5240 }
5241
5242 /* Setting window mode requires window stack change and window geometry
5243  * change. But now, the WM can't control these sequential operations
5244  * using x property set API which whould be able to overwrite previous
5245  * value before getting x property by the WM.
5246  * So we changed ecore_x_e_illume_window_state_set function to use x send
5247  * message and x sync counter. When the WM receives this message,
5248  * the WM sets window mode and then increases x sync counter.
5249  *
5250  * TODO: We need to make a new protocol to set the window mode!!
5251  */
5252 void _policy_illume_win_state_change_request (Ecore_X_Event_Client_Message *event)
5253 {
5254    E_Border *bd = NULL;
5255    Ecore_X_Atom atom = 0, set = 0;
5256    unsigned int state = 0;
5257    Ecore_X_Sync_Counter counter = 0;
5258    long val = 0;
5259
5260    if (!event) return;
5261
5262    bd      = e_border_find_by_client_window(event->win);
5263    atom    = event->data.l[0];
5264    counter = event->data.l[1];
5265    val     = event->data.l[2];
5266
5267    if (atom == ECORE_X_ATOM_E_ILLUME_WINDOW_STATE_NORMAL)
5268      {
5269         state = ECORE_X_ILLUME_WINDOW_STATE_NORMAL;
5270         set = atom;
5271      }
5272    else if (atom == ECORE_X_ATOM_E_ILLUME_WINDOW_STATE_FLOATING)
5273      {
5274         state = ECORE_X_ILLUME_WINDOW_STATE_FLOATING;
5275         set = atom;
5276      }
5277
5278    ELBF(ELBT_ILLUME, 0, event->win,
5279         "GET WIN_STATE_CHANGE_REQ bd:0x%08x(%d->%d) counter:0x%08x val:%d",
5280         bd ? bd->client.win : (unsigned int)NULL,
5281         bd ? bd->client.illume.win_state.state : 0,
5282         state,
5283         counter, val);
5284
5285    if (bd)
5286      _policy_border_illume_window_state_change(bd, state);
5287
5288    if (set != 0)
5289      {
5290         ecore_x_window_prop_atom_set(event->win, ECORE_X_ATOM_E_ILLUME_WINDOW_STATE,
5291                                      &set, 1);
5292         ELB(ELBT_ILLUME, "SET WIN_STATE", event->win);
5293      }
5294
5295    if (counter) ecore_x_sync_counter_inc(counter, 1);
5296 }
5297
5298 void _policy_quickpanel_state_change (Ecore_X_Event_Client_Message* event)
5299 {
5300    E_Zone* zone;
5301    E_Illume_Quickpanel *qp;
5302
5303    if ((zone = e_util_zone_window_find(event->win)))
5304      {
5305         if ((qp = e_illume_quickpanel_by_zone_get(zone)))
5306           {
5307              if (event->data.l[0] == (int)ECORE_X_ATOM_E_ILLUME_QUICKPANEL_ON)
5308                {
5309                   _policy_layout_quickpanel_rotate (qp, g_root_angle);
5310                }
5311           }
5312      }
5313 }
5314
5315 static Eina_Bool
5316 _policy_root_angle_set(E_Border *bd)
5317 {
5318    int angle;
5319    Ecore_X_Window root;
5320
5321    if (bd)
5322      {
5323         angle = _policy_window_rotation_angle_get(bd->client.win);
5324         if (angle == -1) return EINA_FALSE;
5325         if (!(((bd->w == bd->zone->w) && (bd->h == bd->zone->h)) ||
5326               ((bd->w == bd->zone->h) && (bd->h == bd->zone->w))))
5327            return EINA_FALSE;
5328
5329         g_rotated_win = bd->client.win;
5330         root = bd->zone->container->manager->root;
5331      }
5332    else
5333      {
5334         angle = g_root_angle;
5335         g_rotated_win = 0;
5336         root = 0;
5337      }
5338
5339    if (_e_illume_cfg->use_indicator_widget)
5340      {
5341         L(LT_INDICATOR, "[ILLUME2][INDICATOR] %s(%d)... indicator_control_win = 0x%07x...\n", __func__, __LINE__, g_rotated_win);
5342         g_indi_control_win = g_rotated_win;
5343      }
5344
5345    L (LT_ANGLE, "[ILLUME2][ANGLE] %s(%d).. new_win:0x%07x,  old angle:%d -> new_angle:%d\n", __func__, __LINE__, g_rotated_win, g_root_angle, angle);
5346    L (LT_ANGLE, "[ILLUME2][ANGLE] %s(%d).. SET ROOT ANGLE... angle:%d\n\n", __func__, __LINE__, angle);
5347    // set root window property
5348    ecore_x_window_prop_property_set(root, ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE, ECORE_X_ATOM_CARDINAL, 32, &angle, 1);
5349
5350    return EINA_TRUE;
5351 }
5352
5353 static Eina_Bool
5354 e_illume_border_is_camera(E_Border *bd)
5355 {
5356    const char *name = NULL;
5357    const char *clas = NULL;
5358
5359    if (!bd) return EINA_FALSE;
5360
5361    name = bd->client.icccm.name;
5362    clas = bd->client.icccm.class;
5363
5364    if (clas == NULL) return EINA_FALSE;
5365    if (strncmp(clas,"camera",strlen("camera"))!= 0) return EINA_FALSE;
5366    if (name == NULL) return EINA_FALSE;
5367    if (strncmp(name,"camera",strlen("camera"))!= 0) return EINA_FALSE;
5368
5369    return EINA_TRUE;
5370 }
5371
5372 static void
5373 _policy_change_root_angle_by_border_angle (E_Border* bd)
5374 {
5375    L (LT_ANGLE, "[ILLUME2][ANGLE] %s(%d)... win:0x%07x\n", __func__, __LINE__, bd ? (unsigned int)bd->client.win:(unsigned int)NULL);
5376    if (!bd) return;
5377
5378    // ignore the angle of special borders - like indicator, keyboard, quickpanel, etc.
5379    if (e_illume_border_is_indicator(bd)) return;
5380    if (e_illume_border_is_keyboard(bd)) return;
5381    if (e_illume_border_is_quickpanel(bd)) return;
5382    if (e_illume_border_is_quickpanel_popup(bd)) return;
5383
5384    if (e_illume_border_is_camera(bd))
5385      {
5386         if (dep_rot.refer.active_win == bd->client.win)
5387           {
5388              // make rotation request for the dependent windows such as quickpanel
5389              int ang = _policy_window_rotation_angle_get(bd->client.win);
5390              if (ang == -1) ang = 0;
5391
5392              if (dep_rot.ang != ang)
5393                _policy_border_dependent_rotation(bd, ang);
5394           }
5395      }
5396
5397    L (LT_ANGLE, "[ILLUME2][ANGLE] %s(%d)... CALL _policy_root_angle_set.. win:0x%07x\n", __func__, __LINE__, bd->client.win);
5398    _policy_root_angle_set(bd);
5399 }
5400
5401 static void
5402 _policy_indicator_angle_change (E_Border* indi_bd, int angle)
5403 {
5404    L (LT_ANGLE, "[ILLUME2][ANGLE] %s(%d)... indicator:0x%07x\n", __func__, __LINE__, indi_bd ? (unsigned int)indi_bd->client.win:(unsigned int)NULL);
5405    if (!indi_bd) return;
5406
5407    int old_angle = _policy_window_rotation_angle_get (indi_bd->client.win);
5408    if(old_angle == -1) return;
5409
5410    L (LT_ANGLE, "[ILLUME2][ANGLE] %s(%d)... old_angle:%d, new_angle:%d\n", __func__, __LINE__, old_angle, angle);
5411    if (old_angle != angle)
5412      {
5413         int angles[2];
5414         angles[0] = angle;
5415         angles[1] = old_angle;
5416         ecore_x_window_prop_property_set(indi_bd->client.win,
5417                                          ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE,
5418                                          ECORE_X_ATOM_CARDINAL,
5419                                          32,
5420                                          &angles,
5421                                          2);
5422
5423         ecore_x_client_message32_send (indi_bd->client.win, ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE,
5424                                        ECORE_X_EVENT_MASK_WINDOW_CONFIGURE,
5425                                        angle, 0, 0, 0, 0);
5426
5427         E_Illume_Quickpanel *qp;
5428         qp = e_illume_quickpanel_by_zone_get (indi_bd->zone);
5429         if (qp)
5430           {
5431              _policy_layout_quickpanel_rotate (qp, angle);
5432           }
5433      }
5434 }
5435
5436 static void
5437 _policy_border_transient_for_group_make(E_Border  *bd,
5438                                         Eina_List **list)
5439 {
5440    E_Border *child;
5441    Eina_List *l;
5442
5443    if (!bd) return;
5444
5445    E_OBJECT_CHECK(bd);
5446    E_OBJECT_TYPE_CHECK(bd, E_BORDER_TYPE);
5447
5448    if (e_config->transient.raise)
5449      {
5450         EINA_LIST_FOREACH(bd->transients, l, child)
5451           {
5452              if (!child) continue;
5453              if (!child->iconic)
5454                {
5455                   *list = eina_list_prepend(*list, child);
5456                   _policy_border_transient_for_group_make(child, list);
5457                }
5458           }
5459      }
5460 }
5461
5462 static E_Border *
5463 _policy_border_transient_for_border_top_get(E_Border *bd)
5464 {
5465    E_Border *top_border = NULL;
5466    Eina_List *transient_list = NULL;
5467
5468    _policy_border_transient_for_group_make(bd, &transient_list);
5469
5470    if (transient_list)
5471      {
5472         Eina_List *l = NULL;
5473         E_Border *temp_bd;
5474         E_Border *temp_bd2;
5475         E_Border_List *bl;
5476
5477         bl = e_container_border_list_last(bd->zone->container);
5478         while ((temp_bd = e_container_border_list_prev(bl)))
5479           {
5480              if (top_border) break;
5481              if (temp_bd == bd) break;
5482
5483              EINA_LIST_FOREACH(transient_list, l, temp_bd2)
5484                {
5485                   if (temp_bd == temp_bd2)
5486                     {
5487                        top_border = temp_bd2;
5488                        break;
5489                     }
5490                }
5491           }
5492         e_container_border_list_free(bl);
5493      }
5494
5495    L (LT_TRANSIENT_FOR, "[ILLUME2][TRANSIENT] %s(%d).. win:0x%07x, transient_for_top_win:0x%07x\n", __func__, __LINE__, bd->client.win, top_border ? (unsigned int)top_border->client.win:(unsigned int)NULL);
5496
5497    eina_list_free(transient_list);
5498
5499    return top_border;
5500 }
5501
5502 static void
5503 _policy_border_transient_for_layer_set(E_Border *bd,
5504                                        E_Border *parent_bd,
5505                                        int       layer)
5506 {
5507    int raise;
5508    E_Border *top_border;
5509
5510    E_OBJECT_CHECK(bd);
5511    E_OBJECT_TYPE_CHECK(bd, E_BORDER_TYPE);
5512
5513    L (LT_TRANSIENT_FOR, "[ILLUME2][TRANSIENT] %s(%d).. win:0x%07x, transient_for:0x%07x, layer:%d\n", __func__, __LINE__, bd->client.win, parent_bd ? (unsigned int)parent_bd->client.win:(unsigned int)NULL, layer);
5514
5515    ecore_x_window_shadow_tree_flush();
5516
5517    raise = e_config->transient.raise;
5518
5519    bd->saved.layer = bd->layer;
5520    bd->layer = layer;
5521    if (e_config->transient.layer)
5522      {
5523         Eina_List *l;
5524         E_Border *child;
5525
5526         /* We need to set raise to one, else the child wont
5527          * follow to the new layer. It should be like this,
5528          * even if the user usually doesn't want to raise
5529          * the transients.
5530          */
5531         e_config->transient.raise = 1;
5532         EINA_LIST_FOREACH(bd->transients, l, child)
5533           {
5534              if (!child) continue;
5535              child->layer = layer;
5536           }
5537      }
5538
5539    top_border = _policy_border_transient_for_border_top_get(parent_bd);
5540    if (top_border)
5541      {
5542         if (top_border != bd)
5543           {
5544              L (LT_STACK, "[ILLUME2][STACK] %s(%d)... STACK CHANGE with ABOVE... win:0x%07x, above_win:0x%07x\n", __func__, __LINE__, bd->client.win, top_border->client.win);
5545              e_border_stack_above(bd, top_border);
5546           }
5547      }
5548    else
5549      {
5550         L (LT_STACK, "[ILLUME2][STACK] %s(%d)... STACK CHANGE with ABOVE... win:0x%07x, above_win:0x%07x\n", __func__, __LINE__, bd->client.win, parent_bd->client.win);
5551         e_border_stack_above(bd, parent_bd);
5552      }
5553
5554    e_config->transient.raise = raise;
5555 }
5556
5557 /* for desktop mode */
5558 static void
5559 _policy_zone_layout_app_single_monitor(E_Illume_Border_Info* bd_info, E_Illume_Config_Zone *cz)
5560 {
5561    E_Border* bd;
5562    int layer;
5563    Eina_Bool resize = EINA_FALSE;
5564    Eina_Bool move = EINA_FALSE;
5565
5566    bd = bd_info->border;
5567    if (!bd)
5568      {
5569         fprintf(stderr, "[ILLUME2] fatal error! (%s)  There is no border!\n", __func__);
5570         return;
5571      }
5572
5573    if ((!bd->new_client) && (!bd->visible)) return;
5574
5575    layer = _policy_zone_layout_app_layer_check(bd);
5576
5577    if (bd->new_client)
5578      {
5579         int zx = 0, zy = 0, zw = 0, zh = 0;
5580         int new_x, new_y, new_w, new_h;
5581
5582         if (!bd->client.icccm.request_pos)
5583           {
5584              double delta;
5585              Eina_List *skiplist = NULL;
5586
5587              if (bd->zone)
5588                e_zone_useful_geometry_get(bd->zone, &zx, &zy, &zw, &zh);
5589
5590              // calculate width & height
5591              if (zw > zh)
5592                delta = zh / 16.0;
5593              else
5594                delta = zw / 16.0;
5595
5596              delta = delta * 0.66;
5597
5598              new_w = delta * 9.0;
5599              new_h = delta * 16.0;
5600
5601              if (zw > new_w)
5602                new_x = zx + (rand() % (zw - new_w));
5603              else
5604                new_x = zx;
5605              if (zh > new_h)
5606                new_y = zy + (rand() % (zh - new_h));
5607              else
5608                new_y = zy;
5609
5610              skiplist = eina_list_append(skiplist, bd);
5611
5612              e_place_zone_region_smart(bd->zone, skiplist,
5613                                        bd->x, bd->y, new_w, new_h,
5614                                        &new_x, &new_y);
5615
5616              eina_list_free(skiplist);
5617           }
5618         else
5619           {
5620              if (bd->zone)
5621                e_zone_useful_geometry_get(bd->zone, &zx, &zy, &zw, &zh);
5622
5623              if (zx > bd->x) new_x = zx;
5624              else new_x = bd->x;
5625
5626              if (zy > bd->y) new_y = zy;
5627              else new_y = bd->y;
5628
5629              if (zw < bd->w) new_w = zw;
5630              else new_w = bd->w;
5631
5632              if (zh < bd->h) new_h = zh;
5633              else new_h = bd->h;
5634           }
5635
5636         if ((bd->x != new_x) || (bd->y != new_y))
5637           move = EINA_TRUE;
5638
5639         if ((bd->w != new_w) || (bd->h != new_h))
5640           resize = EINA_TRUE;
5641
5642         if (move && resize)
5643           e_border_move_resize(bd, new_x, new_y, new_w, new_h);
5644         else if (move)
5645           _policy_border_move(bd, new_x, new_y);
5646         else if (resize)
5647           _policy_border_resize(bd, new_w, new_h);
5648      }
5649    else
5650      {
5651         /* check if user defined position */
5652         if (bd->client.icccm.request_pos)
5653           {
5654              if (bd->client.illume.win_state.state)
5655                {
5656                   if (bd_info->resize_req.need_change)
5657                     {
5658                        if ((bd->x != bd_info->resize_req.mouse.x) ||
5659                            (bd->y != bd_info->resize_req.mouse.y))
5660                          move = EINA_TRUE;
5661
5662                        if ((bd->w != bd_info->resize_req.mouse.w) ||
5663                            (bd->h != bd_info->resize_req.mouse.h))
5664                          resize = EINA_TRUE;
5665
5666                        if (move && resize)
5667                          {
5668                             e_border_move_resize(bd,
5669                                                  bd_info->resize_req.mouse.x,
5670                                                  bd_info->resize_req.mouse.y,
5671                                                  bd_info->resize_req.mouse.w,
5672                                                  bd_info->resize_req.mouse.h);
5673                          }
5674                        else if (move)
5675                          {
5676                             _policy_border_move(bd,
5677                                                 bd_info->resize_req.mouse.x,
5678                                                 bd_info->resize_req.mouse.y);
5679                          }
5680                        else if (resize)
5681                          {
5682                             _policy_border_resize(bd,
5683                                                   bd_info->resize_req.mouse.w,
5684                                                   bd_info->resize_req.mouse.h);
5685                          }
5686
5687                        bd_info->resize_req.need_change = 0;
5688                        L(LT_AIA, "[ILLUME2][AIA] %s(%d)... bd move resize... (%d, %d, %d, %d)\n", __func__, __LINE__, bd->x, bd->y, bd->w, bd->h);
5689                     }
5690
5691                   if (bd_info->resize_req.mouse.down &&
5692                       bd_info->resize_req.mouse.locked)
5693                     {
5694                        if ((bd->x != bd_info->resize_req.mouse.x) ||
5695                            (bd->y != bd_info->resize_req.mouse.y))
5696                          _policy_border_move(bd,
5697                                              bd_info->resize_req.mouse.x,
5698                                              bd_info->resize_req.mouse.y);
5699                        L(LT_AIA, "[ILLUME2][AIA] %s(%d)... bd move resize... (%d, %d, %d, %d)\n", __func__, __LINE__, bd->x, bd->y, bd->w, bd->h);
5700                     }
5701                }
5702              _policy_zone_layout_app_layer_set(bd, layer);
5703              return;
5704           }
5705
5706         /* resize & move if needed */
5707         if (bd->client.illume.win_state.state)
5708           {
5709              if (bd_info->resize_req.need_change)
5710                {
5711                   if ((bd->x != bd_info->resize_req.mouse.x) ||
5712                       (bd->y != bd_info->resize_req.mouse.y))
5713                     move = EINA_TRUE;
5714
5715                   if ((bd->w != bd_info->resize_req.mouse.w) ||
5716                       (bd->h != bd_info->resize_req.mouse.h))
5717                     resize = EINA_TRUE;
5718
5719                   if (move && resize)
5720                     {
5721                        e_border_move_resize(bd,
5722                                             bd_info->resize_req.mouse.x,
5723                                             bd_info->resize_req.mouse.y,
5724                                             bd_info->resize_req.mouse.w,
5725                                             bd_info->resize_req.mouse.h);
5726                     }
5727                   else if (move)
5728                     {
5729                        _policy_border_move(bd,
5730                                            bd_info->resize_req.mouse.x,
5731                                            bd_info->resize_req.mouse.y);
5732                     }
5733                   else if (resize)
5734                     {
5735                        _policy_border_resize(bd,
5736                                              bd_info->resize_req.mouse.w,
5737                                              bd_info->resize_req.mouse.h);
5738                     }
5739
5740                   L(LT_AIA, "[ILLUME2][AIA] %s(%d)... bd move resize... (%d, %d, %d, %d)\n", __func__, __LINE__, bd->x, bd->y, bd->w, bd->h);
5741                   bd_info->resize_req.need_change = 0;
5742                }
5743
5744              if (bd_info->resize_req.mouse.down &&
5745                  bd_info->resize_req.mouse.locked)
5746                {
5747                   if ((bd->x != bd_info->resize_req.mouse.x) ||
5748                       (bd->y != bd_info->resize_req.mouse.y))
5749                     _policy_border_move(bd,
5750                                         bd_info->resize_req.mouse.x,
5751                                         bd_info->resize_req.mouse.y);
5752                   L(LT_AIA, "[ILLUME2][AIA] %s(%d)... bd move resize... (%d, %d, %d, %d)\n", __func__, __LINE__, bd->x, bd->y, bd->w, bd->h);
5753                }
5754           }
5755      }
5756
5757    /* set layer if needed */
5758    _policy_zone_layout_app_layer_set(bd, layer);
5759 }
5760
5761 void _policy_window_move_resize_request(Ecore_X_Event_Window_Move_Resize_Request *event)
5762 {
5763    E_Border *bd;
5764    E_Illume_Border_Info *bd_info;
5765    Ecore_X_Event_Window_Move_Resize_Request *e;
5766
5767    e = event;
5768    bd = e_border_find_by_client_window(e->win);
5769
5770    L(LT_AIA, "[ILLUME2][AIA]  %s(%d)... win:0x%07x, x:%d, y:%d, direction:%d, button:%d, source:%d\n", __func__, __LINE__, e->win, e->x, e->y, e->direction, e->button, e->source);
5771    if (!bd) return;
5772    if (e->direction == ECORE_X_NETWM_DIRECTION_MOVE ||
5773        e->direction == ECORE_X_NETWM_DIRECTION_CANCEL)
5774      return;
5775
5776    if (bd->client.illume.win_state.state != ECORE_X_ILLUME_WINDOW_STATE_FLOATING)
5777      return;
5778
5779    bd_info = _policy_get_border_info(bd);
5780    if (!bd_info) return;
5781
5782    e_border_resize_cancel();
5783
5784    if (bd_info->resize_req.mouse.down)
5785      return;
5786
5787    L(LT_AIA, "[ILLUME2][AIA] %s(%d)... \n", __func__, __LINE__);
5788
5789    bd_info->resize_req.mouse.down = 1;
5790    bd_info->resize_req.mouse.dx = bd->x - e->x;
5791    bd_info->resize_req.mouse.dy = bd->y - e->y;
5792    bd_info->resize_req.mouse.x = bd->x;
5793    bd_info->resize_req.mouse.y = bd->y;
5794
5795    bd->lock_user_location = 1;
5796
5797    _policy_border_illume_handlers_add(bd_info);
5798    ecore_x_window_raise(bd->event_win);
5799    if (bd->client.icccm.accepts_focus || bd->client.icccm.take_focus)
5800      e_grabinput_get(bd->event_win, 0, bd->event_win);
5801    else
5802      e_grabinput_get(bd->event_win, 0, 0);
5803
5804    bd_info->resize_req.direction = e->direction;
5805    _policy_resize_start(bd_info);
5806 }
5807
5808 void _policy_window_state_request(Ecore_X_Event_Window_State_Request *event)
5809 {
5810    E_Border *bd;
5811    Ecore_X_Event_Window_State_Request *e;
5812    int i;
5813    E_Maximize maximize = 0;
5814
5815    e = event;
5816    bd = e_border_find_by_client_window(e->win);
5817    if (!bd) return;
5818
5819    for (i = 0; i < 2; i++)
5820      {
5821         switch (e->state[i])
5822           {
5823            case ECORE_X_WINDOW_STATE_MAXIMIZED_VERT:
5824              if (bd->lock_client_maximize) break;
5825              maximize |= E_MAXIMIZE_VERTICAL;
5826              break;
5827
5828            case ECORE_X_WINDOW_STATE_MAXIMIZED_HORZ:
5829              if (bd->lock_client_maximize) break;
5830              maximize |= E_MAXIMIZE_HORIZONTAL;
5831              break;
5832
5833            default:
5834              break;
5835           }
5836      }
5837
5838    if (maximize &= E_MAXIMIZE_BOTH)
5839      {
5840         if (e->action == ECORE_X_WINDOW_STATE_ACTION_ADD)
5841           {
5842              if (bd->pointer && bd->pointer->type)
5843                e_pointer_type_pop(bd->pointer, bd, bd->pointer->type);
5844           }
5845      }
5846 }
5847
5848 static void _policy_border_root_angle_control(E_Zone *zone)
5849 {
5850    Eina_Inlist *xwin_info_list;
5851    E_Illume_XWin_Info *xwin_info;
5852    E_Border *bd;
5853
5854    xwin_info = NULL;
5855    xwin_info_list = _e_illume_xwin_info_list;
5856
5857    if (xwin_info_list)
5858      {
5859         EINA_INLIST_REVERSE_FOREACH (xwin_info_list, xwin_info)
5860           {
5861              if (xwin_info->visibility != E_ILLUME_VISIBILITY_FULLY_OBSCURED)
5862                {
5863                   if (xwin_info->bd_info)
5864                     {
5865                        bd = xwin_info->bd_info->border;
5866
5867                        if (!bd) continue;
5868                        if (!bd->visible) continue;
5869                        if (bd->zone != zone) continue;
5870                        if (e_illume_border_is_indicator(bd)) continue;
5871                        if (e_illume_border_is_keyboard(bd)) continue;
5872                        if (e_illume_border_is_quickpanel(bd)) continue;
5873                        if (e_illume_border_is_quickpanel_popup(bd)) continue;
5874                        if (bd->client.illume.win_state.state == ECORE_X_ILLUME_WINDOW_STATE_FLOATING) continue;
5875
5876                        if (_policy_root_angle_set(bd)) break;
5877                     }
5878                }
5879           }
5880      }
5881 }
5882
5883 static int _policy_border_layer_map(int layer)
5884 {
5885    int pos = 0;
5886
5887    if (layer < 0) layer = 0;
5888    pos = 1 + (layer / 50);
5889    if (pos > POL_NUM_OF_LAYER) pos = POL_NUM_OF_LAYER;
5890    return pos;
5891 }
5892
5893 static void
5894 _policy_msg_handler(void *data, const char *name, const char *info, int val, E_Object *obj, void *msgdata)
5895 {
5896    E_Manager *man = (E_Manager *)obj;
5897    E_Manager_Comp_Source *src = (E_Manager_Comp_Source *)msgdata;
5898
5899    // handle only comp.manager msg
5900    if (strncmp(name, "comp.manager", sizeof("comp.manager"))) return;
5901
5902    if (!strncmp(info, "visibility.src", sizeof("visibility.src")))
5903      {
5904         E_Illume_XWin_Info *xwin_info;
5905         Ecore_X_Window win;
5906         Ecore_X_Window active_win;
5907         Ecore_X_Window client_win;
5908         Eina_Bool visible;
5909
5910         win = e_manager_comp_src_window_get(man, src);
5911
5912         xwin_info = _policy_xwin_info_find(win);
5913         if (!xwin_info) return;
5914
5915         visible = e_manager_comp_src_visible_get(man, src);
5916         if (visible)
5917           {
5918              xwin_info->is_drawed = EINA_TRUE;
5919              xwin_info->comp_vis = 1;
5920              L(LT_VISIBILITY, "[ILLUME2][VISIBILITY] %s(%d).. visibility is changed... win:0x%07x\n",  __func__, __LINE__, win);
5921              _g_visibility_changed = EINA_TRUE;
5922
5923              if (xwin_info->bd_info && xwin_info->bd_info->border)
5924                client_win = xwin_info->bd_info->border->client.win;
5925              else
5926                client_win = win;
5927
5928              active_win = _policy_active_window_get(ecore_x_window_root_get(win));
5929              if (active_win == client_win)
5930                {
5931                   _policy_active_win_change(xwin_info, active_win);
5932                }
5933           }
5934         else
5935           {
5936              xwin_info->comp_vis = 0;
5937           }
5938      }
5939 }
5940
5941 void _policy_module_update(E_Event_Module_Update *event)
5942 {
5943    if ((!strncmp(event->name, "comp-tizen", sizeof("comp-tizen"))) ||
5944        (!strncmp(event->name, "comp", sizeof("comp"))))
5945      {
5946         if (event->enabled)
5947           {
5948              // set variable
5949              _e_use_comp = EINA_TRUE;
5950           }
5951         else
5952           {
5953              // unset variable
5954              _e_use_comp = EINA_FALSE;
5955
5956              // change all variable to 1
5957              Eina_Inlist* xwin_info_list;
5958              E_Illume_XWin_Info *xwin_info;
5959
5960              xwin_info_list = _e_illume_xwin_info_list;
5961              if (xwin_info_list)
5962                {
5963                   EINA_INLIST_REVERSE_FOREACH (xwin_info_list, xwin_info)
5964                     {
5965                        xwin_info->comp_vis = EINA_TRUE;
5966                     }
5967                }
5968           }
5969      }
5970 }
5971
5972 void _policy_border_iconify_cb(E_Border *bd)
5973 {
5974    if (!_e_illume_cfg->use_force_iconify) return;
5975
5976    if (!bd) return;
5977    if (e_object_is_del(E_OBJECT(bd))) return;
5978
5979    E_Illume_XWin_Info* xwin_info = _policy_xwin_info_find(bd->win);
5980    if (xwin_info == NULL) return;
5981
5982    _policy_border_uniconify_below_borders_by_illume(xwin_info);
5983
5984    if (xwin_info->visibility != E_ILLUME_VISIBILITY_FULLY_OBSCURED)
5985      {
5986         int old_vis = xwin_info->visibility;
5987         xwin_info->visibility = E_ILLUME_VISIBILITY_FULLY_OBSCURED;
5988         L (LT_VISIBILITY, "[ILLUME2][VISIBILITY] SEND VISIBILITY NOTIFY (Line:%d)... win:0x%07x (old:%d -> new:%d)\n", __LINE__, xwin_info->bd_info->border->client.win, old_vis, xwin_info->visibility);
5989 #ifdef USE_DLOG
5990         SECURE_SLOGD("[WM] SEND VISIBILITY. win:0x%07x (old:%d -> new:%d)", xwin_info->bd_info->border->client.win, old_vis, xwin_info->visibility);
5991 #endif
5992         _policy_send_visibility_notify (xwin_info->bd_info->border->client.win, xwin_info->visibility);
5993      }
5994
5995    L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d)... ICONFIY win:0x%07x (iconify_by_wm:%d)\n", __func__, __LINE__, bd->client.win, xwin_info->iconify_by_wm);
5996    L(LT_VISIBILITY, "[ILLUME2][VISIBILITY] %s(%d).. visibility is changed... win:0x%07x\n",  __func__, __LINE__, bd->client.win);
5997    _g_visibility_changed = EINA_TRUE;
5998
5999    xwin_info->attr.visible = 0;
6000
6001    _policy_border_focus_top_stack_set(bd);
6002 }
6003
6004 void _policy_border_uniconify_cb(E_Border *bd)
6005 {
6006    if (!_e_illume_cfg->use_force_iconify) return;
6007
6008    if (!bd) return;
6009    if (e_object_is_del(E_OBJECT(bd))) return;
6010
6011    E_Illume_XWin_Info* xwin_info = _policy_xwin_info_find(bd->win);
6012    if (xwin_info == NULL) return;
6013
6014    L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d)... UNICONIFY win:0x%07x (iconify_by_wm:%d)\n", __func__, __LINE__, bd->client.win, xwin_info->iconify_by_wm);
6015
6016    xwin_info->iconify_by_wm = 0;
6017    xwin_info->attr.visible = 1;
6018
6019    L(LT_VISIBILITY, "[ILLUME2][VISIBILITY] %s(%d).. visibility is changed... win:0x%07x\n",  __func__, __LINE__, bd->client.win);
6020    _g_visibility_changed = EINA_TRUE;
6021
6022    _policy_border_focus_top_stack_set(bd);
6023 }
6024
6025 static void
6026 _policy_border_event_border_iconify_free(void *data __UNUSED__,
6027                                          void      *ev)
6028 {
6029    E_Event_Border_Iconify *e;
6030
6031    e = ev;
6032    //   e_object_breadcrumb_del(E_OBJECT(e->border), "border_iconify_event");
6033    e_object_unref(E_OBJECT(e->border));
6034    E_FREE(e);
6035 }
6036
6037
6038 static void
6039 _policy_border_force_iconify(E_Border *bd)
6040 {
6041    E_Event_Border_Iconify *ev;
6042    unsigned int iconic;
6043    E_Illume_XWin_Info* xwin_info;
6044
6045    E_OBJECT_CHECK(bd);
6046    E_OBJECT_TYPE_CHECK(bd, E_BORDER_TYPE);
6047    if (bd->shading) return;
6048    ecore_x_window_shadow_tree_flush();
6049    if (!bd->iconic)
6050      {
6051         bd->iconic = 1;
6052         e_border_hide(bd, 0);
6053         if (bd->fullscreen) bd->desk->fullscreen_borders--;
6054         edje_object_signal_emit(bd->bg_object, "e,action,iconify", "e");
6055      }
6056    iconic = 1;
6057    e_hints_window_iconic_set(bd);
6058    ecore_x_window_prop_card32_set(bd->client.win, E_ATOM_MAPPED, &iconic, 1);
6059
6060    ev = E_NEW(E_Event_Border_Iconify, 1);
6061    ev->border = bd;
6062    e_object_ref(E_OBJECT(bd));
6063    //   e_object_breadcrumb_add(E_OBJECT(bd), "border_iconify_event");
6064    ecore_event_add(E_EVENT_BORDER_ICONIFY, ev, _policy_border_event_border_iconify_free, NULL);
6065
6066    xwin_info = _policy_xwin_info_find(bd->win);
6067    if (xwin_info)
6068      {
6069         xwin_info->iconify_by_wm = 1;
6070      }
6071
6072    if (e_config->transient.iconify)
6073      {
6074         Eina_List *l;
6075         E_Border *child;
6076         E_Illume_XWin_Info* child_xwin_info;
6077
6078         EINA_LIST_FOREACH(bd->transients, l, child)
6079           {
6080              if (!e_object_is_del(E_OBJECT(child)))
6081                {
6082                   if (!child->iconic)
6083                     {
6084                        L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d)... Iconify by illume.. child:0x%07x\n", __func__, __LINE__, child->client.win);
6085                        child_xwin_info = _policy_xwin_info_find(child->win);
6086                        if (child_xwin_info)
6087                          {
6088                             _policy_border_iconify_by_illume(child_xwin_info);
6089                          }
6090                     }
6091                }
6092           }
6093      }
6094    e_remember_update(bd);
6095 }
6096
6097 static void
6098 _policy_border_iconify_by_illume(E_Illume_XWin_Info *xwin_info)
6099 {
6100    E_Border *bd;
6101
6102    if (!xwin_info) return;
6103    if (!xwin_info->bd_info) return;
6104    if (!xwin_info->bd_info->border) return;
6105
6106    bd = xwin_info->bd_info->border;
6107    if (!E_ILLUME_BORDER_IS_IN_MOBILE(bd)) return;
6108    if (e_object_is_del(E_OBJECT(bd))) return;
6109
6110    if (bd->parent && (!bd->parent->iconic)) return;
6111
6112    if (e_illume_border_is_indicator(bd)) return;
6113    if (e_illume_border_is_keyboard(bd)) return;
6114    if (e_illume_border_is_keyboard_sub(bd)) return;
6115    if (e_illume_border_is_quickpanel(bd)) return;
6116    if (e_illume_border_is_quickpanel_popup(bd)) return;
6117    if (e_illume_border_is_clipboard(bd)) return;
6118    if (e_illume_border_is_app_tray(bd)) return;
6119    if (e_illume_border_is_miniapp_tray(bd)) return;
6120 //   if (bd->client.illume.win_state.state == ECORE_X_ILLUME_WINDOW_STATE_FLOATING) return;
6121
6122    xwin_info->iconify_by_wm = 1;
6123
6124    if (!bd->iconic)
6125      {
6126         L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d)... FORCE_ICONIFY win:0x%07x\n", __func__, __LINE__, bd->client.win);
6127         _policy_border_force_iconify(bd);
6128      }
6129 }
6130
6131 static void
6132 _policy_border_event_border_uniconify_free(void *data, void *ev)
6133 {
6134    E_Event_Border_Uniconify *e;
6135
6136    e = ev;
6137    //   e_object_breadcrumb_del(E_OBJECT(e->border), "border_uniconify_event");
6138    e_object_unref(E_OBJECT(e->border));
6139    E_FREE(e);
6140 }
6141
6142 static void _policy_border_force_uniconify(E_Border *bd)
6143 {
6144    E_Desk *desk;
6145    E_Event_Border_Uniconify *ev;
6146    unsigned int iconic;
6147    E_Illume_XWin_Info* xwin_info;
6148
6149    E_OBJECT_CHECK(bd);
6150    E_OBJECT_TYPE_CHECK(bd, E_BORDER_TYPE);
6151
6152    xwin_info = _policy_xwin_info_find(bd->win);
6153    if (!(xwin_info && xwin_info->iconify_by_wm)) return;
6154
6155    if (bd->shading) return;
6156    ecore_x_window_shadow_tree_flush();
6157    e_border_show(bd);
6158    if (bd->iconic)
6159      {
6160         bd->iconic = 0;
6161         if (bd->fullscreen) bd->desk->fullscreen_borders++;
6162         if (e_manager_comp_evas_get(bd->zone->container->manager))
6163           {
6164              if (bd->await_hide_event > 0)
6165                bd->await_hide_event--;
6166           }
6167         desk = e_desk_current_get(bd->desk->zone);
6168         e_border_desk_set(bd, desk);
6169         edje_object_signal_emit(bd->bg_object, "e,action,uniconify", "e");
6170      }
6171    iconic = 0;
6172    ecore_x_window_prop_card32_set(bd->client.win, E_ATOM_MAPPED, &iconic, 1);
6173
6174    ev = E_NEW(E_Event_Border_Uniconify, 1);
6175    ev->border = bd;
6176    e_object_ref(E_OBJECT(bd));
6177    //   e_object_breadcrumb_add(E_OBJECT(bd), "border_uniconify_event");
6178    ecore_event_add(E_EVENT_BORDER_UNICONIFY, ev, _policy_border_event_border_uniconify_free, NULL);
6179
6180    if (e_config->transient.iconify)
6181      {
6182         Eina_List *l;
6183         E_Border *child;
6184         E_Illume_XWin_Info* child_xwin_info;
6185
6186         EINA_LIST_FOREACH(bd->transients, l, child)
6187           {
6188              if (!e_object_is_del(E_OBJECT(child)))
6189                {
6190                   if (child->iconic)
6191                     {
6192                        child_xwin_info = _policy_xwin_info_find(child->win);
6193                        if (child_xwin_info) child_xwin_info->iconify_by_wm = 1;
6194
6195                        L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d).. FORCE UNICONIFY... win:0x%07x\n", __func__, __LINE__, child->client.win);
6196                        _policy_border_force_uniconify(child);
6197                     }
6198                }
6199           }
6200      }
6201    e_remember_update(bd);
6202 }
6203
6204 static void
6205 _policy_border_uniconify_below_borders_by_illume(E_Illume_XWin_Info *xwin_info)
6206 {
6207    E_Border *bd;
6208
6209    if (!xwin_info) return;
6210    if (!xwin_info->bd_info) return;
6211
6212    bd = xwin_info->bd_info->border;
6213
6214    // 1. check if iconify is caused by visibility change or not
6215    if (xwin_info->iconify_by_wm) return;
6216
6217    // 2. check if current bd's visibility is fully-obscured or not
6218    if (xwin_info->visibility == E_ILLUME_VISIBILITY_FULLY_OBSCURED) return;
6219
6220    // 3-1. find bd's below window and un-iconify it
6221    L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d)... UNICONIFY Below Windows of win:0x%07x\n", __func__, __LINE__, bd->client.win);
6222    _policy_border_uniconify_below_borders(bd);
6223
6224    if (!e_object_is_del(E_OBJECT(bd)))
6225      {
6226         e_border_lower(bd);
6227      }
6228 }
6229
6230 static E_Border* _policy_border_find_below(E_Border *bd)
6231 {
6232    Eina_List *l;
6233    int i, pos;
6234    Eina_Bool passed;
6235    E_Illume_XWin_Info* xwin_info;
6236
6237    passed = EINA_FALSE;
6238
6239    /* determine layering position */
6240    pos = _policy_border_layer_map(bd->layer);
6241
6242    /* Find the windows below this one */
6243    for (i = pos; i >= 2; i--)
6244      {
6245         E_Border *b;
6246
6247         EINA_LIST_REVERSE_FOREACH(bd->zone->container->layers[i].clients, l, b)
6248           {
6249              if (!b) continue;
6250
6251              /* skip if it's the same border */
6252              if (b == bd)
6253                {
6254                   passed = EINA_TRUE;
6255                   continue;
6256                }
6257
6258              if ((b->x == b->zone->x) &&
6259                  (b->y == b->zone->y) &&
6260                  (b->w == b->zone->w) &&
6261                  (b->h == b->zone->h) &&
6262                  (b->h == b->zone->h) &&
6263                  (b->client.illume.win_state.state != ECORE_X_ILLUME_WINDOW_STATE_FLOATING) &&
6264                  (b->visible))
6265                {
6266                   xwin_info = _policy_xwin_info_find(b->win);
6267                   if (xwin_info)
6268                     {
6269                        if ((!xwin_info->argb) ||
6270                            (xwin_info->argb && xwin_info->bd_info->opaque))
6271                          {
6272                             L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d)... win:0x%07x, ALREADY FULLY-OBSCURED... by win:0x%07x visible:%d (visibility:%d)\n", __func__, __LINE__, bd->client.win, b->client.win, b->visible, xwin_info->visibility);
6273                             break;
6274                          }
6275                     }
6276                }
6277
6278              if (!passed) continue;
6279
6280              /* skip if it's not on this zone */
6281              if (b->zone != bd->zone) continue;
6282
6283              /* skip special borders */
6284              if (e_illume_border_is_indicator(b)) continue;
6285              if (e_illume_border_is_keyboard(b)) continue;
6286              if (e_illume_border_is_keyboard_sub(b)) continue;
6287              if (e_illume_border_is_quickpanel(b)) continue;
6288              if (e_illume_border_is_quickpanel_popup(b)) continue;
6289              if (e_illume_border_is_clipboard(b)) continue;
6290              if (e_illume_border_is_app_tray(b)) continue;
6291              if (e_illume_border_is_miniapp_tray(b)) continue;
6292
6293              return b;
6294           }
6295      }
6296
6297    return NULL;
6298 }
6299
6300 static void _policy_border_uniconify_below_borders(E_Border *bd)
6301 {
6302    E_Border *below_bd;
6303
6304    below_bd = _policy_border_find_below(bd);
6305    if (!below_bd) return;
6306
6307    E_Illume_XWin_Info* below_xwin_info = _policy_xwin_info_find(below_bd->win);
6308    if (below_xwin_info == NULL) return;
6309
6310    if ((below_bd->w != below_bd->zone->w) ||
6311        (below_bd->h != below_bd->zone->h) ||
6312        (below_xwin_info->argb))
6313      {
6314         if (!(below_xwin_info->bd_info && below_xwin_info->bd_info->opaque))
6315           _policy_border_uniconify_below_borders(below_bd);
6316      }
6317
6318    // 3-2.
6319    if (below_bd->iconic)
6320      {
6321         L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d).. FORCE UNICONIFY... win:0x%07x\n", __func__, __LINE__, below_bd->client.win);
6322         _policy_border_force_uniconify(below_bd);
6323      }
6324 }
6325
6326 static void _policy_border_uniconify_top_border(E_Border *bd)
6327 {
6328    Eina_List *l;
6329    int i;
6330    int zone_w, zone_h;
6331    E_Illume_XWin_Info* xwin_info;
6332
6333    if (!_e_illume_cfg->use_force_iconify) return;
6334
6335    zone_w = bd->zone->w;
6336    zone_h = bd->zone->h;
6337    /* determine layering position */
6338
6339    /* Find the windows below this one */
6340    for (i = POL_NUM_OF_LAYER; i >= 2; i--)
6341      {
6342         E_Border *b;
6343
6344         EINA_LIST_REVERSE_FOREACH(bd->zone->container->layers[i].clients, l, b)
6345           {
6346              if (!b) continue;
6347
6348              if ((b->x >= zone_w) || (b->y >= zone_h)) continue;
6349              if (((b->x + b->w) <= 0) || ((b->y + b->h) <= 0)) continue;
6350
6351              /* skip if it's not on this zone */
6352              if (b->zone != bd->zone) continue;
6353
6354              /* skip special borders */
6355              if (e_illume_border_is_indicator(b)) continue;
6356              if (e_illume_border_is_keyboard(b)) continue;
6357              if (e_illume_border_is_keyboard_sub(b)) continue;
6358              if (e_illume_border_is_quickpanel(b)) continue;
6359              if (e_illume_border_is_quickpanel_popup(b)) continue;
6360              if (e_illume_border_is_clipboard(b)) continue;
6361              if (e_illume_border_is_app_tray(b)) continue;
6362              if (e_illume_border_is_miniapp_tray(b)) continue;
6363
6364              if (b->iconic)
6365                {
6366                   L(LT_ICONIFY, "[ILLUME2][ICONIFY] %s(%d).. FORCE UNICONIFY... win:0x%07x\n", __func__, __LINE__, b->client.win);
6367                   _policy_border_force_uniconify(b);
6368                }
6369
6370              if ((b->x == b->zone->x) &&
6371                  (b->y == b->zone->y) &&
6372                  (b->w == b->zone->w) &&
6373                  (b->h == b->zone->h))
6374                {
6375                   xwin_info = _policy_xwin_info_find(b->win);
6376                   if (xwin_info)
6377                     {
6378                        if (xwin_info->argb && !xwin_info->bd_info->opaque)
6379                          {
6380                             continue;
6381                          }
6382                        else
6383                          break;
6384                     }
6385                   else
6386                     break;
6387                }
6388           }
6389      }
6390    return;
6391 }
6392
6393 /* change the desk of window for popsync.
6394  * if there is no window in data read from ev->l[0],
6395  * window that is latest above stack will be changed.
6396  *   - event->data.l[0] : window ID
6397  *   - event->data.l[1]
6398  *     1(default): mobile
6399  *     2: popsync
6400  */
6401 void
6402 _policy_window_desk_set(Ecore_X_Event_Client_Message *event)
6403 {
6404    Ecore_X_Event_Client_Message *ev = event;
6405    Ecore_X_Window win;
6406    E_Container *con;
6407    E_Zone *zone;
6408    E_Desk *desk = NULL;
6409    E_Border_List *bl;
6410    E_Border *bd;
6411    Eina_Bool one_time = EINA_FALSE;
6412    char *profile = NULL, *new_profile = NULL;
6413    unsigned int desk_num;
6414    int x, y;
6415    int err_tracer = 0;
6416
6417    EINA_SAFETY_ON_NULL_RETURN(ev);
6418
6419    win = ev->data.l[0];
6420    desk_num = ev->data.l[1];
6421    if (win) one_time = EINA_TRUE;
6422
6423    // decide new desk's profile from received data.
6424    switch (desk_num)
6425      {
6426       case 2:
6427          new_profile = _e_illume_cfg->display_name.popsync;
6428          break;
6429       case 1:
6430       default:
6431          new_profile = _e_illume_cfg->display_name.mobile;
6432          break;
6433      }
6434
6435    con = e_container_current_get(e_manager_current_get());
6436    bl = e_container_border_list_last(con);
6437
6438    // if there exists a ID of window read from data ev->data.l[0],
6439    // find and set this window's border window, or set latest above border.
6440    bd = win ? e_border_find_by_client_window(win) :
6441       e_container_border_list_prev(bl);
6442    if (!bd) bd = e_border_find_by_window(win);
6443    if (!bd) goto fin;
6444    err_tracer++;
6445
6446    do {
6447         // skip special window.
6448         if ((e_illume_border_is_indicator(bd)) ||
6449             (e_illume_border_is_keyboard(bd)) ||
6450             (e_illume_border_is_keyboard_sub(bd)) ||
6451             (e_illume_border_is_quickpanel(bd)) ||
6452             (e_illume_border_is_quickpanel_popup(bd)) ||
6453             (e_illume_border_is_clipboard(bd)))
6454           {
6455              if (one_time) goto fin;
6456              continue;
6457           }
6458
6459         if ((bd->client.icccm.accepts_focus || bd->client.icccm.take_focus) &&
6460             (bd->client.netwm.type != ECORE_X_WINDOW_TYPE_DOCK) &&
6461             (bd->client.netwm.type != ECORE_X_WINDOW_TYPE_TOOLBAR) &&
6462             (bd->client.netwm.type != ECORE_X_WINDOW_TYPE_MENU) &&
6463             (bd->client.netwm.type != ECORE_X_WINDOW_TYPE_SPLASH) &&
6464             (bd->client.netwm.type != ECORE_X_WINDOW_TYPE_DESKTOP) &&
6465             (bd->client.netwm.type != ECORE_X_WINDOW_TYPE_NOTIFICATION))
6466           {
6467              err_tracer++;
6468              zone = bd->zone;
6469
6470              // terminated this function if there is only one desk.
6471              if ((zone->desk_x_count < 2) && (zone->desk_y_count < 2))
6472                goto fin;
6473              err_tracer++;
6474
6475              // find the corresponsive desk.
6476              for (x = 0; x < zone->desk_x_count; x++)
6477                {
6478                   for (y = 0; y < zone->desk_y_count; y++)
6479                     {
6480                        int index = x + (y * zone->desk_x_count);
6481                        profile = zone->desks[index]->window_profile;
6482
6483                        if (!strcmp(new_profile, profile))
6484                          desk = zone->desks[index];
6485                     }
6486                }
6487
6488              if (!desk) goto fin;
6489
6490              e_border_desk_set(bd, desk);
6491
6492              // we have to receive the DAMAGE notify from this window.
6493              // for this, the window has to have visible state as a its property.
6494              // if not, can not receive DAMAGE notify.
6495              e_hints_window_visible_set(bd);
6496              e_hints_window_desktop_set(bd);
6497              _policy_border_uniconify_below_borders(bd);
6498              break;
6499           }
6500    } while((!one_time) && (bd = e_container_border_list_prev(bl)));
6501
6502 fin:
6503    e_container_border_list_free(bl);
6504    if (err_tracer)
6505      {
6506         fprintf(stderr,
6507                 "[POPSYNC] ERROR: ");
6508         switch (err_tracer)
6509           {
6510            case 0:
6511               fprintf(stderr, "Couldn't find border.\n");
6512               break;
6513            case 1:
6514               fprintf(stderr, "Couldn't change desk. No border, or special window.\n");
6515               break;
6516            case 2:
6517               fprintf(stderr, "NO desk to change \n");
6518               break;
6519            case 3:
6520               fprintf(stderr, "Couldn't find desk such a profile.\n");
6521               break;
6522            default:
6523               fprintf(stderr, "Non-defined error\n");
6524           }
6525      }
6526    return;
6527 }
6528
6529 /* for supporting rotation */
6530 void
6531 _policy_border_hook_rotation_list_add(E_Border *bd)
6532 {
6533    int rotation = 0;
6534    if (!bd) return;
6535
6536    rotation = bd->client.e.state.rot.curr;
6537    _policy_border_dependent_rotation(bd, rotation);
6538 }
6539
6540 static void
6541 _policy_border_dependent_rotation(E_Border *bd, int rotation)
6542 {
6543    Eina_List *l;
6544    E_Border *dep_bd = NULL;
6545
6546    if (!bd) return;
6547    if (!dep_rot.list) return;
6548    if (dep_rot.refer.active_win != bd->client.win) return;
6549
6550    EINA_LIST_FOREACH(dep_rot.list, l, dep_bd)
6551      {
6552         if (!dep_bd) continue;
6553         if (_policy_dependent_rotation_check(dep_bd, rotation))
6554           {
6555              ELBF(ELBT_ROT, 0, dep_bd->client.win, "ROT_SET ANG [%d -> %d]",
6556                   dep_bd->client.e.state.rot.curr, rotation);
6557              e_border_rotation_set(dep_bd, rotation);
6558           }
6559      }
6560    dep_rot.ang = rotation;
6561 }
6562
6563 static Eina_Bool
6564 _policy_dependent_rotation_check(E_Border *bd, int rotation)
6565 {
6566    Eina_Bool ret = EINA_FALSE;
6567
6568    if (!bd) return ret;
6569    if (!bd->visible) return ret;
6570    if (bd->client.e.state.rot.curr == rotation) return ret;
6571    ret = EINA_TRUE;
6572
6573    return ret;
6574 }
6575
6576 static void
6577 _policy_property_indicator_cmd_win_change(Ecore_X_Event_Window_Property *event)
6578 {
6579    Ecore_X_Window cmd_win;
6580
6581    cmd_win = _policy_indicator_cmd_win_get(event->win);
6582
6583    if (!cmd_win)
6584      {
6585         ELB(ELBT_ROT, "ERR! NO INDI_CMD_WIN", event->win);
6586         return;
6587      }
6588
6589    if (dep_rot.refer.cmd_win != cmd_win)
6590      {
6591         ELBF(ELBT_ROT, 0, cmd_win,
6592              "INDICATOR COMMAND WIN: [0x%08x -> 0x%08x]",
6593              dep_rot.refer.cmd_win, cmd_win);
6594         dep_rot.refer.cmd_win = cmd_win;
6595      }
6596 }
6597
6598 static void
6599 _policy_property_active_indicator_win_change(Ecore_X_Event_Window_Property *event)
6600 {
6601    Ecore_X_Window active_win = 0;
6602    E_Border *bd = NULL;
6603    int rotation = 0;
6604
6605    if (!event) return;
6606
6607    active_win = _policy_active_indicator_win_get(event->win);
6608    if (!active_win)
6609      {
6610         ELB(ELBT_ROT, "ERR! NO ACTIVE_INDI_WIN", event->win);
6611         return;
6612      }
6613
6614    if (dep_rot.refer.active_win != active_win)
6615      {
6616         bd = e_border_find_by_client_window(active_win);
6617         if (!bd)
6618           {
6619              ELB(ELBT_ROT, "ERR! NO BD ACTIVE_INDI_WIN", active_win);
6620              return;
6621           }
6622
6623         /* The normal application window is ok to rotate dependent rotation windows.
6624          * But if the notification window which doesn't have accepts_focus such as volume popup
6625          * is the active window, then the illume doesn't rotate dependent windows.
6626          */
6627         Eina_Bool rot = EINA_FALSE;
6628         if (e_illume_border_is_notification(bd))
6629           {
6630             if ((bd->client.icccm.accepts_focus) || (bd->client.icccm.take_focus))
6631               {
6632                  rot = EINA_TRUE;
6633               }
6634           }
6635         else
6636           {
6637              rot = EINA_TRUE;
6638           }
6639
6640         ELBF(ELBT_ROT, 0, bd->client.win,
6641              "ROT:%d NOTI:%d ACCEPT_FOCUS:%d TAKE_FOCUS:%d",
6642              rot,
6643              e_illume_border_is_notification(bd),
6644              bd->client.icccm.accepts_focus,
6645              bd->client.icccm.take_focus);
6646
6647         if (rot)
6648           {
6649              E_Border *prev_bd = e_border_find_by_client_window(dep_rot.refer.active_win);
6650              ELBF(ELBT_ROT, 0, active_win,
6651                   "INDICATOR ACTIVE WIN: [%s(0x%08x) -> %s(0x%08x)]",
6652                   prev_bd ? (prev_bd->client.icccm.name ? prev_bd->client.icccm.name : "") : "",
6653                   dep_rot.refer.active_win,
6654                   bd->client.icccm.name ? bd->client.icccm.name : "",
6655                   active_win);
6656              dep_rot.refer.active_win = active_win;
6657              rotation = bd->client.e.state.rot.curr;
6658
6659              _policy_border_dependent_rotation(bd, rotation);
6660           }
6661      }
6662 }
6663
6664 static Ecore_X_Window
6665 _policy_indicator_cmd_win_get(Ecore_X_Window win)
6666 {
6667    Ecore_X_Window cmd_win = NULL;
6668    unsigned char* prop_data = NULL;
6669    int ret = 0, count = 0;
6670
6671    if (win != dep_rot.root) return NULL;
6672
6673    ret = ecore_x_window_prop_property_get(win, E_INDICATOR_CMD_WIN,
6674                                           ECORE_X_ATOM_WINDOW, 32,
6675                                           &prop_data, &count);
6676    if (ret)
6677      memcpy (&cmd_win, prop_data, sizeof(ECORE_X_ATOM_WINDOW));
6678
6679    if (prop_data) free(prop_data);
6680
6681    return cmd_win;
6682 }
6683
6684 static Ecore_X_Window
6685 _policy_active_indicator_win_get(Ecore_X_Window win)
6686 {
6687    Ecore_X_Window active_win = NULL;
6688    unsigned char* prop_data = NULL;
6689    int ret = 0, count = 0;
6690
6691    if (win != dep_rot.refer.cmd_win) return NULL;
6692
6693    ret = ecore_x_window_prop_property_get(win, E_ACTIVE_INDICATOR_WIN,
6694                                           ECORE_X_ATOM_WINDOW, 32,
6695                                           &prop_data, &count);
6696    if (ret)
6697      memcpy (&active_win, prop_data, sizeof(ECORE_X_ATOM_WINDOW));
6698
6699    if (prop_data) free(prop_data);
6700
6701    return active_win;
6702 }
6703
6704 static int
6705 _prev_angle_get(Ecore_X_Window win)
6706 {
6707    int ret, count = 0, ang = -1;
6708    unsigned char* data = NULL;
6709
6710    ret = ecore_x_window_prop_property_get
6711       (win, ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE,
6712        ECORE_X_ATOM_CARDINAL, 32, &data, &count);
6713
6714    if ((ret) && (data) && (count))
6715      ang = ((int *)data)[0];
6716    if (data) free(data);
6717    return ang;
6718 }
6719
6720
6721 void
6722 _policy_idle_enterer(void)
6723 {
6724    _policy_calculate_visibility();
6725 }