From 50908afd6e18b57b55def0e4a6972f8777db2021 Mon Sep 17 00:00:00 2001 From: "Nathaniel R. Lewis" Date: Wed, 21 Aug 2019 04:46:29 +0000 Subject: Add relative coordinates for touchpad events. By their nature, touchpad devices deal in absolute coordinates. It may prove useful for app developers to receive information about how touches have changed position since the last event. Test: connect a device that android classifies as a touchpad (such as a DualShock 4 in touchpad capture mode). MotionEvents received in an app should have valid content in AXIS_RELATIVE_X and AXIS_RELATIVE_Y fields. Bug: 38511270 Change-Id: Ic96323464af6f11027fbf36ee00e5d226c1b8626 Merged-In: Ic96323464af6f11027fbf36ee00e5d226c1b8626 --- .../reader/mapper/TouchInputMapper.cpp | 25 +++++++++++++++++----- .../inputflinger/reader/mapper/TouchInputMapper.h | 4 +++- 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'services') diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp index 0733342f38..0f4e3a502c 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp @@ -142,12 +142,14 @@ void CookedPointerData::clear() { hoveringIdBits.clear(); touchingIdBits.clear(); canceledIdBits.clear(); + validIdBits.clear(); } void CookedPointerData::copyFrom(const CookedPointerData& other) { pointerCount = other.pointerCount; hoveringIdBits = other.hoveringIdBits; touchingIdBits = other.touchingIdBits; + validIdBits = other.validIdBits; for (uint32_t i = 0; i < pointerCount; i++) { pointerProperties[i].copyFrom(other.pointerProperties[i]); @@ -288,12 +290,14 @@ void TouchInputMapper::dump(std::string& dump) { const PointerProperties& pointerProperties = mLastCookedState.cookedPointerData.pointerProperties[i]; const PointerCoords& pointerCoords = mLastCookedState.cookedPointerData.pointerCoords[i]; - dump += StringPrintf(INDENT4 "[%d]: id=%d, x=%0.3f, y=%0.3f, pressure=%0.3f, " - "touchMajor=%0.3f, touchMinor=%0.3f, toolMajor=%0.3f, " - "toolMinor=%0.3f, " + dump += StringPrintf(INDENT4 "[%d]: id=%d, x=%0.3f, y=%0.3f, dx=%0.3f, dy=%0.3f, " + "pressure=%0.3f, touchMajor=%0.3f, touchMinor=%0.3f, " + "toolMajor=%0.3f, toolMinor=%0.3f, " "orientation=%0.3f, tilt=%0.3f, distance=%0.3f, " "toolType=%d, isHovering=%s\n", i, pointerProperties.id, pointerCoords.getX(), pointerCoords.getY(), + pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X), + pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y), pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR), pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR), @@ -2270,15 +2274,26 @@ void TouchInputMapper::cookPointerData() { out.setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, toolMinor); } + // Write output relative fieldis if applicable. + uint32_t id = in.id; + if (mSource == AINPUT_SOURCE_TOUCHPAD && + mLastCookedState.cookedPointerData.hasPointerCoordsForId(id)) { + const PointerCoords& p = mLastCookedState.cookedPointerData.pointerCoordsForId(id); + float dx = xTransformed - p.getAxisValue(AMOTION_EVENT_AXIS_X); + float dy = yTransformed - p.getAxisValue(AMOTION_EVENT_AXIS_Y); + out.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, dx); + out.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, dy); + } + // Write output properties. PointerProperties& properties = mCurrentCookedState.cookedPointerData.pointerProperties[i]; - uint32_t id = in.id; properties.clear(); properties.id = id; properties.toolType = in.toolType; - // Write id index. + // Write id index and mark id as valid. mCurrentCookedState.cookedPointerData.idToIndex[id] = i; + mCurrentCookedState.cookedPointerData.validIdBits.markBit(id); } } diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.h b/services/inputflinger/reader/mapper/TouchInputMapper.h index 94486a67b0..df6581d1c8 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.h +++ b/services/inputflinger/reader/mapper/TouchInputMapper.h @@ -103,7 +103,7 @@ struct CookedPointerData { uint32_t pointerCount; PointerProperties pointerProperties[MAX_POINTERS]; PointerCoords pointerCoords[MAX_POINTERS]; - BitSet32 hoveringIdBits, touchingIdBits, canceledIdBits; + BitSet32 hoveringIdBits, touchingIdBits, canceledIdBits, validIdBits; uint32_t idToIndex[MAX_POINTER_ID + 1]; CookedPointerData(); @@ -129,6 +129,8 @@ struct CookedPointerData { inline bool isTouching(uint32_t pointerIndex) const { return touchingIdBits.hasBit(pointerProperties[pointerIndex].id); } + + inline bool hasPointerCoordsForId(uint32_t id) const { return validIdBits.hasBit(id); } }; class TouchInputMapper : public InputMapper { -- cgit v1.2.3-59-g8ed1b