diff options
author | TingPing <tingping@tingping.se> | 2012-11-18 16:35:18 -0500 |
---|---|---|
committer | TingPing <tingping@tingping.se> | 2012-11-18 16:35:18 -0500 |
commit | a7631810bdd00232b6039cb94ed9079b46eba144 (patch) | |
tree | 4788e56c5638e47c8a16433bffcedf7b4d516254 | |
parent | d67dc36bbec949e4cfe5cc0d6a837e6576b85080 (diff) |
auto close menu on windows
-rw-r--r-- | src/fe-gtk/plugin-tray.c | 38 |
1 files changed, 38 insertions, 0 deletions
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,9 +496,35 @@ 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) { static GtkWidget *menu; @@ -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); |