1 /* 2 * Copyright (c) 2021-2022 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_MANAGER_H 17 #define OHOS_ROSEN_WINDOW_MANAGER_H 18 19 #include <memory> 20 #include <refbase.h> 21 #include <vector> 22 #include <iremote_object.h> 23 #include "wm_single_instance.h" 24 #include "wm_common.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 struct SystemBarRegionTint { 29 WindowType type_; 30 SystemBarProperty prop_; 31 Rect region_; SystemBarRegionTintSystemBarRegionTint32 SystemBarRegionTint() : prop_(SystemBarProperty()) {} SystemBarRegionTintSystemBarRegionTint33 SystemBarRegionTint(WindowType type, SystemBarProperty prop, Rect region) 34 : type_(type), prop_(prop), region_(region) {} 35 }; 36 using SystemBarRegionTints = std::vector<SystemBarRegionTint>; 37 38 class FocusChangeInfo : public Parcelable { 39 public: 40 FocusChangeInfo() = default; FocusChangeInfo(uint32_t winId,DisplayId displayId,int32_t pid,int32_t uid,WindowType type,const sptr<IRemoteObject> & abilityToken)41 FocusChangeInfo(uint32_t winId, DisplayId displayId, int32_t pid, int32_t uid, WindowType type, 42 const sptr<IRemoteObject>& abilityToken): windowId_(winId), displayId_(displayId), pid_(pid), uid_(uid), 43 windowType_(type), abilityToken_(abilityToken) {}; 44 ~FocusChangeInfo() = default; 45 46 virtual bool Marshalling(Parcel& parcel) const override; 47 static FocusChangeInfo* Unmarshalling(Parcel& parcel); 48 49 uint32_t windowId_ = INVALID_WINDOW_ID; 50 DisplayId displayId_ = 0; 51 int32_t pid_ = 0; 52 int32_t uid_ = 0; 53 WindowType windowType_ = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW; 54 sptr<IRemoteObject> abilityToken_; 55 }; 56 57 class IFocusChangedListener : public RefBase { 58 public: 59 virtual void OnFocused(const sptr<FocusChangeInfo>& focusChangeInfo) = 0; 60 61 virtual void OnUnfocused(const sptr<FocusChangeInfo>& focusChangeInfo) = 0; 62 }; 63 64 class ISystemBarChangedListener : virtual public RefBase { 65 public: 66 virtual void OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints) = 0; 67 }; 68 69 class WindowVisibilityInfo : public Parcelable { 70 public: 71 WindowVisibilityInfo() = default; WindowVisibilityInfo(uint32_t winId,int32_t pid,int32_t uid,bool visibility)72 WindowVisibilityInfo(uint32_t winId, int32_t pid, int32_t uid, bool visibility) 73 : windowId_(winId), pid_(pid), uid_(uid), isVisible_(visibility) {}; 74 ~WindowVisibilityInfo() = default; 75 76 virtual bool Marshalling(Parcel& parcel) const override; 77 static WindowVisibilityInfo* Unmarshalling(Parcel& parcel); 78 79 uint32_t windowId_ { INVALID_WINDOW_ID }; 80 int32_t pid_ { 0 }; 81 int32_t uid_ { 0 }; 82 bool isVisible_ { false }; 83 }; 84 85 class IVisibilityChangedListener : public RefBase { 86 public: 87 virtual void OnWindowVisibilityChanged(const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfo) = 0; 88 }; 89 90 class WindowInfo : public Parcelable { 91 public: 92 WindowInfo() = default; 93 ~WindowInfo() = default; 94 95 virtual bool Marshalling(Parcel& parcel) const override; 96 static WindowInfo* Unmarshalling(Parcel& parcel); 97 98 int32_t wid_; 99 Rect windowRect_; 100 bool focused_; 101 WindowMode mode_; 102 WindowType type_; 103 }; 104 105 class AccessibilityWindowInfo : public Parcelable { 106 public: 107 AccessibilityWindowInfo() = default; 108 ~AccessibilityWindowInfo() = default; 109 110 virtual bool Marshalling(Parcel& parcel) const override; 111 static AccessibilityWindowInfo* Unmarshalling(Parcel& parcel); 112 113 sptr<WindowInfo> currentWindowInfo_; 114 std::vector<sptr<WindowInfo>> windowList_; 115 116 private: 117 bool VectorMarshalling(Parcel& parcel) const; 118 static void VectorUnmarshalling(Parcel& parcel, AccessibilityWindowInfo* windowInfo); 119 }; 120 class IWindowUpdateListener : public RefBase { 121 public: 122 virtual void OnWindowUpdate(const sptr<AccessibilityWindowInfo>& windowInfo, WindowUpdateType type) = 0; 123 }; 124 125 class WindowManager { 126 WM_DECLARE_SINGLE_INSTANCE_BASE(WindowManager); 127 friend class WindowManagerAgent; 128 public: 129 void RegisterFocusChangedListener(const sptr<IFocusChangedListener>& listener); 130 void UnregisterFocusChangedListener(const sptr<IFocusChangedListener>& listener); 131 void RegisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener); 132 void UnregisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener); 133 void RegisterWindowUpdateListener(const sptr<IWindowUpdateListener>& listener); 134 void UnregisterWindowUpdateListener(const sptr<IWindowUpdateListener>& listener); 135 void RegisterVisibilityChangedListener(const sptr<IVisibilityChangedListener>& listener); 136 void UnregisterVisibilityChangedListener(const sptr<IVisibilityChangedListener>& listener); 137 void MinimizeAllAppWindows(DisplayId displayId); 138 WMError SetWindowLayoutMode(WindowLayoutMode mode, DisplayId displayId); 139 140 private: 141 WindowManager(); 142 ~WindowManager(); 143 class Impl; 144 std::unique_ptr<Impl> pImpl_; 145 146 void UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType, 147 DisplayId displayId, bool focused) const; 148 void UpdateFocusChangeInfo(const sptr<FocusChangeInfo>& focusChangeInfo, bool focused) const; 149 void UpdateSystemBarRegionTints(DisplayId displayId, const SystemBarRegionTints& tints) const; 150 void NotifyAccessibilityWindowInfo(const sptr<AccessibilityWindowInfo>& windowInfo, WindowUpdateType type); 151 void UpdateWindowVisibilityInfo( 152 const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos) const; 153 }; 154 } // namespace Rosen 155 } // namespace OHOS 156 157 #endif // OHOS_ROSEN_WINDOW_MANAGER_H