Here's an example of how to use an animation for a GtkStatusIcon.
You should be able to adapt it to your needs.
Code:
#include <gtk/gtk.h>
#define ANIM_FILE "test.gif"
typedef struct _Data
{
GtkStatusIcon *icon;
GdkPixbufAnimationIter *iter;
} Data;
gboolean button_press_cb(GtkStatusIcon *icon, GdkEventButton *ev, gpointer user_data)
{
GtkWidget *menu;
GtkWidget *item;
/* Create a menu just for an example */
menu = gtk_menu_new();
/* Create a stock quit item */
item = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, NULL);
g_signal_connect(item, "activate", G_CALLBACK(gtk_main_quit), NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
gtk_widget_show(item);
/* Popup the menu */
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, ev->button, ev->time);
return FALSE;
}
gboolean pixbuf_anim_timeout(gpointer user_data)
{
GdkPixbuf *pbuf;
Data *data = (Data*)user_data;
/* If the image doesn't need to be updated, return */
if(gdk_pixbuf_animation_iter_advance(data->iter, NULL) == FALSE)
return TRUE;
/* Get our current frame's pixbuf */
pbuf = gdk_pixbuf_animation_iter_get_pixbuf(data->iter);
/* Update the status icon */
gtk_status_icon_set_from_pixbuf(data->icon, pbuf);
/* Return TRUE to keep the animation running */
return TRUE;
}
gint main(gint argc, gchar **argv)
{
GtkStatusIcon *icon;
GdkPixbufAnimation *anim;
GdkPixbufAnimationIter *iter;
GdkPixbuf *pbuf;
gint delay;
GError *err = NULL;
Data data;
gtk_init(&argc, &argv);
/* Create a new GdkPixbufAnimation and do error checking */
anim = gdk_pixbuf_animation_new_from_file(ANIM_FILE, &err);
if(err != NULL)
{
g_warning("%s", err->message);
g_error_free(err);
return 1;
}
/* Get a start iter... */
iter = gdk_pixbuf_animation_get_iter(anim, NULL);
data.iter = iter;
/* ...and get the start frame */
pbuf = gdk_pixbuf_animation_iter_get_pixbuf(iter);
/* Create a new GtkStatusIcon from our pixbuf */
icon = gtk_status_icon_new_from_pixbuf(pbuf);
data.icon = icon;
/* And connect a signal so we can quit */
g_signal_connect(icon, "button-press-event", G_CALLBACK(button_press_cb), NULL);
/* Set up the timeout */
delay = gdk_pixbuf_animation_iter_get_delay_time(iter);
/* If delay == -1, then it should be static */
if(delay != -1)
g_timeout_add(delay, pixbuf_anim_timeout, (gpointer)&data);
gtk_main();
return 0;
}
Docs:
http://library.gnome.org/devel/gtk/stab ... sIcon.html
http://library.gnome.org/devel/gdk-pixb ... ation.html
Also, here's one of your older topics with more information on GdkPixbufAnimation:
viewtopic.php?t=1639