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 fprintf(stderr,"GST_MESSAGE_EOS:\n");
96 if (desktop_plugin->priv->rich_animation){
97 fprintf(stderr,"GST_MESSAGE_EOS222222222222222222222222\n");
98 GstClockTime nach = (GstClockTime)(10 * GST_MSECOND);
99 if (!gst_element_seek(desktop_plugin->priv->pipeline, 1.0, GST_FORMAT_TIME, (GstSeekFlags) (GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT), GST_SEEK_TYPE_SET, nach, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
100 fprintf(stderr,"ERROR in seek\n");
106 // gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_READY);
108 // gst_element_set_start_time(desktop_plugin->priv->pipeline, 0);
109 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
111 fprintf(stderr,"GST_MESSAGE_EOS33333333333333333333\n");
112 if (desktop_plugin->priv->pipeline){ gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_NULL); gst_object_unref (GST_OBJECT (desktop_plugin->priv->pipeline));
116 case GST_MESSAGE_ERROR: break;
123 init_scene_Video(AWallpaperPlugin *desktop_plugin)
126 GstElement *videosink;
128 gchar *file_plus_uri;
131 desktop_plugin->priv->pipeline = gst_pipeline_new("gst-player");
132 bin = gst_element_factory_make ("playbin2", "bin");
133 videosink = gst_element_factory_make ("ximagesink", "videosink");
134 g_object_set (G_OBJECT (bin), "video-sink", videosink, NULL);
135 gst_bin_add (GST_BIN (desktop_plugin->priv->pipeline), bin);
139 bus = gst_pipeline_get_bus (GST_PIPELINE (desktop_plugin->priv->pipeline));
140 gst_bus_add_watch(bus, bus_call, desktop_plugin);
141 gst_object_unref (bus);
143 file_plus_uri = g_strdup_printf("file://%s",desktop_plugin->priv->theme_string_parametr1);
144 g_object_set (G_OBJECT (bin), "uri", file_plus_uri, NULL );
145 g_object_set (G_OBJECT (videosink), "force-aspect-ratio", TRUE, NULL );
146 if (GST_IS_X_OVERLAY (videosink))
147 gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (videosink), GDK_DRAWABLE_XID(desktop_plugin->priv->window->window));
148 if (desktop_plugin->priv->visible)
149 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
153 init_scene_Matrix(AWallpaperPlugin *desktop_plugin)
158 gint now = time(NULL);
161 if (desktop_plugin->priv->rich_animation){
169 /* fprintf(stderr, "init scene2 \n"); */
170 scene = g_new0(Scene, 1);
171 //scene.daytime = get_daytime();
172 scene->actors = NULL;
173 desktop_plugin->priv->scene = scene;
175 actor = init_object(desktop_plugin, "background", "bg.png",
177 TRUE, TRUE, 100, 255,
179 scene->actors = g_slist_append(scene->actors, actor);
181 actor = init_object(desktop_plugin, "symbols", "symbols.png",
183 TRUE, TRUE, 100, 255,
185 scene->actors = g_slist_append(scene->actors, actor);
187 child = g_ptr_array_sized_new(4);
188 actor = init_object(desktop_plugin, "layer1", "layer1_2.png",
190 TRUE, TRUE, 100, 255,
192 //actor->time_start_animation = now;
193 //actor->duration_animation = G_MAXINT;
194 scene->actors = g_slist_append(scene->actors, actor);
195 g_ptr_array_add(child, actor);
197 actor = init_object(desktop_plugin, "layer1", "layer1_1.png",
199 TRUE, TRUE, 100, 255,
201 //actor->time_start_animation = now;
202 //actor->duration_animation = G_MAXINT;
203 scene->actors = g_slist_append(scene->actors, actor);
204 g_ptr_array_add(child, actor);
206 actor = init_object(desktop_plugin, "layer2", "layer2_2.png",
208 TRUE, TRUE, 100, 255,
210 //actor->time_start_animation = now;
211 //actor->duration_animation = G_MAXINT;
212 scene->actors = g_slist_append(scene->actors, actor);
213 g_ptr_array_add(child, actor);
215 actor = init_object(desktop_plugin, "layer2", "layer2_1.png",
217 TRUE, TRUE, 100, 255,
219 //actor->time_start_animation = now;
220 //actor->duration_animation = G_MAXINT;
221 scene->actors = g_slist_append(scene->actors, actor);
222 g_ptr_array_add(child, actor);
224 actor = init_object(desktop_plugin, "layers", "",
226 FALSE, FALSE, 100, 255,
227 (gpointer)&change_layer, NULL, child);
228 actor->time_start_animation = now;
229 actor->duration_animation = G_MAXINT;
230 scene->actors = g_slist_append(scene->actors, actor);
232 run_long_timeout(desktop_plugin);
236 /* Init Modern Scene */
238 init_scene_Modern(AWallpaperPlugin *desktop_plugin)
242 gint now = time(NULL);
247 /* fprintf(stderr, "init scene \n"); */
248 scene = g_new0(Scene, 1);
249 scene->daytime = get_daytime();
250 scene->actors = NULL;
251 scene->wind_orientation = -1;
252 scene->wind_angle = 0.3;
253 /* init value for random */
254 scene->seed = time(NULL);
255 scene->notification = TRUE;
256 desktop_plugin->priv->scene = scene;
257 actor = init_object(desktop_plugin, "sky", "sky0.png",
259 TRUE , TRUE, 100, 255,
260 (gpointer)&change_static_actor, NULL, NULL);
261 scene->actors = g_slist_append(scene->actors, actor);
262 change_static_actor(actor, desktop_plugin);
264 actor = init_object(desktop_plugin, "sun", "sun.png",
266 FALSE, FALSE, 100, 255,
267 (gpointer)&change_sun, NULL, NULL);
268 actor->time_start_animation = now;
269 actor->duration_animation = G_MAXINT;
270 change_sun(actor, desktop_plugin);
271 scene->actors = g_slist_append(scene->actors, actor);
273 //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
274 // TRUE, 100, 255, NULL, NULL);
275 //scene.actors = g_slist_append(scene.actors, actor);
277 actor = init_object(desktop_plugin, "cloud1", "cloud1.png",
278 0, fast_rnd(300)-97, 7, 150, 97,
279 FALSE, FALSE, 100, 255,
280 (gpointer)&change_cloud, NULL, NULL);
281 actor->time_start_animation = now + fast_rnd(20);
282 actor->duration_animation = 3*60;
283 scene->actors = g_slist_append(scene->actors, actor);
285 actor = init_object(desktop_plugin, "cloud2", "cloud2.png",
286 0, fast_rnd(300)-75, 7, 188, 75,
287 FALSE, FALSE, 100, 255,
288 (gpointer)&change_cloud, NULL, NULL);
289 actor->time_start_animation = now + fast_rnd(40)+10;
290 actor->duration_animation = 3*60;
291 scene->actors = g_slist_append(scene->actors, actor);
293 actor = init_object(desktop_plugin, "cloud4", "cloud4.png",
294 0, fast_rnd(300)-75, 7, 150, 75,
295 FALSE, FALSE, 100, 255,
296 (gpointer)&change_cloud, NULL, NULL);
297 actor->time_start_animation = now + fast_rnd(60) + 20;
298 actor->duration_animation = 5*60;
299 scene->actors = g_slist_append(scene->actors, actor);
302 actor = init_object(desktop_plugin, "town", "town0.png",
304 TRUE, TRUE, 100, 255,
305 (gpointer)&change_static_actor, NULL, NULL);
306 change_static_actor(actor, desktop_plugin);
307 scene->actors = g_slist_append(scene->actors, actor);
309 actor = init_object(desktop_plugin, "stend", "stend0.png",
310 452, 166, 9, 300, 305,
311 TRUE, TRUE, 100, 255,
312 (gpointer)&change_static_actor, NULL, NULL);
313 change_static_actor(actor, desktop_plugin);
314 scene->actors = g_slist_append(scene->actors, actor);
317 child = g_ptr_array_sized_new(4);
318 actor = init_object(desktop_plugin, "call", "call.png",
320 FALSE, TRUE, 100, 255,
322 scene->actors = g_slist_append(scene->actors, actor);
323 g_ptr_array_add(child, actor);
325 actor = init_object(desktop_plugin, "chat", "chat.png",
327 FALSE, TRUE, 100, 255,
329 scene->actors = g_slist_append(scene->actors, actor);
330 g_ptr_array_add(child, actor);
332 actor = init_object(desktop_plugin, "mail", "mail.png",
334 FALSE, TRUE, 100, 255,
336 scene->actors = g_slist_append(scene->actors, actor);
337 g_ptr_array_add(child, actor);
339 actor = init_object(desktop_plugin, "sms", "sms.png",
341 FALSE, TRUE, 100, 255,
343 scene->actors = g_slist_append(scene->actors, actor);
344 g_ptr_array_add(child, actor);
346 actor = init_object(desktop_plugin, "billboard_text", "",
347 470, 174, 9, 300, 108,
348 FALSE, FALSE, 100, 255,
349 (gpointer)&change_billboard, NULL, child);
350 create_hildon_actor_text(actor, desktop_plugin);
351 //actor->time_start_animation = time(NULL) + 20;
352 change_billboard(actor, desktop_plugin);
353 scene->actors = g_slist_append(scene->actors, actor);
355 actor = init_object(desktop_plugin, "tram", "tram.png",
356 -300, 225, 10, 350, 210,
357 FALSE, FALSE, 100, 255,
358 (gpointer)&change_tram, NULL, NULL);
359 actor->time_start_animation = time(NULL) + fast_rnd(10);
360 actor->duration_animation = 60;
361 scene->actors = g_slist_append(scene->actors, actor);
363 actor = init_object(desktop_plugin, "border", "border0.png",
364 0, 480-79, 11, 800, 79,
365 TRUE, TRUE, 100, 255,
366 (gpointer)&change_static_actor_with_corner, NULL, NULL);
367 change_static_actor_with_corner(actor, desktop_plugin);
368 scene->actors = g_slist_append(scene->actors, actor);
370 actor = init_object(desktop_plugin, "moon", "moon1.png",
372 FALSE, FALSE, 100, 255,
373 (gpointer)&change_moon, NULL, NULL);
374 change_moon(actor, desktop_plugin);
375 scene->actors = g_slist_append(scene->actors, actor);
377 actor = init_object(desktop_plugin, "wind", "",
379 FALSE, FALSE, 100, 255,
380 (gpointer)&change_wind, NULL, NULL);
381 change_wind(actor, desktop_plugin);
382 scene->actors = g_slist_append(scene->actors, actor);
384 /* windows in 4-th house */
424 for (i=0; i<13; i++){
425 actor = init_object(desktop_plugin, "window1", "window1.png",
426 winds[i][0], winds[i][1], 8, 8, 10,
427 FALSE, FALSE, 100, 255,
428 (gpointer)&change_window1, NULL, NULL);
429 //change_window1(actor, desktop_plugin);
430 actor->time_start_animation = now + fast_rnd(30);
431 scene->actors = g_slist_append(scene->actors, actor);
435 /* windows in 1-th house */
461 actor = init_object(desktop_plugin, "window2", "window2.png",
462 winds[i][0], winds[i][1], 8, 8, 10,
463 FALSE, FALSE, 100, 255,
464 (gpointer)&change_window1, NULL, NULL);
465 //change_window1(actor, desktop_plugin);
466 actor->time_start_animation = now + fast_rnd(30);
467 scene->actors = g_slist_append(scene->actors, actor);
471 /* windows in 3-th house */
503 for (i=0; i<10; i++){
504 actor = init_object(desktop_plugin, "window3", "window3.png",
505 winds[i][0], winds[i][1], 8, 8, 10,
506 FALSE, FALSE, 100, 255,
507 (gpointer)&change_window1, NULL, NULL);
508 //change_window1(actor, desktop_plugin);
509 actor->time_start_animation = now + fast_rnd(30);
510 scene->actors = g_slist_append(scene->actors, actor);
514 /* windows in 5-th house */
538 actor = init_object(desktop_plugin, "window4", "window4.png",
539 winds[i][0], winds[i][1], 8, 8, 10,
540 FALSE, FALSE, 100, 255,
541 (gpointer)&change_window1, NULL, NULL);
542 //change_window1(actor, desktop_plugin);
543 actor->time_start_animation = now + fast_rnd(30);
544 scene->actors = g_slist_append(scene->actors, actor);
548 /* windows in 6-th house */
569 actor = init_object(desktop_plugin, "window5", "window5.png",
570 winds[i][0], winds[i][1], 8, 8, 10,
571 FALSE, FALSE, 100, 255,
572 (gpointer)&change_window1, NULL, NULL);
573 //change_window1(actor, desktop_plugin);
574 actor->time_start_animation = now + fast_rnd(30);
575 scene->actors = g_slist_append(scene->actors, actor);
578 run_long_timeout(desktop_plugin);
581 anim = g_new0(Animation, 1);
584 anim->func_change = &change_tram;
585 anim->func_time = NULL;
586 anim->timestart = time(NULL);
589 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
593 /* Init Berlin Scene */
595 init_scene_Berlin(AWallpaperPlugin *desktop_plugin)
597 Actor *actor, *actor1, *actor2;
599 gint now = time(NULL);
602 GPtrArray *child = NULL;
604 scene = g_new0(Scene, 1);
605 scene->daytime = get_daytime();
606 scene->actors = NULL;
607 scene->wind_orientation = -1;
608 scene->wind_angle = 0.3;
609 /* init value for random */
610 scene->seed = time(NULL);
611 desktop_plugin->priv->scene = scene;
613 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
614 TRUE, TRUE, 100, 255,
615 (gpointer)&change_static_actor, NULL, NULL);
616 change_static_actor(actor, desktop_plugin);
617 scene->actors = g_slist_append(scene->actors, actor);
620 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
621 FALSE, FALSE, 100, 255,
622 (gpointer)&change_sun, NULL, NULL);
623 actor->time_start_animation = time(NULL);
624 actor->duration_animation = G_MAXINT;
625 change_sun(actor, desktop_plugin);
626 scene->actors = g_slist_append(scene->actors, actor);
629 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
630 TRUE, 100, 255, NULL, NULL);
631 scene.actors = g_slist_append(scene.actors, actor);
634 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
635 FALSE, FALSE, 100, 255,
636 (gpointer)&change_moon, NULL, NULL);
637 change_moon(actor, desktop_plugin);
638 scene->actors = g_slist_append(scene->actors, actor);
640 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
641 FALSE, FALSE, 100, 255,
642 (gpointer)&change_cloud, NULL, NULL);
643 actor->time_start_animation = now + fast_rnd(30) + 10;
644 actor->duration_animation = 3*60;
645 scene->actors = g_slist_append(scene->actors, actor);
647 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
648 FALSE, FALSE, 100, 255,
649 (gpointer)&change_cloud, NULL, NULL);
650 actor->time_start_animation = now + fast_rnd(10);
651 actor->duration_animation = 3*60;
652 scene->actors = g_slist_append(scene->actors, actor);
654 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
655 FALSE, FALSE, 100, 255,
656 (gpointer)&change_cloud, NULL, NULL);
657 actor->time_start_animation = now + fast_rnd(60) + 20;
658 actor->duration_animation = 5*60;
659 scene->actors = g_slist_append(scene->actors, actor);
662 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
663 FALSE, FALSE, 100, 255,
664 (gpointer)&change_plane2, NULL, NULL);
665 actor->time_start_animation = now + fast_rnd(40) + 20;
666 actor->duration_animation = 60;
667 scene->actors = g_slist_append(scene->actors, actor);
669 actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116,
670 FALSE, FALSE, 100, 255,
671 (gpointer)&change_plane1, NULL, NULL);
672 actor->time_start_animation = now + fast_rnd(20);
673 actor->duration_animation = 30;
674 scene->actors = g_slist_append(scene->actors, actor);
676 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
677 TRUE, TRUE, 100, 255,
678 (gpointer)&change_static_actor_with_corner, NULL, NULL);
679 change_static_actor_with_corner(actor, desktop_plugin);
680 scene->actors = g_slist_append(scene->actors, actor);
682 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
683 FALSE, FALSE, 100, 255,
684 (gpointer)&change_wind, NULL, NULL);
685 change_wind(actor, desktop_plugin);
686 scene->actors = g_slist_append(scene->actors, actor);
688 actor1 = init_object(desktop_plugin, "signal_red", "red.png",
689 486, 425, 10, 18, 38,
690 FALSE, TRUE, 100, 255, NULL, NULL, NULL);
691 //actor->time_start_animation = now + fast_rnd(30) + 10;
692 scene->actors = g_slist_append(scene->actors, actor1);
694 actor2 = init_object(desktop_plugin, "signal_green", "green.png",
695 486, 425, 10, 18, 38,
696 TRUE, TRUE, 100, 255, NULL, NULL, NULL);
697 //actor->time_start_animation = now + fast_rnd(30) + 10;
698 scene->actors = g_slist_append(scene->actors, actor2);
699 child = g_ptr_array_sized_new(2);
700 g_ptr_array_add(child, actor1);
701 g_ptr_array_add(child, actor2);
702 actor = init_object(desktop_plugin, "signal", "",
703 486, 425, 10, 18, 38,
704 FALSE, FALSE, 100, 255,
705 (gpointer)&change_signal, NULL, child);
706 actor->time_start_animation = now + fast_rnd(30) + 10;
707 scene->actors = g_slist_append(scene->actors, actor);
748 for (i=0; i<13; i++){
749 actor = init_object(desktop_plugin, "window", "window.png",
750 winds[i][0], winds[i][1], 10, 8, 9,
751 FALSE, TRUE, 100, 255,
752 (gpointer)&change_window1, NULL, NULL);
753 //change_window1(actor, desktop_plugin);
754 actor->time_start_animation = now + fast_rnd(30);
755 scene->actors = g_slist_append(scene->actors, actor);
759 run_long_timeout(desktop_plugin);
764 init_scene_theme(AWallpaperPlugin *desktop_plugin)
766 void (*func)(gpointer);
767 func = g_hash_table_lookup(desktop_plugin->priv->hash_scene_func, desktop_plugin->priv->theme);
769 (*func)(desktop_plugin);