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