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