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));
50 /*******************************************************************************/
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);
58 /*******************************************************************************/
60 init_scene_Accel(AWallpaperPlugin *desktop_plugin)
65 gint now = time(NULL);
67 gint sizes[4] = {170, 229, 130, 150},
68 sizes1[4] = {57, 76, 43, 50},
69 heights[4] = {0, 100, 200, 300},
72 fprintf(stderr, "init scene accel\n");
73 scene = g_new0(Scene, 1);
75 desktop_plugin->priv->scene = scene;
77 actor = init_object(desktop_plugin, "background", "bg.png",
81 scene->actors = g_slist_append(scene->actors, actor);
83 child = g_ptr_array_sized_new(16);
87 //for (i=0; i<3; i++){
88 str = g_strdup_printf("tape%i.png", n+1);
89 actor = init_object(desktop_plugin, "tape", str,
90 fast_rnd(800), fast_rnd(480), 2+fast_rnd(6), 800, sizes1[n],
93 scene->actors = g_slist_append(scene->actors, actor);
94 g_ptr_array_add(child, actor);
99 actor = init_object(desktop_plugin, "tape", "",
101 FALSE, FALSE, 100, 255,
102 (gpointer)&change_tape, NULL, child);
103 actor->time_start_animation = now;
104 actor->duration_animation = G_MAXINT;
105 scene->actors = g_slist_append(scene->actors, actor);
107 run_long_timeout(desktop_plugin);
109 /*******************************************************************************/
111 parsestring(char *line, char **argv)
113 while (*line != '\0') {
114 while (*line == ' ' || *line == '\n')
115 *line++ = '\0'; /* replace white spaces with 0 */
116 *argv++ = line; /* save the argument position */
117 while (*line != '\0' && *line != ' ' &&
119 line++; /* skip the argument until ... */
121 *argv = '\0'; /* mark the end of argument list */
126 sync_handler(GstBus *bus, GstMessage *message, AWallpaperPlugin *desktop_plugin){
128 if (!desktop_plugin->priv->visible)
129 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PAUSED);
130 if (GST_MESSAGE_TYPE(message) != GST_MESSAGE_ELEMENT){
131 return (GST_BUS_PASS);
133 if (!gst_structure_has_name(message->structure, "prepare-xwindow-id")){
134 return (GST_BUS_PASS);
136 return (GST_BUS_DROP);
140 /*******************************************************************************/
142 bus_call (GstBus *bus, GstMessage *msg, AWallpaperPlugin *desktop_plugin)
144 switch (GST_MESSAGE_TYPE (msg))
146 case GST_MESSAGE_EOS:
147 if (desktop_plugin->priv->rich_animation){
149 GstClockTime nach = (GstClockTime)(0 * GST_MSECOND);
150 if (!gst_element_seek(desktop_plugin->priv->pipeline, 1.0, GST_FORMAT_TIME,
151 (GstSeekFlags) (GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT), GST_SEEK_TYPE_SET,
152 nach, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
153 fprintf(stderr,"ERROR in seek\n");
155 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
158 if (desktop_plugin->priv->pipeline){
159 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_NULL);
160 gst_object_unref (GST_OBJECT (desktop_plugin->priv->pipeline));
164 case GST_MESSAGE_ERROR: break;
169 /*******************************************************************************/
171 init_scene_Video(AWallpaperPlugin *desktop_plugin)
174 GstElement *videosink;
176 gchar *file_plus_uri;
179 desktop_plugin->priv->pipeline = gst_pipeline_new("gst-player");
180 bin = gst_element_factory_make ("playbin2", "bin");
181 videosink = gst_element_factory_make ("ximagesink", "videosink");
182 g_object_set (G_OBJECT (bin), "video-sink", videosink, NULL);
183 gst_bin_add (GST_BIN (desktop_plugin->priv->pipeline), bin);
187 bus = gst_pipeline_get_bus (GST_PIPELINE (desktop_plugin->priv->pipeline));
188 gst_bus_add_watch(bus, bus_call, desktop_plugin);
189 gst_object_unref (bus);
191 file_plus_uri = g_strdup_printf("file://%s",desktop_plugin->priv->theme_string_parametr1);
192 g_object_set (G_OBJECT (bin), "uri", file_plus_uri, NULL );
193 g_object_set (G_OBJECT (videosink), "force-aspect-ratio", TRUE, NULL );
194 if (GST_IS_X_OVERLAY (videosink))
195 gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (videosink), GDK_DRAWABLE_XID(desktop_plugin->priv->window->window));
196 if (desktop_plugin->priv->visible)
197 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
199 /*******************************************************************************/
201 init_scene_Matrix(AWallpaperPlugin *desktop_plugin)
206 gint now = time(NULL);
209 if (desktop_plugin->priv->rich_animation){
217 /* fprintf(stderr, "init scene2 \n"); */
218 scene = g_new0(Scene, 1);
219 //scene.daytime = get_daytime();
220 scene->actors = NULL;
221 desktop_plugin->priv->scene = scene;
223 actor = init_object(desktop_plugin, "background", "bg.png",
225 TRUE, TRUE, 100, 255,
227 scene->actors = g_slist_append(scene->actors, actor);
229 actor = init_object(desktop_plugin, "symbols", "symbols.png",
231 TRUE, TRUE, 100, 255,
233 scene->actors = g_slist_append(scene->actors, actor);
235 child = g_ptr_array_sized_new(4);
236 actor = init_object(desktop_plugin, "layer1", "layer1_2.png",
238 TRUE, TRUE, 100, 255,
240 //actor->time_start_animation = now;
241 //actor->duration_animation = G_MAXINT;
242 scene->actors = g_slist_append(scene->actors, actor);
243 g_ptr_array_add(child, actor);
245 actor = init_object(desktop_plugin, "layer1", "layer1_1.png",
247 TRUE, TRUE, 100, 255,
249 //actor->time_start_animation = now;
250 //actor->duration_animation = G_MAXINT;
251 scene->actors = g_slist_append(scene->actors, actor);
252 g_ptr_array_add(child, actor);
254 actor = init_object(desktop_plugin, "layer2", "layer2_2.png",
256 TRUE, TRUE, 100, 255,
258 //actor->time_start_animation = now;
259 //actor->duration_animation = G_MAXINT;
260 scene->actors = g_slist_append(scene->actors, actor);
261 g_ptr_array_add(child, actor);
263 actor = init_object(desktop_plugin, "layer2", "layer2_1.png",
265 TRUE, TRUE, 100, 255,
267 //actor->time_start_animation = now;
268 //actor->duration_animation = G_MAXINT;
269 scene->actors = g_slist_append(scene->actors, actor);
270 g_ptr_array_add(child, actor);
272 actor = init_object(desktop_plugin, "layers", "",
274 FALSE, FALSE, 100, 255,
275 (gpointer)&change_layer, NULL, child);
276 actor->time_start_animation = now;
277 actor->duration_animation = G_MAXINT;
278 scene->actors = g_slist_append(scene->actors, actor);
280 run_long_timeout(desktop_plugin);
283 /*******************************************************************************/
284 /* Init Modern Scene */
286 init_scene_Modern(AWallpaperPlugin *desktop_plugin)
290 gint now = time(NULL);
295 /* fprintf(stderr, "init scene \n"); */
296 scene = g_new0(Scene, 1);
297 scene->daytime = get_daytime();
298 scene->actors = NULL;
299 scene->wind_orientation = -1;
300 scene->wind_angle = 0.3;
301 /* init value for random */
302 scene->seed = time(NULL);
303 scene->notification = TRUE;
304 desktop_plugin->priv->scene = scene;
305 actor = init_object(desktop_plugin, "sky", "sky0.png",
307 TRUE , TRUE, 100, 255,
308 (gpointer)&change_static_actor, NULL, NULL);
309 scene->actors = g_slist_append(scene->actors, actor);
310 change_static_actor(actor, desktop_plugin);
312 actor = init_object(desktop_plugin, "sun", "sun.png",
314 FALSE, FALSE, 100, 255,
315 (gpointer)&change_sun, NULL, NULL);
316 actor->time_start_animation = now;
317 actor->duration_animation = G_MAXINT;
318 change_sun(actor, desktop_plugin);
319 scene->actors = g_slist_append(scene->actors, actor);
321 //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
322 // TRUE, 100, 255, NULL, NULL);
323 //scene.actors = g_slist_append(scene.actors, actor);
325 actor = init_object(desktop_plugin, "cloud1", "cloud1.png",
326 0, fast_rnd(300)-97, 7, 150, 97,
327 FALSE, FALSE, 100, 255,
328 (gpointer)&change_cloud, NULL, NULL);
329 actor->time_start_animation = now + fast_rnd(20);
330 actor->duration_animation = 3*60;
331 scene->actors = g_slist_append(scene->actors, actor);
333 actor = init_object(desktop_plugin, "cloud2", "cloud2.png",
334 0, fast_rnd(300)-75, 7, 188, 75,
335 FALSE, FALSE, 100, 255,
336 (gpointer)&change_cloud, NULL, NULL);
337 actor->time_start_animation = now + fast_rnd(40)+10;
338 actor->duration_animation = 3*60;
339 scene->actors = g_slist_append(scene->actors, actor);
341 actor = init_object(desktop_plugin, "cloud4", "cloud4.png",
342 0, fast_rnd(300)-75, 7, 150, 75,
343 FALSE, FALSE, 100, 255,
344 (gpointer)&change_cloud, NULL, NULL);
345 actor->time_start_animation = now + fast_rnd(60) + 20;
346 actor->duration_animation = 5*60;
347 scene->actors = g_slist_append(scene->actors, actor);
350 actor = init_object(desktop_plugin, "town", "town0.png",
352 TRUE, TRUE, 100, 255,
353 (gpointer)&change_static_actor, NULL, NULL);
354 change_static_actor(actor, desktop_plugin);
355 scene->actors = g_slist_append(scene->actors, actor);
357 actor = init_object(desktop_plugin, "stend", "stend0.png",
358 452, 166, 9, 300, 305,
359 TRUE, TRUE, 100, 255,
360 (gpointer)&change_static_actor, NULL, NULL);
361 change_static_actor(actor, desktop_plugin);
362 scene->actors = g_slist_append(scene->actors, actor);
365 child = g_ptr_array_sized_new(4);
366 actor = init_object(desktop_plugin, "call", "call.png",
368 FALSE, TRUE, 100, 255,
370 scene->actors = g_slist_append(scene->actors, actor);
371 g_ptr_array_add(child, actor);
373 actor = init_object(desktop_plugin, "chat", "chat.png",
375 FALSE, TRUE, 100, 255,
377 scene->actors = g_slist_append(scene->actors, actor);
378 g_ptr_array_add(child, actor);
380 actor = init_object(desktop_plugin, "mail", "mail.png",
382 FALSE, TRUE, 100, 255,
384 scene->actors = g_slist_append(scene->actors, actor);
385 g_ptr_array_add(child, actor);
387 actor = init_object(desktop_plugin, "sms", "sms.png",
389 FALSE, TRUE, 100, 255,
391 scene->actors = g_slist_append(scene->actors, actor);
392 g_ptr_array_add(child, actor);
394 actor = init_object(desktop_plugin, "billboard_text", "",
395 470, 174, 9, 300, 108,
396 FALSE, FALSE, 100, 255,
397 (gpointer)&change_billboard, NULL, child);
398 create_hildon_actor_text(actor, desktop_plugin);
399 //actor->time_start_animation = time(NULL) + 20;
400 change_billboard(actor, desktop_plugin);
401 scene->actors = g_slist_append(scene->actors, actor);
403 actor = init_object(desktop_plugin, "tram", "tram.png",
404 -300, 225, 10, 350, 210,
405 FALSE, FALSE, 100, 255,
406 (gpointer)&change_tram, NULL, NULL);
407 actor->time_start_animation = time(NULL) + fast_rnd(10);
408 actor->duration_animation = 60;
409 scene->actors = g_slist_append(scene->actors, actor);
411 actor = init_object(desktop_plugin, "border", "border0.png",
412 0, 480-79, 11, 800, 79,
413 TRUE, TRUE, 100, 255,
414 (gpointer)&change_static_actor_with_corner, NULL, NULL);
415 change_static_actor_with_corner(actor, desktop_plugin);
416 scene->actors = g_slist_append(scene->actors, actor);
418 actor = init_object(desktop_plugin, "moon", "moon1.png",
420 FALSE, FALSE, 100, 255,
421 (gpointer)&change_moon, NULL, NULL);
422 change_moon(actor, desktop_plugin);
423 scene->actors = g_slist_append(scene->actors, actor);
425 actor = init_object(desktop_plugin, "wind", "",
427 FALSE, FALSE, 100, 255,
428 (gpointer)&change_wind, NULL, NULL);
429 change_wind(actor, desktop_plugin);
430 scene->actors = g_slist_append(scene->actors, actor);
432 /* windows in 4-th house */
472 for (i=0; i<13; i++){
473 actor = init_object(desktop_plugin, "window1", "window1.png",
474 winds[i][0], winds[i][1], 8, 8, 10,
475 FALSE, FALSE, 100, 255,
476 (gpointer)&change_window1, NULL, NULL);
477 //change_window1(actor, desktop_plugin);
478 actor->time_start_animation = now + fast_rnd(30);
479 scene->actors = g_slist_append(scene->actors, actor);
483 /* windows in 1-th house */
509 actor = init_object(desktop_plugin, "window2", "window2.png",
510 winds[i][0], winds[i][1], 8, 8, 10,
511 FALSE, FALSE, 100, 255,
512 (gpointer)&change_window1, NULL, NULL);
513 //change_window1(actor, desktop_plugin);
514 actor->time_start_animation = now + fast_rnd(30);
515 scene->actors = g_slist_append(scene->actors, actor);
519 /* windows in 3-th house */
551 for (i=0; i<10; i++){
552 actor = init_object(desktop_plugin, "window3", "window3.png",
553 winds[i][0], winds[i][1], 8, 8, 10,
554 FALSE, FALSE, 100, 255,
555 (gpointer)&change_window1, NULL, NULL);
556 //change_window1(actor, desktop_plugin);
557 actor->time_start_animation = now + fast_rnd(30);
558 scene->actors = g_slist_append(scene->actors, actor);
562 /* windows in 5-th house */
586 actor = init_object(desktop_plugin, "window4", "window4.png",
587 winds[i][0], winds[i][1], 8, 8, 10,
588 FALSE, FALSE, 100, 255,
589 (gpointer)&change_window1, NULL, NULL);
590 //change_window1(actor, desktop_plugin);
591 actor->time_start_animation = now + fast_rnd(30);
592 scene->actors = g_slist_append(scene->actors, actor);
596 /* windows in 6-th house */
617 actor = init_object(desktop_plugin, "window5", "window5.png",
618 winds[i][0], winds[i][1], 8, 8, 10,
619 FALSE, FALSE, 100, 255,
620 (gpointer)&change_window1, NULL, NULL);
621 //change_window1(actor, desktop_plugin);
622 actor->time_start_animation = now + fast_rnd(30);
623 scene->actors = g_slist_append(scene->actors, actor);
626 run_long_timeout(desktop_plugin);
629 anim = g_new0(Animation, 1);
632 anim->func_change = &change_tram;
633 anim->func_time = NULL;
634 anim->timestart = time(NULL);
637 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
640 /*******************************************************************************/
641 /* Init Berlin Scene */
643 init_scene_Berlin(AWallpaperPlugin *desktop_plugin)
645 Actor *actor, *actor1, *actor2;
647 gint now = time(NULL);
650 GPtrArray *child = NULL;
652 scene = g_new0(Scene, 1);
653 scene->daytime = get_daytime();
654 scene->actors = NULL;
655 scene->wind_orientation = -1;
656 scene->wind_angle = 0.3;
657 /* init value for random */
658 scene->seed = time(NULL);
659 desktop_plugin->priv->scene = scene;
661 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
662 TRUE, TRUE, 100, 255,
663 (gpointer)&change_static_actor, NULL, NULL);
664 change_static_actor(actor, desktop_plugin);
665 scene->actors = g_slist_append(scene->actors, actor);
668 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
669 FALSE, FALSE, 100, 255,
670 (gpointer)&change_sun, NULL, NULL);
671 actor->time_start_animation = time(NULL);
672 actor->duration_animation = G_MAXINT;
673 change_sun(actor, desktop_plugin);
674 scene->actors = g_slist_append(scene->actors, actor);
677 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
678 TRUE, 100, 255, NULL, NULL);
679 scene.actors = g_slist_append(scene.actors, actor);
682 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
683 FALSE, FALSE, 100, 255,
684 (gpointer)&change_moon, NULL, NULL);
685 change_moon(actor, desktop_plugin);
686 scene->actors = g_slist_append(scene->actors, actor);
688 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
689 FALSE, FALSE, 100, 255,
690 (gpointer)&change_cloud, NULL, NULL);
691 actor->time_start_animation = now + fast_rnd(30) + 10;
692 actor->duration_animation = 3*60;
693 scene->actors = g_slist_append(scene->actors, actor);
695 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
696 FALSE, FALSE, 100, 255,
697 (gpointer)&change_cloud, NULL, NULL);
698 actor->time_start_animation = now + fast_rnd(10);
699 actor->duration_animation = 3*60;
700 scene->actors = g_slist_append(scene->actors, actor);
702 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
703 FALSE, FALSE, 100, 255,
704 (gpointer)&change_cloud, NULL, NULL);
705 actor->time_start_animation = now + fast_rnd(60) + 20;
706 actor->duration_animation = 5*60;
707 scene->actors = g_slist_append(scene->actors, actor);
710 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
711 FALSE, FALSE, 100, 255,
712 (gpointer)&change_plane2, NULL, NULL);
713 actor->time_start_animation = now + fast_rnd(40) + 20;
714 actor->duration_animation = 60;
715 scene->actors = g_slist_append(scene->actors, actor);
717 actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116,
718 FALSE, FALSE, 100, 255,
719 (gpointer)&change_plane1, NULL, NULL);
720 actor->time_start_animation = now + fast_rnd(20);
721 actor->duration_animation = 30;
722 scene->actors = g_slist_append(scene->actors, actor);
724 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
725 TRUE, TRUE, 100, 255,
726 (gpointer)&change_static_actor_with_corner, NULL, NULL);
727 change_static_actor_with_corner(actor, desktop_plugin);
728 scene->actors = g_slist_append(scene->actors, actor);
730 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
731 FALSE, FALSE, 100, 255,
732 (gpointer)&change_wind, NULL, NULL);
733 change_wind(actor, desktop_plugin);
734 scene->actors = g_slist_append(scene->actors, actor);
736 actor1 = init_object(desktop_plugin, "signal_red", "red.png",
737 486, 425, 10, 18, 38,
738 FALSE, TRUE, 100, 255, NULL, NULL, NULL);
739 //actor->time_start_animation = now + fast_rnd(30) + 10;
740 scene->actors = g_slist_append(scene->actors, actor1);
742 actor2 = init_object(desktop_plugin, "signal_green", "green.png",
743 486, 425, 10, 18, 38,
744 TRUE, TRUE, 100, 255, NULL, NULL, NULL);
745 //actor->time_start_animation = now + fast_rnd(30) + 10;
746 scene->actors = g_slist_append(scene->actors, actor2);
747 child = g_ptr_array_sized_new(2);
748 g_ptr_array_add(child, actor1);
749 g_ptr_array_add(child, actor2);
750 actor = init_object(desktop_plugin, "signal", "",
751 486, 425, 10, 18, 38,
752 FALSE, FALSE, 100, 255,
753 (gpointer)&change_signal, NULL, child);
754 actor->time_start_animation = now + fast_rnd(30) + 10;
755 scene->actors = g_slist_append(scene->actors, actor);
796 for (i=0; i<13; i++){
797 actor = init_object(desktop_plugin, "window", "window.png",
798 winds[i][0], winds[i][1], 10, 8, 9,
799 FALSE, TRUE, 100, 255,
800 (gpointer)&change_window1, NULL, NULL);
801 //change_window1(actor, desktop_plugin);
802 actor->time_start_animation = now + fast_rnd(30);
803 scene->actors = g_slist_append(scene->actors, actor);
807 run_long_timeout(desktop_plugin);
810 /*******************************************************************************/
812 init_scene_theme(AWallpaperPlugin *desktop_plugin)
814 void (*func)(gpointer);
815 func = g_hash_table_lookup(desktop_plugin->priv->hash_scene_func, desktop_plugin->priv->theme);
817 (*func)(desktop_plugin);