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-common.h"
26 #include "livewp-home-widget.h"
27 #include <gconf/gconf-client.h>
28 #include "livewp-rules.h"
32 #define PLUGIN_NAME "livewp-home-widget.desktop-0"
33 #define GCONF_KEY_POSITION "/apps/osso/hildon-desktop/applets/%s/position"
34 #define GCONF_KEY_MODIFIED "/apps/osso/hildon-desktop/applets/%s/modified"
35 #define GCONF_KEY_VIEW "/apps/osso/hildon-desktop/applets/%s/view"
37 HD_DEFINE_PLUGIN_MODULE (AWallpaperPlugin, animation_wallpaper_plugin, HD_TYPE_HOME_PLUGIN_ITEM)
38 #define Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE (obj,\
39 Animation_Wallpaper_TYPE_HOME_PLUGIN,\
40 Animation_WallpaperPrivate))
43 lw_applet_realize (GtkWidget *widget)
47 screen = gtk_widget_get_screen (widget);
48 gtk_widget_set_colormap (widget,
49 gdk_screen_get_rgba_colormap (screen));
50 gtk_widget_set_app_paintable (widget,
52 GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->realize (widget);
57 lw_applet_expose_event(GtkWidget *widget,
58 GdkEventExpose *event)
62 /* Create cairo context */
63 cr = gdk_cairo_create (GDK_DRAWABLE (widget->window));
64 gdk_cairo_region (cr, event->region);
67 /* Draw alpha background */
68 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
69 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0);
75 return GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->expose_event (widget,
80 expose_event (GtkWidget *widget,GdkEventExpose *event,
84 GdkPixbuf *pixbuf = (GdkPixbuf *) data;
86 cr = gdk_cairo_create(widget->window);
88 gdk_cairo_region(cr, event->region);
89 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
90 gdk_cairo_set_source_pixbuf(cr, pixbuf, 0.0, 0.0);
98 realize (GtkWidget *widget)
101 screen = gtk_widget_get_screen (widget);
102 gtk_widget_set_colormap (widget, gdk_screen_get_rgba_colormap (screen));
105 /* Set position of widget on desktop */
107 init_applet_position(gint *xapplet, gint *yapplet)
109 GSList *position = NULL;
113 GError *error = NULL;
114 GConfClient *gconf_client = gconf_client_get_default ();
115 position_key = g_strdup_printf (GCONF_KEY_POSITION, PLUGIN_NAME);
116 position = gconf_client_get_list (gconf_client,
120 if (position && position->data && position->next->data){
121 *xapplet = GPOINTER_TO_INT (position->data);
122 *yapplet = GPOINTER_TO_INT (position->next->data);
124 position = g_slist_prepend (g_slist_prepend (NULL,
125 GINT_TO_POINTER (Ystartposition)),
126 GINT_TO_POINTER (Xstartposition));
127 gconf_client_set_list (gconf_client,
132 *xapplet = Xstartposition;
133 *yapplet = Ystartposition;
135 g_free (position_key);
136 modified = g_strdup_printf ("%i", 0);
137 modified_key = g_strdup_printf (GCONF_KEY_MODIFIED, PLUGIN_NAME);
138 gconf_client_set_string (gconf_client,
143 g_free(modified_key);
144 gconf_client_clear_cache(gconf_client);
145 g_object_unref(gconf_client);
149 actor_set_position_full(GtkWidget *actor, gint x, gint y, gint z)
151 /* fprintf(stderr, "actor_set_position_full z=%d\n", z); */
152 hildon_animation_actor_set_position_full (HILDON_ANIMATION_ACTOR (actor),x-0, y-0, z);
157 destroy_hildon_actor(Actor *actor)
159 //fprintf(stderr, "destroy_hildon_actor %s\n",actor->name);
160 gtk_widget_destroy(actor->widget);
161 actor->widget = NULL;
166 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
168 GtkWidget *ha = NULL;
169 GdkPixbuf *pixbuf = NULL;
170 GtkWidget *image = NULL;
173 ha = hildon_animation_actor_new();
174 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
175 desktop_plugin->priv->theme, actor->filename);
176 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
180 /*fprintf(stderr, "create_hildon_actor %s %s\n", actor->name, str);*/
184 image = gtk_image_new_from_pixbuf (pixbuf);
185 g_object_unref(G_OBJECT(pixbuf));
188 g_signal_connect(G_OBJECT(image), "expose_event",
189 G_CALLBACK(expose_event), pixbuf);
190 gtk_container_add (GTK_CONTAINER (ha), image);
193 gtk_widget_show_all(ha);
198 //g_object_set_data(G_OBJECT(ha), "image", image);
199 actor->image = image;
200 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
202 set_actor_position(actor, actor->x, actor->y, actor->z, desktop_plugin);
203 set_actor_scale(actor, (double)actor->scale/100, (double)actor->scale/100);
204 set_actor_visible(actor, actor->visible);
209 change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
211 GtkWidget *image = NULL;
212 GdkPixbuf *pixbuf = NULL;
215 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
216 desktop_plugin->priv->theme, actor->filename);
218 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
225 image = gtk_image_new_from_pixbuf (pixbuf);
226 g_object_unref(G_OBJECT(pixbuf));
229 g_signal_connect(G_OBJECT(image), "expose_event",
230 G_CALLBACK(expose_event), pixbuf);
231 //if (g_object_get_data(G_OBJECT(actor->widget), "image")){
233 gtk_container_remove(GTK_CONTAINER(actor->widget), actor->image);
235 //g_object_set_data(G_OBJECT(actor->widget), "image", image);
236 actor->image = image;
237 gtk_container_add (GTK_CONTAINER (actor->widget), image);
238 realize(actor->widget);
239 gtk_widget_show_all(actor->widget);
249 destroy_scene(AWallpaperPlugin *desktop_plugin)
251 GSList * tmp = desktop_plugin->priv->scene->actors;
253 destroy_actor(tmp->data);
254 tmp = g_slist_next(tmp);
261 reload_scene(AWallpaperPlugin *desktop_plugin)
263 fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);
264 destroy_scene(desktop_plugin);
265 if (!strcmp(desktop_plugin->priv->theme,"Modern"))
266 init_scene(desktop_plugin);
267 else if (!strcmp(desktop_plugin->priv->theme,"Berlin"))
268 init_scene1(desktop_plugin);
269 else if (!strcmp(desktop_plugin->priv->theme,"Matrix"))
270 init_scene2(desktop_plugin);
274 init_scene2(AWallpaperPlugin *desktop_plugin)
279 gint now = time(NULL);
282 if (desktop_plugin->priv->rich_animation){
290 fprintf(stderr, "init scene2 \n");
291 scene = g_new0(Scene, 1);
292 //scene.daytime = get_daytime();
293 scene->actors = NULL;
294 desktop_plugin->priv->scene = scene;
296 actor = init_object(desktop_plugin, "background", "bg.png",
298 TRUE, TRUE, 100, 255,
300 scene->actors = g_slist_append(scene->actors, actor);
302 actor = init_object(desktop_plugin, "symbols", "symbols.png",
304 TRUE, TRUE, 100, 255,
306 scene->actors = g_slist_append(scene->actors, actor);
308 child = g_ptr_array_sized_new(4);
309 actor = init_object(desktop_plugin, "layer1", "layer1_2.png",
311 TRUE, TRUE, 100, 255,
313 //actor->time_start_animation = now;
314 //actor->duration_animation = G_MAXINT;
315 scene->actors = g_slist_append(scene->actors, actor);
316 g_ptr_array_add(child, actor);
318 actor = init_object(desktop_plugin, "layer1", "layer1_1.png",
320 TRUE, TRUE, 100, 255,
322 //actor->time_start_animation = now;
323 //actor->duration_animation = G_MAXINT;
324 scene->actors = g_slist_append(scene->actors, actor);
325 g_ptr_array_add(child, actor);
327 actor = init_object(desktop_plugin, "layer2", "layer2_2.png",
329 TRUE, TRUE, 100, 255,
331 //actor->time_start_animation = now;
332 //actor->duration_animation = G_MAXINT;
333 scene->actors = g_slist_append(scene->actors, actor);
334 g_ptr_array_add(child, actor);
336 actor = init_object(desktop_plugin, "layer2", "layer2_1.png",
338 TRUE, TRUE, 100, 255,
340 //actor->time_start_animation = now;
341 //actor->duration_animation = G_MAXINT;
342 scene->actors = g_slist_append(scene->actors, actor);
343 g_ptr_array_add(child, actor);
345 actor = init_object(desktop_plugin, "layers", "",
347 FALSE, FALSE, 100, 255,
348 (gpointer)&change_layer, NULL, child);
349 actor->time_start_animation = now;
350 actor->duration_animation = G_MAXINT;
351 scene->actors = g_slist_append(scene->actors, actor);
353 run_long_timeout(desktop_plugin);
357 /* Init Modern Scene */
359 init_scene(AWallpaperPlugin *desktop_plugin)
363 gint now = time(NULL);
367 //fprintf(stderr, "init scene \n");
368 scene = g_new0(Scene, 1);
369 scene->daytime = get_daytime();
370 scene->actors = NULL;
371 scene->wind_orientation = -1;
372 scene->wind_angle = 0.3;
373 /* init value for random */
374 scene->seed = time(NULL);
375 desktop_plugin->priv->scene = scene;
377 actor = init_object(desktop_plugin, "sky", "sky0.png",
379 TRUE , TRUE, 100, 255,
380 (gpointer)&change_static_actor, NULL, NULL);
381 change_static_actor(actor, desktop_plugin);
382 scene->actors = g_slist_append(scene->actors, actor);
384 actor = init_object(desktop_plugin, "sun", "sun.png",
386 FALSE, FALSE, 100, 255,
387 (gpointer)&change_sun, NULL, NULL);
388 actor->time_start_animation = now;
389 actor->duration_animation = G_MAXINT;
390 change_sun(actor, desktop_plugin);
391 scene->actors = g_slist_append(scene->actors, actor);
393 //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
394 // TRUE, 100, 255, NULL, NULL);
395 //scene.actors = g_slist_append(scene.actors, actor);
397 actor = init_object(desktop_plugin, "cloud1", "cloud1.png",
398 0, fast_rnd(300)-97, 7, 150, 97,
399 FALSE, FALSE, 100, 255,
400 (gpointer)&change_cloud, NULL, NULL);
401 actor->time_start_animation = now + fast_rnd(20);
402 actor->duration_animation = 3*60;
403 scene->actors = g_slist_append(scene->actors, actor);
405 actor = init_object(desktop_plugin, "cloud2", "cloud2.png",
406 0, fast_rnd(300)-75, 7, 188, 75,
407 FALSE, FALSE, 100, 255,
408 (gpointer)&change_cloud, NULL, NULL);
409 actor->time_start_animation = now + fast_rnd(40)+10;
410 actor->duration_animation = 3*60;
411 scene->actors = g_slist_append(scene->actors, actor);
413 actor = init_object(desktop_plugin, "cloud4", "cloud4.png",
414 0, fast_rnd(300)-75, 7, 150, 75,
415 FALSE, FALSE, 100, 255,
416 (gpointer)&change_cloud, NULL, NULL);
417 actor->time_start_animation = now + fast_rnd(60) + 20;
418 actor->duration_animation = 5*60;
419 scene->actors = g_slist_append(scene->actors, actor);
422 actor = init_object(desktop_plugin, "town", "town0.png",
424 TRUE, TRUE, 100, 255,
425 (gpointer)&change_static_actor, NULL, NULL);
426 change_static_actor(actor, desktop_plugin);
427 scene->actors = g_slist_append(scene->actors, actor);
429 actor = init_object(desktop_plugin, "stend", "stend0.png",
430 482, 146, 9, 300, 305,
431 TRUE, TRUE, 100, 255,
432 (gpointer)&change_static_actor, NULL, NULL);
433 change_static_actor(actor, desktop_plugin);
434 scene->actors = g_slist_append(scene->actors, actor);
436 actor = init_object(desktop_plugin, "tram", "tram.png",
437 -300, 225, 10, 350, 210,
438 FALSE, FALSE, 100, 255,
439 (gpointer)&change_tram, NULL, NULL);
440 actor->time_start_animation = time(NULL) + fast_rnd(10);
441 actor->duration_animation = 60;
442 scene->actors = g_slist_append(scene->actors, actor);
444 actor = init_object(desktop_plugin, "border", "border0.png",
445 0, 480-79, 11, 800, 79,
446 TRUE, TRUE, 100, 255,
447 (gpointer)&change_static_actor_with_corner, NULL, NULL);
448 change_static_actor_with_corner(actor, desktop_plugin);
449 scene->actors = g_slist_append(scene->actors, actor);
451 actor = init_object(desktop_plugin, "moon", "moon1.png",
453 FALSE, FALSE, 100, 255,
454 (gpointer)&change_moon, NULL, NULL);
455 change_moon(actor, desktop_plugin);
456 scene->actors = g_slist_append(scene->actors, actor);
458 actor = init_object(desktop_plugin, "wind", "",
460 FALSE, FALSE, 100, 255,
461 (gpointer)&change_wind, NULL, NULL);
462 change_wind(actor, desktop_plugin);
463 scene->actors = g_slist_append(scene->actors, actor);
465 /* windows in 4-th house */
505 for (i=0; i<13; i++){
506 actor = init_object(desktop_plugin, "window1", "window1.png",
507 winds[i][0], winds[i][1], 8, 8, 10,
508 FALSE, FALSE, 100, 255,
509 (gpointer)&change_window1, NULL, NULL);
510 //change_window1(actor, desktop_plugin);
511 actor->time_start_animation = now + fast_rnd(30);
512 scene->actors = g_slist_append(scene->actors, actor);
516 /* windows in 1-th house */
542 actor = init_object(desktop_plugin, "window2", "window2.png",
543 winds[i][0], winds[i][1], 8, 8, 10,
544 FALSE, FALSE, 100, 255,
545 (gpointer)&change_window1, NULL, NULL);
546 //change_window1(actor, desktop_plugin);
547 actor->time_start_animation = now + fast_rnd(30);
548 scene->actors = g_slist_append(scene->actors, actor);
552 /* windows in 3-th house */
584 for (i=0; i<10; i++){
585 actor = init_object(desktop_plugin, "window3", "window3.png",
586 winds[i][0], winds[i][1], 8, 8, 10,
587 FALSE, FALSE, 100, 255,
588 (gpointer)&change_window1, NULL, NULL);
589 //change_window1(actor, desktop_plugin);
590 actor->time_start_animation = now + fast_rnd(30);
591 scene->actors = g_slist_append(scene->actors, actor);
595 /* windows in 5-th house */
619 actor = init_object(desktop_plugin, "window4", "window4.png",
620 winds[i][0], winds[i][1], 8, 8, 10,
621 FALSE, FALSE, 100, 255,
622 (gpointer)&change_window1, NULL, NULL);
623 //change_window1(actor, desktop_plugin);
624 actor->time_start_animation = now + fast_rnd(30);
625 scene->actors = g_slist_append(scene->actors, actor);
629 /* windows in 6-th house */
650 actor = init_object(desktop_plugin, "window5", "window5.png",
651 winds[i][0], winds[i][1], 8, 8, 10,
652 FALSE, FALSE, 100, 255,
653 (gpointer)&change_window1, NULL, NULL);
654 //change_window1(actor, desktop_plugin);
655 actor->time_start_animation = now + fast_rnd(30);
656 scene->actors = g_slist_append(scene->actors, actor);
659 run_long_timeout(desktop_plugin);
662 anim = g_new0(Animation, 1);
665 anim->func_change = &change_tram;
666 anim->func_time = NULL;
667 anim->timestart = time(NULL);
670 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
674 /* Init Berlin Scene */
676 init_scene1(AWallpaperPlugin *desktop_plugin)
678 Actor *actor, *actor1, *actor2;
680 gint now = time(NULL);
683 GPtrArray *child = NULL;
685 scene = g_new0(Scene, 1);
686 scene->daytime = get_daytime();
687 scene->actors = NULL;
688 scene->wind_orientation = -1;
689 scene->wind_angle = 0.3;
690 /* init value for random */
691 scene->seed = time(NULL);
692 desktop_plugin->priv->scene = scene;
694 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
695 TRUE, TRUE, 100, 255,
696 (gpointer)&change_static_actor, NULL, NULL);
697 change_static_actor(actor, desktop_plugin);
698 scene->actors = g_slist_append(scene->actors, actor);
701 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
702 FALSE, FALSE, 100, 255,
703 (gpointer)&change_sun, NULL, NULL);
704 actor->time_start_animation = time(NULL);
705 actor->duration_animation = G_MAXINT;
706 change_sun(actor, desktop_plugin);
707 scene->actors = g_slist_append(scene->actors, actor);
710 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
711 TRUE, 100, 255, NULL, NULL);
712 scene.actors = g_slist_append(scene.actors, actor);
715 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
716 FALSE, FALSE, 100, 255,
717 (gpointer)&change_moon, NULL, NULL);
718 change_moon(actor, desktop_plugin);
719 scene->actors = g_slist_append(scene->actors, actor);
721 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
722 FALSE, FALSE, 100, 255,
723 (gpointer)&change_cloud, NULL, NULL);
724 actor->time_start_animation = now + fast_rnd(30) + 10;
725 actor->duration_animation = 3*60;
726 scene->actors = g_slist_append(scene->actors, actor);
728 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
729 FALSE, FALSE, 100, 255,
730 (gpointer)&change_cloud, NULL, NULL);
731 actor->time_start_animation = now + fast_rnd(10);
732 actor->duration_animation = 3*60;
733 scene->actors = g_slist_append(scene->actors, actor);
735 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
736 FALSE, FALSE, 100, 255,
737 (gpointer)&change_cloud, NULL, NULL);
738 actor->time_start_animation = now + fast_rnd(60) + 20;
739 actor->duration_animation = 5*60;
740 scene->actors = g_slist_append(scene->actors, actor);
743 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
744 FALSE, FALSE, 100, 255,
745 (gpointer)&change_plane2, NULL, NULL);
746 actor->time_start_animation = now + fast_rnd(40) + 20;
747 actor->duration_animation = 60;
748 scene->actors = g_slist_append(scene->actors, actor);
750 actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116,
751 FALSE, FALSE, 100, 255,
752 (gpointer)&change_plane1, NULL, NULL);
753 actor->time_start_animation = now + fast_rnd(20);
754 actor->duration_animation = 30;
755 scene->actors = g_slist_append(scene->actors, actor);
757 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
758 TRUE, TRUE, 100, 255,
759 (gpointer)&change_static_actor_with_corner, NULL, NULL);
760 change_static_actor_with_corner(actor, desktop_plugin);
761 scene->actors = g_slist_append(scene->actors, actor);
763 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
764 FALSE, FALSE, 100, 255,
765 (gpointer)&change_wind, NULL, NULL);
766 change_wind(actor, desktop_plugin);
767 scene->actors = g_slist_append(scene->actors, actor);
769 actor1 = init_object(desktop_plugin, "signal_red", "red.png",
770 486, 425, 10, 18, 38,
771 FALSE, TRUE, 100, 255, NULL, NULL, NULL);
772 //actor->time_start_animation = now + fast_rnd(30) + 10;
773 scene->actors = g_slist_append(scene->actors, actor1);
775 actor2 = init_object(desktop_plugin, "signal_green", "green.png",
776 486, 425, 10, 18, 38,
777 TRUE, TRUE, 100, 255, NULL, NULL, NULL);
778 //actor->time_start_animation = now + fast_rnd(30) + 10;
779 scene->actors = g_slist_append(scene->actors, actor2);
780 child = g_ptr_array_sized_new(2);
781 g_ptr_array_add(child, actor1);
782 g_ptr_array_add(child, actor2);
783 actor = init_object(desktop_plugin, "signal", "",
784 486, 425, 10, 18, 38,
785 FALSE, FALSE, 100, 255,
786 (gpointer)&change_signal, NULL, child);
787 actor->time_start_animation = now + fast_rnd(30) + 10;
788 scene->actors = g_slist_append(scene->actors, actor);
829 for (i=0; i<13; i++){
830 actor = init_object(desktop_plugin, "window", "window.png",
831 winds[i][0], winds[i][1], 10, 8, 9,
832 FALSE, TRUE, 100, 255,
833 (gpointer)&change_window1, NULL, NULL);
834 //change_window1(actor, desktop_plugin);
835 actor->time_start_animation = now + fast_rnd(30);
836 scene->actors = g_slist_append(scene->actors, actor);
840 run_long_timeout(desktop_plugin);
845 get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
847 gint y0 = 365;// - уровень горизонта
848 *x = (int)(azm * 800) - 64;
849 *y = (int)((1 - alt) * y0) - 64;
850 //fprintf(stderr, "sun pos alt=%f azm=%f x=%d y=%d\n", alt, azm, *x, *y);
854 change_actor(GtkWidget * actor)
857 gint x, y, daytime, scale;
864 void (*pfunc)(gpointer, gpointer);
866 name = g_object_get_data(G_OBJECT(actor), "name");
867 fprintf(stderr, "change actor %s\n", name);
869 pfunc = g_object_get_data(G_OBJECT(actor), "func");
871 (*pfunc)(actor, g_strdup(name));
872 daytime = get_daytime();
873 if (daytime != TIME_NIGHT){
874 hildon_animation_actor_set_show(actor, 1);
875 get_sun_pos(&alt, &azm);
876 get_sun_screen_pos(alt, azm, &x, &y);
877 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
881 if (name == "cloud1"){
882 x = g_object_get_data(G_OBJECT(actor), "x");
883 y = g_object_get_data(G_OBJECT(actor), "y");
884 scale = g_object_get_data(G_OBJECT(actor), "scale");
887 image = g_object_get_data(G_OBJECT(actor), "image");
889 gtk_container_remove(actor, image);
890 pixbuf = gdk_pixbuf_new_from_file_at_size ("/usr/share/livewp/theme/Modern/sun.png",
895 image = gtk_image_new_from_pixbuf (pixbuf);
896 g_object_unref(G_OBJECT(pixbuf));
898 g_signal_connect(G_OBJECT(image), "expose_event",
899 G_CALLBACK(expose_event), pixbuf);
900 gtk_container_add (GTK_CONTAINER (actor), image);
902 gtk_widget_show_all(actor);
914 sc = (double)scale / 100;
915 hildon_animation_actor_set_scale(actor, sc, sc);
916 fprintf(stderr, "cloud x=%d y=%d scale=%f", x, y, sc);
917 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
918 g_object_set_data(G_OBJECT(actor), "x", x);
919 g_object_set_data(G_OBJECT(actor), "y", y);
920 g_object_set_data(G_OBJECT(actor), "scale", scale);
926 short_timeout (AWallpaperPlugin *desktop_plugin)
928 //gint daytime = get_daytime();
930 void (*pfunc)(gpointer, gpointer);
933 gboolean stop_flag = TRUE;
935 if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
936 desktop_plugin->priv->short_timer = 0;
941 //scene.daytime = daytime;
942 /* fprintf(stderr, "Short timer %d\n", now); */
943 tmp = desktop_plugin->priv->scene->actors;
946 if (now >= actor->time_start_animation
947 && actor->time_start_animation > 0
948 /* && now - actor->time_start_animation <= actor->duration_animation*/){
949 pfunc = actor->func_change;
951 (*pfunc)(actor, desktop_plugin);
955 tmp = g_slist_next(tmp);
958 desktop_plugin->priv->short_timer = 0;
961 return TRUE; /* keep running this event */
965 run_long_timeout(AWallpaperPlugin *desktop_plugin)
968 gint daytime = get_daytime();
970 void (*pfunc)(gpointer, gpointer);
975 //fprintf(stderr, "!!!run long timeout short_timer=%d\n", desktop_plugin->priv->short_timer);
976 if (desktop_plugin->priv->scene->daytime != daytime){
977 desktop_plugin->priv->scene->daytime = daytime;
978 tmp = desktop_plugin->priv->scene->actors;
980 //change_actor(tmp->data);
981 pfunc =((Actor*)tmp->data)->func_change;
983 (*pfunc)(tmp->data, desktop_plugin);
985 tmp = g_slist_next(tmp);
990 //fprintf(stderr, "Now %d\n", now);
991 tmp = desktop_plugin->priv->scene->actors;
994 if (now >= actor->time_start_animation
995 && actor->time_start_animation > 0
996 && desktop_plugin->priv->short_timer == 0){
997 /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
998 if (desktop_plugin->priv->rich_animation){
999 actor->time_start_animation = now;
1000 desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
1003 (*actor->func_change)(actor, desktop_plugin);
1006 tmp = g_slist_next(tmp);
1012 long_timeout (AWallpaperPlugin *desktop_plugin)
1014 /* fprintf(stderr, "long_timeout %i\n", desktop_plugin->priv->long_timer); */
1015 if (desktop_plugin->priv->long_timer == 0 )
1017 if (!desktop_plugin->priv->visible){
1018 if(desktop_plugin->priv->short_timer != 0){
1019 g_source_remove(desktop_plugin->priv->short_timer);
1020 desktop_plugin->priv->short_timer = 0;
1022 desktop_plugin->priv->long_timer = 0;
1027 run_long_timeout(desktop_plugin);
1028 return TRUE; /* keep running this event */
1032 desktop_plugin_visible_notify (GObject *object,
1034 AWallpaperPlugin *desktop_plugin)
1037 g_object_get (object, "is-on-current-desktop", &visible, NULL);
1038 /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
1040 desktop_plugin->priv->visible = TRUE;
1041 if (desktop_plugin->priv->long_timer == 0 ){
1042 desktop_plugin->priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1043 run_long_timeout(desktop_plugin);
1046 desktop_plugin->priv->visible = FALSE;
1047 if (desktop_plugin->priv->long_timer != 0 ){
1048 g_source_remove(desktop_plugin->priv->long_timer);
1049 desktop_plugin->priv->long_timer = 0;
1055 rich_animation_press(GtkWidget *widget, GdkEvent *event,
1056 gpointer user_data){
1057 fprintf(stderr,"gggggggggggggggggggg2222\n");
1061 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
1063 GtkWidget *rich_animation;
1067 //fprintf(stderr, "!!!!!!!plugin init \n");
1068 Animation_WallpaperPrivate *priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1069 desktop_plugin->priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1070 priv->osso = osso_initialize(PACKAGE, VERSION, TRUE, NULL);
1074 /* Initialize DBUS */
1075 livewp_initialize_dbus(priv);
1077 priv->desktop_plugin = desktop_plugin;
1078 priv->visible = TRUE;
1079 priv->short_timer = 0;
1082 //priv->theme = g_strdup("Modern");
1083 desktop_plugin->priv->main_widget = gtk_fixed_new();
1085 gtk_widget_set_size_request(desktop_plugin->priv->main_widget, 100, 32);
1086 desktop_plugin->priv->right_corner = NULL;
1087 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/%s", THEME_PATH, desktop_plugin->priv->theme, "town0_right_corner.png");
1088 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
1089 if (desktop_plugin->priv->right_corner){
1090 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
1091 gtk_widget_show (desktop_plugin->priv->right_corner);
1093 /* Create rich animation event */
1094 rich_animation = gtk_event_box_new();
1096 gtk_widget_set_events(rich_animation, GDK_BUTTON_PRESS_MASK);
1097 gtk_event_box_set_visible_window(GTK_EVENT_BOX(rich_animation), FALSE);
1098 gtk_widget_set_size_request(rich_animation, 100, 32);
1099 gtk_widget_show (rich_animation);
1100 g_signal_connect(rich_animation, "button-press-event", G_CALLBACK(rich_animation_press), desktop_plugin);
1101 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), rich_animation, 0, 0);
1104 GtkWidget *label = gtk_label_new ("ddddddddddddd");
1105 gtk_widget_set_size_request(label, 95, 30);
1106 gtk_widget_show (label);
1107 gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
1108 gtk_fixed_put(GTK_FIXED(widget), label, 0, 0);
1110 hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
1111 g_signal_connect (desktop_plugin, "show-settings",
1112 G_CALLBACK (show_settings), priv);
1113 gtk_widget_show (desktop_plugin->priv->main_widget);
1114 gtk_container_add (GTK_CONTAINER (desktop_plugin), desktop_plugin->priv->main_widget);
1115 init_applet_position(&(priv->xapplet), &(priv->yapplet));
1118 fprintf(stderr, "!!!theme = %s\n", priv->theme);
1120 if (!strcmp(priv->theme,"Modern"))
1121 init_scene(desktop_plugin);
1122 else if (!strcmp(priv->theme,"Berlin"))
1123 init_scene1(desktop_plugin);
1124 else if (!strcmp(priv->theme, "Matrix"))
1125 init_scene2(desktop_plugin);
1126 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1127 /* TODO Move scene to priv */
1128 //scene.timer_type = LONG_TIMER_TYPE;
1129 g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
1130 G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
1137 lw_applet_finalize (GObject *object)
1139 AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
1140 Animation_WallpaperPrivate *priv = desktop_plugin->priv;
1142 fprintf(stderr,"finalaze %i\n", priv->long_timer);
1143 if (priv->long_timer){
1144 g_source_remove(priv->long_timer);
1145 priv->long_timer = 0;
1147 if (priv->short_timer){
1148 g_source_remove(priv->short_timer);
1149 priv->short_timer = 0;
1152 destroy_scene(desktop_plugin);
1156 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
1158 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1159 GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
1162 gobject_class->destroy = (gpointer)lw_applet_finalize;
1163 widget_class->realize = lw_applet_realize;
1164 widget_class->expose_event = lw_applet_expose_event;
1166 g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));
1171 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {