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