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