1 /*
2  * Copyright (c) 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 OHOS_ROSEN_WINDOW_SCENE_SESSION_UTILS_H
17 #define OHOS_ROSEN_WINDOW_SCENE_SESSION_UTILS_H
18 
19 #include "wm_common_inner.h"
20 
21 namespace OHOS::Rosen {
22 namespace SessionUtils {
23 constexpr const char* SESSION_NAME_MARK_HEAD = "#";
24 constexpr const char* SESSION_NAME_SEPARATOR = ":";
25 
ToLayoutWidth(const int32_t winWidth,float vpr)26 inline float ToLayoutWidth(const int32_t winWidth, float vpr)
27 {
28     return winWidth - 2 * WINDOW_FRAME_WIDTH * vpr; // 2: left and right edge
29 }
30 
ToLayoutHeight(const int32_t winHeight,float vpr)31 inline float ToLayoutHeight(const int32_t winHeight, float vpr)
32 {
33     return winHeight - (WINDOW_FRAME_WIDTH + WINDOW_TITLE_BAR_HEIGHT) * vpr;
34 }
35 
ToWinWidth(const int32_t layoutWidth,float vpr)36 inline float ToWinWidth(const int32_t layoutWidth, float vpr)
37 {
38     return layoutWidth + 2 * WINDOW_FRAME_WIDTH * vpr; // 2: left and right edge
39 }
40 
ToWinHeight(const int32_t layoutHeight,float vpr)41 inline float ToWinHeight(const int32_t layoutHeight, float vpr)
42 {
43     return layoutHeight + (WINDOW_FRAME_WIDTH + WINDOW_TITLE_BAR_HEIGHT) * vpr;
44 }
45 
CalcFloatWindowRectLimits(const WindowLimits & limits,uint32_t maxFloatingWindowSize,float vpr,int32_t & minWidth,int32_t & maxWidth,int32_t & minHeight,int32_t & maxHeight)46 inline void CalcFloatWindowRectLimits(const WindowLimits& limits, uint32_t maxFloatingWindowSize, float vpr,
47     int32_t& minWidth, int32_t& maxWidth, int32_t& minHeight, int32_t& maxHeight)
48 {
49     minWidth = limits.minWidth_;
50     maxWidth = (limits.maxWidth_ == 0 || limits.maxWidth_ >= INT32_MAX) ? INT32_MAX : limits.maxWidth_;
51     minHeight = limits.minHeight_;
52     maxHeight = (limits.maxHeight_ == 0 || limits.maxHeight_ >= INT32_MAX) ? INT32_MAX : limits.maxHeight_;
53     minWidth = std::max(minWidth, static_cast<int32_t>(MIN_FLOATING_WIDTH * vpr));
54     maxWidth = std::min(maxWidth, static_cast<int32_t>(maxFloatingWindowSize * vpr));
55     minHeight = std::max(minHeight, static_cast<int32_t>(MIN_FLOATING_HEIGHT * vpr));
56     maxHeight = std::min(maxHeight, static_cast<int32_t>(maxFloatingWindowSize * vpr));
57 }
58 
59 inline std::string ConvertSessionName(const std::string& bundleName, const std::string& name,
60     const std::string& moduleName, const int32_t appIndex = 0)
61 {
62     std::string strName;
63     if (appIndex == 0) {
64         strName = SESSION_NAME_MARK_HEAD + bundleName + SESSION_NAME_SEPARATOR + moduleName +
65             SESSION_NAME_SEPARATOR + name;
66     } else {
67         strName = SESSION_NAME_MARK_HEAD + bundleName + SESSION_NAME_SEPARATOR + std::to_string(appIndex) +
68             SESSION_NAME_SEPARATOR + moduleName + SESSION_NAME_SEPARATOR + name;
69     }
70 
71     return strName;
72 }
73 } // namespace SessionUtils
74 } // namespace OHOS::Rosen
75 #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_UTILS_H
76