From dcadd4e3699469aadbb2f77dd08b74b7c7ff6fe2 Mon Sep 17 00:00:00 2001 From: Xingyu Wu Date: Tue, 15 Jul 2025 14:52:57 +0800 Subject: [PATCH] Add cangjie window function Signed-off-by: Xingyu Wu --- .../cj/display_runtime/cj_display_manager.cpp | 23 +++++- .../cj/display_runtime/cj_display_manager.h | 1 + .../kits/cj/display_runtime/display_ffi.cpp | 6 ++ .../kits/cj/display_runtime/display_ffi.h | 1 + .../display_runtime/display_runtime_mock.cpp | 1 + .../kits/cj/window_runtime/window_ffi.cpp | 75 +++++++++++++++++++ .../kits/cj/window_runtime/window_ffi.h | 7 +- .../kits/cj/window_runtime/window_impl.cpp | 69 +++++++++++++++++ .../kits/cj/window_runtime/window_impl.h | 3 + .../cj/window_runtime/window_listener.cpp | 11 +++ .../kits/cj/window_runtime/window_listener.h | 3 + .../cj/window_runtime/window_manager_impl.cpp | 68 +++++++++++++++++ .../cj/window_runtime/window_manager_impl.h | 3 + .../kits/cj/window_runtime/window_mock.cpp | 6 ++ .../window_register_manager.cpp | 25 ++++++- .../window_runtime/window_register_manager.h | 2 + .../cj/window_runtime/window_stage_impl.cpp | 20 +++++ .../cj/window_runtime/window_stage_impl.h | 1 + .../kits/cj/window_runtime/window_utils.h | 30 ++++++++ 19 files changed, 349 insertions(+), 6 deletions(-) diff --git a/interfaces/kits/cj/display_runtime/cj_display_manager.cpp b/interfaces/kits/cj/display_runtime/cj_display_manager.cpp index 02d30e16dc..bf98f991f8 100644 --- a/interfaces/kits/cj/display_runtime/cj_display_manager.cpp +++ b/interfaces/kits/cj/display_runtime/cj_display_manager.cpp @@ -34,7 +34,7 @@ static void SetDisplayObject(sptr& obj, RetStruct& ret) { auto result = DisplayImpl::CreateDisplayImpl(obj); if (result == nullptr || ret.data == nullptr) { - TLOGE(WmsLogTag::DMS, "[GetDefaultDisplaySync] ERROR Failed to create DisplayImpl."); + TLOGE(WmsLogTag::DMS, "[GetDefault/PrimaryDisplaySync] ERROR Failed to create DisplayImpl."); ret.code = static_cast(DmErrorCode::DM_ERROR_SYSTEM_INNORMAL); return; } @@ -140,6 +140,27 @@ RetStruct CJDisplayManager::GetDefaultDisplaySync() return ret; } +RetStruct CJDisplayManager::GetPrimaryDisplaySync() +{ + RetStruct ret = {.code = static_cast(DmErrorCode::DM_ERROR_SYSTEM_INNORMAL), .len = 0, .data = nullptr}; + sptr display = SingletonContainer::Get().GetPrimaryDisplaySync(); + if (display == nullptr) { + TLOGE(WmsLogTag::DMS, "[GetPrimaryDisplaySync] Get default display is nullptr."); + ret.code = static_cast(DmErrorCode::DM_ERROR_INVALID_SCREEN); + return ret; + } + int64_t* displayImplId = static_cast(malloc(sizeof(int64_t))); + if (displayImplId == nullptr) { + TLOGE(WmsLogTag::DMS, "[GetPrimaryDisplaySync] ERROR Failed to create displayImplId."); + ret.code = static_cast(DmErrorCode::DM_ERROR_INVALID_SCREEN); + return ret; + } + ret.data = displayImplId; + ret.len = 0; + SetDisplayObject(display, ret); + return ret; +} + RetStruct CJDisplayManager::GetAllDisplays() { RetStruct ret = { .code = static_cast(DmErrorCode::DM_ERROR_SYSTEM_INNORMAL), .len = 0, .data = nullptr }; diff --git a/interfaces/kits/cj/display_runtime/cj_display_manager.h b/interfaces/kits/cj/display_runtime/cj_display_manager.h index 94ef1d9e23..d572899443 100644 --- a/interfaces/kits/cj/display_runtime/cj_display_manager.h +++ b/interfaces/kits/cj/display_runtime/cj_display_manager.h @@ -28,6 +28,7 @@ namespace Rosen { class CJDisplayManager { public: static RetStruct GetDefaultDisplaySync(); + static RetStruct GetPrimaryDisplaySync(); static RetStruct GetAllDisplays(); static RetStruct HasPrivateWindow(uint32_t displayId); static bool IsFoldable(); diff --git a/interfaces/kits/cj/display_runtime/display_ffi.cpp b/interfaces/kits/cj/display_runtime/display_ffi.cpp index 4c6f084736..d0b5dcf653 100644 --- a/interfaces/kits/cj/display_runtime/display_ffi.cpp +++ b/interfaces/kits/cj/display_runtime/display_ffi.cpp @@ -33,6 +33,12 @@ RetStruct FfiOHOSGetDefaultDisplaySync() return CJDisplayManager::GetDefaultDisplaySync(); } +RetStruct FfiOHOSGetPrimaryDisplaySync() +{ + TLOGI(WmsLogTag::DMS, "start"); + return CJDisplayManager::GetPrimaryDisplaySync(); +} + RetStruct FfiOHOSGetAllDisplays() { TLOGI(WmsLogTag::DMS, "start"); diff --git a/interfaces/kits/cj/display_runtime/display_ffi.h b/interfaces/kits/cj/display_runtime/display_ffi.h index 196989a391..c92d351196 100644 --- a/interfaces/kits/cj/display_runtime/display_ffi.h +++ b/interfaces/kits/cj/display_runtime/display_ffi.h @@ -21,6 +21,7 @@ extern "C" { FFI_EXPORT RetStruct FfiOHOSGetDefaultDisplaySync(); +FFI_EXPORT RetStruct FfiOHOSGetPrimaryDisplaySync(); FFI_EXPORT RetStruct FfiOHOSGetAllDisplays(); FFI_EXPORT RetStruct FfiOHOSHasPrivateWindow(uint32_t displayId); FFI_EXPORT bool FfiOHOSIsFoldable(); diff --git a/interfaces/kits/cj/display_runtime/display_runtime_mock.cpp b/interfaces/kits/cj/display_runtime/display_runtime_mock.cpp index 523f7c129d..e2375628c6 100644 --- a/interfaces/kits/cj/display_runtime/display_runtime_mock.cpp +++ b/interfaces/kits/cj/display_runtime/display_runtime_mock.cpp @@ -15,6 +15,7 @@ extern "C" { FFI_EXPORT int FfiOHOSGetDefaultDisplaySync = 0; +FFI_EXPORT int FfiOHOSGetPrimaryDisplaySync = 0; FFI_EXPORT int FfiOHOSGetAllDisplays = 0; FFI_EXPORT int FfiOHOSHasPrivateWindow = 0; FFI_EXPORT int FfiOHOSIsFoldable = 0; diff --git a/interfaces/kits/cj/window_runtime/window_ffi.cpp b/interfaces/kits/cj/window_runtime/window_ffi.cpp index 926a346581..5d39cbd758 100644 --- a/interfaces/kits/cj/window_runtime/window_ffi.cpp +++ b/interfaces/kits/cj/window_runtime/window_ffi.cpp @@ -77,6 +77,22 @@ int32_t FfiOHOSShiftAppWindowFocus(int32_t sourceWindowId, int32_t targetWindowI return ret; } +CArrWindowInfo FfiOHOSGetVisibleWindowInfo(int32_t* errCode) +{ + TLOGI(WmsLogTag::WMS_ATTRIBUTE, "GetVisibleWindowInfo start"); + CArrWindowInfo ret = OHOS::Rosen::WindowManagerImpl::GetVisibleWindowInfo(errCode); + TLOGI(WmsLogTag::WMS_ATTRIBUTE, "GetVisibleWindowInfo success"); + return ret; +} + +int32_t FfiOHOSShiftAppWindowPointerEvent(int32_t sourceWindowId, int32_t targetWindowId) +{ + TLOGI(WmsLogTag::WMS_PC, "ShiftAppWindowFocus start"); + int32_t ret = OHOS::Rosen::WindowManagerImpl::ShiftAppWindowPointerEvent(sourceWindowId, targetWindowId); + TLOGI(WmsLogTag::WMS_PC, "ShiftAppWindowFocus success"); + return ret; +} + // window int32_t FfiOHOSWindowHide(int64_t id) { @@ -1135,6 +1151,52 @@ RetDataI64 FfiOHOSCreateSubWindowWithOptions(int64_t id, char* name, return ret; } +CRect FfiOHOSGetGlobalRect(int64_t id, int32_t* errCode) +{ + TLOGI(WmsLogTag::DEFAULT, "GetGlobalRect start"); + CRect ret; + auto instance = FFIData::GetData(id); + if (instance == nullptr) { + *errCode = WM_ERROR_STATE_ABNORMALLY; + return ret; + } + ret = instance->GetGlobalRect(errCode); + TLOGI(WmsLogTag::DEFAULT, "GetGlobalRect success"); + return ret; +} + +int32_t FfiOHOSSetDecorButtonStyle(int64_t id, CDecorButtonStyle decorButtonStyle) +{ + TLOGI(WmsLogTag::DEFAULT, "SetDecorButtonStyle start"); + auto instance = FFIData::GetData(id); + if (instance == nullptr) { + return WM_ERROR_STATE_ABNORMALLY; + } + int32_t ret = instance->SetDecorButtonStyle(decorButtonStyle); + if (ret != 0) { + TLOGE(WmsLogTag::DEFAULT, "SetDecorButtonStyle error %{public}d", ret); + return static_cast(ret); + } + TLOGI(WmsLogTag::DEFAULT, "SetDecorButtonStyle success"); + return ret; +} + +int32_t FfiOHOSStartMoving(int64_t id) +{ + TLOGI(WmsLogTag::DEFAULT, "StartMoving start"); + auto instance = FFIData::GetData(id); + if (instance == nullptr) { + return WM_ERROR_STATE_ABNORMALLY; + } + int32_t ret = instance->StartMoving(); + if (ret != 0) { + TLOGE(WmsLogTag::DEFAULT, "StartMoving error %{public}d", ret); + return static_cast(ret); + } + TLOGI(WmsLogTag::DEFAULT, "StartMoving success"); + return ret; +} + // WindowStage RetDataI64 FfiOHOSBindWindowStage(int64_t windowStageImplPtr) { @@ -1279,6 +1341,19 @@ RetDataI64 FfiOHOSCreateSubWindowWithOptionsStage(int64_t id, const char* name, return ret; } +int32_t FfiOHOSSetWindowRectAutoSave(int64_t id, bool enabled) +{ + TLOGI(WmsLogTag::DEFAULT, "SetWindowRectAutoSave start"); + auto instance = FFIData::GetData(id); + if (instance == nullptr) { + TLOGI(WmsLogTag::DEFAULT, "SetWindowRectAutoSave is nullptr"); + return WM_ERROR_STATE_ABNORMALLY; + } + int32_t ret = instance->SetWindowRectAutoSave(enabled); + TLOGI(WmsLogTag::DEFAULT, "SetWindowRectAutoSave success"); + return ret; +} + } // extern "C" } } diff --git a/interfaces/kits/cj/window_runtime/window_ffi.h b/interfaces/kits/cj/window_runtime/window_ffi.h index 5546bd9d2f..a8255e870a 100644 --- a/interfaces/kits/cj/window_runtime/window_ffi.h +++ b/interfaces/kits/cj/window_runtime/window_ffi.h @@ -32,6 +32,8 @@ extern "C" { FFI_EXPORT int32_t FfiOHOSWindowMinimizeAll(int64_t displayId); FFI_EXPORT RetDataI64 FfiOHOSGetLastWindow(OHOS::AbilityRuntime::Context* ctx); FFI_EXPORT int32_t FfiOHOSShiftAppWindowFocus(int32_t sourceWindowId, int32_t targetWindowId); + FFI_EXPORT CArrWindowInfo FfiOHOSGetVisibleWindowInfo(int32_t* errCode); + FFI_EXPORT int32_t FfiOHOSShiftAppWindowPointerEvent(int32_t sourceWindowId, int32_t targetWindowId); // window FFI_EXPORT int32_t FfiOHOSWindowHide(int64_t id); @@ -119,7 +121,9 @@ extern "C" { FFI_EXPORT int32_t FfiOHOSGetWindowStatus(int64_t id, int32_t* errCode); FFI_EXPORT int32_t FfiOHOSMaximize(int64_t id, int32_t presentation); FFI_EXPORT RetDataI64 FfiOHOSCreateSubWindowWithOptions(int64_t id, char* name, CSubWindowOptions option); - + FFI_EXPORT CRect FfiOHOSGetGlobalRect(int64_t id, int32_t* errCode); + FFI_EXPORT int32_t FfiOHOSSetDecorButtonStyle(int64_t id, CDecorButtonStyle decorButtonStyle); + FFI_EXPORT int32_t FfiOHOSStartMoving(int64_t id); // WindowStage FFI_EXPORT RetDataI64 FfiOHOSBindWindowStage(int64_t windowStageImplPtr); @@ -135,6 +139,7 @@ extern "C" { FFI_EXPORT int32_t FfiOHOSStageOff(int64_t id, int64_t callbackId); FFI_EXPORT RetDataI64 FfiOHOSCreateSubWindowWithOptionsStage(int64_t id, const char* name, const char* title, bool decorEnabled, bool isModal); + FFI_EXPORT int32_t FfiOHOSSetWindowRectAutoSave(int64_t id, bool enabled); } #endif diff --git a/interfaces/kits/cj/window_runtime/window_impl.cpp b/interfaces/kits/cj/window_runtime/window_impl.cpp index bde513ca8a..b9fbabb0de 100644 --- a/interfaces/kits/cj/window_runtime/window_impl.cpp +++ b/interfaces/kits/cj/window_runtime/window_impl.cpp @@ -1656,5 +1656,74 @@ int32_t CJWindowImpl::CreateSubWindowWithOptions(std::string name, windowId = windowImpl->GetID(); return static_cast(WmErrorCode::WM_OK); } + +CRect CJWindowImpl::GetGlobalRect(int32_t* errCode) +{ + CRect cGlobalScaleRect; + if (windowToken_ == nullptr) { + TLOGE(WmsLogTag::WMS_LAYOUT, "windowToken_ is nullptr"); + *errCode = static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return cGlobalScaleRect; + } + Rect globalScaleRect; + WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->GetGlobalScaledRect(globalScaleRect)); + if (ret != WmErrorCode::WM_OK) { + TLOGE(WmsLogTag::WMS_LAYOUT, "GetGlobalRect failed"); + } + *errCode = static_cast(ret); + TLOGI(WmsLogTag::WMS_LAYOUT, "Window [%{public}u, %{public}s] end", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str()); + cGlobalScaleRect.posX = globalScaleRect.posX_; + cGlobalScaleRect.posY = globalScaleRect.posY_; + cGlobalScaleRect.height = globalScaleRect.height_; + cGlobalScaleRect.width = globalScaleRect.width_; + return cGlobalScaleRect; +} + +int32_t CJWindowImpl::SetDecorButtonStyle(CDecorButtonStyle cDecorButtonStyle) +{ + if (windowToken_ == nullptr) { + TLOGE(WmsLogTag::WMS_DECOR, "windowToken_ is nullptr"); + return static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + if (!windowToken_->IsPcOrPadFreeMultiWindowMode()) { + TLOGE(WmsLogTag::WMS_DECOR, "device not support"); + return static_cast(WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT); + } + + DecorButtonStyle decorButtonStyle; + decorButtonStyle.buttonBackgroundCornerRadius = cDecorButtonStyle.buttonBackgroundCornerRadius; + decorButtonStyle.buttonBackgroundSize = cDecorButtonStyle.buttonBackgroundSize; + decorButtonStyle.buttonIconSize = cDecorButtonStyle.buttonIconSize; + decorButtonStyle.closeButtonRightMargin = cDecorButtonStyle.closeButtonRightMargin; + decorButtonStyle.colorMode = cDecorButtonStyle.colorMode; + decorButtonStyle.spacingBetweenButtons = cDecorButtonStyle.spacingBetweenButtons; + + if (!WindowHelper::CheckButtonStyleValid(decorButtonStyle)) { + TLOGE(WmsLogTag::WMS_DECOR, "out of range params"); + return static_cast(WmErrorCode::WM_ERROR_INVALID_PARAM); + } + WMError errCode = windowToken_->SetDecorButtonStyle(decorButtonStyle); + WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(errCode); + if (ret != WmErrorCode::WM_OK) { + TLOGE(WmsLogTag::WMS_DECOR, "SetDecorButtonStyle failed"); + } + return static_cast(ret); +} + +int32_t CJWindowImpl::StartMoving() +{ + if (windowToken_ == nullptr) { + TLOGE(WmsLogTag::WMS_IMMS, "windowToken_ is nullptr"); + return static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + ResWindow result = CheckWindow(); + if (result.ret != 0) { + return result.ret; + } + sptr weakWindow = result.nativeWindow; + WmErrorCode ret = weakWindow->StartMoveWindow(); + return static_cast(ret); +} } } diff --git a/interfaces/kits/cj/window_runtime/window_impl.h b/interfaces/kits/cj/window_runtime/window_impl.h index 044751551e..25c450cd0c 100644 --- a/interfaces/kits/cj/window_runtime/window_impl.h +++ b/interfaces/kits/cj/window_runtime/window_impl.h @@ -141,6 +141,9 @@ public: int32_t Maximize(int32_t presentation); int32_t CreateSubWindowWithOptions(std::string name, int64_t &windowId, CSubWindowOptions option); + CRect GetGlobalRect(int32_t* errCode); + int32_t SetDecorButtonStyle(CDecorButtonStyle cDecorButtonStyle); + int32_t StartMoving(); private: friend class OHOS::FFI::RuntimeType; friend class OHOS::FFI::TypeBase; diff --git a/interfaces/kits/cj/window_runtime/window_listener.cpp b/interfaces/kits/cj/window_runtime/window_listener.cpp index 8795e9ee7a..9b5290041a 100644 --- a/interfaces/kits/cj/window_runtime/window_listener.cpp +++ b/interfaces/kits/cj/window_runtime/window_listener.cpp @@ -302,6 +302,17 @@ void CjWindowListener::OnWaterMarkFlagUpdate(bool showWaterMark) thisListener->CallCjMethod(WATER_MARK_FLAG_CHANGE_CB.c_str(), &waterMarkFlag, sizeof(waterMarkFlag)); } +void CjWindowListener::OnDisplayIdChanged(uint64_t id) +{ + auto thisListener = weakRef_.promote(); + if (thisListener == nullptr) { + return; + } + + uint64_t displayId = id; + thisListener->CallCjMethod(DISPLAY_ID_CHANGE_CB.c_str(), &displayId, sizeof(displayId)); +} + void CjWindowListener::OnWindowVisibilityChangedCallback(const bool isVisible) { auto thisListener = weakRef_.promote(); diff --git a/interfaces/kits/cj/window_runtime/window_listener.h b/interfaces/kits/cj/window_runtime/window_listener.h index 4f029c2dc8..b1fe4955b0 100644 --- a/interfaces/kits/cj/window_runtime/window_listener.h +++ b/interfaces/kits/cj/window_runtime/window_listener.h @@ -40,6 +40,7 @@ const std::string DIALOG_TARGET_TOUCH_CB = "dialogTargetTouch"; const std::string DIALOG_DEATH_RECIPIENT_CB = "dialogDeathRecipient"; const std::string GESTURE_NAVIGATION_ENABLED_CHANGE_CB = "gestureNavigationEnabledChange"; const std::string WATER_MARK_FLAG_CHANGE_CB = "waterMarkFlagChange"; +const std::string DISPLAY_ID_CHANGE_CB = "displayIdChange"; const std::string WINDOW_VISIBILITY_CHANGE_CB = "windowVisibilityChange"; const std::string WINDOW_STATUS_CHANGE_CB = "windowStatusChange"; const std::string WINDOW_TITLE_BUTTON_RECT_CHANGE_CB = "windowTitleButtonRectChange"; @@ -59,6 +60,7 @@ class CjWindowListener : public IWindowChangeListener, public IDialogDeathRecipientListener, public IWaterMarkFlagChangedListener, public IGestureNavigationEnabledChangedListener, + public IDisplayIdChangeListener, public IWindowVisibilityChangedListener, public IWindowTitleButtonRectChangedListener, public IWindowStatusChangeListener, @@ -93,6 +95,7 @@ public: void OnDialogDeathRecipient() const override; void OnGestureNavigationEnabledUpdate(bool enable) override; void OnWaterMarkFlagUpdate(bool showWaterMark) override; + void OnDisplayIdChanged(uint64_t id) override; void OnWindowVisibilityChangedCallback(const bool isVisible) override; void OnWindowStatusChange(WindowStatus status) override; void OnWindowTitleButtonRectChanged(const TitleButtonRect& titleButtonRect) override; diff --git a/interfaces/kits/cj/window_runtime/window_manager_impl.cpp b/interfaces/kits/cj/window_runtime/window_manager_impl.cpp index 5548ba0250..6442aae73c 100644 --- a/interfaces/kits/cj/window_runtime/window_manager_impl.cpp +++ b/interfaces/kits/cj/window_runtime/window_manager_impl.cpp @@ -176,5 +176,73 @@ int32_t WindowManagerImpl::ShiftAppWindowFocus(int32_t sourceWindowId, } return static_cast(ret); } + +CWindowInfo CreateWindowInfoObject(const sptr& info) +{ + CWindowInfo cWindowInfo; + cWindowInfo.rect.posX = info->GetRect().posX_; + cWindowInfo.rect.posY = info->GetRect().posY_; + cWindowInfo.rect.height = info->GetRect().height_; + cWindowInfo.rect.width = info->GetRect().width_; + cWindowInfo.globalDisplayRect.posX = info->GetGlobalDisplayRect().posX_; + cWindowInfo.globalDisplayRect.posY = info->GetGlobalDisplayRect().posY_; + cWindowInfo.globalDisplayRect.height = info->GetGlobalDisplayRect().height_; + cWindowInfo.globalDisplayRect.width = info->GetGlobalDisplayRect().width_; + cWindowInfo.bundleName = info->GetBundleName().c_str(); + cWindowInfo.abilityName = info->GetAbilityName().c_str(); + cWindowInfo.windowId = info->GetWindowId(); + cWindowInfo.windowStatusType = static_cast(info->GetWindowStatus()); + cWindowInfo.isFocused = info->IsFocused(); + return cWindowInfo; +} + +CArrWindowInfo CreateWindowInfoArrayObject(const std::vector>& infos) +{ + CArrWindowInfo arr = { .head = nullptr, .size = 0 }; + arr.size = infos.size(); + arr.head = static_cast(malloc(sizeof(CWindowInfo) * arr.size)); + if (arr.head == nullptr) { + return arr; + } + + uint32_t count = 0; + for (size_t i = 0; i < infos.size(); i++) { + auto info = infos[i]; + auto windowType = info->GetWindowType(); + if (windowType >= WindowType::APP_MAIN_WINDOW_BASE && windowType < WindowType::APP_MAIN_WINDOW_END) { + arr.head[count] = CreateWindowInfoObject(info); + count++; + } + } + return arr; +} + +CArrWindowInfo WindowManagerImpl::GetVisibleWindowInfo(int32_t* errCode) +{ + std::vector> infos; + WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at( + SingletonContainer::Get().GetVisibilityWindowInfo(infos)); + *errCode = static_cast(ret); + if (ret != WmErrorCode::WM_OK) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Get visible window infos failed"); + } + return CreateWindowInfoArrayObject(infos); +} + +int32_t WindowManagerImpl::ShiftAppWindowPointerEvent(int32_t sourceWindowId, + int32_t targetWindowId) +{ + if (sourceWindowId == static_cast(INVALID_WINDOW_ID) || + targetWindowId == static_cast(INVALID_WINDOW_ID)) { + TLOGE(WmsLogTag::DEFAULT, "Invalid sourceWindowId or targetWindowId"); + return static_cast(WmErrorCode::WM_ERROR_INVALID_PARAM); + } + WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(SingletonContainer::Get(). + ShiftAppWindowPointerEvent(sourceWindowId, targetWindowId)); + if (ret != WmErrorCode::WM_OK) { + TLOGE(WmsLogTag::WMS_PC, "Shift application window focus failed"); + } + return static_cast(ret); +} } } diff --git a/interfaces/kits/cj/window_runtime/window_manager_impl.h b/interfaces/kits/cj/window_runtime/window_manager_impl.h index 6a2eb4820d..9ce41c8ebf 100644 --- a/interfaces/kits/cj/window_runtime/window_manager_impl.h +++ b/interfaces/kits/cj/window_runtime/window_manager_impl.h @@ -17,6 +17,7 @@ #define WINDOW_MANAGER_IMPL_H #include "window.h" +#include "window_utils.h" namespace OHOS { namespace Rosen { @@ -37,6 +38,8 @@ public: static int32_t FindWindow(std::string name, int64_t& windowId); static int32_t GetLastWindow(OHOS::AbilityRuntime::Context* ctx, int64_t& id); static int32_t ShiftAppWindowFocus(int32_t sourceWindowId, int32_t targetWindowId); + static CArrWindowInfo GetVisibleWindowInfo(int32_t* errCode); + static int32_t ShiftAppWindowPointerEvent(int32_t sourceWindowId, int32_t targetWindowId); private: }; diff --git a/interfaces/kits/cj/window_runtime/window_mock.cpp b/interfaces/kits/cj/window_runtime/window_mock.cpp index a9b3b18af6..0f43a0d167 100644 --- a/interfaces/kits/cj/window_runtime/window_mock.cpp +++ b/interfaces/kits/cj/window_runtime/window_mock.cpp @@ -114,4 +114,10 @@ FFI_EXPORT int FfiOHOSSetDefaultDensityEnabled = 0; FFI_EXPORT int FfiOHOSStageOn = 0; FFI_EXPORT int FfiOHOSStageOff = 0; FFI_EXPORT int FfiOHOSCreateSubWindowWithOptionsStage = 0; +FFI_EXPORT int FfiOHOSGetVisibleWindowInfo = 0; +FFI_EXPORT int FfiOHOSGetGlobalRect = 0; +FFI_EXPORT int FfiOHOSSetDecorButtonStyle = 0; +FFI_EXPORT int FfiOHOSShiftAppWindowPointerEvent = 0; +FFI_EXPORT int FfiOHOSStartMoving = 0; +FFI_EXPORT int FfiOHOSSetWindowRectAutoSave = 0; } diff --git a/interfaces/kits/cj/window_runtime/window_register_manager.cpp b/interfaces/kits/cj/window_runtime/window_register_manager.cpp index c70a331d44..460703a121 100644 --- a/interfaces/kits/cj/window_runtime/window_register_manager.cpp +++ b/interfaces/kits/cj/window_runtime/window_register_manager.cpp @@ -51,8 +51,7 @@ void CjWindowRegisterManager::InitWindowListeners() {SYSTEM_AVOID_AREA_CHANGE_CB, [this](sptr listener, sptr window, const RegListenerInfo& info) {return this->ProcessSystemAvoidAreaChangeRegister(listener, window, info); } }, - {AVOID_AREA_CHANGE_CB, - [this](sptr listener, sptr window, const RegListenerInfo& info) + {AVOID_AREA_CHANGE_CB, [this](sptr listener, sptr window, const RegListenerInfo& info) {return this->ProcessAvoidAreaChangeRegister(listener, window, info); } }, {LIFECYCLE_EVENT_CB, [this](sptr listener, sptr window, const RegListenerInfo& info) {return this->ProcessLifeCycleEventRegister(listener, window, info); } }, @@ -63,8 +62,7 @@ void CjWindowRegisterManager::InitWindowListeners() {return this->ProcessOccupiedAreaChangeRegister(listener, window, info); } }, {TOUCH_OUTSIDE_CB, [this](sptr listener, sptr window, const RegListenerInfo& info) {return this->ProcessTouchOutsideRegister(listener, window, info); } }, - {SCREENSHOT_EVENT_CB, - [this](sptr listener, sptr window, const RegListenerInfo& info) + {SCREENSHOT_EVENT_CB, [this](sptr listener, sptr window, const RegListenerInfo& info) {return this->ProcessScreenshotRegister(listener, window, info); } }, {DIALOG_TARGET_TOUCH_CB, [this](sptr listener, sptr window, const RegListenerInfo& info) @@ -78,6 +76,8 @@ void CjWindowRegisterManager::InitWindowListeners() {WINDOW_TITLE_BUTTON_RECT_CHANGE_CB, [this](sptr listener, sptr window, const RegListenerInfo& info) {return this->ProcessWindowTitleButtonRectChangeRegister(listener, window, info); } }, + {DISPLAY_ID_CHANGE_CB, [this](sptr listener, sptr window, const RegListenerInfo& info) + {return this->ProcessDisplayIdChangeRegister(listener, window, info); } }, {WINDOW_VISIBILITY_CHANGE_CB, [this](sptr listener, sptr window, const RegListenerInfo& info) {return this->ProcessWindowVisibilityChangeRegister(listener, window, info); } }, @@ -285,6 +285,23 @@ WmErrorCode CjWindowRegisterManager::ProcessWindowTitleButtonRectChangeRegister( return ret; } +WmErrorCode CjWindowRegisterManager::ProcessDisplayIdChangeRegister( + sptr listener, sptr window, const RegListenerInfo& info) +{ + if (window == nullptr) { + TLOGE(WmsLogTag::DEFAULT, "[WindowRegister] window is nullptr"); + return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; + } + sptr thisListener(listener); + WmErrorCode ret; + if (info.isRegister) { + ret = WM_JS_TO_ERROR_CODE_MAP.at(window->RegisterDisplayIdChangeListener(thisListener)); + } else { + ret = WM_JS_TO_ERROR_CODE_MAP.at(window->UnregisterDisplayIdChangeListener(thisListener)); + } + return ret; +} + WmErrorCode CjWindowRegisterManager::ProcessWindowVisibilityChangeRegister( sptr listener, sptr window, const RegListenerInfo& info) { diff --git a/interfaces/kits/cj/window_runtime/window_register_manager.h b/interfaces/kits/cj/window_runtime/window_register_manager.h index 007d53f53d..4bc09800ea 100644 --- a/interfaces/kits/cj/window_runtime/window_register_manager.h +++ b/interfaces/kits/cj/window_runtime/window_register_manager.h @@ -79,6 +79,8 @@ private: sptr window, const RegListenerInfo& info); WmErrorCode ProcessWaterMarkFlagChangeRegister(sptr listener, sptr window, const RegListenerInfo& info); + WmErrorCode ProcessDisplayIdChangeRegister(sptr listener, sptr window, + const RegListenerInfo& info); WmErrorCode ProcessWindowVisibilityChangeRegister(sptr listener, sptr window, const RegListenerInfo& info); WmErrorCode ProcessWindowStatusChangeRegister(sptr listener, sptr window, diff --git a/interfaces/kits/cj/window_runtime/window_stage_impl.cpp b/interfaces/kits/cj/window_runtime/window_stage_impl.cpp index 442b033de2..f3ab9f0cf8 100644 --- a/interfaces/kits/cj/window_runtime/window_stage_impl.cpp +++ b/interfaces/kits/cj/window_runtime/window_stage_impl.cpp @@ -291,6 +291,26 @@ int32_t CJWindowStageImpl::CreateSubWindowWithOptions(int64_t &windowId, return static_cast(WmErrorCode::WM_OK); } +int32_t CJWindowStageImpl::SetWindowRectAutoSave(bool enabled) +{ + auto windowScene = windowScene_.lock(); + if (windowScene == nullptr) { + TLOGE(WmsLogTag::WMS_LAYOUT_PC, "windowScene is null"); + return static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + auto window = windowScene->GetMainWindow(); + if (window == nullptr) { + TLOGE(WmsLogTag::WMS_LAYOUT_PC, "Window is null"); + return static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->SetWindowRectAutoSave(enabled)); + if (ret != WmErrorCode::WM_OK) { + TLOGE(WmsLogTag::WMS_LAYOUT_PC, "Enable recover position failed"); + return static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + return static_cast(ret); +} + extern "C" { FFI_EXPORT int64_t OHOS_CreateCJWindowStage(const std::shared_ptr& windowScene) { diff --git a/interfaces/kits/cj/window_runtime/window_stage_impl.h b/interfaces/kits/cj/window_runtime/window_stage_impl.h index f88a202b8d..4fcb92eb98 100644 --- a/interfaces/kits/cj/window_runtime/window_stage_impl.h +++ b/interfaces/kits/cj/window_runtime/window_stage_impl.h @@ -39,6 +39,7 @@ public: int32_t OffEvent(int64_t funcId); int32_t CreateSubWindowWithOptions(int64_t& windowId, const std::string& name, const std::string& title, bool decorEnabled, bool isModal); + int32_t SetWindowRectAutoSave(bool enabled); private: std::weak_ptr windowScene_; std::unique_ptr registerManager_ = nullptr; diff --git a/interfaces/kits/cj/window_runtime/window_utils.h b/interfaces/kits/cj/window_runtime/window_utils.h index 871db50fdb..f02fd9b912 100644 --- a/interfaces/kits/cj/window_runtime/window_utils.h +++ b/interfaces/kits/cj/window_runtime/window_utils.h @@ -33,6 +33,12 @@ struct SystemBarPropertyFlag { }; constexpr int32_t RGB_LENGTH = 6; +constexpr int32_t DEFAULT_COLOR_MODE = -1; +constexpr uint32_t DEFAULT_SPACING_BETWEEN_BUTTONS = 12; +constexpr uint32_t DEFAULT_CLOSE_BUTTON_RIGHT_MARGINS = 28; +constexpr uint32_t DEFAULT_BUTTON_BACKGROUND_SIZE = 20; +constexpr uint32_t DEFAULT_BUTTON_ICON_SIZE = 20; +constexpr uint32_t DEFAULT_BUTTON_BACKGROUND_CORNER_RADIUS = 4; extern "C" { struct RetStruct { @@ -48,6 +54,30 @@ struct CRect { uint32_t height; }; +struct CWindowInfo { + CRect rect; + CRect globalDisplayRect; + const char* bundleName; + const char* abilityName; + uint32_t windowId; + int32_t windowStatusType; + bool isFocused; +}; + +struct CArrWindowInfo { + CWindowInfo* head; + int64_t size; +}; + +struct CDecorButtonStyle { + int32_t colorMode = DEFAULT_COLOR_MODE; + uint32_t spacingBetweenButtons = DEFAULT_SPACING_BETWEEN_BUTTONS; + uint32_t closeButtonRightMargin = DEFAULT_CLOSE_BUTTON_RIGHT_MARGINS; + uint32_t buttonBackgroundSize = DEFAULT_BUTTON_BACKGROUND_SIZE; + uint32_t buttonIconSize = DEFAULT_BUTTON_ICON_SIZE; + uint32_t buttonBackgroundCornerRadius = DEFAULT_BUTTON_BACKGROUND_CORNER_RADIUS; +}; + struct CWindowProperties { CRect windowRect; CRect drawableRect; -- Gitee