nothing
[livewp] / applet / src / livewp-home-widget.c
index e05fb42..3cde353 100644 (file)
@@ -1,4 +1,4 @@
-/* vim: set sw=4 ts=4 et: */
+/*vim: set sw=4 ts=4 et: */
 /*
  * This file is part of Live Wallpaper (livewp)
  * 
  * 02110-1301 USA
 */
 /*******************************************************************************/
-#include "livewp-common.h"
+#include "livewp-common.h" 
 #include "livewp-home-widget.h"
 #include <gconf/gconf-client.h>
 #include "livewp-rules.h"
+#include <sys/time.h>
+#include <stdlib.h>
 
 #define PLUGIN_NAME "livewp-home-widget.desktop-0"
 #define GCONF_KEY_POSITION "/apps/osso/hildon-desktop/applets/%s/position"
@@ -39,11 +41,9 @@ HD_DEFINE_PLUGIN_MODULE (AWallpaperPlugin, animation_wallpaper_plugin, HD_TYPE_H
 
 /* Position of plugin on desktop */
 #define Xstartposition 700 
-#define Ystartposition 425 
+#define Ystartposition 448 
 
 gint xapplet = 0, yapplet = 0;
-GSList * objects_list = NULL;
-MultiActor * ma1;
 Scene scene;
 
 static void
@@ -91,11 +91,13 @@ expose_event (GtkWidget *widget,GdkEventExpose *event,
     GdkPixbuf *pixbuf = (GdkPixbuf *) data;
        
     cr = gdk_cairo_create(widget->window);
-    gdk_cairo_region(cr, event->region);
-    cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
-    gdk_cairo_set_source_pixbuf(cr, pixbuf, 0.0, 0.0);
-    cairo_paint(cr);
-    cairo_destroy(cr);
+    if (cr){
+        gdk_cairo_region(cr, event->region);
+        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+        gdk_cairo_set_source_pixbuf(cr, pixbuf, 0.0, 0.0);
+        cairo_paint(cr);
+        cairo_destroy(cr);
+    }
     return TRUE;
 }
 
@@ -138,7 +140,7 @@ init_applet_position(void)
        yapplet = Ystartposition;
   }
   g_free (position_key);
