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