auto close menu on windows

This commit is contained in:
TingPing 2012-11-18 16:35:18 -05:00
parent d67dc36bbe
commit a7631810bd

View File

@ -60,6 +60,8 @@ typedef GdkPixbuf* TrayIcon;
static GtkStatusIcon *sticon; static GtkStatusIcon *sticon;
static gint flash_tag; static gint flash_tag;
static TrayStatus tray_status; static TrayStatus tray_status;
static guint tray_menu_timer;
static gint64 tray_menu_inactivetime;
static hexchat_plugin *ph; static hexchat_plugin *ph;
static TrayIcon custom_icon1; static TrayIcon custom_icon1;
@ -494,8 +496,34 @@ tray_menu_destroy (GtkWidget *menu, gpointer userdata)
{ {
gtk_widget_destroy (menu); gtk_widget_destroy (menu);
g_object_unref (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 static void
tray_menu_cb (GtkWidget *widget, guint button, guint time, gpointer userdata) 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_object_unref (menu);
g_signal_connect (G_OBJECT (menu), "selection-done", g_signal_connect (G_OBJECT (menu), "selection-done",
G_CALLBACK (tray_menu_destroy), NULL); 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, gtk_menu_popup (GTK_MENU (menu), NULL, NULL, gtk_status_icon_position_menu,
userdata, button, time); userdata, button, time);