/* gcc -o demo-statusicon `pkg-config --cflags --libs gtk+-2.0` demo-statusicon.c * * Copyright (C) 2007 Imendio AB * Contact: Carlos Garnacho * * This work is provided "as is"; redistribution and modification * in whole or in part, in any medium, physical or electronic is * permitted without restriction. * * This work is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * In no event shall the authors or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even * if advised of the possibility of such damage. */ #include static void popup_not_so_urgent_cb (GtkAction *action, gpointer data); static void popup_urgent_cb (GtkAction *action, gpointer data); static void popup_really_urgent_cb (GtkAction *action, gpointer data); static GtkActionEntry menu_items [] = { { "NoTanUrgente", NULL, "No tan urgente", NULL, NULL, G_CALLBACK (popup_not_so_urgent_cb) }, { "Urgente", NULL, "Urgente", NULL, NULL, G_CALLBACK (popup_urgent_cb) }, { "UrgenteDeLaLeche", NULL, "Urgente de la leche!", NULL, NULL, G_CALLBACK (popup_really_urgent_cb) }, }; const gchar *ui_description = "" " " " " " " " " " " ""; static void popup_not_so_urgent_cb (GtkAction *action, gpointer data) { GtkStatusIcon *icon; icon = GTK_STATUS_ICON (data); gtk_status_icon_set_from_stock (icon, GTK_STOCK_HELP); gtk_status_icon_set_blinking (icon, FALSE); } static void popup_urgent_cb (GtkAction *action, gpointer data) { GtkStatusIcon *icon; icon = GTK_STATUS_ICON (data); gtk_status_icon_set_from_stock (icon, GTK_STOCK_STOP); gtk_status_icon_set_blinking (icon, FALSE); } static void popup_really_urgent_cb (GtkAction *action, gpointer data) { GtkStatusIcon *icon; icon = GTK_STATUS_ICON (data); gtk_status_icon_set_from_stock (icon, GTK_STOCK_STOP); gtk_status_icon_set_blinking (icon, TRUE); } static GtkWidget* create_popup (GtkStatusIcon *icon) { GtkWidget *popup; GtkActionGroup *action_group; GtkUIManager *ui_manager; action_group = gtk_action_group_new ("PopupActions"); gtk_action_group_set_translation_domain (action_group, NULL); gtk_action_group_add_actions (action_group, menu_items, G_N_ELEMENTS (menu_items), icon); ui_manager = gtk_ui_manager_new (); gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); if (gtk_ui_manager_add_ui_from_string (ui_manager, ui_description, -1, NULL)) { popup = gtk_ui_manager_get_widget (ui_manager, "/ui/PopupMenu"); } return popup; } static void do_popup_menu (GtkStatusIcon *icon, guint button, guint activate_time, gpointer data) { GtkWidget *popup; popup = GTK_WIDGET (data); gtk_menu_popup (GTK_MENU (popup), NULL, NULL, NULL, NULL, button, activate_time); } gint main (gint argc, gchar *argv[]) { GtkStatusIcon *icon; GtkWidget *popup; gtk_init (&argc, &argv); icon = gtk_status_icon_new_from_stock (GTK_STOCK_HELP); popup = create_popup (icon); g_signal_connect (icon, "popup-menu", G_CALLBACK (do_popup_menu), popup); gtk_main (); }