1 /* vim: set sw=4 ts=4 et: */
3 * This file is part of Live Wallpaper (livewp)
5 * Copyright (C) 2010 Vlad Vasiliev
6 * Copyright (C) 2010 Tanya Makova
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.
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.
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
24 /*******************************************************************************/
25 #include "livewp-scene.h"
28 destroy_scene(AWallpaperPlugin *desktop_plugin)
30 if (desktop_plugin->priv->scene){
31 GSList * tmp = desktop_plugin->priv->scene->actors;
33 destroy_actor(tmp->data);
34 tmp = g_slist_next(tmp);
38 desktop_plugin->priv->scene->actors = NULL;
39 if (desktop_plugin->priv->scene){
40 g_free(desktop_plugin->priv->scene);
41 desktop_plugin->priv->scene = NULL;
47 reload_scene(AWallpaperPlugin *desktop_plugin)
49 fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);
50 destroy_scene(desktop_plugin);
51 init_scene_theme(desktop_plugin);
55 parsestring(char *line, char **argv)
57 while (*line != '\0') {
58 while (*line == ' ' || *line == '\n')
59 *line++ = '\0'; /* replace white spaces with 0 */
60 *argv++ = line; /* save the argument position */
61 while (*line != '\0' && *line != ' ' &&
63 line++; /* skip the argument until ... */
65 *argv = '\0'; /* mark the end of argument list */
70 sync_handler(GstBus *bus, GstMessage *message, AWallpaperPlugin *desktop_plugin){
72 if (!desktop_plugin->priv->visible)
73 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PAUSED);
74 if (GST_MESSAGE_TYPE(message) != GST_MESSAGE_ELEMENT){
75 return (GST_BUS_PASS);
77 if (!gst_structure_has_name(message->structure, "prepare-xwindow-id")){
78 return (GST_BUS_PASS);
80 return (GST_BUS_DROP);
85 init_scene_Video(AWallpaperPlugin *desktop_plugin)
88 GstElement *videosink;
93 desktop_plugin->priv->pipeline= gst_pipeline_new("gst-player");
94 bin = gst_element_factory_make ("playbin2", "bin");
95 videosink = gst_element_factory_make ("ximagesink", "videosink");
96 g_object_set (G_OBJECT (bin), "video-sink", videosink, NULL);
97 gst_bin_add (GST_BIN (desktop_plugin->priv->pipeline), bin);
101 bus = gst_pipeline_get_bus (GST_PIPELINE (desktop_plugin->priv->pipeline));
102 // gst_bus_add_watch(bus, bus_call, NULL);
103 gst_object_unref (bus);
105 file_plus_uri = g_strdup_printf("file://%s",desktop_plugin->priv->theme_string_parametr1);
106 g_object_set (G_OBJECT (bin), "uri", file_plus_uri, NULL );
107 g_object_set (G_OBJECT (videosink), "force-aspect-ratio", TRUE, NULL );
108 if (GST_IS_X_OVERLAY (videosink))
109 gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (videosink), GDK_DRAWABLE_XID(desktop_plugin->priv->window->window));
110 if (desktop_plugin->priv->visible)
111 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
115 init_scene_Matrix(AWallpaperPlugin *desktop_plugin)
120 gint now = time(NULL);
123 if (desktop_plugin->priv->rich_animation){
131 /* fprintf(stderr, "init scene2 \n"); */
132 scene = g_new0(Scene, 1);
133 //scene.daytime = get_daytime();
134 scene->actors = NULL;
135 desktop_plugin->priv->scene = scene;
137 actor = init_object(desktop_plugin, "background", "bg.png",
139 TRUE, TRUE, 100, 255,
141 scene->actors = g_slist_append(scene->actors, actor);
143 actor = init_object(desktop_plugin, "symbols", "symbols.png",
145 TRUE, TRUE, 100, 255,
147 scene->actors = g_slist_append(scene->actors, actor);
149 child = g_ptr_array_sized_new(4);
150 actor = init_object(desktop_plugin, "layer1", "layer1_2.png",
152 TRUE, TRUE, 100, 255,
154 //actor->time_start_animation = now;
155 //actor->duration_animation = G_MAXINT;
156 scene->actors = g_slist_append(scene->actors, actor);
157 g_ptr_array_add(child, actor);
159 actor = init_object(desktop_plugin, "layer1", "layer1_1.png",
161 TRUE, TRUE, 100, 255,
163 //actor->time_start_animation = now;
164 //actor->duration_animation = G_MAXINT;
165 scene->actors = g_slist_append(scene->actors, actor);
166 g_ptr_array_add(child, actor);
168 actor = init_object(desktop_plugin, "layer2", "layer2_2.png",
170 TRUE, TRUE, 100, 255,
172 //actor->time_start_animation = now;
173 //actor->duration_animation = G_MAXINT;
174 scene->actors = g_slist_append(scene->actors, actor);
175 g_ptr_array_add(child, actor);
177 actor = init_object(desktop_plugin, "layer2", "layer2_1.png",
179 TRUE, TRUE, 100, 255,
181 //actor->time_start_animation = now;
182 //actor->duration_animation = G_MAXINT;
183 scene->actors = g_slist_append(scene->actors, actor);
184 g_ptr_array_add(child, actor);
186 actor = init_object(desktop_plugin, "layers", "",
188 FALSE, FALSE, 100, 255,
189 (gpointer)&change_layer, NULL, child);
190 actor->time_start_animation = now;
191 actor->duration_animation = G_MAXINT;
192 scene->actors = g_slist_append(scene->actors, actor);
194 run_long_timeout(desktop_plugin);
198 /* Init Modern Scene */
200 init_scene_Modern(AWallpaperPlugin *desktop_plugin)
204 gint now = time(NULL);
209 /* fprintf(stderr, "init scene \n"); */
210 scene = g_new0(Scene, 1);
211 scene->daytime = get_daytime();
212 scene->actors = NULL;
213 scene->wind_orientation = -1;
214 scene->wind_angle = 0.3;
215 /* init value for random */
216 scene->seed = time(NULL);
217 scene->notification = TRUE;
218 desktop_plugin->priv->scene = scene;
219 actor = init_object(desktop_plugin, "sky", "sky0.png",
221 TRUE , TRUE, 100, 255,
222 (gpointer)&change_static_actor, NULL, NULL);
223 scene->actors = g_slist_append(scene->actors, actor);
224 change_static_actor(actor, desktop_plugin);
226 actor = init_object(desktop_plugin, "sun", "sun.png",
228 FALSE, FALSE, 100, 255,
229 (gpointer)&change_sun, NULL, NULL);
230 actor->time_start_animation = now;
231 actor->duration_animation = G_MAXINT;
232 change_sun(actor, desktop_plugin);
233 scene->actors = g_slist_append(scene->actors, actor);
235 //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
236 // TRUE, 100, 255, NULL, NULL);
237 //scene.actors = g_slist_append(scene.actors, actor);
239 actor = init_object(desktop_plugin, "cloud1", "cloud1.png",
240 0, fast_rnd(300)-97, 7, 150, 97,
241 FALSE, FALSE, 100, 255,
242 (gpointer)&change_cloud, NULL, NULL);
243 actor->time_start_animation = now + fast_rnd(20);
244 actor->duration_animation = 3*60;
245 scene->actors = g_slist_append(scene->actors, actor);
247 actor = init_object(desktop_plugin, "cloud2", "cloud2.png",
248 0, fast_rnd(300)-75, 7, 188, 75,
249 FALSE, FALSE, 100, 255,
250 (gpointer)&change_cloud, NULL, NULL);
251 actor->time_start_animation = now + fast_rnd(40)+10;
252 actor->duration_animation = 3*60;
253 scene->actors = g_slist_append(scene->actors, actor);
255 actor = init_object(desktop_plugin, "cloud4", "cloud4.png",
256 0, fast_rnd(300)-75, 7, 150, 75,
257 FALSE, FALSE, 100, 255,
258 (gpointer)&change_cloud, NULL, NULL);
259 actor->time_start_animation = now + fast_rnd(60) + 20;
260 actor->duration_animation = 5*60;
261 scene->actors = g_slist_append(scene->actors, actor);
264 actor = init_object(desktop_plugin, "town", "town0.png",
266 TRUE, TRUE, 100, 255,
267 (gpointer)&change_static_actor, NULL, NULL);
268 change_static_actor(actor, desktop_plugin);
269 scene->actors = g_slist_append(scene->actors, actor);
271 actor = init_object(desktop_plugin, "stend", "stend0.png",
272 452, 166, 9, 300, 305,
273 TRUE, TRUE, 100, 255,
274 (gpointer)&change_static_actor, NULL, NULL);
275 change_static_actor(actor, desktop_plugin);
276 scene->actors = g_slist_append(scene->actors, actor);
279 child = g_ptr_array_sized_new(4);
280 actor = init_object(desktop_plugin, "call", "call.png",
282 FALSE, TRUE, 100, 255,
284 scene->actors = g_slist_append(scene->actors, actor);
285 g_ptr_array_add(child, actor);
287 actor = init_object(desktop_plugin, "chat", "chat.png",
289 FALSE, TRUE, 100, 255,
291 scene->actors = g_slist_append(scene->actors, actor);
292 g_ptr_array_add(child, actor);
294 actor = init_object(desktop_plugin, "mail", "mail.png",
296 FALSE, TRUE, 100, 255,
298 scene->actors = g_slist_append(scene->actors, actor);
299 g_ptr_array_add(child, actor);
301 actor = init_object(desktop_plugin, "sms", "sms.png",
303 FALSE, TRUE, 100, 255,
305 scene->actors = g_slist_append(scene->actors, actor);
306 g_ptr_array_add(child, actor);
308 actor = init_object(desktop_plugin, "billboard_text", "",
309 470, 174, 9, 300, 108,
310 FALSE, FALSE, 100, 255,
311 (gpointer)&change_billboard, NULL, child);
312 create_hildon_actor_text(actor, desktop_plugin);
313 //actor->time_start_animation = time(NULL) + 20;
314 change_billboard(actor, desktop_plugin);
315 scene->actors = g_slist_append(scene->actors, actor);
317 actor = init_object(desktop_plugin, "tram", "tram.png",
318 -300, 225, 10, 350, 210,
319 FALSE, FALSE, 100, 255,
320 (gpointer)&change_tram, NULL, NULL);
321 actor->time_start_animation = time(NULL) + fast_rnd(10);
322 actor->duration_animation = 60;
323 scene->actors = g_slist_append(scene->actors, actor);
325 actor = init_object(desktop_plugin, "border", "border0.png",
326 0, 480-79, 11, 800, 79,
327 TRUE, TRUE, 100, 255,
328 (gpointer)&change_static_actor_with_corner, NULL, NULL);
329 change_static_actor_with_corner(actor, desktop_plugin);
330 scene->actors = g_slist_append(scene->actors, actor);
332 actor = init_object(desktop_plugin, "moon", "moon1.png",
334 FALSE, FALSE, 100, 255,
335 (gpointer)&change_moon, NULL, NULL);
336 change_moon(actor, desktop_plugin);
337 scene->actors = g_slist_append(scene->actors, actor);
339 actor = init_object(desktop_plugin, "wind", "",
341 FALSE, FALSE, 100, 255,
342 (gpointer)&change_wind, NULL, NULL);
343 change_wind(actor, desktop_plugin);
344 scene->actors = g_slist_append(scene->actors, actor);
346 /* windows in 4-th house */
386 for (i=0; i<13; i++){
387 actor = init_object(desktop_plugin, "window1", "window1.png",
388 winds[i][0], winds[i][1], 8, 8, 10,
389 FALSE, FALSE, 100, 255,
390 (gpointer)&change_window1, NULL, NULL);
391 //change_window1(actor, desktop_plugin);
392 actor->time_start_animation = now + fast_rnd(30);
393 scene->actors = g_slist_append(scene->actors, actor);
397 /* windows in 1-th house */
423 actor = init_object(desktop_plugin, "window2", "window2.png",
424 winds[i][0], winds[i][1], 8, 8, 10,
425 FALSE, FALSE, 100, 255,
426 (gpointer)&change_window1, NULL, NULL);
427 //change_window1(actor, desktop_plugin);
428 actor->time_start_animation = now + fast_rnd(30);
429 scene->actors = g_slist_append(scene->actors, actor);
433 /* windows in 3-th house */
465 for (i=0; i<10; i++){
466 actor = init_object(desktop_plugin, "window3", "window3.png",
467 winds[i][0], winds[i][1], 8, 8, 10,
468 FALSE, FALSE, 100, 255,
469 (gpointer)&change_window1, NULL, NULL);
470 //change_window1(actor, desktop_plugin);
471 actor->time_start_animation = now + fast_rnd(30);
472 scene->actors = g_slist_append(scene->actors, actor);
476 /* windows in 5-th house */
500 actor = init_object(desktop_plugin, "window4", "window4.png",
501 winds[i][0], winds[i][1], 8, 8, 10,
502 FALSE, FALSE, 100, 255,
503 (gpointer)&change_window1, NULL, NULL);
504 //change_window1(actor, desktop_plugin);
505 actor->time_start_animation = now + fast_rnd(30);
506 scene->actors = g_slist_append(scene->actors, actor);
510 /* windows in 6-th house */
531 actor = init_object(desktop_plugin, "window5", "window5.png",
532 winds[i][0], winds[i][1], 8, 8, 10,
533 FALSE, FALSE, 100, 255,
534 (gpointer)&change_window1, NULL, NULL);
535 //change_window1(actor, desktop_plugin);
536 actor->time_start_animation = now + fast_rnd(30);
537 scene->actors = g_slist_append(scene->actors, actor);
540 run_long_timeout(desktop_plugin);
543 anim = g_new0(Animation, 1);
546 anim->func_change = &change_tram;
547 anim->func_time = NULL;
548 anim->timestart = time(NULL);
551 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
555 /* Init Berlin Scene */
557 init_scene_Berlin(AWallpaperPlugin *desktop_plugin)
559 Actor *actor, *actor1, *actor2;
561 gint now = time(NULL);
564 GPtrArray *child = NULL;
566 scene = g_new0(Scene, 1);
567 scene->daytime = get_daytime();
568 scene->actors = NULL;
569 scene->wind_orientation = -1;
570 scene->wind_angle = 0.3;
571 /* init value for random */
572 scene->seed = time(NULL);
573 desktop_plugin->priv->scene = scene;
575 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
576 TRUE, TRUE, 100, 255,
577 (gpointer)&change_static_actor, NULL, NULL);
578 change_static_actor(actor, desktop_plugin);
579 scene->actors = g_slist_append(scene->actors, actor);
582 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
583 FALSE, FALSE, 100, 255,
584 (gpointer)&change_sun, NULL, NULL);
585 actor->time_start_animation = time(NULL);
586 actor->duration_animation = G_MAXINT;
587 change_sun(actor, desktop_plugin);
588 scene->actors = g_slist_append(scene->actors, actor);
591 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
592 TRUE, 100, 255, NULL, NULL);
593 scene.actors = g_slist_append(scene.actors, actor);
596 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
597 FALSE, FALSE, 100, 255,
598 (gpointer)&change_moon, NULL, NULL);
599 change_moon(actor, desktop_plugin);
600 scene->actors = g_slist_append(scene->actors, actor);
602 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
603 FALSE, FALSE, 100, 255,
604 (gpointer)&change_cloud, NULL, NULL);
605 actor->time_start_animation = now + fast_rnd(30) + 10;
606 actor->duration_animation = 3*60;
607 scene->actors = g_slist_append(scene->actors, actor);
609 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
610 FALSE, FALSE, 100, 255,
611 (gpointer)&change_cloud, NULL, NULL);
612 actor->time_start_animation = now + fast_rnd(10);
613 actor->duration_animation = 3*60;
614 scene->actors = g_slist_append(scene->actors, actor);
616 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
617 FALSE, FALSE, 100, 255,
618 (gpointer)&change_cloud, NULL, NULL);
619 actor->time_start_animation = now + fast_rnd(60) + 20;
620 actor->duration_animation = 5*60;
621 scene->actors = g_slist_append(scene->actors, actor);
624 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
625 FALSE, FALSE, 100, 255,
626 (gpointer)&change_plane2, NULL, NULL);
627 actor->time_start_animation = now + fast_rnd(40) + 20;
628 actor->duration_animation = 60;
629 scene->actors = g_slist_append(scene->actors, actor);
631 actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116,
632 FALSE, FALSE, 100, 255,
633 (gpointer)&change_plane1, NULL, NULL);
634 actor->time_start_animation = now + fast_rnd(20);
635 actor->duration_animation = 30;
636 scene->actors = g_slist_append(scene->actors, actor);
638 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
639 TRUE, TRUE, 100, 255,
640 (gpointer)&change_static_actor_with_corner, NULL, NULL);
641 change_static_actor_with_corner(actor, desktop_plugin);
642 scene->actors = g_slist_append(scene->actors, actor);
644 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
645 FALSE, FALSE, 100, 255,
646 (gpointer)&change_wind, NULL, NULL);
647 change_wind(actor, desktop_plugin);
648 scene->actors = g_slist_append(scene->actors, actor);
650 actor1 = init_object(desktop_plugin, "signal_red", "red.png",
651 486, 425, 10, 18, 38,
652 FALSE, TRUE, 100, 255, NULL, NULL, NULL);
653 //actor->time_start_animation = now + fast_rnd(30) + 10;
654 scene->actors = g_slist_append(scene->actors, actor1);
656 actor2 = init_object(desktop_plugin, "signal_green", "green.png",
657 486, 425, 10, 18, 38,
658 TRUE, TRUE, 100, 255, NULL, NULL, NULL);
659 //actor->time_start_animation = now + fast_rnd(30) + 10;
660 scene->actors = g_slist_append(scene->actors, actor2);
661 child = g_ptr_array_sized_new(2);
662 g_ptr_array_add(child, actor1);
663 g_ptr_array_add(child, actor2);
664 actor = init_object(desktop_plugin, "signal", "",
665 486, 425, 10, 18, 38,
666 FALSE, FALSE, 100, 255,
667 (gpointer)&change_signal, NULL, child);
668 actor->time_start_animation = now + fast_rnd(30) + 10;
669 scene->actors = g_slist_append(scene->actors, actor);
710 for (i=0; i<13; i++){
711 actor = init_object(desktop_plugin, "window", "window.png",
712 winds[i][0], winds[i][1], 10, 8, 9,
713 FALSE, TRUE, 100, 255,
714 (gpointer)&change_window1, NULL, NULL);
715 //change_window1(actor, desktop_plugin);
716 actor->time_start_animation = now + fast_rnd(30);
717 scene->actors = g_slist_append(scene->actors, actor);
721 run_long_timeout(desktop_plugin);
726 init_scene_theme(AWallpaperPlugin *desktop_plugin)
728 void (*func)(gpointer);
729 func = g_hash_table_lookup(desktop_plugin->priv->hash_scene_func, desktop_plugin->priv->theme);
731 (*func)(desktop_plugin);