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