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 #ifdef OHOS_BUILD_ENABLE_POINTER 33 #include "mouse_event_normalize.h" 34 #endif // OHOS_BUILD_ENABLE_POINTER 35 // #ifdef OHOS_BUILD_ENABLE_SWITCH 36 #include "switch_subscriber_handler.h" 37 // #endif // OHOS_BUILD_ENABLE_SWITCH 38 #include "event_pre_monitor_handler.h" 39 40 namespace OHOS { 41 namespace MMI { 42 using EventFun = std::function<int32_t(libinput_event *event)>; 43 using NotifyDeviceChange = std::function<void(int32_t, int32_t, char *)>; 44 class InputEventHandler final : public std::enable_shared_from_this<InputEventHandler> { 45 DECLARE_DELAYED_SINGLETON(InputEventHandler); 46 public: 47 DISALLOW_COPY_AND_MOVE(InputEventHandler); 48 void Init(UDSServer& udsServer); 49 void OnEvent(void *event, int64_t frameTime); 50 UDSServer *GetUDSServer() const; 51 int32_t GetIntervalSinceLastInput(int64_t &timeInterval); 52 53 std::shared_ptr<EventNormalizeHandler> GetEventNormalizeHandler() const; 54 std::shared_ptr<EventInterceptorHandler> GetInterceptorHandler() const; 55 std::shared_ptr<KeySubscriberHandler> GetSubscriberHandler() const; 56 std::shared_ptr<SwitchSubscriberHandler> GetSwitchSubscriberHandler() const; 57 std::shared_ptr<KeyCommandHandler> GetKeyCommandHandler() const; 58 std::shared_ptr<EventMonitorHandler> GetMonitorHandler() const; 59 std::shared_ptr<EventFilterHandler> GetFilterHandler() const; 60 std::shared_ptr<EventDispatchHandler> GetEventDispatchHandler() const; 61 std::shared_ptr<EventPreMonitorHandler> GetEventPreMonitorHandler() const; 62 63 private: 64 int32_t BuildInputHandlerChain(); 65 bool IsTouchpadMistouch(libinput_event* event); 66 bool IsTouchpadTapMistouch(libinput_event* event); 67 68 UDSServer *udsServer_ { nullptr }; 69 std::shared_ptr<EventNormalizeHandler> eventNormalizeHandler_ { nullptr }; 70 std::shared_ptr<EventFilterHandler> eventFilterHandler_ { nullptr }; 71 std::shared_ptr<EventInterceptorHandler> eventInterceptorHandler_ { nullptr }; 72 std::shared_ptr<KeySubscriberHandler> eventSubscriberHandler_ { nullptr }; 73 std::shared_ptr<SwitchSubscriberHandler> switchEventSubscriberHandler_ { nullptr }; 74 std::shared_ptr<KeyCommandHandler> eventKeyCommandHandler_ { nullptr }; 75 std::shared_ptr<EventMonitorHandler> eventMonitorHandler_ { nullptr }; 76 std::shared_ptr<EventDispatchHandler> eventDispatchHandler_ { nullptr }; 77 std::shared_ptr<EventPreMonitorHandler> eventPreMonitorHandler_ { nullptr }; 78 79 uint64_t idSeed_ { 0 }; 80 bool isTyping_ { false }; 81 int32_t timerId_ { -1 }; 82 bool isTapMistouch_ { false }; 83 int64_t lastEventBeginTime_ { 0 }; 84 }; 85 #define InputHandler ::OHOS::DelayedSingleton<InputEventHandler>::GetInstance() 86 } // namespace MMI 87 } // namespace OHOS 88 #endif // INPUT_EVENT_HANDLER_H 89