aboutsummaryrefslogtreecommitdiff
path: root/src/lib/trayicon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/trayicon.c')
-rw-r--r--src/lib/trayicon.c43
1 files changed, 37 insertions, 6 deletions
diff --git a/src/lib/trayicon.c b/src/lib/trayicon.c
index 6c426f00..0be8541f 100644
--- a/src/lib/trayicon.c
+++ b/src/lib/trayicon.c
@@ -45,10 +45,37 @@ static GtkWindow *main_window;
45static void 45static void
46tray_icon_on_click (GtkStatusIcon * status_icon, gpointer user_data) 46tray_icon_on_click (GtkStatusIcon * status_icon, gpointer user_data)
47{ 47{
48 if (gtk_window_is_active (main_window)) 48 gboolean tlf;
49
50 g_object_get (main_window,
51 "visible", &tlf,
52 NULL);
53 if (tlf)
54 {
49 gtk_widget_hide (GTK_WIDGET (main_window)); 55 gtk_widget_hide (GTK_WIDGET (main_window));
56 }
50 else 57 else
51 gtk_window_present (main_window); 58 {
59 gtk_widget_show (GTK_WIDGET (main_window));
60 gtk_window_deiconify (main_window);
61 gtk_widget_grab_focus (GTK_WIDGET (main_window));
62 }
63}
64
65
66/**
67 * Function called from trayicon "quit" context menu
68 * to trigger shutdown.
69 *
70 * @param menuitem quit item
71 * @param user_data the main loop context
72 */
73void
74GNUNET_GTK_tray_icon_quit (GtkMenuItem *menuitem,
75 gpointer user_data)
76{
77 /* struct GNUNET_GTK_MainLoop *ml = user_data; */
78 GNUNET_SCHEDULER_shutdown ();
52} 79}
53 80
54 81
@@ -59,6 +86,7 @@ tray_icon_on_click (GtkStatusIcon * status_icon, gpointer user_data)
59static int 86static int
60tray_icon_on_menu (GtkWidget * widget, GdkEvent * event, gpointer user_data) 87tray_icon_on_menu (GtkWidget * widget, GdkEvent * event, gpointer user_data)
61{ 88{
89 struct GNUNET_GTK_MainLoop *ml = user_data;
62 GtkMenu *tray_menu; 90 GtkMenu *tray_menu;
63 GdkEventButton *event_button; 91 GdkEventButton *event_button;
64 GtkBuilder *builder; 92 GtkBuilder *builder;
@@ -68,10 +96,11 @@ tray_icon_on_menu (GtkWidget * widget, GdkEvent * event, gpointer user_data)
68 event_button = (GdkEventButton *) event; 96 event_button = (GdkEventButton *) event;
69 if (event_button->button == 3) 97 if (event_button->button == 3)
70 { 98 {
71 builder = GNUNET_GTK_get_new_builder ("gnunet_gtk_status_bar_menu.glade", NULL); 99 builder = GNUNET_GTK_get_new_builder ("gnunet_gtk_status_bar_menu.glade", ml);
72 tray_menu = 100 tray_menu =
73 GTK_MENU (gtk_builder_get_object 101 GTK_MENU (gtk_builder_get_object
74 (builder, "GNUNET_GTK_status_bar_popup_menu")); 102 (builder, "GNUNET_GTK_status_bar_popup_menu"));
103 g_object_ref (tray_menu);
75 gtk_menu_popup (tray_menu, NULL, NULL, NULL, NULL, event_button->button, 104 gtk_menu_popup (tray_menu, NULL, NULL, NULL, NULL, event_button->button,
76 event_button->time); 105 event_button->time);
77 g_object_unref (builder); 106 g_object_unref (builder);
@@ -84,12 +113,14 @@ tray_icon_on_menu (GtkWidget * widget, GdkEvent * event, gpointer user_data)
84/** 113/**
85 * Create our tray icon. 114 * Create our tray icon.
86 * 115 *
116 * @param ml main loop
87 * @param main handle to the main window (show or hide) 117 * @param main handle to the main window (show or hide)
88 * @param icon_name name of the tray icon file 118 * @param icon_name name of the tray icon file
89 * @param tooltip tooltip for the tray icon 119 * @param tooltip tooltip for the tray icon
90 */ 120 */
91void 121void
92GNUNET_GTK_tray_icon_create (GtkWindow * main, const char *icon_name, 122GNUNET_GTK_tray_icon_create (struct GNUNET_GTK_MainLoop *ml,
123 GtkWindow * main, const char *icon_name,
93 const char *tooltip) 124 const char *tooltip)
94{ 125{
95 if (NULL != tray_icon) 126 if (NULL != tray_icon)
@@ -100,9 +131,9 @@ GNUNET_GTK_tray_icon_create (GtkWindow * main, const char *icon_name,
100 main_window = main; 131 main_window = main;
101 tray_icon = gtk_status_icon_new (); 132 tray_icon = gtk_status_icon_new ();
102 g_signal_connect (G_OBJECT (tray_icon), "activate", 133 g_signal_connect (G_OBJECT (tray_icon), "activate",
103 G_CALLBACK (tray_icon_on_click), NULL); 134 G_CALLBACK (tray_icon_on_click), ml);
104 g_signal_connect (G_OBJECT (tray_icon), "button_press_event", 135 g_signal_connect (G_OBJECT (tray_icon), "button_press_event",
105 G_CALLBACK (tray_icon_on_menu), tray_icon); 136 G_CALLBACK (tray_icon_on_menu), ml);
106 gtk_status_icon_set_from_icon_name (tray_icon, icon_name); 137 gtk_status_icon_set_from_icon_name (tray_icon, icon_name);
107 gtk_status_icon_set_tooltip_text (tray_icon, tooltip); 138 gtk_status_icon_set_tooltip_text (tray_icon, tooltip);
108 gtk_status_icon_set_visible (tray_icon, TRUE); 139 gtk_status_icon_set_visible (tray_icon, TRUE);