• 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 <memory>
20 
21 #include "singleton.h"
22 
23 #include "event_dispatch_handler.h"
24 #include "event_filter_handler.h"
25 #include "event_interceptor_handler.h"
26 #include "event_monitor_handler.h"
27 #include "event_normalize_handler.h"
28 #include "i_event_filter.h"
29 #include "i_input_event_handler.h"
30 #include "key_command_handler.h"
31 #include "key_subscriber_handler.h"
32 #include "mouse_event_normalize.h"
33 #include "switch_subscriber_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 
47     std::shared_ptr<EventNormalizeHandler> GetEventNormalizeHandler() const;
48     std::shared_ptr<EventInterceptorHandler> GetInterceptorHandler() const;
49     std::shared_ptr<KeySubscriberHandler> GetSubscriberHandler() const;
50     std::shared_ptr<SwitchSubscriberHandler> GetSwitchSubscriberHandler() const;
51     std::shared_ptr<KeyCommandHandler> GetKeyCommandHandler() const;
52     std::shared_ptr<EventMonitorHandler> GetMonitorHandler() const;
53     std::shared_ptr<EventFilterHandler> GetFilterHandler() const;
54     std::shared_ptr<EventDispatchHandler> GetEventDispatchHandler() const;
55 
56 private:
57     int32_t BuildInputHandlerChain();
58     bool IsTouchpadMistouch(libinput_event* event);
59     bool IsTouchpadTapMistouch(libinput_event* event);
60 
61     UDSServer *udsServer_ { nullptr };
62     std::shared_ptr<EventNormalizeHandler> eventNormalizeHandler_ { nullptr };
63     std::shared_ptr<EventFilterHandler> eventFilterHandler_ { nullptr };
64     std::shared_ptr<EventInterceptorHandler> eventInterceptorHandler_ { nullptr };
65     std::shared_ptr<KeySubscriberHandler> eventSubscriberHandler_ { nullptr };
66     std::shared_ptr<SwitchSubscriberHandler> switchEventSubscriberHandler_ { nullptr };
67     std::shared_ptr<KeyCommandHandler> eventKeyCommandHandler_ { nullptr };
68     std::shared_ptr<EventMonitorHandler> eventMonitorHandler_ { nullptr };
69     std::shared_ptr<EventDispatchHandler> eventDispatchHandler_ { nullptr };
70 
71     uint64_t idSeed_ { 0 };
72     bool isTyping_ { false };
73     int32_t timerId_ { -1 };
74     bool isTapMistouch_ { false };
75 };
76 #define InputHandler ::OHOS::DelayedSingleton<InputEventHandler>::GetInstance()
77 } // namespace MMI
78 } // namespace OHOS
79 #endif // INPUT_EVENT_HANDLER_H
80