• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 OHOS_ROSEN_WINDOW_SESSION_COORDINATE_HELPER_H
17 #define OHOS_ROSEN_WINDOW_SESSION_COORDINATE_HELPER_H
18 
19 #include "interfaces/include/ws_common.h"
20 
21 namespace OHOS::Rosen {
22 
23 /**
24  * @class SessionCoordinateHelper
25  *
26  * @brief Helper class for converting between global and screen-relative coordinates.
27  *
28  * Provides utility methods to convert window rectangles between:
29  * - Global coordinates: a unified coordinate space where (0, 0) is the top-left of the primary screen.
30  * - Screen-relative coordinates: coordinates relative to the top-left corner of a specific screen.
31  */
32 class SessionCoordinateHelper {
33 public:
34     /**
35      * @brief Convert screen-relative coordinates to global coordinates.
36      *
37      * This function converts a rectangle defined relative to a specific screen's origin
38      * into global coordinates based on the screen’s global position.
39      *
40      * @param screenId The screen ID associated with the relative coordinates.
41      * @param relativeRect The rectangle relative to the given screen.
42      * @return The rectangle in global coordinates.
43      */
44     static WSRect RelativeToGlobalDisplayRect(ScreenId screenId, const WSRect& relativeRect);
45 
46     /**
47      * @brief Convert global coordinates to screen-relative coordinates.
48      *
49      * This function maps a global rectangle into the coordinate space of a specific screen.
50      * It selects the screen that has the largest intersection area with the given global rectangle.
51      * If no screen overlaps, the original screen is used as a fallback.
52      *
53      * @param originalScreenId The original screen ID where the window was originally located.
54      * @param globalRect The rectangle in global coordinates.
55      * @return The rectangle relative to the selected screen, along with its screen ID.
56      */
57     static WSScreenRelativeRect GlobalToScreenRelativeRect(ScreenId originalScreenId, const WSRect& globalRect);
58 };
59 } // namespace OHOS::Rosen
60 
61 #endif // OHOS_ROSEN_WINDOW_SESSION_COORDINATE_HELPER_H
62