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