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