diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2011-12-14 17:04:38 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2011-12-21 12:38:36 +1000 |
commit | 753c4dca1e42035e29fb21458a746e484ed93ca3 (patch) | |
tree | 2602bdd710861c0e0895a338503287e5920bce97 | |
parent | c3843f5498a849920ab68cca3557411ad8ab3454 (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.c | 62 | ||||
-rw-r--r-- | include/input.h | 2 |
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 */ |