7c1de56275ee25c32aa4825a69b419fcd87487b0
[framework/uifw/e17-extra-modules.git] / comp-tizen / src / e_mod_comp_effect_image_launch.c
1 #include "e_mod_comp_shared_types.h"
2 #include "e_mod_comp.h"
3 #include "e_mod_comp_atoms.h"
4 #include "e_mod_comp_debug.h"
5 #include "e_mod_comp_effect_image_launch.h"
6
7 struct _E_Comp_Effect_Image_Launch
8 {
9    Eina_Bool       running : 1;
10    Eina_Bool       fake_image_show_done : 1; // image launch edje object got effect done or not.
11    Evas_Object    *obj;             // image object
12    Evas_Object    *shobj;           // image shadow object
13    Ecore_Timer    *timeout;         // max time between show, hide image launch
14    Ecore_X_Window  win;             // this represent image launch effect's real window id.
15    int             w, h;            // width and height of image object
16    int             rot;             // rotation angle
17    int             indicator_show;  // indicator enable / disable flag
18    Evas_Object*    indicator_obj;   // plugin indicator object
19    Evas_Object*    layer_obj;       // evas_object between normal layer with float layer
20 };
21
22 /* local subsystem functions */
23 static void      _show_done(void *data, Evas_Object *obj, const char *emission, const char *source);
24 static void      _hide_done(void *data, Evas_Object *obj, const char *emission, const char *source);
25 static Eina_Bool _launch_timeout(void *data);
26 static E_Comp_Win *_appinapp_bottom_win_get(E_Comp_Win *normal_top);
27
28 /* local subsystem globals */
29
30 /* externally accessible functions */
31 EINTERN E_Comp_Effect_Image_Launch *
32 e_mod_comp_effect_image_launch_new(Evas *e,
33                                    int w, int h)
34 {
35    E_Comp_Effect_Image_Launch *eff;
36    int ok = 0;
37
38    E_Container *con;
39    E_Comp_Win *layers_cw = NULL;
40    Eina_List *ll;
41    E_Comp_Object *co;
42    int layer;
43
44    E_CHECK_RETURN(e, NULL);
45
46    eff = E_NEW(E_Comp_Effect_Image_Launch, 1);
47    E_CHECK_RETURN(eff, NULL);
48
49    eff->shobj = edje_object_add(e);
50    E_CHECK_GOTO(eff->shobj, error);
51
52    //indicator_comp
53    Ecore_Evas *ee;
54    ee = ecore_evas_ecore_evas_get(e);
55    E_CHECK_GOTO(ee, error);
56    eff->indicator_obj = ecore_evas_extn_plug_new(ee);
57    E_CHECK_GOTO(eff->indicator_obj, error);
58
59    ok = edje_object_file_set
60           (eff->shobj,
61           _comp_mod->conf->shadow_file,
62           "fake_effect_fade");
63    E_CHECK_GOTO(ok, error);
64
65    eff->w = w;
66    eff->h = h;
67
68    evas_object_move(eff->shobj, 0, 0);
69    evas_object_resize(eff->shobj, w, h);
70
71    eff->obj = evas_object_image_add(e);
72    E_CHECK_GOTO(eff->obj, error);
73
74    edje_object_signal_callback_add
75      (eff->shobj, "fake,action,hide,done", "fake",
76      _hide_done, eff);
77
78    edje_object_signal_callback_add
79      (eff->shobj, "fake,action,show,done", "fake",
80      _show_done, eff);
81
82    // check fake image object stack (Choice proper layer)
83    eff->layer_obj = NULL;
84    layer = _comp_mod->conf->fake_launch_layer;
85    con = e_container_current_get(e_manager_current_get());
86    if ((con) && (layer))
87      layers_cw = e_mod_comp_win_find(con->layers[layer].win);
88
89    if (layers_cw)
90      {
91         EINA_LIST_FOREACH(layers_cw->objs, ll, co)
92           {
93              if (!co) continue;
94              eff->layer_obj = co->shadow;
95           }
96      }
97
98    return eff;
99
100 error:
101    e_mod_comp_effect_image_launch_free(eff);
102    return NULL;
103 }
104
105 EINTERN void
106 e_mod_comp_effect_image_launch_free(E_Comp_Effect_Image_Launch *eff)
107 {
108    E_CHECK(eff);
109    if (eff->shobj) evas_object_del(eff->shobj);
110    if (eff->obj) evas_object_del(eff->obj);
111    E_FREE(eff);
112 }
113
114 EINTERN Eina_Bool
115 e_mod_comp_effect_image_launch_handler_message(Ecore_X_Event_Client_Message *ev)
116 {
117    E_Comp_Effect_Image_Launch *eff;
118    E_Comp *c = NULL;
119    char *file = NULL;
120
121    E_CHECK_RETURN(ev, 0);
122
123    c = e_mod_comp_find(ev->win);
124    E_CHECK_RETURN(c, 0);
125    E_CHECK_RETURN(c->fake_image_launch, 0);
126
127    eff = c->eff_img;
128    E_CHECK_RETURN(eff, 0);
129
130    eff->rot = ev->data.l[1]; //rotation value
131    eff->indicator_show = ev->data.l[2]; //indicator flag value
132
133    if (ev->data.l[0] == 0)
134      {
135         e_mod_comp_effect_image_launch_hide(eff);
136      }
137    else if (ev->data.l[0] == 1)
138      {
139         file = ecore_x_window_prop_string_get
140                  (ev->win, ATOM_IMAGE_LAUNCH_FILE);
141         E_CHECK_RETURN(file, 0);
142
143         e_mod_comp_effect_image_launch_show(eff, file);
144         E_FREE(file);
145      }
146
147    return EINA_TRUE;
148 }
149
150 EINTERN Eina_Bool
151 e_mod_comp_effect_image_launch_show(E_Comp_Effect_Image_Launch *eff,
152                                     const char *file)
153 {
154    E_Comp *c = e_mod_comp_util_get();
155    E_Comp_Win *bg_cw = NULL;
156    Eina_Bool grabbed;
157    Evas_Load_Error err;
158    Eina_Bool res;
159    int img_w, img_h;
160    Eina_List *ll;
161    E_Comp_Object *co;
162    E_Comp_Win *bottom_appinapp_cw = NULL;
163
164    E_CHECK_RETURN(eff, 0);
165    E_CHECK_RETURN(file, 0);
166    E_CHECK_RETURN(c, 0);
167
168    grabbed = e_mod_comp_util_grab_key_set(EINA_TRUE);
169    E_CHECK_RETURN(grabbed, 0);
170
171    eff->running = EINA_TRUE;
172
173    //fake image part
174    evas_object_image_file_set(eff->obj, file, NULL);
175    err = evas_object_image_load_error_get(eff->obj);
176    E_CHECK_GOTO(err == EVAS_LOAD_ERROR_NONE, error);
177
178    evas_object_image_size_get(eff->obj, &(img_w), &(img_h));
179    evas_object_image_fill_set(eff->obj, 0, 0, img_w, img_h);
180    evas_object_image_filled_set(eff->obj, EINA_TRUE);
181
182    evas_object_show(eff->obj);
183
184    res = edje_object_part_swallow
185            (eff->shobj, "fake.swallow.content", eff->obj);
186    E_CHECK_GOTO(res, error);
187
188    if ((eff->rot == 0) || (eff->rot == 180))//portrait mode
189      {
190         evas_object_move(eff->shobj, 0, 0);
191         evas_object_resize(eff->shobj, eff->w, eff->h);
192
193         //get indicator object
194         if (eff->indicator_show)
195           {
196              if (!ecore_evas_extn_plug_connect(eff->indicator_obj, "elm_indicator_portrait", 0, EINA_FALSE))
197                eff->indicator_show = 0;
198           }
199      }
200    else //landscape mode
201      {
202         evas_object_move(eff->shobj, (eff->w - eff->h)/2, (eff->h - eff->w)/2);
203         evas_object_resize(eff->shobj, eff->h, eff->w);
204
205         //get indicator object
206         if (eff->indicator_show)
207           {
208              if (!ecore_evas_extn_plug_connect(eff->indicator_obj, "elm_indicator_landscape", 0, EINA_FALSE))
209                eff->indicator_show = 0;
210           }
211      }
212
213    if (eff->indicator_show)
214      {
215         evas_object_show(eff->indicator_obj);
216         res = edje_object_part_swallow
217               (eff->shobj, "fake.swallow.indicator", eff->indicator_obj);
218         E_CHECK_GOTO(res, error);
219      }
220
221    // set position of fake launch image
222    if (eff->layer_obj)
223      {
224         evas_object_stack_above(eff->shobj, eff->layer_obj);
225      }
226    else
227      {
228         bottom_appinapp_cw = _appinapp_bottom_win_get(bg_cw);
229
230         if (bottom_appinapp_cw)
231           {
232              EINA_LIST_FOREACH(bottom_appinapp_cw->objs, ll, co)
233                {
234                   if (!co) continue;
235                   evas_object_stack_below(eff->shobj, co->shadow);
236                }
237           }
238         else
239           evas_object_raise(eff->shobj);
240      }
241
242    evas_object_show(eff->shobj);
243
244    if (c->animatable)
245      {
246         switch (eff->rot)
247           {
248            case 90:
249               e_mod_comp_effect_signal_add
250                 (NULL, eff->shobj,
251                 "fake,state,visible,90,on", "fake");
252               break;
253            case 180:
254               e_mod_comp_effect_signal_add
255                 (NULL, eff->shobj,
256                 "fake,state,visible,180,on", "fake");
257               break;
258            case 270:
259               e_mod_comp_effect_signal_add
260                 (NULL, eff->shobj,
261                 "fake,state,visible,270,on", "fake");
262               break;
263            default:
264         e_mod_comp_effect_signal_add
265           (NULL, eff->shobj,
266           "fake,state,visible,on", "fake");
267               break;
268           }
269      }
270    else
271      {
272         switch (eff->rot)
273           {
274            case 90:
275               e_mod_comp_effect_signal_add
276                 (NULL, eff->shobj,
277                 "fake,state,visible,90,on,noeffect", "fake");
278               break;
279            case 180:
280               e_mod_comp_effect_signal_add
281                 (NULL, eff->shobj,
282                 "fake,state,visible,180,on,noeffect", "fake");
283               break;
284            case 270:
285               e_mod_comp_effect_signal_add
286                 (NULL, eff->shobj,
287                 "fake,state,visible,270,on,noeffect", "fake");
288               break;
289            default:
290         e_mod_comp_effect_signal_add
291           (NULL, eff->shobj,
292           "fake,state,visible,on,noeffect", "fake");
293               break;
294           }
295      }
296    eff->timeout = ecore_timer_add(10.0f, _launch_timeout, eff);
297    e_mod_comp_util_screen_input_region_set(EINA_TRUE);
298
299    e_mod_comp_render_queue(c);
300    return EINA_TRUE;
301
302 error:
303    eff->running = EINA_FALSE;
304    if (grabbed)
305      e_mod_comp_util_grab_key_set(EINA_FALSE);
306    return EINA_FALSE;
307 }
308
309 EINTERN Eina_Bool
310 e_mod_comp_effect_image_launch_hide(E_Comp_Effect_Image_Launch *eff)
311 {
312    E_Comp *c = e_mod_comp_util_get();
313    E_CHECK_RETURN(c, 0);
314    E_CHECK_RETURN(eff, 0);
315
316    if (eff->timeout)
317      ecore_timer_del(eff->timeout);
318    eff->timeout = NULL;
319
320    if (c->animatable)
321      {
322         switch (eff->rot)
323           {
324            case 90:
325               e_mod_comp_effect_signal_add
326                 (NULL, eff->shobj,
327                 "fake,state,visible,90,off", "fake");
328               break;
329            case 180:
330               e_mod_comp_effect_signal_add
331                 (NULL, eff->shobj,
332                 "fake,state,visible,180,off", "fake");
333               break;
334            case 270:
335               e_mod_comp_effect_signal_add
336                 (NULL, eff->shobj,
337                 "fake,state,visible,270,off", "fake");
338               break;
339            default:
340      e_mod_comp_effect_signal_add
341        (NULL, eff->shobj,
342        "fake,state,visible,off", "fake");
343               break;
344           }
345      }
346    else
347      e_mod_comp_effect_signal_add
348        (NULL, eff->shobj,
349        "fake,state,visible,off,noeffect", "fake");
350
351    e_mod_comp_render_queue(c);
352    return EINA_TRUE;
353 }
354
355 EINTERN Eina_Bool
356 e_mod_comp_effect_image_launch_window_check(E_Comp_Effect_Image_Launch *eff, E_Comp_Win *cw)
357 {
358    E_CHECK_RETURN(eff, 0);
359    E_CHECK_RETURN(eff->running, 0);
360    E_CHECK_RETURN(cw, 0);
361    E_CHECK_RETURN(cw->bd, 0);
362
363    if ( REGION_EQUAL_TO_ROOT(cw) && TYPE_NORMAL_CHECK(cw))
364      {
365         return EINA_TRUE;
366      }
367    return EINA_FALSE;
368 }
369
370 EINTERN Eina_Bool
371 e_mod_comp_effect_image_launch_running_check(E_Comp_Effect_Image_Launch *eff)
372 {
373    E_CHECK_RETURN(eff, 0);
374    return eff->running;
375 }
376
377 EINTERN Eina_Bool
378 e_mod_comp_effect_image_launch_fake_show_done_check(E_Comp_Effect_Image_Launch *eff)
379 {
380    E_CHECK_RETURN(eff, 0);
381    return eff->fake_image_show_done;
382 }
383
384 EINTERN Eina_Bool
385 e_mod_comp_effect_image_launch_window_set(E_Comp_Effect_Image_Launch *eff,
386                                           Ecore_X_Window w)
387 {
388    E_CHECK_RETURN(eff, 0);
389    E_CHECK_RETURN(w, 0);
390    eff->win = w;
391    return EINA_TRUE;
392 }
393
394 EINTERN void
395 e_mod_comp_effect_image_launch_disable(E_Comp_Effect_Image_Launch *eff)
396 {
397    E_CHECK(eff);
398    E_CHECK(eff->running);
399
400    eff->running = EINA_FALSE;
401    eff->fake_image_show_done= EINA_FALSE;
402    eff->win = 0;
403
404    e_mod_comp_util_screen_input_region_set(EINA_FALSE);
405    e_mod_comp_util_grab_key_set(EINA_FALSE);
406
407    E_Comp *c = e_mod_comp_util_get();
408    if (c)
409      e_mod_comp_win_shape_input_update(c);
410
411    if (eff->timeout)
412      ecore_timer_del(eff->timeout);
413    eff->timeout = NULL;
414
415    if (eff->indicator_show)
416      {
417         edje_object_part_unswallow(eff->shobj, eff->indicator_obj);
418         evas_object_hide(eff->indicator_obj);
419      }
420    edje_object_part_unswallow(eff->shobj, eff->obj);
421
422    evas_object_hide(eff->shobj);
423    evas_object_hide(eff->obj);
424 }
425
426 static E_Comp_Win *
427 _appinapp_bottom_win_get(E_Comp_Win *normal_top)
428 {
429    E_Comp *c = e_mod_comp_util_get();
430    E_Comp_Win *cw = NULL;
431    E_Comp_Win *_cw = NULL;
432    E_CHECK_RETURN(c, 0);
433    Ecore_X_Window win = 0;
434
435    if (normal_top)
436      win = normal_top->win;
437
438    EINA_INLIST_REVERSE_FOREACH(c->wins, cw)
439      {
440         if((cw->win) == (win)) break;
441         if (!(cw->bd)) continue;
442
443         if(cw->bd->client.illume.win_state.state == ECORE_X_ILLUME_WINDOW_STATE_FLOATING)
444           _cw = cw;
445      }
446    return _cw;
447 }
448
449 static void
450 _show_done(void *data,
451            Evas_Object *obj __UNUSED__,
452            const char *emission __UNUSED__,
453            const char *source __UNUSED__)
454 {
455    E_Comp_Win *cw;
456    E_Comp_Effect_Image_Launch *eff;
457    eff = (E_Comp_Effect_Image_Launch *)data;
458    E_CHECK(eff);
459
460    eff->fake_image_show_done = EINA_TRUE;
461
462    E_CHECK(eff->win);
463
464    cw = e_mod_comp_win_find(eff->win);
465    E_CHECK(cw);
466
467    e_mod_comp_effect_signal_add
468      (cw, NULL, "e,state,visible,on,noeffect", "e");
469    e_mod_comp_comp_event_src_visibility_send(cw);
470    e_mod_comp_effect_image_launch_disable(eff);
471
472    e_mod_comp_win_render_queue(cw);
473 }
474
475 static void
476 _hide_done(void *data,
477            Evas_Object *obj __UNUSED__,
478            const char *emission __UNUSED__,
479            const char *source __UNUSED__)
480 {
481    E_Comp_Effect_Image_Launch *eff;
482    eff = (E_Comp_Effect_Image_Launch *)data;
483    E_CHECK(eff);
484
485    e_mod_comp_util_screen_input_region_set(EINA_FALSE);
486    e_mod_comp_util_grab_key_set(EINA_FALSE);
487
488    if (eff->indicator_show)
489      {
490         edje_object_part_unswallow(eff->shobj, eff->indicator_obj);
491         evas_object_hide(eff->indicator_obj);
492      }
493    edje_object_part_unswallow(eff->shobj, eff->obj);
494    evas_object_hide(eff->shobj);
495    evas_object_hide(eff->obj);
496 }
497
498 static Eina_Bool
499 _launch_timeout(void *data)
500 {
501    E_Comp_Effect_Image_Launch *eff;
502    E_Comp *c = e_mod_comp_util_get();
503    eff = (E_Comp_Effect_Image_Launch *)data;
504
505    E_CHECK_RETURN(c, 0);
506    E_CHECK_RETURN(eff, 0);
507
508    if (eff->timeout)
509      ecore_timer_del(eff->timeout);
510    eff->timeout = NULL;
511
512    eff->running = EINA_FALSE;
513    eff->win = 0;
514    eff->fake_image_show_done = EINA_FALSE;
515
516    if (c->animatable)
517      {
518         switch (eff->rot)
519           {
520            case 90:
521               e_mod_comp_effect_signal_add
522                 (NULL, eff->shobj,
523                 "fake,state,visible,90,off", "fake");
524               break;
525            case 180:
526               e_mod_comp_effect_signal_add
527                 (NULL, eff->shobj,
528                 "fake,state,visible,180,off", "fake");
529               break;
530            case 270:
531               e_mod_comp_effect_signal_add
532                 (NULL, eff->shobj,
533                 "fake,state,visible,270,off", "fake");
534               break;
535            default:
536      e_mod_comp_effect_signal_add
537        (NULL, eff->shobj,
538        "fake,state,visible,off", "fake");
539               break;
540           }
541      }
542    else
543      e_mod_comp_effect_signal_add
544        (NULL, eff->shobj,
545        "fake,state,visible,off,noeffect", "fake");
546
547    e_mod_comp_render_queue(c);
548
549    return EINA_FALSE;
550 }