| 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 |  | 
| Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 21 | SingleTouchInputMapper::SingleTouchInputMapper(InputDeviceContext& deviceContext) | 
 | 22 |       : TouchInputMapper(deviceContext) {} | 
| Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 23 |  | 
 | 24 | SingleTouchInputMapper::~SingleTouchInputMapper() {} | 
 | 25 |  | 
| Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 26 | std::list<NotifyArgs> SingleTouchInputMapper::reset(nsecs_t when) { | 
| Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 27 |     mSingleTouchMotionAccumulator.reset(getDeviceContext()); | 
| Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 28 |  | 
| Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 29 |     return TouchInputMapper::reset(when); | 
| Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 30 | } | 
 | 31 |  | 
| Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 32 | std::list<NotifyArgs> SingleTouchInputMapper::process(const RawEvent* rawEvent) { | 
 | 33 |     std::list<NotifyArgs> out = TouchInputMapper::process(rawEvent); | 
| Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 34 |  | 
 | 35 |     mSingleTouchMotionAccumulator.process(rawEvent); | 
| Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 36 |     return out; | 
| Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 37 | } | 
 | 38 |  | 
 | 39 | void SingleTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { | 
 | 40 |     if (mTouchButtonAccumulator.isToolActive()) { | 
 | 41 |         outState->rawPointerData.pointerCount = 1; | 
 | 42 |         outState->rawPointerData.idToIndex[0] = 0; | 
 | 43 |  | 
 | 44 |         bool isHovering = mTouchButtonAccumulator.getToolType() != AMOTION_EVENT_TOOL_TYPE_MOUSE && | 
 | 45 |                 (mTouchButtonAccumulator.isHovering() || | 
 | 46 |                  (mRawPointerAxes.pressure.valid && | 
 | 47 |                   mSingleTouchMotionAccumulator.getAbsolutePressure() <= 0)); | 
 | 48 |         outState->rawPointerData.markIdBit(0, isHovering); | 
 | 49 |  | 
 | 50 |         RawPointerData::Pointer& outPointer = outState->rawPointerData.pointers[0]; | 
 | 51 |         outPointer.id = 0; | 
 | 52 |         outPointer.x = mSingleTouchMotionAccumulator.getAbsoluteX(); | 
 | 53 |         outPointer.y = mSingleTouchMotionAccumulator.getAbsoluteY(); | 
 | 54 |         outPointer.pressure = mSingleTouchMotionAccumulator.getAbsolutePressure(); | 
 | 55 |         outPointer.touchMajor = 0; | 
 | 56 |         outPointer.touchMinor = 0; | 
 | 57 |         outPointer.toolMajor = mSingleTouchMotionAccumulator.getAbsoluteToolWidth(); | 
 | 58 |         outPointer.toolMinor = mSingleTouchMotionAccumulator.getAbsoluteToolWidth(); | 
 | 59 |         outPointer.orientation = 0; | 
 | 60 |         outPointer.distance = mSingleTouchMotionAccumulator.getAbsoluteDistance(); | 
 | 61 |         outPointer.tiltX = mSingleTouchMotionAccumulator.getAbsoluteTiltX(); | 
 | 62 |         outPointer.tiltY = mSingleTouchMotionAccumulator.getAbsoluteTiltY(); | 
 | 63 |         outPointer.toolType = mTouchButtonAccumulator.getToolType(); | 
 | 64 |         if (outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { | 
 | 65 |             outPointer.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; | 
 | 66 |         } | 
 | 67 |         outPointer.isHovering = isHovering; | 
 | 68 |     } | 
 | 69 | } | 
 | 70 |  | 
 | 71 | void SingleTouchInputMapper::configureRawPointerAxes() { | 
 | 72 |     TouchInputMapper::configureRawPointerAxes(); | 
 | 73 |  | 
 | 74 |     getAbsoluteAxisInfo(ABS_X, &mRawPointerAxes.x); | 
 | 75 |     getAbsoluteAxisInfo(ABS_Y, &mRawPointerAxes.y); | 
 | 76 |     getAbsoluteAxisInfo(ABS_PRESSURE, &mRawPointerAxes.pressure); | 
 | 77 |     getAbsoluteAxisInfo(ABS_TOOL_WIDTH, &mRawPointerAxes.toolMajor); | 
 | 78 |     getAbsoluteAxisInfo(ABS_DISTANCE, &mRawPointerAxes.distance); | 
 | 79 |     getAbsoluteAxisInfo(ABS_TILT_X, &mRawPointerAxes.tiltX); | 
 | 80 |     getAbsoluteAxisInfo(ABS_TILT_Y, &mRawPointerAxes.tiltY); | 
 | 81 | } | 
 | 82 |  | 
 | 83 | bool SingleTouchInputMapper::hasStylus() const { | 
 | 84 |     return mTouchButtonAccumulator.hasStylus(); | 
 | 85 | } | 
 | 86 |  | 
 | 87 | } // namespace android |