diff options
| -rw-r--r-- | include/input/Input.h | 4 | ||||
| -rw-r--r-- | libs/input/Input.cpp | 13 | ||||
| -rw-r--r-- | services/inputflinger/reader/mapper/TouchInputMapper.cpp | 26 |
3 files changed, 26 insertions, 17 deletions
diff --git a/include/input/Input.h b/include/input/Input.h index 567361d679..bd544b5264 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -257,6 +257,10 @@ enum class KeyState { bool isStylusToolType(ToolType toolType); +struct PointerProperties; + +bool isStylusEvent(uint32_t source, const std::vector<PointerProperties>& properties); + /* * Flags that flow alongside events in the input dispatch system to help with certain * policy decisions such as waking from device sleep. diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index c1274110d3..bd5b67b1d0 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -217,6 +217,19 @@ bool isStylusToolType(ToolType toolType) { return toolType == ToolType::STYLUS || toolType == ToolType::ERASER; } +bool isStylusEvent(uint32_t source, const std::vector<PointerProperties>& properties) { + if (!isFromSource(source, AINPUT_SOURCE_STYLUS)) { + return false; + } + // Need at least one stylus pointer for this event to be considered a stylus event + for (const PointerProperties& pointerProperties : properties) { + if (isStylusToolType(pointerProperties.toolType)) { + return true; + } + } + return false; +} + VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event) { return {{VerifiedInputEvent::Type::KEY, event.getDeviceId(), event.getEventTime(), event.getSource(), event.getDisplayId()}, diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp index 90bd7c9c74..3c26d1d73e 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp @@ -3782,34 +3782,26 @@ std::list<NotifyArgs> TouchInputMapper::abortPointerSimple(nsecs_t when, nsecs_t return out; } -static bool isStylusEvent(uint32_t source, int32_t action, const PointerProperties* properties) { - if (!isFromSource(source, AINPUT_SOURCE_STYLUS)) { - return false; - } - const auto actionIndex = action >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; - return isStylusToolType(properties[actionIndex].toolType); -} - NotifyMotionArgs TouchInputMapper::dispatchMotion( nsecs_t when, nsecs_t readTime, uint32_t policyFlags, uint32_t source, int32_t action, int32_t actionButton, int32_t flags, int32_t metaState, int32_t buttonState, int32_t edgeFlags, const PropertiesArray& properties, const CoordsArray& coords, const IdToIndexArray& idToIndex, BitSet32 idBits, int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime, MotionClassification classification) { - PointerCoords pointerCoords[MAX_POINTERS]; - PointerProperties pointerProperties[MAX_POINTERS]; + std::vector<PointerCoords> pointerCoords; + std::vector<PointerProperties> pointerProperties; uint32_t pointerCount = 0; while (!idBits.isEmpty()) { uint32_t id = idBits.clearFirstMarkedBit(); uint32_t index = idToIndex[id]; - pointerProperties[pointerCount] = properties[index]; - pointerCoords[pointerCount] = coords[index]; + pointerProperties.push_back(properties[index]); + pointerCoords.push_back(coords[index]); if (changedId >= 0 && id == uint32_t(changedId)) { action |= pointerCount << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; } - pointerCount += 1; + pointerCount++; } ALOG_ASSERT(pointerCount != 0); @@ -3837,7 +3829,7 @@ NotifyMotionArgs TouchInputMapper::dispatchMotion( const int32_t displayId = getAssociatedDisplayId().value_or(ADISPLAY_ID_NONE); const bool showDirectStylusPointer = mConfig.stylusPointerIconEnabled && - mDeviceMode == DeviceMode::DIRECT && isStylusEvent(source, action, pointerProperties) && + mDeviceMode == DeviceMode::DIRECT && isStylusEvent(source, pointerProperties) && mPointerController && displayId != ADISPLAY_ID_NONE && displayId == mPointerController->getDisplayId(); if (showDirectStylusPointer) { @@ -3869,9 +3861,9 @@ NotifyMotionArgs TouchInputMapper::dispatchMotion( [this](TouchVideoFrame& frame) { frame.rotate(this->mInputDeviceOrientation); }); return NotifyMotionArgs(getContext()->getNextId(), when, readTime, deviceId, source, displayId, policyFlags, action, actionButton, flags, metaState, buttonState, - classification, edgeFlags, pointerCount, pointerProperties, - pointerCoords, xPrecision, yPrecision, xCursorPosition, yCursorPosition, - downTime, std::move(frames)); + classification, edgeFlags, pointerCount, pointerProperties.data(), + pointerCoords.data(), xPrecision, yPrecision, xCursorPosition, + yCursorPosition, downTime, std::move(frames)); } std::list<NotifyArgs> TouchInputMapper::cancelTouch(nsecs_t when, nsecs_t readTime) { |