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