/* gcc -Wall -o test-tray `pkg-config --cflags --libs gtk+-2.0` test-tray.c */
#include <string.h>
#include <gtk/gtk.h>

static gboolean workaround = FALSE;

static gboolean
unref_icon(gpointer data)
{
	if (workaround) {
		gtk_status_icon_set_visible (GTK_STATUS_ICON (data), FALSE);
	}

	g_object_unref (GTK_STATUS_ICON (data));
	return FALSE;
}

static gboolean
create_icons (gpointer data)
{
	GtkStatusIcon *icon;
	static int count = 0;

	g_print ("Creating icon (previous count: %d)\n", count++);
	icon = gtk_status_icon_new_from_icon_name ("dialog-information");
	g_idle_add(unref_icon, icon);

	return TRUE;
}

int
main (int argc, char **argv)
{
	gtk_init (&argc, &argv);

	if (argc > 1 && strcmp (argv[1], "--workaround") == 0) {
		workaround = TRUE;
	}

	g_timeout_add_seconds (1, create_icons, NULL);
	gtk_main ();

	return 0;
}
