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