-  modified = g_strdup_printf ("%ld", 0);
+  modified = g_strdup_printf ("%i", 0);
   modified_key = g_strdup_printf (GCONF_KEY_MODIFIED, PLUGIN_NAME);
   gconf_client_set_string (gconf_client,
                            modified_key,
@@ -153,55 +155,63 @@ init_applet_position(void)
 void
 actor_set_position_full(GtkWidget *actor, gint x, gint y, gint z)
 {
-// fprintf(stderr, "actor_set_position_full\n");
- hildon_animation_actor_set_position_full (HILDON_ANIMATION_ACTOR (actor),x-xapplet, y-yapplet, z);
+/*  fprintf(stderr, "actor_set_position_full z=%d\n", z); */
+    hildon_animation_actor_set_position_full (HILDON_ANIMATION_ACTOR (actor),x-xapplet, y-yapplet, z);
 }
 
-static GtkWidget* 
-init_object(AWallpaperPlugin *desktop_plugin, gchar * name, gchar * filename, gint x, gint y, gint z, gint width, gint height, gboolean visible, gint scale, gint opacity, void (*pfunc)(GtkWidget*, gpointer))
+static gint 
+path_line(gint x0, gint x1, double t)
 {
-  GtkWidget *actor = NULL;
-  GdkPixbuf *pixbuf = NULL;
-  GtkWidget *image = NULL;
+    // уравниение прямой
+    return ((x1 - x0) * t + x0);
+}
 
-  actor = hildon_animation_actor_new();
-  gchar str[256];
-  snprintf(str, 255, "%s/%s/%s", THEME_PATH, desktop_plugin->priv->theme, filename);
-  //fprintf(stderr, "!!!init object !!!!file = %s\n", str);
-  pixbuf = gdk_pixbuf_new_from_file_at_size (str, 
-                                             width, 
-                                             height, 
-                                             NULL);
-  if (pixbuf){
-      image = gtk_image_new_from_pixbuf (pixbuf);
-      g_object_unref(G_OBJECT(pixbuf));
-  }
-  if (image){
-    g_signal_connect(G_OBJECT(image), "expose_event",
-                           G_CALLBACK(expose_event), pixbuf);
-    gtk_container_add (GTK_CONTAINER (actor), image);
-  }  
 
-  actor_set_position_full(actor, x, y, z);
-  hildon_animation_actor_set_show (actor, visible);
-  hildon_animation_actor_set_scale(actor, (double)scale/100, (double)scale/100);
-  realize(actor);
-  gtk_widget_show_all(actor);
-  g_object_set_data(G_OBJECT(actor), "name", name);
-  g_object_set_data(G_OBJECT(actor), "filename", filename);
-  g_object_set_data(G_OBJECT(actor), "image", image);
-  g_object_set_data(G_OBJECT(actor), "x", x);
-  g_object_set_data(G_OBJECT(actor), "y", y);
-  g_object_set_data(G_OBJECT(actor), "z", z);
-  g_object_set_data(G_OBJECT(actor), "width", width);
-  g_object_set_data(G_OBJECT(actor), "height", height);
-  g_object_set_data(G_OBJECT(actor), "scale", scale);
-  g_object_set_data(G_OBJECT(actor), "visible", visible);
-  g_object_set_data(G_OBJECT(actor), "opacity", opacity);
-  g_object_set_data(G_OBJECT(actor), "func", pfunc);
-  
-  hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (actor), desktop_plugin);
-/*
+void
+destroy_hildon_actor(Actor *actor)
+{
+    //fprintf(stderr, "destroy_hildon_actor %s\n",actor->name);
+    gtk_widget_destroy(actor->widget);
+    actor->widget = NULL;
+}
+
+static Actor* 
+init_object(AWallpaperPlugin *desktop_plugin, 
+            gchar * name, 
+            gchar * filename, 
+            gint x, 
+            gint y, 
+            gint z, 
+            gint width, 
+            gint height, 
+            gboolean visible, 
+            gint scale, 
+            gint opacity, 
+            void (*pfunc_change)(Actor*),
+            void (*pfunc_probability)(Actor*)
+           )
+{
+  Actor *actor = NULL;
+  actor = g_new0(Actor, 1);
+  actor->x = x;
+  actor->y = y;
+  actor->z = z;
+  actor->width = width;
+  actor->height = height;
+  actor->visible = visible;
+  actor->scale = scale;
+  actor->opacity = opacity;
+  actor->filename = g_strdup(filename);
+  actor->name = g_strdup(name);
+  actor->func_change = (gpointer)pfunc_change; 
+  actor->func_probability = (gpointer)pfunc_probability;
+  if (visible)
+    create_hildon_actor(actor, desktop_plugin);
+  else 
+    actor->widget = NULL;
+  actor->time_start_animation = 0;
+  actor->duration_animation = 0;
+  /*
   a.widget = actor;
   a.name = name;
   a.x = x;
@@ -213,143 +223,508 @@ init_object(AWallpaperPlugin *desktop_plugin, gchar * name, gchar * filename, gi
   return actor;
 }
 
-void change_sun(GtkWidget * actor, gpointer data)
+gint 
+rnd(gint max)
+{
+    srand(time(NULL));
+    return rand() % max;
+}
+gint fast_rnd(gint max)
+{
+    guint offset = 12923;
+    guint multiplier = 4079;
+    
+    scene.seed = scene.seed * multiplier + offset;
+    return (gint)(scene.seed % max);
+}
+
+gint 
+probability_sun()
+{
+    /* update sun position after ...  second */
+    return 60;
+}
+
+
+gint 
+probability_plane()
+{
+    return (fast_rnd(10) + 1) * 60;
+//    return 0;
+}
+
+void 
+change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
+{
+    gint phase;
+    char *newfile;
+
+    if (actor){
+        if (scene.daytime == TIME_NIGHT){
+            if (!actor->visible){
+                actor->visible = TRUE;
+                phase = get_moon_phase();
+                newfile = g_strdup_printf( "%s%d.png", actor->name, phase);
+                if (actor->filename)
+                    g_free(actor->filename);
+                actor->filename = newfile;
+                create_hildon_actor(actor, desktop_plugin);
+
+            }
+            //actor->x = 400;
+            //actor->y = 10;
+           // actor_set_position_full(actor->widget, x, y, actor->z);
+            //probability_sun(actor);
+            //fprintf(stderr, "after change sun %d\n", actor->time_start_animation);
+         }else if (actor->visible){
+            actor->visible = FALSE;
+            fprintf(stderr, "destroy moon \n");
+            destroy_hildon_actor(actor);
+            /* TO DO make moonrise*/
+            actor->time_start_animation = 0;
+        } 
+    }
+    
+}
+
+void 
+change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
 {
     double alt, azm;
-    gint x, y, z, daytime;
-    //fprintf(stderr, "change sun \n");
+    gint x, y;
+
+    //fprintf(stderr, "change sun\n");
     if (actor){
-        daytime = get_daytime();
-        if (daytime != TIME_NIGHT){
-             hildon_animation_actor_set_show(actor, 1);
-             get_sun_pos(&alt, &azm);
-             get_sun_screen_pos(alt, azm, &x, &y);
-             actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
-             g_object_set_data(G_OBJECT(actor), "visible", 1);
-             g_object_set_data(G_OBJECT(actor), "x", x);
-             g_object_set_data(G_OBJECT(actor), "y", y);
-        }else {
-            hildon_animation_actor_set_show(actor, 0);
-            g_object_set_data(G_OBJECT(actor), "visible", 0);
+        if (scene.daytime != TIME_NIGHT){
+            if (!actor->visible){
+                actor->visible = TRUE;
+                create_hildon_actor(actor, desktop_plugin);
+            }
+            get_sun_pos(&alt, &azm);
+            get_sun_screen_pos(alt, azm, &x, &y);
+            actor->x = x;
+            actor->y = y;
+            actor_set_position_full(actor->widget, x, y, actor->z);
+            //probability_sun(actor);
+            actor->time_start_animation = time(NULL) + probability_sun();
+         }else if (actor->visible){
+            actor->visible = FALSE;
+            destroy_hildon_actor(actor);
+            actor->time_start_animation = 0;
         } 
     }
+    
 }
-void change_static_actor(GtkWidget * actor, gpointer data)
+
+static void 
+change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
 {
-    gint daytime;
-    gchar newfile[2048];
-    gchar * name;
-    GtkWidget *image;
-    GdkPixbuf *pixbuf;
-    AWallpaperPlugin *desktop_plugin;
-    if (!actor) return;
-    if (!data) return;
-    desktop_plugin = data;
-    daytime = get_daytime();
+    gint x0 = -300, y0 = 225, scale0 = 100,
+         x1 = 800, y1 = 162, scale1 = 130, 
+         x, y, scale;
+    struct timeval tvb;     
+    suseconds_t ms;
+    long sec;
+    double t;
+
+    //fprintf(stderr, "change tram\n");
+    gettimeofday(&tvb, NULL);
     
-    name = g_object_get_data(G_OBJECT(actor), "name");
-    snprintf(newfile, 2047, "%s/%s/%s%d.png", THEME_PATH, desktop_plugin->priv->theme, name, daytime);
+    ms = tvb.tv_usec;
+    sec = tvb.tv_sec;
     
-    pixbuf = gdk_pixbuf_new_from_file_at_size (newfile, 
-                                               g_object_get_data(G_OBJECT(actor), "width"), 
-                                               g_object_get_data(G_OBJECT(actor), "height"), 
-                                               NULL);
-    if (pixbuf){
-        image = gtk_image_new_from_pixbuf (pixbuf);
-        g_object_unref(G_OBJECT(pixbuf));
+    if (!actor->visible){
+        actor->visible = TRUE;
+        if (scene.daytime == TIME_NIGHT){
+            if (actor->filename)
+                g_free(actor->filename);
+            actor->filename = g_strdup("tram_dark.png");
+        } else{
+            if (actor->filename)
+                g_free(actor->filename);
+            actor->filename = g_strdup("tram.png");
+        }
+        create_hildon_actor(actor, desktop_plugin);
     }
-    
-    g_signal_connect(G_OBJECT(image), "expose_event",
-                                   G_CALLBACK(expose_event), pixbuf);
-    if (g_object_get_data(G_OBJECT(actor), "image")){
-        gtk_container_remove(actor, g_object_get_data(G_OBJECT(actor), "image"));  
+    t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
+    x = path_line(x0, x1, t);
+    y = path_line(y0, y1, t);
+    scale = path_line(scale0, scale1, t);
+    //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
+    actor_set_position_full(actor->widget, x, y, actor->z);
+    hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
+    if (t >= 1){
+        /* stop animation */
+        actor->visible = FALSE;
+        destroy_hildon_actor(actor);
+        actor->time_start_animation = sec + fast_rnd(300);
     }
-    g_object_set_data(G_OBJECT(actor), "image", image);
-    gtk_container_add (GTK_CONTAINER (actor), image);
-    realize(actor);
-    gtk_widget_show_all(actor);
 }
 
-static gint 
-path_line(gint x0, gint x1, double t)
+void
+change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
 {
-    // уравниение прямой
-    return ((x1 - x0) * t + x0);
+    gint x0 = 620, y0 = 233, scale0 = 100,
+         x1 = 79, y1 = -146, scale1 = 100, 
+         x, y, scale;
+    struct timeval tvb;     
+    suseconds_t ms;
+    long sec;
+    double t;
+
+    gettimeofday(&tvb, NULL);
+    
+    ms = tvb.tv_usec;
+    sec = tvb.tv_sec;
+//    fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
+   
+    if (scene.daytime != TIME_NIGHT){
+        if (actor->time_start_animation == 0){
+            actor->time_start_animation = sec + probability_plane();
+            return;
+        }
+    }
+    if (!actor->visible){
+        actor->visible = TRUE;
+        create_hildon_actor(actor, desktop_plugin);
+    }
+    t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
+    x = path_line(x0, x1, t);
+    y = path_line(y0, y1, t);
+    //scale = path_line(scale0, scale1, t);
+    //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
+    actor_set_position_full(actor->widget, x, y, actor->z);
+    //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
+    if (t >= 1){
+        /* stop animation */
+        actor->visible = FALSE;
+        destroy_hildon_actor(actor);
+        if (scene.daytime == TIME_NIGHT) 
+            actor->time_start_animation = 0;
+        else 
+            actor->time_start_animation = sec + probability_plane();
+    }
+
 }
 
-static void 
-change_tram(GtkWidget * actor, double t)
+void
+change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
 {
-    gint x0 = -300, y0 = 225, scale0 = 100,
-         x1 = 800, y1 = 162, scale1 = 130, 
+    gint x0 = -actor->width, y0 = 45, scale0 = 100,
+         x1 = 800, y1 = 20, scale1 = 100, 
          x, y, scale;
+    struct timeval tvb;     
+    suseconds_t ms;
+    long sec;
+    double t;
+
+    gettimeofday(&tvb, NULL);
+    
+    ms = tvb.tv_usec;
+    sec = tvb.tv_sec;
+//    fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
+    if (scene.daytime != TIME_NIGHT){
+        if (actor->time_start_animation == 0){
+            actor->time_start_animation = sec + probability_plane();
+            return;
+        }
+    }
+    if (!actor->visible){
+        actor->visible = TRUE;
+        create_hildon_actor(actor, desktop_plugin);
+    }
 
+    t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
     x = path_line(x0, x1, t);
     y = path_line(y0, y1, t);
-    scale = path_line(scale0, scale1, t);
-    fprintf(stderr, "path tram:  t=%f, x=%d, y=%d, scale=%d\n", t, x, y, scale);
-    actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
-    hildon_animation_actor_set_scale(actor, (double)scale/100, (double)scale/100);
+    //scale = path_line(scale0, scale1, t);
+    //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
+    actor_set_position_full(actor->widget, x, y, actor->z);
+    //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
+    if (t >= 1){
+        /* stop animation */
+        actor->visible = FALSE;
+        destroy_hildon_actor(actor);
+        if (scene.daytime == TIME_NIGHT) 
+            actor->time_start_animation = 0;
+        else 
+            actor->time_start_animation = sec + probability_plane();
+    }
+
 }
 
-void change_sky(GtkWidget * actor, gpointer data)
+void
+change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
 {
-    gint daytime, opacity;
-    //fprintf(stderr, "change sky \n");
-    if (actor){
-        daytime = get_daytime();
-        opacity = g_object_get_data(G_OBJECT(actor), "opacity") - 10;
-        if (opacity < 0) opacity = 255;
-        hildon_animation_actor_set_show_full(actor, 1, opacity);
-        g_object_set_data(G_OBJECT(actor), "opacity", opacity);
-        switch (daytime){
-            case TIME_NIGHT:
-                //fprintf(stderr, "change sky night\n");
-            break;
-            case TIME_DAY:
-                //fprintf(stderr, "change sky day\n");
-            break;
+    gint x0, y0 = 300, scale0 = 100,
+         x1, y1 = -actor->height, scale1 = 150, 
+         x, y, scale;
+    struct timeval tvb;     
+    suseconds_t ms;
+    long sec;
+    double t;
+    gchar *newfile;
+
+    //fprintf(stderr, "change cloud\n");
+    gettimeofday(&tvb, NULL);
+    
+    ms = tvb.tv_usec;
+    sec = tvb.tv_sec;
+    //fprintf(stderr, "c1oud %s - y0=%d\n", actor->name, actor->y);
+   
+    if (!actor->visible){
+        actor->visible = TRUE;
+        if (scene.daytime == TIME_NIGHT){
+            newfile = g_strdup_printf("%s_dark.png", actor->name);
+        }else{
+            newfile = g_strdup_printf("%s.png", actor->name);
+        } 
+        if (actor->filename)
+            g_free(actor->filename);
+        actor->filename = newfile;
+         
+
+        create_hildon_actor(actor, desktop_plugin);
+    }
+    t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
+    
+    if (scene.wind_orientation == 1){
+        x0 = -actor->width;
+        x1 = 800;
+    }
+    else {
+        x0 = 800;
+        x1 = -actor->width;
+    }
+
+    x = path_line(x0, x1, t);    
+    y = -scene.wind_angle * (x - x0) + actor->y;
+    scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
+
+    //fprintf(stderr, "change cloud t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
+    actor_set_position_full(actor->widget, x, y, actor->z);
+    hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
+    if ((y < y1 || y > y0) || t >= 1){
+        /* stop animation */
+        actor->visible = FALSE;
+        destroy_hildon_actor(actor);
+        actor->time_start_animation = sec + fast_rnd(300);
+        actor->y = fast_rnd(300);
+    }
+
+}
+
+void
+change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
+{
+    scene.wind_orientation = fast_rnd(2);
+    if (scene.wind_orientation == 0) scene.wind_orientation = -1;
+    scene.wind_angle = (double)(fast_rnd(200) - 100) / 100;
+    actor->time_start_animation = time(NULL) + (fast_rnd(10) + 10) * 60;
+    //fprintf(stderr, "change wind orient = %d angle = %f after = %d\n", scene.wind_orientation, scene.wind_angle, actor->time_start_animation-time(NULL));
+}
 
+void 
+change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin)
+{
+    
+    gint now = time(NULL);
+    if (scene.daytime == TIME_DAY){
+        if (actor->visible){
+            actor->visible = FALSE;
+            destroy_hildon_actor(actor);
         }
+        actor->time_start_animation = 0;
+        return;
+    }else if (actor->time_start_animation == 0){
+        actor->time_start_animation = now + fast_rnd(30);
+        return;
+    }
+
+    if (!actor->visible){
+        actor->visible = TRUE;
+        create_hildon_actor(actor, desktop_plugin);
+        actor->time_start_animation = now + fast_rnd(60) + 10;
+    }else {
+        actor->visible = FALSE;
+        destroy_hildon_actor(actor);
+        actor->time_start_animation = now + fast_rnd(60) + 10;
     }
+   
 }
+
 void 
-change_background(GtkWidget * actor, gpointer data)
+change_signal(Actor * actor, AWallpaperPlugin *desktop_plugin)
 {
-    gint opacity;
-    if (actor){
-        opacity = g_object_get_data(G_OBJECT(actor), "opacity") - 1;
-        if (opacity < 0) opacity = 255;
-        hildon_animation_actor_set_show_full(actor, 1, opacity);
-        g_object_set_data(G_OBJECT(actor), "opacity", opacity);
+    gchar *newfile;
+    gint now = time(NULL);
+    newfile = g_strdup_printf("%s%d.png", actor->name, scene.daytime); 
+    if (!strcmp(actor->filename, "red.png"))
+        newfile = g_strdup_printf("%s", "green.png");
+    else 
+        newfile = g_strdup_printf("%s", "red.png");
+    g_free(actor->filename);
+    actor->filename = newfile;
+    change_hildon_actor(actor, desktop_plugin);
+    actor->time_start_animation = now + fast_rnd(30) + 10;
+}
 
+void
+create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin) 
+{
+  GtkWidget *ha = NULL;
+  GdkPixbuf *pixbuf = NULL;
+  GtkWidget *image = NULL;
+  gchar     *str = NULL;
+
+  /* fprintf(stderr, "create_hildon_actor %s\n", actor->name);*/
+  ha = hildon_animation_actor_new();
+  str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
+                        desktop_plugin->priv->theme, actor->filename);
+  pixbuf = gdk_pixbuf_new_from_file_at_size (str, 
+                                             actor->width, 
+                                             actor->height, 
+                                             NULL);
+  if (str)
+      g_free(str);
+  if (pixbuf){
+      image = gtk_image_new_from_pixbuf (pixbuf);
+      g_object_unref(G_OBJECT(pixbuf));
+  }
+  if (image){
+    g_signal_connect(G_OBJECT(image), "expose_event",
+                           G_CALLBACK(expose_event), pixbuf);
+    gtk_container_add (GTK_CONTAINER (ha), image);
+  }  
+  actor_set_position_full(ha, actor->x, actor->y, actor->z);
+  hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(ha), actor->visible);
+  hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(ha), (double)actor->scale/100, (double)actor->scale/100);
+  realize(ha);
+  gtk_widget_show_all(ha);
+
+  /* TO DO check it */
+  /*  gdk_flush (); */
+
+  //g_object_set_data(G_OBJECT(ha), "name", name);
+  //g_object_set_data(G_OBJECT(ha), "filename", filename);
+  g_object_set_data(G_OBJECT(ha), "image", image);
+  /*
+  g_object_set_data(G_OBJECT(ha), "x", x);
+  g_object_set_data(G_OBJECT(ha), "y", y);
+  g_object_set_data(G_OBJECT(ha), "z", z);
+  g_object_set_data(G_OBJECT(ha), "width", width);
+  g_object_set_data(G_OBJECT(ha), "height", height);
+  g_object_set_data(G_OBJECT(ha), "scale", scale);
+  g_object_set_data(G_OBJECT(ha), "visible", visible);
+  g_object_set_data(G_OBJECT(ha), "opacity", opacity);
+  g_object_set_data(G_OBJECT(ha), "func", pfunc);
+  */
+  hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
+  actor->widget = ha;
+}
+
+
+void
+change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
+{
+    GtkWidget *image = NULL;
+    GdkPixbuf *pixbuf = NULL;
+    gchar     *str = NULL;
+
+    str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
+                            desktop_plugin->priv->theme, actor->filename);
+    pixbuf = gdk_pixbuf_new_from_file_at_size (str, 
+                                               actor->width, 
+                                               actor->height, 
+                                               NULL);
+    if(str)
+        g_free(str);
+    if (pixbuf){
+        image = gtk_image_new_from_pixbuf (pixbuf);
+        g_object_unref(G_OBJECT(pixbuf));
     }
+    if (image){ 
+        g_signal_connect(G_OBJECT(image), "expose_event",
+                                       G_CALLBACK(expose_event), pixbuf);
+        if (g_object_get_data(G_OBJECT(actor->widget), "image")){
+            gtk_container_remove(GTK_CONTAINER(actor->widget), g_object_get_data(G_OBJECT(actor->widget), "image"));  
+        }
+        g_object_set_data(G_OBJECT(actor->widget), "image", image);
+        gtk_container_add (GTK_CONTAINER (actor->widget), image);
+        realize(actor->widget);
+        gtk_widget_show_all(actor->widget);
+        /* TO DO check it */
+       /*  gdk_flush (); */
+
+
+    }
+
 }
 
