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 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){ gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_NULL); gst_object_unref (GST_OBJECT (desktop_plugin->priv->pipeline));
162 case GST_MESSAGE_ERROR: break;
169 init_scene_Video(AWallpaperPlugin *desktop_plugin)
172 GstElement *videosink;
174 gchar *file_plus_uri;
177 desktop_plugin->priv->pipeline = gst_pipeline_new("gst-player");
178 bin = gst_element_factory_make ("playbin2", "bin");
179 videosink = gst_element_factory_make ("ximagesink", "videosink");
180 g_object_set (G_OBJECT (bin), "video-sink", videosink, NULL);
181 gst_bin_add (GST_BIN (desktop_plugin->priv->pipeline), bin);
185 bus = gst_pipeline_get_bus (GST_PIPELINE (desktop_plugin->priv->pipeline));
186 gst_bus_add_watch(bus, bus_call, desktop_plugin);
187 gst_object_unref (bus);
189 file_plus_uri = g_strdup_printf("file://%s",desktop_plugin->priv->theme_string_parametr1);
190 g_object_set (G_OBJECT (bin), "uri", file_plus_uri, NULL );
191 g_object_set (G_OBJECT (videosink), "force-aspect-ratio", TRUE, NULL );
192 if (GST_IS_X_OVERLAY (videosink))
193 gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (videosink), GDK_DRAWABLE_XID(desktop_plugin->priv->window->window));
194 if (desktop_plugin->priv->visible)
195 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
199 init_scene_Matrix(AWallpaperPlugin *desktop_plugin)
204 gint now = time(NULL);
207 if (desktop_plugin->priv->rich_animation){
215 /* fprintf(stderr, "init scene2 \n"); */
216 scene = g_new0(Scene, 1);
217 //scene.daytime = get_daytime();
218 scene->actors = NULL;
219 desktop_plugin->priv->scene = scene;
221 actor = init_object(desktop_plugin, "background", "bg.png",
223 TRUE, TRUE, 100, 255,
225 scene->actors = g_slist_append(scene->actors, actor);
227 actor = init_object(desktop_plugin, "symbols", "symbols.png",
229 TRUE, TRUE, 100, 255,
231 scene->actors = g_slist_append(scene->actors, actor);
233 child = g_ptr_array_sized_new(4);
234 actor = init_object(desktop_plugin, "layer1", "layer1_2.png",
236 TRUE, TRUE, 100, 255,
238 //actor->time_start_animation = now;
239 //actor->duration_animation = G_MAXINT;
240 scene->actors = g_slist_append(scene->actors, actor);
241 g_ptr_array_add(child, actor);
243 actor = init_object(desktop_plugin, "layer1", "layer1_1.png",
245 TRUE, TRUE, 100, 255,
247 //actor->time_start_animation = now;
248 //actor->duration_animation = G_MAXINT;
249 scene->actors = g_slist_append(scene->actors, actor);
250 g_ptr_array_add(child, actor);
252 actor = init_object(desktop_plugin, "layer2", "layer2_2.png",
254 TRUE, TRUE, 100, 255,
256 //actor->time_start_animation = now;
257 //actor->duration_animation = G_MAXINT;
258 scene->actors = g_slist_append(scene->actors, actor);
259 g_ptr_array_add(child, actor);
261 actor = init_object(desktop_plugin, "layer2", "layer2_1.png",
263 TRUE, TRUE, 100, 255,
265 //actor->time_start_animation = now;
266 //actor->duration_animation = G_MAXINT;
267 scene->actors = g_slist_append(scene->actors, actor);
268 g_ptr_array_add(child, actor);
270 actor = init_object(desktop_plugin, "layers", "",
272 FALSE, FALSE, 100, 255,
273 (gpointer)&change_layer, NULL, child);
274 actor->time_start_animation = now;
275 actor->duration_animation = G_MAXINT;
276 scene->actors = g_slist_append(scene->actors, actor);
278 run_long_timeout(desktop_plugin);
282 /* Init Modern Scene */
284 init_scene_Modern(AWallpaperPlugin *desktop_plugin)
288 gint now = time(NULL);
293 /* fprintf(stderr, "init scene \n"); */
294 scene = g_new0(Scene, 1);
295 scene->daytime = get_daytime();
296 scene->actors = NULL;
297 scene->wind_orientation = -1;
298 scene->wind_angle = 0.3;
299 /* init value for random */
300 scene->seed = time(NULL);
301 scene->notification = TRUE;
302 desktop_plugin->priv->scene = scene;
303 actor = init_object(desktop_plugin, "sky", "sky0.png",
305 TRUE , TRUE, 100, 255,
306 (gpointer)&change_static_actor, NULL, NULL);
307 scene->actors = g_slist_append(scene->actors, actor);
308 change_static_actor(actor, desktop_plugin);
310 actor = init_object(desktop_plugin, "sun", "sun.png",
312 FALSE, FALSE, 100, 255,
313 (gpointer)&change_sun, NULL, NULL);
314 actor->time_start_animation = now;
315 actor->duration_animation = G_MAXINT;
316 change_sun(actor, desktop_plugin);
317 scene->actors = g_slist_append(scene->actors, actor);
319 //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
320 // TRUE, 100, 255, NULL, NULL);
321 //scene.actors = g_slist_append(scene.actors, actor);
323 actor = init_object(desktop_plugin, "cloud1", "cloud1.png",
324 0, fast_rnd(300)-97, 7, 150, 97,
325 FALSE, FALSE, 100, 255,
326 (gpointer)&change_cloud, NULL, NULL);
327 actor->time_start_animation = now + fast_rnd(20);
328 actor->duration_animation = 3*60;
329 scene->actors = g_slist_append(scene->actors, actor);
331 actor = init_object(desktop_plugin, "cloud2", "cloud2.png",
332 0, fast_rnd(300)-75, 7, 188, 75,
333 FALSE, FALSE, 100, 255,
334 (gpointer)&change_cloud, NULL, NULL);
335 actor->time_start_animation = now + fast_rnd(40)+10;
336 actor->duration_animation = 3*60;
337 scene->actors = g_slist_append(scene->actors, actor);
339 actor = init_object(desktop_plugin, "cloud4", "cloud4.png",
340 0, fast_rnd(300)-75, 7, 150, 75,
341 FALSE, FALSE, 100, 255,
342 (gpointer)&change_cloud, NULL, NULL);
343 actor->time_start_animation = now + fast_rnd(60) + 20;
344 actor->duration_animation = 5*60;
345 scene->actors = g_slist_append(scene->actors, actor);
348 actor = init_object(desktop_plugin, "town", "town0.png",
350 TRUE, TRUE, 100, 255,
351 (gpointer)&change_static_actor, NULL, NULL);
352 change_static_actor(actor, desktop_plugin);
353 scene->actors = g_slist_append(scene->actors, actor);
355 actor = init_object(desktop_plugin, "stend", "stend0.png",
356 452, 166, 9, 300, 305,
357 TRUE, TRUE, 100, 255,
358 (gpointer)&change_static_actor, NULL, NULL);
359 change_static_actor(actor, desktop_plugin);
360 scene->actors = g_slist_append(scene->actors, actor);
363 child = g_ptr_array_sized_new(4);
364 actor = init_object(desktop_plugin, "call", "call.png",
366 FALSE, TRUE, 100, 255,
368 scene->actors = g_slist_append(scene->actors, actor);
369 g_ptr_array_add(child, actor);
371 actor = init_object(desktop_plugin, "chat", "chat.png",
373 FALSE, TRUE, 100, 255,
375 scene->actors = g_slist_append(scene->actors, actor);
376 g_ptr_array_add(child, actor);
378 actor = init_object(desktop_plugin, "mail", "mail.png",
380 FALSE, TRUE, 100, 255,
382 scene->actors = g_slist_append(scene->actors, actor);
383 g_ptr_array_add(child, actor);
385 actor = init_object(desktop_plugin, "sms", "sms.png",
387 FALSE, TRUE, 100, 255,
389 scene->actors = g_slist_append(scene->actors, actor);
390 g_ptr_array_add(child, actor);
392 actor = init_object(desktop_plugin, "billboard_text", "",
393 470, 174, 9, 300, 108,
394 FALSE, FALSE, 100, 255,
395 (gpointer)&change_billboard, NULL, child);
396 create_hildon_actor_text(actor, desktop_plugin);
397 //actor->time_start_animation = time(NULL) + 20;
398 change_billboard(actor, desktop_plugin);
399 scene->actors = g_slist_append(scene->actors, actor);
401 actor = init_object(desktop_plugin, "tram", "tram.png",
402 -300, 225, 10, 350, 210,
403 FALSE, FALSE, 100, 255,
404 (gpointer)&change_tram, NULL, NULL);
405 actor->time_start_animation = time(NULL) + fast_rnd(10);
406 actor->duration_animation = 60;
407 scene->actors = g_slist_append(scene->actors, actor);
409 actor = init_object(desktop_plugin, "border", "border0.png",
410 0, 480-79, 11, 800, 79,
411 TRUE, TRUE, 100, 255,
412 (gpointer)&change_static_actor_with_corner, NULL, NULL);
413 change_static_actor_with_corner(actor, desktop_plugin);
414 scene->actors = g_slist_append(scene->actors, actor);
416 actor = init_object(desktop_plugin, "moon", "moon1.png",
418 FALSE, FALSE, 100, 255,
419 (gpointer)&change_moon, NULL, NULL);
420 change_moon(actor, desktop_plugin);
421 scene->actors = g_slist_append(scene->actors, actor);
423 actor = init_object(desktop_plugin, "wind", "",
425 FALSE, FALSE, 100, 255,
426 (gpointer)&change_wind, NULL, NULL);
427 change_wind(actor, desktop_plugin);
428 scene->actors = g_slist_append(scene->actors, actor);
430 /* windows in 4-th house */
470 for (i=0; i<13; i++){
471 actor = init_object(desktop_plugin, "window1", "window1.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 1-th house */
507 actor = init_object(desktop_plugin, "window2", "window2.png",
508 winds[i][0], winds[i][1], 8, 8, 10,
509 FALSE, FALSE, 100, 255,
510 (gpointer)&change_window1, NULL, NULL);
511 //change_window1(actor, desktop_plugin);
512 actor->time_start_animation = now + fast_rnd(30);
513 scene->actors = g_slist_append(scene->actors, actor);
517 /* windows in 3-th house */
549 for (i=0; i<10; i++){
550 actor = init_object(desktop_plugin, "window3", "window3.png",
551 winds[i][0], winds[i][1], 8, 8, 10,
552 FALSE, FALSE, 100, 255,
553 (gpointer)&change_window1, NULL, NULL);
554 //change_window1(actor, desktop_plugin);
555 actor->time_start_animation = now + fast_rnd(30);
556 scene->actors = g_slist_append(scene->actors, actor);
560 /* windows in 5-th house */
584 actor = init_object(desktop_plugin, "window4", "window4.png",
585 winds[i][0], winds[i][1], 8, 8, 10,
586 FALSE, FALSE, 100, 255,
587 (gpointer)&change_window1, NULL, NULL);
588 //change_window1(actor, desktop_plugin);
589 actor->time_start_animation = now + fast_rnd(30);
590 scene->actors = g_slist_append(scene->actors, actor);
594 /* windows in 6-th house */
615 actor = init_object(desktop_plugin, "window5", "window5.png",
616 winds[i][0], winds[i][1], 8, 8, 10,
617 FALSE, FALSE, 100, 255,
618 (gpointer)&change_window1, NULL, NULL);
619 //change_window1(actor, desktop_plugin);
620 actor->time_start_animation = now + fast_rnd(30);
621 scene->actors = g_slist_append(scene->actors, actor);
624 run_long_timeout(desktop_plugin);
627 anim = g_new0(Animation, 1);
630 anim->func_change = &change_tram;
631 anim->func_time = NULL;
632 anim->timestart = time(NULL);
635 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
639 /* Init Berlin Scene */
641 init_scene_Berlin(AWallpaperPlugin *desktop_plugin)
643 Actor *actor, *actor1, *actor2;
645 gint now = time(NULL);
648 GPtrArray *child = NULL;
650 scene = g_new0(Scene, 1);
651 scene->daytime = get_daytime();
652 scene->actors = NULL;
653 scene->wind_orientation = -1;
654 scene->wind_angle = 0.3;
655 /* init value for random */
656 scene->seed = time(NULL);
657 desktop_plugin->priv->scene = scene;
659 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
660 TRUE, TRUE, 100, 255,
661 (gpointer)&change_static_actor, NULL, NULL);
662 change_static_actor(actor, desktop_plugin);
663 scene->actors = g_slist_append(scene->actors, actor);
666 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
667 FALSE, FALSE, 100, 255,
668 (gpointer)&change_sun, NULL, NULL);
669 actor->time_start_animation = time(NULL);
670 actor->duration_animation = G_MAXINT;
671 change_sun(actor, desktop_plugin);
672 scene->actors = g_slist_append(scene->actors, actor);
675 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
676 TRUE, 100, 255, NULL, NULL);
677 scene.actors = g_slist_append(scene.actors, actor);
680 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
681 FALSE, FALSE, 100, 255,
682 (gpointer)&change_moon, NULL, NULL);
683 change_moon(actor, desktop_plugin);
684 scene->actors = g_slist_append(scene->actors, actor);
686 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
687 FALSE, FALSE, 100, 255,
688 (gpointer)&change_cloud, NULL, NULL);
689 actor->time_start_animation = now + fast_rnd(30) + 10;
690 actor->duration_animation = 3*60;
691 scene->actors = g_slist_append(scene->actors, actor);
693 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
694 FALSE, FALSE, 100, 255,
695 (gpointer)&change_cloud, NULL, NULL);
696 actor->time_start_animation = now + fast_rnd(10);
697 actor->duration_animation = 3*60;
698 scene->actors = g_slist_append(scene->actors, actor);
700 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
701 FALSE, FALSE, 100, 255,
702 (gpointer)&change_cloud, NULL, NULL);
703 actor->time_start_animation = now + fast_rnd(60) + 20;
704 actor->duration_animation = 5*60;
705 scene->actors = g_slist_append(scene->actors, actor);
708 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
709 FALSE, FALSE, 100, 255,
710 (gpointer)&change_plane2, NULL, NULL);
711 actor->time_start_animation = now + fast_rnd(40) + 20;
712 actor->duration_animation = 60;
713 scene->actors = g_slist_append(scene->actors, actor);
715 actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116,
716 FALSE, FALSE, 100, 255,
717 (gpointer)&change_plane1, NULL, NULL);
718 actor->time_start_animation = now + fast_rnd(20);
719 actor->duration_animation = 30;
720 scene->actors = g_slist_append(scene->actors, actor);
722 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
723 TRUE, TRUE, 100, 255,
724 (gpointer)&change_static_actor_with_corner, NULL, NULL);
725 change_static_actor_with_corner(actor, desktop_plugin);
726 scene->actors = g_slist_append(scene->actors, actor);
728 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
729 FALSE, FALSE, 100, 255,
730 (gpointer)&change_wind, NULL, NULL);
731 change_wind(actor, desktop_plugin);
732 scene->actors = g_slist_append(scene->actors, actor);
734 actor1 = init_object(desktop_plugin, "signal_red", "red.png",
735 486, 425, 10, 18, 38,
736 FALSE, TRUE, 100, 255, NULL, NULL, NULL);
737 //actor->time_start_animation = now + fast_rnd(30) + 10;
738 scene->actors = g_slist_append(scene->actors, actor1);
740 actor2 = init_object(desktop_plugin, "signal_green", "green.png",
741 486, 425, 10, 18, 38,
742 TRUE, TRUE, 100, 255, NULL, NULL, NULL);
743 //actor->time_start_animation = now + fast_rnd(30) + 10;
744 scene->actors = g_slist_append(scene->actors, actor2);
745 child = g_ptr_array_sized_new(2);
746 g_ptr_array_add(child, actor1);
747 g_ptr_array_add(child, actor2);
748 actor = init_object(desktop_plugin, "signal", "",
749 486, 425, 10, 18, 38,
750 FALSE, FALSE, 100, 255,
751 (gpointer)&change_signal, NULL, child);
752 actor->time_start_animation = now + fast_rnd(30) + 10;
753 scene->actors = g_slist_append(scene->actors, actor);
794 for (i=0; i<13; i++){
795 actor = init_object(desktop_plugin, "window", "window.png",
796 winds[i][0], winds[i][1], 10, 8, 9,
797 FALSE, TRUE, 100, 255,
798 (gpointer)&change_window1, NULL, NULL);
799 //change_window1(actor, desktop_plugin);
800 actor->time_start_animation = now + fast_rnd(30);
801 scene->actors = g_slist_append(scene->actors, actor);
805 run_long_timeout(desktop_plugin);
810 init_scene_theme(AWallpaperPlugin *desktop_plugin)
812 void (*func)(gpointer);
813 func = g_hash_table_lookup(desktop_plugin->priv->hash_scene_func, desktop_plugin->priv->theme);
815 (*func)(desktop_plugin);