From a7631810bdd00232b6039cb94ed9079b46eba144 Mon Sep 17 00:00:00 2001 From: TingPing Date: Sun, 18 Nov 2012 16:35:18 -0500 Subject: auto close menu on windows --- src/fe-gtk/plugin-tray.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src') diff --git a/src/fe-gtk/plugin-tray.c b/src/fe-gtk/plugin-tray.c index 4380b450..a5623b3f 100644 --- a/src/fe-gtk/plugin-tray.c +++ b/src/fe-gtk/plugin-tray.c @@ -60,6 +60,8 @@ typedef GdkPixbuf* TrayIcon; static GtkStatusIcon *sticon; static gint flash_tag; static TrayStatus tray_status; +static guint tray_menu_timer; +static gint64 tray_menu_inactivetime; static hexchat_plugin *ph; static TrayIcon custom_icon1; @@ -494,8 +496,34 @@ tray_menu_destroy (GtkWidget *menu, gpointer userdata) { gtk_widget_destroy (menu); g_object_unref (menu); +#ifdef WIN32 + g_source_remove (tray_menu_timer); +#endif +} + +#ifdef WIN32 +static void +tray_menu_enter_cb (GtkWidget *menu) +{ + tray_menu_inactivetime = 0; +} + +static void +tray_menu_left_cb (GtkWidget *menu) +{ + tray_menu_inactivetime = g_get_real_time (); } +static void +tray_check_hide (GtkWidget *menu) +{ + if (tray_menu_inactivetime && g_get_real_time () - tray_menu_inactivetime >= 2000000) + { + tray_menu_destroy (menu, NULL); + } +} +#endif + static void tray_menu_cb (GtkWidget *widget, guint button, guint time, gpointer userdata) { @@ -549,6 +577,16 @@ tray_menu_cb (GtkWidget *widget, guint button, guint time, gpointer userdata) g_object_unref (menu); g_signal_connect (G_OBJECT (menu), "selection-done", G_CALLBACK (tray_menu_destroy), NULL); +#ifdef WIN32 + g_signal_connect (G_OBJECT (menu), "leave-notify-event", + G_CALLBACK (tray_menu_left_cb), NULL); + g_signal_connect (G_OBJECT (menu), "enter-notify-event", + G_CALLBACK (tray_menu_enter_cb), NULL); + + tray_menu_timer = g_timeout_add(500, (GSourceFunc) tray_check_hide, menu); +#endif + + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, gtk_status_icon_position_menu, userdata, button, time); -- cgit 1.4.1