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 bus_call (GstBus *bus, GstMessage *msg, AWallpaperPlugin *desktop_plugin)
92 switch (GST_MESSAGE_TYPE (msg))
95 if (desktop_plugin->priv->rich_animation){
96 gst_element_set_start_time(desktop_plugin->priv->pipeline, 0);
97 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
100 case GST_MESSAGE_ERROR: break;
107 init_scene_Video(AWallpaperPlugin *desktop_plugin)
110 GstElement *videosink;
112 gchar *file_plus_uri;
115 desktop_plugin->priv->pipeline = gst_pipeline_new("gst-player");
116 bin = gst_element_factory_make ("playbin2", "bin");
117 videosink = gst_element_factory_make ("ximagesink", "videosink");
118 g_object_set (G_OBJECT (bin), "video-sink", videosink, NULL);
119 gst_bin_add (GST_BIN (desktop_plugin->priv->pipeline), bin);
123 bus = gst_pipeline_get_bus (GST_PIPELINE (desktop_plugin->priv->pipeline));
124 gst_bus_add_watch(bus, bus_call, desktop_plugin);
125 gst_object_unref (bus);
127 file_plus_uri = g_strdup_printf("file://%s",desktop_plugin->priv->theme_string_parametr1);
128 g_object_set (G_OBJECT (bin), "uri", file_plus_uri, NULL );
129 g_object_set (G_OBJECT (videosink), "force-aspect-ratio", TRUE, NULL );
130 if (GST_IS_X_OVERLAY (videosink))
131 gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (videosink), GDK_DRAWABLE_XID(desktop_plugin->priv->window->window));
132 if (desktop_plugin->priv->visible)
133 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
137 init_scene_Matrix(AWallpaperPlugin *desktop_plugin)
142 gint now = time(NULL);
145 if (desktop_plugin->priv->rich_animation){
153 /* fprintf(stderr, "init scene2 \n"); */
154 scene = g_new0(Scene, 1);
155 //scene.daytime = get_daytime();
156 scene->actors = NULL;
157 desktop_plugin->priv->scene = scene;
159 actor = init_object(desktop_plugin, "background", "bg.png",
161 TRUE, TRUE, 100, 255,
163 scene->actors = g_slist_append(scene->actors, actor);
165 actor = init_object(desktop_plugin, "symbols", "symbols.png",
167 TRUE, TRUE, 100, 255,
169 scene->actors = g_slist_append(scene->actors, actor);
171 child = g_ptr_array_sized_new(4);
172 actor = init_object(desktop_plugin, "layer1", "layer1_2.png",
174 TRUE, TRUE, 100, 255,
176 //actor->time_start_animation = now;
177 //actor->duration_animation = G_MAXINT;
178 scene->actors = g_slist_append(scene->actors, actor);
179 g_ptr_array_add(child, actor);
181 actor = init_object(desktop_plugin, "layer1", "layer1_1.png",
183 TRUE, TRUE, 100, 255,
185 //actor->time_start_animation = now;
186 //actor->duration_animation = G_MAXINT;
187 scene->actors = g_slist_append(scene->actors, actor);
188 g_ptr_array_add(child, actor);
190 actor = init_object(desktop_plugin, "layer2", "layer2_2.png",
192 TRUE, TRUE, 100, 255,
194 //actor->time_start_animation = now;
195 //actor->duration_animation = G_MAXINT;
196 scene->actors = g_slist_append(scene->actors, actor);
197 g_ptr_array_add(child, actor);
199 actor = init_object(desktop_plugin, "layer2", "layer2_1.png",
201 TRUE, TRUE, 100, 255,
203 //actor->time_start_animation = now;
204 //actor->duration_animation = G_MAXINT;
205 scene->actors = g_slist_append(scene->actors, actor);
206 g_ptr_array_add(child, actor);
208 actor = init_object(desktop_plugin, "layers", "",
210 FALSE, FALSE, 100, 255,
211 (gpointer)&change_layer, NULL, child);
212 actor->time_start_animation = now;
213 actor->duration_animation = G_MAXINT;
214 scene->actors = g_slist_append(scene->actors, actor);
216 run_long_timeout(desktop_plugin);
220 /* Init Modern Scene */
222 init_scene_Modern(AWallpaperPlugin *desktop_plugin)
226 gint now = time(NULL);
231 /* fprintf(stderr, "init scene \n"); */
232 scene = g_new0(Scene, 1);
233 scene->daytime = get_daytime();
234 scene->actors = NULL;
235 scene->wind_orientation = -1;
236 scene->wind_angle = 0.3;
237 /* init value for random */
238 scene->seed = time(NULL);
239 scene->notification = TRUE;
240 desktop_plugin->priv->scene = scene;
241 actor = init_object(desktop_plugin, "sky", "sky0.png",
243 TRUE , TRUE, 100, 255,
244 (gpointer)&change_static_actor, NULL, NULL);
245 scene->actors = g_slist_append(scene->actors, actor);
246 change_static_actor(actor, desktop_plugin);
248 actor = init_object(desktop_plugin, "sun", "sun.png",
250 FALSE, FALSE, 100, 255,
251 (gpointer)&change_sun, NULL, NULL);
252 actor->time_start_animation = now;
253 actor->duration_animation = G_MAXINT;
254 change_sun(actor, desktop_plugin);
255 scene->actors = g_slist_append(scene->actors, actor);
257 //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
258 // TRUE, 100, 255, NULL, NULL);
259 //scene.actors = g_slist_append(scene.actors, actor);
261 actor = init_object(desktop_plugin, "cloud1", "cloud1.png",
262 0, fast_rnd(300)-97, 7, 150, 97,
263 FALSE, FALSE, 100, 255,
264 (gpointer)&change_cloud, NULL, NULL);
265 actor->time_start_animation = now + fast_rnd(20);
266 actor->duration_animation = 3*60;
267 scene->actors = g_slist_append(scene->actors, actor);
269 actor = init_object(desktop_plugin, "cloud2", "cloud2.png",
270 0, fast_rnd(300)-75, 7, 188, 75,
271 FALSE, FALSE, 100, 255,
272 (gpointer)&change_cloud, NULL, NULL);
273 actor->time_start_animation = now + fast_rnd(40)+10;
274 actor->duration_animation = 3*60;
275 scene->actors = g_slist_append(scene->actors, actor);
277 actor = init_object(desktop_plugin, "cloud4", "cloud4.png",
278 0, fast_rnd(300)-75, 7, 150, 75,
279 FALSE, FALSE, 100, 255,
280 (gpointer)&change_cloud, NULL, NULL);
281 actor->time_start_animation = now + fast_rnd(60) + 20;
282 actor->duration_animation = 5*60;
283 scene->actors = g_slist_append(scene->actors, actor);
286 actor = init_object(desktop_plugin, "town", "town0.png",
288 TRUE, TRUE, 100, 255,
289 (gpointer)&change_static_actor, NULL, NULL);
290 change_static_actor(actor, desktop_plugin);
291 scene->actors = g_slist_append(scene->actors, actor);
293 actor = init_object(desktop_plugin, "stend", "stend0.png",
294 452, 166, 9, 300, 305,
295 TRUE, TRUE, 100, 255,
296 (gpointer)&change_static_actor, NULL, NULL);
297 change_static_actor(actor, desktop_plugin);
298 scene->actors = g_slist_append(scene->actors, actor);
301 child = g_ptr_array_sized_new(4);
302 actor = init_object(desktop_plugin, "call", "call.png",
304 FALSE, TRUE, 100, 255,
306 scene->actors = g_slist_append(scene->actors, actor);
307 g_ptr_array_add(child, actor);
309 actor = init_object(desktop_plugin, "chat", "chat.png",
311 FALSE, TRUE, 100, 255,
313 scene->actors = g_slist_append(scene->actors, actor);
314 g_ptr_array_add(child, actor);
316 actor = init_object(desktop_plugin, "mail", "mail.png",
318 FALSE, TRUE, 100, 255,
320 scene->actors = g_slist_append(scene->actors, actor);
321 g_ptr_array_add(child, actor);
323 actor = init_object(desktop_plugin, "sms", "sms.png",
325 FALSE, TRUE, 100, 255,
327 scene->actors = g_slist_append(scene->actors, actor);
328 g_ptr_array_add(child, actor);
330 actor = init_object(desktop_plugin, "billboard_text", "",
331 470, 174, 9, 300, 108,
332 FALSE, FALSE, 100, 255,
333 (gpointer)&change_billboard, NULL, child);
334 create_hildon_actor_text(actor, desktop_plugin);
335 //actor->time_start_animation = time(NULL) + 20;
336 change_billboard(actor, desktop_plugin);
337 scene->actors = g_slist_append(scene->actors, actor);
339 actor = init_object(desktop_plugin, "tram", "tram.png",
340 -300, 225, 10, 350, 210,
341 FALSE, FALSE, 100, 255,
342 (gpointer)&change_tram, NULL, NULL);
343 actor->time_start_animation = time(NULL) + fast_rnd(10);
344 actor->duration_animation = 60;
345 scene->actors = g_slist_append(scene->actors, actor);
347 actor = init_object(desktop_plugin, "border", "border0.png",
348 0, 480-79, 11, 800, 79,
349 TRUE, TRUE, 100, 255,
350 (gpointer)&change_static_actor_with_corner, NULL, NULL);
351 change_static_actor_with_corner(actor, desktop_plugin);
352 scene->actors = g_slist_append(scene->actors, actor);
354 actor = init_object(desktop_plugin, "moon", "moon1.png",
356 FALSE, FALSE, 100, 255,
357 (gpointer)&change_moon, NULL, NULL);
358 change_moon(actor, desktop_plugin);
359 scene->actors = g_slist_append(scene->actors, actor);
361 actor = init_object(desktop_plugin, "wind", "",
363 FALSE, FALSE, 100, 255,
364 (gpointer)&change_wind, NULL, NULL);
365 change_wind(actor, desktop_plugin);
366 scene->actors = g_slist_append(scene->actors, actor);
368 /* windows in 4-th house */
408 for (i=0; i<13; i++){
409 actor = init_object(desktop_plugin, "window1", "window1.png",
410 winds[i][0], winds[i][1], 8, 8, 10,
411 FALSE, FALSE, 100, 255,
412 (gpointer)&change_window1, NULL, NULL);
413 //change_window1(actor, desktop_plugin);
414 actor->time_start_animation = now + fast_rnd(30);
415 scene->actors = g_slist_append(scene->actors, actor);
419 /* windows in 1-th house */
445 actor = init_object(desktop_plugin, "window2", "window2.png",
446 winds[i][0], winds[i][1], 8, 8, 10,
447 FALSE, FALSE, 100, 255,
448 (gpointer)&change_window1, NULL, NULL);
449 //change_window1(actor, desktop_plugin);
450 actor->time_start_animation = now + fast_rnd(30);
451 scene->actors = g_slist_append(scene->actors, actor);
455 /* windows in 3-th house */
487 for (i=0; i<10; i++){
488 actor = init_object(desktop_plugin, "window3", "window3.png",
489 winds[i][0], winds[i][1], 8, 8, 10,
490 FALSE, FALSE, 100, 255,
491 (gpointer)&change_window1, NULL, NULL);
492 //change_window1(actor, desktop_plugin);
493 actor->time_start_animation = now + fast_rnd(30);
494 scene->actors = g_slist_append(scene->actors, actor);
498 /* windows in 5-th house */
522 actor = init_object(desktop_plugin, "window4", "window4.png",
523 winds[i][0], winds[i][1], 8, 8, 10,
524 FALSE, FALSE, 100, 255,
525 (gpointer)&change_window1, NULL, NULL);
526 //change_window1(actor, desktop_plugin);
527 actor->time_start_animation = now + fast_rnd(30);
528 scene->actors = g_slist_append(scene->actors, actor);
532 /* windows in 6-th house */
553 actor = init_object(desktop_plugin, "window5", "window5.png",
554 winds[i][0], winds[i][1], 8, 8, 10,
555 FALSE, FALSE, 100, 255,
556 (gpointer)&change_window1, NULL, NULL);
557 //change_window1(actor, desktop_plugin);
558 actor->time_start_animation = now + fast_rnd(30);
559 scene->actors = g_slist_append(scene->actors, actor);
562 run_long_timeout(desktop_plugin);
565 anim = g_new0(Animation, 1);
568 anim->func_change = &change_tram;
569 anim->func_time = NULL;
570 anim->timestart = time(NULL);
573 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
577 /* Init Berlin Scene */
579 init_scene_Berlin(AWallpaperPlugin *desktop_plugin)
581 Actor *actor, *actor1, *actor2;
583 gint now = time(NULL);
586 GPtrArray *child = NULL;
588 scene = g_new0(Scene, 1);
589 scene->daytime = get_daytime();
590 scene->actors = NULL;
591 scene->wind_orientation = -1;
592 scene->wind_angle = 0.3;
593 /* init value for random */
594 scene->seed = time(NULL);
595 desktop_plugin->priv->scene = scene;
597 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
598 TRUE, TRUE, 100, 255,
599 (gpointer)&change_static_actor, NULL, NULL);
600 change_static_actor(actor, desktop_plugin);
601 scene->actors = g_slist_append(scene->actors, actor);
604 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
605 FALSE, FALSE, 100, 255,
606 (gpointer)&change_sun, NULL, NULL);
607 actor->time_start_animation = time(NULL);
608 actor->duration_animation = G_MAXINT;
609 change_sun(actor, desktop_plugin);
610 scene->actors = g_slist_append(scene->actors, actor);
613 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
614 TRUE, 100, 255, NULL, NULL);
615 scene.actors = g_slist_append(scene.actors, actor);
618 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
619 FALSE, FALSE, 100, 255,
620 (gpointer)&change_moon, NULL, NULL);
621 change_moon(actor, desktop_plugin);
622 scene->actors = g_slist_append(scene->actors, actor);
624 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
625 FALSE, FALSE, 100, 255,
626 (gpointer)&change_cloud, NULL, NULL);
627 actor->time_start_animation = now + fast_rnd(30) + 10;
628 actor->duration_animation = 3*60;
629 scene->actors = g_slist_append(scene->actors, actor);
631 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
632 FALSE, FALSE, 100, 255,
633 (gpointer)&change_cloud, NULL, NULL);
634 actor->time_start_animation = now + fast_rnd(10);
635 actor->duration_animation = 3*60;
636 scene->actors = g_slist_append(scene->actors, actor);
638 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
639 FALSE, FALSE, 100, 255,
640 (gpointer)&change_cloud, NULL, NULL);
641 actor->time_start_animation = now + fast_rnd(60) + 20;
642 actor->duration_animation = 5*60;
643 scene->actors = g_slist_append(scene->actors, actor);
646 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
647 FALSE, FALSE, 100, 255,
648 (gpointer)&change_plane2, NULL, NULL);
649 actor->time_start_animation = now + fast_rnd(40) + 20;
650 actor->duration_animation = 60;
651 scene->actors = g_slist_append(scene->actors, actor);
653 actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116,
654 FALSE, FALSE, 100, 255,
655 (gpointer)&change_plane1, NULL, NULL);
656 actor->time_start_animation = now + fast_rnd(20);
657 actor->duration_animation = 30;
658 scene->actors = g_slist_append(scene->actors, actor);
660 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
661 TRUE, TRUE, 100, 255,
662 (gpointer)&change_static_actor_with_corner, NULL, NULL);
663 change_static_actor_with_corner(actor, desktop_plugin);
664 scene->actors = g_slist_append(scene->actors, actor);
666 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
667 FALSE, FALSE, 100, 255,
668 (gpointer)&change_wind, NULL, NULL);
669 change_wind(actor, desktop_plugin);
670 scene->actors = g_slist_append(scene->actors, actor);
672 actor1 = init_object(desktop_plugin, "signal_red", "red.png",
673 486, 425, 10, 18, 38,
674 FALSE, TRUE, 100, 255, NULL, NULL, NULL);
675 //actor->time_start_animation = now + fast_rnd(30) + 10;
676 scene->actors = g_slist_append(scene->actors, actor1);
678 actor2 = init_object(desktop_plugin, "signal_green", "green.png",
679 486, 425, 10, 18, 38,
680 TRUE, TRUE, 100, 255, NULL, NULL, NULL);
681 //actor->time_start_animation = now + fast_rnd(30) + 10;
682 scene->actors = g_slist_append(scene->actors, actor2);
683 child = g_ptr_array_sized_new(2);
684 g_ptr_array_add(child, actor1);
685 g_ptr_array_add(child, actor2);
686 actor = init_object(desktop_plugin, "signal", "",
687 486, 425, 10, 18, 38,
688 FALSE, FALSE, 100, 255,
689 (gpointer)&change_signal, NULL, child);
690 actor->time_start_animation = now + fast_rnd(30) + 10;
691 scene->actors = g_slist_append(scene->actors, actor);
732 for (i=0; i<13; i++){
733 actor = init_object(desktop_plugin, "window", "window.png",
734 winds[i][0], winds[i][1], 10, 8, 9,
735 FALSE, TRUE, 100, 255,
736 (gpointer)&change_window1, NULL, NULL);
737 //change_window1(actor, desktop_plugin);
738 actor->time_start_animation = now + fast_rnd(30);
739 scene->actors = g_slist_append(scene->actors, actor);
743 run_long_timeout(desktop_plugin);
748 init_scene_theme(AWallpaperPlugin *desktop_plugin)
750 void (*func)(gpointer);
751 func = g_hash_table_lookup(desktop_plugin->priv->hash_scene_func, desktop_plugin->priv->theme);
753 (*func)(desktop_plugin);