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("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 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
114 init_scene_Matrix(AWallpaperPlugin *desktop_plugin)
119 gint now = time(NULL);
122 if (desktop_plugin->priv->rich_animation){
130 /* fprintf(stderr, "init scene2 \n"); */
131 scene = g_new0(Scene, 1);
132 //scene.daytime = get_daytime();
133 scene->actors = NULL;
134 desktop_plugin->priv->scene = scene;
136 actor = init_object(desktop_plugin, "background", "bg.png",
138 TRUE, TRUE, 100, 255,
140 scene->actors = g_slist_append(scene->actors, actor);
142 actor = init_object(desktop_plugin, "symbols", "symbols.png",
144 TRUE, TRUE, 100, 255,
146 scene->actors = g_slist_append(scene->actors, actor);
148 child = g_ptr_array_sized_new(4);
149 actor = init_object(desktop_plugin, "layer1", "layer1_2.png",
151 TRUE, TRUE, 100, 255,
153 //actor->time_start_animation = now;
154 //actor->duration_animation = G_MAXINT;
155 scene->actors = g_slist_append(scene->actors, actor);
156 g_ptr_array_add(child, actor);
158 actor = init_object(desktop_plugin, "layer1", "layer1_1.png",
160 TRUE, TRUE, 100, 255,
162 //actor->time_start_animation = now;
163 //actor->duration_animation = G_MAXINT;
164 scene->actors = g_slist_append(scene->actors, actor);
165 g_ptr_array_add(child, actor);
167 actor = init_object(desktop_plugin, "layer2", "layer2_2.png",
169 TRUE, TRUE, 100, 255,
171 //actor->time_start_animation = now;
172 //actor->duration_animation = G_MAXINT;
173 scene->actors = g_slist_append(scene->actors, actor);
174 g_ptr_array_add(child, actor);
176 actor = init_object(desktop_plugin, "layer2", "layer2_1.png",
178 TRUE, TRUE, 100, 255,
180 //actor->time_start_animation = now;
181 //actor->duration_animation = G_MAXINT;
182 scene->actors = g_slist_append(scene->actors, actor);
183 g_ptr_array_add(child, actor);
185 actor = init_object(desktop_plugin, "layers", "",
187 FALSE, FALSE, 100, 255,
188 (gpointer)&change_layer, NULL, child);
189 actor->time_start_animation = now;
190 actor->duration_animation = G_MAXINT;
191 scene->actors = g_slist_append(scene->actors, actor);
193 run_long_timeout(desktop_plugin);
197 /* Init Modern Scene */
199 init_scene_Modern(AWallpaperPlugin *desktop_plugin)
203 gint now = time(NULL);
208 /* fprintf(stderr, "init scene \n"); */
209 scene = g_new0(Scene, 1);
210 scene->daytime = get_daytime();
211 scene->actors = NULL;
212 scene->wind_orientation = -1;
213 scene->wind_angle = 0.3;
214 /* init value for random */
215 scene->seed = time(NULL);
216 scene->notification = TRUE;
217 desktop_plugin->priv->scene = scene;
218 actor = init_object(desktop_plugin, "sky", "sky0.png",
220 TRUE , TRUE, 100, 255,
221 (gpointer)&change_static_actor, NULL, NULL);
222 scene->actors = g_slist_append(scene->actors, actor);
223 change_static_actor(actor, desktop_plugin);
225 actor = init_object(desktop_plugin, "sun", "sun.png",
227 FALSE, FALSE, 100, 255,
228 (gpointer)&change_sun, NULL, NULL);
229 actor->time_start_animation = now;
230 actor->duration_animation = G_MAXINT;
231 change_sun(actor, desktop_plugin);
232 scene->actors = g_slist_append(scene->actors, actor);
234 //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
235 // TRUE, 100, 255, NULL, NULL);
236 //scene.actors = g_slist_append(scene.actors, actor);
238 actor = init_object(desktop_plugin, "cloud1", "cloud1.png",
239 0, fast_rnd(300)-97, 7, 150, 97,
240 FALSE, FALSE, 100, 255,
241 (gpointer)&change_cloud, NULL, NULL);
242 actor->time_start_animation = now + fast_rnd(20);
243 actor->duration_animation = 3*60;
244 scene->actors = g_slist_append(scene->actors, actor);
246 actor = init_object(desktop_plugin, "cloud2", "cloud2.png",
247 0, fast_rnd(300)-75, 7, 188, 75,
248 FALSE, FALSE, 100, 255,
249 (gpointer)&change_cloud, NULL, NULL);
250 actor->time_start_animation = now + fast_rnd(40)+10;
251 actor->duration_animation = 3*60;
252 scene->actors = g_slist_append(scene->actors, actor);
254 actor = init_object(desktop_plugin, "cloud4", "cloud4.png",
255 0, fast_rnd(300)-75, 7, 150, 75,
256 FALSE, FALSE, 100, 255,
257 (gpointer)&change_cloud, NULL, NULL);
258 actor->time_start_animation = now + fast_rnd(60) + 20;
259 actor->duration_animation = 5*60;
260 scene->actors = g_slist_append(scene->actors, actor);
263 actor = init_object(desktop_plugin, "town", "town0.png",
265 TRUE, TRUE, 100, 255,
266 (gpointer)&change_static_actor, NULL, NULL);
267 change_static_actor(actor, desktop_plugin);
268 scene->actors = g_slist_append(scene->actors, actor);
270 actor = init_object(desktop_plugin, "stend", "stend0.png",
271 452, 166, 9, 300, 305,
272 TRUE, TRUE, 100, 255,
273 (gpointer)&change_static_actor, NULL, NULL);
274 change_static_actor(actor, desktop_plugin);
275 scene->actors = g_slist_append(scene->actors, actor);
278 child = g_ptr_array_sized_new(4);
279 actor = init_object(desktop_plugin, "call", "call.png",
281 FALSE, TRUE, 100, 255,
283 scene->actors = g_slist_append(scene->actors, actor);
284 g_ptr_array_add(child, actor);
286 actor = init_object(desktop_plugin, "chat", "chat.png",
288 FALSE, TRUE, 100, 255,
290 scene->actors = g_slist_append(scene->actors, actor);
291 g_ptr_array_add(child, actor);
293 actor = init_object(desktop_plugin, "mail", "mail.png",
295 FALSE, TRUE, 100, 255,
297 scene->actors = g_slist_append(scene->actors, actor);
298 g_ptr_array_add(child, actor);
300 actor = init_object(desktop_plugin, "sms", "sms.png",
302 FALSE, TRUE, 100, 255,
304 scene->actors = g_slist_append(scene->actors, actor);
305 g_ptr_array_add(child, actor);
307 actor = init_object(desktop_plugin, "billboard_text", "",
308 470, 174, 9, 300, 108,
309 FALSE, FALSE, 100, 255,
310 (gpointer)&change_billboard, NULL, child);
311 create_hildon_actor_text(actor, desktop_plugin);
312 //actor->time_start_animation = time(NULL) + 20;
313 change_billboard(actor, desktop_plugin);
314 scene->actors = g_slist_append(scene->actors, actor);
316 actor = init_object(desktop_plugin, "tram", "tram.png",
317 -300, 225, 10, 350, 210,
318 FALSE, FALSE, 100, 255,
319 (gpointer)&change_tram, NULL, NULL);
320 actor->time_start_animation = time(NULL) + fast_rnd(10);
321 actor->duration_animation = 60;
322 scene->actors = g_slist_append(scene->actors, actor);
324 actor = init_object(desktop_plugin, "border", "border0.png",
325 0, 480-79, 11, 800, 79,
326 TRUE, TRUE, 100, 255,
327 (gpointer)&change_static_actor_with_corner, NULL, NULL);
328 change_static_actor_with_corner(actor, desktop_plugin);
329 scene->actors = g_slist_append(scene->actors, actor);
331 actor = init_object(desktop_plugin, "moon", "moon1.png",
333 FALSE, FALSE, 100, 255,
334 (gpointer)&change_moon, NULL, NULL);
335 change_moon(actor, desktop_plugin);
336 scene->actors = g_slist_append(scene->actors, actor);
338 actor = init_object(desktop_plugin, "wind", "",
340 FALSE, FALSE, 100, 255,
341 (gpointer)&change_wind, NULL, NULL);
342 change_wind(actor, desktop_plugin);
343 scene->actors = g_slist_append(scene->actors, actor);
345 /* windows in 4-th house */
385 for (i=0; i<13; i++){
386 actor = init_object(desktop_plugin, "window1", "window1.png",
387 winds[i][0], winds[i][1], 8, 8, 10,
388 FALSE, FALSE, 100, 255,
389 (gpointer)&change_window1, NULL, NULL);
390 //change_window1(actor, desktop_plugin);
391 actor->time_start_animation = now + fast_rnd(30);
392 scene->actors = g_slist_append(scene->actors, actor);
396 /* windows in 1-th house */
422 actor = init_object(desktop_plugin, "window2", "window2.png",
423 winds[i][0], winds[i][1], 8, 8, 10,
424 FALSE, FALSE, 100, 255,
425 (gpointer)&change_window1, NULL, NULL);
426 //change_window1(actor, desktop_plugin);
427 actor->time_start_animation = now + fast_rnd(30);
428 scene->actors = g_slist_append(scene->actors, actor);
432 /* windows in 3-th house */
464 for (i=0; i<10; i++){
465 actor = init_object(desktop_plugin, "window3", "window3.png",
466 winds[i][0], winds[i][1], 8, 8, 10,
467 FALSE, FALSE, 100, 255,
468 (gpointer)&change_window1, NULL, NULL);
469 //change_window1(actor, desktop_plugin);
470 actor->time_start_animation = now + fast_rnd(30);
471 scene->actors = g_slist_append(scene->actors, actor);
475 /* windows in 5-th house */
499 actor = init_object(desktop_plugin, "window4", "window4.png",
500 winds[i][0], winds[i][1], 8, 8, 10,
501 FALSE, FALSE, 100, 255,
502 (gpointer)&change_window1, NULL, NULL);
503 //change_window1(actor, desktop_plugin);
504 actor->time_start_animation = now + fast_rnd(30);
505 scene->actors = g_slist_append(scene->actors, actor);
509 /* windows in 6-th house */
530 actor = init_object(desktop_plugin, "window5", "window5.png",
531 winds[i][0], winds[i][1], 8, 8, 10,
532 FALSE, FALSE, 100, 255,
533 (gpointer)&change_window1, NULL, NULL);
534 //change_window1(actor, desktop_plugin);
535 actor->time_start_animation = now + fast_rnd(30);
536 scene->actors = g_slist_append(scene->actors, actor);
539 run_long_timeout(desktop_plugin);
542 anim = g_new0(Animation, 1);
545 anim->func_change = &change_tram;
546 anim->func_time = NULL;
547 anim->timestart = time(NULL);
550 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
554 /* Init Berlin Scene */
556 init_scene_Berlin(AWallpaperPlugin *desktop_plugin)
558 Actor *actor, *actor1, *actor2;
560 gint now = time(NULL);
563 GPtrArray *child = NULL;
565 scene = g_new0(Scene, 1);
566 scene->daytime = get_daytime();
567 scene->actors = NULL;
568 scene->wind_orientation = -1;
569 scene->wind_angle = 0.3;
570 /* init value for random */
571 scene->seed = time(NULL);
572 desktop_plugin->priv->scene = scene;
574 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
575 TRUE, TRUE, 100, 255,
576 (gpointer)&change_static_actor, NULL, NULL);
577 change_static_actor(actor, desktop_plugin);
578 scene->actors = g_slist_append(scene->actors, actor);
581 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
582 FALSE, FALSE, 100, 255,
583 (gpointer)&change_sun, NULL, NULL);
584 actor->time_start_animation = time(NULL);
585 actor->duration_animation = G_MAXINT;
586 change_sun(actor, desktop_plugin);
587 scene->actors = g_slist_append(scene->actors, actor);
590 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
591 TRUE, 100, 255, NULL, NULL);
592 scene.actors = g_slist_append(scene.actors, actor);
595 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
596 FALSE, FALSE, 100, 255,
597 (gpointer)&change_moon, NULL, NULL);
598 change_moon(actor, desktop_plugin);
599 scene->actors = g_slist_append(scene->actors, actor);
601 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
602 FALSE, FALSE, 100, 255,
603 (gpointer)&change_cloud, NULL, NULL);
604 actor->time_start_animation = now + fast_rnd(30) + 10;
605 actor->duration_animation = 3*60;
606 scene->actors = g_slist_append(scene->actors, actor);
608 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
609 FALSE, FALSE, 100, 255,
610 (gpointer)&change_cloud, NULL, NULL);
611 actor->time_start_animation = now + fast_rnd(10);
612 actor->duration_animation = 3*60;
613 scene->actors = g_slist_append(scene->actors, actor);
615 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
616 FALSE, FALSE, 100, 255,
617 (gpointer)&change_cloud, NULL, NULL);
618 actor->time_start_animation = now + fast_rnd(60) + 20;
619 actor->duration_animation = 5*60;
620 scene->actors = g_slist_append(scene->actors, actor);
623 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
624 FALSE, FALSE, 100, 255,
625 (gpointer)&change_plane2, NULL, NULL);
626 actor->time_start_animation = now + fast_rnd(40) + 20;
627 actor->duration_animation = 60;
628 scene->actors = g_slist_append(scene->actors, actor);
630 actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116,
631 FALSE, FALSE, 100, 255,
632 (gpointer)&change_plane1, NULL, NULL);
633 actor->time_start_animation = now + fast_rnd(20);
634 actor->duration_animation = 30;
635 scene->actors = g_slist_append(scene->actors, actor);
637 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
638 TRUE, TRUE, 100, 255,
639 (gpointer)&change_static_actor_with_corner, NULL, NULL);
640 change_static_actor_with_corner(actor, desktop_plugin);
641 scene->actors = g_slist_append(scene->actors, actor);
643 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
644 FALSE, FALSE, 100, 255,
645 (gpointer)&change_wind, NULL, NULL);
646 change_wind(actor, desktop_plugin);
647 scene->actors = g_slist_append(scene->actors, actor);
649 actor1 = init_object(desktop_plugin, "signal_red", "red.png",
650 486, 425, 10, 18, 38,
651 FALSE, TRUE, 100, 255, NULL, NULL, NULL);
652 //actor->time_start_animation = now + fast_rnd(30) + 10;
653 scene->actors = g_slist_append(scene->actors, actor1);
655 actor2 = init_object(desktop_plugin, "signal_green", "green.png",
656 486, 425, 10, 18, 38,
657 TRUE, TRUE, 100, 255, NULL, NULL, NULL);
658 //actor->time_start_animation = now + fast_rnd(30) + 10;
659 scene->actors = g_slist_append(scene->actors, actor2);
660 child = g_ptr_array_sized_new(2);
661 g_ptr_array_add(child, actor1);
662 g_ptr_array_add(child, actor2);
663 actor = init_object(desktop_plugin, "signal", "",
664 486, 425, 10, 18, 38,
665 FALSE, FALSE, 100, 255,
666 (gpointer)&change_signal, NULL, child);
667 actor->time_start_animation = now + fast_rnd(30) + 10;
668 scene->actors = g_slist_append(scene->actors, actor);
709 for (i=0; i<13; i++){
710 actor = init_object(desktop_plugin, "window", "window.png",
711 winds[i][0], winds[i][1], 10, 8, 9,
712 FALSE, TRUE, 100, 255,
713 (gpointer)&change_window1, NULL, NULL);
714 //change_window1(actor, desktop_plugin);
715 actor->time_start_animation = now + fast_rnd(30);
716 scene->actors = g_slist_append(scene->actors, actor);
720 run_long_timeout(desktop_plugin);
725 init_scene_theme(AWallpaperPlugin *desktop_plugin)
727 void (*func)(gpointer);
728 func = g_hash_table_lookup(desktop_plugin->priv->hash_scene_func, desktop_plugin->priv->theme);
730 (*func)(desktop_plugin);