[gtk+/touch-for-3.4] gtk: translate unhandled touch events to button events
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/touch-for-3.4] gtk: translate unhandled touch events to button events
- Date: Sun, 26 Feb 2012 16:20:13 +0000 (UTC)
commit 4556f13208980a571659d4bad0c825c5aa5339c5
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Feb 26 11:19:29 2012 -0500
gtk: translate unhandled touch events to button events
We clearly need something like this, but the patch is experimental
and untested.
gtk/gtkwidget.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 73 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 1393109..a62396c 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -590,6 +590,8 @@ static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
GdkEventFocus *event);
static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
GdkEventFocus *event);
+static gboolean gtk_widget_real_touch_event (GtkWidget *widget,
+ GdkEventTouch *event);
static gboolean gtk_widget_real_focus (GtkWidget *widget,
GtkDirectionType direction);
static void gtk_widget_real_move_focus (GtkWidget *widget,
@@ -906,6 +908,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
klass->button_press_event = NULL;
klass->button_release_event = NULL;
klass->motion_notify_event = NULL;
+ klass->touch_event = gtk_widget_real_touch_event;
klass->delete_event = NULL;
klass->destroy_event = NULL;
klass->key_press_event = gtk_widget_real_key_press_event;
@@ -5843,6 +5846,76 @@ gtk_widget_real_focus_out_event (GtkWidget *widget,
return FALSE;
}
+static gboolean
+gtk_widget_real_touch_event (GtkWidget *widget,
+ GdkEventTouch *event)
+{
+ GdkEvent *bevent;
+ gboolean return_val;
+ gint signum;
+
+ /* FIXME: we may need to remember the touch sequence and
+ * ignore other touches until the first sequence ends
+ */
+ if (event->type == GDK_TOUCH_BEGIN ||
+ event->type == GDK_TOUCH_END)
+ {
+ GdkEventType type;
+
+ if (event->type == GDK_TOUCH_BEGIN)
+ {
+ type = GDK_BUTTON_PRESS;
+ signum = BUTTON_PRESS_EVENT;
+ }
+ else
+ {
+ type = GDK_BUTTON_RELEASE;
+ signum = BUTTON_RELEASE_EVENT;
+ }
+ bevent = gdk_event_new (type);
+ bevent->any.window = g_object_ref (event->window);
+ bevent->any.send_event = FALSE;
+ bevent->button.time = event->time;
+ bevent->button.state = event->state;
+ bevent->button.button = 1;
+ bevent->button.x_root = event->x_root;
+ bevent->button.y_root = event->y_root;
+ bevent->button.x = event->x;
+ bevent->button.y = event->y;
+ bevent->button.device = event->device;
+ bevent->button.axes = g_memdup (event->axes,
+ sizeof (gdouble) * gdk_device_get_n_axes (event->device));
+ gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
+ }
+ else if (event->type == GDK_TOUCH_UPDATE)
+ {
+ signum = MOTION_NOTIFY_EVENT;
+ bevent = gdk_event_new (GDK_MOTION_NOTIFY);
+ bevent->any.window = g_object_ref (event->window);
+ bevent->any.send_event = FALSE;
+ bevent->motion.time = event->time;
+ bevent->motion.state = event->state;
+ bevent->motion.x_root = event->x_root;
+ bevent->motion.y_root = event->y_root;
+ bevent->motion.x = event->x;
+ bevent->motion.y = event->y;
+ bevent->motion.device = event->device;
+ bevent->motion.is_hint = FALSE;
+ bevent->motion.axes = g_memdup (event->axes,
+ sizeof (gdouble) * gdk_device_get_n_axes (event->device));
+ gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
+ }
+ else
+ return FALSE;
+
+ g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
+
+ gdk_event_free (bevent);
+
+ return return_val;
+}
+
+
#define WIDGET_REALIZED_FOR_EVENT(widget, event) \
(event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]