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;
44 if (desktop_plugin->priv->pipeline){
45 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_NULL);
46 gst_object_unref (GST_OBJECT (desktop_plugin->priv->pipeline));
52 reload_scene(AWallpaperPlugin *desktop_plugin)
54 fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);
55 destroy_scene(desktop_plugin);
56 init_scene_theme(desktop_plugin);
60 parsestring(char *line, char **argv)
62 while (*line != '\0') {
63 while (*line == ' ' || *line == '\n')
64 *line++ = '\0'; /* replace white spaces with 0 */
65 *argv++ = line; /* save the argument position */
66 while (*line != '\0' && *line != ' ' &&
68 line++; /* skip the argument until ... */
70 *argv = '\0'; /* mark the end of argument list */
75 sync_handler(GstBus *bus, GstMessage *message, AWallpaperPlugin *desktop_plugin){
77 if (!desktop_plugin->priv->visible)
78 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PAUSED);
79 if (GST_MESSAGE_TYPE(message) != GST_MESSAGE_ELEMENT){
80 return (GST_BUS_PASS);
82 if (!gst_structure_has_name(message->structure, "prepare-xwindow-id")){
83 return (GST_BUS_PASS);
85 return (GST_BUS_DROP);
90 init_scene_Video(AWallpaperPlugin *desktop_plugin)
93 GstElement *videosink;
98 desktop_plugin->priv->pipeline = gst_pipeline_new("gst-player");
99 bin = gst_element_factory_make ("playbin2", "bin");
100 videosink = gst_element_factory_make ("ximagesink", "videosink");
101 g_object_set (G_OBJECT (bin), "video-sink", videosink, NULL);
102 gst_bin_add (GST_BIN (desktop_plugin->priv->pipeline), bin);
106 bus = gst_pipeline_get_bus (GST_PIPELINE (desktop_plugin->priv->pipeline));
107 // gst_bus_add_watch(bus, bus_call, NULL);
108 gst_object_unref (bus);
110 file_plus_uri = g_strdup_printf("file://%s",desktop_plugin->priv->theme_string_parametr1);
111 g_object_set (G_OBJECT (bin), "uri", file_plus_uri, NULL );
112 g_object_set (G_OBJECT (videosink), "force-aspect-ratio", TRUE, NULL );
113 if (GST_IS_X_OVERLAY (videosink))
114 gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (videosink), GDK_DRAWABLE_XID(desktop_plugin->priv->window->window));
115 if (desktop_plugin->priv->visible)
116 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
120 init_scene_Matrix(AWallpaperPlugin *desktop_plugin)
125 gint now = time(NULL);
128 if (desktop_plugin->priv->rich_animation){
136 /* fprintf(stderr, "init scene2 \n"); */
137 scene = g_new0(Scene, 1);
138 //scene.daytime = get_daytime();
139 scene->actors = NULL;
140 desktop_plugin->priv->scene = scene;
142 actor = init_object(desktop_plugin, "background", "bg.png",
144 TRUE, TRUE, 100, 255,
146 scene->actors = g_slist_append(scene->actors, actor);
148 actor = init_object(desktop_plugin, "symbols", "symbols.png",
150 TRUE, TRUE, 100, 255,
152 scene->actors = g_slist_append(scene->actors, actor);
154 child = g_ptr_array_sized_new(4);
155 actor = init_object(desktop_plugin, "layer1", "layer1_2.png",
157 TRUE, TRUE, 100, 255,
159 //actor->time_start_animation = now;
160 //actor->duration_animation = G_MAXINT;
161 scene->actors = g_slist_append(scene->actors, actor);
162 g_ptr_array_add(child, actor);
164 actor = init_object(desktop_plugin, "layer1", "layer1_1.png",
166 TRUE, TRUE, 100, 255,
168 //actor->time_start_animation = now;
169 //actor->duration_animation = G_MAXINT;
170 scene->actors = g_slist_append(scene->actors, actor);
171 g_ptr_array_add(child, actor);
173 actor = init_object(desktop_plugin, "layer2", "layer2_2.png",
175 TRUE, TRUE, 100, 255,
177 //actor->time_start_animation = now;
178 //actor->duration_animation = G_MAXINT;
179 scene->actors = g_slist_append(scene->actors, actor);
180 g_ptr_array_add(child, actor);
182 actor = init_object(desktop_plugin, "layer2", "layer2_1.png",
184 TRUE, TRUE, 100, 255,
186 //actor->time_start_animation = now;
187 //actor->duration_animation = G_MAXINT;
188 scene->actors = g_slist_append(scene->actors, actor);
189 g_ptr_array_add(child, actor);
191 actor = init_object(desktop_plugin, "layers", "",
193 FALSE, FALSE, 100, 255,
194 (gpointer)&change_layer, NULL, child);
195 actor->time_start_animation = now;
196 actor->duration_animation = G_MAXINT;
197 scene->actors = g_slist_append(scene->actors, actor);
199 run_long_timeout(desktop_plugin);
203 /* Init Modern Scene */
205 init_scene_Modern(AWallpaperPlugin *desktop_plugin)
209 gint now = time(NULL);
214 /* fprintf(stderr, "init scene \n"); */
215 scene = g_new0(Scene, 1);
216 scene->daytime = get_daytime();
217 scene->actors = NULL;
218 scene->wind_orientation = -1;
219 scene->wind_angle = 0.3;
220 /* init value for random */
221 scene->seed = time(NULL);
222 scene->notification = TRUE;
223 desktop_plugin->priv->scene = scene;
224 actor = init_object(desktop_plugin, "sky", "sky0.png",
226 TRUE , TRUE, 100, 255,
227 (gpointer)&change_static_actor, NULL, NULL);
228 scene->actors = g_slist_append(scene->actors, actor);
229 change_static_actor(actor, desktop_plugin);
231 actor = init_object(desktop_plugin, "sun", "sun.png",
233 FALSE, FALSE, 100, 255,
234 (gpointer)&change_sun, NULL, NULL);
235 actor->time_start_animation = now;
236 actor->duration_animation = G_MAXINT;
237 change_sun(actor, desktop_plugin);
238 scene->actors = g_slist_append(scene->actors, actor);
240 //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
241 // TRUE, 100, 255, NULL, NULL);
242 //scene.actors = g_slist_append(scene.actors, actor);
244 actor = init_object(desktop_plugin, "cloud1", "cloud1.png",
245 0, fast_rnd(300)-97, 7, 150, 97,
246 FALSE, FALSE, 100, 255,
247 (gpointer)&change_cloud, NULL, NULL);
248 actor->time_start_animation = now + fast_rnd(20);
249 actor->duration_animation = 3*60;
250 scene->actors = g_slist_append(scene->actors, actor);
252 actor = init_object(desktop_plugin, "cloud2", "cloud2.png",
253 0, fast_rnd(300)-75, 7, 188, 75,
254 FALSE, FALSE, 100, 255,
255 (gpointer)&change_cloud, NULL, NULL);
256 actor->time_start_animation = now + fast_rnd(40)+10;
257 actor->duration_animation = 3*60;
258 scene->actors = g_slist_append(scene->actors, actor);
260 actor = init_object(desktop_plugin, "cloud4", "cloud4.png",
261 0, fast_rnd(300)-75, 7, 150, 75,
262 FALSE, FALSE, 100, 255,
263 (gpointer)&change_cloud, NULL, NULL);
264 actor->time_start_animation = now + fast_rnd(60) + 20;
265 actor->duration_animation = 5*60;
266 scene->actors = g_slist_append(scene->actors, actor);
269 actor = init_object(desktop_plugin, "town", "town0.png",
271 TRUE, TRUE, 100, 255,
272 (gpointer)&change_static_actor, NULL, NULL);
273 change_static_actor(actor, desktop_plugin);
274 scene->actors = g_slist_append(scene->actors, actor);
276 actor = init_object(desktop_plugin, "stend", "stend0.png",
277 452, 166, 9, 300, 305,
278 TRUE, TRUE, 100, 255,
279 (gpointer)&change_static_actor, NULL, NULL);
280 change_static_actor(actor, desktop_plugin);
281 scene->actors = g_slist_append(scene->actors, actor);
284 child = g_ptr_array_sized_new(4);
285 actor = init_object(desktop_plugin, "call", "call.png",
287 FALSE, TRUE, 100, 255,
289 scene->actors = g_slist_append(scene->actors, actor);
290 g_ptr_array_add(child, actor);
292 actor = init_object(desktop_plugin, "chat", "chat.png",
294 FALSE, TRUE, 100, 255,
296 scene->actors = g_slist_append(scene->actors, actor);
297 g_ptr_array_add(child, actor);
299 actor = init_object(desktop_plugin, "mail", "mail.png",
301 FALSE, TRUE, 100, 255,
303 scene->actors = g_slist_append(scene->actors, actor);
304 g_ptr_array_add(child, actor);
306 actor = init_object(desktop_plugin, "sms", "sms.png",
308 FALSE, TRUE, 100, 255,
310 scene->actors = g_slist_append(scene->actors, actor);
311 g_ptr_array_add(child, actor);
313 actor = init_object(desktop_plugin, "billboard_text", "",
314 470, 174, 9, 300, 108,
315 FALSE, FALSE, 100, 255,
316 (gpointer)&change_billboard, NULL, child);
317 create_hildon_actor_text(actor, desktop_plugin);
318 //actor->time_start_animation = time(NULL) + 20;
319 change_billboard(actor, desktop_plugin);
320 scene->actors = g_slist_append(scene->actors, actor);
322 actor = init_object(desktop_plugin, "tram", "tram.png",
323 -300, 225, 10, 350, 210,
324 FALSE, FALSE, 100, 255,
325 (gpointer)&change_tram, NULL, NULL);
326 actor->time_start_animation = time(NULL) + fast_rnd(10);
327 actor->duration_animation = 60;
328 scene->actors = g_slist_append(scene->actors, actor);
330 actor = init_object(desktop_plugin, "border", "border0.png",
331 0, 480-79, 11, 800, 79,
332 TRUE, TRUE, 100, 255,
333 (gpointer)&change_static_actor_with_corner, NULL, NULL);
334 change_static_actor_with_corner(actor, desktop_plugin);
335 scene->actors = g_slist_append(scene->actors, actor);
337 actor = init_object(desktop_plugin, "moon", "moon1.png",
339 FALSE, FALSE, 100, 255,
340 (gpointer)&change_moon, NULL, NULL);
341 change_moon(actor, desktop_plugin);
342 scene->actors = g_slist_append(scene->actors, actor);
344 actor = init_object(desktop_plugin, "wind", "",
346 FALSE, FALSE, 100, 255,
347 (gpointer)&change_wind, NULL, NULL);
348 change_wind(actor, desktop_plugin);
349 scene->actors = g_slist_append(scene->actors, actor);
351 /* windows in 4-th house */
391 for (i=0; i<13; i++){
392 actor = init_object(desktop_plugin, "window1", "window1.png",
393 winds[i][0], winds[i][1], 8, 8, 10,
394 FALSE, FALSE, 100, 255,
395 (gpointer)&change_window1, NULL, NULL);
396 //change_window1(actor, desktop_plugin);
397 actor->time_start_animation = now + fast_rnd(30);
398 scene->actors = g_slist_append(scene->actors, actor);
402 /* windows in 1-th house */
428 actor = init_object(desktop_plugin, "window2", "window2.png",
429 winds[i][0], winds[i][1], 8, 8, 10,
430 FALSE, FALSE, 100, 255,
431 (gpointer)&change_window1, NULL, NULL);
432 //change_window1(actor, desktop_plugin);
433 actor->time_start_animation = now + fast_rnd(30);
434 scene->actors = g_slist_append(scene->actors, actor);
438 /* windows in 3-th house */
470 for (i=0; i<10; i++){
471 actor = init_object(desktop_plugin, "window3", "window3.png",
472 winds[i][0], winds[i][1], 8, 8, 10,
473 FALSE, FALSE, 100, 255,
474 (gpointer)&change_window1, NULL, NULL);
475 //change_window1(actor, desktop_plugin);
476 actor->time_start_animation = now + fast_rnd(30);
477 scene->actors = g_slist_append(scene->actors, actor);
481 /* windows in 5-th house */
505 actor = init_object(desktop_plugin, "window4", "window4.png",
506 winds[i][0], winds[i][1], 8, 8, 10,
507 FALSE, FALSE, 100, 255,
508 (gpointer)&change_window1, NULL, NULL);
509 //change_window1(actor, desktop_plugin);
510 actor->time_start_animation = now + fast_rnd(30);
511 scene->actors = g_slist_append(scene->actors, actor);
515 /* windows in 6-th house */
536 actor = init_object(desktop_plugin, "window5", "window5.png",
537 winds[i][0], winds[i][1], 8, 8, 10,
538 FALSE, FALSE, 100, 255,
539 (gpointer)&change_window1, NULL, NULL);
540 //change_window1(actor, desktop_plugin);
541 actor->time_start_animation = now + fast_rnd(30);
542 scene->actors = g_slist_append(scene->actors, actor);
545 run_long_timeout(desktop_plugin);
548 anim = g_new0(Animation, 1);
551 anim->func_change = &change_tram;
552 anim->func_time = NULL;
553 anim->timestart = time(NULL);
556 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
560 /* Init Berlin Scene */
562 init_scene_Berlin(AWallpaperPlugin *desktop_plugin)
564 Actor *actor, *actor1, *actor2;
566 gint now = time(NULL);
569 GPtrArray *child = NULL;
571 scene = g_new0(Scene, 1);
572 scene->daytime = get_daytime();
573 scene->actors = NULL;
574 scene->wind_orientation = -1;
575 scene->wind_angle = 0.3;
576 /* init value for random */
577 scene->seed = time(NULL);
578 desktop_plugin->priv->scene = scene;
580 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
581 TRUE, TRUE, 100, 255,
582 (gpointer)&change_static_actor, NULL, NULL);
583 change_static_actor(actor, desktop_plugin);
584 scene->actors = g_slist_append(scene->actors, actor);
587 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
588 FALSE, FALSE, 100, 255,
589 (gpointer)&change_sun, NULL, NULL);
590 actor->time_start_animation = time(NULL);
591 actor->duration_animation = G_MAXINT;
592 change_sun(actor, desktop_plugin);
593 scene->actors = g_slist_append(scene->actors, actor);
596 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
597 TRUE, 100, 255, NULL, NULL);
598 scene.actors = g_slist_append(scene.actors, actor);
601 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
602 FALSE, FALSE, 100, 255,
603 (gpointer)&change_moon, NULL, NULL);
604 change_moon(actor, desktop_plugin);
605 scene->actors = g_slist_append(scene->actors, actor);
607 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
608 FALSE, FALSE, 100, 255,
609 (gpointer)&change_cloud, NULL, NULL);
610 actor->time_start_animation = now + fast_rnd(30) + 10;
611 actor->duration_animation = 3*60;
612 scene->actors = g_slist_append(scene->actors, actor);
614 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
615 FALSE, FALSE, 100, 255,
616 (gpointer)&change_cloud, NULL, NULL);
617 actor->time_start_animation = now + fast_rnd(10);
618 actor->duration_animation = 3*60;
619 scene->actors = g_slist_append(scene->actors, actor);
621 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
622 FALSE, FALSE, 100, 255,
623 (gpointer)&change_cloud, NULL, NULL);
624 actor->time_start_animation = now + fast_rnd(60) + 20;
625 actor->duration_animation = 5*60;
626 scene->actors = g_slist_append(scene->actors, actor);
629 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
630 FALSE, FALSE, 100, 255,
631 (gpointer)&change_plane2, NULL, NULL);
632 actor->time_start_animation = now + fast_rnd(40) + 20;
633 actor->duration_animation = 60;
634 scene->actors = g_slist_append(scene->actors, actor);
636 actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116,
637 FALSE, FALSE, 100, 255,
638 (gpointer)&change_plane1, NULL, NULL);
639 actor->time_start_animation = now + fast_rnd(20);
640 actor->duration_animation = 30;
641 scene->actors = g_slist_append(scene->actors, actor);
643 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
644 TRUE, TRUE, 100, 255,
645 (gpointer)&change_static_actor_with_corner, NULL, NULL);
646 change_static_actor_with_corner(actor, desktop_plugin);
647 scene->actors = g_slist_append(scene->actors, actor);
649 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
650 FALSE, FALSE, 100, 255,
651 (gpointer)&change_wind, NULL, NULL);
652 change_wind(actor, desktop_plugin);
653 scene->actors = g_slist_append(scene->actors, actor);
655 actor1 = init_object(desktop_plugin, "signal_red", "red.png",
656 486, 425, 10, 18, 38,
657 FALSE, TRUE, 100, 255, NULL, NULL, NULL);
658 //actor->time_start_animation = now + fast_rnd(30) + 10;
659 scene->actors = g_slist_append(scene->actors, actor1);
661 actor2 = init_object(desktop_plugin, "signal_green", "green.png",
662 486, 425, 10, 18, 38,
663 TRUE, TRUE, 100, 255, NULL, NULL, NULL);
664 //actor->time_start_animation = now + fast_rnd(30) + 10;
665 scene->actors = g_slist_append(scene->actors, actor2);
666 child = g_ptr_array_sized_new(2);
667 g_ptr_array_add(child, actor1);
668 g_ptr_array_add(child, actor2);
669 actor = init_object(desktop_plugin, "signal", "",
670 486, 425, 10, 18, 38,
671 FALSE, FALSE, 100, 255,
672 (gpointer)&change_signal, NULL, child);
673 actor->time_start_animation = now + fast_rnd(30) + 10;
674 scene->actors = g_slist_append(scene->actors, actor);
715 for (i=0; i<13; i++){
716 actor = init_object(desktop_plugin, "window", "window.png",
717 winds[i][0], winds[i][1], 10, 8, 9,
718 FALSE, TRUE, 100, 255,
719 (gpointer)&change_window1, NULL, NULL);
720 //change_window1(actor, desktop_plugin);
721 actor->time_start_animation = now + fast_rnd(30);
722 scene->actors = g_slist_append(scene->actors, actor);
726 run_long_timeout(desktop_plugin);
731 init_scene_theme(AWallpaperPlugin *desktop_plugin)
733 void (*func)(gpointer);
734 func = g_hash_table_lookup(desktop_plugin->priv->hash_scene_func, desktop_plugin->priv->theme);
736 (*func)(desktop_plugin);