Index: gtk/gtkmenu.c
===================================================================
--- gtk/gtkmenu.c	(revision 17656)
+++ gtk/gtkmenu.c	(working copy)
@@ -1429,6 +1429,19 @@ gtk_menu_popup (GtkMenu		    *menu,
 
   gtk_menu_scroll_to (menu, menu->scroll_offset);
 
+  /* if no item is selected, select the first one */
+  if (!menu_shell->active_menu_item)
+    {
+      gboolean touchscreen_mode;
+
+      g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu)),
+                    "gtk-touchscreen-mode", &touchscreen_mode,
+                    NULL);
+
+      if (touchscreen_mode)
+        gtk_menu_shell_select_first (menu_shell, TRUE);
+    }
+
   /* Once everything is set up correctly, map the toplevel window on
      the screen.
    */
Index: gtk/gtkmenushell.c
===================================================================
--- gtk/gtkmenushell.c	(revision 17656)
+++ gtk/gtkmenushell.c	(working copy)
@@ -32,6 +32,7 @@
 #include "gtkkeyhash.h"
 #include "gtkmain.h"
 #include "gtkmarshalers.h"
+#include "gtkmenu.h"
 #include "gtkmenubar.h"
 #include "gtkmenuitem.h"
 #include "gtkmenushell.h"
@@ -132,7 +133,8 @@ struct _GtkMenuShellPrivate
   GtkMnemonicHash *mnemonic_hash;
   GtkKeyHash *key_hash;
 
-  gboolean take_focus;
+  guint take_focus : 1;
+  guint activated_submenu : 1;
 };
 
 static void gtk_menu_shell_set_property      (GObject           *object,
@@ -365,6 +367,7 @@ gtk_menu_shell_init (GtkMenuShell *menu_
   priv->mnemonic_hash = NULL;
   priv->key_hash = NULL;
   priv->take_focus = TRUE;
+  priv->activated_submenu = FALSE;
 }
 
 static void
@@ -520,26 +523,22 @@ gtk_menu_shell_button_press (GtkWidget  
   GtkMenuShell *menu_shell;
   GtkWidget *menu_item;
 
-  g_return_val_if_fail (GTK_IS_MENU_SHELL (widget), FALSE);
-  g_return_val_if_fail (event != NULL, FALSE);
-
   if (event->type != GDK_BUTTON_PRESS)
     return FALSE;
 
   menu_shell = GTK_MENU_SHELL (widget);
 
   if (menu_shell->parent_menu_shell)
-    {
       return gtk_widget_event (menu_shell->parent_menu_shell, (GdkEvent*) event);
-    }
-  else if (!menu_shell->active || !menu_shell->button)
+
+  menu_item = gtk_menu_shell_get_item (menu_shell, (GdkEvent *)event);
+
+  if (!menu_shell->active || !menu_shell->button)
     {
       _gtk_menu_shell_activate (menu_shell);
       
       menu_shell->button = event->button;
 
-      menu_item = gtk_menu_shell_get_item (menu_shell, (GdkEvent *)event);
-
       if (menu_item && _gtk_menu_item_is_selectable (menu_item))
 	{
 	  if ((menu_item->parent == widget) &&
@@ -564,6 +563,19 @@ gtk_menu_shell_button_press (GtkWidget  
 	}
     }
 
+  if (menu_item && _gtk_menu_item_is_selectable (menu_item) &&
+      GTK_MENU_ITEM (menu_item)->submenu != NULL &&
+      !GTK_WIDGET_VISIBLE (GTK_MENU_ITEM (menu_item)->submenu))
+    {
+      GtkMenuShellPrivate *priv;
+
+      gtk_menu_shell_select_item (menu_shell, menu_item);
+      _gtk_menu_item_popup_submenu (menu_item, FALSE);
+
+      priv = GTK_MENU_SHELL_GET_PRIVATE (menu_item->parent);
+      priv->activated_submenu = TRUE;
+    }
+
   return TRUE;
 }
 
@@ -591,16 +603,14 @@ static gint
 gtk_menu_shell_button_release (GtkWidget      *widget,
 			       GdkEventButton *event)
 {
-  GtkMenuShell *menu_shell;
-  GtkWidget *menu_item;
-  gint deactivate;
-
-  g_return_val_if_fail (GTK_IS_MENU_SHELL (widget), FALSE);
-  g_return_val_if_fail (event != NULL, FALSE);
+  GtkMenuShell *menu_shell = GTK_MENU_SHELL (widget);
+  GtkMenuShellPrivate *priv = GTK_MENU_SHELL_GET_PRIVATE (widget);
 
-  menu_shell = GTK_MENU_SHELL (widget);
   if (menu_shell->active)
     {
+      GtkWidget *menu_item;
+      gboolean   deactivate = TRUE;
+
       if (menu_shell->button && (event->button != menu_shell->button))
 	{
 	  menu_shell->button = 0;
@@ -611,22 +621,59 @@ gtk_menu_shell_button_release (GtkWidget
       menu_shell->button = 0;
       menu_item = gtk_menu_shell_get_item (menu_shell, (GdkEvent*) event);
 
-      deactivate = TRUE;
-
       if ((event->time - menu_shell->activate_time) > MENU_SHELL_TIMEOUT)
 	{
 	  if (menu_item && (menu_shell->active_menu_item == menu_item) &&
 	      _gtk_menu_item_is_selectable (menu_item))
 	    {
-	      if (GTK_MENU_ITEM (menu_item)->submenu == NULL)
+              GtkWidget *submenu = GTK_MENU_ITEM (menu_item)->submenu;
+
+              if (submenu == NULL)
 		{
 		  gtk_menu_shell_activate_item (menu_shell, menu_item, TRUE);
-		  return TRUE;
+
+                  deactivate = FALSE;
+                }
+              else
+                {
+                  gint popdown_delay;
+                  GTimeVal *popup_time;
+                  gint64 usec_since_popup = 0;
+
+                  g_object_get (gtk_widget_get_settings (widget),
+                                "gtk-menu-popdown-delay", &popdown_delay,
+                                NULL);
+
+                  popup_time = g_object_get_data (G_OBJECT (submenu),
+                                                  "gtk-menu-exact-popup-time");
+
+                  if (popup_time)
+                    {
+                      GTimeVal current_time;
+
+                      g_get_current_time (&current_time);
+
+                      usec_since_popup = ((gint64) current_time.tv_sec * 1000 * 1000 +
+                                          (gint64) current_time.tv_usec -
+                                          (gint64) popup_time->tv_sec * 1000 * 1000 -
+                                          (gint64) popup_time->tv_usec);
+
+                      g_object_set_data (G_OBJECT (submenu),
+                                         "gtk-menu-exact-popup-time", NULL);
+                    }
+
+                  if (!priv->activated_submenu &&
+                      (usec_since_popup == 0 ||
+                       usec_since_popup > popdown_delay * 1000))
+                    {
+                      _gtk_menu_item_popdown_submenu (menu_item);
 		}
 	      else if (GTK_MENU_SHELL_GET_CLASS (menu_shell)->submenu_placement != GTK_TOP_BOTTOM)
 		{
 		  gtk_menu_item_select (GTK_MENU_ITEM (menu_item));
-		  return TRUE;
+                    }
+
+                  deactivate = FALSE;
 		}
 	    }
 	  else if (menu_item &&
@@ -639,7 +686,7 @@ gtk_menu_shell_button_release (GtkWidget
 	    {
 	      menu_shell->active = TRUE;
 	      gtk_widget_event (menu_shell->parent_menu_shell, (GdkEvent*) event);
-	      return TRUE;
+              deactivate = FALSE;
 	    }
 
 	  /* If we ended up on an item with a submenu, leave the menu up.
@@ -668,6 +715,8 @@ gtk_menu_shell_button_release (GtkWidget
 	  gtk_menu_shell_deactivate (menu_shell);
 	  g_signal_emit (menu_shell, menu_shell_signals[SELECTION_DONE], 0);
 	}
+
+      priv->activated_submenu = FALSE;
     }
 
   return TRUE;
@@ -706,7 +755,6 @@ gtk_menu_shell_enter_notify (GtkWidget  
 			     GdkEventCrossing *event)
 {
   GtkMenuShell *menu_shell;
-  GtkWidget *menu_item;
 
   g_return_val_if_fail (GTK_IS_MENU_SHELL (widget), FALSE);
   g_return_val_if_fail (event != NULL, FALSE);
@@ -715,6 +763,8 @@ gtk_menu_shell_enter_notify (GtkWidget  
 
   if (menu_shell->active)
     {
+      GtkWidget *menu_item;
+
       menu_item = gtk_get_event_widget ((GdkEvent*) event);
 
       if (!menu_item ||
@@ -733,6 +783,22 @@ gtk_menu_shell_enter_notify (GtkWidget  
 	      (GTK_WIDGET_STATE (menu_item) != GTK_STATE_PRELIGHT))
 	    {
 	      gtk_menu_shell_select_item (menu_shell, menu_item);
+
+              /* If the pen is down, and there is a submenu that is not
+               * yet visible, activate it
+               */
+              if ((event->state & GDK_BUTTON1_MASK) &&
+                  GTK_MENU_ITEM (menu_item)->submenu != NULL &&
+                  !GTK_WIDGET_VISIBLE (GTK_MENU_ITEM (menu_item)->submenu))
+                {
+                  GtkMenuShellPrivate *priv;
+
+                  priv = GTK_MENU_SHELL_GET_PRIVATE (menu_item->parent);
+
+                  _gtk_menu_item_popup_submenu (menu_item, TRUE);
+
+                  priv->activated_submenu = TRUE;
+                }
 	    }
 	}
       else if (menu_shell->parent_menu_shell)
@@ -1169,7 +1235,7 @@ gtk_menu_shell_select_submenu_first (Gtk
   
   if (menu_item->submenu)
     {
-      _gtk_menu_item_popup_submenu (GTK_WIDGET (menu_item));
+      _gtk_menu_item_popup_submenu (GTK_WIDGET (menu_item), FALSE);
       gtk_menu_shell_select_first (GTK_MENU_SHELL (menu_item->submenu), TRUE);
       if (GTK_MENU_SHELL (menu_item->submenu)->active_menu_item)
 	return TRUE;
@@ -1195,6 +1261,19 @@ gtk_real_menu_shell_move_current (GtkMen
     case GTK_MENU_DIR_PARENT:
       if (parent_menu_shell)
 	{
+          gboolean touchscreen_mode;
+
+          g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu_shell)),
+                        "gtk-touchscreen-mode", &touchscreen_mode,
+                        NULL);
+
+          if (touchscreen_mode)
+            {
+              /* close menu when returning from submenu. */
+              _gtk_menu_item_popdown_submenu (GTK_MENU (menu_shell)->parent_menu_item);
+              break;
+            }
+
 	  if (GTK_MENU_SHELL_GET_CLASS (parent_menu_shell)->submenu_placement ==
               GTK_MENU_SHELL_GET_CLASS (menu_shell)->submenu_placement)
 	    gtk_menu_shell_deselect (menu_shell);
@@ -1276,13 +1355,12 @@ gtk_real_menu_shell_activate_current (Gt
   if (menu_shell->active_menu_item &&
       _gtk_menu_item_is_selectable (menu_shell->active_menu_item))
   {
-   
     if (GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu == NULL)
       gtk_menu_shell_activate_item (menu_shell,
 				    menu_shell->active_menu_item,
 				    force_hide);
     else
-      _gtk_menu_item_popup_submenu (menu_shell->active_menu_item);
+      _gtk_menu_item_popup_submenu (menu_shell->active_menu_item, FALSE);
   }
 }
 
Index: gtk/gtkmenuitem.c
===================================================================
--- gtk/gtkmenuitem.c	(revision 17656)
+++ gtk/gtkmenuitem.c	(working copy)
@@ -79,7 +79,7 @@ static void gtk_real_menu_item_toggle_si
 static gboolean gtk_menu_item_mnemonic_activate     (GtkWidget   *widget,
 						     gboolean     group_cycling);
 
-static gint gtk_menu_item_select_timeout (gpointer          data);
+static gint gtk_menu_item_popup_timeout  (gpointer          data);
 static void gtk_menu_item_position_menu  (GtkMenu          *menu,
 					  gint             *x,
 					  gint             *y,
@@ -875,70 +875,26 @@ gtk_menu_item_expose (GtkWidget      *wi
   return FALSE;
 }
 
-static gint
-get_popup_delay (GtkMenuItem *menu_item)
-{
-  GtkWidget *parent = GTK_WIDGET (menu_item)->parent;
-
-  if (GTK_IS_MENU_SHELL (parent))
-    {
-      return _gtk_menu_shell_get_popup_delay (GTK_MENU_SHELL (parent));
-    }
-  else
-    {
-      gint popup_delay;
-      
-      g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu_item)),
-		    "gtk-menu-popup-delay", &popup_delay,
-		    NULL);
-
-      return popup_delay;
-    }
-}
-
 static void
 gtk_real_menu_item_select (GtkItem *item)
 {
   GtkMenuItem *menu_item;
+  gboolean touchscreen_mode;
 
   g_return_if_fail (GTK_IS_MENU_ITEM (item));
 
   menu_item = GTK_MENU_ITEM (item);
 
-  if (menu_item->submenu &&
+  g_object_get (gtk_widget_get_settings (GTK_WIDGET (item)),
+                "gtk-touchscreen-mode", &touchscreen_mode,
+                NULL);
+
+  if (!touchscreen_mode &&
+      menu_item->submenu &&
       (!GTK_WIDGET_MAPPED (menu_item->submenu) ||
        GTK_MENU (menu_item->submenu)->tearoff_active))
     {
-      gint popup_delay;
-
-      if (menu_item->timer)
-	{
-	  g_source_remove (menu_item->timer);
-	  menu_item->timer = 0;
-	  popup_delay = 0;
-	}
-      else
-	popup_delay = get_popup_delay (menu_item);
-      
-      if (popup_delay > 0)
-	{
-	  GdkEvent *event = gtk_get_current_event ();
-	  
-	  menu_item->timer = gdk_threads_add_timeout (popup_delay,
-					    gtk_menu_item_select_timeout,
-					    menu_item);
-	  if (event &&
-	      event->type != GDK_BUTTON_PRESS &&
-	      event->type != GDK_ENTER_NOTIFY)
-	    menu_item->timer_from_keypress = TRUE;
-	  else
-	    menu_item->timer_from_keypress = FALSE;
-
-	  if (event)
-	    gdk_event_free (event);
-	}
-      else
-	_gtk_menu_item_popup_submenu (GTK_WIDGET (menu_item));
+      _gtk_menu_item_popup_submenu (GTK_WIDGET (menu_item), TRUE);
     }
   
   gtk_widget_set_state (GTK_WIDGET (menu_item), GTK_STATE_PRELIGHT);
@@ -955,15 +911,7 @@ gtk_real_menu_item_deselect (GtkItem *it
   menu_item = GTK_MENU_ITEM (item);
 
   if (menu_item->submenu)
-    {
-      if (menu_item->timer)
-	{
-	  g_source_remove (menu_item->timer);
-	  menu_item->timer = 0;
-	}
-      else
-	gtk_menu_popdown (GTK_MENU (menu_item->submenu));
-    }
+    _gtk_menu_item_popdown_submenu (GTK_WIDGET (menu_item));
 
   gtk_widget_set_state (GTK_WIDGET (menu_item), GTK_STATE_NORMAL);
   gtk_widget_queue_draw (GTK_WIDGET (menu_item));
@@ -987,7 +935,6 @@ gtk_menu_item_mnemonic_activate (GtkWidg
   return TRUE;
 }
 
-
 static void
 gtk_real_menu_item_activate_item (GtkMenuItem *menu_item)
 {
@@ -1010,12 +957,13 @@ gtk_real_menu_item_activate_item (GtkMen
 	  _gtk_menu_shell_activate (menu_shell);
 
 	  gtk_menu_shell_select_item (GTK_MENU_SHELL (widget->parent), widget); 
-	  _gtk_menu_item_popup_submenu (widget); 
+	  _gtk_menu_item_popup_submenu (widget, FALSE);
 
 	  gtk_menu_shell_select_first (GTK_MENU_SHELL (menu_item->submenu), TRUE);
 	}
     }
 }
+
 static void
 gtk_real_menu_item_toggle_size_request (GtkMenuItem *menu_item,
 					gint        *requisition)
@@ -1034,8 +982,53 @@ gtk_real_menu_item_toggle_size_allocate 
   menu_item->toggle_size = allocation;
 }
 
+static void
+gtk_menu_item_real_popup_submenu (GtkWidget *widget,
+                                  gboolean   remember_exact_time)
+{
+  GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
+
+  if (GTK_WIDGET_IS_SENSITIVE (menu_item->submenu))
+    {
+      gboolean take_focus;
+
+      take_focus = gtk_menu_shell_get_take_focus (GTK_MENU_SHELL (widget->parent));
+      gtk_menu_shell_set_take_focus (GTK_MENU_SHELL (menu_item->submenu),
+                                     take_focus);
+
+      if (remember_exact_time)
+        {
+          GTimeVal *popup_time = g_new0 (GTimeVal, 1);
+
+          g_get_current_time (popup_time);
+
+          g_object_set_data_full (G_OBJECT (menu_item->submenu),
+                                  "gtk-menu-exact-popup-time", popup_time,
+                                  (GDestroyNotify) g_free);
+        }
+      else
+        {
+          g_object_set_data (G_OBJECT (menu_item->submenu),
+                             "gtk-menu-exact-popup-time", NULL);
+        }
+
+      gtk_menu_popup (GTK_MENU (menu_item->submenu),
+                      widget->parent,
+                      widget,
+                      gtk_menu_item_position_menu,
+                      menu_item,
+                      GTK_MENU_SHELL (widget->parent)->button,
+                      0);
+    }
+
+  /* Enable themeing of the parent menu item depending on whether
+   * its submenu is shown or not.
+   */
+  gtk_widget_queue_draw (widget);
+}
+
 static gint
-gtk_menu_item_select_timeout (gpointer data)
+gtk_menu_item_popup_timeout (gpointer data)
 {
   GtkMenuItem *menu_item;
   GtkWidget *parent;
@@ -1047,40 +1040,98 @@ gtk_menu_item_select_timeout (gpointer d
   if ((GTK_IS_MENU_SHELL (parent) && GTK_MENU_SHELL (parent)->active) || 
       (GTK_IS_MENU (parent) && GTK_MENU (parent)->torn_off))
     {
-      _gtk_menu_item_popup_submenu (GTK_WIDGET (menu_item));
+      gtk_menu_item_real_popup_submenu (GTK_WIDGET (menu_item), TRUE);
       if (menu_item->timer_from_keypress && menu_item->submenu)
 	GTK_MENU_SHELL (menu_item->submenu)->ignore_enter = TRUE;
     }
 
+  menu_item->timer = 0;
+
   return FALSE;  
 }
 
-void
-_gtk_menu_item_popup_submenu (GtkWidget *widget)
+static gint
+get_popup_delay (GtkWidget *widget)
 {
-  GtkMenuItem *menu_item;
+  if (GTK_IS_MENU_SHELL (widget->parent))
+    {
+      return _gtk_menu_shell_get_popup_delay (GTK_MENU_SHELL (widget->parent));
+    }
+  else
+    {
+      gint popup_delay;
 
-  menu_item = GTK_MENU_ITEM (widget);
+      g_object_get (gtk_widget_get_settings (widget),
+		    "gtk-menu-popup-delay", &popup_delay,
+		    NULL);
+
+      return popup_delay;
+    }
+}
+
+void
+_gtk_menu_item_popup_submenu (GtkWidget *widget,
+                              gboolean   with_delay)
+{
+  GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
 
   if (menu_item->timer)
+    {
     g_source_remove (menu_item->timer);
   menu_item->timer = 0;
+      with_delay = FALSE;
+    }
 
-  if (GTK_WIDGET_IS_SENSITIVE (menu_item->submenu))
+  if (with_delay)
     {
-      gboolean take_focus;
+      gint popup_delay = get_popup_delay (widget);
 
-      take_focus = gtk_menu_shell_get_take_focus (GTK_MENU_SHELL (widget->parent));
-      gtk_menu_shell_set_take_focus (GTK_MENU_SHELL (menu_item->submenu),
-                                     take_focus);
+      if (popup_delay > 0)
+	{
+	  GdkEvent *event = gtk_get_current_event ();
 
-      gtk_menu_popup (GTK_MENU (menu_item->submenu),
-                      widget->parent,
-                      widget,
-                      gtk_menu_item_position_menu,
-                      menu_item,
-                      GTK_MENU_SHELL (widget->parent)->button,
-                      0);
+	  menu_item->timer = gdk_threads_add_timeout (popup_delay,
+                                                      gtk_menu_item_popup_timeout,
+                                                      menu_item);
+
+	  if (event &&
+	      event->type != GDK_BUTTON_PRESS &&
+	      event->type != GDK_ENTER_NOTIFY)
+	    menu_item->timer_from_keypress = TRUE;
+	  else
+	    menu_item->timer_from_keypress = FALSE;
+
+	  if (event)
+	    gdk_event_free (event);
+
+          return;
+        }
+    }
+
+  gtk_menu_item_real_popup_submenu (widget, FALSE);
+}
+
+void
+_gtk_menu_item_popdown_submenu (GtkWidget *widget)
+{
+  GtkMenuItem *menu_item;
+
+  menu_item = GTK_MENU_ITEM (widget);
+
+  if (menu_item->submenu)
+    {
+      g_object_set_data (G_OBJECT (menu_item->submenu),
+                         "gtk-menu-exact-popup-time", NULL);
+
+      if (menu_item->timer)
+        {
+          g_source_remove (menu_item->timer);
+          menu_item->timer = 0;
+        }
+      else
+        gtk_menu_popdown (GTK_MENU (menu_item->submenu));
+
+      gtk_widget_queue_draw (widget);
     }
 }
 
Index: gtk/gtkmenuitem.h
===================================================================
--- gtk/gtkmenuitem.h	(revision 17656)
+++ gtk/gtkmenuitem.h	(working copy)
@@ -119,7 +119,9 @@ void	  _gtk_menu_item_refresh_accel_path
 					       GtkAccelGroup	   *accel_group,
 					       gboolean		    group_changed);
 gboolean  _gtk_menu_item_is_selectable        (GtkWidget           *menu_item);
-void      _gtk_menu_item_popup_submenu        (GtkWidget           *menu_item);
+void      _gtk_menu_item_popup_submenu        (GtkWidget           *menu_item,
+                                               gboolean             with_delay);
+void      _gtk_menu_item_popdown_submenu      (GtkWidget           *menu_item);
 
 #ifndef GTK_DISABLE_DEPRECATED
 #define gtk_menu_item_right_justify(menu_item) gtk_menu_item_set_right_justified ((menu_item), TRUE)
