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);
61 init_scene_Accel(AWallpaperPlugin *desktop_plugin)
66 gint now = time(NULL);
68 gint sizes[4] = {170, 229, 130, 150},
69 sizes1[4] = {57, 76, 43, 50},
70 heights[4] = {0, 100, 200, 300},
73 fprintf(stderr, "init scene accel\n");
74 scene = g_new0(Scene, 1);
76 desktop_plugin->priv->scene = scene;
78 actor = init_object(desktop_plugin, "background", "bg.png",
82 scene->actors = g_slist_append(scene->actors, actor);
84 child = g_ptr_array_sized_new(16);
88 //for (i=0; i<3; i++){
89 str = g_strdup_printf("tape%i.png", n+1);
90 actor = init_object(desktop_plugin, "tape", str,
91 fast_rnd(800), fast_rnd(480), 2+fast_rnd(6), 800, sizes1[n],
94 scene->actors = g_slist_append(scene->actors, actor);
95 g_ptr_array_add(child, actor);
100 actor = init_object(desktop_plugin, "tape", "",
102 FALSE, FALSE, 100, 255,
103 (gpointer)&change_tape, NULL, child);
104 actor->time_start_animation = now;
105 actor->duration_animation = G_MAXINT;
106 scene->actors = g_slist_append(scene->actors, actor);
108 run_long_timeout(desktop_plugin);
112 parsestring(char *line, char **argv)
114 while (*line != '\0') {
115 while (*line == ' ' || *line == '\n')
116 *line++ = '\0'; /* replace white spaces with 0 */
117 *argv++ = line; /* save the argument position */
118 while (*line != '\0' && *line != ' ' &&
120 line++; /* skip the argument until ... */
122 *argv = '\0'; /* mark the end of argument list */
127 sync_handler(GstBus *bus, GstMessage *message, AWallpaperPlugin *desktop_plugin){
129 if (!desktop_plugin->priv->visible)
130 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PAUSED);
131 if (GST_MESSAGE_TYPE(message) != GST_MESSAGE_ELEMENT){
132 return (GST_BUS_PASS);
134 if (!gst_structure_has_name(message->structure, "prepare-xwindow-id")){
135 return (GST_BUS_PASS);
137 return (GST_BUS_DROP);
142 bus_call (GstBus *bus, GstMessage *msg, AWallpaperPlugin *desktop_plugin)
144 switch (GST_MESSAGE_TYPE (msg))
146 case GST_MESSAGE_EOS:
147 fprintf(stderr,"GST_MESSAGE_EOS:\n");
148 if (desktop_plugin->priv->rich_animation){
149 fprintf(stderr,"GST_MESSAGE_EOS222222222222222222222222\n");
150 GstClockTime nach = (GstClockTime)(10 * GST_MSECOND);
151 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))
152 fprintf(stderr,"ERROR in seek\n");
158 // gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_READY);
160 // gst_element_set_start_time(desktop_plugin->priv->pipeline, 0);
161 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
163 fprintf(stderr,"GST_MESSAGE_EOS33333333333333333333\n");
164 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));
168 case GST_MESSAGE_ERROR: break;
175 init_scene_Video(AWallpaperPlugin *desktop_plugin)
178 GstElement *videosink;
180 gchar *file_plus_uri;
183 desktop_plugin->priv->pipeline = gst_pipeline_new("gst-player");
184 bin = gst_element_factory_make ("playbin2", "bin");
185 videosink = gst_element_factory_make ("ximagesink", "videosink");
186 g_object_set (G_OBJECT (bin), "video-sink", videosink, NULL);
187 gst_bin_add (GST_BIN (desktop_plugin->priv->pipeline), bin);
191 bus = gst_pipeline_get_bus (GST_PIPELINE (desktop_plugin->priv->pipeline));
192 gst_bus_add_watch(bus, bus_call, desktop_plugin);
193 gst_object_unref (bus);
195 file_plus_uri = g_strdup_printf("file://%s",desktop_plugin->priv->theme_string_parametr1);
196 g_object_set (G_OBJECT (bin), "uri", file_plus_uri, NULL );
197 g_object_set (G_OBJECT (videosink), "force-aspect-ratio", TRUE, NULL );
198 if (GST_IS_X_OVERLAY (videosink))
199 gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (videosink), GDK_DRAWABLE_XID(desktop_plugin->priv->window->window));
200 if (desktop_plugin->priv->visible)
201 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
205 init_scene_Matrix(AWallpaperPlugin *desktop_plugin)
210 gint now = time(NULL);
213 if (desktop_plugin->priv->rich_animation){
221 /* fprintf(stderr, "init scene2 \n"); */
222 scene = g_new0(Scene, 1);
223 //scene.daytime = get_daytime();
224 scene->actors = NULL;
225 desktop_plugin->priv->scene = scene;
227 actor = init_object(desktop_plugin, "background", "bg.png",
229 TRUE, TRUE, 100, 255,
231 scene->actors = g_slist_append(scene->actors, actor);
233 actor = init_object(desktop_plugin, "symbols", "symbols.png",
235 TRUE, TRUE, 100, 255,
237 scene->actors = g_slist_append(scene->actors, actor);
239 child = g_ptr_array_sized_new(4);
240 actor = init_object(desktop_plugin, "layer1", "layer1_2.png",
242 TRUE, TRUE, 100, 255,
244 //actor->time_start_animation = now;
245 //actor->duration_animation = G_MAXINT;
246 scene->actors = g_slist_append(scene->actors, actor);
247 g_ptr_array_add(child, actor);
249 actor = init_object(desktop_plugin, "layer1", "layer1_1.png",
251 TRUE, TRUE, 100, 255,
253 //actor->time_start_animation = now;
254 //actor->duration_animation = G_MAXINT;
255 scene->actors = g_slist_append(scene->actors, actor);
256 g_ptr_array_add(child, actor);
258 actor = init_object(desktop_plugin, "layer2", "layer2_2.png",
260 TRUE, TRUE, 100, 255,
262 //actor->time_start_animation = now;
263 //actor->duration_animation = G_MAXINT;
264 scene->actors = g_slist_append(scene->actors, actor);
265 g_ptr_array_add(child, actor);
267 actor = init_object(desktop_plugin, "layer2", "layer2_1.png",
269 TRUE, TRUE, 100, 255,
271 //actor->time_start_animation = now;
272 //actor->duration_animation = G_MAXINT;
273 scene->actors = g_slist_append(scene->actors, actor);
274 g_ptr_array_add(child, actor);
276 actor = init_object(desktop_plugin, "layers", "",
278 FALSE, FALSE, 100, 255,
279 (gpointer)&change_layer, NULL, child);
280 actor->time_start_animation = now;
281 actor->duration_animation = G_MAXINT;
282 scene->actors = g_slist_append(scene->actors, actor);
284 run_long_timeout(desktop_plugin);
288 /* Init Modern Scene */
290 init_scene_Modern(AWallpaperPlugin *desktop_plugin)
294 gint now = time(NULL);
299 /* fprintf(stderr, "init scene \n"); */
300 scene = g_new0(Scene, 1);
301 scene->daytime = get_daytime();
302 scene->actors = NULL;
303 scene->wind_orientation = -1;
304 scene->wind_angle = 0.3;
305 /* init value for random */
306 scene->seed = time(NULL);
307 scene->notification = TRUE;
308 desktop_plugin->priv->scene = scene;
309 actor = init_object(desktop_plugin, "sky", "sky0.png",
311 TRUE , TRUE, 100, 255,
312 (gpointer)&change_static_actor, NULL, NULL);
313 scene->actors = g_slist_append(scene->actors, actor);
314 change_static_actor(actor, desktop_plugin);
316 actor = init_object(desktop_plugin, "sun", "sun.png",
318 FALSE, FALSE, 100, 255,
319 (gpointer)&change_sun, NULL, NULL);
320 actor->time_start_animation = now;
321 actor->duration_animation = G_MAXINT;
322 change_sun(actor, desktop_plugin);
323 scene->actors = g_slist_append(scene->actors, actor);
325 //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
326 // TRUE, 100, 255, NULL, NULL);
327 //scene.actors = g_slist_append(scene.actors, actor);
329 actor = init_object(desktop_plugin, "cloud1", "cloud1.png",
330 0, fast_rnd(300)-97, 7, 150, 97,
331 FALSE, FALSE, 100, 255,
332 (gpointer)&change_cloud, NULL, NULL);
333 actor->time_start_animation = now + fast_rnd(20);
334 actor->duration_animation = 3*60;
335 scene->actors = g_slist_append(scene->actors, actor);
337 actor = init_object(desktop_plugin, "cloud2", "cloud2.png",
338 0, fast_rnd(300)-75, 7, 188, 75,
339 FALSE, FALSE, 100, 255,
340 (gpointer)&change_cloud, NULL, NULL);
341 actor->time_start_animation = now + fast_rnd(40)+10;
342 actor->duration_animation = 3*60;
343 scene->actors = g_slist_append(scene->actors, actor);
345 actor = init_object(desktop_plugin, "cloud4", "cloud4.png",
346 0, fast_rnd(300)-75, 7, 150, 75,
347 FALSE, FALSE, 100, 255,
348 (gpointer)&change_cloud, NULL, NULL);
349 actor->time_start_animation = now + fast_rnd(60) + 20;
350 actor->duration_animation = 5*60;
351 scene->actors = g_slist_append(scene->actors, actor);
354 actor = init_object(desktop_plugin, "town", "town0.png",
356 TRUE, TRUE, 100, 255,
357 (gpointer)&change_static_actor, NULL, NULL);
358 change_static_actor(actor, desktop_plugin);
359 scene->actors = g_slist_append(scene->actors, actor);
361 actor = init_object(desktop_plugin, "stend", "stend0.png",
362 452, 166, 9, 300, 305,
363 TRUE, TRUE, 100, 255,
364 (gpointer)&change_static_actor, NULL, NULL);
365 change_static_actor(actor, desktop_plugin);
366 scene->actors = g_slist_append(scene->actors, actor);
369 child = g_ptr_array_sized_new(4);
370 actor = init_object(desktop_plugin, "call", "call.png",
372 FALSE, TRUE, 100, 255,
374 scene->actors = g_slist_append(scene->actors, actor);
375 g_ptr_array_add(child, actor);
377 actor = init_object(desktop_plugin, "chat", "chat.png",
379 FALSE, TRUE, 100, 255,
381 scene->actors = g_slist_append(scene->actors, actor);
382 g_ptr_array_add(child, actor);
384 actor = init_object(desktop_plugin, "mail", "mail.png",
386 FALSE, TRUE, 100, 255,
388 scene->actors = g_slist_append(scene->actors, actor);
389 g_ptr_array_add(child, actor);
391 actor = init_object(desktop_plugin, "sms", "sms.png",
393 FALSE, TRUE, 100, 255,
395 scene->actors = g_slist_append(scene->actors, actor);
396 g_ptr_array_add(child, actor);
398 actor = init_object(desktop_plugin, "billboard_text", "",
399 470, 174, 9, 300, 108,
400 FALSE, FALSE, 100, 255,
401 (gpointer)&change_billboard, NULL, child);
402 create_hildon_actor_text(actor, desktop_plugin);
403 //actor->time_start_animation = time(NULL) + 20;
404 change_billboard(actor, desktop_plugin);
405 scene->actors = g_slist_append(scene->actors, actor);
407 actor = init_object(desktop_plugin, "tram", "tram.png",
408 -300, 225, 10, 350, 210,
409 FALSE, FALSE, 100, 255,
410 (gpointer)&change_tram, NULL, NULL);
411 actor->time_start_animation = time(NULL) + fast_rnd(10);
412 actor->duration_animation = 60;
413 scene->actors = g_slist_append(scene->actors, actor);
415 actor = init_object(desktop_plugin, "border", "border0.png",
416 0, 480-79, 11, 800, 79,
417 TRUE, TRUE, 100, 255,
418 (gpointer)&change_static_actor_with_corner, NULL, NULL);
419 change_static_actor_with_corner(actor, desktop_plugin);
420 scene->actors = g_slist_append(scene->actors, actor);
422 actor = init_object(desktop_plugin, "moon", "moon1.png",
424 FALSE, FALSE, 100, 255,
425 (gpointer)&change_moon, NULL, NULL);
426 change_moon(actor, desktop_plugin);
427 scene->actors = g_slist_append(scene->actors, actor);
429 actor = init_object(desktop_plugin, "wind", "",
431 FALSE, FALSE, 100, 255,
432 (gpointer)&change_wind, NULL, NULL);
433 change_wind(actor, desktop_plugin);
434 scene->actors = g_slist_append(scene->actors, actor);
436 /* windows in 4-th house */
476 for (i=0; i<13; i++){
477 actor = init_object(desktop_plugin, "window1", "window1.png",
478 winds[i][0], winds[i][1], 8, 8, 10,
479 FALSE, FALSE, 100, 255,
480 (gpointer)&change_window1, NULL, NULL);
481 //change_window1(actor, desktop_plugin);
482 actor->time_start_animation = now + fast_rnd(30);
483 scene->actors = g_slist_append(scene->actors, actor);
487 /* windows in 1-th house */
513 actor = init_object(desktop_plugin, "window2", "window2.png",
514 winds[i][0], winds[i][1], 8, 8, 10,
515 FALSE, FALSE, 100, 255,
516 (gpointer)&change_window1, NULL, NULL);
517 //change_window1(actor, desktop_plugin);
518 actor->time_start_animation = now + fast_rnd(30);
519 scene->actors = g_slist_append(scene->actors, actor);
523 /* windows in 3-th house */
555 for (i=0; i<10; i++){
556 actor = init_object(desktop_plugin, "window3", "window3.png",
557 winds[i][0], winds[i][1], 8, 8, 10,
558 FALSE, FALSE, 100, 255,
559 (gpointer)&change_window1, NULL, NULL);
560 //change_window1(actor, desktop_plugin);
561 actor->time_start_animation = now + fast_rnd(30);
562 scene->actors = g_slist_append(scene->actors, actor);
566 /* windows in 5-th house */
590 actor = init_object(desktop_plugin, "window4", "window4.png",
591 winds[i][0], winds[i][1], 8, 8, 10,
592 FALSE, FALSE, 100, 255,
593 (gpointer)&change_window1, NULL, NULL);
594 //change_window1(actor, desktop_plugin);
595 actor->time_start_animation = now + fast_rnd(30);
596 scene->actors = g_slist_append(scene->actors, actor);
600 /* windows in 6-th house */
621 actor = init_object(desktop_plugin, "window5", "window5.png",
622 winds[i][0], winds[i][1], 8, 8, 10,
623 FALSE, FALSE, 100, 255,
624 (gpointer)&change_window1, NULL, NULL);
625 //change_window1(actor, desktop_plugin);
626 actor->time_start_animation = now + fast_rnd(30);
627 scene->actors = g_slist_append(scene->actors, actor);
630 run_long_timeout(desktop_plugin);
633 anim = g_new0(Animation, 1);
636 anim->func_change = &change_tram;
637 anim->func_time = NULL;
638 anim->timestart = time(NULL);
641 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
645 /* Init Berlin Scene */
647 init_scene_Berlin(AWallpaperPlugin *desktop_plugin)
649 Actor *actor, *actor1, *actor2;
651 gint now = time(NULL);
654 GPtrArray *child = NULL;
656 scene = g_new0(Scene, 1);
657 scene->daytime = get_daytime();
658 scene->actors = NULL;
659 scene->wind_orientation = -1;
660 scene->wind_angle = 0.3;
661 /* init value for random */
662 scene->seed = time(NULL);
663 desktop_plugin->priv->scene = scene;
665 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
666 TRUE, TRUE, 100, 255,
667 (gpointer)&change_static_actor, NULL, NULL);
668 change_static_actor(actor, desktop_plugin);
669 scene->actors = g_slist_append(scene->actors, actor);
672 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
673 FALSE, FALSE, 100, 255,
674 (gpointer)&change_sun, NULL, NULL);
675 actor->time_start_animation = time(NULL);
676 actor->duration_animation = G_MAXINT;
677 change_sun(actor, desktop_plugin);
678 scene->actors = g_slist_append(scene->actors, actor);
681 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
682 TRUE, 100, 255, NULL, NULL);
683 scene.actors = g_slist_append(scene.actors, actor);
686 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
687 FALSE, FALSE, 100, 255,
688 (gpointer)&change_moon, NULL, NULL);
689 change_moon(actor, desktop_plugin);
690 scene->actors = g_slist_append(scene->actors, actor);
692 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
693 FALSE, FALSE, 100, 255,
694 (gpointer)&change_cloud, NULL, NULL);
695 actor->time_start_animation = now + fast_rnd(30) + 10;
696 actor->duration_animation = 3*60;
697 scene->actors = g_slist_append(scene->actors, actor);
699 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
700 FALSE, FALSE, 100, 255,
701 (gpointer)&change_cloud, NULL, NULL);
702 actor->time_start_animation = now + fast_rnd(10);
703 actor->duration_animation = 3*60;
704 scene->actors = g_slist_append(scene->actors, actor);
706 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
707 FALSE, FALSE, 100, 255,
708 (gpointer)&change_cloud, NULL, NULL);
709 actor->time_start_animation = now + fast_rnd(60) + 20;
710 actor->duration_animation = 5*60;
711 scene->actors = g_slist_append(scene->actors, actor);
714 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
715 FALSE, FALSE, 100, 255,
716 (gpointer)&change_plane2, NULL, NULL);
717 actor->time_start_animation = now + fast_rnd(40) + 20;
718 actor->duration_animation = 60;
719 scene->actors = g_slist_append(scene->actors, actor);
721 actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116,
722 FALSE, FALSE, 100, 255,
723 (gpointer)&change_plane1, NULL, NULL);
724 actor->time_start_animation = now + fast_rnd(20);
725 actor->duration_animation = 30;
726 scene->actors = g_slist_append(scene->actors, actor);
728 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
729 TRUE, TRUE, 100, 255,
730 (gpointer)&change_static_actor_with_corner, NULL, NULL);
731 change_static_actor_with_corner(actor, desktop_plugin);
732 scene->actors = g_slist_append(scene->actors, actor);
734 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
735 FALSE, FALSE, 100, 255,
736 (gpointer)&change_wind, NULL, NULL);
737 change_wind(actor, desktop_plugin);
738 scene->actors = g_slist_append(scene->actors, actor);
740 actor1 = init_object(desktop_plugin, "signal_red", "red.png",
741 486, 425, 10, 18, 38,
742 FALSE, TRUE, 100, 255, NULL, NULL, NULL);
743 //actor->time_start_animation = now + fast_rnd(30) + 10;
744 scene->actors = g_slist_append(scene->actors, actor1);
746 actor2 = init_object(desktop_plugin, "signal_green", "green.png",
747 486, 425, 10, 18, 38,
748 TRUE, TRUE, 100, 255, NULL, NULL, NULL);
749 //actor->time_start_animation = now + fast_rnd(30) + 10;
750 scene->actors = g_slist_append(scene->actors, actor2);
751 child = g_ptr_array_sized_new(2);
752 g_ptr_array_add(child, actor1);
753 g_ptr_array_add(child, actor2);
754 actor = init_object(desktop_plugin, "signal", "",
755 486, 425, 10, 18, 38,
756 FALSE, FALSE, 100, 255,
757 (gpointer)&change_signal, NULL, child);
758 actor->time_start_animation = now + fast_rnd(30) + 10;
759 scene->actors = g_slist_append(scene->actors, actor);
800 for (i=0; i<13; i++){
801 actor = init_object(desktop_plugin, "window", "window.png",
802 winds[i][0], winds[i][1], 10, 8, 9,
803 FALSE, TRUE, 100, 255,
804 (gpointer)&change_window1, NULL, NULL);
805 //change_window1(actor, desktop_plugin);
806 actor->time_start_animation = now + fast_rnd(30);
807 scene->actors = g_slist_append(scene->actors, actor);
811 run_long_timeout(desktop_plugin);
816 init_scene_theme(AWallpaperPlugin *desktop_plugin)
818 void (*func)(gpointer);
819 func = g_hash_table_lookup(desktop_plugin->priv->hash_scene_func, desktop_plugin->priv->theme);
821 (*func)(desktop_plugin);