-static gint 
-get_time(gint t)
+
+void 
+change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
+{
+    gchar *newfile;
+    newfile = g_strdup_printf("%s%d.png", actor->name, scene.daytime); 
+    if (actor->filename)
+            g_free(actor->filename);
+    actor->filename = newfile;
+    change_hildon_actor(actor, desktop_plugin);
+}
+
+void 
+change_static_actor_with_corner(Actor * actor, AWallpaperPlugin *desktop_plugin)
+{
+    gchar *newfile;
+    gchar           buffer[2048];
+
+    if (desktop_plugin->priv->right_corner)
+        gtk_widget_destroy(desktop_plugin->priv->right_corner);
+    snprintf(buffer, sizeof(buffer) - 1, "%s/%s/town%i_right_corner.png", \
+                                  THEME_PATH, desktop_plugin->priv->theme, scene.daytime);
+    desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
+    if (desktop_plugin->priv->right_corner){
+        gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
+        gtk_widget_show (desktop_plugin->priv->right_corner);
+    }
+    change_static_actor(actor, desktop_plugin);
+
+}
+
+void
+change_layer1(Actor * actor, AWallpaperPlugin *desktop_plugin)
 {
+    gint y;
+    y = actor->y + 20;
+    if (y > 480) y = -480;
+    //fprintf(stderr, "!! %s - %d\n", actor->name, y);
+    actor_set_position_full(actor->widget, actor->x, y, actor->z);
+    actor->y = y;
+}
+
+/*
+static gint 
+get_time(gint t){
     // уравнение изменения времени
     return t*1.1;
 }
-
+*/
 static void 
