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 "livewp-actor.h"
28 #include <gconf/gconf-client.h>
29 #include "livewp-rules.h"
33 #define PLUGIN_NAME "livewp-home-widget.desktop-0"
34 #define GCONF_KEY_POSITION "/apps/osso/hildon-desktop/applets/%s/position"
35 #define GCONF_KEY_MODIFIED "/apps/osso/hildon-desktop/applets/%s/modified"
36 #define GCONF_KEY_VIEW "/apps/osso/hildon-desktop/applets/%s/view"
38 HD_DEFINE_PLUGIN_MODULE (AWallpaperPlugin, animation_wallpaper_plugin, HD_TYPE_HOME_PLUGIN_ITEM)
39 #define Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE (obj,\
40 Animation_Wallpaper_TYPE_HOME_PLUGIN,\
41 Animation_WallpaperPrivate))
43 /* Position of plugin on desktop */
44 #define Xstartposition 700
45 #define Ystartposition 448
47 gint xapplet = 0, yapplet = 0;
51 lw_applet_realize (GtkWidget *widget)
55 screen = gtk_widget_get_screen (widget);
56 gtk_widget_set_colormap (widget,
57 gdk_screen_get_rgba_colormap (screen));
58 gtk_widget_set_app_paintable (widget,
60 GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->realize (widget);
65 lw_applet_expose_event(GtkWidget *widget,
66 GdkEventExpose *event)
70 /* Create cairo context */
71 cr = gdk_cairo_create (GDK_DRAWABLE (widget->window));
72 gdk_cairo_region (cr, event->region);
75 /* Draw alpha background */
76 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
77 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0);
83 return GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->expose_event (widget,
88 expose_event (GtkWidget *widget,GdkEventExpose *event,
92 GdkPixbuf *pixbuf = (GdkPixbuf *) data;
94 cr = gdk_cairo_create(widget->window);
96 gdk_cairo_region(cr, event->region);
97 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
98 gdk_cairo_set_source_pixbuf(cr, pixbuf, 0.0, 0.0);
106 realize (GtkWidget *widget)
109 screen = gtk_widget_get_screen (widget);
110 gtk_widget_set_colormap (widget, gdk_screen_get_rgba_colormap (screen));
113 /* Set position of widget on desktop */
115 init_applet_position(void)
117 GSList *position = NULL;
121 GError *error = NULL;
122 GConfClient *gconf_client = gconf_client_get_default ();
123 position_key = g_strdup_printf (GCONF_KEY_POSITION, PLUGIN_NAME);
124 position = gconf_client_get_list (gconf_client,
128 if (position && position->data && position->next->data){
129 xapplet = GPOINTER_TO_INT (position->data);
130 yapplet = GPOINTER_TO_INT (position->next->data);
132 position = g_slist_prepend (g_slist_prepend (NULL,
133 GINT_TO_POINTER (Ystartposition)),
134 GINT_TO_POINTER (Xstartposition));
135 gconf_client_set_list (gconf_client,
140 xapplet = Xstartposition;
141 yapplet = Ystartposition;
143 g_free (position_key);
144 modified = g_strdup_printf ("%i", 0);
145 modified_key = g_strdup_printf (GCONF_KEY_MODIFIED, PLUGIN_NAME);
146 gconf_client_set_string (gconf_client,
151 g_free(modified_key);
152 gconf_client_clear_cache(gconf_client);
153 g_object_unref(gconf_client);
157 actor_set_position_full(GtkWidget *actor, gint x, gint y, gint z)
159 /* fprintf(stderr, "actor_set_position_full z=%d\n", z); */
160 hildon_animation_actor_set_position_full (HILDON_ANIMATION_ACTOR (actor),x-xapplet, y-yapplet, z);
165 destroy_hildon_actor(Actor *actor)
167 //fprintf(stderr, "destroy_hildon_actor %s\n",actor->name);
168 gtk_widget_destroy(actor->widget);
169 actor->widget = NULL;
179 gint fast_rnd(gint max)
181 guint offset = 12923;
182 guint multiplier = 4079;
184 //*seed = *seed * multiplier + offset;
185 //return (gint)(*seed % max);
186 guint seed = time(NULL);
187 return (gint)(seed % max);
191 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
193 GtkWidget *ha = NULL;
194 GdkPixbuf *pixbuf = NULL;
195 GtkWidget *image = NULL;
198 ha = hildon_animation_actor_new();
199 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
200 desktop_plugin->priv->theme, actor->filename);
201 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
205 /*fprintf(stderr, "create_hildon_actor %s %s\n", actor->name, str);*/
209 image = gtk_image_new_from_pixbuf (pixbuf);
210 g_object_unref(G_OBJECT(pixbuf));
213 g_signal_connect(G_OBJECT(image), "expose_event",
214 G_CALLBACK(expose_event), pixbuf);
215 gtk_container_add (GTK_CONTAINER (ha), image);
217 actor_set_position_full(ha, actor->x, actor->y, actor->z);
218 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(ha), (double)actor->scale/100, (double)actor->scale/100);
220 gtk_widget_show_all(ha);
221 hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(ha), actor->visible);
226 g_object_set_data(G_OBJECT(ha), "image", image);
227 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
233 change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
235 GtkWidget *image = NULL;
236 GdkPixbuf *pixbuf = NULL;
239 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
240 desktop_plugin->priv->theme, actor->filename);
242 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
249 image = gtk_image_new_from_pixbuf (pixbuf);
250 g_object_unref(G_OBJECT(pixbuf));
253 g_signal_connect(G_OBJECT(image), "expose_event",
254 G_CALLBACK(expose_event), pixbuf);
255 if (g_object_get_data(G_OBJECT(actor->widget), "image")){
256 gtk_container_remove(GTK_CONTAINER(actor->widget), g_object_get_data(G_OBJECT(actor->widget), "image"));
258 g_object_set_data(G_OBJECT(actor->widget), "image", image);
259 gtk_container_add (GTK_CONTAINER (actor->widget), image);
260 realize(actor->widget);
261 gtk_widget_show_all(actor->widget);
272 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
275 newfile = g_strdup_printf("%s%d.png", actor->name, desktop_plugin->priv->scene->daytime);
277 g_free(actor->filename);
278 actor->filename = newfile;
279 change_hildon_actor(actor, desktop_plugin);
283 change_static_actor_with_corner(Actor * actor, AWallpaperPlugin *desktop_plugin)
287 if (desktop_plugin->priv->right_corner)
288 gtk_widget_destroy(desktop_plugin->priv->right_corner);
289 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/town%i_right_corner.png", \
290 THEME_PATH, desktop_plugin->priv->theme, desktop_plugin->priv->scene->daytime);
291 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
292 if (desktop_plugin->priv->right_corner){
293 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
294 gtk_widget_show (desktop_plugin->priv->right_corner);
296 change_static_actor(actor, desktop_plugin);
301 change_layer(Actor * actor, AWallpaperPlugin *desktop_plugin)
306 if (!desktop_plugin->priv->rich_animation) return;
308 a = g_ptr_array_index(actor->child, 0);
310 if (y > 480) y = -480;
311 actor_set_position_full(a->widget, a->x, y, a->z);
314 a = g_ptr_array_index(actor->child, 1);
316 if (y > 480) y = -480;
317 actor_set_position_full(a->widget, a->x, y, a->z);
320 a = g_ptr_array_index(actor->child, 2);
322 if (y > 480) y = -480;
323 actor_set_position_full(a->widget, a->x, y, a->z);
326 a = g_ptr_array_index(actor->child, 3);
328 if (y > 480) y = -480;
329 actor_set_position_full(a->widget, a->x, y, a->z);
335 change_layer1(Actor * actor, AWallpaperPlugin *desktop_plugin)
339 if (y > 480) y = -480;
340 actor_set_position_full(actor->widget, actor->x, y, actor->z);
345 change_layer2(Actor * actor, AWallpaperPlugin *desktop_plugin)
349 if (y >= 480) y = -480;
350 actor_set_position_full(actor->widget, actor->x, y, actor->z);
357 // уравнение изменения времени
362 destroy_scene(AWallpaperPlugin *desktop_plugin)
364 GSList * tmp = desktop_plugin->priv->scene->actors;
370 g_ptr_array_free(actor->child, TRUE);
373 g_free(actor->filename);
376 gtk_widget_destroy(actor->widget);
377 //actor->widget = NULL;
380 tmp = g_slist_next(tmp);
387 reload_scene(AWallpaperPlugin *desktop_plugin)
389 fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);
390 destroy_scene(desktop_plugin);
391 if (!strcmp(desktop_plugin->priv->theme,"Modern"))
392 init_scene(desktop_plugin);
393 else if (!strcmp(desktop_plugin->priv->theme,"Berlin"))
394 init_scene1(desktop_plugin);
395 else if (!strcmp(desktop_plugin->priv->theme,"Matrix"))
396 init_scene2(desktop_plugin);
400 init_scene2(AWallpaperPlugin *desktop_plugin)
405 gint now = time(NULL);
408 if (desktop_plugin->priv->rich_animation){
416 fprintf(stderr, "init scene2 \n");
417 scene = g_new0(Scene, 1);
418 //scene.daytime = get_daytime();
419 scene->actors = NULL;
420 desktop_plugin->priv->scene = scene;
422 actor = init_object(desktop_plugin, "background", "bg.png",
424 TRUE, TRUE, 100, 255,
426 scene->actors = g_slist_append(scene->actors, actor);
428 actor = init_object(desktop_plugin, "symbols", "symbols.png",
430 TRUE, TRUE, 100, 255,
432 scene->actors = g_slist_append(scene->actors, actor);
434 child = g_ptr_array_sized_new(4);
435 actor = init_object(desktop_plugin, "layer1", "layer1_2.png",
437 TRUE, TRUE, 100, 255,
439 //actor->time_start_animation = now;
440 //actor->duration_animation = G_MAXINT;
441 scene->actors = g_slist_append(scene->actors, actor);
442 g_ptr_array_add(child, actor);
444 actor = init_object(desktop_plugin, "layer1", "layer1_1.png",
446 TRUE, TRUE, 100, 255,
448 //actor->time_start_animation = now;
449 //actor->duration_animation = G_MAXINT;
450 scene->actors = g_slist_append(scene->actors, actor);
451 g_ptr_array_add(child, actor);
453 actor = init_object(desktop_plugin, "layer2", "layer2_2.png",
455 TRUE, TRUE, 100, 255,
457 //actor->time_start_animation = now;
458 //actor->duration_animation = G_MAXINT;
459 scene->actors = g_slist_append(scene->actors, actor);
460 g_ptr_array_add(child, actor);
462 actor = init_object(desktop_plugin, "layer2", "layer2_1.png",
464 TRUE, TRUE, 100, 255,
466 //actor->time_start_animation = now;
467 //actor->duration_animation = G_MAXINT;
468 scene->actors = g_slist_append(scene->actors, actor);
469 g_ptr_array_add(child, actor);
471 actor = init_object(desktop_plugin, "layers", "",
473 FALSE, FALSE, 100, 255,
474 (gpointer)&change_layer, NULL, child);
475 actor->time_start_animation = now;
476 actor->duration_animation = G_MAXINT;
477 scene->actors = g_slist_append(scene->actors, actor);
479 run_long_timeout(desktop_plugin);
483 /* Init Modern Scene */
485 init_scene(AWallpaperPlugin *desktop_plugin)
489 gint now = time(NULL);
493 //fprintf(stderr, "init scene \n");
494 scene = g_new0(Scene, 1);
495 scene->daytime = get_daytime();
496 scene->actors = NULL;
497 scene->wind_orientation = -1;
498 scene->wind_angle = 0.3;
499 /* init value for random */
500 scene->seed = time(NULL);
501 desktop_plugin->priv->scene = scene;
503 actor = init_object(desktop_plugin, "sky", "sky0.png",
505 TRUE , TRUE, 100, 255,
506 (gpointer)&change_static_actor, NULL, NULL);
507 change_static_actor(actor, desktop_plugin);
508 scene->actors = g_slist_append(scene->actors, actor);
510 actor = init_object(desktop_plugin, "sun", "sun.png",
512 FALSE, FALSE, 100, 255,
513 (gpointer)&change_sun, NULL, NULL);
514 actor->time_start_animation = now;
515 actor->duration_animation = G_MAXINT;
516 change_sun(actor, desktop_plugin);
517 scene->actors = g_slist_append(scene->actors, actor);
519 //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
520 // TRUE, 100, 255, NULL, NULL);
521 //scene.actors = g_slist_append(scene.actors, actor);
523 actor = init_object(desktop_plugin, "cloud1", "cloud1.png",
524 0, fast_rnd(300)-97, 7, 150, 97,
525 FALSE, FALSE, 100, 255,
526 (gpointer)&change_cloud, NULL, NULL);
527 actor->time_start_animation = now + fast_rnd(20);
528 actor->duration_animation = 3*60;
529 scene->actors = g_slist_append(scene->actors, actor);
531 actor = init_object(desktop_plugin, "cloud2", "cloud2.png",
532 0, fast_rnd(300)-75, 7, 188, 75,
533 FALSE, FALSE, 100, 255,
534 (gpointer)&change_cloud, NULL, NULL);
535 actor->time_start_animation = now + fast_rnd(40)+10;
536 actor->duration_animation = 3*60;
537 scene->actors = g_slist_append(scene->actors, actor);
539 actor = init_object(desktop_plugin, "cloud4", "cloud4.png",
540 0, fast_rnd(300)-75, 7, 150, 75,
541 FALSE, FALSE, 100, 255,
542 (gpointer)&change_cloud, NULL, NULL);
543 actor->time_start_animation = now + fast_rnd(60) + 20;
544 actor->duration_animation = 5*60;
545 scene->actors = g_slist_append(scene->actors, actor);
548 actor = init_object(desktop_plugin, "town", "town0.png",
550 TRUE, TRUE, 100, 255,
551 (gpointer)&change_static_actor, NULL, NULL);
552 change_static_actor(actor, desktop_plugin);
553 scene->actors = g_slist_append(scene->actors, actor);
555 actor = init_object(desktop_plugin, "stend", "stend0.png",
556 482, 146, 9, 300, 305,
557 TRUE, TRUE, 100, 255,
558 (gpointer)&change_static_actor, NULL, NULL);
559 change_static_actor(actor, desktop_plugin);
560 scene->actors = g_slist_append(scene->actors, actor);
562 actor = init_object(desktop_plugin, "tram", "tram.png",
563 -300, 225, 10, 350, 210,
564 FALSE, FALSE, 100, 255,
565 (gpointer)&change_tram, NULL, NULL);
566 actor->time_start_animation = time(NULL) + fast_rnd(10);
567 actor->duration_animation = 60;
568 scene->actors = g_slist_append(scene->actors, actor);
570 actor = init_object(desktop_plugin, "border", "border0.png",
571 0, 480-79, 11, 800, 79,
572 TRUE, TRUE, 100, 255,
573 (gpointer)&change_static_actor_with_corner, NULL, NULL);
574 change_static_actor_with_corner(actor, desktop_plugin);
575 scene->actors = g_slist_append(scene->actors, actor);
577 actor = init_object(desktop_plugin, "moon", "moon1.png",
579 FALSE, FALSE, 100, 255,
580 (gpointer)&change_moon, NULL, NULL);
581 change_moon(actor, desktop_plugin);
582 scene->actors = g_slist_append(scene->actors, actor);
584 actor = init_object(desktop_plugin, "wind", "",
586 FALSE, FALSE, 100, 255,
587 (gpointer)&change_wind, NULL, NULL);
588 change_wind(actor, desktop_plugin);
589 scene->actors = g_slist_append(scene->actors, actor);
591 /* windows in 4-th house */
631 for (i=0; i<13; i++){
632 actor = init_object(desktop_plugin, "window1", "window1.png",
633 winds[i][0], winds[i][1], 8, 8, 10,
634 FALSE, FALSE, 100, 255,
635 (gpointer)&change_window1, NULL, NULL);
636 //change_window1(actor, desktop_plugin);
637 actor->time_start_animation = now + fast_rnd(30);
638 scene->actors = g_slist_append(scene->actors, actor);
642 /* windows in 1-th house */
668 actor = init_object(desktop_plugin, "window2", "window2.png",
669 winds[i][0], winds[i][1], 8, 8, 10,
670 FALSE, FALSE, 100, 255,
671 (gpointer)&change_window1, NULL, NULL);
672 //change_window1(actor, desktop_plugin);
673 actor->time_start_animation = now + fast_rnd(30);
674 scene->actors = g_slist_append(scene->actors, actor);
678 /* windows in 3-th house */
710 for (i=0; i<10; i++){
711 actor = init_object(desktop_plugin, "window3", "window3.png",
712 winds[i][0], winds[i][1], 8, 8, 10,
713 FALSE, FALSE, 100, 255,
714 (gpointer)&change_window1, NULL, NULL);
715 //change_window1(actor, desktop_plugin);
716 actor->time_start_animation = now + fast_rnd(30);
717 scene->actors = g_slist_append(scene->actors, actor);
721 /* windows in 5-th house */
745 actor = init_object(desktop_plugin, "window4", "window4.png",
746 winds[i][0], winds[i][1], 8, 8, 10,
747 FALSE, FALSE, 100, 255,
748 (gpointer)&change_window1, NULL, NULL);
749 //change_window1(actor, desktop_plugin);
750 actor->time_start_animation = now + fast_rnd(30);
751 scene->actors = g_slist_append(scene->actors, actor);
755 /* windows in 6-th house */
776 actor = init_object(desktop_plugin, "window5", "window5.png",
777 winds[i][0], winds[i][1], 8, 8, 10,
778 FALSE, FALSE, 100, 255,
779 (gpointer)&change_window1, NULL, NULL);
780 //change_window1(actor, desktop_plugin);
781 actor->time_start_animation = now + fast_rnd(30);
782 scene->actors = g_slist_append(scene->actors, actor);
785 run_long_timeout(desktop_plugin);
788 anim = g_new0(Animation, 1);
791 anim->func_change = &change_tram;
792 anim->func_time = NULL;
793 anim->timestart = time(NULL);
796 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
800 /* Init Berlin Scene */
802 init_scene1(AWallpaperPlugin *desktop_plugin)
804 Actor *actor, *actor1, *actor2;
806 gint now = time(NULL);
809 GPtrArray *child = NULL;
811 scene = g_new0(Scene, 1);
812 scene->daytime = get_daytime();
813 scene->actors = NULL;
814 scene->wind_orientation = -1;
815 scene->wind_angle = 0.3;
816 /* init value for random */
817 scene->seed = time(NULL);
818 desktop_plugin->priv->scene = scene;
820 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
821 TRUE, TRUE, 100, 255,
822 (gpointer)&change_static_actor, NULL, NULL);
823 change_static_actor(actor, desktop_plugin);
824 scene->actors = g_slist_append(scene->actors, actor);
827 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
828 FALSE, FALSE, 100, 255,
829 (gpointer)&change_sun, NULL, NULL);
830 actor->time_start_animation = time(NULL);
831 actor->duration_animation = G_MAXINT;
832 change_sun(actor, desktop_plugin);
833 scene->actors = g_slist_append(scene->actors, actor);
836 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
837 TRUE, 100, 255, NULL, NULL);
838 scene.actors = g_slist_append(scene.actors, actor);
841 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
842 FALSE, FALSE, 100, 255,
843 (gpointer)&change_moon, NULL, NULL);
844 change_moon(actor, desktop_plugin);
845 scene->actors = g_slist_append(scene->actors, actor);
847 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
848 FALSE, FALSE, 100, 255,
849 (gpointer)&change_cloud, NULL, NULL);
850 actor->time_start_animation = now + fast_rnd(30) + 10;
851 actor->duration_animation = 3*60;
852 scene->actors = g_slist_append(scene->actors, actor);
854 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
855 FALSE, FALSE, 100, 255,
856 (gpointer)&change_cloud, NULL, NULL);
857 actor->time_start_animation = now + fast_rnd(10);
858 actor->duration_animation = 3*60;
859 scene->actors = g_slist_append(scene->actors, actor);
861 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
862 FALSE, FALSE, 100, 255,
863 (gpointer)&change_cloud, NULL, NULL);
864 actor->time_start_animation = now + fast_rnd(60) + 20;
865 actor->duration_animation = 5*60;
866 scene->actors = g_slist_append(scene->actors, actor);
869 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
870 FALSE, FALSE, 100, 255,
871 (gpointer)&change_plane2, NULL, NULL);
872 actor->time_start_animation = now + fast_rnd(40) + 20;
873 actor->duration_animation = 60;
874 scene->actors = g_slist_append(scene->actors, actor);
876 actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116,
877 FALSE, FALSE, 100, 255,
878 (gpointer)&change_plane1, NULL, NULL);
879 actor->time_start_animation = now + fast_rnd(20);
880 actor->duration_animation = 30;
881 scene->actors = g_slist_append(scene->actors, actor);
883 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
884 TRUE, TRUE, 100, 255,
885 (gpointer)&change_static_actor_with_corner, NULL, NULL);
886 change_static_actor_with_corner(actor, desktop_plugin);
887 scene->actors = g_slist_append(scene->actors, actor);
889 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
890 FALSE, FALSE, 100, 255,
891 (gpointer)&change_wind, NULL, NULL);
892 change_wind(actor, desktop_plugin);
893 scene->actors = g_slist_append(scene->actors, actor);
895 actor1 = init_object(desktop_plugin, "signal_red", "red.png",
896 486, 425, 10, 18, 38,
897 FALSE, TRUE, 100, 255, NULL, NULL, NULL);
898 //actor->time_start_animation = now + fast_rnd(30) + 10;
899 scene->actors = g_slist_append(scene->actors, actor1);
901 actor2 = init_object(desktop_plugin, "signal_green", "green.png",
902 486, 425, 10, 18, 38,
903 TRUE, TRUE, 100, 255, NULL, NULL, NULL);
904 //actor->time_start_animation = now + fast_rnd(30) + 10;
905 scene->actors = g_slist_append(scene->actors, actor2);
906 child = g_ptr_array_sized_new(2);
907 g_ptr_array_add(child, actor1);
908 g_ptr_array_add(child, actor2);
909 actor = init_object(desktop_plugin, "signal", "",
910 486, 425, 10, 18, 38,
911 FALSE, FALSE, 100, 255,
912 (gpointer)&change_signal, NULL, child);
913 actor->time_start_animation = now + fast_rnd(30) + 10;
914 scene->actors = g_slist_append(scene->actors, actor);
955 for (i=0; i<13; i++){
956 actor = init_object(desktop_plugin, "window", "window.png",
957 winds[i][0], winds[i][1], 10, 8, 9,
958 FALSE, TRUE, 100, 255,
959 (gpointer)&change_window1, NULL, NULL);
960 //change_window1(actor, desktop_plugin);
961 actor->time_start_animation = now + fast_rnd(30);
962 scene->actors = g_slist_append(scene->actors, actor);
966 run_long_timeout(desktop_plugin);
971 get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
973 gint y0 = 365;// - уровень горизонта
974 *x = (int)(azm * 800) - 64;
975 *y = (int)((1 - alt) * y0) - 64;
976 //fprintf(stderr, "sun pos alt=%f azm=%f x=%d y=%d\n", alt, azm, *x, *y);
980 change_actor(GtkWidget * actor)
983 gint x, y, daytime, scale;
990 void (*pfunc)(gpointer, gpointer);
992 name = g_object_get_data(G_OBJECT(actor), "name");
993 fprintf(stderr, "change actor %s\n", name);
995 pfunc = g_object_get_data(G_OBJECT(actor), "func");
997 (*pfunc)(actor, g_strdup(name));
998 daytime = get_daytime();
999 if (daytime != TIME_NIGHT){
1000 hildon_animation_actor_set_show(actor, 1);
1001 get_sun_pos(&alt, &azm);
1002 get_sun_screen_pos(alt, azm, &x, &y);
1003 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
1007 if (name == "cloud1"){
1008 x = g_object_get_data(G_OBJECT(actor), "x");
1009 y = g_object_get_data(G_OBJECT(actor), "y");
1010 scale = g_object_get_data(G_OBJECT(actor), "scale");
1013 image = g_object_get_data(G_OBJECT(actor), "image");
1015 gtk_container_remove(actor, image);
1016 pixbuf = gdk_pixbuf_new_from_file_at_size ("/usr/share/livewp/theme/Modern/sun.png",
1021 image = gtk_image_new_from_pixbuf (pixbuf);
1022 g_object_unref(G_OBJECT(pixbuf));
1024 g_signal_connect(G_OBJECT(image), "expose_event",
1025 G_CALLBACK(expose_event), pixbuf);
1026 gtk_container_add (GTK_CONTAINER (actor), image);
1028 gtk_widget_show_all(actor);
1040 sc = (double)scale / 100;
1041 hildon_animation_actor_set_scale(actor, sc, sc);
1042 fprintf(stderr, "cloud x=%d y=%d scale=%f", x, y, sc);
1043 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
1044 g_object_set_data(G_OBJECT(actor), "x", x);
1045 g_object_set_data(G_OBJECT(actor), "y", y);
1046 g_object_set_data(G_OBJECT(actor), "scale", scale);
1052 short_timeout (AWallpaperPlugin *desktop_plugin)
1054 //gint daytime = get_daytime();
1056 void (*pfunc)(gpointer, gpointer);
1059 gboolean stop_flag = TRUE;
1061 if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
1062 desktop_plugin->priv->short_timer = 0;
1067 //scene.daytime = daytime;
1068 /* fprintf(stderr, "Short timer %d\n", now); */
1069 tmp = desktop_plugin->priv->scene->actors;
1070 while (tmp != NULL){
1072 if (now >= actor->time_start_animation
1073 && actor->time_start_animation > 0
1074 /* && now - actor->time_start_animation <= actor->duration_animation*/){
1075 pfunc = actor->func_change;
1077 (*pfunc)(actor, desktop_plugin);
1081 tmp = g_slist_next(tmp);
1084 desktop_plugin->priv->short_timer = 0;
1087 return TRUE; /* keep running this event */
1091 run_long_timeout(AWallpaperPlugin *desktop_plugin)
1094 gint daytime = get_daytime();
1096 void (*pfunc)(gpointer, gpointer);
1101 //fprintf(stderr, "!!!run long timeout short_timer=%d\n", desktop_plugin->priv->short_timer);
1102 if (desktop_plugin->priv->scene->daytime != daytime){
1103 desktop_plugin->priv->scene->daytime = daytime;
1104 tmp = desktop_plugin->priv->scene->actors;
1105 while (tmp != NULL){
1106 //change_actor(tmp->data);
1107 pfunc =((Actor*)tmp->data)->func_change;
1109 (*pfunc)(tmp->data, desktop_plugin);
1111 tmp = g_slist_next(tmp);
1116 //fprintf(stderr, "Now %d\n", now);
1117 tmp = desktop_plugin->priv->scene->actors;
1118 while (tmp != NULL){
1120 if (now >= actor->time_start_animation
1121 && actor->time_start_animation > 0
1122 && desktop_plugin->priv->short_timer == 0){
1123 /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
1124 if (desktop_plugin->priv->rich_animation){
1125 actor->time_start_animation = now;
1126 desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
1129 (*actor->func_change)(actor, desktop_plugin);
1132 tmp = g_slist_next(tmp);
1138 long_timeout (AWallpaperPlugin *desktop_plugin)
1140 /* fprintf(stderr, "long_timeout %i\n", desktop_plugin->priv->long_timer); */
1141 if (desktop_plugin->priv->long_timer == 0 )
1143 if (!desktop_plugin->priv->visible){
1144 if(desktop_plugin->priv->short_timer != 0){
1145 g_source_remove(desktop_plugin->priv->short_timer);
1146 desktop_plugin->priv->short_timer = 0;
1148 desktop_plugin->priv->long_timer = 0;
1153 run_long_timeout(desktop_plugin);
1154 return TRUE; /* keep running this event */
1158 desktop_plugin_visible_notify (GObject *object,
1160 AWallpaperPlugin *desktop_plugin)
1163 g_object_get (object, "is-on-current-desktop", &visible, NULL);
1164 /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
1166 desktop_plugin->priv->visible = TRUE;
1167 if (desktop_plugin->priv->long_timer == 0 ){
1168 desktop_plugin->priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1169 run_long_timeout(desktop_plugin);
1172 desktop_plugin->priv->visible = FALSE;
1173 if (desktop_plugin->priv->long_timer != 0 ){
1174 g_source_remove(desktop_plugin->priv->long_timer);
1175 desktop_plugin->priv->long_timer = 0;
1181 rich_animation_press(GtkWidget *widget, GdkEvent *event,
1182 gpointer user_data){
1183 fprintf(stderr,"gggggggggggggggggggg2222\n");
1187 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
1189 GtkWidget *rich_animation;
1193 //fprintf(stderr, "!!!!!!!plugin init \n");
1194 Animation_WallpaperPrivate *priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1195 desktop_plugin->priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1196 priv->osso = osso_initialize(PACKAGE, VERSION, TRUE, NULL);
1200 /* Initialize DBUS */
1201 livewp_initialize_dbus(priv);
1203 priv->desktop_plugin = desktop_plugin;
1204 priv->visible = TRUE;
1205 priv->short_timer = 0;
1206 //priv->theme = g_strdup("Modern");
1207 desktop_plugin->priv->main_widget = gtk_fixed_new();
1209 gtk_widget_set_size_request(desktop_plugin->priv->main_widget, 100, 32);
1210 desktop_plugin->priv->right_corner = NULL;
1211 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/%s", THEME_PATH, desktop_plugin->priv->theme, "town0_right_corner.png");
1212 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
1213 if (desktop_plugin->priv->right_corner){
1214 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
1215 gtk_widget_show (desktop_plugin->priv->right_corner);
1217 /* Create rich animation event */
1218 rich_animation = gtk_event_box_new();
1220 gtk_widget_set_events(rich_animation, GDK_BUTTON_PRESS_MASK);
1221 gtk_event_box_set_visible_window(GTK_EVENT_BOX(rich_animation), FALSE);
1222 gtk_widget_set_size_request(rich_animation, 100, 32);
1223 gtk_widget_show (rich_animation);
1224 g_signal_connect(rich_animation, "button-press-event", G_CALLBACK(rich_animation_press), desktop_plugin);
1225 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), rich_animation, 0, 0);
1228 GtkWidget *label = gtk_label_new ("ddddddddddddd");
1229 gtk_widget_set_size_request(label, 95, 30);
1230 gtk_widget_show (label);
1231 // gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
1232 gtk_fixed_put(GTK_FIXED(widget), label, 0, 0);
1234 hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
1235 g_signal_connect (desktop_plugin, "show-settings",
1236 G_CALLBACK (show_settings), priv);
1237 gtk_widget_show (desktop_plugin->priv->main_widget);
1238 gtk_container_add (GTK_CONTAINER (desktop_plugin), desktop_plugin->priv->main_widget);
1239 init_applet_position();
1242 fprintf(stderr, "!!!theme = %s\n", priv->theme);
1244 if (!strcmp(priv->theme,"Modern"))
1245 init_scene(desktop_plugin);
1246 else if (!strcmp(priv->theme,"Berlin"))
1247 init_scene1(desktop_plugin);
1248 else if (!strcmp(priv->theme, "Matrix"))
1249 init_scene2(desktop_plugin);
1250 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1251 /* TODO Move scene to priv */
1252 //scene.timer_type = LONG_TIMER_TYPE;
1253 g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
1254 G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
1261 lw_applet_finalize (GObject *object)
1263 AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
1264 Animation_WallpaperPrivate *priv = desktop_plugin->priv;
1266 fprintf(stderr,"finalaze %i\n", priv->long_timer);
1267 if (priv->long_timer){
1268 g_source_remove(priv->long_timer);
1269 priv->long_timer = 0;
1271 if (priv->short_timer){
1272 g_source_remove(priv->short_timer);
1273 priv->short_timer = 0;
1276 destroy_scene(desktop_plugin);
1280 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
1282 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1283 GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
1286 gobject_class->destroy = (gpointer)lw_applet_finalize;
1287 widget_class->realize = lw_applet_realize;
1288 widget_class->expose_event = lw_applet_expose_event;
1290 g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));
1295 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {