1 /* 2 * Copyright (c) 2024 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 COOPERATE_HOTAREA_H 17 #define COOPERATE_HOTAREA_H 18 19 #include <set> 20 21 #include "nocopyable.h" 22 #include "pointer_event.h" 23 24 #include "cooperate_events.h" 25 #include "coordination_message.h" 26 #include "i_context.h" 27 #include "proto.h" 28 29 namespace OHOS { 30 namespace Msdp { 31 namespace DeviceStatus { 32 namespace Cooperate { 33 class HotArea final { 34 public: 35 struct HotAreaInfo { 36 int32_t pid { -1 }; 37 MessageId msgId { MessageId::INVALID }; 38 HotAreaType msg { HotAreaType::AREA_NONE }; 39 bool isEdge { false }; 40 41 bool operator<(const HotAreaInfo &other) const 42 { 43 return (pid < other.pid); 44 } 45 }; 46 HotArea(IContext * env)47 HotArea(IContext *env) : env_(env) {} 48 ~HotArea() = default; 49 DISALLOW_COPY_AND_MOVE(HotArea); 50 51 void AddListener(const RegisterHotareaListenerEvent &event); 52 void RemoveListener(const UnregisterHotareaListenerEvent &event); 53 54 void EnableCooperate(const EnableCooperateEvent &event); 55 int32_t ProcessData(std::shared_ptr<MMI::PointerEvent> pointerEvent); 56 void OnClientDied(const ClientDiedEvent &event); 57 58 private: 59 void CheckInHotArea(); 60 void CheckPointerToEdge(HotAreaType type); 61 void NotifyMessage(); 62 void OnHotAreaMessage(HotAreaType msg, bool isEdge); 63 void NotifyHotAreaMessage(int32_t pid, MessageId msgId, HotAreaType msg, bool isEdge); 64 65 private: 66 IContext *env_ { nullptr }; 67 int32_t width_ { 720 }; 68 int32_t height_ { 1280 }; 69 int32_t displayX_ { 0 }; 70 int32_t displayY_ { 0 }; 71 int32_t deltaX_ { 0 }; 72 int32_t deltaY_ { 0 }; 73 bool isEdge_ { false }; 74 HotAreaType type_ { HotAreaType::AREA_NONE }; 75 std::mutex lock_; 76 std::set<HotAreaInfo> callbacks_; 77 }; 78 } // namespace Cooperate 79 } // namespace DeviceStatus 80 } // namespace Msdp 81 } // namespace OHOS 82 #endif // COOPERATE_HOTAREA_H 83