Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "SingleTouchInputMapper.h" |
| 18 | |
| 19 | namespace android { |
| 20 | |
Arpit Singh | 8e6fb25 | 2023-04-06 11:49:17 +0000 | [diff] [blame] | 21 | SingleTouchInputMapper::SingleTouchInputMapper(InputDeviceContext& deviceContext, |
| 22 | const InputReaderConfiguration& readerConfig) |
| 23 | : TouchInputMapper(deviceContext, readerConfig) {} |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 24 | |
| 25 | SingleTouchInputMapper::~SingleTouchInputMapper() {} |
| 26 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 27 | std::list<NotifyArgs> SingleTouchInputMapper::reset(nsecs_t when) { |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 28 | mSingleTouchMotionAccumulator.reset(getDeviceContext()); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 29 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 30 | return TouchInputMapper::reset(when); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Harry Cutts | a32a119 | 2024-06-04 15:10:31 +0000 | [diff] [blame] | 33 | std::list<NotifyArgs> SingleTouchInputMapper::process(const RawEvent& rawEvent) { |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 34 | std::list<NotifyArgs> out = TouchInputMapper::process(rawEvent); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 35 | |
Harry Cutts | a32a119 | 2024-06-04 15:10:31 +0000 | [diff] [blame] | 36 | mSingleTouchMotionAccumulator.process(rawEvent); |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 37 | return out; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void SingleTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { |
| 41 | if (mTouchButtonAccumulator.isToolActive()) { |
| 42 | outState->rawPointerData.pointerCount = 1; |
| 43 | outState->rawPointerData.idToIndex[0] = 0; |
| 44 | |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 45 | bool isHovering = mTouchButtonAccumulator.getToolType() != ToolType::MOUSE && |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 46 | (mTouchButtonAccumulator.isHovering() || |
Prabir Pradhan | 132f21c | 2024-07-25 16:48:30 +0000 | [diff] [blame] | 47 | (mRawPointerAxes.pressure && |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 48 | mSingleTouchMotionAccumulator.getAbsolutePressure() <= 0)); |
| 49 | outState->rawPointerData.markIdBit(0, isHovering); |
| 50 | |
| 51 | RawPointerData::Pointer& outPointer = outState->rawPointerData.pointers[0]; |
| 52 | outPointer.id = 0; |
| 53 | outPointer.x = mSingleTouchMotionAccumulator.getAbsoluteX(); |
| 54 | outPointer.y = mSingleTouchMotionAccumulator.getAbsoluteY(); |
| 55 | outPointer.pressure = mSingleTouchMotionAccumulator.getAbsolutePressure(); |
| 56 | outPointer.touchMajor = 0; |
| 57 | outPointer.touchMinor = 0; |
| 58 | outPointer.toolMajor = mSingleTouchMotionAccumulator.getAbsoluteToolWidth(); |
| 59 | outPointer.toolMinor = mSingleTouchMotionAccumulator.getAbsoluteToolWidth(); |
| 60 | outPointer.orientation = 0; |
| 61 | outPointer.distance = mSingleTouchMotionAccumulator.getAbsoluteDistance(); |
| 62 | outPointer.tiltX = mSingleTouchMotionAccumulator.getAbsoluteTiltX(); |
| 63 | outPointer.tiltY = mSingleTouchMotionAccumulator.getAbsoluteTiltY(); |
| 64 | outPointer.toolType = mTouchButtonAccumulator.getToolType(); |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 65 | if (outPointer.toolType == ToolType::UNKNOWN) { |
| 66 | outPointer.toolType = ToolType::FINGER; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 67 | } |
| 68 | outPointer.isHovering = isHovering; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | void SingleTouchInputMapper::configureRawPointerAxes() { |
| 73 | TouchInputMapper::configureRawPointerAxes(); |
| 74 | |
Prabir Pradhan | 132f21c | 2024-07-25 16:48:30 +0000 | [diff] [blame] | 75 | // TODO(b/351870641): Investigate why we are sometime not getting valid axis infos for the x/y |
| 76 | // axes, even though those axes are required to be supported. |
| 77 | if (const auto xInfo = getAbsoluteAxisInfo(ABS_X); xInfo.has_value()) { |
| 78 | mRawPointerAxes.x = *xInfo; |
| 79 | } |
| 80 | if (const auto yInfo = getAbsoluteAxisInfo(ABS_Y); yInfo.has_value()) { |
| 81 | mRawPointerAxes.y = *yInfo; |
| 82 | } |
| 83 | mRawPointerAxes.pressure = getAbsoluteAxisInfo(ABS_PRESSURE); |
| 84 | mRawPointerAxes.toolMajor = getAbsoluteAxisInfo(ABS_TOOL_WIDTH); |
| 85 | mRawPointerAxes.distance = getAbsoluteAxisInfo(ABS_DISTANCE); |
| 86 | mRawPointerAxes.tiltX = getAbsoluteAxisInfo(ABS_TILT_X); |
| 87 | mRawPointerAxes.tiltY = getAbsoluteAxisInfo(ABS_TILT_Y); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | bool SingleTouchInputMapper::hasStylus() const { |
| 91 | return mTouchButtonAccumulator.hasStylus(); |
| 92 | } |
| 93 | |
| 94 | } // namespace android |