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