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