• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #pragma once
18 
19 #include <cstdint>
20 #include "HidUsageAccumulator.h"
21 
22 namespace android {
23 
24 class InputDeviceContext;
25 struct RawEvent;
26 
27 /* Keeps track of the state of touch, stylus and tool buttons. */
28 class TouchButtonAccumulator {
29 public:
TouchButtonAccumulator(const InputDeviceContext & deviceContext)30     explicit TouchButtonAccumulator(const InputDeviceContext& deviceContext)
31           : mDeviceContext(deviceContext){};
32 
33     void configure();
34     void reset();
35 
36     void process(const RawEvent* rawEvent);
37 
38     uint32_t getButtonState() const;
39     ToolType getToolType() const;
40     bool isToolActive() const;
41     bool isHovering() const;
42     bool hasStylus() const;
43     bool hasButtonTouch() const;
44 
45     /*
46      * Returns the number of touches reported by the device through its BTN_TOOL_FINGER and
47      * BTN_TOOL_*TAP "buttons". Note that this count includes touches reported with their
48      * ABS_MT_TOOL_TYPE set to MT_TOOL_PALM.
49      */
50     int getTouchCount() const;
51 
52 private:
53     bool mHaveBtnTouch{};
54     bool mHaveStylus{};
55 
56     bool mBtnTouch{};
57     bool mBtnStylus{};
58     bool mBtnStylus2{};
59     bool mBtnToolFinger{};
60     bool mBtnToolPen{};
61     bool mBtnToolRubber{};
62     bool mBtnToolBrush{};
63     bool mBtnToolPencil{};
64     bool mBtnToolAirbrush{};
65     bool mBtnToolMouse{};
66     bool mBtnToolLens{};
67     bool mBtnToolDoubleTap{};
68     bool mBtnToolTripleTap{};
69     bool mBtnToolQuadTap{};
70     bool mBtnToolQuintTap{};
71 
72     HidUsageAccumulator mHidUsageAccumulator{};
73 
74     const InputDeviceContext& mDeviceContext;
75 
76     void processMappedKey(int32_t scanCode, bool down);
77 };
78 
79 } // namespace android
80