-destroy_scene(void)
-{
-    GSList * tmp = scene.dynamic_actors;
+destroy_scene(void){
+    GSList * tmp = scene.actors;
+    Actor *actor;
     while (tmp != NULL){
-        if (tmp->data){
-            gtk_widget_destroy(tmp->data);
-            tmp->data = NULL;
-        }
-        tmp = g_slist_next(tmp);
-    }
-    g_slist_free(tmp);
-    tmp = scene.static_actors;
-    while (tmp != NULL){        
-        if (tmp->data){
-            gtk_widget_destroy(tmp->data);
-            tmp->data = NULL;
+        actor = tmp->data;
+        if (actor){
+            if (actor->filename)
+                g_free(actor->filename);
+            if (actor->name)
+                g_free(actor->name);
+            gtk_widget_destroy(actor->widget);
+            //actor->widget = NULL;
+            g_free(actor);
         }
         tmp = g_slist_next(tmp);
     }
@@ -366,55 +741,322 @@ reload_scene(AWallpaperPlugin *desktop_plugin)
         init_scene(desktop_plugin);
     else if (!strcmp(desktop_plugin->priv->theme,"Berlin")) 
         init_scene1(desktop_plugin);
+    else if (!strcmp(desktop_plugin->priv->theme,"Modern")) 
+        init_scene1(desktop_plugin);
+
 }
 
-void
-anim_tram(GtkWidget *actor, Animation * an)
+static void
+init_scene2(AWallpaperPlugin *desktop_plugin)
 {
-    //change_tram1(an->actor, t, an->timeall);
-}
+  Actor *actor;
+  gint now = time(NULL);
+
+  /* fprintf(stderr, "init scene \n");*/
+  scene.daytime = get_daytime();
+  scene.actors = NULL;
+  scene.wind_orientation = -1;
+  scene.wind_angle = 0.3;
+  /* init value for random */
+  scene.seed = time(NULL);
+
+  
 
+  actor = init_object(desktop_plugin, "background", "33.png", 0, 0, 5, 800, 480, 
+                      TRUE, 100, 255, NULL, NULL);
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  actor = init_object(desktop_plugin, "layer1", "11.png", 0, -480, 6, 800, 1920, 
+                      TRUE, 100, 255, (gpointer)&change_layer1, NULL);
+  actor->time_start_animation = now;
+  actor->duration_animation = G_MAXINT;
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  actor = init_object(desktop_plugin, "layer2", "111.png", 0, -480 - 480, 6, 800, 1920, 
+                      TRUE, 100, 255, (gpointer)&change_layer1, NULL);
+  actor->time_start_animation = now;
+  actor->duration_animation = G_MAXINT;
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  actor = init_object(desktop_plugin, "symbols", "22.png", 0, 0, 7, 800, 480, 
+                      TRUE, 100, 255, NULL, NULL);
+  scene.actors = g_slist_append(scene.actors, actor);
+  
+
+    run_long_timeout(desktop_plugin);
+}
+/* Init Modern Scene */
 static void
 init_scene(AWallpaperPlugin *desktop_plugin)
 {
-  GtkWidget *actor;
-  GdkPixbuf *pixbuf;
-  GtkWidget *image;
-  double alt, azm;
-  gint x, y;
-  GSList * list = NULL;
-  gchar str[256];
-  Animation *anim = NULL;
+  Actor *actor;
+  gint now = time(NULL);
+  gint i;
+  gint winds[13][2];
 
-fprintf(stderr, "init scene modern\n");
+  /* fprintf(stderr, "init scene \n");*/
   scene.daytime = get_daytime();
-  scene.dynamic_actors = NULL;
-  scene.static_actors = NULL;
-  //get_sun_pos(&alt, &azm);
-  //get_sun_screen_pos(alt, azm, &x, &y);
-  actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 11, 88, 88, 1, 100, 255, &change_sun);
-  change_sun(actor, NULL);
-  scene.static_actors = g_slist_append(scene.static_actors, G_OBJECT(actor));
-  //scene.dynamic_actors = g_slist_append(scene.dynamic_actors, G_OBJECT(actor));
-
-  actor = init_object(desktop_plugin, "sky", "sky0.png", 0, 0, 5, 800, 480, 1, 100, 255, &change_static_actor);
-  change_static_actor(G_OBJECT(actor), desktop_plugin);
-  scene.static_actors = g_slist_append(scene.static_actors, G_OBJECT(actor));
-
-  actor = init_object(desktop_plugin, "town", "town0.png", 0, 480-374, 10, 800, 374, 1, 100, 255, &change_static_actor);
-  change_static_actor(G_OBJECT(actor), desktop_plugin);
-  scene.static_actors = g_slist_append(scene.static_actors, G_OBJECT(actor));
+  scene.actors = NULL;
+  scene.wind_orientation = -1;
+  scene.wind_angle = 0.3;
+  /* init value for random */
+  scene.seed = time(NULL);
+
+  
+
+  actor = init_object(desktop_plugin, "sky", "sky0.png", 0, 0, 5, 800, 480, 
+                      TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
+  change_static_actor(actor, desktop_plugin);
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88, 
+                      TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
+  actor->time_start_animation = now;
+  actor->duration_animation = G_MAXINT;
+  change_sun(actor, desktop_plugin);
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50, 
+    //                  TRUE, 100, 255, NULL, NULL);
+  //scene.actors = g_slist_append(scene.actors, actor);
   
-  actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 30, 800, 79, 1, 100, 255, &change_static_actor);
-  change_static_actor(G_OBJECT(actor), desktop_plugin);
-  scene.static_actors = g_slist_append(scene.static_actors, G_OBJECT(actor));
+  actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97, 
+                      FALSE, 100, 255, (gpointer)&change_cloud, NULL);
+  actor->time_start_animation = now + fast_rnd(180);
+  actor->duration_animation = 3*60;
+  scene.actors = g_slist_append(scene.actors, actor);
   
