[gtk+/multitouch: 35/40] gtk,button: Handle touch events
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/multitouch: 35/40] gtk,button: Handle touch events
- Date: Thu, 5 Jan 2012 11:43:40 +0000 (UTC)
commit ccb456536d7fd8b9fcc223dcde441b6fbc434959
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 3b3b5b2..94324c1 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -1679,7 +1679,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;
@@ -1798,6 +1799,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)
{
@@ -1810,7 +1842,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]