From 289eb367d435668fc0515fdc33d0c73c33884cdd Mon Sep 17 00:00:00 2001
From: William Hua <william@attente.ca>
Date: Fri, 9 May 2014 13:05:35 -0400
Subject: [PATCH] Signal menu close transition in idle.

---
 gtk/gtkmenutrackeritem.c | 39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)

diff --git a/gtk/gtkmenutrackeritem.c b/gtk/gtkmenutrackeritem.c
index 232ac37..53fdc30 100644
--- a/gtk/gtkmenutrackeritem.c
+++ b/gtk/gtkmenutrackeritem.c
@@ -837,24 +837,53 @@ gtk_menu_tracker_opener_changed (GActionGroup *action_group,
     gtk_menu_tracker_opener_update (opener);
 }
 
+typedef struct
+{
+  GActionGroup *action_group;
+  gchar        *action_name;
+} GtkMenuTrackerCloser;
+
+static void
+gtk_menu_tracker_closer_real_free (gpointer data)
+{
+  GtkMenuTrackerCloser *closer = data;
+
+  g_free (closer->action_name);
+  g_object_unref (closer->action_group);
+  g_slice_free (GtkMenuTrackerCloser, closer);
+}
+
+static gboolean
+gtk_menu_tracker_closer_free (gpointer user_data)
+{
+  GtkMenuTrackerCloser *closer = user_data;
+
+  g_action_group_change_action_state (closer->action_group,
+                                      closer->action_name,
+                                      g_variant_new_boolean (FALSE));
+
+  return G_SOURCE_REMOVE;
+}
+
 static void
 gtk_menu_tracker_opener_free (gpointer data)
 {
   GtkMenuTrackerOpener *opener = data;
+  GtkMenuTrackerCloser *closer;
 
   g_signal_handlers_disconnect_by_func (opener->item->observable, gtk_menu_tracker_opener_added, opener);
   g_signal_handlers_disconnect_by_func (opener->item->observable, gtk_menu_tracker_opener_removed, opener);
   g_signal_handlers_disconnect_by_func (opener->item->observable, gtk_menu_tracker_opener_changed, opener);
 
-  g_action_group_change_action_state (G_ACTION_GROUP (opener->item->observable),
-                                      opener->submenu_action,
-                                      g_variant_new_boolean (FALSE));
-
   gtk_menu_tracker_item_set_submenu_shown (opener->item, FALSE);
 
-  g_free (opener->submenu_action);
+  closer = g_slice_new (GtkMenuTrackerCloser);
+  closer->action_group = g_object_ref (opener->item->observable);
+  closer->action_name = opener->submenu_action;
 
   g_slice_free (GtkMenuTrackerOpener, opener);
+
+  g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, gtk_menu_tracker_closer_free, closer, gtk_menu_tracker_closer_real_free);
 }
 
 static GtkMenuTrackerOpener *
-- 
1.9.1