-  //if (scene.daytime == TIME_DAY) snprintf(str, 255, "tram.png");
-  //else snprintf(str, 255, "tram_dark.png");
-  //actor = init_object("tram", "tram.png", -300, 191, 25, 350, 210, 1, 100, 255, NULL);
-  actor = init_object(desktop_plugin, "tram", "tram_dark.png", -300, 225, 25, 350, 210, 1, 100, 255, NULL);
-  //scene.dynamic_actors = g_slist_append(scene.dynamic_actors, G_OBJECT(actor));
+  actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75, 
+                      FALSE, 100, 255, (gpointer)&change_cloud, NULL);
+  actor->time_start_animation = now + fast_rnd(180);
+  actor->duration_animation = 3*60;
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75, 
+                      FALSE, 100, 255, (gpointer)&change_cloud, NULL);
+  actor->time_start_animation = now + fast_rnd(180);
+  actor->duration_animation = 5*60;
+  scene.actors = g_slist_append(scene.actors, actor);
+
+
+  actor = init_object(desktop_plugin, "town", "town0.png", 0, 0, 8, 800, 480, 
+                      TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
+  change_static_actor(actor, desktop_plugin);
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  actor = init_object(desktop_plugin, "tram", "tram.png", -300, 225, 9, 350, 210, 
+                      FALSE, 100, 255, (gpointer)&change_tram, NULL);
+  actor->time_start_animation = time(NULL) + fast_rnd(10); 
+  actor->duration_animation = 60;
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 10, 800, 79,
+                      TRUE, 100, 255, (gpointer)&change_static_actor_with_corner, NULL);
+  change_static_actor_with_corner(actor, desktop_plugin);
+  scene.actors = g_slist_append(scene.actors, actor);
   
+  actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 20, 6, 60, 60, 
+                      FALSE, 100, 255, (gpointer)&change_moon, NULL);
+  change_moon(actor, desktop_plugin);
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0, 
+                      FALSE, 100, 255, (gpointer)&change_wind, NULL);
+  change_wind(actor, desktop_plugin);
+  scene.actors = g_slist_append(scene.actors, actor);
+
+    /* windows in 4-th house  */
+
+    winds[0][0] = 482;
+    winds[0][1] = 180;
+
+    winds[1][0] = 495;
+    winds[1][1] = 179;
+
+    winds[2][0] = 482;
+    winds[2][1] = 191;
+
+    winds[3][0] = 495;
+    winds[3][1] = 190;
+    
+    winds[4][0] = 482;
+    winds[4][1] = 201;
+    
+    winds[5][0] = 495;
+    winds[5][1] = 210;
+    
+    winds[6][0] = 482;
+    winds[6][1] = 222;
+    
+    winds[7][0] = 495;
+    winds[7][1] = 221;
+    
+    winds[8][0] = 459;
+    winds[8][1] = 203;
+    
+    winds[9][0] = 495;
+    winds[9][1] = 241;
+    
+    winds[10][0] = 495;
+    winds[10][1] = 252;
+    
+    winds[11][0] = 482;
+    winds[11][1] = 273;
+    
+    winds[12][0] = 495;
+    winds[12][1] = 303;
+    for (i=0; i<13; i++){
+        actor = init_object(desktop_plugin, "window1", "window1.png", 
+                            winds[i][0], winds[i][1], 8, 8, 10, 
+                            FALSE, 100, 255, (gpointer)&change_window1, NULL);
+        //change_window1(actor, desktop_plugin);
+        actor->time_start_animation = now + fast_rnd(30);
+        scene.actors = g_slist_append(scene.actors, actor);
+
+    }
+    
+    /* windows in 1-th house  */
+    
+    winds[0][0] = 86;
+    winds[0][1] = 321;
+
+    winds[1][0] = 86;
+    winds[1][1] = 363;
+
+    winds[2][0] = 86;
+    winds[2][1] = 385;
+
+    winds[3][0] = 86;
+    winds[3][1] = 286;
+    
+    winds[4][0] = 94;
+    winds[4][1] = 232;
+    
+    winds[5][0] = 94;
+    winds[5][1] = 243;
+    
+    winds[6][0] = 94;
+    winds[6][1] = 265;
+    
+    winds[7][0] = 94;
+    winds[7][1] = 331;
+    for (i=0; i<8; i++){
+        actor = init_object(desktop_plugin, "window2", "window2.png", 
+                            winds[i][0], winds[i][1], 8, 8, 10, 
+                            FALSE, 100, 255, (gpointer)&change_window1, NULL);
+        //change_window1(actor, desktop_plugin);
+        actor->time_start_animation = now + fast_rnd(30);
+        scene.actors = g_slist_append(scene.actors, actor);
+
+    }
+    
+    /* windows in 3-th house  */
+    
+    winds[0][0] = 251;
+    winds[0][1] = 162;
+
+    winds[1][0] = 251;
+    winds[1][1] = 196;
+
+    winds[2][0] = 251;
+    winds[2][1] = 278;
+
+    winds[3][0] = 251;
+    winds[3][1] = 289;
+    
+    winds[4][0] = 313;
+    winds[4][1] = 173;
+    
+    winds[5][0] = 322;
+    winds[5][1] = 160;
+    
+    winds[6][0] = 303;
+    winds[6][1] = 217;
+    
+    winds[7][0] = 322;
+    winds[7][1] = 224;
+    
+    winds[8][0] = 323;
+    winds[8][1] = 217;
+    
+    winds[9][0] = 322;
+    winds[9][1] = 288;
+    
+    for (i=0; i<10; i++){
+        actor = init_object(desktop_plugin, "window3", "window3.png", 
+                            winds[i][0], winds[i][1], 8, 8, 10, 
+                            FALSE, 100, 255, (gpointer)&change_window1, NULL);
+        //change_window1(actor, desktop_plugin);
+        actor->time_start_animation = now + fast_rnd(30);
+        scene.actors = g_slist_append(scene.actors, actor);
+
+    }
+
+    /* windows in 5-th house  */
+    
+    winds[0][0] = 610;
+    winds[0][1] = 224;
+
+    winds[1][0] = 602;
+    winds[1][1] = 245;
+
+    winds[2][0] = 602;
+    winds[2][1] = 264;
+
+    winds[3][0] = 610;
+    winds[3][1] = 301;
+    
+    winds[4][0] = 610;
+    winds[4][1] = 320;
+    
+    winds[5][0] = 593;
+    winds[5][1] = 352;
+    
+    winds[6][0] = 610;
+    winds[6][1] = 368;
+    
+    for (i=0; i<7; i++){
+        actor = init_object(desktop_plugin, "window4", "window4.png", 
+                            winds[i][0], winds[i][1], 8, 8, 10, 
+                            FALSE, 100, 255, (gpointer)&change_window1, NULL);
+        //change_window1(actor, desktop_plugin);
+        actor->time_start_animation = now + fast_rnd(30);
+        scene.actors = g_slist_append(scene.actors, actor);
+
+    }
+
+    /* windows in 6-th house  */
+    
+    winds[0][0] = 717;
+    winds[0][1] = 283;
+
+    winds[1][0] = 698;
+    winds[1][1] = 293;
+
+    winds[2][0] = 717;
+    winds[2][1] = 315;
+
+    winds[3][0] = 717;
+    winds[3][1] = 323;
+    
+    winds[4][0] = 698;
+    winds[4][1] = 362;
+    
+    winds[5][0] = 698;
+    winds[5][1] = 400;
+    
+    for (i=0; i<6; i++){
+        actor = init_object(desktop_plugin, "window5", "window5.png", 
+                            winds[i][0], winds[i][1], 8, 8, 10, 
+                            FALSE, 100, 255, (gpointer)&change_window1, NULL);
+        //change_window1(actor, desktop_plugin);
+        actor->time_start_animation = now + fast_rnd(30);
+        scene.actors = g_slist_append(scene.actors, actor);
+
+    }
+
+    run_long_timeout(desktop_plugin);
+#if 0    
   anim = g_new0(Animation, 1);
   anim->count = 1;
   anim->actor = actor;
