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){
97 GstClockTime nach = (GstClockTime)(0 * GST_MSECOND);
98 if (!gst_element_seek(desktop_plugin->priv->pipeline, 1.0, GST_FORMAT_TIME,
99 (GstSeekFlags) (GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT), GST_SEEK_TYPE_SET,
100 nach, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
101 fprintf(stderr,"ERROR in seek\n");
103 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
106 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));
110 case GST_MESSAGE_ERROR: break;
117 init_scene_Video(AWallpaperPlugin *desktop_plugin)
120 GstElement *videosink;
122 gchar *file_plus_uri;
125 desktop_plugin->priv->pipeline = gst_pipeline_new("gst-player");
126 bin = gst_element_factory_make ("playbin2", "bin");
127 videosink = gst_element_factory_make ("ximagesink", "videosink");
128 g_object_set (G_OBJECT (bin), "video-sink", videosink, NULL);
129 gst_bin_add (GST_BIN (desktop_plugin->priv->pipeline), bin);
133 bus = gst_pipeline_get_bus (GST_PIPELINE (desktop_plugin->priv->pipeline));
134 gst_bus_add_watch(bus, bus_call, desktop_plugin);
135 gst_object_unref (bus);
137 file_plus_uri = g_strdup_printf("file://%s",desktop_plugin->priv->theme_string_parametr1);
138 g_object_set (G_OBJECT (bin), "uri", file_plus_uri, NULL );
139 g_object_set (G_OBJECT (videosink), "force-aspect-ratio", TRUE, NULL );
140 if (GST_IS_X_OVERLAY (videosink))
141 gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (videosink), GDK_DRAWABLE_XID(desktop_plugin->priv->window->window));
142 if (desktop_plugin->priv->visible)
143 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
147 init_scene_Matrix(AWallpaperPlugin *desktop_plugin)
152 gint now = time(NULL);
155 if (desktop_plugin->priv->rich_animation){
163 /* fprintf(stderr, "init scene2 \n"); */
164 scene = g_new0(Scene, 1);
165 //scene.daytime = get_daytime();
166 scene->actors = NULL;
167 desktop_plugin->priv->scene = scene;
169 actor = init_object(desktop_plugin, "background", "bg.png",
171 TRUE, TRUE, 100, 255,
173 scene->actors = g_slist_append(scene->actors, actor);
175 actor = init_object(desktop_plugin, "symbols", "symbols.png",
177 TRUE, TRUE, 100, 255,
179 scene->actors = g_slist_append(scene->actors, actor);
181 child = g_ptr_array_sized_new(4);
182 actor = init_object(desktop_plugin, "layer1", "layer1_2.png",
184 TRUE, TRUE, 100, 255,
186 //actor->time_start_animation = now;
187 //actor->duration_animation = G_MAXINT;
188 scene->actors = g_slist_append(scene->actors, actor);
189 g_ptr_array_add(child, actor);
191 actor = init_object(desktop_plugin, "layer1", "layer1_1.png",
193 TRUE, TRUE, 100, 255,
195 //actor->time_start_animation = now;
196 //actor->duration_animation = G_MAXINT;
197 scene->actors = g_slist_append(scene->actors, actor);
198 g_ptr_array_add(child, actor);
200 actor = init_object(desktop_plugin, "layer2", "layer2_2.png",
202 TRUE, TRUE, 100, 255,
204 //actor->time_start_animation = now;
205 //actor->duration_animation = G_MAXINT;
206 scene->actors = g_slist_append(scene->actors, actor);
207 g_ptr_array_add(child, actor);
209 actor = init_object(desktop_plugin, "layer2", "layer2_1.png",
211 TRUE, TRUE, 100, 255,
213 //actor->time_start_animation = now;
214 //actor->duration_animation = G_MAXINT;
215 scene->actors = g_slist_append(scene->actors, actor);
216 g_ptr_array_add(child, actor);
218 actor = init_object(desktop_plugin, "layers", "",
220 FALSE, FALSE, 100, 255,
221 (gpointer)&change_layer, NULL, child);
222 actor->time_start_animation = now;
223 actor->duration_animation = G_MAXINT;
224 scene->actors = g_slist_append(scene->actors, actor);
226 run_long_timeout(desktop_plugin);
230 /* Init Modern Scene */
232 init_scene_Modern(AWallpaperPlugin *desktop_plugin)
236 gint now = time(NULL);
241 /* fprintf(stderr, "init scene \n"); */
242 scene = g_new0(Scene, 1);
243 scene->daytime = get_daytime();
244 scene->actors = NULL;
245 scene->wind_orientation = -1;
246 scene->wind_angle = 0.3;
247 /* init value for random */
248 scene->seed = time(NULL);
249 scene->notification = TRUE;
250 desktop_plugin->priv->scene = scene;
251 actor = init_object(desktop_plugin, "sky", "sky0.png",
253 TRUE , TRUE, 100, 255,
254 (gpointer)&change_static_actor, NULL, NULL);
255 scene->actors = g_slist_append(scene->actors, actor);
256 change_static_actor(actor, desktop_plugin);
258 actor = init_object(desktop_plugin, "sun", "sun.png",
260 FALSE, FALSE, 100, 255,
261 (gpointer)&change_sun, NULL, NULL);
262 actor->time_start_animation = now;
263 actor->duration_animation = G_MAXINT;
264 change_sun(actor, desktop_plugin);
265 scene->actors = g_slist_append(scene->actors, actor);
267 //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
268 // TRUE, 100, 255, NULL, NULL);
269 //scene.actors = g_slist_append(scene.actors, actor);
271 actor = init_object(desktop_plugin, "cloud1", "cloud1.png",
272 0, fast_rnd(300)-97, 7, 150, 97,
273 FALSE, FALSE, 100, 255,
274 (gpointer)&change_cloud, NULL, NULL);
275 actor->time_start_animation = now + fast_rnd(20);
276 actor->duration_animation = 3*60;
277 scene->actors = g_slist_append(scene->actors, actor);
279 actor = init_object(desktop_plugin, "cloud2", "cloud2.png",
280 0, fast_rnd(300)-75, 7, 188, 75,
281 FALSE, FALSE, 100, 255,
282 (gpointer)&change_cloud, NULL, NULL);
283 actor->time_start_animation = now + fast_rnd(40)+10;
284 actor->duration_animation = 3*60;
285 scene->actors = g_slist_append(scene->actors, actor);
287 actor = init_object(desktop_plugin, "cloud4", "cloud4.png",
288 0, fast_rnd(300)-75, 7, 150, 75,
289 FALSE, FALSE, 100, 255,
290 (gpointer)&change_cloud, NULL, NULL);
291 actor->time_start_animation = now + fast_rnd(60) + 20;
292 actor->duration_animation = 5*60;
293 scene->actors = g_slist_append(scene->actors, actor);
296 actor = init_object(desktop_plugin, "town", "town0.png",
298 TRUE, TRUE, 100, 255,
299 (gpointer)&change_static_actor, NULL, NULL);
300 change_static_actor(actor, desktop_plugin);
301 scene->actors = g_slist_append(scene->actors, actor);
303 actor = init_object(desktop_plugin, "stend", "stend0.png",
304 452, 166, 9, 300, 305,
305 TRUE, TRUE, 100, 255,
306 (gpointer)&change_static_actor, NULL, NULL);
307 change_static_actor(actor, desktop_plugin);
308 scene->actors = g_slist_append(scene->actors, actor);
311 child = g_ptr_array_sized_new(4);
312 actor = init_object(desktop_plugin, "call", "call.png",
314 FALSE, TRUE, 100, 255,
316 scene->actors = g_slist_append(scene->actors, actor);
317 g_ptr_array_add(child, actor);
319 actor = init_object(desktop_plugin, "chat", "chat.png",
321 FALSE, TRUE, 100, 255,
323 scene->actors = g_slist_append(scene->actors, actor);
324 g_ptr_array_add(child, actor);
326 actor = init_object(desktop_plugin, "mail", "mail.png",
328 FALSE, TRUE, 100, 255,
330 scene->actors = g_slist_append(scene->actors, actor);
331 g_ptr_array_add(child, actor);
333 actor = init_object(desktop_plugin, "sms", "sms.png",
335 FALSE, TRUE, 100, 255,
337 scene->actors = g_slist_append(scene->actors, actor);
338 g_ptr_array_add(child, actor);
340 actor = init_object(desktop_plugin, "billboard_text", "",
341 470, 174, 9, 300, 108,
342 FALSE, FALSE, 100, 255,
343 (gpointer)&change_billboard, NULL, child);
344 create_hildon_actor_text(actor, desktop_plugin);
345 //actor->time_start_animation = time(NULL) + 20;
346 change_billboard(actor, desktop_plugin);
347 scene->actors = g_slist_append(scene->actors, actor);
349 actor = init_object(desktop_plugin, "tram", "tram.png",
350 -300, 225, 10, 350, 210,
351 FALSE, FALSE, 100, 255,
352 (gpointer)&change_tram, NULL, NULL);
353 actor->time_start_animation = time(NULL) + fast_rnd(10);
354 actor->duration_animation = 60;
355 scene->actors = g_slist_append(scene->actors, actor);
357 actor = init_object(desktop_plugin, "border", "border0.png",
358 0, 480-79, 11, 800, 79,
359 TRUE, TRUE, 100, 255,
360 (gpointer)&change_static_actor_with_corner, NULL, NULL);
361 change_static_actor_with_corner(actor, desktop_plugin);
362 scene->actors = g_slist_append(scene->actors, actor);
364 actor = init_object(desktop_plugin, "moon", "moon1.png",
366 FALSE, FALSE, 100, 255,
367 (gpointer)&change_moon, NULL, NULL);
368 change_moon(actor, desktop_plugin);
369 scene->actors = g_slist_append(scene->actors, actor);
371 actor = init_object(desktop_plugin, "wind", "",
373 FALSE, FALSE, 100, 255,
374 (gpointer)&change_wind, NULL, NULL);
375 change_wind(actor, desktop_plugin);
376 scene->actors = g_slist_append(scene->actors, actor);
378 /* windows in 4-th house */
418 for (i=0; i<13; i++){
419 actor = init_object(desktop_plugin, "window1", "window1.png",
420 winds[i][0], winds[i][1], 8, 8, 10,
421 FALSE, FALSE, 100, 255,
422 (gpointer)&change_window1, NULL, NULL);
423 //change_window1(actor, desktop_plugin);
424 actor->time_start_animation = now + fast_rnd(30);
425 scene->actors = g_slist_append(scene->actors, actor);
429 /* windows in 1-th house */
455 actor = init_object(desktop_plugin, "window2", "window2.png",
456 winds[i][0], winds[i][1], 8, 8, 10,
457 FALSE, FALSE, 100, 255,
458 (gpointer)&change_window1, NULL, NULL);
459 //change_window1(actor, desktop_plugin);
460 actor->time_start_animation = now + fast_rnd(30);
461 scene->actors = g_slist_append(scene->actors, actor);
465 /* windows in 3-th house */
497 for (i=0; i<10; i++){
498 actor = init_object(desktop_plugin, "window3", "window3.png",
499 winds[i][0], winds[i][1], 8, 8, 10,
500 FALSE, FALSE, 100, 255,
501 (gpointer)&change_window1, NULL, NULL);
502 //change_window1(actor, desktop_plugin);
503 actor->time_start_animation = now + fast_rnd(30);
504 scene->actors = g_slist_append(scene->actors, actor);
508 /* windows in 5-th house */
532 actor = init_object(desktop_plugin, "window4", "window4.png",
533 winds[i][0], winds[i][1], 8, 8, 10,
534 FALSE, FALSE, 100, 255,
535 (gpointer)&change_window1, NULL, NULL);
536 //change_window1(actor, desktop_plugin);
537 actor->time_start_animation = now + fast_rnd(30);
538 scene->actors = g_slist_append(scene->actors, actor);
542 /* windows in 6-th house */
563 actor = init_object(desktop_plugin, "window5", "window5.png",
564 winds[i][0], winds[i][1], 8, 8, 10,
565 FALSE, FALSE, 100, 255,
566 (gpointer)&change_window1, NULL, NULL);
567 //change_window1(actor, desktop_plugin);
568 actor->time_start_animation = now + fast_rnd(30);
569 scene->actors = g_slist_append(scene->actors, actor);
572 run_long_timeout(desktop_plugin);
575 anim = g_new0(Animation, 1);
578 anim->func_change = &change_tram;
579 anim->func_time = NULL;
580 anim->timestart = time(NULL);
583 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
587 /* Init Berlin Scene */
589 init_scene_Berlin(AWallpaperPlugin *desktop_plugin)
591 Actor *actor, *actor1, *actor2;
593 gint now = time(NULL);
596 GPtrArray *child = NULL;
598 scene = g_new0(Scene, 1);
599 scene->daytime = get_daytime();
600 scene->actors = NULL;
601 scene->wind_orientation = -1;
602 scene->wind_angle = 0.3;
603 /* init value for random */
604 scene->seed = time(NULL);
605 desktop_plugin->priv->scene = scene;
607 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
608 TRUE, TRUE, 100, 255,
609 (gpointer)&change_static_actor, NULL, NULL);
610 change_static_actor(actor, desktop_plugin);
611 scene->actors = g_slist_append(scene->actors, actor);
614 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
615 FALSE, FALSE, 100, 255,
616 (gpointer)&change_sun, NULL, NULL);
617 actor->time_start_animation = time(NULL);
618 actor->duration_animation = G_MAXINT;
619 change_sun(actor, desktop_plugin);
620 scene->actors = g_slist_append(scene->actors, actor);
623 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
624 TRUE, 100, 255, NULL, NULL);
625 scene.actors = g_slist_append(scene.actors, actor);
628 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
629 FALSE, FALSE, 100, 255,
630 (gpointer)&change_moon, NULL, NULL);
631 change_moon(actor, desktop_plugin);
632 scene->actors = g_slist_append(scene->actors, actor);
634 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
635 FALSE, FALSE, 100, 255,
636 (gpointer)&change_cloud, NULL, NULL);
637 actor->time_start_animation = now + fast_rnd(30) + 10;
638 actor->duration_animation = 3*60;
639 scene->actors = g_slist_append(scene->actors, actor);
641 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
642 FALSE, FALSE, 100, 255,
643 (gpointer)&change_cloud, NULL, NULL);
644 actor->time_start_animation = now + fast_rnd(10);
645 actor->duration_animation = 3*60;
646 scene->actors = g_slist_append(scene->actors, actor);
648 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
649 FALSE, FALSE, 100, 255,
650 (gpointer)&change_cloud, NULL, NULL);
651 actor->time_start_animation = now + fast_rnd(60) + 20;
652 actor->duration_animation = 5*60;
653 scene->actors = g_slist_append(scene->actors, actor);
656 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
657 FALSE, FALSE, 100, 255,
658 (gpointer)&change_plane2, NULL, NULL);
659 actor->time_start_animation = now + fast_rnd(40) + 20;
660 actor->duration_animation = 60;
661 scene->actors = g_slist_append(scene->actors, actor);
663 actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116,
664 FALSE, FALSE, 100, 255,
665 (gpointer)&change_plane1, NULL, NULL);
666 actor->time_start_animation = now + fast_rnd(20);
667 actor->duration_animation = 30;
668 scene->actors = g_slist_append(scene->actors, actor);
670 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
671 TRUE, TRUE, 100, 255,
672 (gpointer)&change_static_actor_with_corner, NULL, NULL);
673 change_static_actor_with_corner(actor, desktop_plugin);
674 scene->actors = g_slist_append(scene->actors, actor);
676 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
677 FALSE, FALSE, 100, 255,
678 (gpointer)&change_wind, NULL, NULL);
679 change_wind(actor, desktop_plugin);
680 scene->actors = g_slist_append(scene->actors, actor);
682 actor1 = init_object(desktop_plugin, "signal_red", "red.png",
683 486, 425, 10, 18, 38,
684 FALSE, TRUE, 100, 255, NULL, NULL, NULL);
685 //actor->time_start_animation = now + fast_rnd(30) + 10;
686 scene->actors = g_slist_append(scene->actors, actor1);
688 actor2 = init_object(desktop_plugin, "signal_green", "green.png",
689 486, 425, 10, 18, 38,
690 TRUE, TRUE, 100, 255, NULL, NULL, NULL);
691 //actor->time_start_animation = now + fast_rnd(30) + 10;
692 scene->actors = g_slist_append(scene->actors, actor2);
693 child = g_ptr_array_sized_new(2);
694 g_ptr_array_add(child, actor1);
695 g_ptr_array_add(child, actor2);
696 actor = init_object(desktop_plugin, "signal", "",
697 486, 425, 10, 18, 38,
698 FALSE, FALSE, 100, 255,
699 (gpointer)&change_signal, NULL, child);
700 actor->time_start_animation = now + fast_rnd(30) + 10;
701 scene->actors = g_slist_append(scene->actors, actor);
742 for (i=0; i<13; i++){
743 actor = init_object(desktop_plugin, "window", "window.png",
744 winds[i][0], winds[i][1], 10, 8, 9,
745 FALSE, TRUE, 100, 255,
746 (gpointer)&change_window1, NULL, NULL);
747 //change_window1(actor, desktop_plugin);
748 actor->time_start_animation = now + fast_rnd(30);
749 scene->actors = g_slist_append(scene->actors, actor);
753 run_long_timeout(desktop_plugin);
758 init_scene_theme(AWallpaperPlugin *desktop_plugin)
760 void (*func)(gpointer);
761 func = g_hash_table_lookup(desktop_plugin->priv->hash_scene_func, desktop_plugin->priv->theme);
763 (*func)(desktop_plugin);