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))
42 /* Position of plugin on desktop */
43 #define Xstartposition 700
44 #define Ystartposition 425
46 gint xapplet = 0, yapplet = 0;
47 GSList * objects_list = NULL;
51 lw_applet_realize (GtkWidget *widget)
55 screen = gtk_widget_get_screen (widget);
56 gtk_widget_set_colormap (widget,
57 gdk_screen_get_rgba_colormap (screen));
58 gtk_widget_set_app_paintable (widget,
60 GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->realize (widget);
65 lw_applet_expose_event(GtkWidget *widget,
66 GdkEventExpose *event)
70 /* Create cairo context */
71 cr = gdk_cairo_create (GDK_DRAWABLE (widget->window));
72 gdk_cairo_region (cr, event->region);
75 /* Draw alpha background */
76 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
77 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0);
83 return GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->expose_event (widget,
88 expose_event (GtkWidget *widget,GdkEventExpose *event,
92 GdkPixbuf *pixbuf = (GdkPixbuf *) data;
94 cr = gdk_cairo_create(widget->window);
96 gdk_cairo_region(cr, event->region);
97 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
98 gdk_cairo_set_source_pixbuf(cr, pixbuf, 0.0, 0.0);
106 realize (GtkWidget *widget)
109 screen = gtk_widget_get_screen (widget);
110 gtk_widget_set_colormap (widget, gdk_screen_get_rgba_colormap (screen));
113 /* Set position of widget on desktop */
115 init_applet_position(void)
117 GSList *position = NULL;
121 GError *error = NULL;
122 GConfClient *gconf_client = gconf_client_get_default ();
123 position_key = g_strdup_printf (GCONF_KEY_POSITION, PLUGIN_NAME);
124 position = gconf_client_get_list (gconf_client,
128 if (position && position->data && position->next->data){
129 xapplet = GPOINTER_TO_INT (position->data);
130 yapplet = GPOINTER_TO_INT (position->next->data);
132 position = g_slist_prepend (g_slist_prepend (NULL,
133 GINT_TO_POINTER (Ystartposition)),
134 GINT_TO_POINTER (Xstartposition));
135 gconf_client_set_list (gconf_client,
140 xapplet = Xstartposition;
141 yapplet = Ystartposition;
143 g_free (position_key);
144 modified = g_strdup_printf ("%i", 0);
145 modified_key = g_strdup_printf (GCONF_KEY_MODIFIED, PLUGIN_NAME);
146 gconf_client_set_string (gconf_client,
151 g_free(modified_key);
152 gconf_client_clear_cache(gconf_client);
153 g_object_unref(gconf_client);
157 actor_set_position_full(GtkWidget *actor, gint x, gint y, gint z)
159 /* fprintf(stderr, "actor_set_position_full z=%d\n", z); */
160 hildon_animation_actor_set_position_full (HILDON_ANIMATION_ACTOR (actor),x-xapplet, y-yapplet, z);
164 path_line(gint x0, gint x1, double t)
167 return ((x1 - x0) * t + x0);
172 destroy_hildon_actor(Actor *actor)
174 fprintf(stderr, "estroy_hildon_actor %p\n",actor->widget);
175 gtk_widget_destroy(actor->widget);
176 actor->widget = NULL;
180 init_object(AWallpaperPlugin *desktop_plugin,
191 void (*pfunc_change)(Actor*),
192 void (*pfunc_probability)(Actor*)
196 actor = g_new0(Actor, 1);
200 actor->width = width;
201 actor->height = height;
202 actor->visible = visible;
203 actor->scale = scale;
204 actor->opacity = opacity;
205 actor->filename = g_strdup(filename);
206 actor->name = g_strdup(name);
207 actor->func_change = (gpointer)pfunc_change;
208 actor->func_probability = (gpointer)pfunc_probability;
210 create_hildon_actor(actor, desktop_plugin);
212 actor->widget = NULL;
213 actor->time_start_animation = 0;
214 actor->duration_animation = 0;
222 //objects_list = g_slist_append(objects_list, G_OBJECT(actor));
223 //objects_list = g_slist_append(objects_list, G_OBJECT(a));
234 gint fast_rnd(gint max)
236 guint offset = 12923;
237 guint multiplier = 4079;
239 seed = seed * multiplier + offset;
240 return (gint)(seed % max);
246 /* update sun position after ... second */
254 return (fast_rnd(10) + 1) * 60;
258 change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
264 if (get_daytime() == TIME_NIGHT){
265 if (!actor->visible){
266 actor->visible = TRUE;
267 phase = get_moon_phase();
268 newfile = g_strdup_printf( "%s%d.png", actor->name, phase);
270 g_free(actor->filename);
271 actor->filename = newfile;
272 create_hildon_actor(actor, desktop_plugin);
277 // actor_set_position_full(actor->widget, x, y, actor->z);
278 //probability_sun(actor);
279 //fprintf(stderr, "after change sun %d\n", actor->time_start_animation);
280 }else if (actor->visible){
281 actor->visible = FALSE;
282 fprintf(stderr, "destroy moon \n");
283 destroy_hildon_actor(actor);
284 /* TO DO make moonrise*/
285 actor->time_start_animation = 0;
292 change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
297 //fprintf(stderr, "change sun\n");
299 if (scene.daytime != TIME_NIGHT){
300 if (!actor->visible){
301 actor->visible = TRUE;
302 create_hildon_actor(actor, desktop_plugin);
304 get_sun_pos(&alt, &azm);
305 get_sun_screen_pos(alt, azm, &x, &y);
308 actor_set_position_full(actor->widget, x, y, actor->z);
309 //probability_sun(actor);
310 actor->time_start_animation = time(NULL) + probability_sun();
311 }else if (actor->visible){
312 actor->visible = FALSE;
313 destroy_hildon_actor(actor);
314 actor->time_start_animation = 0;
321 change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
323 gint x0 = -300, y0 = 225, scale0 = 100,
324 x1 = 800, y1 = 162, scale1 = 130,
331 gettimeofday(&tvb, NULL);
336 if (!actor->visible){
337 actor->visible = TRUE;
338 if (scene.daytime == TIME_NIGHT){
340 g_free(actor->filename);
341 actor->filename = g_strdup("tram_dark.png");
344 g_free(actor->filename);
345 actor->filename = g_strdup("tram.png");
347 create_hildon_actor(actor, desktop_plugin);
349 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
350 x = path_line(x0, x1, t);
351 y = path_line(y0, y1, t);
352 scale = path_line(scale0, scale1, t);
353 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
354 actor_set_position_full(actor->widget, x, y, actor->z);
355 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
358 actor->visible = FALSE;
359 destroy_hildon_actor(actor);
360 actor->time_start_animation = sec + 5*60;
365 change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
367 gint x0 = 620, y0 = 233, scale0 = 100,
368 x1 = 79, y1 = -146, scale1 = 100,
375 gettimeofday(&tvb, NULL);
379 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
381 if (!actor->visible){
382 actor->visible = TRUE;
383 if (scene.daytime == TIME_NIGHT){
385 g_free(actor->filename);
386 actor->filename = g_strdup("tu154.png");
389 g_free(actor->filename);
390 actor->filename = g_strdup("tu154.png");
392 create_hildon_actor(actor, desktop_plugin);
394 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
395 x = path_line(x0, x1, t);
396 y = path_line(y0, y1, t);
397 //scale = path_line(scale0, scale1, t);
398 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
399 actor_set_position_full(actor->widget, x, y, actor->z);
400 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
403 actor->visible = FALSE;
404 destroy_hildon_actor(actor);
405 actor->time_start_animation = sec + probability_plane();
411 change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
413 gint x0 = -actor->width, y0 = 45, scale0 = 100,
414 x1 = 800, y1 = 20, scale1 = 100,
421 gettimeofday(&tvb, NULL);
425 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
427 if (!actor->visible){
428 actor->visible = TRUE;
429 if (scene.daytime == TIME_NIGHT){
431 g_free(actor->filename);
432 if (scene.daytime == TIME_NIGHT)
433 actor->filename = g_strdup("plane3.png");
436 g_free(actor->filename);
437 actor->filename = g_strdup("plane3.png");
439 create_hildon_actor(actor, desktop_plugin);
441 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
442 x = path_line(x0, x1, t);
443 y = path_line(y0, y1, t);
444 //scale = path_line(scale0, scale1, t);
445 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
446 actor_set_position_full(actor->widget, x, y, actor->z);
447 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
450 actor->visible = FALSE;
451 destroy_hildon_actor(actor);
452 actor->time_start_animation = sec + probability_plane();
458 change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
460 gint x0, y0 = 300, scale0 = 100,
461 x1, y1 = -actor->height, scale1 = 150,
468 gettimeofday(&tvb, NULL);
472 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
474 if (!actor->visible){
475 actor->visible = TRUE;
476 if (scene.daytime == TIME_NIGHT)
477 actor->filename = actor->filename;
479 actor->filename = actor->filename;
480 create_hildon_actor(actor, desktop_plugin);
482 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
484 if (scene.wind_orientation == 1){
493 x = path_line(x0, x1, t);
494 y = -scene.wind_angle * (x - x0) + actor->y;
495 scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
497 //fprintf(stderr, "change cloud t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
498 actor_set_position_full(actor->widget, x, y, actor->z);
499 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
500 if ((y < y1 || y > y0) || t >= 1){
502 actor->visible = FALSE;
503 destroy_hildon_actor(actor);
504 actor->time_start_animation = sec + (fast_rnd(5) + 1)*60;
510 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
512 GtkWidget *ha = NULL;
513 GdkPixbuf *pixbuf = NULL;
514 GtkWidget *image = NULL;
517 /* fprintf(stderr, "create_hildon_actor %s\n", actor->name);*/
518 ha = hildon_animation_actor_new();
519 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
520 desktop_plugin->priv->theme, actor->filename);
521 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
528 image = gtk_image_new_from_pixbuf (pixbuf);
529 g_object_unref(G_OBJECT(pixbuf));
532 g_signal_connect(G_OBJECT(image), "expose_event",
533 G_CALLBACK(expose_event), pixbuf);
534 gtk_container_add (GTK_CONTAINER (ha), image);
536 actor_set_position_full(ha, actor->x, actor->y, actor->z);
537 hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(ha), actor->visible);
538 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(ha), (double)actor->scale/100, (double)actor->scale/100);
540 gtk_widget_show_all(ha);
545 //g_object_set_data(G_OBJECT(ha), "name", name);
546 //g_object_set_data(G_OBJECT(ha), "filename", filename);
547 g_object_set_data(G_OBJECT(ha), "image", image);
549 g_object_set_data(G_OBJECT(ha), "x", x);
550 g_object_set_data(G_OBJECT(ha), "y", y);
551 g_object_set_data(G_OBJECT(ha), "z", z);
552 g_object_set_data(G_OBJECT(ha), "width", width);
553 g_object_set_data(G_OBJECT(ha), "height", height);
554 g_object_set_data(G_OBJECT(ha), "scale", scale);
555 g_object_set_data(G_OBJECT(ha), "visible", visible);
556 g_object_set_data(G_OBJECT(ha), "opacity", opacity);
557 g_object_set_data(G_OBJECT(ha), "func", pfunc);
559 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
565 change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
567 GtkWidget *image = NULL;
568 GdkPixbuf *pixbuf = NULL;
571 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
572 desktop_plugin->priv->theme, actor->filename);
574 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
581 image = gtk_image_new_from_pixbuf (pixbuf);
582 g_object_unref(G_OBJECT(pixbuf));
585 g_signal_connect(G_OBJECT(image), "expose_event",
586 G_CALLBACK(expose_event), pixbuf);
587 if (g_object_get_data(G_OBJECT(actor->widget), "image")){
588 gtk_container_remove(GTK_CONTAINER(actor->widget), g_object_get_data(G_OBJECT(actor->widget), "image"));
590 g_object_set_data(G_OBJECT(actor->widget), "image", image);
591 gtk_container_add (GTK_CONTAINER (actor->widget), image);
592 realize(actor->widget);
593 gtk_widget_show_all(actor->widget);
604 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
609 daytime = get_daytime();
610 newfile = g_strdup_printf("%s%d.png", actor->name, daytime);
612 g_free(actor->filename);
613 actor->filename = newfile;
614 change_hildon_actor(actor, desktop_plugin);
622 // уравнение изменения времени
628 GSList * tmp = scene.actors;
634 g_free(actor->filename);
637 gtk_widget_destroy(actor->widget);
638 //actor->widget = NULL;
641 tmp = g_slist_next(tmp);
648 reload_scene(AWallpaperPlugin *desktop_plugin)
650 fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);
652 if (!strcmp(desktop_plugin->priv->theme,"Modern"))
653 init_scene(desktop_plugin);
654 else if (!strcmp(desktop_plugin->priv->theme,"Berlin"))
655 init_scene1(desktop_plugin);
659 /* Init Modern Scene */
661 init_scene(AWallpaperPlugin *desktop_plugin)
665 /* fprintf(stderr, "init scene \n");*/
666 scene.daytime = get_daytime();
669 actor = init_object(desktop_plugin, "sky", "sky0.png", 0, 0, 5, 800, 480,
670 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
671 change_static_actor(actor, desktop_plugin);
672 scene.actors = g_slist_append(scene.actors, actor);
674 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
675 TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
676 actor->time_start_animation = time(NULL);
677 actor->duration_animation = G_MAXINT;
678 change_sun(actor, desktop_plugin);
679 scene.actors = g_slist_append(scene.actors, actor);
681 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
682 TRUE, 100, 255, NULL, NULL);
683 scene.actors = g_slist_append(scene.actors, actor);
686 actor = init_object(desktop_plugin, "town", "town0.png", 0, 0, 7, 800, 480,
687 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
688 change_static_actor(actor, desktop_plugin);
689 scene.actors = g_slist_append(scene.actors, actor);
693 actor = init_object(desktop_plugin, "tram", "tram.png", -300, 225, 8, 350, 210,
694 FALSE, 100, 255, (gpointer)&change_tram, NULL);
695 actor->time_start_animation = time(NULL) + 10;
696 actor->duration_animation = 60;
697 scene.actors = g_slist_append(scene.actors, actor);
699 actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 9, 800, 79,
700 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
701 change_static_actor(actor, desktop_plugin);
702 scene.actors = g_slist_append(scene.actors, actor);
704 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 20, 10, 60, 60,
705 FALSE, 100, 255, (gpointer)&change_moon, NULL);
706 change_moon(actor, desktop_plugin);
707 scene.actors = g_slist_append(scene.actors, actor);
710 anim = g_new0(Animation, 1);
713 anim->func_change = &change_tram;
714 anim->func_time = NULL;
715 anim->timestart = time(NULL);
718 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
722 /* Init Berlin Scene */
724 init_scene1(AWallpaperPlugin *desktop_plugin)
727 gint now = time(NULL);
730 scene.daytime = get_daytime();
732 scene.wind_orientation = -1;
733 scene.wind_angle = 0.3;
735 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
736 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
737 change_static_actor(actor, desktop_plugin);
738 scene.actors = g_slist_append(scene.actors, actor);
741 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
742 TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
743 actor->time_start_animation = time(NULL);
744 actor->duration_animation = G_MAXINT;
745 change_sun(actor, desktop_plugin);
746 scene.actors = g_slist_append(scene.actors, actor);
749 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
750 TRUE, 100, 255, NULL, NULL);
751 scene.actors = g_slist_append(scene.actors, actor);
754 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
755 FALSE, 100, 255, (gpointer)&change_moon, NULL);
756 change_moon(actor, desktop_plugin);
757 scene.actors = g_slist_append(scene.actors, actor);
759 actor = init_object(desktop_plugin, "cloud1", "cloud2.png", 0, fast_rnd(300), 11, 188, 75,
760 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
761 actor->time_start_animation = now + fast_rnd(3) * 60;
762 actor->duration_animation = 5*60;
763 scene.actors = g_slist_append(scene.actors, actor);
765 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
766 FALSE, 100, 255, (gpointer)&change_plane2, NULL);
767 actor->time_start_animation = now + probability_plane();
768 actor->duration_animation = 60;
769 scene.actors = g_slist_append(scene.actors, actor);
771 actor = init_object(desktop_plugin, "plane1", "tu154_small.png", 620, 233, 9, 300, 116,
772 FALSE, 100, 255, (gpointer)&change_plane1, NULL);
773 actor->time_start_animation = now + probability_plane();
774 actor->duration_animation = 30;
775 scene.actors = g_slist_append(scene.actors, actor);
777 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
778 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
779 change_static_actor(actor, desktop_plugin);
780 scene.actors = g_slist_append(scene.actors, actor);
787 get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
789 gint y0 = 365;// - уровень горизонта
790 *x = (int)(azm * 800) - 64;
791 *y = (int)((1 - alt) * y0) - 64;
792 //fprintf(stderr, "sun pos alt=%f azm=%f x=%d y=%d\n", alt, azm, *x, *y);
796 change_actor(GtkWidget * actor)
799 gint x, y, daytime, scale;
806 void (*pfunc)(gpointer, gpointer);
808 name = g_object_get_data(G_OBJECT(actor), "name");
809 fprintf(stderr, "change actor %s\n", name);
811 pfunc = g_object_get_data(G_OBJECT(actor), "func");
813 (*pfunc)(actor, g_strdup(name));
814 daytime = get_daytime();
815 if (daytime != TIME_NIGHT){
816 hildon_animation_actor_set_show(actor, 1);
817 get_sun_pos(&alt, &azm);
818 get_sun_screen_pos(alt, azm, &x, &y);
819 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
823 if (name == "cloud1"){
824 x = g_object_get_data(G_OBJECT(actor), "x");
825 y = g_object_get_data(G_OBJECT(actor), "y");
826 scale = g_object_get_data(G_OBJECT(actor), "scale");
829 image = g_object_get_data(G_OBJECT(actor), "image");
831 gtk_container_remove(actor, image);
832 pixbuf = gdk_pixbuf_new_from_file_at_size ("/usr/share/livewp/theme/Modern/sun.png",
837 image = gtk_image_new_from_pixbuf (pixbuf);
838 g_object_unref(G_OBJECT(pixbuf));
840 g_signal_connect(G_OBJECT(image), "expose_event",
841 G_CALLBACK(expose_event), pixbuf);
842 gtk_container_add (GTK_CONTAINER (actor), image);
844 gtk_widget_show_all(actor);
856 sc = (double)scale / 100;
857 hildon_animation_actor_set_scale(actor, sc, sc);
858 fprintf(stderr, "cloud x=%d y=%d scale=%f", x, y, sc);
859 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
860 g_object_set_data(G_OBJECT(actor), "x", x);
861 g_object_set_data(G_OBJECT(actor), "y", y);
862 g_object_set_data(G_OBJECT(actor), "scale", scale);
868 short_timeout (AWallpaperPlugin *desktop_plugin)
870 gint daytime = get_daytime();
872 void (*pfunc)(gpointer, gpointer);
875 gboolean stop_flag = TRUE;
877 if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
878 desktop_plugin->priv->short_timer = 0;
883 //scene.daytime = daytime;
884 /* fprintf(stderr, "Short timer %d\n", now); */
888 if (now >= actor->time_start_animation
889 && actor->time_start_animation > 0
890 /* && now - actor->time_start_animation <= actor->duration_animation*/){
891 pfunc = actor->func_change;
893 (*pfunc)(actor, desktop_plugin);
897 tmp = g_slist_next(tmp);
900 desktop_plugin->priv->short_timer = 0;
903 return TRUE; /* keep running this event */
908 long_timeout (AWallpaperPlugin *desktop_plugin)
910 gint daytime = get_daytime();
912 void (*pfunc)(gpointer, gpointer);
916 /* TODO remove timeout */
917 if (!desktop_plugin->priv->visible){
918 desktop_plugin->priv->short_timer = 0;
921 //fprintf(stderr, "timer daytime=%d\n", daytime);
922 if (scene.daytime != daytime){
925 //change_actor(tmp->data);
926 pfunc =((Actor*)tmp->data)->func_change;
928 (*pfunc)(tmp->data, desktop_plugin);
930 tmp = g_slist_next(tmp);
935 //fprintf(stderr, "Now %d\n", now);
939 if (now >= actor->time_start_animation
940 && actor->time_start_animation > 0
941 && desktop_plugin->priv->short_timer == 0){
942 actor->time_start_animation = now;
943 /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
944 if (desktop_plugin->priv->rich_animation)
945 desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
947 tmp = g_slist_next(tmp);
950 scene.daytime = daytime;
952 return TRUE; /* keep running this event */
956 desktop_plugin_visible_notify (GObject *object,
958 AWallpaperPlugin *desktop_plugin)
961 g_object_get (object, "is-on-current-desktop", &visible, NULL);
963 desktop_plugin->priv->visible = TRUE;
964 desktop_plugin->priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
966 desktop_plugin->priv->visible = FALSE;
967 /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
971 rich_animation_press(GtkWidget *widget, GdkEvent *event,
973 fprintf(stderr,"gggggggggggggggggggg\n");
976 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
979 GtkWidget *rich_animation;
980 fprintf(stderr, "!!!!!!!plugin init \n");
981 Animation_WallpaperPrivate *priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
982 desktop_plugin->priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
985 priv->desktop_plugin = desktop_plugin;
986 /* Create rich animation event */
987 rich_animation = gtk_event_box_new();
989 gtk_widget_set_events(rich_animation, GDK_BUTTON_PRESS_MASK);
990 gtk_event_box_set_visible_window(GTK_EVENT_BOX(rich_animation), FALSE);
991 gtk_widget_set_size_request(rich_animation, 95, 30);
992 gtk_widget_show (rich_animation);
993 g_signal_connect(rich_animation, "button-press-event", G_CALLBACK(rich_animation_press), desktop_plugin);
996 label = gtk_label_new ("");
997 gtk_widget_set_size_request(label, 95, 30);
998 gtk_widget_show (label);
999 gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
1001 hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
1002 g_signal_connect (desktop_plugin, "show-settings",
1003 G_CALLBACK (lw_settings), priv);
1004 g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
1005 G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
1007 gtk_container_add (GTK_CONTAINER (desktop_plugin), rich_animation);
1008 init_applet_position();
1010 /* start value for random */
1013 fprintf(stderr, "!!!theme = %s\n", priv->theme);
1014 if (!strcmp(priv->theme,"Modern"))
1015 init_scene(desktop_plugin);
1016 else if (!strcmp(priv->theme,"Berlin"))
1017 init_scene1(desktop_plugin);
1018 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1019 priv->short_timer = 0;
1020 /* TODO Move scene to priv */
1021 scene.timer_type = LONG_TIMER_TYPE;
1027 lw_applet_finalize (GObject *object)
1029 AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
1030 Animation_WallpaperPrivate *priv = desktop_plugin->priv;
1032 if (priv->long_timer){
1033 g_source_remove(priv->long_timer);
1034 priv->long_timer = 0;
1036 if (priv->short_timer){
1037 g_source_remove(priv->short_timer);
1038 priv->short_timer = 0;
1045 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
1047 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1048 GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
1051 gobject_class->destroy = (gpointer)lw_applet_finalize;
1052 widget_class->realize = lw_applet_realize;
1053 widget_class->expose_event = lw_applet_expose_event;
1055 g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));
1060 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {}