summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2011-12-14 17:04:38 +1000
committerChase Douglas <chase.douglas@canonical.com>2011-12-21 10:34:12 -0800
commit9ae79ae1c644f843a05d8e07d0342607c6d70b6f (patch)
treef8cf873b78ca31f0a360e4ebc8f9b91d11ca127d
parentbdfbf9e1e48bebbba4f9434ba257c6320626f35b (diff)
dix: add touch to pointer event conversion helper
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Chase Douglas <chase.douglas@canonical.com>
-rw-r--r--dix/touch.c62
-rw-r--r--include/input.h2
2 files changed, 64 insertions, 0 deletions
diff --git a/dix/touch.c b/dix/touch.c
index 5615f2be6..5731d9118 100644
--- a/dix/touch.c
+++ b/dix/touch.c
@@ -599,6 +599,68 @@ TouchEnsureSprite(DeviceIntPtr sourcedev, TouchPointInfoPtr ti,
}
/**
+ * Copy the touch event into the pointer_event, switching the required
+ * fields to make it a correct pointer event.
+ *
+ * @param event The original touch event
+ * @param[in] motion_event The respective motion event
+ * @param[in] button_event The respective button event (if any)
+ *
+ * @returns The number of converted events.
+ * @retval 0 An error occured
+ * @retval 1 only the motion event is valid
+ * @retval 2 motion and button event are valid
+ */
+int
+TouchConvertToPointerEvent(const InternalEvent *event,
+ InternalEvent *motion_event,
+ InternalEvent *button_event)
+{
+ int ptrtype;
+ int nevents = 0;
+
+ BUG_WARN(!event);
+ BUG_WARN(!motion_event);
+
+ switch(event->any.type)
+ {
+ case ET_TouchUpdate:
+ nevents = 1;
+ break;
+ case ET_TouchBegin:
+ nevents = 2; /* motion + press */
+ ptrtype = ET_ButtonPress;
+ break;
+ case ET_TouchEnd:
+ nevents = 2; /* motion + release */
+ ptrtype = ET_ButtonRelease;
+ break;
+ default:
+ BUG_WARN_MSG(1,"Invalid event type %d\n", event->any.type);
+ return 0;
+ }
+
+ BUG_WARN_MSG(!(event->device_event.flags & TOUCH_POINTER_EMULATED),
+ "Non-emulating touch event\n");
+
+ *motion_event = *event;
+ motion_event->any.type = ET_Motion;
+ motion_event->device_event.detail.button = 0;
+ motion_event->device_event.flags = XIPointerEmulated;
+
+ if (nevents > 1)
+ {
+ BUG_WARN(!button_event);
+ *button_event = *event;
+ button_event->any.type = ptrtype;
+ button_event->device_event.flags = XIPointerEmulated;
+ /* detail is already correct */
+ }
+
+ return nevents;
+}
+
+/**
* Return the corresponding pointer emulation internal event type for the given
* touch event or 0 if no such event type exists.
*/
diff --git a/include/input.h b/include/input.h
index 9fec92b96..03eb053c8 100644
--- a/include/input.h
+++ b/include/input.h
@@ -619,6 +619,8 @@ extern void TouchSetupListeners(DeviceIntPtr dev, TouchPointInfoPtr ti, Internal
extern Bool TouchEnsureSprite(DeviceIntPtr sourcedev, TouchPointInfoPtr ti,
InternalEvent *ev);
extern Bool TouchBuildDependentSpriteTrace(DeviceIntPtr dev, SpritePtr sprite);
+extern int TouchConvertToPointerEvent(const InternalEvent *ev,
+ InternalEvent *motion, InternalEvent *button);
extern int TouchGetPointerEventType(const InternalEvent *ev);
/* misc event helpers */