/* * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef INTERACTION_MANAGER_H #define INTERACTION_MANAGER_H #include #include #include "nocopyable.h" #include "coordination_message.h" #include "drag_data.h" #include "i_coordination_listener.h" #include "i_drag_listener.h" namespace OHOS { namespace Msdp { namespace DeviceStatus { class InteractionManager { public: static InteractionManager *GetInstance(); virtual ~InteractionManager() = default; /** * @brief Registers a listener for screen hopping events of the mouse pointer. * @param listener Indicates the listener for screen hopping events of the mouse pointer. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. * @since 9 */ int32_t RegisterCoordinationListener(std::shared_ptr listener); /** * @brief Unregisters a listener for screen hopping events of the mouse pointer. * @param listener Indicates the listener for screen hopping events of the mouse pointer. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. * @since 9 */ int32_t UnregisterCoordinationListener(std::shared_ptr listener = nullptr); /** * @brief Prepares for screen hopping. * @param callback Indicates the callback used to receive the result of enabling or disabling screen hopping. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. * @since 9 */ int32_t PrepareCoordination(std::function callback); /** * @brief Cancels the preparation for screen hopping. * @param callback Indicates the callback used to receive the result of enabling or disabling screen hopping. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. * @since 9 */ int32_t UnprepareCoordination(std::function callback); /** * @brief Starts screen hopping for the mouse pointer. * @param s remoteNetworkId Indicates the descriptor of the target input device (network ID) for screen hopping. * @param startDeviceId Indicates the ID of the source input device (device ID handle) for screen hopping. * @param callback Indicates the callback used to receive the result of starting screen hopping. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. * @since 9 */ int32_t ActivateCoordination(const std::string &remoteNetworkId, int32_t startDeviceId, std::function callback); /** * @brief Stops screen hopping for the mouse pointer. * @param isUnchained Specifies Whether to disable the cross-device link. * The value true means to disable the cross-device link, and false means the opposite. * @param callback Indicates the callback used to receive the result of stopping screen hopping. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. * @since 9 */ int32_t DeactivateCoordination(bool isUnchained, std::function callback); /** * @brief Obtains the screen hopping status of a mouse pointer. * @param deviceId Indicates the descriptor of the input device. * @param callback Indicates the callback used to receive the screen hopping status. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. * @since 9 */ int32_t GetCoordinationState(const std::string &deviceId, std::function callback); /** * @brief Starts dragging. * @param dragData Indicates additional data used for dragging. * @param callback Indicates the callback used to return the dragging result. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. * @since 10 */ int32_t StartDrag(const DragData &dragData, std::function callback); /** * @brief Stops dragging. * @param result Indicates the dragging result. The value 0 means that the dragging operation is successful; * 1 means that the dragging operation is failed; 2 means that the dragging operation is canceled. * @param hasCustomAnimation Specifies whether a custom animation is played when the dragging is successful. * The value true means that a custom animation is played, * and false means that the default animation is played. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. * @since 10 */ int32_t StopDrag(DragResult result, bool hasCustomAnimation); /** * @brief Updates the mouse pointer style used for dragging. * @param style Indicates the new mouse pointer style. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. * @since 10 */ int32_t UpdateDragStyle(DragCursorStyle style); /** * @brief Obtains the PID of the target window. * @return Returns a value greater than or equal to 0 in normal cases; returns -1 if the PID is invalid. * @since 10 */ int32_t GetDragTargetPid(); /** * @brief Obtains the unified data key of the target window. * @param UdKey Indicates the unified data key of the target window. * @return Returns a value greater than or equal to 0 in normal cases; returns -1 if the PID is invalid. * @since 10 */ int32_t GetUdKey(std::string &udKey); /** * @brief Registers a listener for dragging status changes. * @param listener Indicates the listener for dragging status changes. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. * @since 10 */ int32_t AddDraglistener(std::shared_ptr listener); /** * @brief Unregisters a listener for dragging status changes. * @param listener Indicates the listener for dragging status changes. * If no value is passed, all listeners are canceled. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. * @since 10 */ int32_t RemoveDraglistener(std::shared_ptr listener = nullptr); /** * @brief Displays or hides the dragging window. * @param visible Specifies whether to display the dragging window. * The value true means to display the dragging window, and false means to hide the window. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. * @since 10 */ int32_t SetDragWindowVisible(bool visible); /** * @brief Obtains the position of the touch point or mouse pointer relative to * the upper left corner of the shadow thumbnail. * @param offsetX Indicates the x coordinate. * @param offsetY Indicates the y coordinate. * @param width Indicates the width of the shadow thumbnail. * @param height Indicates the height of the shadow thumbnail. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. * @since 10 */ int32_t GetShadowOffset(int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height); /** * @brief Updates the shadow thumbnail information used for dragging. * @param shadowInfo Indicates the new shadow thumbnail information. * @return Returns 0 if the operation is successful; returns other values if the operation fails. * @since 10 */ int32_t UpdateShadowPic(const ShadowInfo &shadowInfo); private: InteractionManager() = default; DISALLOW_COPY_AND_MOVE(InteractionManager); static InteractionManager *instance_; }; } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS #define INTERACTION_MGR OHOS::Msdp::DeviceStatus::InteractionManager::GetInstance() #endif // INTERACTION_MANAGER_H