[PATCH 09/42] Hook up TouchBegin/Update/End events

Peter Hutterer peter.hutterer at who-t.net
Wed Dec 14 19:01:46 PST 2011


The are the same as device events internally but require the touch ID
separately from the detail.button field (the protocol uses the detail field
for the touch id).
For simpler integration of pointer emulation we need to set the
detail.button field while keeping the touchid around.

Add the three new touch event types to the various places in the server
where they need to be handled. The actual handling of the events is somewhat
more complicated in most places.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 Xi/exevents.c      |   15 +++++++++++++++
 Xi/extinit.c       |    3 +++
 dix/eventconvert.c |   24 ++++++++++++++++++++++--
 dix/events.c       |    3 +++
 include/dix.h      |    1 +
 include/eventstr.h |    7 ++++++-
 mi/mieq.c          |    3 +++
 7 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 1e16b74..b05cf2c 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -128,6 +128,21 @@ IsPointerEvent(InternalEvent* event)
     return FALSE;
 }
 
+Bool
+IsTouchEvent(InternalEvent* event)
+{
+    switch(event->any.type)
+    {
+        case ET_TouchBegin:
+        case ET_TouchUpdate:
+        case ET_TouchEnd:
+            return TRUE;
+        default:
+            break;
+    }
+    return FALSE;
+}
+
 /**
  * @return the device matching the deviceid of the device set in the event, or
  * NULL if the event is not an XInput event.
diff --git a/Xi/extinit.c b/Xi/extinit.c
index b43f9bb..87f7933 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -858,6 +858,9 @@ XI2EventSwap(xGenericEvent *from, xGenericEvent *to)
         case XI_KeyRelease:
         case XI_ButtonPress:
         case XI_ButtonRelease:
+        case XI_TouchBegin:
+        case XI_TouchUpdate:
+        case XI_TouchEnd:
             SDeviceEvent((xXIDeviceEvent*)from, (xXIDeviceEvent*)to);
             break;
         case XI_RawMotion:
diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index 67b420a..3802ea1 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -158,6 +158,9 @@ EventToCore(InternalEvent *event, xEvent **core_out, int *count_out)
         case ET_RawButtonPress:
         case ET_RawButtonRelease:
         case ET_RawMotion:
+        case ET_TouchBegin:
+        case ET_TouchUpdate:
+        case ET_TouchEnd:
             ret = BadMatch;
             break;
         default:
@@ -208,6 +211,9 @@ EventToXI(InternalEvent *ev, xEvent **xi, int *count)
         case ET_RawButtonPress:
         case ET_RawButtonRelease:
         case ET_RawMotion:
+        case ET_TouchBegin:
+        case ET_TouchUpdate:
+        case ET_TouchEnd:
             *count = 0;
             *xi = NULL;
             return BadMatch;
@@ -249,6 +255,9 @@ EventToXI2(InternalEvent *ev, xEvent **xi)
         case ET_ButtonRelease:
         case ET_KeyPress:
         case ET_KeyRelease:
+        case ET_TouchBegin:
+        case ET_TouchUpdate:
+        case ET_TouchEnd:
             return eventToDeviceEvent(&ev->device_event, xi);
         case ET_ProximityIn:
         case ET_ProximityOut:
@@ -650,7 +659,11 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi)
     xde->evtype         = GetXI2Type(ev->type);
     xde->time           = ev->time;
     xde->length         = bytes_to_int32(len - sizeof(xEvent));
-    xde->detail         = ev->detail.button;
+    if (IsTouchEvent((InternalEvent*)ev))
+        xde->detail     = ev->touchid;
+    else
+        xde->detail     = ev->detail.button;
+
     xde->root           = ev->root;
     xde->buttons_len    = btlen;
     xde->valuators_len  = vallen;
@@ -659,7 +672,11 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi)
     xde->root_x         = FP1616(ev->root_x, ev->root_x_frac);
     xde->root_y         = FP1616(ev->root_y, ev->root_y_frac);
 
-    xde->flags          = ev->flags;
+    if (ev->type == ET_TouchUpdate)
+        xde->flags |= (ev->flags & TOUCH_PENDING_END) ? XITouchPendingEnd : 0;
+    else
+        xde->flags = ev->flags;
+
     if (ev->key_repeat)
         xde->flags      |= XIKeyRepeat;
 
@@ -812,6 +829,9 @@ GetXI2Type(enum EventType type)
         case ET_RawMotion:      xi2type = XI_RawMotion;        break;
         case ET_FocusIn:        xi2type = XI_FocusIn;          break;
         case ET_FocusOut:       xi2type = XI_FocusOut;         break;
+        case ET_TouchBegin:     xi2type = XI_TouchBegin;       break;
+        case ET_TouchEnd:       xi2type = XI_TouchEnd;         break;
+        case ET_TouchUpdate:    xi2type = XI_TouchUpdate;      break;
         default:
             break;
     }
diff --git a/dix/events.c b/dix/events.c
index 8dff299..2b54969 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2978,6 +2978,9 @@ CheckMotion(DeviceEvent *ev, DeviceIntPtr pDev)
             case ET_ButtonPress:
             case ET_ButtonRelease:
             case ET_Motion:
+            case ET_TouchBegin:
+            case ET_TouchUpdate:
+            case ET_TouchEnd:
                 break;
             default:
                 /* all other events return FALSE */
diff --git a/include/dix.h b/include/dix.h
index 9b9dc4b..7043201 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -582,6 +582,7 @@ extern Bool DevHasCursor(DeviceIntPtr pDev);
 extern _X_EXPORT Bool IsPointerDevice(DeviceIntPtr dev);
 extern _X_EXPORT Bool IsKeyboardDevice(DeviceIntPtr dev);
 extern Bool IsPointerEvent(InternalEvent *event);
+extern Bool IsTouchEvent(InternalEvent *event);
 extern _X_EXPORT Bool IsMaster(DeviceIntPtr dev);
 extern _X_EXPORT Bool IsFloating(DeviceIntPtr dev);
 
diff --git a/include/eventstr.h b/include/eventstr.h
index 4d836fb..9626076 100644
--- a/include/eventstr.h
+++ b/include/eventstr.h
@@ -50,6 +50,9 @@ enum EventType {
     ET_ButtonPress,
     ET_ButtonRelease,
     ET_Motion,
+    ET_TouchBegin,
+    ET_TouchUpdate,
+    ET_TouchEnd,
     ET_Enter,
     ET_Leave,
     ET_FocusIn,
@@ -84,9 +87,11 @@ struct _DeviceEvent
     int deviceid;         /**< Device to post this event for */
     int sourceid;         /**< The physical source device */
     union {
-        uint32_t button;  /**< Button number */
+        uint32_t button;  /**< Button number (also used in pointer emulating
+                               touch events) */
         uint32_t key;     /**< Key code */
     } detail;
+    uint32_t touchid;     /**< Touch ID (client_id) */
     int16_t root_x;       /**< Pos relative to root window in integral data */
     float root_x_frac;    /**< Pos relative to root window in frac part */
     int16_t root_y;       /**< Pos relative to root window in integral part */
diff --git a/mi/mieq.c b/mi/mieq.c
index 093dba2..06c3d8e 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -370,6 +370,9 @@ ChangeDeviceID(DeviceIntPtr dev, InternalEvent* event)
         case ET_ProximityOut:
         case ET_Hierarchy:
         case ET_DeviceChanged:
+        case ET_TouchBegin:
+        case ET_TouchUpdate:
+        case ET_TouchEnd:
             event->device_event.deviceid = dev->id;
             break;
 #if XFreeXDGA
-- 
1.7.7.1



More information about the xorg-devel mailing list