@@ -424,50 +1066,146 @@ fprintf(stderr, "init scene modern\n");
   anim->timeall = 10;
   
   scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
-  
+#endif  
  }
+
+/* Init Berlin Scene */
 static void
 init_scene1(AWallpaperPlugin *desktop_plugin)
 {
-  GtkWidget *actor;
-  GdkPixbuf *pixbuf;
-  GtkWidget *image;
-  double alt, azm;
-  gint x, y;
-  GSList * list = NULL;
+  Actor *actor;
+  gint now = time(NULL);
+  gint i; 
+  gint winds[13][2];
 
   scene.daytime = get_daytime();
-  scene.dynamic_actors = NULL;
-  scene.static_actors = NULL;
+  scene.actors = NULL;
+  scene.wind_orientation = -1;
+  scene.wind_angle = 0.3;
+  /* init value for random */
+  scene.seed = time(NULL);
 
-  actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 20, 88, 88, 1, 100, 255, &change_sun);
-  change_sun(actor, NULL);
-  //scene.static_actors = g_slist_append(scene.static_actors, G_OBJECT(actor));
-  scene.dynamic_actors = g_slist_append(scene.dynamic_actors, G_OBJECT(actor));
-/*
-  actor = init_object(desktop_plugin, "background", "sky_dark.png", 0, 0, 4, 800, 480, 1, 100, 255, NULL);
-  scene.dynamic_actors = g_slist_append(scene.dynamic_actors, G_OBJECT(actor));
-*/
-  actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480, 1, 100, 255, &change_static_actor);
-  change_static_actor(actor, NULL);
-  scene.static_actors = g_slist_append(scene.static_actors, G_OBJECT(actor));
+  
+  actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480, 
+                      TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
+  change_static_actor(actor, desktop_plugin);
+  scene.actors = g_slist_append(scene.actors, actor);
 
-  actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480, 1, 100, 255, &change_static_actor);
-  change_static_actor(actor, NULL);
-  scene.static_actors = g_slist_append(scene.static_actors, G_OBJECT(actor));
   
-/*
-  actor = init_object("cloud1", 400, 150, 2, 200, 150, NULL);
-  scene.dynamic_actors = g_slist_append(scene.dynamic_actors, G_OBJECT(actor));
+  actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88, 
+                      TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
+  actor->time_start_animation = time(NULL);
+  actor->duration_animation = G_MAXINT;
+  change_sun(actor, desktop_plugin);
+  scene.actors = g_slist_append(scene.actors, actor);
+
+#if 0
+  actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50, 
+                      TRUE, 100, 255, NULL, NULL);
+  scene.actors = g_slist_append(scene.actors, actor);
+#endif
+
+  actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60, 
+                      FALSE, 100, 255, (gpointer)&change_moon, NULL);
+  change_moon(actor, desktop_plugin);
+  scene.actors = g_slist_append(scene.actors, actor);
+  
+  actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97, 
+                      FALSE, 100, 255, (gpointer)&change_cloud, NULL);
+  actor->time_start_animation = now + fast_rnd(180);
+  actor->duration_animation = 3*60;
+  scene.actors = g_slist_append(scene.actors, actor);
+  
+  actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75, 
+                      FALSE, 100, 255, (gpointer)&change_cloud, NULL);
+  actor->time_start_animation = now + fast_rnd(180);
+  actor->duration_animation = 3*60;
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75, 
+                      FALSE, 100, 255, (gpointer)&change_cloud, NULL);
+  actor->time_start_animation = now + fast_rnd(180);
+  actor->duration_animation = 5*60;
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50, 
+                      FALSE, 100, 255, (gpointer)&change_plane2, NULL);
+  actor->time_start_animation = now + probability_plane();
+  actor->duration_animation = 60;
+  scene.actors = g_slist_append(scene.actors, actor);
+  
+  actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116, 
+                      FALSE, 100, 255, (gpointer)&change_plane1, NULL);
+  actor->time_start_animation = now + probability_plane();
+  actor->duration_animation = 30;
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480, 
+                      TRUE, 100, 255, (gpointer)&change_static_actor_with_corner, NULL);
+  change_static_actor_with_corner(actor, desktop_plugin);
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0, 
+                      FALSE, 100, 255, (gpointer)&change_wind, NULL);
+  change_wind(actor, desktop_plugin);
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  actor = init_object(desktop_plugin, "signal", "red.png", 486, 425, 10, 18, 38, 
+                      TRUE, 100, 255, (gpointer)&change_signal, NULL);
+  actor->time_start_animation = now + fast_rnd(30) + 10;  
+  scene.actors = g_slist_append(scene.actors, actor);winds[0][0] = 717;
+    
+    winds[0][0] = 389;
+    winds[0][1] = 305;
 
-  actor = init_object("sun", 10, 10, 50, 88, 88, NULL);
-  list = g_slist_append(list, G_OBJECT(actor));
-  actor = init_object("cloud1", 50, 50, 49, 150, 100, NULL);
-  list = g_slist_append(list, G_OBJECT(actor));
+    winds[1][0] = 373;
+    winds[1][1] = 306;
 
-  ma1 = multiactor_init("multi", list, 0, 0, 50, 1.0, TRUE);
-  //objects_list = g_slist_append(objects_list, G_OBJECT(ma)); 
-  */
+    winds[2][0] = 355;
+    winds[2][1] = 306;
+
+    winds[3][0] = 356;
+    winds[3][1] = 288;
+    
+    winds[4][0] = 337;
+    winds[4][1] = 269;
+    
+    winds[5][0] = 372;
+    winds[5][1] = 268;
+  
+    winds[6][0] = 372;
+    winds[6][1] = 249;
+    
+    winds[7][0] = 388;
+    winds[7][1] = 249;
+    
+    winds[8][0] = 387;
+    winds[8][1] = 230;
+    
+    winds[9][0] = 372;
+    winds[9][1] = 211;
+    
+    winds[10][0] = 355;
+    winds[10][1] = 159;
+    
+    winds[11][0] = 335;
+    winds[11][1] = 158;
+    
+    winds[12][0] = 386;
+    winds[12][1] = 119;
+  
+    for (i=0; i<13; i++){
+        actor = init_object(desktop_plugin, "window", "window.png", 
+                            winds[i][0], winds[i][1], 10, 8, 9, 
+                            FALSE, 100, 255, (gpointer)&change_window1, NULL);
+        //change_window1(actor, desktop_plugin);
+        actor->time_start_animation = now + fast_rnd(30);
+        scene.actors = g_slist_append(scene.actors, actor);
+
+    }
+    
+    run_long_timeout(desktop_plugin);
 
 }
 
@@ -475,33 +1213,12 @@ init_scene1(AWallpaperPlugin *desktop_plugin)
 void 
 get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
 {
-    gint y0 = 400;// - уровень горизонта
-    gint o_width = 128,
-         o_height = 128; 
+    gint y0 = 365;// - уровень горизонта
     *x = (int)(azm * 800) - 64;
     *y = (int)((1 - alt) * y0) - 64;
+    //fprintf(stderr, "sun pos alt=%f azm=%f x=%d y=%d\n", alt, azm, *x, *y);
 }
-
-void change_multiactor()
-{
-    gboolean fl;
-    double scale;
-    gint x, y, z;
-    if (ma1->visible) fl = FALSE;
-    else fl = TRUE;
-    //multiactor_set_visible(ma1, fl);
-
-    scale = ma1->scale;
-    scale -= 0.1;
-    if (scale == 0) scale = 1;
-    //multiactor_set_scale(ma1, scale);
-
-    x = ma1->x + 10;
-    y = ma1->y + 10;
-    //multiactor_set_position(ma1, x, y, 0);
-
-}
-
+#if 0
 static void 
 change_actor(GtkWidget * actor)
 {
@@ -573,102 +1290,110 @@ change_actor(GtkWidget * actor)
     }
 
 }
-gint ttt = 0;
+#endif
 static gboolean
-plugin_on_timeout (AWallpaperPlugin *desktop_plugin)
-{
-  gint daytime = get_daytime();
-  GSList * tmp;
-  gchar * name;
-  void (*pfunc)(gpointer, gpointer);
-  time_t now;
-  gint t;
-  Animation *anim = NULL;
-  if (scene.daytime != daytime){
-      tmp = scene.static_actors;
-      while (tmp != NULL){
-          //change_actor(tmp->data);
-          pfunc = g_object_get_data(G_OBJECT(tmp->data), "func");
-          /*name = g_object_get_data(G_OBJECT(tmp->data), "name");
-          if (name == "tram"){
-              if (pfunc)
-                (*pfunc)(tmp->data, ttt);
-              ttt = get_time(ttt+1);
-              if (ttt >= 100) ttt = 0;
-            }else*/
-          if (pfunc){
-              (*pfunc)(tmp->data, NULL);
-          }
-          tmp = g_slist_next(tmp);
-      }
-   }
-   tmp = scene.dynamic_actors;
-   now = time(NULL);
-   
-   while (tmp != NULL)
-   {    
-        anim = tmp->data;
-        if (anim == NULL) fprintf(stderr, "get anim\n");
-        t = now - anim->timestart;
-        if (t > anim->timeall){
-            anim->timestart = now;
-            if (anim->count != -1) anim->count--;
-             
-        } 
-        if (anim->count == 0){
-            g_free(anim);
-            scene.dynamic_actors = g_slist_remove(scene.dynamic_actors, anim);
-            //tmp->data = NULL;
-            tmp = scene.dynamic_actors;
-            fprintf(stderr, "delete anim %d\n", g_slist_length(tmp));
-
-        }else {
-            if (anim->func_time ) t = (*anim->func_time)(t);
-            if (anim->func_change) (*anim->func_change)(anim->actor, (double)t/anim->timeall);
+short_timeout (AWallpaperPlugin *desktop_plugin)
+{
+    gint daytime = get_daytime();
+    GSList * tmp;
+    void (*pfunc)(gpointer, gpointer);
+    time_t now;
+    Actor *actor;
+    gboolean stop_flag = TRUE;
+
+    if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
+        desktop_plugin->priv->short_timer = 0;
+        return FALSE;
+    }
+
+    now = time(NULL);
+    //scene.daytime = daytime;
+    /* fprintf(stderr, "Short timer %d\n", now); */
+    tmp = scene.actors;
+    while (tmp != NULL){
+           actor = tmp->data;
+           if (now >= actor->time_start_animation  
+               && actor->time_start_animation > 0
+               /* && now - actor->time_start_animation <= actor->duration_animation*/){
+                pfunc = actor->func_change;
+                if (pfunc){ 
+                    (*pfunc)(actor, desktop_plugin);
+                    stop_flag = FALSE;
+                }
+            }
+            tmp = g_slist_next(tmp);
+    }
+    if (stop_flag){
+         desktop_plugin->priv->short_timer = 0;
+         return FALSE;
+    }else
+         return TRUE; /* keep running this event */
+}
+
+void
+run_long_timeout(AWallpaperPlugin *desktop_plugin){
+
+    gint daytime = get_daytime();
+    GSList * tmp;
+    void (*pfunc)(gpointer, gpointer);
+    time_t now;
+    Actor *actor;
+
+
+    //fprintf(stderr, "timer daytime=%d\n", daytime);
+    if (scene.daytime != daytime){
+        scene.daytime = daytime;
+        tmp = scene.actors;
+        while (tmp != NULL){
+            //change_actor(tmp->data);
+            pfunc =((Actor*)tmp->data)->func_change;
+            if (pfunc){
+                (*pfunc)(tmp->data, desktop_plugin);
+            }
             tmp = g_slist_next(tmp);
         }
     }
-    
-  scene.daytime = daytime;
+   
+    now = time(NULL);
+    //fprintf(stderr, "Now  %d\n", now);
+    tmp = scene.actors;
+    while (tmp != NULL){
+        actor = tmp->data;
+        if (now >= actor->time_start_animation  
+            && actor->time_start_animation > 0
+            && desktop_plugin->priv->short_timer == 0){
+            /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
+            if (desktop_plugin->priv->rich_animation){
+                actor->time_start_animation = now;
+                desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
+            }
+            else {
+                (*actor->func_change)(actor, desktop_plugin);
+            }
+        }
+        tmp = g_slist_next(tmp);
+    }
+}
 
-  //double azm, alt;
-  //get_sun_pos(&alt, &azm);
-/*
-  GSList * tmp = objects_list;
-  while (tmp != NULL){
-      //processing(tmp->data);
-      
-      str = g_object_get_data(G_OBJECT(tmp->data), "name");
-      fprintf(stderr, "object: %s\n", str);
-      
-      if (str == "sun"){
-        //get_sun_screen_pos(alt, azm, &x, &y);
-        //x = tmp->data
-        //actor_set_position_full(tmp->data, x, y, 20);
-        //g_object_set_data(G_OBJECT(tmp->data), "posX", x);
-        //g_object_set_data(G_OBJECT(tmp->data), "posY", y);
-        //fprintf(stderr, "x = %d y = %d\n", x, y);
-        child = gtk_container_get_children(GTK_CONTAINER (tmp->data));
-        while (child != NULL) {
-            gtk_container_remove(GTK_CONTAINER (tmp->data), child->data);
-            child = child->next;
+static gboolean
+long_timeout (AWallpaperPlugin *desktop_plugin)
+{
+    /* fprintf(stderr, "long_timeout %i\n", desktop_plugin->priv->long_timer); */
+    if (desktop_plugin->priv->long_timer == 0 )
+        return FALSE;
+    if (!desktop_plugin->priv->visible){
+        if(desktop_plugin->priv->short_timer != 0){
+            g_source_remove(desktop_plugin->priv->short_timer);
+            desktop_plugin->priv->short_timer = 0;
         }
+        desktop_plugin->priv->long_timer = 0;
+        return FALSE;
+    }
+  
 
-         //snprintf(str, 255, "/usr/share/anwall/%s.png", name);
-         //fprintf(stderr, "!!!init object !!!!\nname = %s file = %s\n", name, str);
-             
-      }
-      
-      if (str == "town"){
-          //hildon_animation_actor_set_show(tmp->data, 0);
-      }
-      //a = tmp->data;
-      //fprintf(stderr, "--timeout %s\n", a->name);
-      tmp = g_slist_next(tmp);
-  }
-  */
-  return TRUE; /* keep running this event */
+    run_long_timeout(desktop_plugin);
+    return TRUE; /* keep running this event */
 }
 
 static void
