Merged with devel
[platform/core/uifw/e17-extra-modules.git] / move-tizen / src / e_mod_move_mini_apptray_widget.c
1 #include "e_mod_move_shared_types.h"
2 #include "e_mod_move_debug.h"
3 #include "e_mod_move.h"
4
5 /* local subsystem functions */
6 static Eina_Bool      _e_mod_move_mini_apptray_widget_mini_apptray_move_set(E_Move_Mini_Apptray_Widget *mini_apptray_widget, Eina_Bool state);
7 static Eina_Bool      _e_mod_move_mini_apptray_widget_mini_apptray_move_get(E_Move_Mini_Apptray_Widget *mini_apptray_widget);
8 static Eina_Bool      _e_mod_move_mini_apptray_widget_cb_motion_start_internal_mini_apptray_check(E_Move_Border *mini_apptray_mb);
9 static Eina_Bool      _e_mod_move_mini_apptray_widget_mini_apptray_flick_process(E_Move_Mini_Apptray_Widget *mini_apptray_widget, E_Move_Border *mb2, int angle, Eina_Bool state);
10 static Eina_Bool      _e_mod_move_mini_apptray_widget_cb_motion_start(void *data, void *event_info);
11 static Eina_Bool      _e_mod_move_mini_apptray_widget_cb_motion_move(void *data, void *event_info);
12 static Eina_Bool      _e_mod_move_mini_apptray_widget_cb_motion_end(void *data, void *event_info);
13 static Ecore_X_Window _e_mod_move_mini_apptray_event_win_find(void *event_info);
14 static void           _e_mod_move_mini_apptray_widget_obj_event_setup(E_Move_Mini_Apptray_Widget *mini_apptray_widget, E_Move_Widget_Object *mwo);
15 static Eina_Bool      _e_mod_move_mini_apptray_widget_event_send_policy_check(E_Move_Mini_Apptray_Widget *mini_apptray_widget, Evas_Point pos);
16
17 /* local subsystem functions */
18 static Eina_Bool
19 _e_mod_move_mini_apptray_widget_mini_apptray_move_set(E_Move_Mini_Apptray_Widget *mini_apptray_widget,
20                                                       Eina_Bool                   state)
21 {
22    E_CHECK_RETURN(mini_apptray_widget, EINA_FALSE);
23    mini_apptray_widget->mini_apptray_move = state;
24    return EINA_TRUE;
25 }
26
27 static Eina_Bool
28 _e_mod_move_mini_apptray_widget_mini_apptray_move_get(E_Move_Mini_Apptray_Widget *mini_apptray_widget)
29 {
30    E_CHECK_RETURN(mini_apptray_widget, EINA_FALSE);
31    return mini_apptray_widget->mini_apptray_move;
32 }
33
34 static Eina_Bool
35 _e_mod_move_mini_apptray_widget_cb_motion_start_internal_mini_apptray_check(E_Move_Border *mini_apptray_mb)
36 {
37    E_Move        *m;
38    E_Move_Border *find_mb = NULL;
39    E_Move_Border *qp_mb = NULL;
40    Eina_Bool      found = EINA_FALSE;
41    m = e_mod_move_util_get();
42
43    E_CHECK_RETURN(m, EINA_FALSE);
44    E_CHECK_RETURN(mini_apptray_mb, EINA_FALSE);
45    E_CHECK_RETURN(TYPE_MINI_APPTRAY_CHECK(mini_apptray_mb), EINA_FALSE);
46    E_CHECK_RETURN(mini_apptray_mb->visible, EINA_FALSE);
47    E_CHECK_RETURN(e_mod_move_util_compositor_object_visible_get(mini_apptray_mb),
48                   EINA_FALSE);
49    if (e_mod_move_mini_apptray_objs_animation_state_get(mini_apptray_mb)) return EINA_FALSE;
50
51    qp_mb = e_mod_move_quickpanel_find();
52    if (e_mod_move_quickpanel_objs_animation_state_get(qp_mb)) return EINA_FALSE;
53
54    // Mini app-tray is under rotation state.
55    // I think there is another exception case.
56    // It's posible that WM doesn't send rotation change request yet.
57    // In this case the value of wait_for_done is zero,
58    // it means quickpanel isn't rotating for now, but going to be rotated.
59    if (mini_apptray_mb->bd)
60      if (mini_apptray_mb->bd->client.e.state.rot.wait_for_done) return EINA_FALSE;
61
62    // check if notification window is on-screen.
63    EINA_INLIST_REVERSE_FOREACH(m->borders, find_mb)
64      {
65         if (TYPE_INDICATOR_CHECK(find_mb)) continue;
66         if ((find_mb->visible) &&
67             (mini_apptray_mb->bd) &&
68             (REGION_INTERSECTS_WITH_ZONE(find_mb, mini_apptray_mb->bd->zone)))
69           {
70               found = EINA_TRUE;
71               break;
72           }
73      }
74
75    if (found
76         && (find_mb->bd->client.netwm.type == ECORE_X_WINDOW_TYPE_NOTIFICATION)
77         && REGION_EQUAL_TO_ZONE(find_mb, find_mb->bd->zone))
78      {
79         return EINA_FALSE;
80      }
81    // check if notification window is on-screen.
82
83    e_mod_move_mini_apptray_dim_show(mini_apptray_mb);
84
85    if (REGION_INSIDE_ZONE(mini_apptray_mb, mini_apptray_mb->bd->zone))
86      e_mod_move_mini_apptray_objs_add_with_pos(mini_apptray_mb, -10000, -10000);
87    else
88      e_mod_move_mini_apptray_objs_add(mini_apptray_mb);
89
90    return EINA_TRUE;
91 }
92
93 static Eina_Bool
94 _e_mod_move_mini_apptray_widget_mini_apptray_flick_process(E_Move_Mini_Apptray_Widget *mini_apptray_widget,
95                                                            E_Move_Border              *mb2, // mb2 : mini_apptray
96                                                            int                         angle,
97                                                            Eina_Bool                   state)
98 {
99    E_Move_Border            *mb = NULL;
100    E_Move_Widget_Object     *mwo = NULL;
101    Eina_List                *l;
102    E_Zone                   *zone = NULL;
103    int x = 0;
104    int y = 0;
105
106    E_CHECK_RETURN(mini_apptray_widget, EINA_FALSE);
107    mb = e_mod_move_border_client_find(mini_apptray_widget->win);
108    E_CHECK_RETURN(mb, EINA_FALSE);
109    E_CHECK_RETURN(mb2, EINA_FALSE);
110    E_CHECK_RETURN(TYPE_MINI_APPTRAY_CHECK(mb2), EINA_FALSE);
111    E_CHECK_RETURN(state, EINA_FALSE);
112
113    zone = mb->bd->zone;
114
115    EINA_LIST_FOREACH(mini_apptray_widget->objs, l, mwo) // widget click unset
116      {
117         if (!mwo) continue;
118         e_mod_move_event_click_set(mwo->event, EINA_FALSE);
119      }
120
121    _e_mod_move_mini_apptray_widget_mini_apptray_move_set(mini_apptray_widget, EINA_FALSE);
122
123    // flick data free
124    if (mb->flick_data) e_mod_move_flick_data_free(mb);
125
126    switch (angle)
127      {
128       case  90:
129          x = zone->w - mb2->w;
130          y = 0;
131          break;
132       case 180:
133          x = 0;
134          y = 0;
135          break;
136       case 270:
137          x = 0;
138          y = 0;
139          break;
140       case   0:
141       default :
142          x = 0;
143          y = zone->h - mb2->h;
144          break;
145      }
146
147    e_mod_move_mini_apptray_e_border_move(mb2, x, y);
148    e_mod_move_mini_apptray_objs_animation_move(mb2, x, y);
149
150    return EINA_TRUE;
151 }
152
153 static Eina_Bool
154 _e_mod_move_mini_apptray_widget_cb_motion_start(void *data,
155                                                 void *event_info)
156 {
157    E_Move *m = NULL;
158    E_Move_Mini_Apptray_Widget *mini_apptray_widget = (E_Move_Mini_Apptray_Widget *)data;
159
160    E_Move_Border *mb = NULL;
161    E_Move_Border *mini_apptray_mb = NULL;
162    E_Move_Event_Motion_Info *info;
163    E_Move_Widget_Object *mwo = NULL;
164    Evas_Event_Mouse_Down *mouse_down_event = NULL;
165    Eina_Bool clicked = EINA_FALSE;
166    Eina_List *l;
167    E_Move_Border *ev_mb = NULL;
168    Ecore_X_Window ev_win = 0;
169
170    info  = (E_Move_Event_Motion_Info *)event_info;
171    m = e_mod_move_util_get();
172
173    E_CHECK_RETURN(mini_apptray_widget, EINA_FALSE);
174
175    // clicked window indicator policy check
176    EINA_LIST_FOREACH(mini_apptray_widget->objs, l, mwo)
177      {
178         if (!mwo) continue;
179         ev_win = e_mod_move_event_win_get(mwo->event);
180      }
181    ev_mb = e_mod_move_border_client_find(ev_win);
182    // Check Mini Apptray State ( property )
183    if ((ev_mb)
184         && (ev_mb->mini_apptray_state == E_MOVE_MINI_APPTRAY_STATE_OFF))
185      return EINA_FALSE;
186
187    mb = e_mod_move_border_client_find(mini_apptray_widget->win);
188    if (!m || !mb || !mini_apptray_widget || !info) return EINA_FALSE;
189
190    mouse_down_event = info->event_info;
191    E_CHECK_RETURN(mouse_down_event, EINA_FALSE);
192    if (mouse_down_event->button != 1)
193      return EINA_FALSE;
194
195    EINA_LIST_FOREACH(mini_apptray_widget->objs, l, mwo)
196      {
197         if (!mwo) continue;
198         clicked = e_mod_move_event_click_get(mwo->event);
199      }
200    if (clicked)
201      return EINA_FALSE;
202
203    SL(LT_EVENT_OBJ,
204       "[MOVE] ev:%15.15s w:0x%08x MINI_APPTRAY_WIDGET_MOTION_START (%4d,%4d)\n",
205       "EVAS_OBJ", mb->bd->win,
206       info->coord.x, info->coord.y);
207
208    _e_mod_move_mini_apptray_widget_mini_apptray_move_set(mini_apptray_widget, EINA_FALSE);
209
210    /* check if apptray exists on the current zone */
211    mini_apptray_mb = e_mod_move_mini_apptray_find();
212    if ((mini_apptray_mb) &&
213        (mini_apptray_mb->visibility == E_MOVE_VISIBILITY_STATE_VISIBLE))
214      {
215         L(LT_EVENT_OBJ,
216           "[MOVE] ev:%15.15s w:0x%08x MINI_APPTRAY_WIDGET_MOTION_START %s\n",
217           "EVAS_OBJ", mb->bd->win,
218           "mini_apptray exists. return.");
219         return EINA_FALSE;
220      }
221
222    if ((mini_apptray_mb) &&
223        (REGION_INSIDE_ZONE(mini_apptray_mb, mb->bd->zone)))
224      {
225         e_mod_move_mini_apptray_e_border_move(mini_apptray_mb, -10000, -10000);
226      }
227
228    EINA_LIST_FOREACH(mini_apptray_widget->objs, l, mwo)
229      {
230         if (!mwo) continue;
231         e_mod_move_event_click_set(mwo->event, EINA_TRUE);
232      }
233
234    E_CHECK_GOTO(e_mod_move_flick_data_new(mb), error_cleanup);
235    e_mod_move_flick_data_init(mb, info->coord.x, info->coord.y);
236
237    if (!_e_mod_move_mini_apptray_widget_cb_motion_start_internal_mini_apptray_check(mini_apptray_mb))
238      {
239         goto error_cleanup;
240      }
241
242    //e_mod_move_mini_apptray_e_border_raise(mini_apptray_mb);
243    _e_mod_move_mini_apptray_widget_mini_apptray_move_set(mini_apptray_widget, EINA_TRUE);
244    e_mod_move_mini_apptray_objs_animation_start_position_set(mini_apptray_mb,
245                                                              mb->angle);
246    // send mini_apptray to "move start message".
247    e_mod_move_mini_apptray_anim_state_send(mini_apptray_mb, EINA_TRUE);
248
249    mini_apptray_widget->pos = info->coord; // save mouse click position
250
251    return EINA_TRUE;
252
253 error_cleanup:
254
255    EINA_LIST_FOREACH(mini_apptray_widget->objs, l, mwo)
256      {
257         if (!mwo) continue;
258         e_mod_move_event_click_set(mwo->event, EINA_FALSE);
259      }
260
261    _e_mod_move_mini_apptray_widget_mini_apptray_move_set(mini_apptray_widget, EINA_FALSE);
262
263    return EINA_FALSE;
264
265 }
266
267 static Eina_Bool
268 _e_mod_move_mini_apptray_widget_cb_motion_move(void *data,
269                                                void *event_info)
270 {
271    E_Move                      *m = NULL;
272    E_Move_Mini_Apptray_Widget  *mini_apptray_widget = (E_Move_Mini_Apptray_Widget *)data;
273    E_Move_Border               *mb = NULL;
274    E_Move_Event_Motion_Info    *info;
275    E_Move_Widget_Object        *mwo = NULL;
276    E_Zone                      *zone = NULL;
277    Eina_List                   *l;
278    Eina_Bool                    click = EINA_FALSE;
279    int                          angle;
280    Eina_Bool                    flick_state = EINA_FALSE;
281    E_Move_Border               *mini_apptray_mb = NULL;
282
283    info  = (E_Move_Event_Motion_Info *)event_info;
284    m = e_mod_move_util_get();
285
286    E_CHECK_RETURN(mini_apptray_widget, EINA_FALSE);
287    mb = e_mod_move_border_client_find(mini_apptray_widget->win);
288
289    if (!m || !mb || !info) return EINA_FALSE;
290
291    SL(LT_EVENT_OBJ,
292       "[MOVE] ev:%15.15s w:0x%08x MINI_APPTRAY_WIDGET_MOTION_MOVE a:%d (%4d,%4d)\n",
293       "EVAS_OBJ", mb->bd->win, mb->angle,
294       info->coord.x, info->coord.y);
295
296    angle = mb->angle;
297    zone = mb->bd->zone;
298
299    EINA_LIST_FOREACH(mini_apptray_widget->objs, l, mwo)
300      {
301         if (!mwo) continue;
302         click = e_mod_move_event_click_get(mwo->event);
303      }
304    E_CHECK_RETURN(click, EINA_FALSE);
305
306    // do not work on moving just work on flick action
307    e_mod_move_flick_data_update(mb, info->coord.x, info->coord.y);
308    flick_state = e_mod_move_flick_state_get2(mb);
309
310    if (_e_mod_move_mini_apptray_widget_mini_apptray_move_get(mini_apptray_widget))
311      {
312         mini_apptray_mb = e_mod_move_mini_apptray_find();
313
314         if (_e_mod_move_mini_apptray_widget_mini_apptray_flick_process(mini_apptray_widget,
315                                                                        mini_apptray_mb,
316                                                                        angle, flick_state))
317           {
318              return EINA_TRUE;
319           }
320      }
321
322 #if 0
323    if (_e_mod_move_mini_apptray_widget_mini_apptray_move_get(mini_apptray_widget))
324      {
325         mini_apptray_mb = e_mod_move_mini_apptray_find();
326         E_CHECK_RETURN(mini_apptray_mb, EINA_FALSE);
327 // change later for flick_up
328 // todo flick up geometry
329         switch (angle)
330           {
331            case   0:
332               if (info->coord.y > (zone->h - mini_apptray_mb->h))
333                 {
334                    y = info->coord.y;
335                    need_move = EINA_TRUE;
336                 }
337               break;
338            case  90:
339               if (info->coord.x > (zone->w - mini_apptray_mb->w))
340                 {
341                    x = info->coord.x;
342                    need_move = EINA_TRUE;
343                 }
344               break;
345            case 180:
346               if (info->coord.y < mini_apptray_mb->h)
347                 {
348                    y = info->coord.y - mini_apptray_mb->h;
349                    need_move = EINA_TRUE;
350                 }
351               break;
352            case 270:
353               if (info->coord.x < mini_apptray_mb->w)
354                 {
355                    x = info->coord.x - mini_apptray_mb->w;
356                    need_move = EINA_TRUE;
357                 }
358               break;
359            default :
360               break;
361           }
362         if (need_move)
363           e_mod_move_mini_apptray_objs_move(mini_apptray_mb, x, y);
364      }
365
366    mini_apptray_widget->pos = info->coord; // save mouse move position
367 #endif
368
369    return EINA_TRUE;
370 }
371
372 static Eina_Bool
373 _e_mod_move_mini_apptray_widget_cb_motion_end(void *data,
374                                               void *event_info)
375 {
376    E_Move                      *m = NULL;
377    E_Move_Mini_Apptray_Widget  *mini_apptray_widget = (E_Move_Mini_Apptray_Widget *)data;
378    E_Move_Border               *mb = NULL;
379    E_Move_Border               *mini_apptray_mb = NULL;
380    E_Move_Event_Motion_Info    *info;
381    E_Move_Widget_Object        *mwo = NULL;
382    Eina_List                   *l;
383    E_Zone                      *zone;
384    Evas_Event_Mouse_Up         *mouse_up_event;
385    Eina_Bool                    click = EINA_FALSE;
386    Eina_Bool                    flick_state = EINA_FALSE;
387    int                          angle = 0;
388    Ecore_X_Window               ev_win = 0;
389
390    info  = (E_Move_Event_Motion_Info *)event_info;
391    m = e_mod_move_util_get();
392
393    E_CHECK_RETURN(mini_apptray_widget, EINA_FALSE);
394    mb = e_mod_move_border_client_find(mini_apptray_widget->win);
395
396    if (!m || !mb || !info) return EINA_FALSE;
397
398    mouse_up_event = info->event_info;
399    E_CHECK_RETURN(mouse_up_event, EINA_FALSE);
400    if (mouse_up_event->button != 1)
401      return EINA_FALSE;
402
403    SL(LT_EVENT_OBJ,
404       "[MOVE] ev:%15.15s w:0x%08x ,angle:%d, (%d,%d)  %s()\n",
405       "EVAS_OBJ", mb->bd->win, mb->angle, info->coord.x, info->coord.y,
406       __func__);
407
408    angle = mb->angle;
409    zone = mb->bd->zone;
410
411    EINA_LIST_FOREACH(mini_apptray_widget->objs, l, mwo)
412      {
413         if (!mwo) continue;
414         click = e_mod_move_event_click_get(mwo->event);
415      }
416    E_CHECK_GOTO(click, error_cleanup);
417
418    e_mod_move_flick_data_update(mb, info->coord.x, info->coord.y);
419    flick_state = e_mod_move_flick_state_get2(mb);
420
421    if (_e_mod_move_mini_apptray_widget_mini_apptray_move_get(mini_apptray_widget))
422      {
423         mini_apptray_mb = e_mod_move_mini_apptray_find();
424
425         if (_e_mod_move_mini_apptray_widget_mini_apptray_flick_process(mini_apptray_widget,
426                                                                        mini_apptray_mb,
427                                                                        angle, flick_state))
428           {
429              return EINA_TRUE;
430           }
431         else
432           {
433              // if mini_apptray animation is not called, must destory datas explicit
434              if (mini_apptray_mb)
435                {
436                   e_border_focus_set(mini_apptray_mb ->bd, 0, 0);
437                   e_mod_move_mini_apptray_dim_hide(mini_apptray_mb );
438                   e_mod_move_mini_apptray_objs_del(mini_apptray_mb );
439                }
440           }
441      }
442 // just work on flick action. so. currently block.
443 #if 0
444    mx = zone->x;
445    my = zone->y;
446    ax = mx;
447    ay = my;
448    switch (angle)
449      {
450       case   0:
451          if (mini_apptray_mb)
452            {
453               check_h = mini_apptray_mb->h;
454               if (check_h) check_h /= 2;
455               if (info->coord.y > (zone->h - check_h))
456                 {
457                    my = zone->h;
458                    ay = my;
459                 }
460                else
461                 {
462                    my = zone->h - mini_apptray_mb->h;
463                    ay = my;
464                 }
465            }
466          break;
467       case  90:
468          if (mini_apptray_mb)
469            {
470               check_w = mini_apptray_mb->w;
471               if (check_w) check_w /= 2;
472               if (info->coord.x > (zone->w - check_w))
473                 {
474                    mx = zone->w;
475                    ax = mx;
476                 }
477                else
478                 {
479                    mx = zone->w - mini_apptray_mb->w;
480                    ax = mx;
481                 }
482            }
483          break;
484       case 180:
485          if (mini_apptray_mb)
486            {
487               check_h = mini_apptray_mb->h;
488               if (check_h) check_h /= 2;
489               if (info->coord.y < check_h)
490                 {
491                    my = mini_apptray_mb->h * -1;
492                    ay = my;
493                 }
494            }
495          break;
496       case 270:
497          if (mini_apptray_mb)
498            {
499               check_w = mini_apptray_mb->w;
500               if (check_w) check_w /= 2;
501               if (info->coord.x < check_w)
502                 {
503                    mx = mini_apptray_mb->w * -1;
504                    ax = mx;
505                 }
506            }
507          break;
508       default :
509          break;
510      }
511
512    if (mini_apptray_mb)
513      {
514         e_mod_move_mini_apptray_e_border_move(mini_apptray_mb, mx, my);
515         e_mod_move_mini_apptray_objs_animation_move(mini_apptray_mb, ax, ay);
516      }
517 #endif
518
519    // if flick check fail then, redirect event
520    EINA_LIST_FOREACH(mini_apptray_widget->objs, l, mwo)
521      {
522         if (!mwo) continue;
523         ev_win = e_mod_move_event_win_get(mwo->event);
524      }
525
526    if (ev_win)
527      {
528         e_mod_move_mouse_event_send(ev_win, E_MOVE_MOUSE_EVENT_MOVE, mini_apptray_widget->pos);
529         e_mod_move_mouse_event_send(ev_win, E_MOVE_MOUSE_EVENT_DOWN, mini_apptray_widget->pos);
530         e_mod_move_mouse_event_send(ev_win, E_MOVE_MOUSE_EVENT_MOVE, info->coord);
531         e_mod_move_mouse_event_send(ev_win, E_MOVE_MOUSE_EVENT_UP, info->coord);
532      }
533
534    mini_apptray_widget->pos = info->coord; // save mouse up position
535
536    EINA_LIST_FOREACH(mini_apptray_widget->objs, l, mwo)
537      {
538         if (!mwo) continue;
539         e_mod_move_event_click_set(mwo->event, EINA_FALSE);
540      }
541
542 error_cleanup:
543    if (mb->flick_data) e_mod_move_flick_data_free(mb);
544    _e_mod_move_mini_apptray_widget_mini_apptray_move_set(mini_apptray_widget, EINA_FALSE);
545
546    return EINA_TRUE;
547 }
548
549 static Ecore_X_Window
550 _e_mod_move_mini_apptray_event_win_find(void *event_info)
551 {
552    E_Move_Event_Motion_Info *info = NULL;
553    E_Border                 *find_bd = NULL;
554    Ecore_X_Window            win = 0;
555    info  = (E_Move_Event_Motion_Info *)event_info;
556
557    E_CHECK_RETURN(info, 0);
558
559    find_bd = e_mod_move_util_border_find_by_pointer(info->coord.x, info->coord.y);
560
561    if (find_bd) win = find_bd->client.win;
562    else win = 0;
563
564    SL(LT_EVENT_OBJ,
565       "[MOVE] ev:%15.15s MINI_APPTRAY_EVENT_WIN_FIND w:0x%08x (%4d,%4d)\n",
566       "EVAS_OBJ", win, info->coord.x, info->coord.y);
567
568    return win;
569 }
570
571 static void
572 _e_mod_move_mini_apptray_widget_obj_event_setup(E_Move_Mini_Apptray_Widget *mini_apptray_widget,
573                                                 E_Move_Widget_Object    *mwo)
574 {
575    E_CHECK(mini_apptray_widget);
576    E_CHECK(mwo);
577
578    mwo->event = e_mod_move_event_new(mini_apptray_widget->win, mwo->obj);
579    E_CHECK(mwo->event);
580
581    // change later ... below function used for just log
582    e_mod_move_event_data_type_set(mwo->event, E_MOVE_EVENT_DATA_TYPE_WIDGET_INDICATOR);
583
584    e_mod_move_event_angle_cb_set(mwo->event,
585                                  e_mod_move_util_win_prop_angle_get);
586    e_mod_move_event_cb_set(mwo->event, E_MOVE_EVENT_TYPE_MOTION_START,
587                            _e_mod_move_mini_apptray_widget_cb_motion_start,
588                            mini_apptray_widget);
589    e_mod_move_event_cb_set(mwo->event, E_MOVE_EVENT_TYPE_MOTION_MOVE,
590                            _e_mod_move_mini_apptray_widget_cb_motion_move,
591                            mini_apptray_widget);
592    e_mod_move_event_cb_set(mwo->event, E_MOVE_EVENT_TYPE_MOTION_END,
593                            _e_mod_move_mini_apptray_widget_cb_motion_end,
594                            mini_apptray_widget);
595    e_mod_move_event_propagate_type_set(mwo->event,
596                                        E_MOVE_EVENT_PROPAGATE_TYPE_NONE);
597    e_mod_move_event_win_find_cb_set(mwo->event,
598                                     _e_mod_move_mini_apptray_event_win_find);
599 }
600
601 static Eina_Bool
602 _e_mod_move_mini_apptray_widget_event_send_policy_check(E_Move_Mini_Apptray_Widget *mini_apptray_widget,
603                                                         Evas_Point                  pos)
604 {
605    int x = 0, y = 0, w = 0, h = 0;
606    Eina_Bool ret = EINA_FALSE;
607
608    E_CHECK_RETURN(mini_apptray_widget, EINA_FALSE);
609
610    e_mod_move_widget_objs_geometry_get(mini_apptray_widget->objs, &x ,&y, &w, &h);
611
612    if (E_INSIDE(pos.x, pos.y, x, y, w, h)) ret = EINA_TRUE;
613
614    return ret;
615 }
616
617 /* externally accessible functions */
618
619 /* set current mini apptray widget */
620 EINTERN void
621 e_mod_move_mini_apptray_widget_set(E_Move_Mini_Apptray_Widget *mini_apptray_widget)
622 {
623    E_Move *m = NULL;
624
625    m = e_mod_move_util_get();
626    E_CHECK(m);
627
628    if (m->mini_apptray_widget)
629      {
630         e_mod_move_mini_apptray_widget_del(m->mini_apptray_widget);
631      }
632
633    m->mini_apptray_widget = mini_apptray_widget;
634 }
635
636 /* get current mini_apptray widget */
637 EINTERN E_Move_Mini_Apptray_Widget *
638 e_mod_move_mini_apptray_widget_get(void)
639 {
640    E_Move *m = NULL;
641    m = e_mod_move_util_get();
642    E_CHECK_RETURN(m, NULL);
643
644    return m->mini_apptray_widget;
645 }
646
647 /* find mini_apptray widget target window */
648 // must update/change this function ( for mini_apptray policy )
649 EINTERN Eina_Bool
650 e_mod_move_mini_apptray_widget_target_window_find(Ecore_X_Window *win)
651 {
652    E_Move        *m = NULL;
653    E_Move_Border *find_mb = NULL;
654    Eina_Bool      found = EINA_FALSE;
655    E_Zone        *zone = NULL;
656    Eina_Bool      ret = EINA_FALSE;
657
658    E_CHECK_RETURN(win, EINA_FALSE);
659    m = e_mod_move_util_get();
660    E_CHECK_RETURN(m, EINA_FALSE);
661
662    // fix later
663    EINA_INLIST_REVERSE_FOREACH(m->borders, find_mb)
664      {
665         if (!find_mb->bd) continue;
666         // the first OnScreen & FullScreen Window
667         zone = find_mb->bd->zone;
668         if (find_mb->visible
669             && REGION_EQUAL_TO_ZONE(find_mb, zone)  // check fullscreen
670             && (zone->id == 0)) // change zone->id comparing to bd's profile property (mobile)
671           {
672              found = EINA_TRUE;
673              break;
674           }
675      }
676
677    if (found
678        && !(TYPE_INDICATOR_CHECK(find_mb))
679        && !(TYPE_APPTRAY_CHECK(find_mb))
680        && !(TYPE_MINI_APPTRAY_CHECK(find_mb))
681        && !(TYPE_QUICKPANEL_CHECK(find_mb))
682        && (find_mb->mini_apptray_state != E_MOVE_MINI_APPTRAY_STATE_OFF))
683      {
684         *win = find_mb->bd->client.win;
685         ret = EINA_TRUE;
686      }
687
688    return ret;
689 }
690
691 /* find mini_apptray widget's target window and apply mini_apptray widget control */
692 EINTERN void
693 e_mod_move_mini_apptray_widget_apply(void)
694 {
695    E_Move                     *m = NULL;
696    E_Move_Mini_Apptray_Widget *mini_apptray_widget = NULL;
697    E_Move_Border              *mini_apptray_mb = NULL;
698    Ecore_X_Window              target_win;
699
700    m = e_mod_move_util_get();
701    E_CHECK(m);
702
703    E_CHECK(m->apptray_launch_by_flickup);
704
705    if (m->screen_reader_state) return;
706    if (m->setup_wizard_state) return;
707
708    mini_apptray_mb = e_mod_move_mini_apptray_find();
709    if (!mini_apptray_mb)
710      {
711         if ((mini_apptray_widget = e_mod_move_mini_apptray_widget_get()))
712           e_mod_move_mini_apptray_widget_del(mini_apptray_widget);
713         return;
714      }
715
716    if (e_mod_move_mini_apptray_widget_target_window_find(&target_win))
717      {
718         // if previous mini_apptray_widget is created
719         if ((mini_apptray_widget = e_mod_move_mini_apptray_widget_get()))
720           {
721              // if current mini_apptray_widget's win is equal to finded win
722              // then just return.
723              if ((mini_apptray_widget->win == target_win)) return;
724              else
725                {
726                   // if current mini_apptray_widget's win is not equal to finded win
727                   // then del previous mini_apptray_widget and add new mini_apptray_widget.
728                   e_mod_move_mini_apptray_widget_del(mini_apptray_widget);
729
730                   e_mod_move_mini_apptray_widget_set(e_mod_move_mini_apptray_widget_add(target_win));
731                }
732           }
733         else
734           {
735              //if previous mini_apptray_widget is not creagted
736              //then add new mini_apptray_widget.
737              e_mod_move_mini_apptray_widget_set(e_mod_move_mini_apptray_widget_add(target_win));
738           }
739      }
740    else
741      {
742         // if current window does not require mini_apptray_widget
743         // and previous mini_apptray_widget is created,
744         // then del previous mini_apptray_widget
745         if ((mini_apptray_widget = e_mod_move_mini_apptray_widget_get()))
746           {
747              e_mod_move_mini_apptray_widget_del(mini_apptray_widget);
748              e_mod_move_mini_apptray_widget_set(NULL);
749           }
750      }
751 }
752
753 /* create E_Move_Border related Mini_Apptray_Widget */
754 EINTERN E_Move_Mini_Apptray_Widget *
755 e_mod_move_mini_apptray_widget_add(Ecore_X_Window win)
756 {
757    E_Move                     *m = NULL;
758    E_Move_Border              *mb = NULL;
759    E_Move_Mini_Apptray_Widget *mini_apptray_widget = NULL;
760    E_Move_Widget_Object       *mwo = NULL;
761    Eina_List                  *l;
762    int                         x;
763    int                         y;
764    int                         w;
765    int                         h;
766
767    m = e_mod_move_util_get();
768    E_CHECK_RETURN(m, EINA_FALSE);
769
770    E_CHECK_RETURN(e_mod_move_mini_apptray_find(), EINA_FALSE);
771
772    mb = e_mod_move_border_client_find(win);
773    E_CHECK_RETURN(mb, NULL);
774
775    mini_apptray_widget = E_NEW(E_Move_Mini_Apptray_Widget, 1);
776    E_CHECK_RETURN(mini_apptray_widget, NULL);
777
778    mini_apptray_widget->win = win;
779    mini_apptray_widget->objs = e_mod_move_widget_objs_add(m);
780    if (mini_apptray_widget->objs)
781      {
782         switch (mb->angle)
783           {
784              case 90:
785                 x = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_90].x;
786                 y = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_90].y;
787                 w = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_90].w;
788                 h = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_90].h;
789                 break;
790              case 180:
791                 x = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_180].x;
792                 y = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_180].y;
793                 w = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_180].w;
794                 h = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_180].h;
795                 break;
796              case 270:
797                 x = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_270].x;
798                 y = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_270].y;
799                 w = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_270].w;
800                 h = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_270].h;
801                 break;
802              case 0:
803              default:
804                 x = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_0].x;
805                 y = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_0].y;
806                 w = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_0].w;
807                 h = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_0].h;
808                 break;
809           }
810         e_mod_move_widget_objs_move(mini_apptray_widget->objs, x, y);
811         e_mod_move_widget_objs_resize(mini_apptray_widget->objs, w, h);
812         e_mod_move_widget_objs_layer_set(mini_apptray_widget->objs, EVAS_LAYER_MAX-2);
813         e_mod_move_widget_objs_color_set(mini_apptray_widget->objs, 0, 0, 0, 0);
814         e_mod_move_widget_objs_show(mini_apptray_widget->objs);
815         e_mod_move_widget_objs_raise(mini_apptray_widget->objs);
816
817         // Set Input Shape Mask
818         // change later
819         if ((mini_apptray_widget->input_region_id = e_manager_comp_input_region_id_new(m->man)))
820           {
821              e_manager_comp_input_region_id_set(m->man,
822                                                 mini_apptray_widget->input_region_id,
823                                                 x, y, w, h);
824           }
825         else
826           {
827              goto error_cleanup;
828           }
829      }
830    else
831      {
832         goto error_cleanup;
833      }
834
835    // Set Event Handler
836    EINA_LIST_FOREACH(mini_apptray_widget->objs, l, mwo)
837      {
838         if (!mwo) continue;
839         _e_mod_move_mini_apptray_widget_obj_event_setup(mini_apptray_widget, mwo);
840      }
841    return mini_apptray_widget;
842
843 error_cleanup:
844    if (mini_apptray_widget->objs) e_mod_move_widget_objs_del(mini_apptray_widget->objs);
845    memset(mini_apptray_widget, 0, sizeof(E_Move_Mini_Apptray_Widget));
846    E_FREE(mini_apptray_widget);
847    return NULL;
848 }
849
850 /* delete mini_apptray_widget */
851 EINTERN void
852 e_mod_move_mini_apptray_widget_del(E_Move_Mini_Apptray_Widget *mini_apptray_widget)
853 {
854    E_Move        *m = NULL;
855    E_Move_Border *mb = NULL;
856    E_Move_Border *mini_apptray_mb = NULL;
857    E_Zone        *zone = NULL;
858    int x = 0; int y = 0;
859
860    E_CHECK(mini_apptray_widget);
861    m = e_mod_move_util_get();
862
863    if ((mb = e_mod_move_border_client_find(mini_apptray_widget->win)))
864      {
865         // compositor's input region free
866         // change later
867         if (mini_apptray_widget->input_region_id)
868           {
869              e_manager_comp_input_region_id_del(m->man,
870                                                 mini_apptray_widget->input_region_id);
871           }
872
873         // if mini_apptray_widget is deleted, then mini_apptray's mirror object hide with animation
874         if (mini_apptray_widget->mini_apptray_move)
875           {
876              mini_apptray_mb = e_mod_move_mini_apptray_find();
877              E_CHECK_GOTO(mini_apptray_mb, error_cleanup);
878              zone = mini_apptray_mb->bd->zone;
879
880              switch (mb->angle)
881                {
882                 case  90:
883                    x = zone->w;
884                    y = 0;
885                    break;
886                 case 180:
887                    x = 0;
888                    y = mini_apptray_mb->h * -1;
889                    break;
890                 case 270:
891                    x = mini_apptray_mb->w * -1;
892                    y = 0;
893                    break;
894                 case   0:
895                 default :
896                    x = 0;
897                    y = zone->h;
898                    break;
899                }
900              if (e_mod_move_mini_apptray_objs_animation_state_get(mini_apptray_mb))
901                {
902                   e_mod_move_mini_apptray_objs_animation_stop(mini_apptray_mb);
903                   e_mod_move_mini_apptray_objs_animation_clear(mini_apptray_mb);
904                }
905              e_mod_move_mini_apptray_objs_add(mini_apptray_mb);
906
907              e_mod_move_mini_apptray_e_border_move(mini_apptray_mb, x, y);
908              e_mod_move_mini_apptray_objs_animation_move(mini_apptray_mb, x, y);
909              L(LT_EVENT_OBJ,
910                "[MOVE] ev:%15.15s Mini_Apptray Widget Deleted: Hide Mini Apptray %s():%d\n",
911                "EVAS_OBJ", __func__, __LINE__);
912           }
913      }
914
915 error_cleanup:
916    if (mini_apptray_widget->objs) e_mod_move_widget_objs_del(mini_apptray_widget->objs);
917    memset(mini_apptray_widget, 0, sizeof(E_Move_Mini_Apptray_Widget));
918    E_FREE(mini_apptray_widget);
919    if (m) m->mini_apptray_widget = NULL;
920 }
921
922 EINTERN Eina_Bool
923 e_mod_move_mini_apptray_widget_angle_change(Ecore_X_Window win)
924 {
925    E_Move                     *m = NULL;
926    E_Move_Mini_Apptray_Widget *mini_apptray_widget = NULL;
927    Eina_Bool                   ret = EINA_FALSE;
928    E_Move_Border              *mb = NULL;
929    int                         x;
930    int                         y;
931    int                         w;
932    int                         h;
933
934    m = e_mod_move_util_get();
935    E_CHECK_RETURN(m, EINA_FALSE);
936
937    mini_apptray_widget = e_mod_move_mini_apptray_widget_get();
938    E_CHECK_RETURN(mini_apptray_widget, EINA_FALSE);
939
940    if ((mini_apptray_widget->win == win))
941      {
942         if ((mb = e_mod_move_border_client_find(win)))
943           {
944              switch (mb->angle)
945                {
946                   case 90:
947                      x = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_90].x;
948                      y = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_90].y;
949                      w = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_90].w;
950                      h = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_90].h;
951                      break;
952                   case 180:
953                      x = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_180].x;
954                      y = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_180].y;
955                      w = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_180].w;
956                      h = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_180].h;
957                      break;
958                   case 270:
959                      x = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_270].x;
960                      y = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_270].y;
961                      w = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_270].w;
962                      h = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_270].h;
963                      break;
964                   case 0:
965                   default:
966                      x = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_0].x;
967                      y = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_0].y;
968                      w = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_0].w;
969                      h = m->mini_apptray_widget_geometry[E_MOVE_ANGLE_0].h;
970                      break;
971                 }
972               e_mod_move_widget_objs_move(mini_apptray_widget->objs, x, y);
973               e_mod_move_widget_objs_resize(mini_apptray_widget->objs, w, h);
974
975               // Set Input Shape Mask
976               // change later
977               if (mini_apptray_widget->input_region_id)
978                 {
979                    e_manager_comp_input_region_id_set(m->man,
980                                                       mini_apptray_widget->input_region_id,
981                                                       x, y, w, h);
982                 }
983
984               ret = EINA_TRUE;
985            }
986      }
987    return ret;
988 }
989
990 EINTERN Eina_Bool
991 e_mod_move_mini_apptray_widget_scrollable_check(void)
992 {
993    E_Move_Border *lockscr_mb = NULL;
994    E_Move_Border *taskmgr_mb = NULL;
995    E_Move_Border *pwlock_mb = NULL;
996
997    // if lockscreen is exist & visible, then do not show  apptray
998    if ((lockscr_mb = e_mod_move_lockscreen_find()))
999      {
1000         if (lockscr_mb->visibility == E_MOVE_VISIBILITY_STATE_VISIBLE)
1001           {
1002              L(LT_EVENT_OBJ,
1003                "[MOVE] ev:%15.15s  %s %s()\n",
1004                "EVAS_OBJ","Lockscreen is exist.", __func__);
1005              return EINA_FALSE;
1006           }
1007      }
1008    // if taskmanage is exist & visible, then do not show  apptray
1009    if ((taskmgr_mb = e_mod_move_taskmanager_find()))
1010      {
1011         if (taskmgr_mb->visibility == E_MOVE_VISIBILITY_STATE_VISIBLE)
1012           {
1013              L(LT_EVENT_OBJ,
1014                "[MOVE] ev:%15.15s  %s %s()\n",
1015                "EVAS_OBJ","TaskManager is exist.", __func__);
1016              return EINA_FALSE;
1017           }
1018      }
1019
1020    // if pwlock is exist & visible, then do not show  apptray
1021    if ((pwlock_mb = e_mod_move_pwlock_find()))
1022      {
1023         if (pwlock_mb->visibility == E_MOVE_VISIBILITY_STATE_VISIBLE)
1024           {
1025              L(LT_EVENT_OBJ,
1026                "[MOVE] ev:%15.15s  %s %s()\n",
1027                "EVAS_OBJ","PWLOCK is exist.", __func__);
1028              return EINA_FALSE;
1029           }
1030      }
1031
1032    return EINA_TRUE;
1033 }
1034
1035 EINTERN Eina_Bool
1036 e_mod_move_mini_apptray_widget_click_get(E_Move_Mini_Apptray_Widget* mini_apptray_widget)
1037 {
1038    Eina_Bool             click = EINA_FALSE;
1039    E_Move_Widget_Object *mwo = NULL;
1040    Eina_List             *l;
1041
1042    E_CHECK_RETURN(mini_apptray_widget, EINA_FALSE);
1043    E_CHECK_RETURN(mini_apptray_widget->objs, EINA_FALSE);
1044
1045    EINA_LIST_FOREACH(mini_apptray_widget->objs, l, mwo)
1046      {
1047         if (!mwo) continue;
1048         click = e_mod_move_event_click_get(mwo->event);
1049      }
1050
1051    return click;
1052 }
1053
1054 EINTERN Eina_Bool
1055 e_mod_move_mini_apptray_widget_event_clear(E_Move_Mini_Apptray_Widget* mini_apptray_widget)
1056 {
1057    Eina_Bool             click = EINA_FALSE;
1058    E_Move_Widget_Object *mwo = NULL;
1059    Eina_List             *l;
1060    E_Move_Border         *mb = NULL;
1061
1062    E_CHECK_RETURN(mini_apptray_widget, EINA_FALSE);
1063    E_CHECK_RETURN(mini_apptray_widget->objs, EINA_FALSE);
1064
1065    click = e_mod_move_mini_apptray_widget_click_get(mini_apptray_widget);
1066    E_CHECK_RETURN(click, EINA_FALSE);
1067
1068    EINA_LIST_FOREACH(mini_apptray_widget->objs, l, mwo)
1069      {
1070         if (!mwo) continue;
1071         e_mod_move_event_data_clear(mwo->event);
1072         e_mod_move_event_click_set(mwo->event, EINA_FALSE);
1073      }
1074
1075    _e_mod_move_mini_apptray_widget_mini_apptray_move_set(mini_apptray_widget, EINA_FALSE);
1076
1077    mb = e_mod_move_border_client_find(mini_apptray_widget->win);
1078    if (mb && mb->flick_data) e_mod_move_flick_data_free(mb);
1079    return EINA_TRUE;
1080 }
1081
1082 EINTERN Eina_Bool
1083 e_mod_move_mini_apptray_widget_state_change(Ecore_X_Window win, Eina_Bool state)
1084 {
1085    E_Move_Mini_Apptray_Widget *mini_apptray_widget = NULL;
1086
1087    if ((mini_apptray_widget = e_mod_move_mini_apptray_widget_get()))
1088      {
1089         if ((mini_apptray_widget->win == win)
1090             && (!state))
1091           {
1092              // mini_apptray_state disable -> delete current mini_apptray_widget
1093              e_mod_move_mini_apptray_widget_del(mini_apptray_widget);
1094              e_mod_move_mini_apptray_widget_set(NULL);
1095           }
1096      }
1097    else
1098      {
1099         if (state) e_mod_move_mini_apptray_widget_apply();
1100      }
1101
1102    return EINA_TRUE;
1103 }
1104
1105 EINTERN Eina_Bool
1106 e_mod_move_mini_apptray_widget_angle_change_post_job(void)
1107 {
1108    E_Move_Mini_Apptray_Widget *mini_apptray_widget = NULL;
1109    E_Move_Border              *mb = NULL;
1110    E_Border                   *bd = NULL;
1111    E_Zone                     *zone = NULL;
1112    int                         angle = 0;
1113    int                         x = 0, y = 0;
1114
1115    mini_apptray_widget = e_mod_move_mini_apptray_widget_get();
1116    E_CHECK_RETURN(mini_apptray_widget, EINA_FALSE);
1117
1118    mb = e_mod_move_border_client_find(mini_apptray_widget->win);
1119    E_CHECK_RETURN(mb, EINA_FALSE);
1120
1121    bd = mb->bd;
1122    E_CHECK_RETURN(bd, EINA_FALSE);
1123
1124    zone = bd->zone;
1125    E_CHECK_RETURN(zone, EINA_FALSE);
1126
1127    angle = mb->angle;
1128
1129    if (e_mod_move_mini_apptray_widget_click_get(mini_apptray_widget))
1130      {
1131          switch (angle)
1132            {
1133             case   0:
1134                x = zone->x + zone->w;
1135                y = zone->y + zone->h;
1136                break;
1137             case  90:
1138                x = zone->x + zone->w;
1139                y = zone->y + zone->h;
1140                break;
1141             case 180:
1142                x = zone->x;
1143                y = zone->y;
1144                break;
1145             case 270:
1146                x = zone->x;
1147                y = zone->y;
1148                break;
1149             default :
1150                break;
1151            }
1152      }
1153
1154    if (mb->flick_data)
1155      e_mod_move_flick_data_init(mb, x, y);
1156
1157    return EINA_TRUE;
1158 }