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 "livewp-actor.h"
28 #include <gconf/gconf-client.h>
29 #include "livewp-rules.h"
33 #define PLUGIN_NAME "livewp-home-widget.desktop-0"
34 #define GCONF_KEY_POSITION "/apps/osso/hildon-desktop/applets/%s/position"
35 #define GCONF_KEY_MODIFIED "/apps/osso/hildon-desktop/applets/%s/modified"
36 #define GCONF_KEY_VIEW "/apps/osso/hildon-desktop/applets/%s/view"
38 HD_DEFINE_PLUGIN_MODULE (AWallpaperPlugin, animation_wallpaper_plugin, HD_TYPE_HOME_PLUGIN_ITEM)
39 #define Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE (obj,\
40 Animation_Wallpaper_TYPE_HOME_PLUGIN,\
41 Animation_WallpaperPrivate))
43 /* Position of plugin on desktop */
44 #define Xstartposition 700
45 #define Ystartposition 448
47 //gint xapplet = 0, yapplet = 0;
50 lw_applet_realize (GtkWidget *widget)
54 screen = gtk_widget_get_screen (widget);
55 gtk_widget_set_colormap (widget,
56 gdk_screen_get_rgba_colormap (screen));
57 gtk_widget_set_app_paintable (widget,
59 GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->realize (widget);
64 lw_applet_expose_event(GtkWidget *widget,
65 GdkEventExpose *event)
69 /* Create cairo context */
70 cr = gdk_cairo_create (GDK_DRAWABLE (widget->window));
71 gdk_cairo_region (cr, event->region);
74 /* Draw alpha background */
75 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
76 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0);
82 return GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->expose_event (widget,
87 expose_event (GtkWidget *widget,GdkEventExpose *event,
91 GdkPixbuf *pixbuf = (GdkPixbuf *) data;
93 cr = gdk_cairo_create(widget->window);
95 gdk_cairo_region(cr, event->region);
96 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
97 gdk_cairo_set_source_pixbuf(cr, pixbuf, 0.0, 0.0);
105 realize (GtkWidget *widget)
108 screen = gtk_widget_get_screen (widget);
109 gtk_widget_set_colormap (widget, gdk_screen_get_rgba_colormap (screen));
112 /* Set position of widget on desktop */
114 init_applet_position(gint *xapplet, gint *yapplet)
116 GSList *position = NULL;
120 GError *error = NULL;
121 GConfClient *gconf_client = gconf_client_get_default ();
122 position_key = g_strdup_printf (GCONF_KEY_POSITION, PLUGIN_NAME);
123 position = gconf_client_get_list (gconf_client,
127 if (position && position->data && position->next->data){
128 *xapplet = GPOINTER_TO_INT (position->data);
129 *yapplet = GPOINTER_TO_INT (position->next->data);
131 position = g_slist_prepend (g_slist_prepend (NULL,
132 GINT_TO_POINTER (Ystartposition)),
133 GINT_TO_POINTER (Xstartposition));
134 gconf_client_set_list (gconf_client,
139 *xapplet = Xstartposition;
140 *yapplet = Ystartposition;
142 g_free (position_key);
143 modified = g_strdup_printf ("%i", 0);
144 modified_key = g_strdup_printf (GCONF_KEY_MODIFIED, PLUGIN_NAME);
145 gconf_client_set_string (gconf_client,
150 g_free(modified_key);
151 gconf_client_clear_cache(gconf_client);
152 g_object_unref(gconf_client);
156 actor_set_position_full(GtkWidget *actor, gint x, gint y, gint z)
158 /* fprintf(stderr, "actor_set_position_full z=%d\n", z); */
159 hildon_animation_actor_set_position_full (HILDON_ANIMATION_ACTOR (actor),x-0, y-0, z);
164 destroy_hildon_actor(Actor *actor)
166 //fprintf(stderr, "destroy_hildon_actor %s\n",actor->name);
167 gtk_widget_destroy(actor->widget);
168 actor->widget = NULL;
178 gint fast_rnd(gint max)
180 guint offset = 12923;
181 guint multiplier = 4079;
183 //*seed = *seed * multiplier + offset;
184 //return (gint)(*seed % max);
185 guint seed = time(NULL);
186 return (gint)(seed % max);
190 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
192 GtkWidget *ha = NULL;
193 GdkPixbuf *pixbuf = NULL;
194 GtkWidget *image = NULL;
197 ha = hildon_animation_actor_new();
198 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
199 desktop_plugin->priv->theme, actor->filename);
200 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
204 /*fprintf(stderr, "create_hildon_actor %s %s\n", actor->name, str);*/
208 image = gtk_image_new_from_pixbuf (pixbuf);
209 g_object_unref(G_OBJECT(pixbuf));
212 g_signal_connect(G_OBJECT(image), "expose_event",
213 G_CALLBACK(expose_event), pixbuf);
214 gtk_container_add (GTK_CONTAINER (ha), image);
216 //actor_set_position_full(ha, actor->x, actor->y, actor->z);
217 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(ha), (double)actor->scale/100, (double)actor->scale/100);
219 gtk_widget_show_all(ha);
220 //hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(ha), actor->visible);
225 g_object_set_data(G_OBJECT(ha), "image", image);
226 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
228 set_actor_position(actor, actor->x, actor->y, actor->z, desktop_plugin);
229 set_actor_scale(actor, (double)actor->scale/100, (double)actor->scale/100);
230 set_actor_visible(actor, actor->visible);
235 change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
237 GtkWidget *image = NULL;
238 GdkPixbuf *pixbuf = NULL;
241 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
242 desktop_plugin->priv->theme, actor->filename);
244 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
251 image = gtk_image_new_from_pixbuf (pixbuf);
252 g_object_unref(G_OBJECT(pixbuf));
255 g_signal_connect(G_OBJECT(image), "expose_event",
256 G_CALLBACK(expose_event), pixbuf);
257 if (g_object_get_data(G_OBJECT(actor->widget), "image")){
258 gtk_container_remove(GTK_CONTAINER(actor->widget), g_object_get_data(G_OBJECT(actor->widget), "image"));
260 g_object_set_data(G_OBJECT(actor->widget), "image", image);
261 gtk_container_add (GTK_CONTAINER (actor->widget), image);
262 realize(actor->widget);
263 gtk_widget_show_all(actor->widget);
277 // уравнение изменения времени
282 destroy_scene(AWallpaperPlugin *desktop_plugin)
284 GSList * tmp = desktop_plugin->priv->scene->actors;
286 destroy_actor(tmp->data);
287 tmp = g_slist_next(tmp);
294 reload_scene(AWallpaperPlugin *desktop_plugin)
296 fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);
297 destroy_scene(desktop_plugin);
298 if (!strcmp(desktop_plugin->priv->theme,"Modern"))
299 init_scene(desktop_plugin);
300 else if (!strcmp(desktop_plugin->priv->theme,"Berlin"))
301 init_scene1(desktop_plugin);
302 else if (!strcmp(desktop_plugin->priv->theme,"Matrix"))
303 init_scene2(desktop_plugin);
307 init_scene2(AWallpaperPlugin *desktop_plugin)
312 gint now = time(NULL);
315 if (desktop_plugin->priv->rich_animation){
323 fprintf(stderr, "init scene2 \n");
324 scene = g_new0(Scene, 1);
325 //scene.daytime = get_daytime();
326 scene->actors = NULL;
327 desktop_plugin->priv->scene = scene;
329 actor = init_object(desktop_plugin, "background", "bg.png",
331 TRUE, TRUE, 100, 255,
333 scene->actors = g_slist_append(scene->actors, actor);
335 actor = init_object(desktop_plugin, "symbols", "symbols.png",
337 TRUE, TRUE, 100, 255,
339 scene->actors = g_slist_append(scene->actors, actor);
341 child = g_ptr_array_sized_new(4);
342 actor = init_object(desktop_plugin, "layer1", "layer1_2.png",
344 TRUE, TRUE, 100, 255,
346 //actor->time_start_animation = now;
347 //actor->duration_animation = G_MAXINT;
348 scene->actors = g_slist_append(scene->actors, actor);
349 g_ptr_array_add(child, actor);
351 actor = init_object(desktop_plugin, "layer1", "layer1_1.png",
353 TRUE, TRUE, 100, 255,
355 //actor->time_start_animation = now;
356 //actor->duration_animation = G_MAXINT;
357 scene->actors = g_slist_append(scene->actors, actor);
358 g_ptr_array_add(child, actor);
360 actor = init_object(desktop_plugin, "layer2", "layer2_2.png",
362 TRUE, TRUE, 100, 255,
364 //actor->time_start_animation = now;
365 //actor->duration_animation = G_MAXINT;
366 scene->actors = g_slist_append(scene->actors, actor);
367 g_ptr_array_add(child, actor);
369 actor = init_object(desktop_plugin, "layer2", "layer2_1.png",
371 TRUE, TRUE, 100, 255,
373 //actor->time_start_animation = now;
374 //actor->duration_animation = G_MAXINT;
375 scene->actors = g_slist_append(scene->actors, actor);
376 g_ptr_array_add(child, actor);
378 actor = init_object(desktop_plugin, "layers", "",
380 FALSE, FALSE, 100, 255,
381 (gpointer)&change_layer, NULL, child);
382 actor->time_start_animation = now;
383 actor->duration_animation = G_MAXINT;
384 scene->actors = g_slist_append(scene->actors, actor);
386 run_long_timeout(desktop_plugin);
390 /* Init Modern Scene */
392 init_scene(AWallpaperPlugin *desktop_plugin)
396 gint now = time(NULL);
400 //fprintf(stderr, "init scene \n");
401 scene = g_new0(Scene, 1);
402 scene->daytime = get_daytime();
403 scene->actors = NULL;
404 scene->wind_orientation = -1;
405 scene->wind_angle = 0.3;
406 /* init value for random */
407 scene->seed = time(NULL);
408 desktop_plugin->priv->scene = scene;
410 actor = init_object(desktop_plugin, "sky", "sky0.png",
412 TRUE , TRUE, 100, 255,
413 (gpointer)&change_static_actor, NULL, NULL);
414 change_static_actor(actor, desktop_plugin);
415 scene->actors = g_slist_append(scene->actors, actor);
417 actor = init_object(desktop_plugin, "sun", "sun.png",
419 FALSE, FALSE, 100, 255,
420 (gpointer)&change_sun, NULL, NULL);
421 actor->time_start_animation = now;
422 actor->duration_animation = G_MAXINT;
423 change_sun(actor, desktop_plugin);
424 scene->actors = g_slist_append(scene->actors, actor);
426 //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
427 // TRUE, 100, 255, NULL, NULL);
428 //scene.actors = g_slist_append(scene.actors, actor);
430 actor = init_object(desktop_plugin, "cloud1", "cloud1.png",
431 0, fast_rnd(300)-97, 7, 150, 97,
432 FALSE, FALSE, 100, 255,
433 (gpointer)&change_cloud, NULL, NULL);
434 actor->time_start_animation = now + fast_rnd(20);
435 actor->duration_animation = 3*60;
436 scene->actors = g_slist_append(scene->actors, actor);
438 actor = init_object(desktop_plugin, "cloud2", "cloud2.png",
439 0, fast_rnd(300)-75, 7, 188, 75,
440 FALSE, FALSE, 100, 255,
441 (gpointer)&change_cloud, NULL, NULL);
442 actor->time_start_animation = now + fast_rnd(40)+10;
443 actor->duration_animation = 3*60;
444 scene->actors = g_slist_append(scene->actors, actor);
446 actor = init_object(desktop_plugin, "cloud4", "cloud4.png",
447 0, fast_rnd(300)-75, 7, 150, 75,
448 FALSE, FALSE, 100, 255,
449 (gpointer)&change_cloud, NULL, NULL);
450 actor->time_start_animation = now + fast_rnd(60) + 20;
451 actor->duration_animation = 5*60;
452 scene->actors = g_slist_append(scene->actors, actor);
455 actor = init_object(desktop_plugin, "town", "town0.png",
457 TRUE, TRUE, 100, 255,
458 (gpointer)&change_static_actor, NULL, NULL);
459 change_static_actor(actor, desktop_plugin);
460 scene->actors = g_slist_append(scene->actors, actor);
462 actor = init_object(desktop_plugin, "stend", "stend0.png",
463 482, 146, 9, 300, 305,
464 TRUE, TRUE, 100, 255,
465 (gpointer)&change_static_actor, NULL, NULL);
466 change_static_actor(actor, desktop_plugin);
467 scene->actors = g_slist_append(scene->actors, actor);
469 actor = init_object(desktop_plugin, "tram", "tram.png",
470 -300, 225, 10, 350, 210,
471 FALSE, FALSE, 100, 255,
472 (gpointer)&change_tram, NULL, NULL);
473 actor->time_start_animation = time(NULL) + fast_rnd(10);
474 actor->duration_animation = 60;
475 scene->actors = g_slist_append(scene->actors, actor);
477 actor = init_object(desktop_plugin, "border", "border0.png",
478 0, 480-79, 11, 800, 79,
479 TRUE, TRUE, 100, 255,
480 (gpointer)&change_static_actor_with_corner, NULL, NULL);
481 change_static_actor_with_corner(actor, desktop_plugin);
482 scene->actors = g_slist_append(scene->actors, actor);
484 actor = init_object(desktop_plugin, "moon", "moon1.png",
486 FALSE, FALSE, 100, 255,
487 (gpointer)&change_moon, NULL, NULL);
488 change_moon(actor, desktop_plugin);
489 scene->actors = g_slist_append(scene->actors, actor);
491 actor = init_object(desktop_plugin, "wind", "",
493 FALSE, FALSE, 100, 255,
494 (gpointer)&change_wind, NULL, NULL);
495 change_wind(actor, desktop_plugin);
496 scene->actors = g_slist_append(scene->actors, actor);
498 /* windows in 4-th house */
538 for (i=0; i<13; i++){
539 actor = init_object(desktop_plugin, "window1", "window1.png",
540 winds[i][0], winds[i][1], 8, 8, 10,
541 FALSE, FALSE, 100, 255,
542 (gpointer)&change_window1, NULL, NULL);
543 //change_window1(actor, desktop_plugin);
544 actor->time_start_animation = now + fast_rnd(30);
545 scene->actors = g_slist_append(scene->actors, actor);
549 /* windows in 1-th house */
575 actor = init_object(desktop_plugin, "window2", "window2.png",
576 winds[i][0], winds[i][1], 8, 8, 10,
577 FALSE, FALSE, 100, 255,
578 (gpointer)&change_window1, NULL, NULL);
579 //change_window1(actor, desktop_plugin);
580 actor->time_start_animation = now + fast_rnd(30);
581 scene->actors = g_slist_append(scene->actors, actor);
585 /* windows in 3-th house */
617 for (i=0; i<10; i++){
618 actor = init_object(desktop_plugin, "window3", "window3.png",
619 winds[i][0], winds[i][1], 8, 8, 10,
620 FALSE, FALSE, 100, 255,
621 (gpointer)&change_window1, NULL, NULL);
622 //change_window1(actor, desktop_plugin);
623 actor->time_start_animation = now + fast_rnd(30);
624 scene->actors = g_slist_append(scene->actors, actor);
628 /* windows in 5-th house */
652 actor = init_object(desktop_plugin, "window4", "window4.png",
653 winds[i][0], winds[i][1], 8, 8, 10,
654 FALSE, FALSE, 100, 255,
655 (gpointer)&change_window1, NULL, NULL);
656 //change_window1(actor, desktop_plugin);
657 actor->time_start_animation = now + fast_rnd(30);
658 scene->actors = g_slist_append(scene->actors, actor);
662 /* windows in 6-th house */
683 actor = init_object(desktop_plugin, "window5", "window5.png",
684 winds[i][0], winds[i][1], 8, 8, 10,
685 FALSE, FALSE, 100, 255,
686 (gpointer)&change_window1, NULL, NULL);
687 //change_window1(actor, desktop_plugin);
688 actor->time_start_animation = now + fast_rnd(30);
689 scene->actors = g_slist_append(scene->actors, actor);
692 run_long_timeout(desktop_plugin);
695 anim = g_new0(Animation, 1);
698 anim->func_change = &change_tram;
699 anim->func_time = NULL;
700 anim->timestart = time(NULL);
703 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
707 /* Init Berlin Scene */
709 init_scene1(AWallpaperPlugin *desktop_plugin)
711 Actor *actor, *actor1, *actor2;
713 gint now = time(NULL);
716 GPtrArray *child = NULL;
718 scene = g_new0(Scene, 1);
719 scene->daytime = get_daytime();
720 scene->actors = NULL;
721 scene->wind_orientation = -1;
722 scene->wind_angle = 0.3;
723 /* init value for random */
724 scene->seed = time(NULL);
725 desktop_plugin->priv->scene = scene;
727 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
728 TRUE, TRUE, 100, 255,
729 (gpointer)&change_static_actor, NULL, NULL);
730 change_static_actor(actor, desktop_plugin);
731 scene->actors = g_slist_append(scene->actors, actor);
734 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
735 FALSE, FALSE, 100, 255,
736 (gpointer)&change_sun, NULL, NULL);
737 actor->time_start_animation = time(NULL);
738 actor->duration_animation = G_MAXINT;
739 change_sun(actor, desktop_plugin);
740 scene->actors = g_slist_append(scene->actors, actor);
743 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
744 TRUE, 100, 255, NULL, NULL);
745 scene.actors = g_slist_append(scene.actors, actor);
748 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
749 FALSE, FALSE, 100, 255,
750 (gpointer)&change_moon, NULL, NULL);
751 change_moon(actor, desktop_plugin);
752 scene->actors = g_slist_append(scene->actors, actor);
754 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
755 FALSE, FALSE, 100, 255,
756 (gpointer)&change_cloud, NULL, NULL);
757 actor->time_start_animation = now + fast_rnd(30) + 10;
758 actor->duration_animation = 3*60;
759 scene->actors = g_slist_append(scene->actors, actor);
761 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
762 FALSE, FALSE, 100, 255,
763 (gpointer)&change_cloud, NULL, NULL);
764 actor->time_start_animation = now + fast_rnd(10);
765 actor->duration_animation = 3*60;
766 scene->actors = g_slist_append(scene->actors, actor);
768 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
769 FALSE, FALSE, 100, 255,
770 (gpointer)&change_cloud, NULL, NULL);
771 actor->time_start_animation = now + fast_rnd(60) + 20;
772 actor->duration_animation = 5*60;
773 scene->actors = g_slist_append(scene->actors, actor);
776 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
777 FALSE, FALSE, 100, 255,
778 (gpointer)&change_plane2, NULL, NULL);
779 actor->time_start_animation = now + fast_rnd(40) + 20;
780 actor->duration_animation = 60;
781 scene->actors = g_slist_append(scene->actors, actor);
783 actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116,
784 FALSE, FALSE, 100, 255,
785 (gpointer)&change_plane1, NULL, NULL);
786 actor->time_start_animation = now + fast_rnd(20);
787 actor->duration_animation = 30;
788 scene->actors = g_slist_append(scene->actors, actor);
790 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
791 TRUE, TRUE, 100, 255,
792 (gpointer)&change_static_actor_with_corner, NULL, NULL);
793 change_static_actor_with_corner(actor, desktop_plugin);
794 scene->actors = g_slist_append(scene->actors, actor);
796 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
797 FALSE, FALSE, 100, 255,
798 (gpointer)&change_wind, NULL, NULL);
799 change_wind(actor, desktop_plugin);
800 scene->actors = g_slist_append(scene->actors, actor);
802 actor1 = init_object(desktop_plugin, "signal_red", "red.png",
803 486, 425, 10, 18, 38,
804 FALSE, TRUE, 100, 255, NULL, NULL, NULL);
805 //actor->time_start_animation = now + fast_rnd(30) + 10;
806 scene->actors = g_slist_append(scene->actors, actor1);
808 actor2 = init_object(desktop_plugin, "signal_green", "green.png",
809 486, 425, 10, 18, 38,
810 TRUE, TRUE, 100, 255, NULL, NULL, NULL);
811 //actor->time_start_animation = now + fast_rnd(30) + 10;
812 scene->actors = g_slist_append(scene->actors, actor2);
813 child = g_ptr_array_sized_new(2);
814 g_ptr_array_add(child, actor1);
815 g_ptr_array_add(child, actor2);
816 actor = init_object(desktop_plugin, "signal", "",
817 486, 425, 10, 18, 38,
818 FALSE, FALSE, 100, 255,
819 (gpointer)&change_signal, NULL, child);
820 actor->time_start_animation = now + fast_rnd(30) + 10;
821 scene->actors = g_slist_append(scene->actors, actor);
862 for (i=0; i<13; i++){
863 actor = init_object(desktop_plugin, "window", "window.png",
864 winds[i][0], winds[i][1], 10, 8, 9,
865 FALSE, TRUE, 100, 255,
866 (gpointer)&change_window1, NULL, NULL);
867 //change_window1(actor, desktop_plugin);
868 actor->time_start_animation = now + fast_rnd(30);
869 scene->actors = g_slist_append(scene->actors, actor);
873 run_long_timeout(desktop_plugin);
878 get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
880 gint y0 = 365;// - уровень горизонта
881 *x = (int)(azm * 800) - 64;
882 *y = (int)((1 - alt) * y0) - 64;
883 //fprintf(stderr, "sun pos alt=%f azm=%f x=%d y=%d\n", alt, azm, *x, *y);
887 change_actor(GtkWidget * actor)
890 gint x, y, daytime, scale;
897 void (*pfunc)(gpointer, gpointer);
899 name = g_object_get_data(G_OBJECT(actor), "name");
900 fprintf(stderr, "change actor %s\n", name);
902 pfunc = g_object_get_data(G_OBJECT(actor), "func");
904 (*pfunc)(actor, g_strdup(name));
905 daytime = get_daytime();
906 if (daytime != TIME_NIGHT){
907 hildon_animation_actor_set_show(actor, 1);
908 get_sun_pos(&alt, &azm);
909 get_sun_screen_pos(alt, azm, &x, &y);
910 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
914 if (name == "cloud1"){
915 x = g_object_get_data(G_OBJECT(actor), "x");
916 y = g_object_get_data(G_OBJECT(actor), "y");
917 scale = g_object_get_data(G_OBJECT(actor), "scale");
920 image = g_object_get_data(G_OBJECT(actor), "image");
922 gtk_container_remove(actor, image);
923 pixbuf = gdk_pixbuf_new_from_file_at_size ("/usr/share/livewp/theme/Modern/sun.png",
928 image = gtk_image_new_from_pixbuf (pixbuf);
929 g_object_unref(G_OBJECT(pixbuf));
931 g_signal_connect(G_OBJECT(image), "expose_event",
932 G_CALLBACK(expose_event), pixbuf);
933 gtk_container_add (GTK_CONTAINER (actor), image);
935 gtk_widget_show_all(actor);
947 sc = (double)scale / 100;
948 hildon_animation_actor_set_scale(actor, sc, sc);
949 fprintf(stderr, "cloud x=%d y=%d scale=%f", x, y, sc);
950 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
951 g_object_set_data(G_OBJECT(actor), "x", x);
952 g_object_set_data(G_OBJECT(actor), "y", y);
953 g_object_set_data(G_OBJECT(actor), "scale", scale);
959 short_timeout (AWallpaperPlugin *desktop_plugin)
961 //gint daytime = get_daytime();
963 void (*pfunc)(gpointer, gpointer);
966 gboolean stop_flag = TRUE;
968 if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
969 desktop_plugin->priv->short_timer = 0;
974 //scene.daytime = daytime;
975 /* fprintf(stderr, "Short timer %d\n", now); */
976 tmp = desktop_plugin->priv->scene->actors;
979 if (now >= actor->time_start_animation
980 && actor->time_start_animation > 0
981 /* && now - actor->time_start_animation <= actor->duration_animation*/){
982 pfunc = actor->func_change;
984 (*pfunc)(actor, desktop_plugin);
988 tmp = g_slist_next(tmp);
991 desktop_plugin->priv->short_timer = 0;
994 return TRUE; /* keep running this event */
998 run_long_timeout(AWallpaperPlugin *desktop_plugin)
1001 gint daytime = get_daytime();
1003 void (*pfunc)(gpointer, gpointer);
1008 //fprintf(stderr, "!!!run long timeout short_timer=%d\n", desktop_plugin->priv->short_timer);
1009 if (desktop_plugin->priv->scene->daytime != daytime){
1010 desktop_plugin->priv->scene->daytime = daytime;
1011 tmp = desktop_plugin->priv->scene->actors;
1012 while (tmp != NULL){
1013 //change_actor(tmp->data);
1014 pfunc =((Actor*)tmp->data)->func_change;
1016 (*pfunc)(tmp->data, desktop_plugin);
1018 tmp = g_slist_next(tmp);
1023 //fprintf(stderr, "Now %d\n", now);
1024 tmp = desktop_plugin->priv->scene->actors;
1025 while (tmp != NULL){
1027 if (now >= actor->time_start_animation
1028 && actor->time_start_animation > 0
1029 && desktop_plugin->priv->short_timer == 0){
1030 /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
1031 if (desktop_plugin->priv->rich_animation){
1032 actor->time_start_animation = now;
1033 desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
1036 (*actor->func_change)(actor, desktop_plugin);
1039 tmp = g_slist_next(tmp);
1045 long_timeout (AWallpaperPlugin *desktop_plugin)
1047 /* fprintf(stderr, "long_timeout %i\n", desktop_plugin->priv->long_timer); */
1048 if (desktop_plugin->priv->long_timer == 0 )
1050 if (!desktop_plugin->priv->visible){
1051 if(desktop_plugin->priv->short_timer != 0){
1052 g_source_remove(desktop_plugin->priv->short_timer);
1053 desktop_plugin->priv->short_timer = 0;
1055 desktop_plugin->priv->long_timer = 0;
1060 run_long_timeout(desktop_plugin);
1061 return TRUE; /* keep running this event */
1065 desktop_plugin_visible_notify (GObject *object,
1067 AWallpaperPlugin *desktop_plugin)
1070 g_object_get (object, "is-on-current-desktop", &visible, NULL);
1071 /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
1073 desktop_plugin->priv->visible = TRUE;
1074 if (desktop_plugin->priv->long_timer == 0 ){
1075 desktop_plugin->priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1076 run_long_timeout(desktop_plugin);
1079 desktop_plugin->priv->visible = FALSE;
1080 if (desktop_plugin->priv->long_timer != 0 ){
1081 g_source_remove(desktop_plugin->priv->long_timer);
1082 desktop_plugin->priv->long_timer = 0;
1088 rich_animation_press(GtkWidget *widget, GdkEvent *event,
1089 gpointer user_data){
1090 fprintf(stderr,"gggggggggggggggggggg2222\n");
1094 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
1096 GtkWidget *rich_animation;
1100 //fprintf(stderr, "!!!!!!!plugin init \n");
1101 Animation_WallpaperPrivate *priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1102 desktop_plugin->priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1103 priv->osso = osso_initialize(PACKAGE, VERSION, TRUE, NULL);
1107 /* Initialize DBUS */
1108 livewp_initialize_dbus(priv);
1110 priv->desktop_plugin = desktop_plugin;
1111 priv->visible = TRUE;
1112 priv->short_timer = 0;
1115 //priv->theme = g_strdup("Modern");
1116 desktop_plugin->priv->main_widget = gtk_fixed_new();
1118 gtk_widget_set_size_request(desktop_plugin->priv->main_widget, 100, 32);
1119 desktop_plugin->priv->right_corner = NULL;
1120 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/%s", THEME_PATH, desktop_plugin->priv->theme, "town0_right_corner.png");
1121 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
1122 if (desktop_plugin->priv->right_corner){
1123 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
1124 gtk_widget_show (desktop_plugin->priv->right_corner);
1126 /* Create rich animation event */
1127 rich_animation = gtk_event_box_new();
1129 gtk_widget_set_events(rich_animation, GDK_BUTTON_PRESS_MASK);
1130 gtk_event_box_set_visible_window(GTK_EVENT_BOX(rich_animation), FALSE);
1131 gtk_widget_set_size_request(rich_animation, 100, 32);
1132 gtk_widget_show (rich_animation);
1133 g_signal_connect(rich_animation, "button-press-event", G_CALLBACK(rich_animation_press), desktop_plugin);
1134 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), rich_animation, 0, 0);
1137 GtkWidget *label = gtk_label_new ("ddddddddddddd");
1138 gtk_widget_set_size_request(label, 95, 30);
1139 gtk_widget_show (label);
1140 gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
1141 gtk_fixed_put(GTK_FIXED(widget), label, 0, 0);
1143 hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
1144 g_signal_connect (desktop_plugin, "show-settings",
1145 G_CALLBACK (show_settings), priv);
1146 gtk_widget_show (desktop_plugin->priv->main_widget);
1147 gtk_container_add (GTK_CONTAINER (desktop_plugin), desktop_plugin->priv->main_widget);
1148 init_applet_position(&(priv->xapplet), &(priv->yapplet));
1151 fprintf(stderr, "!!!theme = %s\n", priv->theme);
1153 if (!strcmp(priv->theme,"Modern"))
1154 init_scene(desktop_plugin);
1155 else if (!strcmp(priv->theme,"Berlin"))
1156 init_scene1(desktop_plugin);
1157 else if (!strcmp(priv->theme, "Matrix"))
1158 init_scene2(desktop_plugin);
1159 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1160 /* TODO Move scene to priv */
1161 //scene.timer_type = LONG_TIMER_TYPE;
1162 g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
1163 G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
1170 lw_applet_finalize (GObject *object)
1172 AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
1173 Animation_WallpaperPrivate *priv = desktop_plugin->priv;
1175 fprintf(stderr,"finalaze %i\n", priv->long_timer);
1176 if (priv->long_timer){
1177 g_source_remove(priv->long_timer);
1178 priv->long_timer = 0;
1180 if (priv->short_timer){
1181 g_source_remove(priv->short_timer);
1182 priv->short_timer = 0;
1185 destroy_scene(desktop_plugin);
1189 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
1191 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1192 GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
1195 gobject_class->destroy = (gpointer)lw_applet_finalize;
1196 widget_class->realize = lw_applet_realize;
1197 widget_class->expose_event = lw_applet_expose_event;
1199 g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));
1204 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {