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