1 /* 2 * Copyright (c) 2022-2023 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 INTERACTION_MANAGER_H 17 #define INTERACTION_MANAGER_H 18 19 #include <functional> 20 #include <memory> 21 22 #include "nocopyable.h" 23 24 #include "coordination_message.h" 25 #include "drag_data.h" 26 #include "i_coordination_listener.h" 27 #include "i_drag_listener.h" 28 29 namespace OHOS { 30 namespace Msdp { 31 namespace DeviceStatus { 32 class InteractionManager { 33 public: 34 35 static InteractionManager *GetInstance(); 36 virtual ~InteractionManager() = default; 37 38 /** 39 * @brief Registers a listener for screen hopping events of the mouse pointer. 40 * @param listener Indicates the listener for screen hopping events of the mouse pointer. 41 * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise. 42 * @since 9 43 */ 44 int32_t RegisterCoordinationListener(std::shared_ptr<ICoordinationListener> listener); 45 46 /** 47 * @brief Unregisters a listener for screen hopping events of the mouse pointer. 48 * @param listener Indicates the listener for screen hopping events of the mouse pointer. 49 * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise. 50 * @since 9 51 */ 52 int32_t UnregisterCoordinationListener(std::shared_ptr<ICoordinationListener> listener = nullptr); 53 54 /** 55 * @brief Prepares for screen hopping. 56 * @param callback Indicates the callback used to receive the result of enabling or disabling screen hopping. 57 * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise. 58 * @since 9 59 */ 60 int32_t PrepareCoordination(std::function<void(const std::string&, CoordinationMessage)> callback); 61 62 /** 63 * @brief Cancels the preparation for screen hopping. 64 * @param callback Indicates the callback used to receive the result of enabling or disabling screen hopping. 65 * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise. 66 * @since 9 67 */ 68 int32_t UnprepareCoordination(std::function<void(const std::string&, CoordinationMessage)> callback); 69 70 /** 71 * @brief Starts screen hopping for the mouse pointer. 72 * @param s remoteNetworkId Indicates the descriptor of the target input device (network ID) for screen hopping. 73 * @param startDeviceId Indicates the ID of the source input device (device ID handle) for screen hopping. 74 * @param callback Indicates the callback used to receive the result of starting screen hopping. 75 * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise. 76 * @since 9 77 */ 78 int32_t ActivateCoordination(const std::string &remoteNetworkId, int32_t startDeviceId, 79 std::function<void(const std::string&, CoordinationMessage)> callback); 80 81 /** 82 * @brief Stops screen hopping for the mouse pointer. 83 * @param isUnchained Specifies Whether to disable the cross-device link. 84 * The value <b>true</b> means to disable the cross-device link, and <b>false</b> means the opposite. 85 * @param callback Indicates the callback used to receive the result of stopping screen hopping. 86 * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise. 87 * @since 9 88 */ 89 int32_t DeactivateCoordination(bool isUnchained, 90 std::function<void(const std::string&, CoordinationMessage)> callback); 91 92 /** 93 * @brief Obtains the screen hopping status of a mouse pointer. 94 * @param deviceId Indicates the descriptor of the input device. 95 * @param callback Indicates the callback used to receive the screen hopping status. 96 * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise. 97 * @since 9 98 */ 99 int32_t GetCoordinationState(const std::string &deviceId, std::function<void(bool)> callback); 100 101 /** 102 * @brief Starts dragging. 103 * @param dragData Indicates additional data used for dragging. 104 * @param callback Indicates the callback used to return the dragging result. 105 * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise. 106 * @since 10 107 */ 108 int32_t StartDrag(const DragData &dragData, std::function<void(const DragNotifyMsg&)> callback); 109 110 /** 111 * @brief Stops dragging. 112 * @param result Indicates the dragging result. The value <b>0</b> means that the dragging operation is successful; 113 * <b>1</b> means that the dragging operation is failed; <b>2</b> means that the dragging operation is canceled. 114 * @param hasCustomAnimation Specifies whether a custom animation is played when the dragging is successful. 115 * The value <b>true</b> means that a custom animation is played, 116 * and <b>false</b> means that the default animation is played. 117 * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise. 118 * @since 10 119 */ 120 int32_t StopDrag(DragResult result, bool hasCustomAnimation); 121 122 /** 123 * @brief Updates the mouse pointer style used for dragging. 124 * @param style Indicates the new mouse pointer style. 125 * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise. 126 * @since 10 127 */ 128 int32_t UpdateDragStyle(DragCursorStyle style); 129 130 /** 131 * @brief Obtains the PID of the target window. 132 * @return Returns a value greater than or equal to 0 in normal cases; returns <b>-1</b> if the PID is invalid. 133 * @since 10 134 */ 135 int32_t GetDragTargetPid(); 136 137 /** 138 * @brief Obtains the unified data key of the target window. 139 * @param UdKey Indicates the unified data key of the target window. 140 * @return Returns a value greater than or equal to 0 in normal cases; returns <b>-1</b> if the PID is invalid. 141 * @since 10 142 */ 143 int32_t GetUdKey(std::string &udKey); 144 145 /** 146 * @brief Registers a listener for dragging status changes. 147 * @param listener Indicates the listener for dragging status changes. 148 * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise. 149 * @since 10 150 */ 151 int32_t AddDraglistener(std::shared_ptr<IDragListener> listener); 152 153 /** 154 * @brief Unregisters a listener for dragging status changes. 155 * @param listener Indicates the listener for dragging status changes. 156 * If no value is passed, all listeners are canceled. 157 * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise. 158 * @since 10 159 */ 160 int32_t RemoveDraglistener(std::shared_ptr<IDragListener> listener = nullptr); 161 162 /** 163 * @brief Displays or hides the dragging window. 164 * @param visible Specifies whether to display the dragging window. 165 * The value <b>true</b> means to display the dragging window, and <b>false</b> means to hide the window. 166 * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise. 167 * @since 10 168 */ 169 int32_t SetDragWindowVisible(bool visible); 170 171 /** 172 * @brief Obtains the position of the touch point or mouse pointer relative to 173 * the upper left corner of the shadow thumbnail. 174 * @param offsetX Indicates the x coordinate. 175 * @param offsetY Indicates the y coordinate. 176 * @param width Indicates the width of the shadow thumbnail. 177 * @param height Indicates the height of the shadow thumbnail. 178 * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise. 179 * @since 10 180 */ 181 int32_t GetShadowOffset(int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height); 182 183 /** 184 * @brief Updates the shadow thumbnail information used for dragging. 185 * @param shadowInfo Indicates the new shadow thumbnail information. 186 * @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails. 187 * @since 10 188 */ 189 int32_t UpdateShadowPic(const ShadowInfo &shadowInfo); 190 191 private: 192 InteractionManager() = default; 193 DISALLOW_COPY_AND_MOVE(InteractionManager); 194 static InteractionManager *instance_; 195 }; 196 } // namespace DeviceStatus 197 } // namespace Msdp 198 } // namespace OHOS 199 200 #define INTERACTION_MGR OHOS::Msdp::DeviceStatus::InteractionManager::GetInstance() 201 202 #endif // INTERACTION_MANAGER_H 203