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_MANAGER_IMPL_H 17 #define INPUT_MANAGER_IMPL_H 18 19 #include <vector> 20 #include "singleton.h" 21 #include "display_info.h" 22 #include "i_input_event_consumer.h" 23 #include "pointer_event.h" 24 #include "if_mmi_client.h" 25 #include "net_packet.h" 26 #include "if_client_msg_handler.h" 27 #include "event_filter_service.h" 28 #include "input_monitor_manager.h" 29 #include "input_interceptor_manager.h" 30 31 namespace OHOS { 32 namespace MMI { 33 class InputManagerImpl : public DelayedSingleton<InputManagerImpl> { 34 public: 35 virtual ~InputManagerImpl() = default; 36 InputManagerImpl() = default; 37 38 void UpdateDisplayInfo(const std::vector<PhysicalDisplayInfo> &physicalDisplays, 39 const std::vector<LogicalDisplayInfo> &logicalDisplays); // 建议本地调用,可IPC 40 int32_t AddInputEventFilter(std::function<bool(std::shared_ptr<PointerEvent>)> filter); 41 42 void SetWindowInputEventConsumer(std::shared_ptr<OHOS::MMI::IInputEventConsumer> inputEventConsumer); 43 44 void OnKeyEvent(std::shared_ptr<OHOS::MMI::KeyEvent> keyEvent); 45 void OnPointerEvent(std::shared_ptr<OHOS::MMI::PointerEvent> pointerEvent); 46 int32_t PackDisplayData(NetPacket &pkt); 47 48 int32_t AddMonitor(std::function<void(std::shared_ptr<KeyEvent>)> monitor); 49 int32_t AddMontior(std::function<void(std::shared_ptr<PointerEvent>)> monitor); 50 int32_t AddMonitor(std::shared_ptr<IInputEventConsumer> consumer); 51 void RemoveMonitor(int32_t monitorId); 52 void MarkConsumed(int32_t monitorId, int32_t eventId); 53 54 int32_t AddInterceptor(std::shared_ptr<IInputEventConsumer> interceptor); 55 int32_t AddInterceptor(int32_t sourceType, std::function<void(std::shared_ptr<PointerEvent>)> interceptor); 56 int32_t AddInterceptor(std::function<void(std::shared_ptr<KeyEvent>)> interceptor); 57 void RemoveInterceptor(int32_t interceptorId); 58 59 void SimulateInputEvent(std::shared_ptr<OHOS::MMI::KeyEvent> keyEvent); 60 void SimulateInputEvent(std::shared_ptr<OHOS::MMI::PointerEvent> pointerEvent); 61 void OnConnected(); 62 63 private: 64 int32_t PackPhysicalDisplay(NetPacket &pkt); 65 int32_t PackLogicalDisplay(NetPacket &pkt); 66 void PrintDisplayDebugInfo(); 67 void SendDisplayInfo(); 68 69 private: 70 sptr<EventFilterService> eventFilterService_ {nullptr}; 71 std::shared_ptr<OHOS::MMI::IInputEventConsumer> consumer_ = nullptr; 72 std::vector<PhysicalDisplayInfo> physicalDisplays_; 73 std::vector<LogicalDisplayInfo> logicalDisplays_; 74 InputMonitorManager monitorManager_; 75 InputInterceptorManager interceptorManager_; 76 }; 77 } // namespace MMI 78 } // namespace OHOS 79 #endif // INPUT_MANAGER_IMPL_H