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)
237 gint multiplier = 4079;
239 seed = seed * multiplier + offset;
240 return (gint)(seed % max);
247 gint t = (fast_rnd(10) + 1) * 60;
248 fprintf(stderr, "probability_plane %d\n", t);
253 change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
259 if (scene.daytime == TIME_NIGHT){
260 if (!actor->visible){
261 actor->visible = TRUE;
262 phase = get_moon_phase();
263 newfile = g_strdup_printf( "%s%d.png", actor->name, phase);
265 g_free(actor->filename);
266 actor->filename = newfile;
267 create_hildon_actor(actor, desktop_plugin);
272 // actor_set_position_full(actor->widget, x, y, actor->z);
273 //probability_sun(actor);
274 //fprintf(stderr, "after change sun %d\n", actor->time_start_animation);
275 }else if (actor->visible){
276 actor->visible = FALSE;
277 fprintf(stderr, "destroy moon \n");
278 destroy_hildon_actor(actor);
279 /* TO DO make moonrise*/
280 actor->time_start_animation = get_next_sunset();
287 change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
293 if (scene.daytime != TIME_NIGHT){
294 if (!actor->visible){
295 actor->visible = TRUE;
297 create_hildon_actor(actor, desktop_plugin);
299 get_sun_pos(&alt, &azm);
300 get_sun_screen_pos(alt, azm, &x, &y);
303 actor_set_position_full(actor->widget, x, y, actor->z);
304 probability_sun(actor);
305 }else if (actor->visible){
306 actor->visible = FALSE;
307 destroy_hildon_actor(actor);
308 actor->time_start_animation = get_next_sunrise();
315 change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
317 gint x0 = -300, y0 = 225, scale0 = 100,
318 x1 = 800, y1 = 162, scale1 = 130,
325 gettimeofday(&tvb, NULL);
329 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
331 if (!actor->visible){
332 actor->visible = TRUE;
333 if (scene.daytime == TIME_NIGHT){
335 g_free(actor->filename);
336 actor->filename = g_strdup("tram_dark.png");
339 g_free(actor->filename);
340 actor->filename = g_strdup("tram.png");
342 create_hildon_actor(actor, desktop_plugin);
344 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
345 x = path_line(x0, x1, t);
346 y = path_line(y0, y1, t);
347 scale = path_line(scale0, scale1, t);
348 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
349 actor_set_position_full(actor->widget, x, y, actor->z);
350 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
353 actor->visible = FALSE;
354 destroy_hildon_actor(actor);
355 actor->time_start_animation = sec + 5*60;
360 change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
362 gint x0 = 620, y0 = 233, scale0 = 100,
363 x1 = 79, y1 = -146, scale1 = 100,
370 gettimeofday(&tvb, NULL);
374 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
376 if (!actor->visible){
377 actor->visible = TRUE;
378 if (scene.daytime == TIME_NIGHT){
380 g_free(actor->filename);
381 actor->filename = g_strdup("tu154.png");
384 g_free(actor->filename);
385 actor->filename = g_strdup("tu154.png");
387 create_hildon_actor(actor, desktop_plugin);
389 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
390 x = path_line(x0, x1, t);
391 y = path_line(y0, y1, t);
392 //scale = path_line(scale0, scale1, t);
393 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
394 actor_set_position_full(actor->widget, x, y, actor->z);
395 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
398 actor->visible = FALSE;
399 destroy_hildon_actor(actor);
400 actor->time_start_animation = sec + probability_plane();
406 change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
408 gint x0 = -actor->width, y0 = 45, scale0 = 100,
409 x1 = 800, y1 = 20, scale1 = 100,
416 gettimeofday(&tvb, NULL);
420 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
422 if (!actor->visible){
423 actor->visible = TRUE;
424 if (scene.daytime == TIME_NIGHT){
426 g_free(actor->filename);
427 if (scene.daytime == TIME_NIGHT)
428 actor->filename = g_strdup("plane3.png");
431 g_free(actor->filename);
432 actor->filename = g_strdup("plane3.png");
434 create_hildon_actor(actor, desktop_plugin);
436 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
437 x = path_line(x0, x1, t);
438 y = path_line(y0, y1, t);
439 //scale = path_line(scale0, scale1, t);
440 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
441 actor_set_position_full(actor->widget, x, y, actor->z);
442 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
445 actor->visible = FALSE;
446 destroy_hildon_actor(actor);
447 actor->time_start_animation = sec + probability_plane();
453 change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
455 gint x0, y0 = 300, scale0 = 100,
456 x1, y1 = -actor->height, scale1 = 150,
463 gettimeofday(&tvb, NULL);
467 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
469 if (!actor->visible){
470 actor->visible = TRUE;
471 if (scene.daytime == TIME_NIGHT)
472 actor->filename = actor->filename;
474 actor->filename = actor->filename;
475 create_hildon_actor(actor, desktop_plugin);
477 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
479 if (scene.wind_orientation == 1){
488 x = path_line(x0, x1, t);
489 y = -scene.wind_angle * (x - x0) + actor->y;
490 scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
492 //fprintf(stderr, "change cloud t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
493 actor_set_position_full(actor->widget, x, y, actor->z);
494 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
495 if ((y < y1 || y > y0) || t >= 1){
497 actor->visible = FALSE;
498 destroy_hildon_actor(actor);
499 actor->time_start_animation = sec + 5*60;
505 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
507 GtkWidget *ha = NULL;
508 GdkPixbuf *pixbuf = NULL;
509 GtkWidget *image = NULL;
512 /* fprintf(stderr, "create_hildon_actor %s\n", actor->name);*/
513 ha = hildon_animation_actor_new();
514 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
515 desktop_plugin->priv->theme, actor->filename);
516 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
523 image = gtk_image_new_from_pixbuf (pixbuf);
524 g_object_unref(G_OBJECT(pixbuf));
527 g_signal_connect(G_OBJECT(image), "expose_event",
528 G_CALLBACK(expose_event), pixbuf);
529 gtk_container_add (GTK_CONTAINER (ha), image);
531 actor_set_position_full(ha, actor->x, actor->y, actor->z);
532 hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(ha), actor->visible);
533 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(ha), (double)actor->scale/100, (double)actor->scale/100);
535 gtk_widget_show_all(ha);
540 //g_object_set_data(G_OBJECT(ha), "name", name);
541 //g_object_set_data(G_OBJECT(ha), "filename", filename);
542 g_object_set_data(G_OBJECT(ha), "image", image);
544 g_object_set_data(G_OBJECT(ha), "x", x);
545 g_object_set_data(G_OBJECT(ha), "y", y);
546 g_object_set_data(G_OBJECT(ha), "z", z);
547 g_object_set_data(G_OBJECT(ha), "width", width);
548 g_object_set_data(G_OBJECT(ha), "height", height);
549 g_object_set_data(G_OBJECT(ha), "scale", scale);
550 g_object_set_data(G_OBJECT(ha), "visible", visible);
551 g_object_set_data(G_OBJECT(ha), "opacity", opacity);
552 g_object_set_data(G_OBJECT(ha), "func", pfunc);
554 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
560 change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
562 GtkWidget *image = NULL;
563 GdkPixbuf *pixbuf = NULL;
566 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
567 desktop_plugin->priv->theme, actor->filename);
569 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
576 image = gtk_image_new_from_pixbuf (pixbuf);
577 g_object_unref(G_OBJECT(pixbuf));
580 g_signal_connect(G_OBJECT(image), "expose_event",
581 G_CALLBACK(expose_event), pixbuf);
582 if (g_object_get_data(G_OBJECT(actor->widget), "image")){
583 gtk_container_remove(GTK_CONTAINER(actor->widget), g_object_get_data(G_OBJECT(actor->widget), "image"));
585 g_object_set_data(G_OBJECT(actor->widget), "image", image);
586 gtk_container_add (GTK_CONTAINER (actor->widget), image);
587 realize(actor->widget);
588 gtk_widget_show_all(actor->widget);
599 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
604 daytime = get_daytime();
605 newfile = g_strdup_printf("%s%d.png", actor->name, daytime);
607 g_free(actor->filename);
608 actor->filename = newfile;
609 change_hildon_actor(actor, desktop_plugin);
617 // уравнение изменения времени
623 GSList * tmp = scene.actors;
629 g_free(actor->filename);
632 gtk_widget_destroy(actor->widget);
633 //actor->widget = NULL;
636 tmp = g_slist_next(tmp);
643 reload_scene(AWallpaperPlugin *desktop_plugin)
645 fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);
647 if (!strcmp(desktop_plugin->priv->theme,"Modern"))
648 init_scene(desktop_plugin);
649 else if (!strcmp(desktop_plugin->priv->theme,"Berlin"))
650 init_scene1(desktop_plugin);
654 probability_sun(Actor *actor)
656 actor->time_start_animation += 20 * 1;
657 actor->duration_animation = G_MAXINT;
661 /* Init Modern Scene */
663 init_scene(AWallpaperPlugin *desktop_plugin)
667 /* fprintf(stderr, "init scene \n");*/
668 scene.daytime = get_daytime();
671 actor = init_object(desktop_plugin, "sky", "sky0.png", 0, 0, 5, 800, 480,
672 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
673 change_static_actor(actor, desktop_plugin);
674 scene.actors = g_slist_append(scene.actors, actor);
676 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
677 TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
678 actor->time_start_animation = time(NULL);
679 actor->duration_animation = G_MAXINT;
680 change_sun(actor, desktop_plugin);
681 scene.actors = g_slist_append(scene.actors, actor);
683 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
684 TRUE, 100, 255, NULL, NULL);
685 scene.actors = g_slist_append(scene.actors, actor);
688 actor = init_object(desktop_plugin, "town", "town0.png", 0, 0, 7, 800, 480,
689 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
690 change_static_actor(actor, desktop_plugin);
691 scene.actors = g_slist_append(scene.actors, actor);
695 actor = init_object(desktop_plugin, "tram", "tram.png", -300, 225, 8, 350, 210,
696 FALSE, 100, 255, (gpointer)&change_tram, NULL);
697 actor->time_start_animation = time(NULL) + 10;
698 actor->duration_animation = 60;
699 scene.actors = g_slist_append(scene.actors, actor);
701 actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 9, 800, 79,
702 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
703 change_static_actor(actor, desktop_plugin);
704 scene.actors = g_slist_append(scene.actors, actor);
706 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 20, 10, 60, 60,
707 FALSE, 100, 255, (gpointer)&change_moon, NULL);
708 change_moon(actor, desktop_plugin);
709 scene.actors = g_slist_append(scene.actors, actor);
712 anim = g_new0(Animation, 1);
715 anim->func_change = &change_tram;
716 anim->func_time = NULL;
717 anim->timestart = time(NULL);
720 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
724 /* Init Berlin Scene */
726 init_scene1(AWallpaperPlugin *desktop_plugin)
729 gint now = time(NULL);
731 seed = time(NULL)%10;
733 scene.daytime = get_daytime();
735 scene.wind_orientation = -1;
736 scene.wind_angle = 0.3;
738 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
739 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
740 change_static_actor(actor, desktop_plugin);
741 scene.actors = g_slist_append(scene.actors, actor);
744 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
745 TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
746 actor->time_start_animation = time(NULL);
747 actor->duration_animation = G_MAXINT;
748 change_sun(actor, desktop_plugin);
749 scene.actors = g_slist_append(scene.actors, actor);
752 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
753 TRUE, 100, 255, NULL, NULL);
754 scene.actors = g_slist_append(scene.actors, actor);
757 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
758 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
759 change_static_actor(actor, desktop_plugin);
760 scene.actors = g_slist_append(scene.actors, actor);
762 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
763 FALSE, 100, 255, (gpointer)&change_moon, NULL);
764 change_moon(actor, desktop_plugin);
765 scene.actors = g_slist_append(scene.actors, actor);
767 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
768 FALSE, 100, 255, (gpointer)&change_plane2, NULL);
769 actor->time_start_animation = now + probability_plane();
770 actor->duration_animation = 60;
771 scene.actors = g_slist_append(scene.actors, actor);
773 actor = init_object(desktop_plugin, "plane1", "tu154_small.png", 620, 233, 9, 300, 116,
774 FALSE, 100, 255, (gpointer)&change_plane1, NULL);
775 actor->time_start_animation = now + probability_plane();
776 actor->duration_animation = 30;
777 scene.actors = g_slist_append(scene.actors, actor);
779 actor = init_object(desktop_plugin, "cloud1", "cloud2.png", 0, 50, 7, 188, 75,
780 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
781 actor->time_start_animation = now + 5;
782 actor->duration_animation = 5*60;
783 scene.actors = g_slist_append(scene.actors, actor);
789 get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
791 gint y0 = 365;// - уровень горизонта
792 *x = (int)(azm * 800) - 64;
793 *y = (int)((1 - alt) * y0) - 64;
794 //fprintf(stderr, "sun pos alt=%f azm=%f x=%d y=%d\n", alt, azm, *x, *y);
798 change_actor(GtkWidget * actor)
801 gint x, y, daytime, scale;
808 void (*pfunc)(gpointer, gpointer);
810 name = g_object_get_data(G_OBJECT(actor), "name");
811 fprintf(stderr, "change actor %s\n", name);
813 pfunc = g_object_get_data(G_OBJECT(actor), "func");
815 (*pfunc)(actor, g_strdup(name));
816 daytime = get_daytime();
817 if (daytime != TIME_NIGHT){
818 hildon_animation_actor_set_show(actor, 1);
819 get_sun_pos(&alt, &azm);
820 get_sun_screen_pos(alt, azm, &x, &y);
821 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
825 if (name == "cloud1"){
826 x = g_object_get_data(G_OBJECT(actor), "x");
827 y = g_object_get_data(G_OBJECT(actor), "y");
828 scale = g_object_get_data(G_OBJECT(actor), "scale");
831 image = g_object_get_data(G_OBJECT(actor), "image");
833 gtk_container_remove(actor, image);
834 pixbuf = gdk_pixbuf_new_from_file_at_size ("/usr/share/livewp/theme/Modern/sun.png",
839 image = gtk_image_new_from_pixbuf (pixbuf);
840 g_object_unref(G_OBJECT(pixbuf));
842 g_signal_connect(G_OBJECT(image), "expose_event",
843 G_CALLBACK(expose_event), pixbuf);
844 gtk_container_add (GTK_CONTAINER (actor), image);
846 gtk_widget_show_all(actor);
858 sc = (double)scale / 100;
859 hildon_animation_actor_set_scale(actor, sc, sc);
860 fprintf(stderr, "cloud x=%d y=%d scale=%f", x, y, sc);
861 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
862 g_object_set_data(G_OBJECT(actor), "x", x);
863 g_object_set_data(G_OBJECT(actor), "y", y);
864 g_object_set_data(G_OBJECT(actor), "scale", scale);
870 short_timeout (AWallpaperPlugin *desktop_plugin)
872 gint daytime = get_daytime();
874 void (*pfunc)(gpointer, gpointer);
877 gboolean stop_flag = TRUE;
879 if (!desktop_plugin->priv->visible)
883 /* fprintf(stderr, "Short timer %d\n", now); */
887 if (now >= actor->time_start_animation
888 && actor->time_start_animation > 0
889 /* && now - actor->time_start_animation <= actor->duration_animation*/){
890 pfunc = actor->func_change;
892 (*pfunc)(actor, desktop_plugin);
896 tmp = g_slist_next(tmp);
898 scene.daytime = daytime;
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)
919 //fprintf(stderr, "timer daytime=%d\n", daytime);
920 if (scene.daytime != daytime){
923 //change_actor(tmp->data);
924 pfunc =((Actor*)tmp->data)->func_change;
926 (*pfunc)(tmp->data, desktop_plugin);
928 tmp = g_slist_next(tmp);
933 //fprintf(stderr, "Now %d\n", now);
937 if (now >= actor->time_start_animation
938 && actor->time_start_animation > 0
939 && desktop_plugin->priv->short_timer == 0){
940 actor->time_start_animation = now;
941 /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
942 desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
944 tmp = g_slist_next(tmp);
947 scene.daytime = daytime;
949 return TRUE; /* keep running this event */
953 desktop_plugin_visible_notify (GObject *object,
955 AWallpaperPlugin *desktop_plugin)
958 g_object_get (object, "is-on-current-desktop", &visible, NULL);
960 desktop_plugin->priv->visible = TRUE;
962 desktop_plugin->priv->visible = FALSE;
963 /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
967 rich_animation_press(GtkWidget *widget, GdkEvent *event,
969 fprintf(stderr,"gggggggggggggggggggg\n");
972 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
975 GtkWidget *rich_animation;
976 fprintf(stderr, "!!!!!!!plugin init \n");
977 Animation_WallpaperPrivate *priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
978 desktop_plugin->priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
981 priv->desktop_plugin = desktop_plugin;
982 /* Create rich animation event */
983 rich_animation = gtk_event_box_new();
985 gtk_widget_set_events(rich_animation, GDK_BUTTON_PRESS_MASK);
986 gtk_event_box_set_visible_window(GTK_EVENT_BOX(rich_animation), FALSE);
987 gtk_widget_set_size_request(rich_animation, 95, 30);
988 gtk_widget_show (rich_animation);
989 g_signal_connect(rich_animation, "button-press-event", G_CALLBACK(rich_animation_press), desktop_plugin);
992 label = gtk_label_new ("");
993 gtk_widget_set_size_request(label, 95, 30);
994 gtk_widget_show (label);
995 gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
997 hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
998 g_signal_connect (desktop_plugin, "show-settings",
999 G_CALLBACK (lw_settings), priv);
1000 g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
1001 G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
1003 gtk_container_add (GTK_CONTAINER (desktop_plugin), rich_animation);
1004 init_applet_position();
1005 fprintf(stderr, "!!!theme = %s\n", priv->theme);
1006 if (!strcmp(priv->theme,"Modern"))
1007 init_scene(desktop_plugin);
1008 else if (!strcmp(priv->theme,"Berlin"))
1009 init_scene1(desktop_plugin);
1010 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1011 priv->short_timer = 0;
1012 /* TODO Move scene to priv */
1013 scene.timer_type = LONG_TIMER_TYPE;
1019 lw_applet_finalize (GObject *object)
1021 AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
1022 Animation_WallpaperPrivate *priv = desktop_plugin->priv;
1024 if (priv->long_timer){
1025 g_source_remove(priv->long_timer);
1026 priv->long_timer = 0;
1028 if (priv->short_timer){
1029 g_source_remove(priv->short_timer);
1030 priv->short_timer = 0;
1037 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
1039 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1040 GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
1043 gobject_class->destroy = (gpointer)lw_applet_finalize;
1044 widget_class->realize = lw_applet_realize;
1045 widget_class->expose_event = lw_applet_expose_event;
1047 g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));
1052 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {}