1 /* 2 * Copyright (c) 2021 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 FRAMEWORKS_WM_INCLUDE_WINDOW_MANAGER_SERVER_H 17 #define FRAMEWORKS_WM_INCLUDE_WINDOW_MANAGER_SERVER_H 18 19 #include <queue> 20 21 #include <promise.h> 22 #include <refbase.h> 23 #include <window_manager_type.h> 24 #include <wms-client-protocol.h> 25 26 #include "singleton_delegator.h" 27 #include "wayland_service.h" 28 #include "wl_surface.h" 29 30 namespace OHOS { 31 struct WMSWindowInfo { 32 GSError wret; 33 int32_t wid; 34 int32_t x; 35 int32_t y; 36 uint32_t width; 37 uint32_t height; 38 }; 39 40 class WindowManagerServer : public RefBase { 41 public: 42 static sptr<WindowManagerServer> GetInstance(); 43 44 MOCKABLE void Init(); 45 MOCKABLE void Deinit(); 46 47 MOCKABLE sptr<Promise<struct WMSWindowInfo>> CreateWindow( 48 const sptr<WlSurface> &wlSurface, int32_t did, WindowType type); 49 50 virtual void RegisterWindowSizeChange(WindowSizeChangeFunc func); 51 virtual void RegisterSplitModeChange(SplitStatusChangeFunc func); 52 53 private: 54 WindowManagerServer() = default; 55 MOCKABLE ~WindowManagerServer() = default; 56 static inline sptr<WindowManagerServer> instance = nullptr; 57 static inline SingletonDelegator<WindowManagerServer> delegator; 58 59 static void OnAppear(const GetServiceFunc get, const std::string &iname, uint32_t ver); 60 static inline struct wms *wms = nullptr; 61 62 static void OnWindowChange(void *, struct wms *, 63 uint32_t status, uint32_t wid, int32_t x, int32_t y, int32_t width, int32_t height); 64 static void OnWindowSizeChange(void *, struct wms *, int32_t width, int32_t height); 65 static void OnSplitStatusChange(void *, struct wms *, uint32_t status); 66 67 static inline std::queue<sptr<Promise<struct WMSWindowInfo>>> promiseQueue; 68 static inline WindowSizeChangeFunc onWindowSizeChange; 69 static inline SplitStatusChangeFunc onSplitModeChange; 70 }; 71 } // namespace OHOS 72 73 #endif // FRAMEWORKS_WM_INCLUDE_WINDOW_MANAGER_SERVER_H 74