• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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_SCENE_WS_COMMON_H
17 #define OHOS_ROSEN_WINDOW_SCENE_WS_COMMON_H
18 
19 #include <charconv>
20 #include <inttypes.h>
21 #include <iomanip>
22 #include <map>
23 #include <sstream>
24 #include <string>
25 
26 #include <iremote_broker.h>
27 #include <want.h>
28 #include "pixel_map.h"
29 #include "wm_animation_common.h"
30 
31 namespace OHOS::AAFwk {
32 class AbilityStartSetting;
33 class ProcessOptions;
34 class StartWindowOption;
35 }
36 namespace OHOS::AppExecFwk {
37 struct AbilityInfo;
38 enum class SupportWindowMode;
39 }
40 
41 namespace OHOS::Rosen {
42 class RSTransaction;
43 
44 // Type alias for screen identifier, consistent with ScreenId defined in dm_common.h.
45 using ScreenId = uint64_t;
46 
47 constexpr int32_t ROTATE_ANIMATION_DURATION = 400;
48 constexpr int32_t INVALID_SESSION_ID = 0;
49 constexpr int32_t DEFAULT_REQUEST_FROM_SCB_ID = -1;
50 constexpr int32_t WINDOW_SUPPORT_MODE_MAX_SIZE = 4;
51 constexpr int32_t DEFAULT_SCALE_RATIO = 100;
52 const std::string WINDOW_SCREEN_LOCK_PREFIX = "windowLock_";
53 const std::string VIEW_SCREEN_LOCK_PREFIX = "viewLock_";
54 
55 enum class WSError : int32_t {
56     WS_OK = 0,
57     WS_DO_NOTHING,
58     WS_ERROR_NO_MEM,
59     WS_ERROR_DESTROYED_OBJECT,
60     WS_ERROR_INVALID_WINDOW,
61     WS_ERROR_INVALID_WINDOW_MODE_OR_SIZE,
62     WS_ERROR_INVALID_OPERATION,
63     WS_ERROR_INVALID_PERMISSION,
64     WS_ERROR_NOT_SYSTEM_APP,
65     WS_ERROR_NO_REMOTE_ANIMATION,
66     WS_ERROR_INVALID_DISPLAY,
67     WS_ERROR_INVALID_PARENT,
68     WS_ERROR_OPER_FULLSCREEN_FAILED,
69     WS_ERROR_REPEAT_OPERATION,
70     WS_ERROR_INVALID_SESSION,
71     WS_ERROR_INVALID_CALLING,
72     WS_ERROR_UNCLEARABLE_SESSION,
73     WS_ERROR_FAIL_TO_GET_SNAPSHOT,
74     WS_ERROR_INTERNAL_ERROR,
75     WS_ERROR_NO_UI_CONTENT_ERROR,
76 
77     WS_ERROR_DEVICE_NOT_SUPPORT = 801, // the value do not change.It is defined on all system
78 
79     WS_ERROR_NEED_REPORT_BASE = 1000, // error code > 1000 means need report
80     WS_ERROR_NULLPTR,
81     WS_ERROR_INVALID_TYPE,
82     WS_ERROR_INVALID_PARAM,
83     WS_ERROR_SAMGR,
84     WS_ERROR_IPC_FAILED,
85     WS_ERROR_NEED_REPORT_END,
86     WS_ERROR_START_ABILITY_FAILED,
87     WS_ERROR_SET_SESSION_LABEL_FAILED,
88     WS_ERROR_SET_SESSION_ICON_FAILED,
89     WS_ERROR_INVALID_SESSION_LISTENER,
90     WS_ERROR_START_UI_EXTENSION_ABILITY_FAILED,
91     WS_ERROR_MIN_UI_EXTENSION_ABILITY_FAILED,
92     WS_ERROR_TERMINATE_UI_EXTENSION_ABILITY_FAILED,
93     WS_ERROR_PRE_HANDLE_COLLABORATOR_FAILED,
94     WS_ERROR_START_UI_ABILITY_TIMEOUT,
95 
96     WS_ERROR_EDM_CONTROLLED = 2097215, // enterprise limit
97 };
98 
99 enum class WSErrorCode : int32_t {
100     WS_OK = 0,
101     WS_ERROR_NO_PERMISSION = 201,
102     WS_ERROR_INVALID_PARAM = 401,
103     WS_ERROR_DEVICE_NOT_SUPPORT = 801,
104     WS_ERROR_TIMEOUT = 901,
105     WS_ERROR_NOT_REGISTER_SYNC_CALLBACK = 100011,
106     WS_ERROR_TRANSFER_DATA_FAILED       = 100012,
107     WS_ERROR_REPEAT_OPERATION = 1300001,
108     WS_ERROR_STATE_ABNORMALLY = 1300002,
109     WS_ERROR_SYSTEM_ABNORMALLY = 1300003,
110     WS_ERROR_INVALID_CALLING = 1300004,
111     WS_ERROR_STAGE_ABNORMALLY = 1300005,
112     WS_ERROR_CONTEXT_ABNORMALLY = 1300006,
113 
114     WS_ERROR_EDM_CONTROLLED = 16000013, // enterprise limit
115 };
116 
117 const std::map<WSError, WSErrorCode> WS_JS_TO_ERROR_CODE_MAP {
118     { WSError::WS_OK,                    WSErrorCode::WS_OK },
119     { WSError::WS_DO_NOTHING,            WSErrorCode::WS_ERROR_STATE_ABNORMALLY },
120     { WSError::WS_ERROR_INVALID_SESSION, WSErrorCode::WS_ERROR_STATE_ABNORMALLY },
121     { WSError::WS_ERROR_INVALID_PARAM, WSErrorCode::WS_ERROR_STATE_ABNORMALLY },
122     { WSError::WS_ERROR_IPC_FAILED,      WSErrorCode::WS_ERROR_SYSTEM_ABNORMALLY },
123     { WSError::WS_ERROR_NULLPTR,         WSErrorCode::WS_ERROR_STATE_ABNORMALLY },
124     { WSError::WS_ERROR_EDM_CONTROLLED,  WSErrorCode::WS_ERROR_EDM_CONTROLLED },
125     { WSError::WS_ERROR_INVALID_WINDOW,  WSErrorCode::WS_ERROR_STATE_ABNORMALLY },
126 };
127 
128 enum class SessionState : uint32_t {
129     STATE_DISCONNECT = 0,
130     STATE_CONNECT,
131     STATE_FOREGROUND,
132     STATE_ACTIVE,
133     STATE_INACTIVE,
134     STATE_BACKGROUND,
135     STATE_END,
136 };
137 
138 enum ContinueState {
139     CONTINUESTATE_UNKNOWN = -1,
140     CONTINUESTATE_ACTIVE = 0,
141     CONTINUESTATE_INACTIVE = 1,
142     CONTINUESTATE_MAX
143 };
144 
145 enum class StartMethod : int32_t {
146     START_NORMAL,
147     START_CALL
148 };
149 
150 enum class SingleHandMode : int32_t {
151     LEFT = 0,
152     RIGHT,
153     MIDDLE
154 };
155 
156 /**
157  * @brief collaborator type.
158  */
159 enum CollaboratorType : int32_t {
160     DEFAULT_TYPE = 0,
161     RESERVE_TYPE,
162     OTHERS_TYPE,
163 };
164 
165 enum AncoSceneState: int32_t {
166     DEFAULT_STATE = 0,
167     NOTIFY_START,
168     NOTIFY_CREATE,
169     NOTIFY_LOAD,
170     NOTIFY_UPDATE,
171     NOTIFY_FOREGROUND,
172 };
173 
174 /**
175  * @brief collaborator type.
176  */
177 enum SessionOperationType : int32_t {
178     TYPE_DEFAULT = 0,
179     TYPE_CLEAR,
180 };
181 
182 enum class ManagerState : uint32_t {
183     MANAGER_STATE_SCREEN_LOCKED = 0,
184 };
185 
186 /**
187  * @brief Enumerates picture in picture control status.
188  */
189 enum class WsPiPControlStatus : int32_t {
190     PLAY = 1,
191     PAUSE = 0,
192     OPEN = 1,
193     CLOSE = 0,
194     ENABLED = -2,
195     DISABLED = -3,
196 };
197 
198 /**
199  * @brief Enumerates picture in picture control type.
200  */
201 enum class WsPiPControlType : uint32_t {
202     VIDEO_PLAY_PAUSE = 0,
203     VIDEO_PREVIOUS = 1,
204     VIDEO_NEXT = 2,
205     FAST_FORWARD = 3,
206     FAST_BACKWARD = 4,
207     HANG_UP_BUTTON = 5,
208     MICROPHONE_SWITCH = 6,
209     CAMERA_SWITCH = 7,
210     MUTE_SWITCH = 8,
211     END,
212 };
213 
214 enum class FocusChangeReason {
215     /**
216      * default focus change reason
217      */
218     DEFAULT = 0,
219 
220     /**
221      * focus change for move up
222      */
223     MOVE_UP,
224 
225     /**
226      * focus change for click
227      */
228     CLICK,
229 
230     /**
231      * focus change for foreground
232      */
233     FOREGROUND,
234 
235     /**
236      * focus change for background
237      */
238     BACKGROUND,
239 
240     /**
241      * focus change for split screen.5
242      */
243     SPLIT_SCREEN,
244 
245     /**
246      * focus change for full screen
247      */
248     FULL_SCREEN,
249 
250     /**
251      * focus change for global search
252      */
253     SCB_SESSION_REQUEST,
254 
255     /**
256      * focus change for floating scene
257      */
258     FLOATING_SCENE,
259 
260     /**
261      * focus change for losing focus
262      */
263     SCB_SESSION_REQUEST_UNFOCUS,
264 
265     /**
266      * focus change for client requerst.10
267      */
268     CLIENT_REQUEST,
269 
270     /**
271      * focus change for wind
272      */
273     WIND,
274 
275     /**
276      * focus change for app foreground
277      */
278     APP_FOREGROUND,
279 
280     /**
281      * focus change for app background
282      */
283     APP_BACKGROUND,
284 
285     /**
286      * focus change for recent,Multitasking
287      */
288     RECENT,
289 
290     /**
291      * focus change for inner app.
292      */
293     SCB_START_APP,
294 
295     /**
296      * focus for setting focuable.
297      */
298     FOCUSABLE,
299 
300     /**
301      * select last focused app when requestSessionUnFocus.
302      */
303     LAST_FOCUSED_APP,
304 
305     /**
306      * focus for zOrder pass through VOICE_INTERACTION.
307      */
308     VOICE_INTERACTION,
309 
310     /**
311      * focus change for SA requerst.19
312      */
313     SA_REQUEST,
314 
315     /**
316      * focus on previous window for system keyboard
317      */
318     SYSTEM_KEYBOARD,
319 
320     /**
321      * focus change when pressing alt+tab or dock click
322      */
323     REQUEST_WITH_CHECK_SUB_WINDOW,
324 
325     /**
326      * focus change max.
327      */
328     MAX,
329 };
330 
331 enum class SceneType : uint8_t {
332     DEFAULT = 0,
333     WINDOW_SCENE,
334     SYSTEM_WINDOW_SCENE,
335     TRANSFORM_SCENE,
336     PANEL_SCENE,
337     INPUT_SCENE,
338 };
339 
340 struct SessionViewportConfig {
341     bool isDensityFollowHost_ = false;
342     float density_ = 1.0f; // Indicates the host's density, if following the host, use it, otherwise get it from DMS.
343     uint64_t displayId_ = 0;
344     int32_t orientation_ = 0;
345     uint32_t transform_ = 0;
346 };
347 
348 struct WindowSizeLimits {
349     uint32_t maxWindowWidth = 0;
350     uint32_t minWindowWidth = 0;
351     uint32_t maxWindowHeight = 0;
352     uint32_t minWindowHeight = 0;
353 
354     bool operator==(const WindowSizeLimits& sizeLimits) const
355     {
356         return (maxWindowWidth == sizeLimits.maxWindowWidth && minWindowWidth == sizeLimits.minWindowWidth &&
357             maxWindowHeight == sizeLimits.maxWindowHeight && minWindowHeight == sizeLimits.minWindowHeight);
358     }
359 };
360 
361 enum class StartWindowType : uint32_t {
362     DEFAULT = 0,
363     RETAIN_AND_INVISIBLE,
364     REMOVE_NODE_INVISIBLE,
365 };
366 
367 struct AtomicServiceInfo {
368     std::string appNameInfo_ = "";
369     std::string eyelashRingIcon_ = "";
370     std::string circleIcon_ = "";
371     int32_t resizable_ = 0;
372     std::vector<std::string> deviceTypes_;
373     std::vector<std::string> supportWindowMode_;
374 };
375 
376 struct SessionInfo {
377     std::string bundleName_ = "";
378     std::string moduleName_ = "";
379     std::string abilityName_ = "";
380     int32_t appIndex_ = 0;
381     bool isSystem_ = false;
382     SceneType sceneType_ = SceneType::WINDOW_SCENE;
383     uint32_t windowType_ = 1; // WINDOW_TYPE_APP_MAIN_WINDOW
384     sptr<IRemoteObject> callerToken_ = nullptr;
385     sptr<IRemoteObject> rootToken_ = nullptr;
386     uint64_t screenId_ = -1;
387     bool isPersistentRecover_ = false;
388     bool isFromIcon_ = false;
389     AtomicServiceInfo atomicServiceInfo_;
390 
391     mutable std::shared_ptr<AAFwk::Want> want = nullptr; // want for ability start
392     std::shared_ptr<std::mutex> wantMutex_ = std::make_shared<std::mutex>();
393     std::shared_ptr<AAFwk::Want> closeAbilityWant = nullptr;
394     std::shared_ptr<AAFwk::AbilityStartSetting> startSetting = nullptr;
395     std::shared_ptr<AAFwk::ProcessOptions> processOptions = nullptr;
396     std::shared_ptr<AAFwk::StartWindowOption> startWindowOption = nullptr;
397     mutable std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = nullptr;
398     int32_t resultCode = -1;
399     int32_t requestCode = -1;
400     int32_t errorCode = -1;
401     std::string errorReason = "";
402     int32_t persistentId_ = INVALID_SESSION_ID;
403     int32_t callerPersistentId_ = INVALID_SESSION_ID;
404     std::string callerBundleName_ = "";
405     std::string callerAbilityName_ = "";
406     uint32_t callState_ = 0;
407     uint32_t callingTokenId_ = 0;
408     bool reuse = false;
409     int32_t windowMode = 0;
410     StartMethod startMethod = StartMethod::START_NORMAL;
411     bool lockedState = false;
412     std::string time = "";
413     ContinueState continueState = ContinueState::CONTINUESTATE_ACTIVE;
414     int64_t uiAbilityId_ = 0;
415     int32_t ancoSceneState = 0;
416     bool isClearSession = false;
417     std::string sessionAffinity = "";
418     int32_t collaboratorType_ = CollaboratorType::DEFAULT_TYPE;
419     SessionState sessionState_ = SessionState::STATE_DISCONNECT;
420     uint32_t requestOrientation_ = 0;
421     bool isRotable_ = false;
422     bool isSetPointerAreas_ = false;
423     bool isCastSession_ = false;
424     uint32_t windowInputType_ = 0;
425     std::string continueSessionId_ = "";
426     bool isCalledRightlyByCallerId_ = false;
427     bool fullScreenStart_ = false;
428     bool isAtomicService_ = false;
429     bool isBackTransition_ = false;
430     bool needClearInNotShowRecent_ = false;
431     bool isPcOrPadEnableActivation_ = false;
432     bool canStartAbilityFromBackground_ = false;
433     bool isFoundationCall_ = false;
434     int32_t requestId = 0;
435     std::string specifiedFlag_ = "";
436     bool disableDelegator = false;
437     bool reuseDelegatorWindow = false;
438     bool isAbilityHook_ = false;
439     StartWindowType startWindowType_ = StartWindowType::DEFAULT;
440     bool isSetStartWindowType_ = false;
441     int32_t scenarios = 0;
442 
443     /*
444      * Keyboard
445      */
446     bool isKeyboardWillShowRegistered_ { false };
447     bool isKeyboardWillHideRegistered_ { false };
448     bool isKeyboardDidShowRegistered_ { false };
449     bool isKeyboardDidHideRegistered_ { false };
450 
451     /*
452      * App Use Control
453      */
454     bool isUseControlSession = false; // Indicates whether the session is used for controlling a main session.
455     bool hasPrivacyModeControl = false;
456 
457     /*
458      * UIExtension
459      */
460     int32_t realParentId_ = INVALID_SESSION_ID;
461     uint32_t uiExtensionUsage_ = 0;
462     bool isAsyncModalBinding_ = false;
463     uint32_t parentWindowType_ = 1; // WINDOW_TYPE_APP_MAIN_WINDOW
464     SessionViewportConfig config_;
465 
466     /*
467      * Multi Instance
468      */
469     bool isNewAppInstance_ = false;
470     std::string appInstanceKey_;
471 
472     /*
473      * PC Window
474      */
475     std::vector<AppExecFwk::SupportWindowMode> supportedWindowModes;
476     WindowSizeLimits windowSizeLimits;
477     bool isFollowParentMultiScreenPolicy = false;
478 
479     /*
480      * Window Rotation
481      */
482     int32_t currentRotation_ = 0;
483 
GetWantSafelySessionInfo484     AAFwk::Want GetWantSafely() const
485     {
486         std::lock_guard<std::mutex> lock(*wantMutex_);
487         if (want != nullptr) {
488             return *(want);
489         } else {
490             return AAFwk::Want();
491         }
492     }
493 
SetWantSafelySessionInfo494     void SetWantSafely(const AAFwk::Want& newWant) const
495     {
496         std::lock_guard<std::mutex> lock(*wantMutex_);
497         if (want == nullptr) {
498             want = std::make_shared<AAFwk::Want>();
499         }
500         *want = newWant;
501     }
502 
503     std::shared_ptr<StartAnimationOptions> startAnimationOptions = nullptr;
504     std::shared_ptr<StartAnimationSystemOptions> startAnimationSystemOptions = nullptr;
505 };
506 
507 enum class SessionFlag : uint32_t {
508     SESSION_FLAG_NEED_AVOID = 1,
509     SESSION_FLAG_PARENT_LIMIT = 1 << 1,
510     SESSION_FLAG_SHOW_WHEN_LOCKED = 1 << 2,
511     SESSION_FLAG_FORBID_SPLIT_MOVE = 1 << 3,
512     SESSION_FLAG_WATER_MARK = 1 << 4,
513     SESSION_FLAG_END = 1 << 5,
514 };
515 
516 enum class SizeChangeReason : uint32_t {
517     UNDEFINED = 0,
518     MAXIMIZE,
519     RECOVER,
520     ROTATION,
521     DRAG,
522     DRAG_START,
523     DRAG_END,
524     RESIZE,
525     RESIZE_WITH_ANIMATION,
526     MOVE,
527     MOVE_WITH_ANIMATION,
528     HIDE,
529     TRANSFORM,
530     CUSTOM_ANIMATION_SHOW,
531     FULL_TO_SPLIT,
532     SPLIT_TO_FULL,
533     FULL_TO_FLOATING,
534     FLOATING_TO_FULL,
535     PIP_START,
536     PIP_SHOW,
537     PIP_AUTO_START,
538     PIP_RATIO_CHANGE,
539     PIP_RESTORE,
540     UPDATE_DPI_SYNC,
541     DRAG_MOVE,
542     AVOID_AREA_CHANGE,
543     MAXIMIZE_TO_SPLIT,
544     SPLIT_TO_MAXIMIZE,
545     PAGE_ROTATION,
546     SPLIT_DRAG_START,
547     SPLIT_DRAG,
548     SPLIT_DRAG_END,
549     RESIZE_BY_LIMIT,
550     MAXIMIZE_IN_IMPLICT = 32,
551     RECOVER_IN_IMPLICIT = 33,
552     OCCUPIED_AREA_CHANGE = 34,
553     SCREEN_RELATIVE_POSITION_CHANGE,
554     SNAPSHOT_ROTATION = 37,
555     END,
556 };
557 
IsMoveToOrDragMove(SizeChangeReason reason)558 inline bool IsMoveToOrDragMove(SizeChangeReason reason)
559 {
560     return reason == SizeChangeReason::MOVE || reason == SizeChangeReason::DRAG_MOVE ||
561            reason == SizeChangeReason::MOVE_WITH_ANIMATION;
562 }
563 
564 enum class SessionEvent : uint32_t {
565     EVENT_MAXIMIZE = 100,
566     EVENT_RECOVER,
567     EVENT_MINIMIZE,
568     EVENT_CLOSE,
569     EVENT_START_MOVE,
570     EVENT_END_MOVE,
571     EVENT_MAXIMIZE_FLOATING,
572     EVENT_TERMINATE,
573     EVENT_EXCEPTION,
574     EVENT_SPLIT_PRIMARY,
575     EVENT_SPLIT_SECONDARY,
576     EVENT_DRAG_START,
577     EVENT_DRAG,
578     EVENT_MAXIMIZE_WITHOUT_ANIMATION,
579     EVENT_MAXIMIZE_WATERFALL,
580     EVENT_WATERFALL_TO_MAXIMIZE,
581     EVENT_COMPATIBLE_TO_MAXIMIZE,
582     EVENT_COMPATIBLE_TO_RECOVER,
583     EVENT_END
584 };
585 
586 enum class BrokerStates: uint32_t {
587     BROKER_UNKOWN = 1,
588     BROKER_STARTED = 0,
589     BROKER_NOT_START = -1,
590 };
591 
GreatOrEqual(double left,double right)592 inline bool GreatOrEqual(double left, double right)
593 {
594     constexpr double epsilon = -0.00001f;
595     return (left - right) > epsilon;
596 }
597 
LessOrEqual(double left,double right)598 inline bool LessOrEqual(double left, double right)
599 {
600     constexpr double epsilon = 0.00001f;
601     return (left - right) < epsilon;
602 }
603 
NearEqual(const double left,const double right,const double epsilon)604 inline bool NearEqual(const double left, const double right, const double epsilon)
605 {
606     return (std::fabs(left - right) <= epsilon);
607 }
608 
NearEqual(const float & left,const float & right)609 inline bool NearEqual(const float& left, const float& right)
610 {
611     constexpr double epsilon = 0.001f;
612     return NearEqual(left, right, epsilon);
613 }
614 
NearEqual(const int32_t & left,const int32_t & right)615 inline bool NearEqual(const int32_t& left, const int32_t& right)
616 {
617     return left == right;
618 }
619 
NearEqual(const int32_t & left,const int32_t & right,const int32_t threshold)620 inline bool NearEqual(const int32_t& left, const int32_t& right, const int32_t threshold)
621 {
622     return std::abs(left - right) <= threshold;
623 }
624 
NearZero(const double left)625 inline bool NearZero(const double left)
626 {
627     constexpr double epsilon = 0.001f;
628     return NearEqual(left, 0.0, epsilon);
629 }
630 
631 template<typename T>
632 struct WSRectT {
633     T posX_ = 0;
634     T posY_ = 0;
635     T width_ = 0;
636     T height_ = 0;
637 
638     bool operator==(const WSRectT<T>& a) const
639     {
640         return (NearEqual(posX_, a.posX_) && NearEqual(posY_, a.posY_) &&
641                 NearEqual(width_, a.width_) && NearEqual(height_, a.height_));
642     }
643 
644     bool operator!=(const WSRectT<T>& a) const
645     {
646         return !this->operator==(a);
647     }
648 
isNearEqualWSRectT649     inline bool isNearEqual(const WSRectT<T>& rect, const T threshold) const
650     {
651         return (NearEqual(posX_, rect.posX_, threshold) && NearEqual(posY_, rect.posY_, threshold) &&
652                 NearEqual(width_, rect.width_, threshold) && NearEqual(height_, rect.height_, threshold));
653     }
654 
IsEmptyWSRectT655     bool IsEmpty() const
656     {
657         if (NearZero(posX_) && NearZero(posY_) && NearZero(width_) && NearZero(height_)) {
658             return true;
659         }
660         return false;
661     }
662 
IsInRegionWSRectT663     inline bool IsInRegion(int32_t pointX, int32_t pointY) const
664     {
665         return GreatOrEqual(pointX, posX_) && LessOrEqual(pointX, posX_ + width_) &&
666                GreatOrEqual(pointY, posY_) && LessOrEqual(pointY, posY_ + height_);
667     }
668 
IsOverlapWSRectT669     inline bool IsOverlap(const WSRectT<T>& rect) const
670     {
671         int32_t xStart = std::max(posX_, rect.posX_);
672         int32_t xEnd = std::min(posX_ + static_cast<int32_t>(width_),
673             rect.posX_ + static_cast<int32_t>(rect.width_));
674         int32_t yStart = std::max(posY_, rect.posY_);
675         int32_t yEnd = std::min(posY_ + static_cast<int32_t>(height_),
676             rect.posY_ + static_cast<int32_t>(rect.height_));
677         return (yStart < yEnd) && (xStart < xEnd);
678     }
679 
IsInvalidWSRectT680     inline bool IsInvalid() const
681     {
682         return IsEmpty() || LessOrEqual(width_, 0) || LessOrEqual(height_, 0);
683     }
684 
685     /**
686      * @brief Compute the intersection area with another rectangle.
687      *
688      * @tparam F The result type for intersection area calculation.
689      *           Allows returning higher precision or larger integer to avoid overflow.
690      *           By default, F = T.
691      *
692      * @param other The other rectangle to intersect with.
693      * @return The intersection area as type F.
694      */
695     template<typename F = T>
IntersectionAreaWSRectT696     F IntersectionArea(const WSRectT<T>& other) const
697     {
698         const T left = std::max(posX_, other.posX_);
699         const T top = std::max(posY_, other.posY_);
700         const T right = std::min(posX_ + width_, other.posX_ + other.width_);
701         const T bottom = std::min(posY_ + height_, other.posY_ + other.height_);
702         const T interWidth = std::max(static_cast<T>(0), right - left);
703         const T interHeight = std::max(static_cast<T>(0), bottom - top);
704         return static_cast<F>(interWidth) * static_cast<F>(interHeight);
705     }
706 
707     /**
708      * @brief Returns a string in the format: [posX posY width height]
709      *
710      * @note Optimized for performance:
711      *       - Avoid std::stringstream and other formatting streams.
712      *       - Pre-allocates string capacity to minimize reallocations.
713      *       - Use std::to_chars for fast, allocation-free conversions.
714      *
715      * @return std::string A string representing the rectangle.
716      */
ToStringWSRectT717     std::string ToString() const
718     {
719         std::string result;
720         if constexpr (std::is_integral_v<T>) {
721             result.reserve(49); // 49: 11 digits * 4 + spaces + brackets
722         } else {
723             result.reserve(133); // 133: 32 digits * 4 + spaces + brackets
724         }
725 
726         // Helper: append either value or INF/-INF when overflow occurs
727         auto appendValueOrInf = [&](char* buf, char* ptr, const std::errc ec, T value) {
728             if (ec == std::errc::value_too_large) {
729                 result.append(value < 0 ? "-INF" : "INF");
730             } else {
731                 result.append(buf, ptr);
732             }
733         };
734 
735         // Helper: convert and append value based on type
736         auto appendValue = [&](T value) {
737             if constexpr (std::is_integral_v<T>) {
738                 char buf[11]; // 11: max digits for integer
739                 auto [ptr, ec] = std::to_chars(buf, buf + sizeof(buf), value);
740                 appendValueOrInf(buf, ptr, ec, value);
741             } else {
742                 constexpr int precision = 2;
743                 char buf[32]; // 32: max digits for floating number
744                 auto [ptr, ec] = std::to_chars(buf, buf + sizeof(buf), value, std::chars_format::fixed, precision);
745                 appendValueOrInf(buf, ptr, ec, value);
746             }
747         };
748 
749         result.push_back('[');
750         appendValue(posX_);
751         result.push_back(' ');
752         appendValue(posY_);
753         result.push_back(' ');
754         appendValue(width_);
755         result.push_back(' ');
756         appendValue(height_);
757         result.push_back(']');
758         return result;
759     }
760 
761     static const WSRectT<T> EMPTY_RECT;
762 };
763 
764 template<typename T>
765 inline constexpr WSRectT<T> WSRectT<T>::EMPTY_RECT { 0, 0, 0, 0 };
766 
767 using WSRect = WSRectT<int32_t>;
768 using WSRectF = WSRectT<float>;
769 
770 /**
771  * @struct WSScreenRelativeRect
772  *
773  * @brief Represent a window rectangle defined relative to a specific screen.
774  */
775 struct WSScreenRelativeRect {
776     // The ID of the screen this rectangle is relative to.
777     ScreenId screenId;
778     // The window rectangle relative to the specified screen.
779     WSRect rect;
780 
ToStringWSScreenRelativeRect781     inline std::string ToString() const
782     {
783         std::ostringstream oss;
784         oss << screenId << ", " << rect.ToString();
785         return oss.str();
786     }
787 };
788 
789 struct WindowAnimationInfo {
790     WSRect beginRect { 0, 0, 0, 0 };
791     WSRect endRect { 0, 0, 0, 0 };
792     bool animated { false };
793     uint32_t callingId { 0 };
794     bool isGravityChanged { false };
795 };
796 
797 struct WindowShadowConfig {
798     float offsetX_ = 0.0f;
799     float offsetY_ = 0.0f;
800     float alpha_ = 0.0f;
801     float radius_ = 0.0f;
802     std::string color_ = "#000000";
803 };
804 
805 struct KeyboardSceneAnimationConfig {
806     std::string curveType_;
807     float ctrlX1_ = 0.0f;
808     float ctrlY1_ = 0.0f;
809     float ctrlX2_ = 0.0f;
810     float ctrlY2_ = 0.0f;
811     uint32_t duration_ = 0;
812 };
813 
814 struct WindowAnimationConfig {
815     int32_t duration_ = 0;
816     std::string curveType_ = "easeOut";
817     float ctrlX1_ = 0.2f;
818     float ctrlY1_ = 0.0f;
819     float ctrlX2_ = 0.2f;
820     float ctrlY2_ = 1.0f;
821     float scaleX_ = 0.0f;
822     float scaleY_ = 0.0f;
823     float rotationX_ = 0.0f;
824     float rotationY_ = 0.0f;
825     float rotationZ_ = 0.0f;
826     int32_t angle_ = 0;
827     float translateX_ = 0.0f;
828     float translateY_ = 0.0f;
829     float opacity_ = 0;
830 };
831 
832 struct StartingWindowInfo {
833     uint32_t backgroundColorEarlyVersion_;
834     std::string iconPathEarlyVersion_;
835     bool configFileEnabled_;
836     uint32_t backgroundColor_;
837     std::string iconPath_;
838     std::string illustrationPath_;
839     std::string brandingPath_;
840     std::string backgroundImagePath_;
841     std::string backgroundImageFit_;
842     std::string startWindowType_;
843 };
844 
845 enum class StartWindowResType {
846     AppIcon = 0,
847     Illustration,
848     Branding,
849     BgImage,
850     Count
851 };
852 
853 struct ResourceInfo {
854     std::vector<std::shared_ptr<Media::PixelMap>> pixelMaps;
855     std::vector<int32_t> delayTimes;
856 };
857 
858 struct StartingWindowPageDrawInfo {
859     std::shared_ptr<ResourceInfo> appIcon = nullptr;
860     std::shared_ptr<ResourceInfo> illustration = nullptr;
861     std::shared_ptr<ResourceInfo> bgImage = nullptr;
862     std::shared_ptr<ResourceInfo> branding = nullptr;
863     uint32_t bgColor = 0;
864     std::string startWindowBackgroundImageFit = "";
865 };
866 
867 struct StartingWindowAnimationConfig {
868     bool enabled_ = true;
869     int duration_ = 200;
870     std::string curve_ = "linear";
871     float opacityStart_ = 1;
872     float opacityEnd_ = 0;
873 };
874 
875 struct SystemUIStatusBarConfig {
876     bool showInLandscapeMode_ = false;
877     std::string immersiveStatusBarBgColor_ = "#4c000000";
878     std::string immersiveStatusBarContentColor_ = "#ffffff";
879 };
880 
881 struct StatusBarConfig {
882     bool showHide_ = false;
883     std::string contentColor_;
884     std::string backgroundColor_;
885 };
886 
887 struct WindowImmersive {
888     StatusBarConfig desktopStatusBarConfig_;
889     StatusBarConfig leftRightStatusBarConfig_;
890     StatusBarConfig upDownStatusBarConfig_;
891 };
892 
893 struct AppWindowSceneConfig {
894     float floatCornerRadius_ = 0.0f;
895     std::string multiWindowUIType_ = "HandsetSmartWindow";
896     bool backgroundScreenLock_ = false;
897     std::string rotationMode_ = "windowRotation";
898     WindowShadowConfig focusedShadow_;
899     WindowShadowConfig unfocusedShadow_;
900     WindowShadowConfig focusedShadowDark_;
901     WindowShadowConfig unfocusedShadowDark_;
902     KeyboardSceneAnimationConfig keyboardAnimationIn_;
903     KeyboardSceneAnimationConfig keyboardAnimationOut_;
904     WindowAnimationConfig windowAnimation_;
905     StartingWindowAnimationConfig startingWindowAnimationConfig_;
906     SystemUIStatusBarConfig systemUIStatusBarConfig_;
907     WindowImmersive windowImmersive_;
908 };
909 
910 struct SingleHandCompatibleModeConfig {
911     bool enabled = false;
912     float singleHandScale = 1.0f;
913     float heightChangeRatio = 1.0f;
914     float widthChangeRatio = 1.0f;
915 };
916 
917 struct SingleHandScreenInfo {
918     int32_t scaleRatio = DEFAULT_SCALE_RATIO;
919     int32_t scalePivotX = 0;
920     int32_t scalePivotY = 0;
921     SingleHandMode mode = SingleHandMode::MIDDLE;
922 };
923 
924 struct DeviceScreenConfig {
925     std::string rotationPolicy_ = "11"; // default use phone policy
926     std::string defaultRotationPolicy_ = "1"; // default unspecified policy
927     bool isRightPowerButton_ = true;
928 };
929 
930 struct SceneAnimationConfig {
931     std::shared_ptr<RSTransaction> rsTransaction_ = nullptr;
932     int32_t animationDuration_ = ROTATE_ANIMATION_DURATION;
933 };
934 
935 struct RotateAnimationConfig {
936     int32_t duration_ = ROTATE_ANIMATION_DURATION;
937 };
938 
939 struct SessionEventParam {
940     int32_t pointerX_ = 0;
941     int32_t pointerY_ = 0;
942     int32_t sessionWidth_ = 0;
943     int32_t sessionHeight_ = 0;
944     uint32_t dragResizeType = 0;
945     uint32_t gravity = 0;
946 };
947 
948 struct BackgroundParams {
949     int32_t persistentId = INVALID_SESSION_ID;
950     bool shouldBackToCaller = true;
951     AAFwk::WantParams wantParams {};
952 };
953 
954 struct TransferSessionInfo {
955     int32_t persistentId = -1;
956     int32_t toScreenId = -1;
957     AAFwk::WantParams wantParams {};
958 };
959 
960 /**
961  * @brief Enumerates session gravity.
962  */
963 enum class SessionGravity : uint32_t {
964     SESSION_GRAVITY_FLOAT = 0,
965     SESSION_GRAVITY_BOTTOM,
966     SESSION_GRAVITY_DEFAULT,
967 };
968 
969 /**
970  * @brief TerminateType session terminate type.
971  */
972 enum class TerminateType : uint32_t {
973     CLOSE_AND_KEEP_MULTITASK = 0,
974     CLOSE_AND_CLEAR_MULTITASK,
975     CLOSE_AND_START_CALLER,
976     CLOSE_BY_EXCEPTION,
977 };
978 
979 /**
980  * @brief System animaged scene type.
981  */
982 enum class SystemAnimatedSceneType : uint32_t {
983     SCENE_ENTER_MISSION_CENTER, // Enter the mission center
984     SCENE_EXIT_MISSION_CENTER, // Exit the mission center
985     SCENE_ENTER_TFS_WINDOW, // Three-finger sliding window recovery
986     SCENE_EXIT_TFU_WINDOW, // The three-finger up window disappears
987     SCENE_ENTER_WINDOW_FULL_SCREEN, // Enter the window full screen
988     SCENE_EXIT_WINDOW_FULL_SCREEN, // Exit the window full screen
989     SCENE_ENTER_MAX_WINDOW, // Enter the window maximization state
990     SCENE_EXIT_MAX_WINDOW, // Exit the window maximization state
991     SCENE_ENTER_SPLIT_SCREEN, // Enter the split screen
992     SCENE_EXIT_SPLIT_SCREEN, // Exit the split screen
993     SCENE_ENTER_APP_CENTER, // Enter the app center
994     SCENE_EXIT_APP_CENTER, // Exit the app center
995     SCENE_APPEAR_MISSION_CENTER, // A special case scenario that displays the mission center
996     SCENE_ENTER_WIND_CLEAR, // Enter win+D in clear screen mode
997     SCENE_ENTER_WIND_RECOVER, // Enter win+D in recover mode
998     SCENE_ENTER_RECENTS, // Enter recents
999     SCENE_EXIT_RECENTS, // Exit recent.
1000     SCENE_LOCKSCREEN_TO_LAUNCHER, // Unlock screen.
1001     SCENE_ENTER_MIN_WINDOW, // Enter the window minimization state
1002     SCENE_RECOVER_MIN_WINDOW, // Recover minimized window
1003     SCENE_SNAPSHOT_ROTATION, // Snapshot rotation
1004     SCENE_OTHERS, // 1.Default state 2.The state in which the animation ends
1005 };
1006 
1007 /**
1008  * @brief Session UI parameters
1009  */
1010 struct SessionUIParam {
1011     bool interactive_ { true };
1012     WSRect rect_;
1013     float scaleX_ { 1.0f };
1014     float scaleY_ { 1.0f };
1015     float pivotX_ { 1.0f };
1016     float pivotY_ { 1.0f };
1017     float transX_ { 0.0f }; // global translateX
1018     float transY_ { 0.0f }; // global translateY
1019     uint32_t zOrder_ { 0 };
1020     std::string sessionName_;
1021     bool needSync_ { true };
1022 };
1023 
1024 enum class SessionUIDirtyFlag {
1025     NONE = 0,
1026     VISIBLE = 1,
1027     INTERACTIVE = 1 << 1,
1028     RECT = 1 << 2,
1029     SCALE = 1 << 3,
1030     TOUCH_HOT_AREA = 1 << 4,
1031     Z_ORDER = 1 << 5,
1032     AVOID_AREA = 1 << 6,
1033     DRAG_RECT = 1 << 7,
1034     GLOBAL_RECT = 1 << 8,
1035 };
1036 
1037 enum class SessionPropertyFlag {
1038     NONE = 0,
1039     WINDOW_ID = 1,
1040     BUNDLE_NAME = 1 << 1,
1041     ABILITY_NAME = 1 << 2,
1042     APP_INDEX = 1 << 3,
1043     VISIBILITY_STATE = 1 << 4,
1044     DISPLAY_ID = 1 << 5,
1045     WINDOW_RECT = 1 << 6,
1046     WINDOW_MODE = 1 << 7,
1047     FLOATING_SCALE = 1 << 8,
1048 };
1049 
1050 /**
1051  * @brief State for post-process focus
1052  */
1053 struct PostProcessFocusState {
1054     bool enabled_ { false };
1055     bool isFocused_ { false };
1056     bool byForeground_ { true };
1057     FocusChangeReason reason_ { FocusChangeReason::DEFAULT };
1058 
ResetPostProcessFocusState1059     void Reset()
1060     {
1061         enabled_ = false;
1062         isFocused_ = false;
1063         byForeground_ = true;
1064         reason_ = FocusChangeReason::DEFAULT;
1065     }
1066 };
1067 
1068 /**
1069  * @brief WindowNode for snapshot
1070  */
1071 enum class SnapshotNodeType : uint32_t {
1072     DEFAULT_NODE = 0,
1073     LEASH_NODE,
1074     APP_NODE,
1075 };
1076 
1077 enum class ScreenLockReason {
1078     DEFAULT = 0,
1079 
1080     /*
1081      * Expanded to folded on single pocket
1082      */
1083     EXPAND_TO_FOLD_SINGLE_POCKET,
1084 };
1085 
1086 enum class AsyncTraceTaskId: int32_t {
1087     THROW_SLIP_ANIMATION = 0,
1088 };
1089 
1090 /**
1091  * @brief Recover state
1092  */
1093 enum class RecoverState : uint32_t {
1094     RECOVER_INITIAL = 0,
1095     RECOVER_ENABLE_INPUT,
1096     RECOVER_END,
1097 };
1098 
1099 /**
1100  * @brief Client window recover state
1101  */
1102 enum class WindowRecoverState : uint32_t {
1103     WINDOW_NOT_RECONNECT = 0,
1104     WINDOW_START_RECONNECT,
1105     WINDOW_DOING_RECONNECT,
1106     WINDOW_FINISH_RECONNECT,
1107     WINDOW_RECOVER_STATE_END,
1108 };
1109 
1110 /**
1111  * @brief Server session recover state
1112  */
1113 enum class SessionRecoverState : uint32_t {
1114     SESSION_NOT_RECONNECT = 0,
1115     SESSION_START_RECONNECT,
1116     SESSION_DOING_RECONNECT,
1117     SESSION_FINISH_RECONNECT,
1118     SESSION_RECOVER_STATE_END,
1119 };
1120 } // namespace OHOS::Rosen
1121 #endif // OHOS_ROSEN_WINDOW_SCENE_WS_COMMON_H
1122