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