#include <gtk/gtk.h>

GtkWidget *
create_menu (GObject *status_icon)
{
  GtkWidget *menu;
  GtkWidget *item1;

  menu = gtk_menu_new ();
  gtk_widget_show (menu);

  item1 = gtk_menu_item_new_with_mnemonic ("_File");
  gtk_widget_show (item1);
  gtk_container_add (GTK_CONTAINER (menu), item1);

  return g_object_ref_sink (menu);
}

static void
activate_cb (GtkStatusIcon *status_icon, gpointer data)
{
  GtkWidget *menu;
  GdkEvent *event;
  guint32 time;

  menu = create_menu (G_OBJECT (status_icon));
  event = gdk_event_new (GDK_3BUTTON_PRESS);
  time = gdk_event_get_time (event);
  gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
                  gtk_status_icon_position_menu, status_icon,
                  2, time);
  gdk_event_free (event);
  g_object_unref (menu);
}

static void
popup_cb (GtkStatusIcon *status_icon, gpointer data)
{
  gtk_main_quit ();
}

int
main (int argc, char *argv[])
{
  GtkStatusIcon *status_icon;

  gtk_init (&argc, &argv);

  status_icon = gtk_status_icon_new ();
  gtk_status_icon_set_from_icon_name (status_icon, "utilities-terminal");
  gtk_status_icon_set_visible (status_icon, TRUE);

  g_signal_connect (G_OBJECT (status_icon), "activate",
                    G_CALLBACK (activate_cb), NULL);
  g_signal_connect (G_OBJECT (status_icon), "popup-menu",
                    G_CALLBACK (popup_cb), NULL);

  gtk_main ();

  return 0;
}
