• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 INPUT_EVENT_HANDLER_H
17 #define INPUT_EVENT_HANDLER_H
18 
19 #include "event_dispatch_handler.h"
20 #include "event_filter_handler.h"
21 #include "event_interceptor_handler.h"
22 #include "event_monitor_handler.h"
23 #include "event_normalize_handler.h"
24 #include "key_command_handler.h"
25 #include "key_subscriber_handler.h"
26 #ifdef OHOS_BUILD_ENABLE_POINTER
27 #include "mouse_event_normalize.h"
28 #endif // OHOS_BUILD_ENABLE_POINTER
29 // #ifdef OHOS_BUILD_ENABLE_SWITCH
30 #include "switch_subscriber_handler.h"
31 // #endif // OHOS_BUILD_ENABLE_SWITCH
32 #include "event_pre_monitor_handler.h"
33 
34 namespace OHOS {
35 namespace MMI {
36 using EventFun = std::function<int32_t(libinput_event *event)>;
37 using NotifyDeviceChange = std::function<void(int32_t, int32_t, char *)>;
38 class InputEventHandler final : public std::enable_shared_from_this<InputEventHandler> {
39     DECLARE_DELAYED_SINGLETON(InputEventHandler);
40 public:
41     DISALLOW_COPY_AND_MOVE(InputEventHandler);
42     void Init(UDSServer& udsServer);
43     void OnEvent(void *event, int64_t frameTime);
44     UDSServer *GetUDSServer() const;
45     int32_t SetMoveEventFilters(bool flag);
46     int32_t GetIntervalSinceLastInput(int64_t &timeInterval);
47 
48     std::shared_ptr<EventNormalizeHandler> GetEventNormalizeHandler() const;
49     std::shared_ptr<EventInterceptorHandler> GetInterceptorHandler() const;
50     std::shared_ptr<KeySubscriberHandler> GetSubscriberHandler() const;
51     std::shared_ptr<SwitchSubscriberHandler> GetSwitchSubscriberHandler() const;
52     std::shared_ptr<KeyCommandHandler> GetKeyCommandHandler() const;
53     std::shared_ptr<EventMonitorHandler> GetMonitorHandler() const;
54     std::shared_ptr<EventFilterHandler> GetFilterHandler() const;
55     std::shared_ptr<EventDispatchHandler> GetEventDispatchHandler() const;
56     std::shared_ptr<EventPreMonitorHandler> GetEventPreMonitorHandler() const;
57 private:
58     int32_t BuildInputHandlerChain();
59 
60     // disable-while-typing
61     void UpdateDwtRecord(libinput_event *event);
62     void UpdateDwtTouchpadRecord(libinput_event *event);
63     void UpdateDwtKeyboardRecord(libinput_event *event);
64     bool IsStandaloneFunctionKey(uint32_t keycode);
65     bool IsModifierKey(uint32_t keycode);
66     void RefreshDwtActingState();
67     bool IsTouchpadMistouch(libinput_event *event);
68     bool IsTouchpadButtonMistouch(libinput_event *event);
69     bool IsTouchpadTapMistouch(libinput_event *event);
70     bool IsTouchpadMotionMistouch(libinput_event *event);
71     bool IsTouchpadPointerMotionMistouch(libinput_event *event);
72 
73     UDSServer *udsServer_ { nullptr };
74     std::shared_ptr<EventNormalizeHandler> eventNormalizeHandler_ { nullptr };
75     std::shared_ptr<EventFilterHandler> eventFilterHandler_ { nullptr };
76     std::shared_ptr<EventInterceptorHandler> eventInterceptorHandler_ { nullptr };
77     std::shared_ptr<KeySubscriberHandler> eventSubscriberHandler_ { nullptr };
78     std::shared_ptr<SwitchSubscriberHandler> switchEventSubscriberHandler_ { nullptr };
79     std::shared_ptr<KeyCommandHandler> eventKeyCommandHandler_ { nullptr };
80     std::shared_ptr<EventMonitorHandler> eventMonitorHandler_ { nullptr };
81     std::shared_ptr<EventDispatchHandler> eventDispatchHandler_ { nullptr };
82     std::shared_ptr<EventPreMonitorHandler> eventPreMonitorHandler_ { nullptr };
83 
84     uint64_t idSeed_ { 0 };
85 
86     // assumption:
87     // 1. LIBINPUT_EVENT_TOUCHPAD_* and LIBINPUT_EVENT_POINTER_*_TOUCHPAD are in pairs
88     // 2. LIBINPUT_EVENT_POINTER_*_TOUCHPAD always comes after LIBINPUT_EVENT_TOUCHPAD_*
89     double touchpadEventDownAbsX_ { 0.0 };
90     double touchpadEventDownAbsY_ { 0.0 };
91     double touchpadEventAbsX_ { 0.0 };
92     double touchpadEventAbsY_ { 0.0 };
93     // disable-while-typing
94     bool isDwtEdgeAreaForTouchpadMotionActing_ { false };
95     bool isDwtEdgeAreaForTouchpadButtonActing_ { false };
96     bool isDwtEdgeAreaForTouchpadTapActing_ { false };
97     bool isButtonMistouch_ { false };
98     bool isTapMistouch_ { false };
99     int modifierPressedCount_ { 0 };
100     static constexpr uint32_t TOUCHPAD_KEY_CNT = 0x300;
101     std::vector<bool> isKeyPressedWithAnyModifiers_ = std::vector<bool>(TOUCHPAD_KEY_CNT, false); // keycode as index
102 
103     int64_t lastEventBeginTime_ { 0 };
104 
105     static constexpr double TOUCHPAD_EDGE_WIDTH = 15.0;
106     static constexpr double TOUCHPAD_EDGE_WIDTH_RELEASE = 20.0;
107     static constexpr double TOUCHPAD_EDGE_WIDTH_FOR_BUTTON = 8.0;
108     static constexpr double TOUCHPAD_EDGE_WIDTH_FOR_TAP = 25.0;
109 };
110 #define InputHandler ::OHOS::DelayedSingleton<InputEventHandler>::GetInstance()
111 } // namespace MMI
112 } // namespace OHOS
113 #endif // INPUT_EVENT_HANDLER_H