[gtk+/multitouch: 4/57] Handle TouchBegin/End events



commit 082e2f0452cae586d99b84edb53851570390710f
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 6530e72..573be25 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 24c0637..47ba80d 100644
--- a/gdk/gdkevents.h
+++ b/gdk/gdkevents.h
@@ -214,6 +214,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.
@@ -262,6 +264,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;
 
@@ -548,6 +552,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,
@@ -597,6 +603,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 f8bed61..03a2286 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -8056,7 +8056,9 @@ static const guint type_masks[] = {
   0, /* GDK_OWNER_CHANGE = 34 */
   0, /* GDK_GRAB_BROKEN = 35 */
   0, /* GDK_DAMAGE = 36 */
-  GDK_TOUCH_MASK /* GDK_TOUCH_MOTION                   = 37 */
+  GDK_TOUCH_MASK, /* GDK_TOUCH_MOTION                  = 37 */
+  GDK_TOUCH_MASK, /* GDK_TOUCH_PRESS                   = 38 */
+  GDK_TOUCH_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 57082df..80483fb 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -908,6 +908,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;
@@ -1129,56 +1131,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;
@@ -1210,7 +1210,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]