fixed time to change image, added icons to slideshow and flash, added change image...
[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, 
399                 desktop_plugin->priv->theme_string_parametr1);
400
401         scene = g_new0(Scene, 1);
402         scene->actors = NULL;
403         desktop_plugin->priv->scene = scene;
404
405         dir_fd = opendir(desktop_plugin->priv->theme_string_parametr1);
406         if(dir_fd){
407                 while((dp = readdir(dir_fd))){
408                         if(!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
409                                 continue;
410
411                         ext = strrchr(dp->d_name, '.') + 1; /* get file extension */
412                         if (!ext) continue;
413                         /* lowercase string */
414                         for(i=0; ext[i]; i++)
415                                 ext[i] = tolower(ext[i]);
416                         if (strcmp(ext, "jpg") && strcmp(ext, "png"))
417                                 continue;
418                         if(dp->d_type == DT_REG || dp->d_type == DT_LNK){
419                                 str = g_strdup_printf("%s/%s", desktop_plugin->priv->theme_string_parametr1, dp->d_name);
420                                 store = g_slist_append(store, str);
421                                 num++;
422                         }
423                 }
424                 closedir(dir_fd);
425         }
426
427         child = g_ptr_array_sized_new(num);
428         while (store){
429                 actor = init_object(desktop_plugin, "original", store->data,
430                                 0, 0, 5, 800, 480,
431                                 FALSE, FALSE, 100, 0,
432                                 NULL, NULL, NULL);
433                 scene->actors = g_slist_append(scene->actors, actor);
434                 g_ptr_array_add(child, actor);
435                 store = g_slist_next(store);
436         }
437         actor = init_object(desktop_plugin, "images", "",
438                         0, 0, -1, 800, 480,
439                         FALSE, FALSE, num, -1,
440                         (gpointer)&change_slideshow, NULL, child);
441         actor->time_start_animation = now;
442         actor->duration_animation = 5;
443         scene->actors = g_slist_append(scene->actors, actor);
444         desktop_plugin->priv->rich_animation = TRUE;
445         run_long_timeout(desktop_plugin);
446
447 }
448 /*******************************************************************************/
449 void
450 init_scene_Matrix(AWallpaperPlugin *desktop_plugin)
451 {
452         Actor *actor;
453         Scene *scene;
454         GPtrArray *child;
455         gint now = time(NULL);
456         gint y1, y2;
457
458         if (desktop_plugin->priv->rich_animation){
459                 y1 = -480;
460                 y2 = -480-480;
461         }else {
462                 y1 = 0;
463                 y2 = -480;
464         }
465
466         /* fprintf(stderr, "init scene matrix \n"); */
467         scene = g_new0(Scene, 1);
468         //scene.daytime = get_daytime();
469         scene->actors = NULL;
470         desktop_plugin->priv->scene = scene;
471
472         actor = init_object(desktop_plugin, "background", "bg.png",
473                         0, 0, 5, 800, 480,
474                         TRUE, TRUE, 100, 255,
475                         NULL, NULL, NULL);
476         scene->actors = g_slist_append(scene->actors, actor);
477
478         actor = init_object(desktop_plugin, "symbols", "symbols.png",
479                         0, 0, 10, 800, 480,
480                         TRUE, TRUE, 100, 255,
481                         NULL, NULL, NULL);
482         scene->actors = g_slist_append(scene->actors, actor);
483
484         child = g_ptr_array_sized_new(4);
485         actor = init_object(desktop_plugin, "layer1", "layer1_2.png",
486                         0, y1, 6, 800, 960,
487                         TRUE, TRUE, 100, 255,
488                         NULL, NULL, NULL);
489         //actor->time_start_animation = now;
490         //actor->duration_animation = G_MAXINT;
491         scene->actors = g_slist_append(scene->actors, actor);
492         g_ptr_array_add(child, actor);
493
494         actor = init_object(desktop_plugin, "layer1", "layer1_1.png",
495                         0, y2, 7, 800, 960,
496                         TRUE, TRUE, 100, 255,
497                         NULL, NULL, NULL);
498         //actor->time_start_animation = now;
499         //actor->duration_animation = G_MAXINT;
500         scene->actors = g_slist_append(scene->actors, actor);
501         g_ptr_array_add(child, actor);
502
503         actor = init_object(desktop_plugin, "layer2", "layer2_2.png",
504                         0, y1, 8, 800, 960,
505                         TRUE, TRUE, 100, 255,
506                         NULL, NULL, NULL);
507         //actor->time_start_animation = now;
508         //actor->duration_animation = G_MAXINT;
509         scene->actors = g_slist_append(scene->actors, actor);
510         g_ptr_array_add(child, actor);
511
512         actor = init_object(desktop_plugin, "layer2", "layer2_1.png",
513                         0, y2, 9, 800, 960,
514                         TRUE, TRUE, 100, 255,
515                         NULL, NULL, NULL);
516         //actor->time_start_animation = now;
517         //actor->duration_animation = G_MAXINT;
518         scene->actors = g_slist_append(scene->actors, actor);
519         g_ptr_array_add(child, actor);
520
521         actor = init_object(desktop_plugin, "layers", "",
522                         0, y2, 9, 800, 960,
523                         FALSE, FALSE, 100, 255,
524                         (gpointer)&change_layer, NULL, child);
525         actor->time_start_animation = now;
526         actor->duration_animation = G_MAXINT;
527         scene->actors = g_slist_append(scene->actors, actor);
528
529         run_long_timeout(desktop_plugin);
530
531 }
532 /*******************************************************************************/
533 /* Init Modern Scene */
534 void
535 init_scene_Modern(AWallpaperPlugin *desktop_plugin)
536 {
537   Actor *actor;
538   Scene *scene;
539   gint now = time(NULL);
540   gint i;
541   gint winds[13][2];
542   GPtrArray *child;
543
544   /* fprintf(stderr, "init scene \n"); */
545   scene = g_new0(Scene, 1);
546   scene->daytime = get_daytime();
547   scene->actors = NULL;
548   scene->wind_orientation = -1;
549   scene->wind_angle = 0.3;
550   /* init value for random */
551   scene->seed = time(NULL);
552   scene->notification = TRUE;
553   desktop_plugin->priv->scene = scene;
554   actor = init_object(desktop_plugin, "sky", "sky0.png",
555                       0, 0, 5, 800, 480,
556                       TRUE , TRUE, 100, 255,
557                       (gpointer)&change_static_actor, NULL, NULL);
558   scene->actors = g_slist_append(scene->actors, actor);
559   change_static_actor(actor, desktop_plugin);
560
561   actor = init_object(desktop_plugin, "sun", "sun.png",
562                       0, 0, 6, 88, 88,
563                       FALSE, FALSE, 100, 255,
564                       (gpointer)&change_sun, NULL, NULL);
565   actor->time_start_animation = now;
566   actor->duration_animation = G_MAXINT;
567   change_sun(actor, desktop_plugin);
568   scene->actors = g_slist_append(scene->actors, actor);
569
570   //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
571     //                  TRUE, 100, 255, NULL, NULL);
572   //scene.actors = g_slist_append(scene.actors, actor);
573
574   actor = init_object(desktop_plugin, "cloud1", "cloud1.png",
575                       0, fast_rnd(300)-97, 7, 150, 97,
576                       FALSE, FALSE, 100, 255,
577                       (gpointer)&change_cloud, NULL, NULL);
578   actor->time_start_animation = now + fast_rnd(20);
579   actor->duration_animation = 3*60;
580   scene->actors = g_slist_append(scene->actors, actor);
581
582   actor = init_object(desktop_plugin, "cloud2", "cloud2.png",
583                       0, fast_rnd(300)-75, 7, 188, 75,
584                       FALSE, FALSE, 100, 255,
585                       (gpointer)&change_cloud, NULL, NULL);
586   actor->time_start_animation = now + fast_rnd(40)+10;
587   actor->duration_animation = 3*60;
588   scene->actors = g_slist_append(scene->actors, actor);
589
590   actor = init_object(desktop_plugin, "cloud4", "cloud4.png",
591                       0, fast_rnd(300)-75, 7, 150, 75,
592                       FALSE, FALSE, 100, 255,
593                       (gpointer)&change_cloud, NULL, NULL);
594   actor->time_start_animation = now + fast_rnd(60) + 20;
595   actor->duration_animation = 5*60;
596   scene->actors = g_slist_append(scene->actors, actor);
597
598
599   actor = init_object(desktop_plugin, "town", "town0.png",
600                       0, 0, 8, 800, 480,
601                       TRUE, TRUE, 100, 255,
602                       (gpointer)&change_static_actor, NULL, NULL);
603   change_static_actor(actor, desktop_plugin);
604   scene->actors = g_slist_append(scene->actors, actor);
605
606   actor = init_object(desktop_plugin, "stend", "stend0.png",
607                       452, 166, 9, 300, 305,
608                       TRUE, TRUE, 100, 255,
609                       (gpointer)&change_static_actor, NULL, NULL);
610   change_static_actor(actor, desktop_plugin);
611   scene->actors = g_slist_append(scene->actors, actor);
612
613
614   child = g_ptr_array_sized_new(4);
615   actor = init_object(desktop_plugin, "call", "call.png",
616                       480, 190, 9, 50, 58,
617                       FALSE, TRUE, 100, 255,
618                       NULL, NULL, NULL);
619   scene->actors = g_slist_append(scene->actors, actor);
620   g_ptr_array_add(child, actor);
621
622   actor = init_object(desktop_plugin, "chat", "chat.png",
623                       540, 190, 9, 50, 58,
624                       FALSE, TRUE, 100, 255,
625                       NULL, NULL, NULL);
626   scene->actors = g_slist_append(scene->actors, actor);
627   g_ptr_array_add(child, actor);
628
629   actor = init_object(desktop_plugin, "mail", "mail.png",
630                       600, 190, 9, 50, 58,
631                       FALSE, TRUE, 100, 255,
632                       NULL, NULL, NULL);
633   scene->actors = g_slist_append(scene->actors, actor);
634   g_ptr_array_add(child, actor);
635
636   actor = init_object(desktop_plugin, "sms", "sms.png",
637                       660, 190, 9, 50, 58,
638                       FALSE, TRUE, 100, 255,
639                       NULL, NULL, NULL);
640   scene->actors = g_slist_append(scene->actors, actor);
641   g_ptr_array_add(child, actor);
642
643   actor = init_object(desktop_plugin, "billboard_text", "",
644                       470, 174, 9, 300, 108,
645                       FALSE, FALSE, 100, 255,
646                       (gpointer)&change_billboard, NULL, child);
647   create_hildon_actor_text(actor, desktop_plugin);
648   //actor->time_start_animation = time(NULL) + 20;
649   change_billboard(actor, desktop_plugin);
650   scene->actors = g_slist_append(scene->actors, actor);
651
652   actor = init_object(desktop_plugin, "tram", "tram.png",
653                       -300, 225, 10, 350, 210,
654                       FALSE, FALSE, 100, 255,
655                       (gpointer)&change_tram, NULL, NULL);
656   actor->time_start_animation = time(NULL) + fast_rnd(10);
657   actor->duration_animation = 60;
658   scene->actors = g_slist_append(scene->actors, actor);
659
660   actor = init_object(desktop_plugin, "border", "border0.png",
661                       0, 480-79, 11, 800, 79,
662                       TRUE, TRUE, 100, 255,
663                       (gpointer)&change_static_actor_with_corner, NULL, NULL);
664   change_static_actor_with_corner(actor, desktop_plugin);
665   scene->actors = g_slist_append(scene->actors, actor);
666
667   actor = init_object(desktop_plugin, "moon", "moon1.png",
668                       400, 20, 6, 60, 60,
669                       FALSE, FALSE, 100, 255,
670                       (gpointer)&change_moon, NULL, NULL);
671   change_moon(actor, desktop_plugin);
672   scene->actors = g_slist_append(scene->actors, actor);
673
674   actor = init_object(desktop_plugin, "wind", "",
675                       0, 0, 5, 0, 0,
676                       FALSE, FALSE, 100, 255,
677                       (gpointer)&change_wind, NULL, NULL);
678   change_wind(actor, desktop_plugin);
679   scene->actors = g_slist_append(scene->actors, actor);
680
681     /* windows in 4-th house  */
682
683     winds[0][0] = 482;
684     winds[0][1] = 180;
685
686     winds[1][0] = 495;
687     winds[1][1] = 179;
688
689     winds[2][0] = 482;
690     winds[2][1] = 191;
691
692     winds[3][0] = 495;
693     winds[3][1] = 190;
694
695     winds[4][0] = 482;
696     winds[4][1] = 201;
697
698     winds[5][0] = 495;
699     winds[5][1] = 210;
700
701     winds[6][0] = 482;
702     winds[6][1] = 222;
703
704     winds[7][0] = 495;
705     winds[7][1] = 221;
706
707     winds[8][0] = 459;
708     winds[8][1] = 203;
709
710     winds[9][0] = 495;
711     winds[9][1] = 241;
712
713     winds[10][0] = 495;
714     winds[10][1] = 252;
715
716     winds[11][0] = 482;
717     winds[11][1] = 273;
718
719     winds[12][0] = 495;
720     winds[12][1] = 303;
721     for (i=0; i<13; i++){
722         actor = init_object(desktop_plugin, "window1", "window1.png",
723                             winds[i][0], winds[i][1], 8, 8, 10,
724                             FALSE, FALSE, 100, 255,
725                             (gpointer)&change_window1, NULL, NULL);
726         //change_window1(actor, desktop_plugin);
727         actor->time_start_animation = now + fast_rnd(30);
728         scene->actors = g_slist_append(scene->actors, actor);
729
730     }
731
732     /* windows in 1-th house  */
733
734     winds[0][0] = 86;
735     winds[0][1] = 321;
736
737     winds[1][0] = 86;
738     winds[1][1] = 363;
739
740     winds[2][0] = 86;
741     winds[2][1] = 385;
742
743     winds[3][0] = 86;
744     winds[3][1] = 286;
745
746     winds[4][0] = 94;
747     winds[4][1] = 232;
748
749     winds[5][0] = 94;
750     winds[5][1] = 243;
751
752     winds[6][0] = 94;
753     winds[6][1] = 265;
754
755     winds[7][0] = 94;
756     winds[7][1] = 331;
757     for (i=0; i<8; i++){
758         actor = init_object(desktop_plugin, "window2", "window2.png",
759                             winds[i][0], winds[i][1], 8, 8, 10,
760                             FALSE, FALSE, 100, 255,
761                             (gpointer)&change_window1, NULL, NULL);
762         //change_window1(actor, desktop_plugin);
763         actor->time_start_animation = now + fast_rnd(30);
764         scene->actors = g_slist_append(scene->actors, actor);
765
766     }
767
768     /* windows in 3-th house  */
769
770     winds[0][0] = 251;
771     winds[0][1] = 162;
772
773     winds[1][0] = 251;
774     winds[1][1] = 196;
775
776     winds[2][0] = 251;
777     winds[2][1] = 278;
778
779     winds[3][0] = 251;
780     winds[3][1] = 289;
781
782     winds[4][0] = 313;
783     winds[4][1] = 173;
784
785     winds[5][0] = 322;
786     winds[5][1] = 160;
787
788     winds[6][0] = 303;
789     winds[6][1] = 217;
790
791     winds[7][0] = 322;
792     winds[7][1] = 224;
793
794     winds[8][0] = 323;
795     winds[8][1] = 217;
796
797     winds[9][0] = 322;
798     winds[9][1] = 288;
799
800     for (i=0; i<10; i++){
801         actor = init_object(desktop_plugin, "window3", "window3.png",
802                             winds[i][0], winds[i][1], 8, 8, 10,
803                             FALSE, FALSE, 100, 255,
804                             (gpointer)&change_window1, NULL, NULL);
805         //change_window1(actor, desktop_plugin);
806         actor->time_start_animation = now + fast_rnd(30);
807         scene->actors = g_slist_append(scene->actors, actor);
808
809     }
810
811     /* windows in 5-th house  */
812
813     winds[0][0] = 610;
814     winds[0][1] = 224;
815
816     winds[1][0] = 602;
817     winds[1][1] = 245;
818
819     winds[2][0] = 602;
820     winds[2][1] = 264;
821
822     winds[3][0] = 610;
823     winds[3][1] = 301;
824
825     winds[4][0] = 610;
826     winds[4][1] = 320;
827
828     winds[5][0] = 593;
829     winds[5][1] = 352;
830
831     winds[6][0] = 610;
832     winds[6][1] = 368;
833
834     for (i=0; i<7; i++){
835         actor = init_object(desktop_plugin, "window4", "window4.png",
836                             winds[i][0], winds[i][1], 8, 8, 10,
837                             FALSE, FALSE, 100, 255,
838                             (gpointer)&change_window1, NULL, NULL);
839         //change_window1(actor, desktop_plugin);
840         actor->time_start_animation = now + fast_rnd(30);
841         scene->actors = g_slist_append(scene->actors, actor);
842
843     }
844
845     /* windows in 6-th house  */
846
847     winds[0][0] = 717;
848     winds[0][1] = 283;
849
850     winds[1][0] = 698;
851     winds[1][1] = 293;
852
853     winds[2][0] = 717;
854     winds[2][1] = 315;
855
856     winds[3][0] = 717;
857     winds[3][1] = 323;
858
859     winds[4][0] = 698;
860     winds[4][1] = 362;
861
862     winds[5][0] = 698;
863     winds[5][1] = 400;
864
865     for (i=0; i<6; i++){
866         actor = init_object(desktop_plugin, "window5", "window5.png",
867                             winds[i][0], winds[i][1], 8, 8, 10,
868                             FALSE, FALSE, 100, 255,
869                             (gpointer)&change_window1, NULL, NULL);
870         //change_window1(actor, desktop_plugin);
871         actor->time_start_animation = now + fast_rnd(30);
872         scene->actors = g_slist_append(scene->actors, actor);
873
874     }
875     run_long_timeout(desktop_plugin);
876
877 #if 0
878   anim = g_new0(Animation, 1);
879   anim->count = 1;
880   anim->actor = actor;
881   anim->func_change = &change_tram;
882   anim->func_time = NULL;
883   anim->timestart = time(NULL);
884   anim->timeall = 10;
885
886   scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
887 #endif
888 }
889 /*******************************************************************************/
890 /* Init Berlin Scene */
891 void
892 init_scene_Berlin(AWallpaperPlugin *desktop_plugin)
893 {
894   Actor *actor, *actor1, *actor2;
895   Scene *scene;
896   gint now = time(NULL);
897   gint i;
898   gint winds[13][2];
899   GPtrArray *child = NULL;
900
901   scene = g_new0(Scene, 1);
902   scene->daytime = get_daytime();
903   scene->actors = NULL;
904   scene->wind_orientation = -1;
905   scene->wind_angle = 0.3;
906   /* init value for random */
907   scene->seed = time(NULL);
908   desktop_plugin->priv->scene = scene;
909
910   actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
911                       TRUE, TRUE, 100, 255,
912                       (gpointer)&change_static_actor, NULL, NULL);
913   change_static_actor(actor, desktop_plugin);
914   scene->actors = g_slist_append(scene->actors, actor);
915
916
917   actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
918                       FALSE, FALSE, 100, 255,
919                       (gpointer)&change_sun, NULL, NULL);
920   actor->time_start_animation = time(NULL);
921   actor->duration_animation = G_MAXINT;
922   change_sun(actor, desktop_plugin);
923   scene->actors = g_slist_append(scene->actors, actor);
924
925 #if 0
926   actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
927                       TRUE, 100, 255, NULL, NULL);
928   scene.actors = g_slist_append(scene.actors, actor);
929 #endif
930
931   actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
932                       FALSE, FALSE, 100, 255,
933                       (gpointer)&change_moon, NULL, NULL);
934   change_moon(actor, desktop_plugin);
935   scene->actors = g_slist_append(scene->actors, actor);
936
937   actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
938                       FALSE, FALSE, 100, 255,
939                       (gpointer)&change_cloud, NULL, NULL);
940   actor->time_start_animation = now + fast_rnd(30) + 10;
941   actor->duration_animation = 3*60;
942   scene->actors = g_slist_append(scene->actors, actor);
943
944   actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
945                       FALSE, FALSE, 100, 255,
946                       (gpointer)&change_cloud, NULL, NULL);
947   actor->time_start_animation = now + fast_rnd(10);
948   actor->duration_animation = 3*60;
949   scene->actors = g_slist_append(scene->actors, actor);
950
951   actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
952                       FALSE, FALSE, 100, 255,
953                       (gpointer)&change_cloud, NULL, NULL);
954   actor->time_start_animation = now + fast_rnd(60) + 20;
955   actor->duration_animation = 5*60;
956   scene->actors = g_slist_append(scene->actors, actor);
957
958
959   actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
960                       FALSE, FALSE, 100, 255,
961                       (gpointer)&change_plane2, NULL, NULL);
962   actor->time_start_animation = now + fast_rnd(40) + 20;
963   actor->duration_animation = 60;
964   scene->actors = g_slist_append(scene->actors, actor);
965
966   actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116,
967                       FALSE, FALSE, 100, 255,
968                       (gpointer)&change_plane1, NULL, NULL);
969   actor->time_start_animation = now + fast_rnd(20);
970   actor->duration_animation = 30;
971   scene->actors = g_slist_append(scene->actors, actor);
972
973   actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
974                       TRUE, TRUE, 100, 255,
975                       (gpointer)&change_static_actor_with_corner, NULL, NULL);
976   change_static_actor_with_corner(actor, desktop_plugin);
977   scene->actors = g_slist_append(scene->actors, actor);
978
979   actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
980                       FALSE, FALSE, 100, 255,
981                       (gpointer)&change_wind, NULL, NULL);
982   change_wind(actor, desktop_plugin);
983   scene->actors = g_slist_append(scene->actors, actor);
984
985   actor1 = init_object(desktop_plugin, "signal_red", "red.png",
986                       486, 425, 10, 18, 38,
987                       FALSE, TRUE, 100, 255, NULL, NULL, NULL);
988   //actor->time_start_animation = now + fast_rnd(30) + 10;
989   scene->actors = g_slist_append(scene->actors, actor1);
990
991   actor2 = init_object(desktop_plugin, "signal_green", "green.png",
992                       486, 425, 10, 18, 38,
993                       TRUE, TRUE, 100, 255, NULL, NULL, NULL);
994   //actor->time_start_animation = now + fast_rnd(30) + 10;
995   scene->actors = g_slist_append(scene->actors, actor2);
996   child = g_ptr_array_sized_new(2);
997   g_ptr_array_add(child, actor1);
998   g_ptr_array_add(child, actor2);
999   actor = init_object(desktop_plugin, "signal", "",
1000                       486, 425, 10, 18, 38,
1001                       FALSE, FALSE, 100, 255,
1002                       (gpointer)&change_signal, NULL, child);
1003   actor->time_start_animation = now + fast_rnd(30) + 10;
1004   scene->actors = g_slist_append(scene->actors, actor);
1005
1006     winds[0][0] = 389;
1007     winds[0][1] = 305;
1008
1009     winds[1][0] = 373;
1010     winds[1][1] = 306;
1011
1012     winds[2][0] = 355;
1013     winds[2][1] = 306;
1014
1015     winds[3][0] = 356;
1016     winds[3][1] = 288;
1017
1018     winds[4][0] = 337;
1019     winds[4][1] = 269;
1020
1021     winds[5][0] = 372;
1022     winds[5][1] = 268;
1023
1024     winds[6][0] = 372;
1025     winds[6][1] = 249;
1026
1027     winds[7][0] = 388;
1028     winds[7][1] = 249;
1029
1030     winds[8][0] = 387;
1031     winds[8][1] = 230;
1032
1033     winds[9][0] = 372;
1034     winds[9][1] = 211;
1035
1036     winds[10][0] = 355;
1037     winds[10][1] = 159;
1038
1039     winds[11][0] = 335;
1040     winds[11][1] = 158;
1041
1042     winds[12][0] = 386;
1043     winds[12][1] = 119;
1044
1045     for (i=0; i<13; i++){
1046         actor = init_object(desktop_plugin, "window", "window.png",
1047                             winds[i][0], winds[i][1], 10, 8, 9,
1048                             FALSE, TRUE, 100, 255,
1049                             (gpointer)&change_window1, NULL, NULL);
1050         //change_window1(actor, desktop_plugin);
1051         actor->time_start_animation = now + fast_rnd(30);
1052         scene->actors = g_slist_append(scene->actors, actor);
1053
1054     }
1055
1056     run_long_timeout(desktop_plugin);
1057
1058 }
1059 /*******************************************************************************/
1060 void
1061 init_scene_theme(AWallpaperPlugin *desktop_plugin)
1062 {
1063 #if 0
1064     void (*func)(gpointer);
1065     func = g_hash_table_lookup(desktop_plugin->priv->hash_scene_func, desktop_plugin->priv->theme);
1066     if (func){
1067         (*func)(desktop_plugin);
1068     }
1069 #endif
1070     fprintf(stderr, "Init_scene_theme\n");
1071     void (*func)(gpointer);
1072     func = desktop_plugin->priv->scene_func;
1073     if (func){
1074         fprintf(stderr, "Success init_scene_theme %s\n", desktop_plugin->priv->theme);
1075         (*func)(desktop_plugin);
1076     }
1077 }