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