[gtk+/multitouch: 104/123] gtk,button: Handle touch events



commit 61d2d297dff4a8dbd377b9d3d2a60d44a74b8c99
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jan 5 00:35:04 2012 +0100

    gtk,button: Handle touch events
    
    Touch events don't generate crossing events themselves, so
    do not rely on these to determine whether the button release
    happened within the event window.

 gtk/gtkbutton.c |   37 +++++++++++++++++++++++++++++++++++--
 1 files changed, 35 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index 564483b..4608a6a 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -1813,7 +1813,8 @@ gtk_button_button_press (GtkWidget      *widget,
   GtkButton *button;
   GtkButtonPrivate *priv;
 
-  if (event->type == GDK_BUTTON_PRESS)
+  if (event->type == GDK_BUTTON_PRESS ||
+      event->type == GDK_TOUCH_PRESS)
     {
       button = GTK_BUTTON (widget);
       priv = button->priv;
@@ -1932,6 +1933,37 @@ gtk_real_button_pressed (GtkButton *button)
   gtk_button_update_state (button);
 }
 
+static gboolean
+touch_release_in_button (GtkButton *button)
+{
+  GtkButtonPrivate *priv;
+  gint width, height;
+  GdkEvent *event;
+  gdouble x, y;
+
+  priv = button->priv;
+  event = gtk_get_current_event ();
+
+  if (event->type != GDK_TOUCH_RELEASE ||
+      event->button.window != priv->event_window)
+    {
+      gdk_event_free (event);
+      return FALSE;
+    }
+
+  gdk_event_get_coords (event, &x, &y);
+  width = gdk_window_get_width (priv->event_window);
+  height = gdk_window_get_height (priv->event_window);
+
+  gdk_event_free (event);
+
+  if (x >= 0 && x <= width &&
+      y >= 0 && y <= height)
+    return TRUE;
+
+  return FALSE;
+}
+
 static void
 gtk_real_button_released (GtkButton *button)
 {
@@ -1944,7 +1976,8 @@ gtk_real_button_released (GtkButton *button)
       if (priv->activate_timeout)
 	return;
 
-      if (priv->in_button)
+      if (priv->in_button ||
+          touch_release_in_button (button))
 	gtk_button_clicked (button);
 
       gtk_button_update_state (button);



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