[gtk+/multitouch-for-3.4: 55/89] Handle TouchBegin/End events
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/multitouch-for-3.4: 55/89] Handle TouchBegin/End events
- Date: Thu, 23 Feb 2012 12:30:33 +0000 (UTC)
commit a9794ecdb40e005b0d63709cf8b7f607b9376fd1
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Mar 11 20:33:38 2011 +0100
Handle TouchBegin/End events
These are translated into GDK_TOUCH_PRESS/RELEASE GdkEvents,
which use the GdkEventButton struct, a touch_id parameter
has been added there to cope with touches.
gdk/gdkevents.c | 26 ++++++++++-
gdk/gdkevents.h | 7 +++
gdk/gdkwindow.c | 4 +-
gdk/x11/gdkdevicemanager-xi2.c | 102 ++++++++++++++++++++++------------------
4 files changed, 91 insertions(+), 48 deletions(-)
---
diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c
index eda926f..6aeedfd 100644
--- a/gdk/gdkevents.c
+++ b/gdk/gdkevents.c
@@ -455,6 +455,8 @@ gdk_event_new (GdkEventType type)
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
+ case GDK_TOUCH_PRESS:
+ case GDK_TOUCH_RELEASE:
new_event->button.x = 0.;
new_event->button.y = 0.;
new_event->button.x_root = 0.;
@@ -559,6 +561,8 @@ gdk_event_copy (const GdkEvent *event)
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
+ case GDK_TOUCH_PRESS:
+ case GDK_TOUCH_RELEASE:
if (event->button.axes)
new_event->button.axes = g_memdup (event->button.axes,
sizeof (gdouble) * gdk_device_get_n_axes (event->button.device));
@@ -641,6 +645,8 @@ gdk_event_free (GdkEvent *event)
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
+ case GDK_TOUCH_PRESS:
+ case GDK_TOUCH_RELEASE:
g_free (event->button.axes);
break;
@@ -705,6 +711,8 @@ gdk_event_get_time (const GdkEvent *event)
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
+ case GDK_TOUCH_PRESS:
+ case GDK_TOUCH_RELEASE:
return event->button.time;
case GDK_SCROLL:
return event->scroll.time;
@@ -782,6 +790,8 @@ gdk_event_get_state (const GdkEvent *event,
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
+ case GDK_TOUCH_PRESS:
+ case GDK_TOUCH_RELEASE:
*state = event->button.state;
return TRUE;
case GDK_SCROLL:
@@ -870,6 +880,8 @@ gdk_event_get_coords (const GdkEvent *event,
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
+ case GDK_TOUCH_PRESS:
+ case GDK_TOUCH_RELEASE:
x = event->button.x;
y = event->button.y;
break;
@@ -926,6 +938,8 @@ gdk_event_get_root_coords (const GdkEvent *event,
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
+ case GDK_TOUCH_PRESS:
+ case GDK_TOUCH_RELEASE:
x = event->button.x_root;
y = event->button.y_root;
break;
@@ -1180,6 +1194,8 @@ gdk_event_get_axis (const GdkEvent *event,
break;
case GDK_BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
+ case GDK_TOUCH_PRESS:
+ case GDK_TOUCH_RELEASE:
x = event->button.x;
y = event->button.y;
break;
@@ -1201,7 +1217,9 @@ gdk_event_get_axis (const GdkEvent *event,
return TRUE;
}
else if (event->type == GDK_BUTTON_PRESS ||
- event->type == GDK_BUTTON_RELEASE)
+ event->type == GDK_BUTTON_RELEASE ||
+ event->type == GDK_TOUCH_PRESS ||
+ event->type == GDK_TOUCH_RELEASE)
{
device = event->button.device;
axes = event->button.axes;
@@ -1251,6 +1269,8 @@ gdk_event_set_device (GdkEvent *event,
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
+ case GDK_TOUCH_PRESS:
+ case GDK_TOUCH_RELEASE:
event->button.device = device;
break;
case GDK_SCROLL:
@@ -1298,6 +1318,8 @@ gdk_event_get_device (const GdkEvent *event)
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
+ case GDK_TOUCH_PRESS:
+ case GDK_TOUCH_RELEASE:
return event->button.device;
case GDK_SCROLL:
return event->scroll.device;
@@ -1317,6 +1339,8 @@ gdk_event_get_device (const GdkEvent *event)
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
+ case GDK_TOUCH_PRESS:
+ case GDK_TOUCH_RELEASE:
case GDK_ENTER_NOTIFY:
case GDK_LEAVE_NOTIFY:
case GDK_FOCUS_CHANGE:
diff --git a/gdk/gdkevents.h b/gdk/gdkevents.h
index 8316e98..101ba21 100644
--- a/gdk/gdkevents.h
+++ b/gdk/gdkevents.h
@@ -264,6 +264,8 @@ typedef GdkFilterReturn (*GdkFilterFunc) (GdkXEvent *xevent,
* @GDK_DAMAGE: the content of the window has been changed. This event type
* was added in 2.14.
* @GDK_TOUCH_MOTION: A touch device has been updated.
+ * @GDK_TOUCH_PRESS: A new touch stream has just started.
+ * @GDK_TOUCH_RELEASE: A touch stream has finished.
* @GDK_EVENT_LAST: marks the end of the GdkEventType enumeration. Added in 2.18
*
* Specifies the type of the event.
@@ -312,6 +314,8 @@ typedef enum
GDK_GRAB_BROKEN = 35,
GDK_DAMAGE = 36,
GDK_TOUCH_MOTION = 37,
+ GDK_TOUCH_PRESS = 38,
+ GDK_TOUCH_RELEASE = 39,
GDK_EVENT_LAST /* helper variable for decls */
} GdkEventType;
@@ -610,6 +614,8 @@ struct _GdkEventMotion
* screen.
* @y_root: the y coordinate of the pointer relative to the root of the
* screen.
+ * @touch_id: touch ID, only meaningful if event is of type %GDK_TOUCH_PRESS
+ * or %GDK_TOUCH_RELEASE.
*
* Used for button press and button release events. The
* @type field will be one of %GDK_BUTTON_PRESS,
@@ -659,6 +665,7 @@ struct _GdkEventButton
guint button;
GdkDevice *device;
gdouble x_root, y_root;
+ guint touch_id;
};
/**
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index f961ba2..04a14b5 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -8119,7 +8119,9 @@ static const guint type_masks[] = {
0, /* GDK_OWNER_CHANGE = 34 */
0, /* GDK_GRAB_BROKEN = 35 */
0, /* GDK_DAMAGE = 36 */
- GDK_TOUCH_MASK | GDK_BUTTON_MOTION_MASK /* GDK_TOUCH_MOTION = 37 */
+ GDK_TOUCH_MASK | GDK_BUTTON_MOTION_MASK | GDK_POINTER_MOTION_MASK, /* GDK_TOUCH_MOTION = 37 */
+ GDK_TOUCH_MASK | GDK_BUTTON_PRESS_MASK, /* GDK_TOUCH_PRESS = 38 */
+ GDK_TOUCH_MASK | GDK_BUTTON_RELEASE_MASK /* GDK_TOUCH_RELEASE = 39 */
};
G_STATIC_ASSERT (G_N_ELEMENTS (type_masks) == GDK_EVENT_LAST);
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index 99bd4f9..e30397a 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -878,6 +878,8 @@ get_event_window (GdkEventTranslator *translator,
#ifdef XINPUT_2_1
case XI_TouchMotion:
case XI_TouchMotionUnowned:
+ case XI_TouchBegin:
+ case XI_TouchEnd:
#endif /* XINPUT_2_1 */
{
XIDeviceEvent *xev = (XIDeviceEvent *) ev;
@@ -1099,56 +1101,54 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
break;
case XI_ButtonPress:
case XI_ButtonRelease:
+#ifdef XINPUT_2_1
+ case XI_TouchBegin:
+ case XI_TouchEnd:
+#endif /* XINPUT_2_1 */
{
XIDeviceEvent *xev = (XIDeviceEvent *) ev;
GdkDevice *source_device;
- switch (xev->detail)
+ if (ev->evtype == XI_ButtonPress &&
+ (xev->detail >= 4 && xev->detail <= 7))
{
- case 4:
- case 5:
- case 6:
- case 7:
- /* Button presses of button 4-7 are scroll events */
- if (ev->evtype == XI_ButtonPress)
- {
- event->scroll.type = GDK_SCROLL;
-
- if (xev->detail == 4)
- event->scroll.direction = GDK_SCROLL_UP;
- else if (xev->detail == 5)
- event->scroll.direction = GDK_SCROLL_DOWN;
- else if (xev->detail == 6)
- event->scroll.direction = GDK_SCROLL_LEFT;
- else
- event->scroll.direction = GDK_SCROLL_RIGHT;
-
- event->scroll.window = window;
- event->scroll.time = xev->time;
- event->scroll.x = (gdouble) xev->event_x;
- event->scroll.y = (gdouble) xev->event_y;
- event->scroll.x_root = (gdouble) xev->root_x;
- event->scroll.y_root = (gdouble) xev->root_y;
-
- event->scroll.device = g_hash_table_lookup (device_manager->id_table,
- GUINT_TO_POINTER (xev->deviceid));
-
- source_device = g_hash_table_lookup (device_manager->id_table,
- GUINT_TO_POINTER (xev->sourceid));
- gdk_event_set_source_device (event, source_device);
-
- event->scroll.state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
- break;
- }
- /* Button presses of button 4-7 are scroll events, so ignore the release */
- else if (ev->evtype == XI_ButtonRelease)
- {
- return_val = FALSE;
- break;
- }
- /* else (XI_ButtonRelease) fall thru */
- default:
- event->button.type = (ev->evtype == XI_ButtonPress) ? GDK_BUTTON_PRESS : GDK_BUTTON_RELEASE;
+ /* Button presses of button 4-7 are scroll events */
+ event->scroll.type = GDK_SCROLL;
+
+ if (xev->detail == 4)
+ event->scroll.direction = GDK_SCROLL_UP;
+ else if (xev->detail == 5)
+ event->scroll.direction = GDK_SCROLL_DOWN;
+ else if (xev->detail == 6)
+ event->scroll.direction = GDK_SCROLL_LEFT;
+ else
+ event->scroll.direction = GDK_SCROLL_RIGHT;
+
+ event->scroll.window = window;
+ event->scroll.time = xev->time;
+ event->scroll.x = (gdouble) xev->event_x;
+ event->scroll.y = (gdouble) xev->event_y;
+ event->scroll.x_root = (gdouble) xev->root_x;
+ event->scroll.y_root = (gdouble) xev->root_y;
+
+ event->scroll.device = g_hash_table_lookup (device_manager->id_table,
+ GUINT_TO_POINTER (xev->deviceid));
+
+ source_device = g_hash_table_lookup (device_manager->id_table,
+ GUINT_TO_POINTER (xev->sourceid));
+ gdk_event_set_source_device (event, source_device);
+
+ event->scroll.state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
+ }
+ else
+ {
+#ifdef XINPUT_2_1
+ if (ev->evtype == XI_TouchBegin ||
+ ev->evtype == XI_TouchEnd)
+ event->button.type = (ev->evtype == XI_TouchBegin) ? GDK_TOUCH_PRESS : GDK_TOUCH_RELEASE;
+ else
+#endif /* XINPUT_2_1 */
+ event->button.type = (ev->evtype == XI_ButtonPress) ? GDK_BUTTON_PRESS : GDK_BUTTON_RELEASE;
event->button.window = window;
event->button.time = xev->time;
@@ -1180,7 +1180,17 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
}
event->button.state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
- event->button.button = xev->detail;
+
+#ifdef XINPUT_2_1
+ if (ev->evtype == XI_TouchBegin ||
+ ev->evtype == XI_TouchEnd)
+ {
+ event->button.button = 1;
+ event->button.touch_id = xev->detail;
+ }
+ else
+#endif /* XINPUT_2_1 */
+ event->button.button = xev->detail;
}
if (return_val == FALSE)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]