Index: NSMenuView.m
===================================================================
--- NSMenuView.m	(revision 32212)
+++ NSMenuView.m	(working copy)
@@ -1439,7 +1439,6 @@
   int delayCount = 0;
   int indexOfActionToExecute = -1;
   int firstIndex = -1;
-  int space = 0;
   NSEvent *original;
   NSEventType type;
   NSEventType end;
@@ -1487,7 +1486,6 @@
       eventMask |= NSLeftMouseUpMask | NSLeftMouseDraggedMask;
       eventMask |= NSLeftMouseDownMask;
     }
-
   /* We attempt to mimic Mac OS X behavior for pop up menus. If the user
      presses the mouse button over a pop up button and then drags the mouse
      over the menu, the is closed when the user releases the mouse. On the
@@ -1503,6 +1501,11 @@
        */
       shouldFinish = NO;
     }
+  
+  // Capture the mouse so we get clicks outside the menus and
+  // GNUstep windows.
+  [_window _captureMouse: self];
+
   do
     {
       /*Close the menu if the user press a modifier key and menu
@@ -1512,6 +1515,7 @@
 	{
 	  [self setHighlightedItemIndex: -1];
 	  [[[[NSApp mainWindow] menu] attachedMenu] close];
+	  [_window _releaseMouse: self];
 	  return NO;
 	}
 
@@ -1585,7 +1589,6 @@
               NSPoint locationInScreenCoordinates;
               NSWindow *windowUnderMouse;
               NSMenu *candidateMenu;
-	      NSMenu *anAttachedMenu = [[[NSApp mainWindow] menu] attachedMenu];
 
               subMenusNeedRemoving = NO;
 
@@ -1631,6 +1634,7 @@
                   
                   candidateMenuResult = [[candidateMenu menuRepresentation]
                            trackWithEvent: original];
+                  [_window _releaseMouse: self];
                   return candidateMenuResult;
                 }
 
@@ -1650,6 +1654,7 @@
                     {
                       [self detachSubmenu];
                     }
+                  [_window _releaseMouse: self];
                   return subMenuResult;
                 }
 	      
@@ -1660,25 +1665,28 @@
 		  ![[self menu] isTransient] &&
 		  ![[self menu] _ownedByPopUp])
 		{
-		  if ([self hitTest: location] == nil)
+                  // If the user moves the mouse into the main window
+                  // horizontal menu, start tracking again.
+                  NSWindow *mainWindow = [NSApp mainWindow];
+                  NSMenuView *mainWindowMenuView = [[mainWindow menu]
+                    menuRepresentation];
+                  NSPoint locationInMainWindow = [mainWindow 
+                    convertScreenToBase: locationInScreenCoordinates];
+		  if ([mainWindowMenuView 
+                        hitTest: locationInMainWindow] != nil)
 		    {
-		      /*This gives us time to move the cursor between a menu and
-			its submenu (or vice versa) without lose the mouse
-			tracking*/
-		      space += 1;
-
-		      if (space == 2)
-			{
-			  [anAttachedMenu close];
-			  return NO;
-			}
-		    }
-		  
-		  if (self != [[[NSApp mainWindow] menu] menuRepresentation])
-		    {
-		      [self setHighlightedItemIndex: -1];
-		      return [[[[NSApp mainWindow] menu] menuRepresentation]
+                      int index = [mainWindowMenuView indexOfItemAtPoint: 
+                        [mainWindowMenuView 
+                          convertPoint: locationInMainWindow
+                              fromView: nil]];
+                      if (index != -1 &&
+                          index != [mainWindowMenuView highlightedItemIndex])
+                        {
+		          [self setHighlightedItemIndex: -1];
+	                  [_window _releaseMouse: self];
+		          return [[[[NSApp mainWindow] menu] menuRepresentation]
 			       trackWithEvent: original];
+                        }
 		    }
 		}
             }
@@ -1711,6 +1719,9 @@
     }
   while (type != end || shouldFinish == NO);
 
+  // Uncapture the mouse again.
+  [_window _releaseMouse: self];
+
   /*
    * Ok, we released the mouse
    * There are now a few possibilities:
