#include <glib.h>
#include <gtk/gtk.h>

static gboolean focus_out(GtkWidget *widget, GdkEvent *event,
		gpointer user_data)
{
	gtk_menu_popup(GTK_MENU(user_data), NULL, NULL, NULL, NULL, 0,
			gtk_get_current_event_time());
	return FALSE;
}

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

	GtkWidget *m = gtk_menu_new();

	GtkWidget *item = gtk_menu_item_new_with_label("Foo");
	gtk_menu_shell_append(GTK_MENU_SHELL(m), item);
	gtk_widget_show_all(item);

	GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_widget_show_all(window);

	g_signal_connect(G_OBJECT(window), "focus-out-event",
			(GCallback)focus_out, m);

//	gtk_menu_popup(GTK_MENU(m), NULL, NULL, NULL, NULL, 0,
//			gtk_get_current_event_time());

	gtk_main();

	return 0;
}
