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 448
46 gint xapplet = 0, yapplet = 0;
53 lw_applet_realize (GtkWidget *widget)
57 screen = gtk_widget_get_screen (widget);
58 gtk_widget_set_colormap (widget,
59 gdk_screen_get_rgba_colormap (screen));
60 gtk_widget_set_app_paintable (widget,
62 GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->realize (widget);
67 lw_applet_expose_event(GtkWidget *widget,
68 GdkEventExpose *event)
72 /* Create cairo context */
73 cr = gdk_cairo_create (GDK_DRAWABLE (widget->window));
74 gdk_cairo_region (cr, event->region);
77 /* Draw alpha background */
78 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
79 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0);
85 return GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->expose_event (widget,
90 expose_event (GtkWidget *widget,GdkEventExpose *event,
94 GdkPixbuf *pixbuf = (GdkPixbuf *) data;
96 cr = gdk_cairo_create(widget->window);
98 gdk_cairo_region(cr, event->region);
99 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
100 gdk_cairo_set_source_pixbuf(cr, pixbuf, 0.0, 0.0);
108 realize (GtkWidget *widget)
111 screen = gtk_widget_get_screen (widget);
112 gtk_widget_set_colormap (widget, gdk_screen_get_rgba_colormap (screen));
115 /* Set position of widget on desktop */
117 init_applet_position(void)
119 GSList *position = NULL;
123 GError *error = NULL;
124 GConfClient *gconf_client = gconf_client_get_default ();
125 position_key = g_strdup_printf (GCONF_KEY_POSITION, PLUGIN_NAME);
126 position = gconf_client_get_list (gconf_client,
130 if (position && position->data && position->next->data){
131 xapplet = GPOINTER_TO_INT (position->data);
132 yapplet = GPOINTER_TO_INT (position->next->data);
134 position = g_slist_prepend (g_slist_prepend (NULL,
135 GINT_TO_POINTER (Ystartposition)),
136 GINT_TO_POINTER (Xstartposition));
137 gconf_client_set_list (gconf_client,
142 xapplet = Xstartposition;
143 yapplet = Ystartposition;
145 g_free (position_key);
146 modified = g_strdup_printf ("%i", 0);
147 modified_key = g_strdup_printf (GCONF_KEY_MODIFIED, PLUGIN_NAME);
148 gconf_client_set_string (gconf_client,
153 g_free(modified_key);
154 gconf_client_clear_cache(gconf_client);
155 g_object_unref(gconf_client);
159 actor_set_position_full(GtkWidget *actor, gint x, gint y, gint z)
161 /* fprintf(stderr, "actor_set_position_full z=%d\n", z); */
162 hildon_animation_actor_set_position_full (HILDON_ANIMATION_ACTOR (actor),x-xapplet, y-yapplet, z);
166 path_line(gint x0, gint x1, double t)
169 return ((x1 - x0) * t + x0);
174 destroy_hildon_actor(Actor *actor)
176 //fprintf(stderr, "destroy_hildon_actor %s\n",actor->name);
177 gtk_widget_destroy(actor->widget);
178 actor->widget = NULL;
182 init_object(AWallpaperPlugin *desktop_plugin,
193 void (*pfunc_change)(Actor*),
194 void (*pfunc_probability)(Actor*)
198 actor = g_new0(Actor, 1);
202 actor->width = width;
203 actor->height = height;
204 actor->visible = visible;
205 actor->scale = scale;
206 actor->opacity = opacity;
207 actor->filename = g_strdup(filename);
208 actor->name = g_strdup(name);
209 actor->func_change = (gpointer)pfunc_change;
210 actor->func_probability = (gpointer)pfunc_probability;
212 create_hildon_actor(actor, desktop_plugin);
214 actor->widget = NULL;
215 actor->time_start_animation = 0;
216 actor->duration_animation = 0;
224 //objects_list = g_slist_append(objects_list, G_OBJECT(actor));
225 //objects_list = g_slist_append(objects_list, G_OBJECT(a));
235 gint fast_rnd(gint max)
237 guint offset = 12923;
238 guint multiplier = 4079;
240 scene.seed = scene.seed * multiplier + offset;
241 return (gint)(scene.seed % max);
247 /* update sun position after ... second */
255 return (fast_rnd(60));
260 change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
264 fprintf(stderr, "change moon\n");
266 if (scene.daytime == TIME_NIGHT){
267 if (!actor->visible){
268 actor->visible = TRUE;
270 phase = get_moon_phase();
271 newfile = g_strdup_printf( "%s%d.png", actor->name, phase);
273 g_free(actor->filename);
274 actor->filename = newfile;
276 create_hildon_actor(actor, desktop_plugin);
281 // actor_set_position_full(actor->widget, x, y, actor->z);
282 //probability_sun(actor);
283 //fprintf(stderr, "after change sun %d\n", actor->time_start_animation);
284 }else if (actor->visible){
285 actor->visible = FALSE;
286 fprintf(stderr, "destroy moon \n");
287 destroy_hildon_actor(actor);
288 /* TO DO make moonrise*/
289 actor->time_start_animation = 0;
296 change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
301 //fprintf(stderr, "change sun\n");
303 if (scene.daytime != TIME_NIGHT){
304 if (!actor->visible){
305 actor->visible = TRUE;
306 create_hildon_actor(actor, desktop_plugin);
308 get_sun_pos(hour, min, &alt, &azm);
309 get_sun_screen_pos(alt, azm, &x, &y);
312 actor_set_position_full(actor->widget, x, y, actor->z);
313 //probability_sun(actor);
314 actor->time_start_animation = time(NULL);
315 }else if (actor->visible){
316 actor->visible = FALSE;
317 destroy_hildon_actor(actor);
318 actor->time_start_animation = 0;
325 change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
327 gint x0 = -300, y0 = 225, scale0 = 100,
328 x1 = 800, y1 = 162, scale1 = 130,
336 //fprintf(stderr, "change tram\n");
337 gettimeofday(&tvb, NULL);
342 if (!actor->visible){
343 actor->visible = TRUE;
344 if (scene.daytime == TIME_NIGHT){
346 g_free(actor->filename);
347 actor->filename = g_strdup("tram_dark.png");
350 g_free(actor->filename);
351 actor->filename = g_strdup("tram.png");
353 create_hildon_actor(actor, desktop_plugin);
355 if (scene.daytime == TIME_NIGHT){
356 newfile = g_strdup("tram_dark.png");
358 newfile = g_strdup("tram.png");
360 if (strcmp(actor->filename, newfile)){
362 g_free(actor->filename);
363 actor->filename = newfile;
366 change_hildon_actor(actor, desktop_plugin);
369 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
370 x = path_line(x0, x1, t);
371 y = path_line(y0, y1, t);
372 scale = path_line(scale0, scale1, t);
373 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
374 actor_set_position_full(actor->widget, x, y, actor->z);
375 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
378 actor->visible = FALSE;
379 destroy_hildon_actor(actor);
380 actor->time_start_animation = sec + 20;
385 change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
387 gint x0 = 620, y0 = 233, scale0 = 100,
388 x1 = 79, y1 = -146, scale1 = 100,
396 gettimeofday(&tvb, NULL);
400 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
402 if (scene.daytime != TIME_NIGHT){
403 if (actor->time_start_animation == 0){
404 actor->time_start_animation = sec + probability_plane();
408 if (!actor->visible){
409 actor->visible = TRUE;
410 create_hildon_actor(actor, desktop_plugin);
412 if (scene.daytime == TIME_NIGHT){
413 newfile = g_strdup("dot1.png");
415 newfile = g_strdup("tu154.png");
417 if (strcmp(actor->filename, newfile)){
419 g_free(actor->filename);
420 actor->filename = newfile;
423 change_hildon_actor(actor, desktop_plugin);
426 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
427 x = path_line(x0, x1, t);
428 y = path_line(y0, y1, t);
429 //scale line(scale0, scale1, t);
430 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
431 actor_set_position_full(actor->widget, x, y, actor->z);
432 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
435 actor->visible = FALSE;
436 destroy_hildon_actor(actor);
437 if (scene.daytime == TIME_NIGHT)
438 actor->time_start_animation = 0;
440 actor->time_start_animation = sec + 10;
446 change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
448 gint x0 = -actor->width, y0 = 45, scale0 = 100,
449 x1 = 800, y1 = 20, scale1 = 100,
457 gettimeofday(&tvb, NULL);
461 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
462 if (scene.daytime != TIME_NIGHT){
463 if (actor->time_start_animation == 0){
464 actor->time_start_animation = sec + probability_plane();
468 if (!actor->visible){
469 actor->visible = TRUE;
470 create_hildon_actor(actor, desktop_plugin);
472 if (scene.daytime == TIME_NIGHT){
473 newfile = g_strdup("dot1.png");
475 newfile = g_strdup("plane3.png");
477 if (strcmp(actor->filename, newfile)){
479 g_free(actor->filename);
480 actor->filename = newfile;
483 change_hildon_actor(actor, desktop_plugin);
486 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
487 x = path_line(x0, x1, t);
488 y = path_line(y0, y1, t);
489 //scale = path_line(scale0, scale1, t);
490 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
491 actor_set_position_full(actor->widget, x, y, actor->z);
492 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
495 actor->visible = FALSE;
496 destroy_hildon_actor(actor);
497 if (scene.daytime == TIME_NIGHT)
498 actor->time_start_animation = 0;
500 actor->time_start_animation = sec + 15;
506 change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
508 gint x0, y0 = 300, scale0 = 100,
509 x1, y1 = -actor->height, scale1 = 150,
517 //fprintf(stderr, "change cloud\n");
518 gettimeofday(&tvb, NULL);
522 //fprintf(stderr, "c1oud %s - y0=%d\n", actor->name, actor->y);
524 if (!actor->visible){
525 actor->visible = TRUE;
526 if (scene.daytime == TIME_NIGHT){
527 newfile = g_strdup_printf("%s_dark.png", actor->name);
529 newfile = g_strdup_printf("%s.png", actor->name);
532 g_free(actor->filename);
533 actor->filename = newfile;
536 create_hildon_actor(actor, desktop_plugin);
538 if (scene.daytime == TIME_NIGHT){
539 newfile = g_strdup_printf("%s_dark.png", actor->name);
541 newfile = g_strdup_printf("%s.png", actor->name);
543 if (strcmp(actor->filename, newfile)){
545 g_free(actor->filename);
546 actor->filename = newfile;
549 change_hildon_actor(actor, desktop_plugin);
552 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
554 if (scene.wind_orientation == 1){
563 x = path_line(x0, x1, t);
564 y = -scene.wind_angle * (x - x0) + actor->y;
565 scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
567 //fprintf(stderr, "change cloud t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
568 actor_set_position_full(actor->widget, x, y, actor->z);
569 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
570 if ((y < y1 || y > y0) || t >= 1){
572 actor->visible = FALSE;
573 destroy_hildon_actor(actor);
574 actor->time_start_animation = sec + 10;
575 actor->y = fast_rnd(300);
581 change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
583 scene.wind_orientation = fast_rnd(2);
584 if (scene.wind_orientation == 0) scene.wind_orientation = -1;
585 scene.wind_angle = (double)(fast_rnd(200) - 100) / 100;
586 actor->time_start_animation = time(NULL) + (fast_rnd(10) + 10) * 60;
587 //fprintf(stderr, "change wind orient = %d angle = %f after = %d\n", scene.wind_orientation, scene.wind_angle, actor->time_start_animation-time(NULL));
591 change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin)
594 gint now = time(NULL);
595 if (scene.daytime == TIME_DAY){
597 actor->visible = FALSE;
598 destroy_hildon_actor(actor);
600 actor->time_start_animation = 0;
602 }else if (actor->time_start_animation == 0){
603 actor->time_start_animation = now + fast_rnd(30);
607 if (!actor->visible){
608 actor->visible = TRUE;
609 create_hildon_actor(actor, desktop_plugin);
610 actor->time_start_animation = now + 5;
612 actor->visible = FALSE;
613 destroy_hildon_actor(actor);
614 actor->time_start_animation = now + 5;
620 change_signal(Actor * actor, AWallpaperPlugin *desktop_plugin)
623 gint now = time(NULL);
624 newfile = g_strdup_printf("%s%d.png", actor->name, scene.daytime);
625 if (!strcmp(actor->filename, "red.png"))
626 newfile = g_strdup_printf("%s", "green.png");
628 newfile = g_strdup_printf("%s", "red.png");
629 g_free(actor->filename);
630 actor->filename = newfile;
631 change_hildon_actor(actor, desktop_plugin);
632 actor->time_start_animation = now + 5;
636 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
638 GtkWidget *ha = NULL;
639 GdkPixbuf *pixbuf = NULL;
640 GtkWidget *image = NULL;
643 /* fprintf(stderr, "create_hildon_actor %s\n", actor->name);*/
644 ha = hildon_animation_actor_new();
645 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
646 desktop_plugin->priv->theme, actor->filename);
647 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
654 image = gtk_image_new_from_pixbuf (pixbuf);
655 g_object_unref(G_OBJECT(pixbuf));
658 g_signal_connect(G_OBJECT(image), "expose_event",
659 G_CALLBACK(expose_event), pixbuf);
660 gtk_container_add (GTK_CONTAINER (ha), image);
662 actor_set_position_full(ha, actor->x, actor->y, actor->z);
663 hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(ha), actor->visible);
664 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(ha), (double)actor->scale/100, (double)actor->scale/100);
666 gtk_widget_show_all(ha);
671 //g_object_set_data(G_OBJECT(ha), "name", name);
672 //g_object_set_data(G_OBJECT(ha), "filename", filename);
673 g_object_set_data(G_OBJECT(ha), "image", image);
675 g_object_set_data(G_OBJECT(ha), "x", x);
676 g_object_set_data(G_OBJECT(ha), "y", y);
677 g_object_set_data(G_OBJECT(ha), "z", z);
678 g_object_set_data(G_OBJECT(ha), "width", width);
679 g_object_set_data(G_OBJECT(ha), "height", height);
680 g_object_set_data(G_OBJECT(ha), "scale", scale);
681 g_object_set_data(G_OBJECT(ha), "visible", visible);
682 g_object_set_data(G_OBJECT(ha), "opacity", opacity);
683 g_object_set_data(G_OBJECT(ha), "func", pfunc);
685 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
691 change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
693 GtkWidget *image = NULL;
694 GdkPixbuf *pixbuf = NULL;
697 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
698 desktop_plugin->priv->theme, actor->filename);
700 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
707 image = gtk_image_new_from_pixbuf (pixbuf);
708 g_object_unref(G_OBJECT(pixbuf));
711 g_signal_connect(G_OBJECT(image), "expose_event",
712 G_CALLBACK(expose_event), pixbuf);
713 if (g_object_get_data(G_OBJECT(actor->widget), "image")){
714 gtk_container_remove(GTK_CONTAINER(actor->widget), g_object_get_data(G_OBJECT(actor->widget), "image"));
716 g_object_set_data(G_OBJECT(actor->widget), "image", image);
717 gtk_container_add (GTK_CONTAINER (actor->widget), image);
718 realize(actor->widget);
719 gtk_widget_show_all(actor->widget);
730 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
733 newfile = g_strdup_printf("%s%d.png", actor->name, scene.daytime);
735 g_free(actor->filename);
736 actor->filename = newfile;
737 change_hildon_actor(actor, desktop_plugin);
741 change_static_actor_with_corner(Actor * actor, AWallpaperPlugin *desktop_plugin)
746 if (desktop_plugin->priv->right_corner)
747 gtk_widget_destroy(desktop_plugin->priv->right_corner);
748 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/town%i_right_corner.png", \
749 THEME_PATH, desktop_plugin->priv->theme, scene.daytime);
750 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
751 if (desktop_plugin->priv->right_corner){
752 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
753 gtk_widget_show (desktop_plugin->priv->right_corner);
755 change_static_actor(actor, desktop_plugin);
763 // уравнение изменения времени
769 GSList * tmp = scene.actors;
775 g_free(actor->filename);
778 gtk_widget_destroy(actor->widget);
779 //actor->widget = NULL;
782 tmp = g_slist_next(tmp);
789 reload_scene(AWallpaperPlugin *desktop_plugin)
791 fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);
793 if (!strcmp(desktop_plugin->priv->theme,"Modern"))
794 init_scene(desktop_plugin);
795 else if (!strcmp(desktop_plugin->priv->theme,"Berlin"))
796 init_scene1(desktop_plugin);
800 /* Init Modern Scene */
802 init_scene(AWallpaperPlugin *desktop_plugin)
805 gint now = time(NULL);
809 /* fprintf(stderr, "init scene \n");*/
810 scene.daytime = get_daytime(hour, min);
812 scene.wind_orientation = -1;
813 scene.wind_angle = 0.3;
814 /* init value for random */
815 scene.seed = time(NULL);
819 actor = init_object(desktop_plugin, "sky", "sky0.png", 0, 0, 5, 800, 480,
820 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
821 change_static_actor(actor, desktop_plugin);
822 scene.actors = g_slist_append(scene.actors, actor);
824 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
825 TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
826 actor->time_start_animation = now;
827 actor->duration_animation = G_MAXINT;
828 change_sun(actor, desktop_plugin);
829 scene.actors = g_slist_append(scene.actors, actor);
831 //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
832 // TRUE, 100, 255, NULL, NULL);
833 //scene.actors = g_slist_append(scene.actors, actor);
835 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, 0, 7, 150, 97,
836 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
837 actor->time_start_animation = now;
838 actor->duration_animation = 1*60;
839 scene.actors = g_slist_append(scene.actors, actor);
841 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, 80, 7, 188, 75,
842 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
843 actor->time_start_animation = now + 20;
844 actor->duration_animation = 1*60;
845 scene.actors = g_slist_append(scene.actors, actor);
847 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, 30, 7, 150, 75,
848 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
849 actor->time_start_animation = now + 40;
850 actor->duration_animation = 1*60;
851 scene.actors = g_slist_append(scene.actors, actor);
854 actor = init_object(desktop_plugin, "town", "town0.png", 0, 0, 8, 800, 480,
855 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
856 change_static_actor(actor, desktop_plugin);
857 scene.actors = g_slist_append(scene.actors, actor);
859 actor = init_object(desktop_plugin, "tram", "tram.png", -300, 225, 9, 350, 210,
860 FALSE, 100, 255, (gpointer)&change_tram, NULL);
861 actor->time_start_animation = now;
862 actor->duration_animation = 40;
863 scene.actors = g_slist_append(scene.actors, actor);
865 actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 10, 800, 79,
866 TRUE, 100, 255, (gpointer)&change_static_actor_with_corner, NULL);
867 change_static_actor_with_corner(actor, desktop_plugin);
868 scene.actors = g_slist_append(scene.actors, actor);
870 actor = init_object(desktop_plugin, "moon", "moon5.png", 400, 20, 6, 60, 60,
871 FALSE, 100, 255, (gpointer)&change_moon, NULL);
872 change_moon(actor, desktop_plugin);
873 scene.actors = g_slist_append(scene.actors, actor);
875 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
876 FALSE, 100, 255, (gpointer)&change_wind, NULL);
877 change_wind(actor, desktop_plugin);
878 scene.actors = g_slist_append(scene.actors, actor);
880 /* windows in 4-th house */
920 for (i=0; i<13; i++){
921 actor = init_object(desktop_plugin, "window1", "window1.png",
922 winds[i][0], winds[i][1], 8, 8, 10,
923 FALSE, 100, 255, (gpointer)&change_window1, NULL);
924 //change_window1(actor, desktop_plugin);
925 actor->time_start_animation = now + fast_rnd(30);
926 scene.actors = g_slist_append(scene.actors, actor);
930 /* windows in 1-th house */
956 actor = init_object(desktop_plugin, "window2", "window2.png",
957 winds[i][0], winds[i][1], 8, 8, 10,
958 FALSE, 100, 255, (gpointer)&change_window1, NULL);
959 //change_window1(actor, desktop_plugin);
960 actor->time_start_animation = now + fast_rnd(30);
961 scene.actors = g_slist_append(scene.actors, actor);
965 /* windows in 3-th house */
997 for (i=0; i<10; i++){
998 actor = init_object(desktop_plugin, "window3", "window3.png",
999 winds[i][0], winds[i][1], 8, 8, 10,
1000 FALSE, 100, 255, (gpointer)&change_window1, NULL);
1001 //change_window1(actor, desktop_plugin);
1002 actor->time_start_animation = now + fast_rnd(30);
1003 scene.actors = g_slist_append(scene.actors, actor);
1007 /* windows in 5-th house */
1030 for (i=0; i<7; i++){
1031 actor = init_object(desktop_plugin, "window4", "window4.png",
1032 winds[i][0], winds[i][1], 8, 8, 10,
1033 FALSE, 100, 255, (gpointer)&change_window1, NULL);
1034 //change_window1(actor, desktop_plugin);
1035 actor->time_start_animation = now + fast_rnd(30);
1036 scene.actors = g_slist_append(scene.actors, actor);
1040 /* windows in 6-th house */
1060 for (i=0; i<6; i++){
1061 actor = init_object(desktop_plugin, "window5", "window5.png",
1062 winds[i][0], winds[i][1], 8, 8, 10,
1063 FALSE, 100, 255, (gpointer)&change_window1, NULL);
1064 //change_window1(actor, desktop_plugin);
1065 actor->time_start_animation = now + fast_rnd(30);
1066 scene.actors = g_slist_append(scene.actors, actor);
1070 run_long_timeout(desktop_plugin);
1072 anim = g_new0(Animation, 1);
1074 anim->actor = actor;
1075 anim->func_change = &change_tram;
1076 anim->func_time = NULL;
1077 anim->timestart = time(NULL);
1080 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
1084 /* Init Berlin Scene */
1086 init_scene1(AWallpaperPlugin *desktop_plugin)
1089 gint now = time(NULL);
1093 scene.daytime = get_daytime(hour, min);
1094 scene.actors = NULL;
1095 scene.wind_orientation = 1;
1096 scene.wind_angle = 0.3;
1097 /* init value for random */
1098 scene.seed = time(NULL);
1101 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
1102 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
1103 change_static_actor(actor, desktop_plugin);
1104 scene.actors = g_slist_append(scene.actors, actor);
1107 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
1108 TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
1109 actor->time_start_animation = time(NULL);
1110 actor->duration_animation = G_MAXINT;
1111 change_sun(actor, desktop_plugin);
1112 scene.actors = g_slist_append(scene.actors, actor);
1115 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
1116 TRUE, 100, 255, NULL, NULL);
1117 scene.actors = g_slist_append(scene.actors, actor);
1120 actor = init_object(desktop_plugin, "moon", "moon4.png", 400, 15, 6, 60, 60,
1121 FALSE, 100, 255, (gpointer)&change_moon, NULL);
1122 change_moon(actor, desktop_plugin);
1123 scene.actors = g_slist_append(scene.actors, actor);
1125 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, 300, 7, 150, 97,
1126 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
1127 actor->time_start_animation = now + 20;
1128 actor->duration_animation = 1*60;
1129 scene.actors = g_slist_append(scene.actors, actor);
1131 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, 100, 7, 188, 75,
1132 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
1133 actor->time_start_animation = now;
1134 actor->duration_animation = 1*60;
1135 scene.actors = g_slist_append(scene.actors, actor);
1137 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, 200, 7, 150, 75,
1138 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
1139 actor->time_start_animation = now + 40;
1140 actor->duration_animation = 1*60;
1141 scene.actors = g_slist_append(scene.actors, actor);
1144 actor = init_object(desktop_plugin, "plane3", "plane3.png", 0, 45, 8, 160, 50,
1145 FALSE, 100, 255, (gpointer)&change_plane2, NULL);
1146 actor->time_start_animation = now + 20;
1147 actor->duration_animation = 40;
1148 scene.actors = g_slist_append(scene.actors, actor);
1150 actor = init_object(desktop_plugin, "tu154", "tu154.png", 620, 233, 9, 300, 116,
1151 FALSE, 100, 255, (gpointer)&change_plane1, NULL);
1152 actor->time_start_animation = now;
1153 actor->duration_animation = 20;
1154 scene.actors = g_slist_append(scene.actors, actor);
1156 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
1157 TRUE, 100, 255, (gpointer)&change_static_actor_with_corner, NULL);
1158 change_static_actor_with_corner(actor, desktop_plugin);
1159 scene.actors = g_slist_append(scene.actors, actor);
1161 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
1162 FALSE, 100, 255, (gpointer)&change_wind, NULL);
1163 change_wind(actor, desktop_plugin);
1164 scene.actors = g_slist_append(scene.actors, actor);
1166 actor = init_object(desktop_plugin, "signal", "red.png", 486, 425, 10, 18, 38,
1167 TRUE, 100, 255, (gpointer)&change_signal, NULL);
1168 actor->time_start_animation = now;
1169 scene.actors = g_slist_append(scene.actors, actor);winds[0][0] = 717;
1210 for (i=0; i<13; i++){
1211 actor = init_object(desktop_plugin, "window", "window.png",
1212 winds[i][0], winds[i][1], 10, 8, 9,
1213 FALSE, 100, 255, (gpointer)&change_window1, NULL);
1214 //change_window1(actor, desktop_plugin);
1215 actor->time_start_animation = now + fast_rnd(30);
1216 scene.actors = g_slist_append(scene.actors, actor);
1220 run_long_timeout(desktop_plugin);
1226 get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
1228 gint y0 = 365;// - уровень горизонта
1229 *x = (int)(azm * 800) - 64;
1230 *y = (int)((1 - alt) * y0) - 64;
1231 //fprintf(stderr, "sun pos alt=%f azm=%f x=%d y=%d\n", alt, azm, *x, *y);
1235 change_actor(GtkWidget * actor)
1238 gint x, y, daytime, scale;
1245 void (*pfunc)(gpointer, gpointer);
1247 name = g_object_get_data(G_OBJECT(actor), "name");
1248 fprintf(stderr, "change actor %s\n", name);
1250 pfunc = g_object_get_data(G_OBJECT(actor), "func");
1252 (*pfunc)(actor, g_strdup(name));
1253 daytime = get_daytime();
1254 if (daytime != TIME_NIGHT){
1255 hildon_animation_actor_set_show(actor, 1);
1256 get_sun_pos(&alt, &azm);
1257 get_sun_screen_pos(alt, azm, &x, &y);
1258 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
1262 if (name == "cloud1"){
1263 x = g_object_get_data(G_OBJECT(actor), "x");
1264 y = g_object_get_data(G_OBJECT(actor), "y");
1265 scale = g_object_get_data(G_OBJECT(actor), "scale");
1268 image = g_object_get_data(G_OBJECT(actor), "image");
1270 gtk_container_remove(actor, image);
1271 pixbuf = gdk_pixbuf_new_from_file_at_size ("/usr/share/livewp/theme/Modern/sun.png",
1276 image = gtk_image_new_from_pixbuf (pixbuf);
1277 g_object_unref(G_OBJECT(pixbuf));
1279 g_signal_connect(G_OBJECT(image), "expose_event",
1280 G_CALLBACK(expose_event), pixbuf);
1281 gtk_container_add (GTK_CONTAINER (actor), image);
1283 gtk_widget_show_all(actor);
1295 sc = (double)scale / 100;
1296 hildon_animation_actor_set_scale(actor, sc, sc);
1297 fprintf(stderr, "cloud x=%d y=%d scale=%f", x, y, sc);
1298 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
1299 g_object_set_data(G_OBJECT(actor), "x", x);
1300 g_object_set_data(G_OBJECT(actor), "y", y);
1301 g_object_set_data(G_OBJECT(actor), "scale", scale);
1307 short_timeout (AWallpaperPlugin *desktop_plugin)
1309 //gint daytime = get_daytime();
1311 void (*pfunc)(gpointer, gpointer);
1314 gboolean stop_flag = TRUE;
1320 if (hour == 23) hour = 0;
1322 if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
1323 desktop_plugin->priv->short_timer = 0;
1328 //scene.daytime = daytime;
1329 /* fprintf(stderr, "Short timer %d\n", now); */
1331 while (tmp != NULL){
1333 if (now >= actor->time_start_animation
1334 && actor->time_start_animation > 0
1335 /* && now - actor->time_start_animation <= actor->duration_animation*/){
1336 pfunc = actor->func_change;
1338 (*pfunc)(actor, desktop_plugin);
1342 tmp = g_slist_next(tmp);
1345 desktop_plugin->priv->short_timer = 0;
1348 return TRUE; /* keep running this event */
1352 run_long_timeout(AWallpaperPlugin *desktop_plugin){
1354 gint daytime = get_daytime(hour, min);
1356 void (*pfunc)(gpointer, gpointer);
1362 //if (hour == 24) hour = 0;
1363 fprintf(stderr, "---- %d:%d\n", hour, min);
1366 //fprintf(stderr, "timer daytime=%d\n", daytime);
1367 if (scene.daytime != daytime){
1368 scene.daytime = daytime;
1370 while (tmp != NULL){
1371 //change_actor(tmp->data);
1372 pfunc =((Actor*)tmp->data)->func_change;
1374 (*pfunc)(tmp->data, desktop_plugin);
1376 tmp = g_slist_next(tmp);
1381 //fprintf(stderr, "Now %d\n", now);
1383 while (tmp != NULL){
1385 if (now >= actor->time_start_animation
1386 && actor->time_start_animation > 0
1387 && desktop_plugin->priv->short_timer == 0){
1388 /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
1389 if (desktop_plugin->priv->rich_animation){
1390 actor->time_start_animation = now;
1391 desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
1394 (*actor->func_change)(actor, desktop_plugin);
1397 tmp = g_slist_next(tmp);
1403 long_timeout (AWallpaperPlugin *desktop_plugin)
1405 /* fprintf(stderr, "long_timeout %i\n", desktop_plugin->priv->long_timer); */
1406 if (desktop_plugin->priv->long_timer == 0 )
1408 if (!desktop_plugin->priv->visible){
1409 if(desktop_plugin->priv->short_timer != 0){
1410 g_source_remove(desktop_plugin->priv->short_timer);
1411 desktop_plugin->priv->short_timer = 0;
1413 desktop_plugin->priv->long_timer = 0;
1418 run_long_timeout(desktop_plugin);
1419 return TRUE; /* keep running this event */
1423 desktop_plugin_visible_notify (GObject *object,
1425 AWallpaperPlugin *desktop_plugin)
1428 g_object_get (object, "is-on-current-desktop", &visible, NULL);
1429 /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
1431 desktop_plugin->priv->visible = TRUE;
1432 if (desktop_plugin->priv->long_timer == 0 ){
1433 desktop_plugin->priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1434 run_long_timeout(desktop_plugin);
1437 desktop_plugin->priv->visible = FALSE;
1438 if (desktop_plugin->priv->long_timer != 0 ){
1439 g_source_remove(desktop_plugin->priv->long_timer);
1440 desktop_plugin->priv->long_timer = 0;
1446 rich_animation_press(GtkWidget *widget, GdkEvent *event,
1447 gpointer user_data){
1448 fprintf(stderr,"gggggggggggggggggggg2222\n");
1451 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
1453 GtkWidget *rich_animation;
1457 fprintf(stderr, "!!!!!!!plugin init \n");
1458 Animation_WallpaperPrivate *priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1459 desktop_plugin->priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1463 priv->desktop_plugin = desktop_plugin;
1464 desktop_plugin->priv->main_widget = gtk_fixed_new();
1466 gtk_widget_set_size_request(desktop_plugin->priv->main_widget, 100, 32);
1467 desktop_plugin->priv->right_corner = NULL;
1468 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/%s", THEME_PATH, desktop_plugin->priv->theme, "town0_right_corner.png");
1469 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
1470 if (desktop_plugin->priv->right_corner){
1471 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
1472 gtk_widget_show (desktop_plugin->priv->right_corner);
1474 /* Create rich animation event */
1475 rich_animation = gtk_event_box_new();
1477 gtk_widget_set_events(rich_animation, GDK_BUTTON_PRESS_MASK);
1478 gtk_event_box_set_visible_window(GTK_EVENT_BOX(rich_animation), FALSE);
1479 gtk_widget_set_size_request(rich_animation, 100, 32);
1480 gtk_widget_show (rich_animation);
1481 g_signal_connect(rich_animation, "button-press-event", G_CALLBACK(rich_animation_press), desktop_plugin);
1482 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), rich_animation, 0, 0);
1485 GtkWidget *label = gtk_label_new ("ddddddddddddd");
1486 gtk_widget_set_size_request(label, 95, 30);
1487 gtk_widget_show (label);
1488 // gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
1489 gtk_fixed_put(GTK_FIXED(widget), label, 0, 0);
1491 hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
1492 g_signal_connect (desktop_plugin, "show-settings",
1493 G_CALLBACK (lw_settings), priv);
1494 gtk_widget_show (desktop_plugin->priv->main_widget);
1495 gtk_container_add (GTK_CONTAINER (desktop_plugin), desktop_plugin->priv->main_widget);
1496 init_applet_position();
1499 fprintf(stderr, "!!!theme = %s\n", priv->theme);
1500 if (!strcmp(priv->theme,"Modern"))
1501 init_scene(desktop_plugin);
1502 else if (!strcmp(priv->theme,"Berlin"))
1503 init_scene1(desktop_plugin);
1504 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1505 priv->short_timer = 0;
1506 /* TODO Move scene to priv */
1507 scene.timer_type = LONG_TIMER_TYPE;
1508 g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
1509 G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
1516 lw_applet_finalize (GObject *object)
1518 AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
1519 Animation_WallpaperPrivate *priv = desktop_plugin->priv;
1521 fprintf(stderr,"finalaze %i\n", priv->long_timer);
1522 if (priv->long_timer){
1523 g_source_remove(priv->long_timer);
1524 priv->long_timer = 0;
1526 if (priv->short_timer){
1527 g_source_remove(priv->short_timer);
1528 priv->short_timer = 0;
1535 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
1537 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1538 GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
1541 gobject_class->destroy = (gpointer)lw_applet_finalize;
1542 widget_class->realize = lw_applet_realize;
1543 widget_class->expose_event = lw_applet_expose_event;
1545 g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));
1550 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {