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;
50 lw_applet_realize (GtkWidget *widget)
54 screen = gtk_widget_get_screen (widget);
55 gtk_widget_set_colormap (widget,
56 gdk_screen_get_rgba_colormap (screen));
57 gtk_widget_set_app_paintable (widget,
59 GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->realize (widget);
64 lw_applet_expose_event(GtkWidget *widget,
65 GdkEventExpose *event)
69 /* Create cairo context */
70 cr = gdk_cairo_create (GDK_DRAWABLE (widget->window));
71 gdk_cairo_region (cr, event->region);
74 /* Draw alpha background */
75 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
76 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0);
82 return GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->expose_event (widget,
87 expose_event (GtkWidget *widget,GdkEventExpose *event,
91 GdkPixbuf *pixbuf = (GdkPixbuf *) data;
93 cr = gdk_cairo_create(widget->window);
95 gdk_cairo_region(cr, event->region);
96 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
97 gdk_cairo_set_source_pixbuf(cr, pixbuf, 0.0, 0.0);
105 realize (GtkWidget *widget)
108 screen = gtk_widget_get_screen (widget);
109 gtk_widget_set_colormap (widget, gdk_screen_get_rgba_colormap (screen));
112 /* Set position of widget on desktop */
114 init_applet_position(void)
116 GSList *position = NULL;
120 GError *error = NULL;
121 GConfClient *gconf_client = gconf_client_get_default ();
122 position_key = g_strdup_printf (GCONF_KEY_POSITION, PLUGIN_NAME);
123 position = gconf_client_get_list (gconf_client,
127 if (position && position->data && position->next->data){
128 xapplet = GPOINTER_TO_INT (position->data);
129 yapplet = GPOINTER_TO_INT (position->next->data);
131 position = g_slist_prepend (g_slist_prepend (NULL,
132 GINT_TO_POINTER (Ystartposition)),
133 GINT_TO_POINTER (Xstartposition));
134 gconf_client_set_list (gconf_client,
139 xapplet = Xstartposition;
140 yapplet = Ystartposition;
142 g_free (position_key);
143 modified = g_strdup_printf ("%i", 0);
144 modified_key = g_strdup_printf (GCONF_KEY_MODIFIED, PLUGIN_NAME);
145 gconf_client_set_string (gconf_client,
150 g_free(modified_key);
151 gconf_client_clear_cache(gconf_client);
152 g_object_unref(gconf_client);
156 actor_set_position_full(GtkWidget *actor, gint x, gint y, gint z)
158 /* fprintf(stderr, "actor_set_position_full z=%d\n", z); */
159 hildon_animation_actor_set_position_full (HILDON_ANIMATION_ACTOR (actor),x-xapplet, y-yapplet, z);
163 path_line(gint x0, gint x1, double t)
166 return ((x1 - x0) * t + x0);
171 destroy_hildon_actor(Actor *actor)
173 //fprintf(stderr, "destroy_hildon_actor %s\n",actor->name);
174 gtk_widget_destroy(actor->widget);
175 actor->widget = NULL;
179 init_object(AWallpaperPlugin *desktop_plugin,
191 void (*pfunc_change)(Actor*),
192 void (*pfunc_probability)(Actor*),
197 actor = g_new0(Actor, 1);
201 actor->width = width;
202 actor->height = height;
203 actor->visible = visible;
204 actor->scale = scale;
205 actor->opacity = opacity;
206 actor->filename = g_strdup(filename);
207 actor->name = g_strdup(name);
208 actor->func_change = (gpointer)pfunc_change;
209 actor->func_probability = (gpointer)pfunc_probability;
210 actor->child = child;
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(10) + 1) * 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(&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) + probability_sun();
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,
333 //fprintf(stderr, "change tram\n");
334 gettimeofday(&tvb, NULL);
339 if (!actor->visible){
340 actor->visible = TRUE;
341 if (scene.daytime == TIME_NIGHT){
343 g_free(actor->filename);
344 actor->filename = g_strdup("tram_dark.png");
347 g_free(actor->filename);
348 actor->filename = g_strdup("tram.png");
350 create_hildon_actor(actor, desktop_plugin);
352 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
353 x = path_line(x0, x1, t);
354 y = path_line(y0, y1, t);
355 scale = path_line(scale0, scale1, t);
356 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
357 actor_set_position_full(actor->widget, x, y, actor->z);
358 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
361 actor->visible = FALSE;
362 destroy_hildon_actor(actor);
363 actor->time_start_animation = sec + fast_rnd(60);
368 change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
370 gint x0 = 620, y0 = 233,
378 gettimeofday(&tvb, NULL);
382 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
384 if (scene.daytime != TIME_NIGHT){
385 if (actor->time_start_animation == 0){
386 actor->time_start_animation = sec + probability_plane();
390 if (!actor->visible){
391 actor->visible = TRUE;
392 create_hildon_actor(actor, desktop_plugin);
394 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
395 x = path_line(x0, x1, t);
396 y = path_line(y0, y1, t);
397 //scale = path_line(scale0, scale1, t);
398 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
399 actor_set_position_full(actor->widget, x, y, actor->z);
400 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
403 actor->visible = FALSE;
404 destroy_hildon_actor(actor);
405 if (scene.daytime == TIME_NIGHT)
406 actor->time_start_animation = 0;
408 actor->time_start_animation = sec + probability_plane();
414 change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
416 gint x0 = -actor->width, y0 = 45,
424 gettimeofday(&tvb, NULL);
428 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
429 if (scene.daytime != TIME_NIGHT){
430 if (actor->time_start_animation == 0){
431 actor->time_start_animation = sec + probability_plane();
435 if (!actor->visible){
436 actor->visible = TRUE;
437 create_hildon_actor(actor, desktop_plugin);
440 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
441 x = path_line(x0, x1, t);
442 y = path_line(y0, y1, t);
443 //scale = path_line(scale0, scale1, t);
444 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
445 actor_set_position_full(actor->widget, x, y, actor->z);
446 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
449 actor->visible = FALSE;
450 destroy_hildon_actor(actor);
451 if (scene.daytime == TIME_NIGHT)
452 actor->time_start_animation = 0;
454 actor->time_start_animation = sec + probability_plane();
460 change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
462 gint x0, y0 = 300, scale0 = 100,
463 x1, y1 = -actor->height, scale1 = 150,
471 //fprintf(stderr, "change cloud\n");
472 gettimeofday(&tvb, NULL);
476 //fprintf(stderr, "c1oud %s - y0=%d\n", actor->name, actor->y);
478 if (!actor->visible){
479 actor->visible = TRUE;
480 if (scene.daytime == TIME_NIGHT){
481 newfile = g_strdup_printf("%s_dark.png", actor->name);
483 newfile = g_strdup_printf("%s.png", actor->name);
486 g_free(actor->filename);
487 actor->filename = newfile;
490 create_hildon_actor(actor, desktop_plugin);
492 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
494 if (scene.wind_orientation == 1){
503 x = path_line(x0, x1, t);
504 y = -scene.wind_angle * (x - x0) + actor->y;
505 scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
507 //fprintf(stderr, "change cloud t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
508 actor_set_position_full(actor->widget, x, y, actor->z);
509 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
510 if ((y < y1 || y > y0) || t >= 1){
512 actor->visible = FALSE;
513 destroy_hildon_actor(actor);
514 actor->time_start_animation = sec + fast_rnd(300);
515 actor->y = fast_rnd(300);
521 change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
523 scene.wind_orientation = fast_rnd(2);
524 if (scene.wind_orientation == 0) scene.wind_orientation = -1;
525 scene.wind_angle = (double)(fast_rnd(200) - 100) / 100;
526 actor->time_start_animation = time(NULL) + (fast_rnd(10) + 10) * 60;
527 //fprintf(stderr, "change wind orient = %d angle = %f after = %d\n", scene.wind_orientation, scene.wind_angle, actor->time_start_animation-time(NULL));
531 change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin)
534 gint now = time(NULL);
535 if (scene.daytime == TIME_DAY){
537 actor->visible = FALSE;
538 destroy_hildon_actor(actor);
540 actor->time_start_animation = 0;
542 }else if (actor->time_start_animation == 0){
543 actor->time_start_animation = now + fast_rnd(30);
547 if (!actor->visible){
548 actor->visible = TRUE;
549 create_hildon_actor(actor, desktop_plugin);
550 actor->time_start_animation = now + fast_rnd(60) + 10;
552 actor->visible = FALSE;
553 destroy_hildon_actor(actor);
554 actor->time_start_animation = now + fast_rnd(60) + 10;
560 change_signal(Actor * actor, AWallpaperPlugin *desktop_plugin)
562 gint now = time(NULL);
566 gint now = time(NULL);
567 newfile = g_strdup_printf("%s%d.png", actor->name, scene.daytime);
568 if (!strcmp(actor->filename, "red.png"))
569 newfile = g_strdup_printf("%s", "green.png");
571 newfile = g_strdup_printf("%s", "red.png");
572 g_free(actor->filename);
573 actor->filename = newfile;
574 change_hildon_actor(actor, desktop_plugin);
575 actor->time_start_animation = now + fast_rnd(30) + 10;
577 a = g_ptr_array_index(actor->child, 0);
578 //fprintf(stderr, "actor name= %p \n", child->widget);
583 hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(a->widget), a->visible);
585 a = g_ptr_array_index(actor->child, 1);
586 //fprintf(stderr, "actor name= %s \n", child->name);
591 hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(a->widget), a->visible);
593 actor->time_start_animation = now + fast_rnd(30) + 10;
597 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
599 GtkWidget *ha = NULL;
600 GdkPixbuf *pixbuf = NULL;
601 GtkWidget *image = NULL;
604 ha = hildon_animation_actor_new();
605 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
606 desktop_plugin->priv->theme, actor->filename);
607 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
611 /*fprintf(stderr, "create_hildon_actor %s %s\n", actor->name, str);*/
615 image = gtk_image_new_from_pixbuf (pixbuf);
616 g_object_unref(G_OBJECT(pixbuf));
619 g_signal_connect(G_OBJECT(image), "expose_event",
620 G_CALLBACK(expose_event), pixbuf);
621 gtk_container_add (GTK_CONTAINER (ha), image);
623 actor_set_position_full(ha, actor->x, actor->y, actor->z);
624 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(ha), (double)actor->scale/100, (double)actor->scale/100);
626 gtk_widget_show_all(ha);
627 hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(ha), actor->visible);
632 //g_object_set_data(G_OBJECT(ha), "name", name);
633 //g_object_set_data(G_OBJECT(ha), "filename", filename);
634 g_object_set_data(G_OBJECT(ha), "image", image);
636 g_object_set_data(G_OBJECT(ha), "x", x);
637 g_object_set_data(G_OBJECT(ha), "y", y);
638 g_object_set_data(G_OBJECT(ha), "z", z);
639 g_object_set_data(G_OBJECT(ha), "width", width);
640 g_object_set_data(G_OBJECT(ha), "height", height);
641 g_object_set_data(G_OBJECT(ha), "scale", scale);
642 g_object_set_data(G_OBJECT(ha), "visible", visible);
643 g_object_set_data(G_OBJECT(ha), "opacity", opacity);
644 g_object_set_data(G_OBJECT(ha), "func", pfunc);
646 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
652 change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
654 GtkWidget *image = NULL;
655 GdkPixbuf *pixbuf = NULL;
658 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
659 desktop_plugin->priv->theme, actor->filename);
661 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
668 image = gtk_image_new_from_pixbuf (pixbuf);
669 g_object_unref(G_OBJECT(pixbuf));
672 g_signal_connect(G_OBJECT(image), "expose_event",
673 G_CALLBACK(expose_event), pixbuf);
674 if (g_object_get_data(G_OBJECT(actor->widget), "image")){
675 gtk_container_remove(GTK_CONTAINER(actor->widget), g_object_get_data(G_OBJECT(actor->widget), "image"));
677 g_object_set_data(G_OBJECT(actor->widget), "image", image);
678 gtk_container_add (GTK_CONTAINER (actor->widget), image);
679 realize(actor->widget);
680 gtk_widget_show_all(actor->widget);
691 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
694 newfile = g_strdup_printf("%s%d.png", actor->name, scene.daytime);
696 g_free(actor->filename);
697 actor->filename = newfile;
698 change_hildon_actor(actor, desktop_plugin);
702 change_static_actor_with_corner(Actor * actor, AWallpaperPlugin *desktop_plugin)
706 if (desktop_plugin->priv->right_corner)
707 gtk_widget_destroy(desktop_plugin->priv->right_corner);
708 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/town%i_right_corner.png", \
709 THEME_PATH, desktop_plugin->priv->theme, scene.daytime);
710 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
711 if (desktop_plugin->priv->right_corner){
712 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
713 gtk_widget_show (desktop_plugin->priv->right_corner);
715 change_static_actor(actor, desktop_plugin);
720 change_layer(Actor * actor, AWallpaperPlugin *desktop_plugin)
725 a = g_ptr_array_index(actor->child, 0);
727 if (y > 480) y = -480;
728 //fprintf(stderr, "!! %s - %d\n", actor->name, y);
729 actor_set_position_full(a->widget, a->x, y, a->z);
732 a = g_ptr_array_index(actor->child, 1);
734 if (y > 480) y = -480;
735 //fprintf(stderr, "!! %s - %d\n", actor->name, y);
736 actor_set_position_full(a->widget, a->x, y, a->z);
739 a = g_ptr_array_index(actor->child, 2);
741 if (y > 480) y = -480;
742 //fprintf(stderr, "!! %s - %d\n", actor->name, y);
743 actor_set_position_full(a->widget, a->x, y, a->z);
746 a = g_ptr_array_index(actor->child, 3);
748 if (y > 480) y = -480;
749 //fprintf(stderr, "!! %s - %d\n", actor->name, y);
750 actor_set_position_full(a->widget, a->x, y, a->z);
756 change_layer1(Actor * actor, AWallpaperPlugin *desktop_plugin)
760 if (y > 480) y = -480;
761 //fprintf(stderr, "!! %s - %d\n", actor->name, y);
762 actor_set_position_full(actor->widget, actor->x, y, actor->z);
767 change_layer2(Actor * actor, AWallpaperPlugin *desktop_plugin)
771 if (y >= 480) y = -480;
772 //fprintf(stderr, "!! %s - %d\n", actor->name, y);
773 actor_set_position_full(actor->widget, actor->x, y, actor->z);
780 // уравнение изменения времени
786 GSList * tmp = scene.actors;
792 g_ptr_array_free(actor->child, TRUE);
795 g_free(actor->filename);
798 gtk_widget_destroy(actor->widget);
799 //actor->widget = NULL;
802 tmp = g_slist_next(tmp);
809 reload_scene(AWallpaperPlugin *desktop_plugin)
811 fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);
813 if (!strcmp(desktop_plugin->priv->theme,"Modern"))
814 init_scene(desktop_plugin);
815 else if (!strcmp(desktop_plugin->priv->theme,"Berlin"))
816 init_scene1(desktop_plugin);
817 else if (!strcmp(desktop_plugin->priv->theme,"Matrix"))
818 init_scene2(desktop_plugin);
823 init_scene2(AWallpaperPlugin *desktop_plugin)
827 gint now = time(NULL);
829 fprintf(stderr, "init scene2 \n");
830 //scene.daytime = get_daytime();
834 actor = init_object(desktop_plugin, "background", "bg.png",
836 TRUE, TRUE, 100, 255,
838 scene.actors = g_slist_append(scene.actors, actor);
840 actor = init_object(desktop_plugin, "symbols", "symbols.png",
842 TRUE, TRUE, 100, 255,
844 scene.actors = g_slist_append(scene.actors, actor);
846 child = g_ptr_array_sized_new(4);
847 actor = init_object(desktop_plugin, "layer1", "layer1_2.png",
848 0, -480, 6, 800, 960,
849 TRUE, TRUE, 100, 255,
851 //actor->time_start_animation = now;
852 //actor->duration_animation = G_MAXINT;
853 scene.actors = g_slist_append(scene.actors, actor);
854 g_ptr_array_add(child, actor);
856 actor = init_object(desktop_plugin, "layer1", "layer1_1.png",
857 0, (-480 - 480), 7, 800, 960,
858 TRUE, TRUE, 100, 255,
860 //actor->time_start_animation = now;
861 //actor->duration_animation = G_MAXINT;
862 scene.actors = g_slist_append(scene.actors, actor);
863 g_ptr_array_add(child, actor);
865 actor = init_object(desktop_plugin, "layer2", "layer2_2.png",
866 0, -480, 8, 800, 960,
867 TRUE, TRUE, 100, 255,
869 //actor->time_start_animation = now;
870 //actor->duration_animation = G_MAXINT;
871 scene.actors = g_slist_append(scene.actors, actor);
872 g_ptr_array_add(child, actor);
874 actor = init_object(desktop_plugin, "layer2", "layer2_1.png",
875 0, (-480 - 480), 9, 800, 960,
876 TRUE, TRUE, 100, 255,
878 //actor->time_start_animation = now;
879 //actor->duration_animation = G_MAXINT;
880 scene.actors = g_slist_append(scene.actors, actor);
881 g_ptr_array_add(child, actor);
883 actor = init_object(desktop_plugin, "layers", "",
884 0, (-480 - 480), 9, 800, 960,
885 FALSE, FALSE, 100, 255,
886 (gpointer)&change_layer, NULL, child);
887 actor->time_start_animation = now;
888 actor->duration_animation = G_MAXINT;
889 scene.actors = g_slist_append(scene.actors, actor);
891 run_long_timeout(desktop_plugin);
894 /* Init Modern Scene */
896 init_scene(AWallpaperPlugin *desktop_plugin)
899 gint now = time(NULL);
903 /* fprintf(stderr, "init scene \n");*/
904 scene.daytime = get_daytime();
906 scene.wind_orientation = -1;
907 scene.wind_angle = 0.3;
908 /* init value for random */
909 scene.seed = time(NULL);
911 actor = init_object(desktop_plugin, "sky", "sky0.png",
913 TRUE , TRUE, 100, 255,
914 (gpointer)&change_static_actor, NULL, NULL);
915 change_static_actor(actor, desktop_plugin);
916 scene.actors = g_slist_append(scene.actors, actor);
918 actor = init_object(desktop_plugin, "sun", "sun.png",
920 FALSE, FALSE, 100, 255,
921 (gpointer)&change_sun, (gpointer)&probability_sun, NULL);
922 actor->time_start_animation = now;
923 actor->duration_animation = G_MAXINT;
924 change_sun(actor, desktop_plugin);
925 scene.actors = g_slist_append(scene.actors, actor);
927 //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
928 // TRUE, 100, 255, NULL, NULL);
929 //scene.actors = g_slist_append(scene.actors, actor);
931 actor = init_object(desktop_plugin, "cloud1", "cloud1.png",
932 0, fast_rnd(300)-97, 7, 150, 97,
933 FALSE, FALSE, 100, 255,
934 (gpointer)&change_cloud, NULL, NULL);
935 actor->time_start_animation = now + fast_rnd(20);
936 actor->duration_animation = 3*60;
937 scene.actors = g_slist_append(scene.actors, actor);
939 actor = init_object(desktop_plugin, "cloud2", "cloud2.png",
940 0, fast_rnd(300)-75, 7, 188, 75,
941 FALSE, FALSE, 100, 255,
942 (gpointer)&change_cloud, NULL, NULL);
943 actor->time_start_animation = now + fast_rnd(40)+10;
944 actor->duration_animation = 3*60;
945 scene.actors = g_slist_append(scene.actors, actor);
947 actor = init_object(desktop_plugin, "cloud4", "cloud4.png",
948 0, fast_rnd(300)-75, 7, 150, 75,
949 FALSE, FALSE, 100, 255,
950 (gpointer)&change_cloud, NULL, NULL);
951 actor->time_start_animation = now + fast_rnd(60) + 20;
952 actor->duration_animation = 5*60;
953 scene.actors = g_slist_append(scene.actors, actor);
956 actor = init_object(desktop_plugin, "town", "town0.png",
958 TRUE, TRUE, 100, 255,
959 (gpointer)&change_static_actor, NULL, NULL);
960 change_static_actor(actor, desktop_plugin);
961 scene.actors = g_slist_append(scene.actors, actor);
963 actor = init_object(desktop_plugin, "tram", "tram.png",
964 -300, 225, 9, 350, 210,
965 FALSE, FALSE, 100, 255,
966 (gpointer)&change_tram, NULL, NULL);
967 actor->time_start_animation = time(NULL) + fast_rnd(10);
968 actor->duration_animation = 60;
969 scene.actors = g_slist_append(scene.actors, actor);
971 actor = init_object(desktop_plugin, "border", "border0.png",
972 0, 480-79, 10, 800, 79,
973 TRUE, TRUE, 100, 255,
974 (gpointer)&change_static_actor_with_corner, NULL, NULL);
975 change_static_actor_with_corner(actor, desktop_plugin);
976 scene.actors = g_slist_append(scene.actors, actor);
978 actor = init_object(desktop_plugin, "moon", "moon1.png",
980 FALSE, FALSE, 100, 255,
981 (gpointer)&change_moon, NULL, NULL);
982 change_moon(actor, desktop_plugin);
983 scene.actors = g_slist_append(scene.actors, actor);
985 actor = init_object(desktop_plugin, "wind", "",
987 FALSE, FALSE, 100, 255,
988 (gpointer)&change_wind, NULL, NULL);
989 change_wind(actor, desktop_plugin);
990 scene.actors = g_slist_append(scene.actors, actor);
992 /* windows in 4-th house */
1032 for (i=0; i<13; i++){
1033 actor = init_object(desktop_plugin, "window1", "window1.png",
1034 winds[i][0], winds[i][1], 8, 8, 10,
1035 FALSE, FALSE, 100, 255,
1036 (gpointer)&change_window1, NULL, NULL);
1037 //change_window1(actor, desktop_plugin);
1038 actor->time_start_animation = now + fast_rnd(30);
1039 scene.actors = g_slist_append(scene.actors, actor);
1043 /* windows in 1-th house */
1068 for (i=0; i<8; i++){
1069 actor = init_object(desktop_plugin, "window2", "window2.png",
1070 winds[i][0], winds[i][1], 8, 8, 10,
1071 FALSE, FALSE, 100, 255,
1072 (gpointer)&change_window1, NULL, NULL);
1073 //change_window1(actor, desktop_plugin);
1074 actor->time_start_animation = now + fast_rnd(30);
1075 scene.actors = g_slist_append(scene.actors, actor);
1079 /* windows in 3-th house */
1111 for (i=0; i<10; i++){
1112 actor = init_object(desktop_plugin, "window3", "window3.png",
1113 winds[i][0], winds[i][1], 8, 8, 10,
1114 FALSE, FALSE, 100, 255,
1115 (gpointer)&change_window1, NULL, NULL);
1116 //change_window1(actor, desktop_plugin);
1117 actor->time_start_animation = now + fast_rnd(30);
1118 scene.actors = g_slist_append(scene.actors, actor);
1122 /* windows in 5-th house */
1145 for (i=0; i<7; i++){
1146 actor = init_object(desktop_plugin, "window4", "window4.png",
1147 winds[i][0], winds[i][1], 8, 8, 10,
1148 FALSE, FALSE, 100, 255,
1149 (gpointer)&change_window1, NULL, NULL);
1150 //change_window1(actor, desktop_plugin);
1151 actor->time_start_animation = now + fast_rnd(30);
1152 scene.actors = g_slist_append(scene.actors, actor);
1156 /* windows in 6-th house */
1176 for (i=0; i<6; i++){
1177 actor = init_object(desktop_plugin, "window5", "window5.png",
1178 winds[i][0], winds[i][1], 8, 8, 10,
1179 FALSE, FALSE, 100, 255,
1180 (gpointer)&change_window1, NULL, NULL);
1181 //change_window1(actor, desktop_plugin);
1182 actor->time_start_animation = now + fast_rnd(30);
1183 scene.actors = g_slist_append(scene.actors, actor);
1187 run_long_timeout(desktop_plugin);
1190 anim = g_new0(Animation, 1);
1192 anim->actor = actor;
1193 anim->func_change = &change_tram;
1194 anim->func_time = NULL;
1195 anim->timestart = time(NULL);
1198 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
1202 /* Init Berlin Scene */
1204 init_scene1(AWallpaperPlugin *desktop_plugin)
1206 Actor *actor, *actor1, *actor2;
1207 gint now = time(NULL);
1210 GPtrArray *child = NULL;
1212 scene.daytime = get_daytime();
1213 scene.actors = NULL;
1214 scene.wind_orientation = -1;
1215 scene.wind_angle = 0.3;
1216 /* init value for random */
1217 scene.seed = time(NULL);
1220 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
1221 TRUE, TRUE, 100, 255,
1222 (gpointer)&change_static_actor, NULL, NULL);
1223 change_static_actor(actor, desktop_plugin);
1224 scene.actors = g_slist_append(scene.actors, actor);
1227 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
1228 FALSE, FALSE, 100, 255,
1229 (gpointer)&change_sun, (gpointer)&probability_sun, NULL);
1230 actor->time_start_animation = time(NULL);
1231 actor->duration_animation = G_MAXINT;
1232 change_sun(actor, desktop_plugin);
1233 scene.actors = g_slist_append(scene.actors, actor);
1236 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
1237 TRUE, 100, 255, NULL, NULL);
1238 scene.actors = g_slist_append(scene.actors, actor);
1241 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
1242 FALSE, FALSE, 100, 255,
1243 (gpointer)&change_moon, NULL, NULL);
1244 change_moon(actor, desktop_plugin);
1245 scene.actors = g_slist_append(scene.actors, actor);
1247 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
1248 FALSE, FALSE, 100, 255,
1249 (gpointer)&change_cloud, NULL, NULL);
1250 actor->time_start_animation = now + fast_rnd(180);
1251 actor->duration_animation = 3*60;
1252 scene.actors = g_slist_append(scene.actors, actor);
1254 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
1255 FALSE, FALSE, 100, 255,
1256 (gpointer)&change_cloud, NULL, NULL);
1257 actor->time_start_animation = now + fast_rnd(180);
1258 actor->duration_animation = 3*60;
1259 scene.actors = g_slist_append(scene.actors, actor);
1261 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
1262 FALSE, FALSE, 100, 255,
1263 (gpointer)&change_cloud, NULL, NULL);
1264 actor->time_start_animation = now + fast_rnd(180);
1265 actor->duration_animation = 5*60;
1266 scene.actors = g_slist_append(scene.actors, actor);
1269 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
1270 FALSE, FALSE, 100, 255,
1271 (gpointer)&change_plane2, NULL, NULL);
1272 actor->time_start_animation = now + probability_plane();
1273 actor->duration_animation = 60;
1274 scene.actors = g_slist_append(scene.actors, actor);
1276 actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116,
1277 FALSE, FALSE, 100, 255,
1278 (gpointer)&change_plane1, NULL, NULL);
1279 actor->time_start_animation = now + probability_plane();
1280 actor->duration_animation = 30;
1281 scene.actors = g_slist_append(scene.actors, actor);
1283 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
1284 TRUE, TRUE, 100, 255,
1285 (gpointer)&change_static_actor_with_corner, NULL, NULL);
1286 change_static_actor_with_corner(actor, desktop_plugin);
1287 scene.actors = g_slist_append(scene.actors, actor);
1289 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
1290 FALSE, FALSE, 100, 255,
1291 (gpointer)&change_wind, NULL, NULL);
1292 change_wind(actor, desktop_plugin);
1293 scene.actors = g_slist_append(scene.actors, actor);
1295 actor1 = init_object(desktop_plugin, "signal_red", "red.png",
1296 486, 425, 10, 18, 38,
1297 FALSE, TRUE, 100, 255, NULL, NULL, NULL);
1298 //actor->time_start_animation = now + fast_rnd(30) + 10;
1299 scene.actors = g_slist_append(scene.actors, actor1);
1301 actor2 = init_object(desktop_plugin, "signal_green", "green.png",
1302 486, 425, 10, 18, 38,
1303 TRUE, TRUE, 100, 255, NULL, NULL, NULL);
1304 //actor->time_start_animation = now + fast_rnd(30) + 10;
1305 scene.actors = g_slist_append(scene.actors, actor2);
1306 child = g_ptr_array_sized_new(2);
1307 g_ptr_array_add(child, actor1);
1308 g_ptr_array_add(child, actor2);
1309 actor = init_object(desktop_plugin, "signal", "",
1310 486, 425, 10, 18, 38,
1311 FALSE, FALSE, 100, 255,
1312 (gpointer)&change_signal, NULL, child);
1313 actor->time_start_animation = now + fast_rnd(30) + 10;
1314 scene.actors = g_slist_append(scene.actors, actor);
1355 for (i=0; i<13; i++){
1356 actor = init_object(desktop_plugin, "window", "window.png",
1357 winds[i][0], winds[i][1], 10, 8, 9,
1358 FALSE, TRUE, 100, 255,
1359 (gpointer)&change_window1, NULL, NULL);
1360 //change_window1(actor, desktop_plugin);
1361 actor->time_start_animation = now + fast_rnd(30);
1362 scene.actors = g_slist_append(scene.actors, actor);
1366 run_long_timeout(desktop_plugin);
1372 get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
1374 gint y0 = 365;// - уровень горизонта
1375 *x = (int)(azm * 800) - 64;
1376 *y = (int)((1 - alt) * y0) - 64;
1377 //fprintf(stderr, "sun pos alt=%f azm=%f x=%d y=%d\n", alt, azm, *x, *y);
1381 change_actor(GtkWidget * actor)
1384 gint x, y, daytime, scale;
1391 void (*pfunc)(gpointer, gpointer);
1393 name = g_object_get_data(G_OBJECT(actor), "name");
1394 fprintf(stderr, "change actor %s\n", name);
1396 pfunc = g_object_get_data(G_OBJECT(actor), "func");
1398 (*pfunc)(actor, g_strdup(name));
1399 daytime = get_daytime();
1400 if (daytime != TIME_NIGHT){
1401 hildon_animation_actor_set_show(actor, 1);
1402 get_sun_pos(&alt, &azm);
1403 get_sun_screen_pos(alt, azm, &x, &y);
1404 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
1408 if (name == "cloud1"){
1409 x = g_object_get_data(G_OBJECT(actor), "x");
1410 y = g_object_get_data(G_OBJECT(actor), "y");
1411 scale = g_object_get_data(G_OBJECT(actor), "scale");
1414 image = g_object_get_data(G_OBJECT(actor), "image");
1416 gtk_container_remove(actor, image);
1417 pixbuf = gdk_pixbuf_new_from_file_at_size ("/usr/share/livewp/theme/Modern/sun.png",
1422 image = gtk_image_new_from_pixbuf (pixbuf);
1423 g_object_unref(G_OBJECT(pixbuf));
1425 g_signal_connect(G_OBJECT(image), "expose_event",
1426 G_CALLBACK(expose_event), pixbuf);
1427 gtk_container_add (GTK_CONTAINER (actor), image);
1429 gtk_widget_show_all(actor);
1441 sc = (double)scale / 100;
1442 hildon_animation_actor_set_scale(actor, sc, sc);
1443 fprintf(stderr, "cloud x=%d y=%d scale=%f", x, y, sc);
1444 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
1445 g_object_set_data(G_OBJECT(actor), "x", x);
1446 g_object_set_data(G_OBJECT(actor), "y", y);
1447 g_object_set_data(G_OBJECT(actor), "scale", scale);
1453 short_timeout (AWallpaperPlugin *desktop_plugin)
1455 //gint daytime = get_daytime();
1457 void (*pfunc)(gpointer, gpointer);
1460 gboolean stop_flag = TRUE;
1462 if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
1463 desktop_plugin->priv->short_timer = 0;
1468 //scene.daytime = daytime;
1469 /* fprintf(stderr, "Short timer %d\n", now); */
1471 while (tmp != NULL){
1473 if (now >= actor->time_start_animation
1474 && actor->time_start_animation > 0
1475 /* && now - actor->time_start_animation <= actor->duration_animation*/){
1476 pfunc = actor->func_change;
1478 (*pfunc)(actor, desktop_plugin);
1482 tmp = g_slist_next(tmp);
1485 desktop_plugin->priv->short_timer = 0;
1488 return TRUE; /* keep running this event */
1492 run_long_timeout(AWallpaperPlugin *desktop_plugin)
1495 gint daytime = get_daytime();
1497 void (*pfunc)(gpointer, gpointer);
1502 //fprintf(stderr, "!!!run long timeout short_timer=%d\n", desktop_plugin->priv->short_timer);
1503 if (scene.daytime != daytime){
1504 scene.daytime = daytime;
1506 while (tmp != NULL){
1507 //change_actor(tmp->data);
1508 pfunc =((Actor*)tmp->data)->func_change;
1510 (*pfunc)(tmp->data, desktop_plugin);
1512 tmp = g_slist_next(tmp);
1517 //fprintf(stderr, "Now %d\n", now);
1519 while (tmp != NULL){
1521 if (now >= actor->time_start_animation
1522 && actor->time_start_animation > 0
1523 && desktop_plugin->priv->short_timer == 0){
1524 /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
1525 if (desktop_plugin->priv->rich_animation){
1526 actor->time_start_animation = now;
1527 desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
1530 (*actor->func_change)(actor, desktop_plugin);
1533 tmp = g_slist_next(tmp);
1539 long_timeout (AWallpaperPlugin *desktop_plugin)
1541 /* fprintf(stderr, "long_timeout %i\n", desktop_plugin->priv->long_timer); */
1542 if (desktop_plugin->priv->long_timer == 0 )
1544 if (!desktop_plugin->priv->visible){
1545 if(desktop_plugin->priv->short_timer != 0){
1546 g_source_remove(desktop_plugin->priv->short_timer);
1547 desktop_plugin->priv->short_timer = 0;
1549 desktop_plugin->priv->long_timer = 0;
1554 run_long_timeout(desktop_plugin);
1555 return TRUE; /* keep running this event */
1559 desktop_plugin_visible_notify (GObject *object,
1561 AWallpaperPlugin *desktop_plugin)
1564 g_object_get (object, "is-on-current-desktop", &visible, NULL);
1565 /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
1567 desktop_plugin->priv->visible = TRUE;
1568 if (desktop_plugin->priv->long_timer == 0 ){
1569 desktop_plugin->priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1570 run_long_timeout(desktop_plugin);
1573 desktop_plugin->priv->visible = FALSE;
1574 if (desktop_plugin->priv->long_timer != 0 ){
1575 g_source_remove(desktop_plugin->priv->long_timer);
1576 desktop_plugin->priv->long_timer = 0;
1582 rich_animation_press(GtkWidget *widget, GdkEvent *event,
1583 gpointer user_data){
1584 fprintf(stderr,"gggggggggggggggggggg2222\n");
1588 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
1590 GtkWidget *rich_animation;
1594 fprintf(stderr, "!!!!!!!plugin init \n");
1595 Animation_WallpaperPrivate *priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1596 desktop_plugin->priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1597 priv->osso = osso_initialize(PACKAGE, VERSION, TRUE, NULL);
1601 /* Initialize DBUS */
1602 livewp_initialize_dbus(priv);
1604 priv->desktop_plugin = desktop_plugin;
1605 priv->visible = TRUE;
1606 priv->short_timer = 0;
1607 priv->theme = g_strdup("Modern");
1608 desktop_plugin->priv->main_widget = gtk_fixed_new();
1610 gtk_widget_set_size_request(desktop_plugin->priv->main_widget, 100, 32);
1611 desktop_plugin->priv->right_corner = NULL;
1612 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/%s", THEME_PATH, desktop_plugin->priv->theme, "town0_right_corner.png");
1613 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
1614 if (desktop_plugin->priv->right_corner){
1615 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
1616 gtk_widget_show (desktop_plugin->priv->right_corner);
1618 /* Create rich animation event */
1619 rich_animation = gtk_event_box_new();
1621 gtk_widget_set_events(rich_animation, GDK_BUTTON_PRESS_MASK);
1622 gtk_event_box_set_visible_window(GTK_EVENT_BOX(rich_animation), FALSE);
1623 gtk_widget_set_size_request(rich_animation, 100, 32);
1624 gtk_widget_show (rich_animation);
1625 g_signal_connect(rich_animation, "button-press-event", G_CALLBACK(rich_animation_press), desktop_plugin);
1626 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), rich_animation, 0, 0);
1629 GtkWidget *label = gtk_label_new ("ddddddddddddd");
1630 gtk_widget_set_size_request(label, 95, 30);
1631 gtk_widget_show (label);
1632 // gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
1633 gtk_fixed_put(GTK_FIXED(widget), label, 0, 0);
1635 hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
1636 g_signal_connect (desktop_plugin, "show-settings",
1637 G_CALLBACK (show_settings), priv);
1638 gtk_widget_show (desktop_plugin->priv->main_widget);
1639 gtk_container_add (GTK_CONTAINER (desktop_plugin), desktop_plugin->priv->main_widget);
1640 init_applet_position();
1643 fprintf(stderr, "!!!theme = %s\n", priv->theme);
1644 if (!strcmp(priv->theme,"Modern"))
1645 init_scene(desktop_plugin);
1646 else if (!strcmp(priv->theme,"Berlin"))
1647 init_scene1(desktop_plugin);
1648 else if (!strcmp(priv->theme, "Matrix"))
1649 init_scene2(desktop_plugin);
1650 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1651 /* TODO Move scene to priv */
1652 scene.timer_type = LONG_TIMER_TYPE;
1653 g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
1654 G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
1661 lw_applet_finalize (GObject *object)
1663 AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
1664 Animation_WallpaperPrivate *priv = desktop_plugin->priv;
1666 fprintf(stderr,"finalaze %i\n", priv->long_timer);
1667 if (priv->long_timer){
1668 g_source_remove(priv->long_timer);
1669 priv->long_timer = 0;
1671 if (priv->short_timer){
1672 g_source_remove(priv->short_timer);
1673 priv->short_timer = 0;
1680 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
1682 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1683 GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
1686 gobject_class->destroy = (gpointer)lw_applet_finalize;
1687 widget_class->realize = lw_applet_realize;
1688 widget_class->expose_event = lw_applet_expose_event;
1690 g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));
1695 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {