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 #ifndef INPUT_EVENT_HANDLER_H 16 #define INPUT_EVENT_HANDLER_H 17 18 #include <memory> 19 #include "event_dispatch.h" 20 #include "event_package.h" 21 #include "i_event_filter.h" 22 #include "mouse_event_handler.h" 23 #include "msg_handler.h" 24 #include "singleton.h" 25 26 namespace OHOS { 27 namespace MMI { 28 using EventFun = std::function<int32_t(const multimodal_libinput_event& ev)>; 29 using NotifyDeviceChange = std::function<void(int32_t, int32_t, char *)>; 30 class InputEventHandler : public MsgHandler<EventFun>, public DelayedSingleton<InputEventHandler> { 31 public: 32 InputEventHandler(); 33 virtual ~InputEventHandler() override; 34 void Init(UDSServer& udsServer); 35 void OnEvent(void *event); 36 void OnCheckEventReport(); 37 int32_t OnMouseEventEndTimerHandler(std::shared_ptr<OHOS::MMI::PointerEvent> pointerEvent); 38 UDSServer *GetUDSServer(); 39 int32_t AddInputEventFilter(sptr<IEventFilter> filter); 40 void AddHandleTimer(int32_t timeout = 300); 41 protected: 42 int32_t OnEventDeviceAdded(const multimodal_libinput_event& event); 43 int32_t OnEventDeviceRemoved(const multimodal_libinput_event& event); 44 int32_t OnEventPointer(const multimodal_libinput_event& event); 45 int32_t OnEventTouch(const multimodal_libinput_event& event); 46 int32_t OnEventTouchSecond(struct libinput_event *event); 47 int32_t OnEventTouchPadSecond(struct libinput_event *event); 48 int32_t OnEventGesture(const multimodal_libinput_event& event); 49 int32_t OnEventTouchpad(const multimodal_libinput_event& event); 50 int32_t OnGestureEvent(struct libinput_event *event); 51 int32_t OnEventKey(const multimodal_libinput_event& event); 52 53 int32_t OnMouseEventHandler(struct libinput_event *event); 54 bool SendMsg(const int32_t fd, NetPacket& pkt) const; 55 56 private: 57 int32_t OnEventHandler(const multimodal_libinput_event& ev); 58 std::mutex mu_; 59 UDSServer *udsServer_ = nullptr; 60 EventDispatch eventDispatch_; 61 EventPackage eventPackage_; 62 KeyEventValueTransformation xkbKeyboardHandlerKey_; 63 NotifyDeviceChange notifyDeviceChange_; 64 std::shared_ptr<OHOS::MMI::KeyEvent> keyEvent_ = nullptr; 65 66 uint64_t idSeed_ = 0; 67 int32_t eventType_ = 0; 68 int64_t initSysClock_ = 0; 69 int64_t lastSysClock_ = 0; 70 int32_t timerId_ = -1; 71 }; 72 } // namespace MMI 73 } // namespace OHOS 74 #define InputHandler OHOS::MMI::InputEventHandler::GetInstance() 75 #endif // INPUT_EVENT_HANDLER_H 76