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-15 08:30:17 +1000 |
commit | 12c0cedb1c6f7b1f3c77a5945bf7506112219b0e (patch) | |
tree | 5e9f3c97f055c8f1cea79a53f3847f578df2027b | |
parent | e92ea75127939fa6cfd58ac6a93d8c003d689551 (diff) |
dix: add touch to pointer event conversion helper
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | dix/touch.c | 59 | ||||
-rw-r--r-- | include/input.h | 2 |
2 files changed, 61 insertions, 0 deletions
diff --git a/dix/touch.c b/dix/touch.c index 79eb09c2b..cd441deec 100644 --- a/dix/touch.c +++ b/dix/touch.c @@ -593,6 +593,65 @@ 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; + } + + *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 f54ad80cd..b4a0a08cb 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 TouchBuildSpriteTrace(DeviceIntPtr dev, SpritePtr sprite); +extern int TouchConvertToPointerEvent(const InternalEvent *ev, + InternalEvent *motion, InternalEvent *button); extern int TouchGetPointerEventType(const InternalEvent *ev); /* misc event helpers */ |