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