@@ -676,39 +1401,94 @@ desktop_plugin_visible_notify (GObject    *object,
                                           GParamSpec *spec,
                                           AWallpaperPlugin *desktop_plugin)
 {
-      gboolean visible;
-      g_object_get (object, "is-on-current-desktop", &visible, NULL);
-      fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible);
+    gboolean visible;
+    g_object_get (object, "is-on-current-desktop", &visible, NULL);
+    /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
+    if (visible){
+        desktop_plugin->priv->visible = TRUE;
+        if (desktop_plugin->priv->long_timer == 0 ){
+            desktop_plugin->priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
+            run_long_timeout(desktop_plugin);
+        }
+    }else{
+        desktop_plugin->priv->visible = FALSE;
+        if (desktop_plugin->priv->long_timer != 0 ){
+            g_source_remove(desktop_plugin->priv->long_timer);
+            desktop_plugin->priv->long_timer = 0;
+        }
+    }
 }
 
+gboolean
+rich_animation_press(GtkWidget *widget, GdkEvent *event,
+                                            gpointer user_data){
+    fprintf(stderr,"gggggggggggggggggggg2222\n");
+}    
 static void
 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
 {
-    GtkWidget *label;
+    GtkWidget *rich_animation;
+    gchar           buffer[2048];
 
-    //fprintf(stderr, "!!!!!!!plugin init \n");
+
+    fprintf(stderr, "!!!!!!!plugin init \n");
     Animation_WallpaperPrivate *priv =  Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
     desktop_plugin->priv =  Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
+
     /* Load config */
     read_config(priv);
     priv->desktop_plugin = desktop_plugin;
-    label = gtk_label_new (""); 
+    desktop_plugin->priv->main_widget = gtk_fixed_new();
+
+    gtk_widget_set_size_request(desktop_plugin->priv->main_widget, 100, 32);
+    desktop_plugin->priv->right_corner = NULL;
+    snprintf(buffer, sizeof(buffer) - 1, "%s/%s/%s", THEME_PATH, desktop_plugin->priv->theme, "town0_right_corner.png");
+    desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
+    if (desktop_plugin->priv->right_corner){
+        gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
+        gtk_widget_show (desktop_plugin->priv->right_corner);
+    }
+    /* Create rich animation event */
+    rich_animation = gtk_event_box_new();
+    if(rich_animation){
+        gtk_widget_set_events(rich_animation, GDK_BUTTON_PRESS_MASK);
+        gtk_event_box_set_visible_window(GTK_EVENT_BOX(rich_animation), FALSE);
+        gtk_widget_set_size_request(rich_animation, 100, 32);
+        gtk_widget_show (rich_animation);
+        g_signal_connect(rich_animation, "button-press-event", G_CALLBACK(rich_animation_press), desktop_plugin);
+        gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), rich_animation, 0, 0);
+    }
+/*
+    GtkWidget *label = gtk_label_new ("ddddddddddddd"); 
     gtk_widget_set_size_request(label, 95, 30);
     gtk_widget_show (label);
+//    gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
+    gtk_fixed_put(GTK_FIXED(widget), label, 0, 0);
+*/
     hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
     g_signal_connect (desktop_plugin, "show-settings",
                             G_CALLBACK (lw_settings), priv);
+    gtk_widget_show (desktop_plugin->priv->main_widget);
+    gtk_container_add (GTK_CONTAINER (desktop_plugin), desktop_plugin->priv->main_widget);
+    init_applet_position();
+
+    
+    fprintf(stderr, "!!!theme = %s\n", priv->theme);
+    if (!strcmp(priv->theme,"Modern"))
+        init_scene(desktop_plugin);
+    else if (!strcmp(priv->theme,"Berlin")) 
+        init_scene1(desktop_plugin);
+    else if (!strcmp(priv->theme, "Matrix"))
+        init_scene2(desktop_plugin);
+    priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
+    priv->short_timer = 0;
+    /* TODO Move scene to priv */
+    scene.timer_type = LONG_TIMER_TYPE;
     g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
                      G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
 
-  gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
-  init_applet_position();
-  fprintf(stderr, "!!!theme = %s\n", priv->theme);
-  if (!strcmp(priv->theme,"Modern"))
-      init_scene(desktop_plugin);
-  else if (!strcmp(priv->theme,"Berlin")) 
-      init_scene1(desktop_plugin);
-  priv->timer = g_timeout_add(1000*1, plugin_on_timeout, desktop_plugin);
+   
+    //sleep(2);
 }
 
 static void
@@ -716,11 +1496,17 @@ lw_applet_finalize (GObject *object)
 {
      AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
      Animation_WallpaperPrivate *priv = desktop_plugin->priv;
-
-     if (priv->timer){
-        g_source_remove(priv->timer);
-        priv->timer = NULL;
+     
+     fprintf(stderr,"finalaze %i\n", priv->long_timer);
+     if (priv->long_timer){
+        g_source_remove(priv->long_timer);
+        priv->long_timer = 0;
+     }
+     if (priv->short_timer){
+        g_source_remove(priv->short_timer);
+        priv->short_timer = 0;
      }
+
      destroy_scene();
 }
 
@@ -731,7 +1517,7 @@ animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
     GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
 
     /* gobject */
-    gobject_class->destroy = lw_applet_finalize;
+    gobject_class->destroy = (gpointer)lw_applet_finalize;
     widget_class->realize = lw_applet_realize;
     widget_class->expose_event = lw_applet_expose_event;
 
@@ -740,4 +1526,5 @@ animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
 }
 
 static void
-animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {}
+animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {
+}