[gtk+/touch-for-3.4: 47/65] button: Handle touch events
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/touch-for-3.4: 47/65] button: Handle touch events
- Date: Fri, 24 Feb 2012 15:28:47 +0000 (UTC)
commit f09476686cf14e781c6f49f37f85ada8b2706b3c
Author: Carlos Garnacho <carlosg gnome org>
Date: Thu Jan 5 00:35:04 2012 +0100
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 | 47 ++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 42 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index 38fc25c..b0b02eb 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -1431,9 +1431,10 @@ gtk_button_realize (GtkWidget *widget)
attributes.wclass = GDK_INPUT_ONLY;
attributes.event_mask = gtk_widget_get_events (widget);
attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_ENTER_NOTIFY_MASK |
- GDK_LEAVE_NOTIFY_MASK);
+ GDK_BUTTON_RELEASE_MASK |
+ GDK_BUTTON_MOTION_MASK |
+ GDK_ENTER_NOTIFY_MASK |
+ GDK_LEAVE_NOTIFY_MASK);
attributes_mask = GDK_WA_X | GDK_WA_Y;
@@ -1813,7 +1814,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 +1934,40 @@ 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)
+ return FALSE;
+
+ 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 +1980,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]