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 OHOS_WINDOW_UTILS_H
17 #define OHOS_WINDOW_UTILS_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <map>
22 #include <string>
23 #include "wm_common.h"
24 
25 #define FFI_EXPORT __attribute__((visibility("default")))
26 
27 struct SystemBarPropertyFlag {
28     bool enableFlag;
29     bool backgroundColorFlag;
30     bool contentColorFlag;
SystemBarPropertyFlagSystemBarPropertyFlag31     SystemBarPropertyFlag() : enableFlag(false),
32         backgroundColorFlag(false), contentColorFlag(false) {}
33 };
34 
35 constexpr int32_t RGB_LENGTH = 6;
36 
37 extern "C" {
38 struct RetStruct {
39     int32_t code;
40     int64_t len;
41     void* data;
42 };
43 
44 struct CRect {
45     int32_t posX;
46     int32_t posY;
47     uint32_t width;
48     uint32_t height;
49 };
50 
51 struct CWindowProperties {
52     CRect windowRect;
53     CRect drawableRect;
54     uint32_t type;
55     bool isFullScreen;
56     bool isLayoutFullScreen;
57     bool focusable;
58     bool touchable;
59     float brightness;
60     bool isKeepScreenOn;
61     bool isPrivacyMode;
62     bool isRoundCorner;
63     bool isTransparent;
64     uint32_t id;
65 };
66 
67 struct WindowRotate {
68     double x;
69     double y;
70     double z;
71     double pivotX;
72     double pivotY;
73 };
74 
75 struct CJBarProperties {
76     const char* statusBarColor;
77     bool isStatusBarLightIcon;
78     const char* statusBarContentColor;
79     const char* navigationBarColor;
80     bool isNavigationBarLightIcon;
81     const char* navigationBarContentColor;
82 };
83 }
84 
85 namespace OHOS {
86 namespace Rosen {
87 const int32_t WINDOW_SUCCESS = 0;
88 
89 enum class ApiWindowType : uint32_t {
90     TYPE_BASE,
91     TYPE_APP = TYPE_BASE,
92     TYPE_SYSTEM_ALERT,
93     TYPE_INPUT_METHOD,
94     TYPE_STATUS_BAR,
95     TYPE_PANEL,
96     TYPE_KEYGUARD,
97     TYPE_VOLUME_OVERLAY,
98     TYPE_NAVIGATION_BAR,
99     TYPE_FLOAT,
100     TYPE_WALLPAPER,
101     TYPE_DESKTOP,
102     TYPE_LAUNCHER_RECENT,
103     TYPE_LAUNCHER_DOCK,
104     TYPE_VOICE_INTERACTION,
105     TYPE_POINTER,
106     TYPE_FLOAT_CAMERA,
107     TYPE_DIALOG,
108     TYPE_SCREENSHOT,
109     TYPE_SYSTEM_TOAST,
110     TYPE_DIVIDER,
111     TYPE_GLOBAL_SEARCH,
112     TYPE_END
113 };
114 
115 const std::map<ApiWindowType, WindowType> CJ_TO_NATIVE_WINDOW_TYPE_MAP {
116     { ApiWindowType::TYPE_APP,                 WindowType::WINDOW_TYPE_APP_SUB_WINDOW      },
117     { ApiWindowType::TYPE_DIALOG,              WindowType::WINDOW_TYPE_DIALOG              },
118     { ApiWindowType::TYPE_SYSTEM_ALERT,        WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW },
119     { ApiWindowType::TYPE_INPUT_METHOD,        WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT  },
120     { ApiWindowType::TYPE_STATUS_BAR,          WindowType::WINDOW_TYPE_STATUS_BAR          },
121     { ApiWindowType::TYPE_PANEL,               WindowType::WINDOW_TYPE_PANEL               },
122     { ApiWindowType::TYPE_KEYGUARD,            WindowType::WINDOW_TYPE_KEYGUARD            },
123     { ApiWindowType::TYPE_VOLUME_OVERLAY,      WindowType::WINDOW_TYPE_VOLUME_OVERLAY      },
124     { ApiWindowType::TYPE_NAVIGATION_BAR,      WindowType::WINDOW_TYPE_NAVIGATION_BAR      },
125     { ApiWindowType::TYPE_FLOAT,               WindowType::WINDOW_TYPE_FLOAT               },
126     { ApiWindowType::TYPE_FLOAT_CAMERA,        WindowType::WINDOW_TYPE_FLOAT_CAMERA        },
127     { ApiWindowType::TYPE_WALLPAPER,           WindowType::WINDOW_TYPE_WALLPAPER           },
128     { ApiWindowType::TYPE_DESKTOP,             WindowType::WINDOW_TYPE_DESKTOP             },
129     { ApiWindowType::TYPE_LAUNCHER_RECENT,     WindowType::WINDOW_TYPE_LAUNCHER_RECENT     },
130     { ApiWindowType::TYPE_LAUNCHER_DOCK,       WindowType::WINDOW_TYPE_LAUNCHER_DOCK       },
131     { ApiWindowType::TYPE_VOICE_INTERACTION,   WindowType::WINDOW_TYPE_VOICE_INTERACTION   },
132     { ApiWindowType::TYPE_POINTER,             WindowType::WINDOW_TYPE_POINTER             },
133     { ApiWindowType::TYPE_SCREENSHOT,          WindowType::WINDOW_TYPE_SCREENSHOT          },
134     { ApiWindowType::TYPE_SYSTEM_TOAST,        WindowType::WINDOW_TYPE_SYSTEM_TOAST        },
135     { ApiWindowType::TYPE_DIVIDER,             WindowType::WINDOW_TYPE_DOCK_SLICE          },
136     { ApiWindowType::TYPE_GLOBAL_SEARCH,       WindowType::WINDOW_TYPE_GLOBAL_SEARCH       },
137 };
138 
139 enum class ApiWindowMode : uint32_t {
140     UNDEFINED = 1,
141     FULLSCREEN,
142     PRIMARY,
143     SECONDARY,
144     FLOATING,
145     MODE_END = FLOATING
146 };
147 
148 const std::map<ApiWindowMode, WindowMode> CJ_TO_NATIVE_WINDOW_MODE_MAP {
149     {ApiWindowMode::UNDEFINED,  WindowMode::WINDOW_MODE_UNDEFINED       },
150     {ApiWindowMode::FULLSCREEN, WindowMode::WINDOW_MODE_FULLSCREEN      },
151     {ApiWindowMode::PRIMARY,    WindowMode::WINDOW_MODE_SPLIT_PRIMARY   },
152     {ApiWindowMode::SECONDARY,  WindowMode::WINDOW_MODE_SPLIT_SECONDARY },
153     {ApiWindowMode::FLOATING,   WindowMode::WINDOW_MODE_FLOATING        },
154 };
155 
156 const std::map<WindowType, ApiWindowType> CJ_TO_WINDOW_TYPE_MAP {
157     { WindowType::WINDOW_TYPE_APP_SUB_WINDOW,      ApiWindowType::TYPE_APP               },
158     { WindowType::WINDOW_TYPE_DIALOG,              ApiWindowType::TYPE_DIALOG            },
159     { WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, ApiWindowType::TYPE_SYSTEM_ALERT      },
160     { WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT,  ApiWindowType::TYPE_INPUT_METHOD      },
161     { WindowType::WINDOW_TYPE_STATUS_BAR,          ApiWindowType::TYPE_STATUS_BAR        },
162     { WindowType::WINDOW_TYPE_PANEL,               ApiWindowType::TYPE_PANEL             },
163     { WindowType::WINDOW_TYPE_KEYGUARD,            ApiWindowType::TYPE_KEYGUARD          },
164     { WindowType::WINDOW_TYPE_VOLUME_OVERLAY,      ApiWindowType::TYPE_VOLUME_OVERLAY    },
165     { WindowType::WINDOW_TYPE_NAVIGATION_BAR,      ApiWindowType::TYPE_NAVIGATION_BAR    },
166     { WindowType::WINDOW_TYPE_FLOAT,               ApiWindowType::TYPE_FLOAT             },
167     { WindowType::WINDOW_TYPE_FLOAT_CAMERA,        ApiWindowType::TYPE_FLOAT_CAMERA      },
168     { WindowType::WINDOW_TYPE_WALLPAPER,           ApiWindowType::TYPE_WALLPAPER         },
169     { WindowType::WINDOW_TYPE_DESKTOP,             ApiWindowType::TYPE_DESKTOP           },
170     { WindowType::WINDOW_TYPE_LAUNCHER_RECENT,     ApiWindowType::TYPE_LAUNCHER_RECENT   },
171     { WindowType::WINDOW_TYPE_LAUNCHER_DOCK,       ApiWindowType::TYPE_LAUNCHER_DOCK     },
172     { WindowType::WINDOW_TYPE_VOICE_INTERACTION,   ApiWindowType::TYPE_VOICE_INTERACTION },
173     { WindowType::WINDOW_TYPE_POINTER,             ApiWindowType::TYPE_POINTER           },
174     { WindowType::WINDOW_TYPE_SCREENSHOT,          ApiWindowType::TYPE_SCREENSHOT        },
175     { WindowType::WINDOW_TYPE_SYSTEM_TOAST,        ApiWindowType::TYPE_SYSTEM_TOAST      },
176     { WindowType::WINDOW_TYPE_DOCK_SLICE,          ApiWindowType::TYPE_DIVIDER           },
177     { WindowType::WINDOW_TYPE_GLOBAL_SEARCH,       ApiWindowType::TYPE_GLOBAL_SEARCH     },
178 };
179 }
180 }
181 
182 #endif
183