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"
29 #include "livewp-scene.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))
44 lw_applet_realize (GtkWidget *widget)
48 screen = gtk_widget_get_screen (widget);
49 gtk_widget_set_colormap (widget,
50 gdk_screen_get_rgba_colormap (screen));
51 gtk_widget_set_app_paintable (widget,
53 GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->realize (widget);
58 lw_applet_expose_event(GtkWidget *widget,
59 GdkEventExpose *event)
63 /* Create cairo context */
64 cr = gdk_cairo_create (GDK_DRAWABLE (widget->window));
65 gdk_cairo_region (cr, event->region);
68 /* Draw alpha background */
69 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
70 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0);
76 return GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->expose_event (widget,
81 expose_event (GtkWidget *widget,GdkEventExpose *event,
85 GdkPixbuf *pixbuf = (GdkPixbuf *) data;
87 cr = gdk_cairo_create(widget->window);
89 gdk_cairo_region(cr, event->region);
90 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
91 gdk_cairo_set_source_pixbuf(cr, pixbuf, 0.0, 0.0);
99 realize (GtkWidget *widget)
102 screen = gtk_widget_get_screen (widget);
103 gtk_widget_set_colormap (widget, gdk_screen_get_rgba_colormap (screen));
106 /* Set position of widget on desktop */
108 init_applet_position(gint *xapplet, gint *yapplet)
110 GSList *position = NULL;
114 GError *error = NULL;
115 GConfClient *gconf_client = gconf_client_get_default ();
116 position_key = g_strdup_printf (GCONF_KEY_POSITION, PLUGIN_NAME);
117 position = gconf_client_get_list (gconf_client,
121 if (position && position->data && position->next->data){
122 *xapplet = GPOINTER_TO_INT (position->data);
123 *yapplet = GPOINTER_TO_INT (position->next->data);
125 position = g_slist_prepend (g_slist_prepend (NULL,
126 GINT_TO_POINTER (Ystartposition)),
127 GINT_TO_POINTER (Xstartposition));
128 gconf_client_set_list (gconf_client,
133 *xapplet = Xstartposition;
134 *yapplet = Ystartposition;
136 g_free (position_key);
137 modified = g_strdup_printf ("%i", 0);
138 modified_key = g_strdup_printf (GCONF_KEY_MODIFIED, PLUGIN_NAME);
139 gconf_client_set_string (gconf_client,
144 g_free(modified_key);
145 gconf_client_clear_cache(gconf_client);
146 g_object_unref(gconf_client);
150 actor_set_position_full(GtkWidget *actor, gint x, gint y, gint z)
152 /* fprintf(stderr, "actor_set_position_full z=%d\n", z); */
153 hildon_animation_actor_set_position_full (HILDON_ANIMATION_ACTOR (actor),x-0, y-0, z);
158 destroy_hildon_actor(Actor *actor)
160 //fprintf(stderr, "destroy_hildon_actor %s\n",actor->name);
161 gtk_widget_destroy(actor->widget);
162 actor->widget = NULL;
166 create_hildon_actor_text(Actor *actor, AWallpaperPlugin *desktop_plugin)
168 GtkWidget *ha = NULL;
169 GdkPixbuf *pixbuf = NULL;
170 GtkWidget *image = NULL;
171 GtkWidget *label = NULL;
173 ha = hildon_animation_actor_new();
174 label = gtk_label_new(NULL);
177 //g_signal_connect(G_OBJECT(label), "expose_event",
178 // G_CALLBACK(expose_event), NULL);
180 gtk_container_add (GTK_CONTAINER (ha), label);
183 gtk_widget_show(label);
184 gtk_widget_show_all(ha);
189 //g_object_set_data(G_OBJECT(ha), "image", image);
190 actor->image = label;
191 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
193 set_actor_position(actor, actor->x, actor->y, actor->z, desktop_plugin);
194 set_actor_scale(actor, (double)actor->scale/100, (double)actor->scale/100);
195 set_actor_visible(actor, actor->visible);
201 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
203 GtkWidget *ha = NULL;
204 GdkPixbuf *pixbuf = NULL;
205 GtkWidget *image = NULL;
208 ha = hildon_animation_actor_new();
209 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
210 desktop_plugin->priv->theme, actor->filename);
211 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
215 /*fprintf(stderr, "create_hildon_actor %s %s\n", actor->name, str);*/
219 image = gtk_image_new_from_pixbuf (pixbuf);
220 g_object_unref(G_OBJECT(pixbuf));
223 g_signal_connect(G_OBJECT(image), "expose_event",
224 G_CALLBACK(expose_event), pixbuf);
225 gtk_container_add (GTK_CONTAINER (ha), image);
228 gtk_widget_show_all(ha);
233 //g_object_set_data(G_OBJECT(ha), "image", image);
234 actor->image = image;
235 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
237 set_actor_position(actor, actor->x, actor->y, actor->z, desktop_plugin);
238 set_actor_scale(actor, (double)actor->scale/100, (double)actor->scale/100);
239 set_actor_visible(actor, actor->visible);
244 change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
246 GtkWidget *image = NULL;
247 GdkPixbuf *pixbuf = NULL;
250 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
251 desktop_plugin->priv->theme, actor->filename);
253 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
260 image = gtk_image_new_from_pixbuf (pixbuf);
261 g_object_unref(G_OBJECT(pixbuf));
264 g_signal_connect(G_OBJECT(image), "expose_event",
265 G_CALLBACK(expose_event), pixbuf);
266 //if (g_object_get_data(G_OBJECT(actor->widget), "image")){
268 gtk_container_remove(GTK_CONTAINER(actor->widget), actor->image);
270 //g_object_set_data(G_OBJECT(actor->widget), "image", image);
271 actor->image = image;
272 gtk_container_add (GTK_CONTAINER (actor->widget), image);
273 realize(actor->widget);
274 gtk_widget_show_all(actor->widget);
285 short_timeout (AWallpaperPlugin *desktop_plugin)
287 //gint daytime = get_daytime();
289 void (*pfunc)(gpointer, gpointer);
292 gboolean stop_flag = TRUE;
294 if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
295 desktop_plugin->priv->short_timer = 0;
300 //scene.daytime = daytime;
301 /* fprintf(stderr, "Short timer %d\n", now); */
302 tmp = desktop_plugin->priv->scene->actors;
305 if (now >= actor->time_start_animation
306 && actor->time_start_animation > 0
307 /* && now - actor->time_start_animation <= actor->duration_animation*/){
308 pfunc = actor->func_change;
310 (*pfunc)(actor, desktop_plugin);
314 tmp = g_slist_next(tmp);
317 desktop_plugin->priv->short_timer = 0;
320 return TRUE; /* keep running this event */
324 run_long_timeout(AWallpaperPlugin *desktop_plugin)
327 gint daytime = get_daytime();
329 void (*pfunc)(gpointer, gpointer);
334 //fprintf(stderr, "!!!run long timeout short_timer=%d\n", desktop_plugin->priv->short_timer);
335 if (desktop_plugin->priv->scene->daytime != daytime){
336 desktop_plugin->priv->scene->daytime = daytime;
337 tmp = desktop_plugin->priv->scene->actors;
339 //change_actor(tmp->data);
340 pfunc =((Actor*)tmp->data)->func_change;
342 (*pfunc)(tmp->data, desktop_plugin);
344 tmp = g_slist_next(tmp);
349 //fprintf(stderr, "Now %d\n", now);
350 tmp = desktop_plugin->priv->scene->actors;
353 if (now >= actor->time_start_animation
354 && actor->time_start_animation > 0
355 && desktop_plugin->priv->short_timer == 0){
356 /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
357 if (desktop_plugin->priv->rich_animation){
358 actor->time_start_animation = now;
359 desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
362 (*actor->func_change)(actor, desktop_plugin);
365 tmp = g_slist_next(tmp);
371 long_timeout (AWallpaperPlugin *desktop_plugin)
373 /* fprintf(stderr, "long_timeout %i\n", desktop_plugin->priv->long_timer); */
374 if (desktop_plugin->priv->long_timer == 0 )
376 if (!desktop_plugin->priv->visible){
377 if(desktop_plugin->priv->short_timer != 0){
378 g_source_remove(desktop_plugin->priv->short_timer);
379 desktop_plugin->priv->short_timer = 0;
381 desktop_plugin->priv->long_timer = 0;
386 run_long_timeout(desktop_plugin);
387 return TRUE; /* keep running this event */
391 desktop_plugin_visible_notify (GObject *object,
393 AWallpaperPlugin *desktop_plugin)
396 g_object_get (object, "is-on-current-desktop", &visible, NULL);
397 /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
399 desktop_plugin->priv->visible = TRUE;
400 if (desktop_plugin->priv->long_timer == 0 ){
401 desktop_plugin->priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
402 run_long_timeout(desktop_plugin);
405 desktop_plugin->priv->visible = FALSE;
406 if (desktop_plugin->priv->long_timer != 0 ){
407 g_source_remove(desktop_plugin->priv->long_timer);
408 desktop_plugin->priv->long_timer = 0;
414 rich_animation_press(GtkWidget *widget, GdkEvent *event,
416 fprintf(stderr,"gggggggggggggggggggg2222\n");
421 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
423 GtkWidget *rich_animation;
427 //fprintf(stderr, "!!!!!!!plugin init \n");
428 Animation_WallpaperPrivate *priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
429 desktop_plugin->priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
430 priv->osso = osso_initialize(PACKAGE, VERSION, TRUE, NULL);
434 /* Initialize DBUS */
435 livewp_initialize_dbus(priv);
437 priv->desktop_plugin = desktop_plugin;
438 priv->visible = TRUE;
439 priv->short_timer = 0;
443 priv->hash_scene_func = g_hash_table_new(g_str_hash, g_str_equal);
445 g_hash_table_insert(priv->hash_scene_func, g_strdup("Berlin"), (gpointer)&init_scene_Berlin);
446 g_hash_table_insert(priv->hash_scene_func, g_strdup("Modern"), (gpointer)&init_scene_Modern);
447 g_hash_table_insert(priv->hash_scene_func, g_strdup("Matrix"), (gpointer)&init_scene_Matrix);
449 priv->theme = g_strdup("Modern");
450 desktop_plugin->priv->main_widget = gtk_fixed_new();
452 gtk_widget_set_size_request(desktop_plugin->priv->main_widget, 100, 32);
453 desktop_plugin->priv->right_corner = NULL;
454 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/%s", THEME_PATH, desktop_plugin->priv->theme, "town0_right_corner.png");
455 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
456 if (desktop_plugin->priv->right_corner){
457 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
458 gtk_widget_show (desktop_plugin->priv->right_corner);
460 /* Create rich animation event */
461 rich_animation = gtk_event_box_new();
463 gtk_widget_set_events(rich_animation, GDK_BUTTON_PRESS_MASK);
464 gtk_event_box_set_visible_window(GTK_EVENT_BOX(rich_animation), FALSE);
465 gtk_widget_set_size_request(rich_animation, 100, 32);
466 gtk_widget_show (rich_animation);
467 g_signal_connect(rich_animation, "button-press-event", G_CALLBACK(rich_animation_press), desktop_plugin);
468 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), rich_animation, 0, 0);
471 GtkWidget *label = gtk_label_new ("ddddddddddddd");
472 gtk_widget_set_size_request(label, 95, 30);
473 gtk_widget_show (label);
474 gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
475 gtk_fixed_put(GTK_FIXED(widget), label, 0, 0);
477 hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
478 g_signal_connect (desktop_plugin, "show-settings",
479 G_CALLBACK (show_settings), priv);
480 gtk_widget_show (desktop_plugin->priv->main_widget);
481 gtk_container_add (GTK_CONTAINER (desktop_plugin), desktop_plugin->priv->main_widget);
482 init_applet_position(&(priv->xapplet), &(priv->yapplet));
485 fprintf(stderr, "!!!theme = %s\n", priv->theme);
486 snprintf(str, sizeof(str) - 1, "%s", "init_scene2");
487 fprintf(stderr, " str = %s\n", str);
490 if (!strcmp(priv->theme,"Modern"))
491 init_scene_Modern(desktop_plugin);
492 else if (!strcmp(priv->theme,"Berlin"))
493 init_scene_Berlin(desktop_plugin);
494 else if (!strcmp(priv->theme, "Matrix"))
495 init_scene_Matrix(desktop_plugin);
497 init_scene_theme(desktop_plugin);
499 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
500 /* TODO Move scene to priv */
501 //scene.timer_type = LONG_TIMER_TYPE;
502 g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
503 G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
510 lw_applet_finalize (GObject *object)
512 AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
513 Animation_WallpaperPrivate *priv = desktop_plugin->priv;
515 livewp_deinitialize_dbus(priv);
516 fprintf(stderr,"finalaze %i\n", priv->long_timer);
517 if (priv->long_timer){
518 g_source_remove(priv->long_timer);
519 priv->long_timer = 0;
521 if (priv->short_timer){
522 g_source_remove(priv->short_timer);
523 priv->short_timer = 0;
526 destroy_scene(desktop_plugin);
530 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
532 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
533 GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
536 gobject_class->destroy = (gpointer)lw_applet_finalize;
537 widget_class->realize = lw_applet_realize;
538 widget_class->expose_event = lw_applet_expose_event;
540 g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));
545 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {