diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2011-12-12 20:07:57 +0100 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2012-03-01 16:25:24 -0500 |
commit | 535b4150fdbad94f937e709923f3567f17490b76 (patch) | |
tree | ca482c7c3aef0a5ea50a92a854b1b94d35fc1e10 | |
parent | 0e8c2db131d48a8e054bf399b967f349f94e8db9 (diff) | |
download | gtk+-535b4150fdbad94f937e709923f3567f17490b76.tar.gz |
menus: Don't popdown submenus on button release for touch devices
This is so submenus stay open as the parent menu item is
pressed/released, since the user would typically lift the
finger in order to select a submenu item.
-rw-r--r-- | gtk/gtkmenu.c | 16 | ||||
-rw-r--r-- | gtk/gtkmenuitem.c | 2 |
2 files changed, 16 insertions, 2 deletions
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c index 837c201a1c..8ecf9bf05d 100644 --- a/gtk/gtkmenu.c +++ b/gtk/gtkmenu.c @@ -3358,9 +3358,17 @@ static gboolean gtk_menu_button_press (GtkWidget *widget, GdkEventButton *event) { + GdkDevice *source_device; + GtkWidget *event_widget; + GtkMenu *menu; + if (event->type != GDK_BUTTON_PRESS) return FALSE; + source_device = gdk_event_get_source_device ((GdkEvent *) event); + event_widget = gtk_get_event_widget ((GdkEvent *) event); + menu = GTK_MENU (widget); + /* Don't pass down to menu shell if a non-menuitem part of the menu * was clicked. The check for the event_widget being a GtkMenuShell * works because we have the pointer grabbed on menu_shell->window @@ -3368,10 +3376,16 @@ gtk_menu_button_press (GtkWidget *widget, * the menu or on its border are delivered relative to * menu_shell->window. */ - if (GTK_IS_MENU_SHELL (gtk_get_event_widget ((GdkEvent *) event)) && + if (GTK_IS_MENU_SHELL (event_widget) && pointer_in_menu_window (widget, event->x_root, event->y_root)) return TRUE; + if (GTK_IS_MENU_ITEM (event_widget) && + gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN && + GTK_MENU_ITEM (event_widget)->priv->submenu != NULL && + !gtk_widget_is_drawable (GTK_MENU_ITEM (event_widget)->priv->submenu)) + menu->priv->ignore_button_release = TRUE; + return GTK_WIDGET_CLASS (gtk_menu_parent_class)->button_press_event (widget, event); } diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c index 147430bbb6..3d70ed6f92 100644 --- a/gtk/gtkmenuitem.c +++ b/gtk/gtkmenuitem.c @@ -1700,7 +1700,7 @@ gtk_real_menu_item_select (GtkMenuItem *menu_item) } if ((!source_device || - gdk_device_get_source (source_device) != GDK_SOURCE_TOUCH) && + gdk_device_get_source (source_device) != GDK_SOURCE_TOUCHSCREEN) && priv->submenu && (!gtk_widget_get_mapped (priv->submenu) || GTK_MENU (priv->submenu)->priv->tearoff_active)) |