fixed problem with killinkg of Flash
[livewp] / applet / src / livewp-scene.c
1 /* vim: set sw=4 ts=4 et: */
2 /*
3  * This file is part of Live Wallpaper (livewp)
4  * 
5  * Copyright (C) 2010 Vlad Vasiliev
6  * Copyright (C) 2010 Tanya Makova
7  *       for the code
8  * 
9  * This software is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2 of
12  * the License, or (at your option) any later version.
13  * 
14  * This software is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  * 
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this software; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22  * 02110-1301 USA
23 */
24 /*******************************************************************************/
25 #include "livewp-scene.h" 
26 /* This code form X11-utils */
27 Window Window_With_Name( Display *dpy, Window top, char *name)
28 {
29         Window *children, dummy;
30         unsigned int nchildren;
31         int i;
32         Window w=0;
33         char *window_name;
34
35     XClassHint *class_hint;
36     class_hint = XAllocClassHint();
37     XGetClassHint(dpy, top, class_hint);
38     if (class_hint->res_name && name && !strcmp(class_hint->res_name, name)){
39       XFree(class_hint->res_class);
40       XFree(class_hint->res_name);
41       return(top);
42     }
43     XFree(class_hint->res_class);
44     XFree(class_hint->res_name);
45
46         if (XFetchName(dpy, top, &window_name) && !strcmp(window_name, name))
47           return(top);
48
49         if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren))
50           return(0);
51
52         for (i=0; i<nchildren; i++) {
53                 w = Window_With_Name(dpy, children[i], name);
54                 if (w)
55                   break;
56         }
57         if (children) XFree ((char *)children);
58         return(w);
59 }
60
61 /*******************************************************************************/
62
63 void 
64 destroy_scene(AWallpaperPlugin *desktop_plugin)
65 {
66     int status = 0;
67      
68     if (desktop_plugin->priv->scene){
69             GSList * tmp = desktop_plugin->priv->scene->actors;
70             while (tmp != NULL){
71                     destroy_actor(tmp->data);
72                     tmp = g_slist_next(tmp);
73             }
74             if (tmp)
75                     g_slist_free(tmp);
76             desktop_plugin->priv->scene->actors = NULL;
77             if (desktop_plugin->priv->scene){
78                     g_free(desktop_plugin->priv->scene);
79                     desktop_plugin->priv->scene = NULL;
80             }
81     }
82     if (desktop_plugin->priv->pipeline){
83         gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_NULL);
84         gst_object_unref (GST_OBJECT (desktop_plugin->priv->pipeline));
85         desktop_plugin->priv->pipeline = NULL;
86     }
87     if (desktop_plugin->priv->podpid > 1){
88         kill (desktop_plugin->priv->podpid, SIGTERM);
89         /* Hack for Flash */
90         if (!strcmp(desktop_plugin->priv->theme,"Flash")){
91             sleep(1);
92             kill (desktop_plugin->priv->podpid, SIGKILL);
93         }
94         while (TRUE){
95             if (wait(&status) == desktop_plugin->priv->podpid) 
96                 break;
97         } 
98         desktop_plugin->priv->podpid = -1;
99         desktop_plugin->priv->running = FALSE;
100     }
101 }
102 /*******************************************************************************/
103 void
104 reload_scene(AWallpaperPlugin *desktop_plugin)
105 {
106     fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme); 
107     destroy_scene(desktop_plugin);
108     fill_priv(desktop_plugin->priv);
109     gtk_widget_destroy(desktop_plugin->priv->window); 
110     if (desktop_plugin->priv->one_in_all_view && desktop_plugin->priv->view >1)
111         exit(-1);   
112     create_xwindow(desktop_plugin->priv);
113     init_scene_theme(desktop_plugin);
114 }
115 /*******************************************************************************/
116 void 
117 init_scene_Accel(AWallpaperPlugin *desktop_plugin)
118 {
119     Actor *actor;
120     Scene *scene;
121     GPtrArray *child;
122     gint now = time(NULL);
123     gchar *str;
124     gchar *bgfile = NULL;
125     gint sizes1[4] = {57, 76, 43, 50},
126          n, j;
127     
128     /* fprintf(stderr, "init scene accel\n"); */
129     scene = g_new0(Scene, 1);
130     scene->actors = NULL;
131     desktop_plugin->priv->scene = scene;
132     
133     bgfile = g_strdup_printf("/home/user/.backgrounds/background-%i.png", desktop_plugin->priv->view);
134     actor = init_object(desktop_plugin, "original", bgfile, 
135                       0, 0, 0, 800, 480, 
136                       TRUE, TRUE, 100, 255, 
137                       NULL, NULL, NULL);
138     scene->actors = g_slist_append(scene->actors, actor);
139
140     child = g_ptr_array_sized_new(16);
141     
142     for (j= 0; j<4; j++){
143         for (n=0; n<4; n++){
144             str = g_strdup_printf("tape%i.png", n+1);
145             actor = init_object(desktop_plugin, "tape", str,
146                                 fast_rnd(800), fast_rnd(480), 2+fast_rnd(6), 800, sizes1[n],
147                                 TRUE, TRUE, 100, 255,
148                                 NULL, NULL, NULL);
149             scene->actors = g_slist_append(scene->actors, actor);
150             g_ptr_array_add(child, actor);
151             g_free(str);
152         }
153     }
154     actor = init_object(desktop_plugin, "tape", "", 
155                       0, 800, 5, 800, 170, 
156                       FALSE, FALSE, 100, 255, 
157                       (gpointer)&change_tape, NULL, child);
158     actor->time_start_animation = now;
159     actor->duration_animation = G_MAXINT;
160     scene->actors = g_slist_append(scene->actors, actor);
161
162     run_long_timeout(desktop_plugin);
163 }
164 /*******************************************************************************/
165 void  
166 parsestring(char *line, char **argv)
167 {
168    while (*line != '\0') {  
169           while (*line == ' ' || *line == '\n')
170                 *line++ = '\0';     /* replace white spaces with 0    */
171                  *argv++ = line;          /* save the argument position     */
172                  while (*line != '\0' && *line != ' ' && 
173                         *line != '\n') 
174                      line++;             /* skip the argument until ...    */
175    }
176                   *argv = '\0';                 /* mark the end of argument list  */
177 }
178
179 #if 0
180 GstBusSyncReply 
181 sync_handler(GstBus *bus, GstMessage *message, AWallpaperPlugin *desktop_plugin){
182
183     if (!desktop_plugin->priv->visible)
184         gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PAUSED);
185     if (GST_MESSAGE_TYPE(message) != GST_MESSAGE_ELEMENT){
186                 return (GST_BUS_PASS);
187         }
188     if (!gst_structure_has_name(message->structure, "prepare-xwindow-id")){
189         return (GST_BUS_PASS);
190     }
191     return (GST_BUS_DROP);
192
193 }
194 #endif
195 /*******************************************************************************/
196 static gboolean
197 bus_call (GstBus *bus, GstMessage *msg, AWallpaperPlugin *desktop_plugin)
198 {
199     switch (GST_MESSAGE_TYPE (msg))
200     {
201        case GST_MESSAGE_EOS: 
202            if (desktop_plugin->priv->rich_animation){
203
204                 GstClockTime nach   = (GstClockTime)(0 * GST_MSECOND);
205                 if (!gst_element_seek(desktop_plugin->priv->pipeline, 1.0, GST_FORMAT_TIME,
206                    (GstSeekFlags) (GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT), GST_SEEK_TYPE_SET, 
207                    nach, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
208                     fprintf(stderr,"ERROR in seek\n");
209
210                 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
211
212            }else{
213                 if (desktop_plugin->priv->pipeline){
214                     gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_NULL);
215                     gst_object_unref (GST_OBJECT (desktop_plugin->priv->pipeline));
216                 } 
217            }
218            break;
219        case GST_MESSAGE_ERROR: break;
220        default: break;
221      }
222        return TRUE;
223 }
224
225 /*******************************************************************************/
226 void
227 init_scene_External(AWallpaperPlugin *desktop_plugin){
228
229     char* child_argv[2048];
230     char *run_string = NULL;
231     gchar *exec_path = NULL,
232         *window_id = NULL,
233         *window_name = NULL,
234         *view = NULL,
235         *gtk_socket_id = NULL,
236         *strwin = NULL,
237         *strsocket = NULL,
238         *addedstring = NULL,
239         *theme_string_parametr1 = NULL,
240         *straddedstring = NULL,
241         *strview = NULL;
242     gint i;
243     Window  id_xwindow;
244     if (!desktop_plugin->priv->visible)
245         return;
246     
247     exec_path = g_strdup(g_hash_table_lookup(desktop_plugin->priv->hash_theme, "exec_path"));
248     window_id = g_strdup(g_hash_table_lookup(desktop_plugin->priv->hash_theme, "window_id"));
249     view = g_strdup(g_hash_table_lookup(desktop_plugin->priv->hash_theme, "view"));
250     window_name = g_strdup(g_hash_table_lookup(desktop_plugin->priv->hash_theme, "window_name"));
251     gtk_socket_id =  g_strdup(g_hash_table_lookup(desktop_plugin->priv->hash_theme, "gtk_socket_id"));
252     addedstring =  g_strdup(g_hash_table_lookup(desktop_plugin->priv->hash_theme, "added_string"));
253     if (!exec_path) 
254         return;
255     if (window_id){
256         strwin = g_strdup_printf(" %s %i", window_id, (gint)GDK_WINDOW_XID(desktop_plugin->priv->window->window));
257     }else
258         strwin = "";
259     if (gtk_socket_id){
260         strsocket = g_strdup_printf(" %s %i", gtk_socket_id, (int)gtk_socket_get_id (GTK_SOCKET (desktop_plugin->priv->video_socket)));
261     }else
262         strsocket = "";
263
264     if (view){
265         strview = g_strdup_printf(" %s %i", view, desktop_plugin->priv->view);
266     }else
267         strview = "";
268
269     if (addedstring){
270         straddedstring = g_strdup_printf(" %s", addedstring);
271     }else
272         straddedstring = "";
273
274     if (desktop_plugin->priv->theme_string_parametr1){
275         theme_string_parametr1 = g_strdup_printf(" %s", desktop_plugin->priv->theme_string_parametr1);
276     }else
277         theme_string_parametr1 = "";
278
279     run_string = g_strdup_printf("%s%s%s%s%s%s", exec_path, strwin, strview, strsocket, straddedstring, theme_string_parametr1);
280     fprintf(stderr, "runs string = %s\n", run_string);
281     parsestring(run_string, child_argv);
282
283     desktop_plugin->priv->running = TRUE;
284     desktop_plugin->priv->podpid = fork();
285     if (desktop_plugin->priv->podpid == 0){
286         execvp(child_argv[0], child_argv);
287         fprintf(stderr,"Problem with new podprocess");
288     }
289     g_free(run_string);
290
291     fprintf(stderr, "window name = %s\n", window_name);
292     if (window_name){
293         /* Do 10 trying to search of window */
294         for (i=0; i<10; i++){
295             sleep(1);
296             id_xwindow = Window_With_Name(GDK_WINDOW_XDISPLAY (desktop_plugin->priv->window->window), 
297                 RootWindow( GDK_WINDOW_XDISPLAY (desktop_plugin->priv->window->window), XDefaultScreen( GDK_WINDOW_XDISPLAY (desktop_plugin->priv->window->window))),
298                 window_name);
299             fprintf(stderr,"name %s %i %i\n", window_name, id_xwindow, i);
300             if (id_xwindow>0){
301                 if (desktop_plugin->priv->one_in_all_view)
302                     set_live_bg (GDK_WINDOW_XDISPLAY (desktop_plugin->priv->window->window), 
303                                                       id_xwindow, -1);
304                 else
305                     set_live_bg (GDK_WINDOW_XDISPLAY (desktop_plugin->priv->window->window),  
306                                                       id_xwindow, desktop_plugin->priv->view);
307                 /* gtk_widget_destroy(desktop_plugin->priv->window); */
308                 break;
309             }
310         }
311     }
312 }
313 /*******************************************************************************/
314 gboolean 
315 cb_timeout0(AWallpaperPlugin *desktop_plugin) {
316
317     if (!desktop_plugin || !desktop_plugin->priv->pipeline)
318         return FALSE;
319     if (desktop_plugin->priv->theme_int_parametr1 == 0){
320         if (!gst_element_seek((GstElement *)GST_PIPELINE (desktop_plugin->priv->pipeline), 1.0, GST_FORMAT_TIME,
321                                           GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, 
322                                           desktop_plugin->priv->theme_int_parametr1 * GST_SECOND,
323                                           GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
324             fprintf(stderr,"Error in seek:\n");
325         return FALSE;
326     }
327        
328     if (gst_element_get_state (desktop_plugin->priv->pipeline, NULL, NULL, -1) == GST_STATE_CHANGE_FAILURE) 
329         return TRUE;
330     else{
331          if (!gst_element_seek((GstElement *)GST_PIPELINE (desktop_plugin->priv->pipeline), 1.0, GST_FORMAT_TIME,
332                                           GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, 
333                                           desktop_plugin->priv->theme_int_parametr1 * GST_SECOND,
334                                           GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
335             fprintf(stderr,"Error in seek:\n");
336          return FALSE;
337     }
338
339 /*******************************************************************************/
340 void
341 init_scene_Video(AWallpaperPlugin *desktop_plugin)
342 {
343     GstElement *bin;                                                                                                                                                           
344     GstElement *videosink;                                                                                                
345     gchar *file_plus_uri;
346
347
348     /* fprintf(stderr, "init scene Video \n"); */
349     desktop_plugin->priv->pipeline = gst_pipeline_new("gst-player");
350     bin = gst_element_factory_make ("playbin2", "bin");
351     videosink = gst_element_factory_make ("ximagesink", "videosink");
352     g_object_set (G_OBJECT (bin), "video-sink", videosink, NULL);
353     gst_bin_add (GST_BIN (desktop_plugin->priv->pipeline), bin);
354
355     {
356         GstBus *bus;
357         bus = gst_pipeline_get_bus (GST_PIPELINE (desktop_plugin->priv->pipeline));
358         gst_bus_add_watch(bus, (GstBusFunc)bus_call, desktop_plugin);
359         gst_object_unref (bus);
360     }
361     file_plus_uri = g_strdup_printf("file://%s",desktop_plugin->priv->theme_string_parametr1);
362     g_object_set (G_OBJECT (bin), "uri", file_plus_uri, NULL );
363 #if 0
364     /* Doesn't work in real device. Hardware volume buttons can to change volume for mutted track */
365     /* Set Mute */
366     if (!desktop_plugin->priv->theme_bool_parametr1)
367         g_object_set (G_OBJECT (bin), "mute", TRUE, NULL );
368 #endif
369     g_object_set (G_OBJECT (videosink), "force-aspect-ratio", TRUE, NULL  );
370
371     if (GST_IS_X_OVERLAY (videosink))
372             gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (videosink), GDK_DRAWABLE_XID(desktop_plugin->priv->window->window));
373
374     if (desktop_plugin->priv->visible){
375         g_timeout_add(50, (GSourceFunc)cb_timeout0, desktop_plugin); 
376         gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
377     }
378    
379     //gst_element_get_state(deskddtop_plugin->priv->pipeline, NULL, NULL, 100 * GST_MSECOND);
380
381 }
382 /*******************************************************************************/
383 void
384 init_scene_Matrix(AWallpaperPlugin *desktop_plugin)
385 {
386   Actor *actor;
387   Scene *scene;
388   GPtrArray *child;
389   gint now = time(NULL);
390   gint y1, y2;
391
392   if (desktop_plugin->priv->rich_animation){
393       y1 = -480;
394       y2 = -480-480;
395   }else {
396       y1 = 0;
397       y2 = -480;
398   }
399
400   /* fprintf(stderr, "init scene2 \n"); */
401   scene = g_new0(Scene, 1);
402   //scene.daytime = get_daytime();
403   scene->actors = NULL;
404   desktop_plugin->priv->scene = scene;
405   
406   actor = init_object(desktop_plugin, "background", "bg.png", 
407                       0, 0, 5, 800, 480, 
408                       TRUE, TRUE, 100, 255, 
409                       NULL, NULL, NULL);
410   scene->actors = g_slist_append(scene->actors, actor);
411
412   actor = init_object(desktop_plugin, "symbols", "symbols.png", 
413                       0, 0, 10, 800, 480, 
414                       TRUE, TRUE, 100, 255, 
415                       NULL, NULL, NULL);
416   scene->actors = g_slist_append(scene->actors, actor);
417
418   child = g_ptr_array_sized_new(4);
419   actor = init_object(desktop_plugin, "layer1", "layer1_2.png", 
420                       0, y1, 6, 800, 960, 
421                       TRUE, TRUE, 100, 255, 
422                       NULL, NULL, NULL);
423   //actor->time_start_animation = now;
424   //actor->duration_animation = G_MAXINT;
425   scene->actors = g_slist_append(scene->actors, actor);
426   g_ptr_array_add(child, actor);
427
428   actor = init_object(desktop_plugin, "layer1", "layer1_1.png", 
429                       0, y2, 7, 800, 960, 
430                       TRUE, TRUE, 100, 255, 
431                       NULL, NULL, NULL);
432   //actor->time_start_animation = now;
433   //actor->duration_animation = G_MAXINT;
434   scene->actors = g_slist_append(scene->actors, actor);
435   g_ptr_array_add(child, actor);
436
437   actor = init_object(desktop_plugin, "layer2", "layer2_2.png", 
438                       0, y1, 8, 800, 960, 
439                       TRUE, TRUE, 100, 255, 
440                       NULL, NULL, NULL);
441   //actor->time_start_animation = now;
442   //actor->duration_animation = G_MAXINT;
443   scene->actors = g_slist_append(scene->actors, actor);
444   g_ptr_array_add(child, actor);
445
446   actor = init_object(desktop_plugin, "layer2", "layer2_1.png", 
447                       0, y2, 9, 800, 960, 
448                       TRUE, TRUE, 100, 255, 
449                       NULL, NULL, NULL);
450   //actor->time_start_animation = now;
451   //actor->duration_animation = G_MAXINT;
452   scene->actors = g_slist_append(scene->actors, actor);
453   g_ptr_array_add(child, actor);
454
455   actor = init_object(desktop_plugin, "layers", "", 
456                       0, y2, 9, 800, 960, 
457                       FALSE, FALSE, 100, 255, 
458                       (gpointer)&change_layer, NULL, child);
459   actor->time_start_animation = now;
460   actor->duration_animation = G_MAXINT;
461   scene->actors = g_slist_append(scene->actors, actor);
462
463   run_long_timeout(desktop_plugin);
464
465 }
466 /*******************************************************************************/
467 /* Init Modern Scene */
468 void
469 init_scene_Modern(AWallpaperPlugin *desktop_plugin)
470 {
471   Actor *actor;
472   Scene *scene;
473   gint now = time(NULL);
474   gint i;
475   gint winds[13][2];
476   GPtrArray *child; 
477
478   /* fprintf(stderr, "init scene \n"); */
479   scene = g_new0(Scene, 1);
480   scene->daytime = get_daytime();
481   scene->actors = NULL;
482   scene->wind_orientation = -1;
483   scene->wind_angle = 0.3;
484   /* init value for random */
485   scene->seed = time(NULL);
486   scene->notification = TRUE;
487   desktop_plugin->priv->scene = scene;
488   actor = init_object(desktop_plugin, "sky", "sky0.png", 
489                       0, 0, 5, 800, 480, 
490                       TRUE , TRUE, 100, 255, 
491                       (gpointer)&change_static_actor, NULL, NULL);
492   scene->actors = g_slist_append(scene->actors, actor);
493   change_static_actor(actor, desktop_plugin);
494   
495   actor = init_object(desktop_plugin, "sun", "sun.png", 
496                       0, 0, 6, 88, 88, 
497                       FALSE, FALSE, 100, 255, 
498                       (gpointer)&change_sun, NULL, NULL);
499   actor->time_start_animation = now;
500   actor->duration_animation = G_MAXINT;
501   change_sun(actor, desktop_plugin);
502   scene->actors = g_slist_append(scene->actors, actor);
503
504   //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50, 
505     //                  TRUE, 100, 255, NULL, NULL);
506   //scene.actors = g_slist_append(scene.actors, actor);
507   
508   actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 
509                       0, fast_rnd(300)-97, 7, 150, 97, 
510                       FALSE, FALSE, 100, 255, 
511                       (gpointer)&change_cloud, NULL, NULL);
512   actor->time_start_animation = now + fast_rnd(20);
513   actor->duration_animation = 3*60;
514   scene->actors = g_slist_append(scene->actors, actor);
515   
516   actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 
517                       0, fast_rnd(300)-75, 7, 188, 75, 
518                       FALSE, FALSE, 100, 255, 
519                       (gpointer)&change_cloud, NULL, NULL);
520   actor->time_start_animation = now + fast_rnd(40)+10;
521   actor->duration_animation = 3*60;
522   scene->actors = g_slist_append(scene->actors, actor);
523
524   actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 
525                       0, fast_rnd(300)-75, 7, 150, 75, 
526                       FALSE, FALSE, 100, 255, 
527                       (gpointer)&change_cloud, NULL, NULL);
528   actor->time_start_animation = now + fast_rnd(60) + 20;
529   actor->duration_animation = 5*60;
530   scene->actors = g_slist_append(scene->actors, actor);
531
532
533   actor = init_object(desktop_plugin, "town", "town0.png", 
534                       0, 0, 8, 800, 480, 
535                       TRUE, TRUE, 100, 255, 
536                       (gpointer)&change_static_actor, NULL, NULL);
537   change_static_actor(actor, desktop_plugin);
538   scene->actors = g_slist_append(scene->actors, actor);
539
540   actor = init_object(desktop_plugin, "stend", "stend0.png", 
541                       452, 166, 9, 300, 305, 
542                       TRUE, TRUE, 100, 255, 
543                       (gpointer)&change_static_actor, NULL, NULL);
544   change_static_actor(actor, desktop_plugin);
545   scene->actors = g_slist_append(scene->actors, actor);
546
547
548   child = g_ptr_array_sized_new(4);
549   actor = init_object(desktop_plugin, "call", "call.png", 
550                       480, 190, 9, 50, 58, 
551                       FALSE, TRUE, 100, 255, 
552                       NULL, NULL, NULL);
553   scene->actors = g_slist_append(scene->actors, actor);
554   g_ptr_array_add(child, actor);
555
556   actor = init_object(desktop_plugin, "chat", "chat.png", 
557                       540, 190, 9, 50, 58, 
558                       FALSE, TRUE, 100, 255, 
559                       NULL, NULL, NULL);
560   scene->actors = g_slist_append(scene->actors, actor);
561   g_ptr_array_add(child, actor);
562
563   actor = init_object(desktop_plugin, "mail", "mail.png", 
564                       600, 190, 9, 50, 58, 
565                       FALSE, TRUE, 100, 255, 
566                       NULL, NULL, NULL);
567   scene->actors = g_slist_append(scene->actors, actor);
568   g_ptr_array_add(child, actor);
569   
570   actor = init_object(desktop_plugin, "sms", "sms.png", 
571                       660, 190, 9, 50, 58, 
572                       FALSE, TRUE, 100, 255, 
573                       NULL, NULL, NULL);
574   scene->actors = g_slist_append(scene->actors, actor);
575   g_ptr_array_add(child, actor);
576
577   actor = init_object(desktop_plugin, "billboard_text", "",
578                       470, 174, 9, 300, 108,
579                       FALSE, FALSE, 100, 255,
580                       (gpointer)&change_billboard, NULL, child);
581   create_hildon_actor_text(actor, desktop_plugin);
582   //actor->time_start_animation = time(NULL) + 20;
583   change_billboard(actor, desktop_plugin);
584   scene->actors = g_slist_append(scene->actors, actor);
585
586   actor = init_object(desktop_plugin, "tram", "tram.png", 
587                       -300, 225, 10, 350, 210, 
588                       FALSE, FALSE, 100, 255, 
589                       (gpointer)&change_tram, NULL, NULL);
590   actor->time_start_animation = time(NULL) + fast_rnd(10); 
591   actor->duration_animation = 60;
592   scene->actors = g_slist_append(scene->actors, actor);
593
594   actor = init_object(desktop_plugin, "border", "border0.png", 
595                       0, 480-79, 11, 800, 79,
596                       TRUE, TRUE, 100, 255, 
597                       (gpointer)&change_static_actor_with_corner, NULL, NULL);
598   change_static_actor_with_corner(actor, desktop_plugin);
599   scene->actors = g_slist_append(scene->actors, actor);
600   
601   actor = init_object(desktop_plugin, "moon", "moon1.png", 
602                       400, 20, 6, 60, 60, 
603                       FALSE, FALSE, 100, 255, 
604                       (gpointer)&change_moon, NULL, NULL);
605   change_moon(actor, desktop_plugin);
606   scene->actors = g_slist_append(scene->actors, actor);
607
608   actor = init_object(desktop_plugin, "wind", "", 
609                       0, 0, 5, 0, 0, 
610                       FALSE, FALSE, 100, 255, 
611                       (gpointer)&change_wind, NULL, NULL);
612   change_wind(actor, desktop_plugin);
613   scene->actors = g_slist_append(scene->actors, actor);
614
615     /* windows in 4-th house  */
616
617     winds[0][0] = 482;
618     winds[0][1] = 180;
619
620     winds[1][0] = 495;
621     winds[1][1] = 179;
622
623     winds[2][0] = 482;
624     winds[2][1] = 191;
625
626     winds[3][0] = 495;
627     winds[3][1] = 190;
628     
629     winds[4][0] = 482;
630     winds[4][1] = 201;
631     
632     winds[5][0] = 495;
633     winds[5][1] = 210;
634     
635     winds[6][0] = 482;
636     winds[6][1] = 222;
637     
638     winds[7][0] = 495;
639     winds[7][1] = 221;
640     
641     winds[8][0] = 459;
642     winds[8][1] = 203;
643     
644     winds[9][0] = 495;
645     winds[9][1] = 241;
646     
647     winds[10][0] = 495;
648     winds[10][1] = 252;
649     
650     winds[11][0] = 482;
651     winds[11][1] = 273;
652     
653     winds[12][0] = 495;
654     winds[12][1] = 303;
655     for (i=0; i<13; i++){
656         actor = init_object(desktop_plugin, "window1", "window1.png", 
657                             winds[i][0], winds[i][1], 8, 8, 10, 
658                             FALSE, FALSE, 100, 255, 
659                             (gpointer)&change_window1, NULL, NULL);
660         //change_window1(actor, desktop_plugin);
661         actor->time_start_animation = now + fast_rnd(30);
662         scene->actors = g_slist_append(scene->actors, actor);
663
664     }
665     
666     /* windows in 1-th house  */
667     
668     winds[0][0] = 86;
669     winds[0][1] = 321;
670
671     winds[1][0] = 86;
672     winds[1][1] = 363;
673
674     winds[2][0] = 86;
675     winds[2][1] = 385;
676
677     winds[3][0] = 86;
678     winds[3][1] = 286;
679     
680     winds[4][0] = 94;
681     winds[4][1] = 232;
682     
683     winds[5][0] = 94;
684     winds[5][1] = 243;
685     
686     winds[6][0] = 94;
687     winds[6][1] = 265;
688     
689     winds[7][0] = 94;
690     winds[7][1] = 331;
691     for (i=0; i<8; i++){
692         actor = init_object(desktop_plugin, "window2", "window2.png", 
693                             winds[i][0], winds[i][1], 8, 8, 10, 
694                             FALSE, FALSE, 100, 255, 
695                             (gpointer)&change_window1, NULL, NULL);
696         //change_window1(actor, desktop_plugin);
697         actor->time_start_animation = now + fast_rnd(30);
698         scene->actors = g_slist_append(scene->actors, actor);
699
700     }
701     
702     /* windows in 3-th house  */
703     
704     winds[0][0] = 251;
705     winds[0][1] = 162;
706
707     winds[1][0] = 251;
708     winds[1][1] = 196;
709
710     winds[2][0] = 251;
711     winds[2][1] = 278;
712
713     winds[3][0] = 251;
714     winds[3][1] = 289;
715     
716     winds[4][0] = 313;
717     winds[4][1] = 173;
718     
719     winds[5][0] = 322;
720     winds[5][1] = 160;
721     
722     winds[6][0] = 303;
723     winds[6][1] = 217;
724     
725     winds[7][0] = 322;
726     winds[7][1] = 224;
727     
728     winds[8][0] = 323;
729     winds[8][1] = 217;
730     
731     winds[9][0] = 322;
732     winds[9][1] = 288;
733     
734     for (i=0; i<10; i++){
735         actor = init_object(desktop_plugin, "window3", "window3.png", 
736                             winds[i][0], winds[i][1], 8, 8, 10, 
737                             FALSE, FALSE, 100, 255, 
738                             (gpointer)&change_window1, NULL, NULL);
739         //change_window1(actor, desktop_plugin);
740         actor->time_start_animation = now + fast_rnd(30);
741         scene->actors = g_slist_append(scene->actors, actor);
742
743     }
744
745     /* windows in 5-th house  */
746     
747     winds[0][0] = 610;
748     winds[0][1] = 224;
749
750     winds[1][0] = 602;
751     winds[1][1] = 245;
752
753     winds[2][0] = 602;
754     winds[2][1] = 264;
755
756     winds[3][0] = 610;
757     winds[3][1] = 301;
758     
759     winds[4][0] = 610;
760     winds[4][1] = 320;
761     
762     winds[5][0] = 593;
763     winds[5][1] = 352;
764     
765     winds[6][0] = 610;
766     winds[6][1] = 368;
767     
768     for (i=0; i<7; i++){
769         actor = init_object(desktop_plugin, "window4", "window4.png", 
770                             winds[i][0], winds[i][1], 8, 8, 10, 
771                             FALSE, FALSE, 100, 255, 
772                             (gpointer)&change_window1, NULL, NULL);
773         //change_window1(actor, desktop_plugin);
774         actor->time_start_animation = now + fast_rnd(30);
775         scene->actors = g_slist_append(scene->actors, actor);
776
777     }
778
779     /* windows in 6-th house  */
780     
781     winds[0][0] = 717;
782     winds[0][1] = 283;
783
784     winds[1][0] = 698;
785     winds[1][1] = 293;
786
787     winds[2][0] = 717;
788     winds[2][1] = 315;
789
790     winds[3][0] = 717;
791     winds[3][1] = 323;
792     
793     winds[4][0] = 698;
794     winds[4][1] = 362;
795     
796     winds[5][0] = 698;
797     winds[5][1] = 400;
798     
799     for (i=0; i<6; i++){
800         actor = init_object(desktop_plugin, "window5", "window5.png", 
801                             winds[i][0], winds[i][1], 8, 8, 10, 
802                             FALSE, FALSE, 100, 255, 
803                             (gpointer)&change_window1, NULL, NULL);
804         //change_window1(actor, desktop_plugin);
805         actor->time_start_animation = now + fast_rnd(30);
806         scene->actors = g_slist_append(scene->actors, actor);
807
808     }
809     run_long_timeout(desktop_plugin);
810
811 #if 0    
812   anim = g_new0(Animation, 1);
813   anim->count = 1;
814   anim->actor = actor;
815   anim->func_change = &change_tram;
816   anim->func_time = NULL;
817   anim->timestart = time(NULL); 
818   anim->timeall = 10;
819   
820   scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
821 #endif  
822 }
823 /*******************************************************************************/
824 /* Init Berlin Scene */
825 void
826 init_scene_Berlin(AWallpaperPlugin *desktop_plugin)
827 {
828   Actor *actor, *actor1, *actor2;
829   Scene *scene;
830   gint now = time(NULL);
831   gint i; 
832   gint winds[13][2];
833   GPtrArray *child = NULL;
834
835   scene = g_new0(Scene, 1);
836   scene->daytime = get_daytime();
837   scene->actors = NULL;
838   scene->wind_orientation = -1;
839   scene->wind_angle = 0.3;
840   /* init value for random */
841   scene->seed = time(NULL);
842   desktop_plugin->priv->scene = scene;
843   
844   actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480, 
845                       TRUE, TRUE, 100, 255, 
846                       (gpointer)&change_static_actor, NULL, NULL);
847   change_static_actor(actor, desktop_plugin);
848   scene->actors = g_slist_append(scene->actors, actor);
849
850   
851   actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88, 
852                       FALSE, FALSE, 100, 255, 
853                       (gpointer)&change_sun, NULL, NULL);
854   actor->time_start_animation = time(NULL);
855   actor->duration_animation = G_MAXINT;
856   change_sun(actor, desktop_plugin);
857   scene->actors = g_slist_append(scene->actors, actor);
858
859 #if 0
860   actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50, 
861                       TRUE, 100, 255, NULL, NULL);
862   scene.actors = g_slist_append(scene.actors, actor);
863 #endif
864
865   actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60, 
866                       FALSE, FALSE, 100, 255, 
867                       (gpointer)&change_moon, NULL, NULL);
868   change_moon(actor, desktop_plugin);
869   scene->actors = g_slist_append(scene->actors, actor);
870   
871   actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97, 
872                       FALSE, FALSE, 100, 255, 
873                       (gpointer)&change_cloud, NULL, NULL);
874   actor->time_start_animation = now + fast_rnd(30) + 10;
875   actor->duration_animation = 3*60;
876   scene->actors = g_slist_append(scene->actors, actor);
877   
878   actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75, 
879                       FALSE, FALSE, 100, 255, 
880                       (gpointer)&change_cloud, NULL, NULL);
881   actor->time_start_animation = now + fast_rnd(10);
882   actor->duration_animation = 3*60;
883   scene->actors = g_slist_append(scene->actors, actor);
884
885   actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75, 
886                       FALSE, FALSE, 100, 255, 
887                       (gpointer)&change_cloud, NULL, NULL);
888   actor->time_start_animation = now + fast_rnd(60) + 20;
889   actor->duration_animation = 5*60;
890   scene->actors = g_slist_append(scene->actors, actor);
891
892  
893   actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50, 
894                       FALSE, FALSE, 100, 255, 
895                       (gpointer)&change_plane2, NULL, NULL);
896   actor->time_start_animation = now + fast_rnd(40) + 20;
897   actor->duration_animation = 60;
898   scene->actors = g_slist_append(scene->actors, actor);
899   
900   actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116, 
901                       FALSE, FALSE, 100, 255, 
902                       (gpointer)&change_plane1, NULL, NULL);
903   actor->time_start_animation = now + fast_rnd(20);
904   actor->duration_animation = 30;
905   scene->actors = g_slist_append(scene->actors, actor);
906
907   actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480, 
908                       TRUE, TRUE, 100, 255, 
909                       (gpointer)&change_static_actor_with_corner, NULL, NULL);
910   change_static_actor_with_corner(actor, desktop_plugin);
911   scene->actors = g_slist_append(scene->actors, actor);
912
913   actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0, 
914                       FALSE, FALSE, 100, 255, 
915                       (gpointer)&change_wind, NULL, NULL);
916   change_wind(actor, desktop_plugin);
917   scene->actors = g_slist_append(scene->actors, actor);
918
919   actor1 = init_object(desktop_plugin, "signal_red", "red.png", 
920                       486, 425, 10, 18, 38, 
921                       FALSE, TRUE, 100, 255, NULL, NULL, NULL);
922   //actor->time_start_animation = now + fast_rnd(30) + 10;  
923   scene->actors = g_slist_append(scene->actors, actor1);
924    
925   actor2 = init_object(desktop_plugin, "signal_green", "green.png", 
926                       486, 425, 10, 18, 38, 
927                       TRUE, TRUE, 100, 255, NULL, NULL, NULL);
928   //actor->time_start_animation = now + fast_rnd(30) + 10;  
929   scene->actors = g_slist_append(scene->actors, actor2);
930   child = g_ptr_array_sized_new(2);
931   g_ptr_array_add(child, actor1);
932   g_ptr_array_add(child, actor2);
933   actor = init_object(desktop_plugin, "signal", "",
934                       486, 425, 10, 18, 38,
935                       FALSE, FALSE, 100, 255, 
936                       (gpointer)&change_signal, NULL, child);
937   actor->time_start_animation = now + fast_rnd(30) + 10;
938   scene->actors = g_slist_append(scene->actors, actor);
939     
940     winds[0][0] = 389;
941     winds[0][1] = 305;
942
943     winds[1][0] = 373;
944     winds[1][1] = 306;
945
946     winds[2][0] = 355;
947     winds[2][1] = 306;
948
949     winds[3][0] = 356;
950     winds[3][1] = 288;
951     
952     winds[4][0] = 337;
953     winds[4][1] = 269;
954     
955     winds[5][0] = 372;
956     winds[5][1] = 268;
957   
958     winds[6][0] = 372;
959     winds[6][1] = 249;
960     
961     winds[7][0] = 388;
962     winds[7][1] = 249;
963     
964     winds[8][0] = 387;
965     winds[8][1] = 230;
966     
967     winds[9][0] = 372;
968     winds[9][1] = 211;
969     
970     winds[10][0] = 355;
971     winds[10][1] = 159;
972     
973     winds[11][0] = 335;
974     winds[11][1] = 158;
975     
976     winds[12][0] = 386;
977     winds[12][1] = 119;
978   
979     for (i=0; i<13; i++){
980         actor = init_object(desktop_plugin, "window", "window.png", 
981                             winds[i][0], winds[i][1], 10, 8, 9, 
982                             FALSE, TRUE, 100, 255, 
983                             (gpointer)&change_window1, NULL, NULL);
984         //change_window1(actor, desktop_plugin);
985         actor->time_start_animation = now + fast_rnd(30);
986         scene->actors = g_slist_append(scene->actors, actor);
987
988     }
989     
990     run_long_timeout(desktop_plugin);
991
992 }
993 /*******************************************************************************/
994 void 
995 init_scene_theme(AWallpaperPlugin *desktop_plugin)
996 {
997 #if 0
998     void (*func)(gpointer);
999     func = g_hash_table_lookup(desktop_plugin->priv->hash_scene_func, desktop_plugin->priv->theme);
1000     if (func){
1001         (*func)(desktop_plugin);
1002     }
1003 #endif
1004     fprintf(stderr, "Init_scene_theme\n");
1005     void (*func)(gpointer);
1006     func = desktop_plugin->priv->scene_func;
1007     if (func){
1008         fprintf(stderr, "Success init_scene_theme\n");
1009         (*func)(desktop_plugin);
1010     }
1011 }