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