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)
266 if (scene.daytime == TIME_NIGHT){
267 if (!actor->visible){
268 actor->visible = TRUE;
269 phase = get_moon_phase();
270 newfile = g_strdup_printf( "%s%d.png", actor->name, phase);
272 g_free(actor->filename);
273 actor->filename = newfile;
274 create_hildon_actor(actor, desktop_plugin);
279 // actor_set_position_full(actor->widget, x, y, actor->z);
280 //probability_sun(actor);
281 //fprintf(stderr, "after change sun %d\n", actor->time_start_animation);
282 }else if (actor->visible){
283 actor->visible = FALSE;
284 fprintf(stderr, "destroy moon \n");
285 destroy_hildon_actor(actor);
286 /* TO DO make moonrise*/
287 actor->time_start_animation = 0;
294 change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
299 //fprintf(stderr, "change sun\n");
301 if (scene.daytime != TIME_NIGHT){
302 if (!actor->visible){
303 actor->visible = TRUE;
304 create_hildon_actor(actor, desktop_plugin);
306 get_sun_pos(hour, min, &alt, &azm);
307 get_sun_screen_pos(alt, azm, &x, &y);
310 actor_set_position_full(actor->widget, x, y, actor->z);
311 //probability_sun(actor);
312 actor->time_start_animation = time(NULL);
313 }else if (actor->visible){
314 actor->visible = FALSE;
315 destroy_hildon_actor(actor);
316 actor->time_start_animation = 0;
323 change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
325 gint x0 = -300, y0 = 225, scale0 = 100,
326 x1 = 800, y1 = 162, scale1 = 130,
334 //fprintf(stderr, "change tram\n");
335 gettimeofday(&tvb, NULL);
340 if (!actor->visible){
341 actor->visible = TRUE;
342 if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
344 g_free(actor->filename);
345 actor->filename = g_strdup("tram_dark.png");
348 g_free(actor->filename);
349 actor->filename = g_strdup("tram.png");
351 create_hildon_actor(actor, desktop_plugin);
353 if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
354 newfile = g_strdup("tram_dark.png");
356 newfile = g_strdup("tram.png");
358 if (strcmp(actor->filename, newfile)){
360 g_free(actor->filename);
361 actor->filename = newfile;
364 change_hildon_actor(actor, desktop_plugin);
367 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
368 x = path_line(x0, x1, t);
369 y = path_line(y0, y1, t);
370 scale = path_line(scale0, scale1, t);
371 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
372 actor_set_position_full(actor->widget, x, y, actor->z);
373 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
376 actor->visible = FALSE;
377 destroy_hildon_actor(actor);
378 actor->time_start_animation = sec + 20;
383 change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
385 gint x0 = 620, y0 = 233, scale0 = 100,
386 x1 = 79, y1 = -146, scale1 = 100,
394 gettimeofday(&tvb, NULL);
398 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
400 if (scene.daytime != TIME_NIGHT){
401 if (actor->time_start_animation == 0){
402 actor->time_start_animation = sec + probability_plane();
406 if (!actor->visible){
407 actor->visible = TRUE;
408 create_hildon_actor(actor, desktop_plugin);
410 if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
411 newfile = g_strdup("dot1.png");
413 newfile = g_strdup("tu154.png");
415 if (strcmp(actor->filename, newfile)){
417 g_free(actor->filename);
418 actor->filename = newfile;
421 change_hildon_actor(actor, desktop_plugin);
424 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
425 x = path_line(x0, x1, t);
426 y = path_line(y0, y1, t);
427 //scale line(scale0, scale1, t);
428 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
429 actor_set_position_full(actor->widget, x, y, actor->z);
430 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
433 actor->visible = FALSE;
434 destroy_hildon_actor(actor);
435 if (scene.daytime == TIME_NIGHT)
436 actor->time_start_animation = 0;
438 actor->time_start_animation = sec + 10;
444 change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
446 gint x0 = -actor->width, y0 = 45, scale0 = 100,
447 x1 = 800, y1 = 20, scale1 = 100,
455 gettimeofday(&tvb, NULL);
459 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
460 if (scene.daytime != TIME_NIGHT){
461 if (actor->time_start_animation == 0){
462 actor->time_start_animation = sec + probability_plane();
466 if (!actor->visible){
467 actor->visible = TRUE;
468 create_hildon_actor(actor, desktop_plugin);
470 if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
471 newfile = g_strdup("dot1.png");
473 newfile = g_strdup("plane3.png");
475 if (strcmp(actor->filename, newfile)){
477 g_free(actor->filename);
478 actor->filename = newfile;
481 change_hildon_actor(actor, desktop_plugin);
484 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
485 x = path_line(x0, x1, t);
486 y = path_line(y0, y1, t);
487 //scale = path_line(scale0, scale1, t);
488 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
489 actor_set_position_full(actor->widget, x, y, actor->z);
490 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
493 actor->visible = FALSE;
494 destroy_hildon_actor(actor);
495 if (scene.daytime == TIME_NIGHT)
496 actor->time_start_animation = 0;
498 actor->time_start_animation = sec + 15;
504 change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
506 gint x0, y0 = 300, scale0 = 100,
507 x1, y1 = -actor->height, scale1 = 150,
515 //fprintf(stderr, "change cloud\n");
516 gettimeofday(&tvb, NULL);
520 //fprintf(stderr, "c1oud %s - y0=%d\n", actor->name, actor->y);
522 if (!actor->visible){
523 actor->visible = TRUE;
524 if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
525 newfile = g_strdup_printf("%s_dark.png", actor->name);
527 newfile = g_strdup_printf("%s.png", actor->name);
530 g_free(actor->filename);
531 actor->filename = newfile;
534 create_hildon_actor(actor, desktop_plugin);
536 if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
537 newfile = g_strdup_printf("%s_dark.png", actor->name);
539 newfile = g_strdup_printf("%s.png", actor->name);
541 if (strcmp(actor->filename, newfile)){
543 g_free(actor->filename);
544 actor->filename = newfile;
547 change_hildon_actor(actor, desktop_plugin);
550 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
552 if (scene.wind_orientation == 1){
561 x = path_line(x0, x1, t);
562 y = -scene.wind_angle * (x - x0) + actor->y;
563 scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
565 //fprintf(stderr, "change cloud t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
566 actor_set_position_full(actor->widget, x, y, actor->z);
567 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
568 if ((y < y1 || y > y0) || t >= 1){
570 actor->visible = FALSE;
571 destroy_hildon_actor(actor);
572 actor->time_start_animation = sec + 10;
573 actor->y = fast_rnd(300);
579 change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
581 scene.wind_orientation = fast_rnd(2);
582 if (scene.wind_orientation == 0) scene.wind_orientation = -1;
583 scene.wind_angle = (double)(fast_rnd(200) - 100) / 100;
584 actor->time_start_animation = time(NULL) + (fast_rnd(10) + 10) * 60;
585 //fprintf(stderr, "change wind orient = %d angle = %f after = %d\n", scene.wind_orientation, scene.wind_angle, actor->time_start_animation-time(NULL));
589 change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin)
592 gint now = time(NULL);
593 if (scene.daytime == TIME_DAY){
595 actor->visible = FALSE;
596 destroy_hildon_actor(actor);
598 actor->time_start_animation = 0;
600 }else if (actor->time_start_animation == 0){
601 actor->time_start_animation = now + fast_rnd(30);
605 if (!actor->visible){
606 actor->visible = TRUE;
607 create_hildon_actor(actor, desktop_plugin);
608 actor->time_start_animation = now + 10;
610 actor->visible = FALSE;
611 destroy_hildon_actor(actor);
612 actor->time_start_animation = now + 10;
618 change_signal(Actor * actor, AWallpaperPlugin *desktop_plugin)
621 gint now = time(NULL);
622 newfile = g_strdup_printf("%s%d.png", actor->name, scene.daytime);
623 if (!strcmp(actor->filename, "red.png"))
624 newfile = g_strdup_printf("%s", "green.png");
626 newfile = g_strdup_printf("%s", "red.png");
627 g_free(actor->filename);
628 actor->filename = newfile;
629 change_hildon_actor(actor, desktop_plugin);
630 actor->time_start_animation = now + 5;
634 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
636 GtkWidget *ha = NULL;
637 GdkPixbuf *pixbuf = NULL;
638 GtkWidget *image = NULL;
641 /* fprintf(stderr, "create_hildon_actor %s\n", actor->name);*/
642 ha = hildon_animation_actor_new();
643 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
644 desktop_plugin->priv->theme, actor->filename);
645 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
652 image = gtk_image_new_from_pixbuf (pixbuf);
653 g_object_unref(G_OBJECT(pixbuf));
656 g_signal_connect(G_OBJECT(image), "expose_event",
657 G_CALLBACK(expose_event), pixbuf);
658 gtk_container_add (GTK_CONTAINER (ha), image);
660 actor_set_position_full(ha, actor->x, actor->y, actor->z);
661 hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(ha), actor->visible);
662 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(ha), (double)actor->scale/100, (double)actor->scale/100);
664 gtk_widget_show_all(ha);
669 //g_object_set_data(G_OBJECT(ha), "name", name);
670 //g_object_set_data(G_OBJECT(ha), "filename", filename);
671 g_object_set_data(G_OBJECT(ha), "image", image);
673 g_object_set_data(G_OBJECT(ha), "x", x);
674 g_object_set_data(G_OBJECT(ha), "y", y);
675 g_object_set_data(G_OBJECT(ha), "z", z);
676 g_object_set_data(G_OBJECT(ha), "width", width);
677 g_object_set_data(G_OBJECT(ha), "height", height);
678 g_object_set_data(G_OBJECT(ha), "scale", scale);
679 g_object_set_data(G_OBJECT(ha), "visible", visible);
680 g_object_set_data(G_OBJECT(ha), "opacity", opacity);
681 g_object_set_data(G_OBJECT(ha), "func", pfunc);
683 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
689 change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
691 GtkWidget *image = NULL;
692 GdkPixbuf *pixbuf = NULL;
695 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
696 desktop_plugin->priv->theme, actor->filename);
698 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
705 image = gtk_image_new_from_pixbuf (pixbuf);
706 g_object_unref(G_OBJECT(pixbuf));
709 g_signal_connect(G_OBJECT(image), "expose_event",
710 G_CALLBACK(expose_event), pixbuf);
711 if (g_object_get_data(G_OBJECT(actor->widget), "image")){
712 gtk_container_remove(GTK_CONTAINER(actor->widget), g_object_get_data(G_OBJECT(actor->widget), "image"));
714 g_object_set_data(G_OBJECT(actor->widget), "image", image);
715 gtk_container_add (GTK_CONTAINER (actor->widget), image);
716 realize(actor->widget);
717 gtk_widget_show_all(actor->widget);
728 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
731 newfile = g_strdup_printf("%s%d.png", actor->name, scene.daytime);
733 g_free(actor->filename);
734 actor->filename = newfile;
735 change_hildon_actor(actor, desktop_plugin);
739 change_static_actor_with_corner(Actor * actor, AWallpaperPlugin *desktop_plugin)
744 if (desktop_plugin->priv->right_corner)
745 gtk_widget_destroy(desktop_plugin->priv->right_corner);
746 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/town%i_right_corner.png", \
747 THEME_PATH, desktop_plugin->priv->theme, scene.daytime);
748 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
749 if (desktop_plugin->priv->right_corner){
750 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
751 gtk_widget_show (desktop_plugin->priv->right_corner);
753 change_static_actor(actor, desktop_plugin);
761 // уравнение изменения времени
767 GSList * tmp = scene.actors;
773 g_free(actor->filename);
776 gtk_widget_destroy(actor->widget);
777 //actor->widget = NULL;
780 tmp = g_slist_next(tmp);
787 reload_scene(AWallpaperPlugin *desktop_plugin)
789 fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);
791 if (!strcmp(desktop_plugin->priv->theme,"Modern"))
792 init_scene(desktop_plugin);
793 else if (!strcmp(desktop_plugin->priv->theme,"Berlin"))
794 init_scene1(desktop_plugin);
798 /* Init Modern Scene */
800 init_scene(AWallpaperPlugin *desktop_plugin)
803 gint now = time(NULL);
807 /* fprintf(stderr, "init scene \n");*/
808 scene.daytime = get_daytime(hour, min);
810 scene.wind_orientation = -1;
811 scene.wind_angle = 0.3;
812 /* init value for random */
813 scene.seed = time(NULL);
817 actor = init_object(desktop_plugin, "sky", "sky0.png", 0, 0, 5, 800, 480,
818 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
819 change_static_actor(actor, desktop_plugin);
820 scene.actors = g_slist_append(scene.actors, actor);
822 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
823 TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
824 actor->time_start_animation = now;
825 actor->duration_animation = G_MAXINT;
826 change_sun(actor, desktop_plugin);
827 scene.actors = g_slist_append(scene.actors, actor);
829 //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
830 // TRUE, 100, 255, NULL, NULL);
831 //scene.actors = g_slist_append(scene.actors, actor);
833 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, 0, 7, 150, 97,
834 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
835 actor->time_start_animation = now;
836 actor->duration_animation = 1*60;
837 scene.actors = g_slist_append(scene.actors, actor);
839 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, 80, 7, 188, 75,
840 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
841 actor->time_start_animation = now + 20;
842 actor->duration_animation = 1*60;
843 scene.actors = g_slist_append(scene.actors, actor);
845 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, 30, 7, 150, 75,
846 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
847 actor->time_start_animation = now + 40;
848 actor->duration_animation = 1*60;
849 scene.actors = g_slist_append(scene.actors, actor);
852 actor = init_object(desktop_plugin, "town", "town0.png", 0, 0, 8, 800, 480,
853 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
854 change_static_actor(actor, desktop_plugin);
855 scene.actors = g_slist_append(scene.actors, actor);
857 actor = init_object(desktop_plugin, "tram", "tram.png", -300, 225, 9, 350, 210,
858 FALSE, 100, 255, (gpointer)&change_tram, NULL);
859 actor->time_start_animation = now;
860 actor->duration_animation = 40;
861 scene.actors = g_slist_append(scene.actors, actor);
863 actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 10, 800, 79,
864 TRUE, 100, 255, (gpointer)&change_static_actor_with_corner, NULL);
865 change_static_actor_with_corner(actor, desktop_plugin);
866 scene.actors = g_slist_append(scene.actors, actor);
868 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 20, 6, 60, 60,
869 FALSE, 100, 255, (gpointer)&change_moon, NULL);
870 change_moon(actor, desktop_plugin);
871 scene.actors = g_slist_append(scene.actors, actor);
873 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
874 FALSE, 100, 255, (gpointer)&change_wind, NULL);
875 change_wind(actor, desktop_plugin);
876 scene.actors = g_slist_append(scene.actors, actor);
878 /* windows in 4-th house */
918 for (i=0; i<13; i++){
919 actor = init_object(desktop_plugin, "window1", "window1.png",
920 winds[i][0], winds[i][1], 8, 8, 10,
921 FALSE, 100, 255, (gpointer)&change_window1, NULL);
922 //change_window1(actor, desktop_plugin);
923 actor->time_start_animation = now + fast_rnd(30);
924 scene.actors = g_slist_append(scene.actors, actor);
928 /* windows in 1-th house */
954 actor = init_object(desktop_plugin, "window2", "window2.png",
955 winds[i][0], winds[i][1], 8, 8, 10,
956 FALSE, 100, 255, (gpointer)&change_window1, NULL);
957 //change_window1(actor, desktop_plugin);
958 actor->time_start_animation = now + fast_rnd(30);
959 scene.actors = g_slist_append(scene.actors, actor);
963 /* windows in 3-th house */
995 for (i=0; i<10; i++){
996 actor = init_object(desktop_plugin, "window3", "window3.png",
997 winds[i][0], winds[i][1], 8, 8, 10,
998 FALSE, 100, 255, (gpointer)&change_window1, NULL);
999 //change_window1(actor, desktop_plugin);
1000 actor->time_start_animation = now + fast_rnd(30);
1001 scene.actors = g_slist_append(scene.actors, actor);
1005 /* windows in 5-th house */
1028 for (i=0; i<7; i++){
1029 actor = init_object(desktop_plugin, "window4", "window4.png",
1030 winds[i][0], winds[i][1], 8, 8, 10,
1031 FALSE, 100, 255, (gpointer)&change_window1, NULL);
1032 //change_window1(actor, desktop_plugin);
1033 actor->time_start_animation = now + fast_rnd(30);
1034 scene.actors = g_slist_append(scene.actors, actor);
1038 /* windows in 6-th house */
1058 for (i=0; i<6; i++){
1059 actor = init_object(desktop_plugin, "window5", "window5.png",
1060 winds[i][0], winds[i][1], 8, 8, 10,
1061 FALSE, 100, 255, (gpointer)&change_window1, NULL);
1062 //change_window1(actor, desktop_plugin);
1063 actor->time_start_animation = now + fast_rnd(30);
1064 scene.actors = g_slist_append(scene.actors, actor);
1068 run_long_timeout(desktop_plugin);
1070 anim = g_new0(Animation, 1);
1072 anim->actor = actor;
1073 anim->func_change = &change_tram;
1074 anim->func_time = NULL;
1075 anim->timestart = time(NULL);
1078 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
1082 /* Init Berlin Scene */
1084 init_scene1(AWallpaperPlugin *desktop_plugin)
1087 gint now = time(NULL);
1091 scene.daytime = get_daytime(hour, min);
1092 scene.actors = NULL;
1093 scene.wind_orientation = 1;
1094 scene.wind_angle = 0.3;
1095 /* init value for random */
1096 scene.seed = time(NULL);
1099 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
1100 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
1101 change_static_actor(actor, desktop_plugin);
1102 scene.actors = g_slist_append(scene.actors, actor);
1105 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
1106 TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
1107 actor->time_start_animation = time(NULL);
1108 actor->duration_animation = G_MAXINT;
1109 change_sun(actor, desktop_plugin);
1110 scene.actors = g_slist_append(scene.actors, actor);
1113 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
1114 TRUE, 100, 255, NULL, NULL);
1115 scene.actors = g_slist_append(scene.actors, actor);
1118 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
1119 FALSE, 100, 255, (gpointer)&change_moon, NULL);
1120 change_moon(actor, desktop_plugin);
1121 scene.actors = g_slist_append(scene.actors, actor);
1123 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, 300, 7, 150, 97,
1124 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
1125 actor->time_start_animation = now + 20;
1126 actor->duration_animation = 1*60;
1127 scene.actors = g_slist_append(scene.actors, actor);
1129 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, 100, 7, 188, 75,
1130 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
1131 actor->time_start_animation = now;
1132 actor->duration_animation = 1*60;
1133 scene.actors = g_slist_append(scene.actors, actor);
1135 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, 200, 7, 150, 75,
1136 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
1137 actor->time_start_animation = now + 40;
1138 actor->duration_animation = 1*60;
1139 scene.actors = g_slist_append(scene.actors, actor);
1142 actor = init_object(desktop_plugin, "plane3", "plane3.png", 0, 45, 8, 160, 50,
1143 FALSE, 100, 255, (gpointer)&change_plane2, NULL);
1144 actor->time_start_animation = now + 20;
1145 actor->duration_animation = 40;
1146 scene.actors = g_slist_append(scene.actors, actor);
1148 actor = init_object(desktop_plugin, "tu154", "tu154.png", 620, 233, 9, 300, 116,
1149 FALSE, 100, 255, (gpointer)&change_plane1, NULL);
1150 actor->time_start_animation = now;
1151 actor->duration_animation = 20;
1152 scene.actors = g_slist_append(scene.actors, actor);
1154 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
1155 TRUE, 100, 255, (gpointer)&change_static_actor_with_corner, NULL);
1156 change_static_actor_with_corner(actor, desktop_plugin);
1157 scene.actors = g_slist_append(scene.actors, actor);
1159 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
1160 FALSE, 100, 255, (gpointer)&change_wind, NULL);
1161 change_wind(actor, desktop_plugin);
1162 scene.actors = g_slist_append(scene.actors, actor);
1164 actor = init_object(desktop_plugin, "signal", "red.png", 486, 425, 10, 18, 38,
1165 TRUE, 100, 255, (gpointer)&change_signal, NULL);
1166 actor->time_start_animation = now;
1167 scene.actors = g_slist_append(scene.actors, actor);winds[0][0] = 717;
1208 for (i=0; i<13; i++){
1209 actor = init_object(desktop_plugin, "window", "window.png",
1210 winds[i][0], winds[i][1], 10, 8, 9,
1211 FALSE, 100, 255, (gpointer)&change_window1, NULL);
1212 //change_window1(actor, desktop_plugin);
1213 actor->time_start_animation = now + fast_rnd(30);
1214 scene.actors = g_slist_append(scene.actors, actor);
1218 run_long_timeout(desktop_plugin);
1224 get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
1226 gint y0 = 365;// - уровень горизонта
1227 *x = (int)(azm * 800) - 64;
1228 *y = (int)((1 - alt) * y0) - 64;
1229 //fprintf(stderr, "sun pos alt=%f azm=%f x=%d y=%d\n", alt, azm, *x, *y);
1233 change_actor(GtkWidget * actor)
1236 gint x, y, daytime, scale;
1243 void (*pfunc)(gpointer, gpointer);
1245 name = g_object_get_data(G_OBJECT(actor), "name");
1246 fprintf(stderr, "change actor %s\n", name);
1248 pfunc = g_object_get_data(G_OBJECT(actor), "func");
1250 (*pfunc)(actor, g_strdup(name));
1251 daytime = get_daytime();
1252 if (daytime != TIME_NIGHT){
1253 hildon_animation_actor_set_show(actor, 1);
1254 get_sun_pos(&alt, &azm);
1255 get_sun_screen_pos(alt, azm, &x, &y);
1256 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
1260 if (name == "cloud1"){
1261 x = g_object_get_data(G_OBJECT(actor), "x");
1262 y = g_object_get_data(G_OBJECT(actor), "y");
1263 scale = g_object_get_data(G_OBJECT(actor), "scale");
1266 image = g_object_get_data(G_OBJECT(actor), "image");
1268 gtk_container_remove(actor, image);
1269 pixbuf = gdk_pixbuf_new_from_file_at_size ("/usr/share/livewp/theme/Modern/sun.png",
1274 image = gtk_image_new_from_pixbuf (pixbuf);
1275 g_object_unref(G_OBJECT(pixbuf));
1277 g_signal_connect(G_OBJECT(image), "expose_event",
1278 G_CALLBACK(expose_event), pixbuf);
1279 gtk_container_add (GTK_CONTAINER (actor), image);
1281 gtk_widget_show_all(actor);
1293 sc = (double)scale / 100;
1294 hildon_animation_actor_set_scale(actor, sc, sc);
1295 fprintf(stderr, "cloud x=%d y=%d scale=%f", x, y, sc);
1296 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
1297 g_object_set_data(G_OBJECT(actor), "x", x);
1298 g_object_set_data(G_OBJECT(actor), "y", y);
1299 g_object_set_data(G_OBJECT(actor), "scale", scale);
1305 short_timeout (AWallpaperPlugin *desktop_plugin)
1307 //gint daytime = get_daytime();
1309 void (*pfunc)(gpointer, gpointer);
1312 gboolean stop_flag = TRUE;
1319 if (hour == 23) hour = 0;
1323 if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
1324 desktop_plugin->priv->short_timer = 0;
1329 //scene.daytime = daytime;
1330 /* fprintf(stderr, "Short timer %d\n", now); */
1332 while (tmp != NULL){
1334 if (now >= actor->time_start_animation
1335 && actor->time_start_animation > 0
1336 /* && now - actor->time_start_animation <= actor->duration_animation*/){
1337 pfunc = actor->func_change;
1339 (*pfunc)(actor, desktop_plugin);
1343 tmp = g_slist_next(tmp);
1346 desktop_plugin->priv->short_timer = 0;
1349 return TRUE; /* keep running this event */
1353 run_long_timeout(AWallpaperPlugin *desktop_plugin){
1355 gint daytime = get_daytime(hour, min);
1357 void (*pfunc)(gpointer, gpointer);
1363 //if (hour == 24) hour = 0;
1364 fprintf(stderr, "---- %d:%d\n", hour, min);
1367 //fprintf(stderr, "timer daytime=%d\n", daytime);
1368 if (scene.daytime != daytime){
1369 scene.daytime = daytime;
1371 while (tmp != NULL){
1372 //change_actor(tmp->data);
1373 pfunc =((Actor*)tmp->data)->func_change;
1375 (*pfunc)(tmp->data, desktop_plugin);
1377 tmp = g_slist_next(tmp);
1382 //fprintf(stderr, "Now %d\n", now);
1384 while (tmp != NULL){
1386 if (now >= actor->time_start_animation
1387 && actor->time_start_animation > 0
1388 && desktop_plugin->priv->short_timer == 0){
1389 /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
1390 if (desktop_plugin->priv->rich_animation){
1391 actor->time_start_animation = now;
1392 desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
1395 (*actor->func_change)(actor, desktop_plugin);
1398 tmp = g_slist_next(tmp);
1404 long_timeout (AWallpaperPlugin *desktop_plugin)
1406 /* fprintf(stderr, "long_timeout %i\n", desktop_plugin->priv->long_timer); */
1407 if (desktop_plugin->priv->long_timer == 0 )
1409 if (!desktop_plugin->priv->visible){
1410 if(desktop_plugin->priv->short_timer != 0){
1411 g_source_remove(desktop_plugin->priv->short_timer);
1412 desktop_plugin->priv->short_timer = 0;
1414 desktop_plugin->priv->long_timer = 0;
1419 run_long_timeout(desktop_plugin);
1420 return TRUE; /* keep running this event */
1424 desktop_plugin_visible_notify (GObject *object,
1426 AWallpaperPlugin *desktop_plugin)
1429 g_object_get (object, "is-on-current-desktop", &visible, NULL);
1430 /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
1432 desktop_plugin->priv->visible = TRUE;
1433 if (desktop_plugin->priv->long_timer == 0 ){
1434 desktop_plugin->priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1435 run_long_timeout(desktop_plugin);
1438 desktop_plugin->priv->visible = FALSE;
1439 if (desktop_plugin->priv->long_timer != 0 ){
1440 g_source_remove(desktop_plugin->priv->long_timer);
1441 desktop_plugin->priv->long_timer = 0;
1447 rich_animation_press(GtkWidget *widget, GdkEvent *event,
1448 gpointer user_data){
1449 fprintf(stderr,"gggggggggggggggggggg2222\n");
1452 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
1454 GtkWidget *rich_animation;
1458 fprintf(stderr, "!!!!!!!plugin init \n");
1459 Animation_WallpaperPrivate *priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1460 desktop_plugin->priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1464 priv->desktop_plugin = desktop_plugin;
1465 desktop_plugin->priv->main_widget = gtk_fixed_new();
1467 gtk_widget_set_size_request(desktop_plugin->priv->main_widget, 100, 32);
1468 desktop_plugin->priv->right_corner = NULL;
1469 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/%s", THEME_PATH, desktop_plugin->priv->theme, "town0_right_corner.png");
1470 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
1471 if (desktop_plugin->priv->right_corner){
1472 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
1473 gtk_widget_show (desktop_plugin->priv->right_corner);
1475 /* Create rich animation event */
1476 rich_animation = gtk_event_box_new();
1478 gtk_widget_set_events(rich_animation, GDK_BUTTON_PRESS_MASK);
1479 gtk_event_box_set_visible_window(GTK_EVENT_BOX(rich_animation), FALSE);
1480 gtk_widget_set_size_request(rich_animation, 100, 32);
1481 gtk_widget_show (rich_animation);
1482 g_signal_connect(rich_animation, "button-press-event", G_CALLBACK(rich_animation_press), desktop_plugin);
1483 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), rich_animation, 0, 0);
1486 GtkWidget *label = gtk_label_new ("ddddddddddddd");
1487 gtk_widget_set_size_request(label, 95, 30);
1488 gtk_widget_show (label);
1489 // gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
1490 gtk_fixed_put(GTK_FIXED(widget), label, 0, 0);
1492 hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
1493 g_signal_connect (desktop_plugin, "show-settings",
1494 G_CALLBACK (lw_settings), priv);
1495 gtk_widget_show (desktop_plugin->priv->main_widget);
1496 gtk_container_add (GTK_CONTAINER (desktop_plugin), desktop_plugin->priv->main_widget);
1497 init_applet_position();
1500 fprintf(stderr, "!!!theme = %s\n", priv->theme);
1501 if (!strcmp(priv->theme,"Modern"))
1502 init_scene(desktop_plugin);
1503 else if (!strcmp(priv->theme,"Berlin"))
1504 init_scene1(desktop_plugin);
1505 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1506 priv->short_timer = 0;
1507 /* TODO Move scene to priv */
1508 scene.timer_type = LONG_TIMER_TYPE;
1509 g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
1510 G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
1517 lw_applet_finalize (GObject *object)
1519 AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
1520 Animation_WallpaperPrivate *priv = desktop_plugin->priv;
1522 fprintf(stderr,"finalaze %i\n", priv->long_timer);
1523 if (priv->long_timer){
1524 g_source_remove(priv->long_timer);
1525 priv->long_timer = 0;
1527 if (priv->short_timer){
1528 g_source_remove(priv->short_timer);
1529 priv->short_timer = 0;
1536 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
1538 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1539 GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
1542 gobject_class->destroy = (gpointer)lw_applet_finalize;
1543 widget_class->realize = lw_applet_realize;
1544 widget_class->expose_event = lw_applet_expose_event;
1546 g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));
1551 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {