Index: src/display.c
===================================================================
RCS file: /cvs/gnome/metacity/src/display.c,v
retrieving revision 1.286
diff -u -p -r1.286 display.c
--- src/display.c	26 May 2006 16:51:03 -0000	1.286
+++ src/display.c	16 Jun 2006 23:13:53 -0000
@@ -64,6 +64,7 @@
 #include <X11/Xcursor/Xcursor.h>
 #endif
 #include <string.h>
+#include "gdk/gdkdisplay.h"
 
 #define GRAB_OP_IS_WINDOW_SWITCH(g)                     \
         (g == META_GRAB_OP_KEYBOARD_TABBING_NORMAL  ||  \
@@ -1776,9 +1777,40 @@ event_callback (XEvent   *event,
       break;
     case ButtonRelease:
       if (display->grab_window == window &&
-          event->xany.serial >= display->grab_start_serial &&
-          grab_op_is_mouse (display->grab_op))
-        meta_window_handle_mouse_grab_op_event (window, event);
+          event->xany.serial >= display->grab_start_serial)
+        {
+         
+          if (grab_op_is_mouse (display->grab_op))
+            meta_window_handle_mouse_grab_op_event (window, event);
+          else if (display->grab_op == META_GRAB_OP_CLICKING_MENU &&
+              meta_prefs_get_close_on_double_click_menu())
+            {
+              /* We can't rely on GTK's idea of what a double-click is
+               * here, since we're on our own during a grab. And X itself
+               * doesn't grok the concept of double-clicks. So we keep a
+               * track of when they last clicked on the menu button...
+               */
+              static unsigned long previous_menu_click = 0;
+              
+              guint click_delay = event->xbutton.time - previous_menu_click;
+
+              /* But we *can* ask GDK how long it thinks a double-click
+               * should take.
+               */
+              if (click_delay <= gdk_display_get_default()->double_click_time)
+                {
+                  /* Okay, so they double-clicked the menu button. */
+                  meta_display_end_grab_op (display,
+                                            event->xbutton.time);
+
+                  if (window)
+                    if (window->has_close_func)
+                      meta_window_delete (window, event->xbutton.time);
+                }
+              
+              previous_menu_click = event->xbutton.time;
+            }
+        }
       break;
     case MotionNotify:
       if (display->grab_window == window &&
Index: src/prefs.c
===================================================================
RCS file: /cvs/gnome/metacity/src/prefs.c,v
retrieving revision 1.67
diff -u -p -r1.67 prefs.c
--- src/prefs.c	15 May 2006 06:59:30 -0000	1.67
+++ src/prefs.c	16 Jun 2006 23:13:57 -0000
@@ -56,6 +56,7 @@
 #define KEY_BUTTON_LAYOUT "/apps/metacity/general/button_layout"
 #define KEY_REDUCED_RESOURCES "/apps/metacity/general/reduced_resources"
 #define KEY_GNOME_ACCESSIBILITY "/desktop/gnome/interface/accessibility"
+#define KEY_CLOSE_ON_DOUBLE_CLICK_MENU "/apps/metacity/general/close_on_double_click_menu"
 
 #define KEY_COMMAND_PREFIX "/apps/metacity/keybinding_commands/command_"
 
@@ -99,6 +100,7 @@ static gboolean provide_visual_bell = FA
 static gboolean bell_is_audible = TRUE;
 static gboolean reduced_resources = FALSE;
 static gboolean gnome_accessibility = FALSE;
+static gboolean close_on_double_click_menu = FALSE;
 static char *cursor_theme = NULL;
 static int   cursor_size = 24;
 static gboolean compositing_manager = FALSE;
@@ -161,6 +163,7 @@ static gboolean update_workspace_name   
                                            const char  *value);
 static gboolean update_reduced_resources  (gboolean     value);
 static gboolean update_gnome_accessibility  (gboolean     value);
+static gboolean update_close_on_double_click_menu (gboolean     value);
 static gboolean update_cursor_theme       (const char *value);
 static gboolean update_cursor_size        (int size);
 static gboolean update_compositing_manager (gboolean	value);
@@ -418,6 +421,9 @@ meta_prefs_init (void)
   if (get_bool (KEY_AUTO_RAISE, &bool_val))
     update_auto_raise (bool_val);
 
+  if (get_bool (KEY_CLOSE_ON_DOUBLE_CLICK_MENU, &bool_val))
+    update_close_on_double_click_menu (bool_val);
+
   /* FIXME: Since auto_raise_delay of 0 is valid and gconf_client_get_int
    * silently returns that value when KEY_AUTO_RAISE_DELAY doesn't exist,
    * we should be using gconf_client_get() instead if we cared about
@@ -989,6 +995,22 @@ change_notify (GConfClient    *client,
       if (update_gnome_accessibility (b))
         queue_changed (META_PREF_GNOME_ACCESSIBILITY);
     }
+  else if (strcmp (key, KEY_CLOSE_ON_DOUBLE_CLICK_MENU) == 0)
+    {
+      gboolean b;
+
+      if (value && value->type != GCONF_VALUE_BOOL)
+        {
+          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
+                        KEY_CLOSE_ON_DOUBLE_CLICK_MENU);
+          goto out;
+        }
+
+      b = value ? gconf_value_get_bool (value) : close_on_double_click_menu;
+
+      if (update_close_on_double_click_menu (b))
+        queue_changed (META_PREF_CLOSE_ON_DOUBLE_CLICK_MENU);
+    }
   else if (strcmp (key, KEY_CURSOR_THEME) == 0)
     {
       const char *str;
@@ -1670,6 +1692,17 @@ update_gnome_accessibility (gboolean val
   
   return old != gnome_accessibility;
 }
+
+static gboolean
+update_close_on_double_click_menu (gboolean value)
+{
+  gboolean old = close_on_double_click_menu;
+
+  close_on_double_click_menu = value;
+
+  return old != close_on_double_click_menu;
+}
+
 #endif /* HAVE_GCONF */
 
 #ifdef WITH_VERBOSE_MODE
@@ -1747,6 +1780,9 @@ meta_preference_to_string (MetaPreferenc
     case META_PREF_GNOME_ACCESSIBILITY:
       return "GNOME_ACCESSIBILTY";
 
+    case META_PREF_CLOSE_ON_DOUBLE_CLICK_MENU:
+      return "CLOSE_ON_DOUBLE_CLICK_MENU";
+      
     case META_PREF_CURSOR_THEME:
       return "CURSOR_THEME";
 
@@ -2841,6 +2877,12 @@ gboolean
 meta_prefs_get_gnome_accessibility ()
 {
   return gnome_accessibility;
+}
+
+gboolean
+meta_prefs_get_close_on_double_click_menu ()
+{
+  return close_on_double_click_menu;
 }
 
 MetaKeyBindingAction
Index: src/prefs.h
===================================================================
RCS file: /cvs/gnome/metacity/src/prefs.h,v
retrieving revision 1.43
diff -u -p -r1.43 prefs.h
--- src/prefs.h	17 Apr 2006 17:23:09 -0000	1.43
+++ src/prefs.h	16 Jun 2006 23:13:57 -0000
@@ -52,6 +52,7 @@ typedef enum
   META_PREF_VISUAL_BELL_TYPE,
   META_PREF_REDUCED_RESOURCES,
   META_PREF_GNOME_ACCESSIBILITY,
+  META_PREF_CLOSE_ON_DOUBLE_CLICK_MENU,
   META_PREF_CURSOR_THEME,
   META_PREF_CURSOR_SIZE,
   META_PREF_COMPOSITING_MANAGER
@@ -82,6 +83,7 @@ gboolean                    meta_prefs_g
 int                         meta_prefs_get_auto_raise_delay   (void);
 gboolean                    meta_prefs_get_reduced_resources  (void);
 gboolean                    meta_prefs_get_gnome_accessibility (void);
+gboolean                    meta_prefs_get_close_on_double_click_menu (void);
 
 const char*                 meta_prefs_get_command            (int i);
 
