1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef TOUCH_TRANSFORM_PROCESSOR_H
17 #define TOUCH_TRANSFORM_PROCESSOR_H
18 
19 #include "nocopyable.h"
20 
21 #include "aggregator.h"
22 #include "fingersense_manager.h"
23 #include "struct_multimodal.h"
24 #include "timer_manager.h"
25 #include "transform_processor.h"
26 
27 namespace OHOS {
28 namespace MMI {
29 class TouchTransformProcessor final : public TransformProcessor {
30 public:
31     explicit TouchTransformProcessor(int32_t deviceId);
32     DISALLOW_COPY_AND_MOVE(TouchTransformProcessor);
33     ~TouchTransformProcessor() = default;
34     std::shared_ptr<PointerEvent> OnEvent(struct libinput_event *event) override;
GetPointerEvent()35     std::shared_ptr<PointerEvent> GetPointerEvent() override { return nullptr; }
36 
37 private:
38     bool OnEventTouchDown(struct libinput_event *event);
39     bool OnEventTouchMotion(struct libinput_event *event);
40     bool OnEventTouchUp(struct libinput_event *event);
41     int32_t GetTouchToolType(struct libinput_event_touch *data, struct libinput_device *device);
42     int32_t GetTouchToolType(struct libinput_device *device);
43     void TransformTouchProperties(TouchType &rawTouch, PointerEvent::PointerItem &pointerItem);
44     void NotifyFingersenseProcess(PointerEvent::PointerItem &pointerItem, int32_t &toolType);
45     void UpdatePointerItemProperties(PointerEvent::PointerItem &item, EventTouch &touchInfo);
46     void InitToolTypes();
47     bool DumpInner();
48 private:
49     const int32_t deviceId_ { -1 };
50     std::shared_ptr<PointerEvent> pointerEvent_ { nullptr };
51     std::vector<std::pair<int32_t, int32_t>> vecToolType_;
52     std::unordered_map<int32_t, bool> pointerItemCancelMarks_;
53     Aggregator aggregator_ {
54             [](int32_t intervalMs, int32_t repeatCount, std::function<void()> callback) -> int32_t {
55                 return TimerMgr->AddTimer(intervalMs, repeatCount, std::move(callback));
56             },
57             [](int32_t timerId) -> int32_t
58             {
59                 return TimerMgr->ResetTimer(timerId);
60             }
61     };
62 #ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
63     TouchType rawTouch_;
64 #endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
65 };
66 } // namespace MMI
67 } // namespace OHOS
68 #endif // TOUCH_TRANSFORM_PROCESSOR_H