[gtk+/multitouch-for-3.4: 38/89] gtk, menu: handle item selection for touch devices dynamically



commit ad13f0912211a447eabd510dc9d45dba22809cb6
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Dec 11 18:46:50 2011 +0100

    gtk,menu: handle item selection for touch devices dynamically
    
    Instead of using gtk-touchscreen-mode, the behavior changes depending
    on the source device in use.

 gtk/gtkmenu.c      |   11 +++++------
 gtk/gtkmenuitem.c  |   17 ++++++++++++-----
 gtk/gtkmenushell.c |    8 +++-----
 3 files changed, 20 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index 2234789..01829a1 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -4279,18 +4279,16 @@ gtk_menu_enter_notify (GtkWidget        *widget,
 {
   GtkWidget *menu_item;
   GtkWidget *parent;
-  gboolean   touchscreen_mode;
+  GdkDevice *source_device;
 
   if (event->mode == GDK_CROSSING_GTK_GRAB ||
       event->mode == GDK_CROSSING_GTK_UNGRAB ||
       event->mode == GDK_CROSSING_STATE_CHANGED)
     return TRUE;
 
-  g_object_get (gtk_widget_get_settings (widget),
-                "gtk-touchscreen-mode", &touchscreen_mode,
-                NULL);
-
+  source_device = gdk_event_get_source_device (event);
   menu_item = gtk_get_event_widget ((GdkEvent*) event);
+
   if (GTK_IS_MENU (widget))
     {
       GtkMenuShell *menu_shell = GTK_MENU_SHELL (widget);
@@ -4300,7 +4298,8 @@ gtk_menu_enter_notify (GtkWidget        *widget,
                                    event->x_root, event->y_root, TRUE, TRUE);
     }
 
-  if (!touchscreen_mode && GTK_IS_MENU_ITEM (menu_item))
+  if (gdk_device_get_source (source_device) != GDK_SOURCE_TOUCH &&
+      GTK_IS_MENU_ITEM (menu_item))
     {
       GtkWidget *menu = gtk_widget_get_parent (menu_item);
 
diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c
index ed3a60d..259ccc3 100644
--- a/gtk/gtkmenuitem.c
+++ b/gtk/gtkmenuitem.c
@@ -1690,13 +1690,20 @@ static void
 gtk_real_menu_item_select (GtkMenuItem *menu_item)
 {
   GtkMenuItemPrivate *priv = menu_item->priv;
-  gboolean touchscreen_mode;
+  GdkDevice *source_device = NULL;
+  GdkEvent *current_event;
 
-  g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu_item)),
-                "gtk-touchscreen-mode", &touchscreen_mode,
-                NULL);
+  current_event = gtk_get_current_event ();
 
-  if (!touchscreen_mode && priv->submenu &&
+  if (current_event)
+    {
+      source_device = gdk_event_get_source_device (current_event);
+      gdk_event_free (current_event);
+    }
+
+  if ((!source_device ||
+       gdk_device_get_source (source_device) != GDK_SOURCE_TOUCH) &&
+      priv->submenu &&
       (!gtk_widget_get_mapped (priv->submenu) ||
        GTK_MENU (priv->submenu)->priv->tearoff_active))
     {
diff --git a/gtk/gtkmenushell.c b/gtk/gtkmenushell.c
index 34b47ca..2f2596b 100644
--- a/gtk/gtkmenushell.c
+++ b/gtk/gtkmenushell.c
@@ -1084,13 +1084,11 @@ gtk_menu_shell_enter_notify (GtkWidget        *widget,
 
                   if (!gtk_widget_get_visible (GTK_MENU_ITEM (menu_item)->priv->submenu))
                     {
-                      gboolean touchscreen_mode;
+                      GdkDevice *source_device;
 
-                      g_object_get (gtk_widget_get_settings (widget),
-                                    "gtk-touchscreen-mode", &touchscreen_mode,
-                                    NULL);
+                      source_device = gdk_event_get_source_device ((GdkEvent *) event);
 
-                      if (touchscreen_mode)
+                      if (gdk_device_get_source (source_device) == GDK_SOURCE_TOUCH)
                         _gtk_menu_item_popup_submenu (menu_item, TRUE);
                     }
                 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]