diff --git a/interfaces/kits/ndk/libwm.ndk.json b/interfaces/kits/ndk/libwm.ndk.json index 2389fc61e3..d469131242 100644 --- a/interfaces/kits/ndk/libwm.ndk.json +++ b/interfaces/kits/ndk/libwm.ndk.json @@ -71,6 +71,10 @@ "first_instroduced":"16", "name":"OH_WindowManager_Snapshot" }, + { + "first_instroduced":"16", + "name":"OH_WindowManager_SetWindowTouchable" + }, { "first_instroduced":"16", "name":"OH_WindowManager_SetWindowFocusable" diff --git a/interfaces/kits/ndk/wm/oh_window.h b/interfaces/kits/ndk/wm/oh_window.h index 73a3592a62..e3a9658bf1 100644 --- a/interfaces/kits/ndk/wm/oh_window.h +++ b/interfaces/kits/ndk/wm/oh_window.h @@ -203,6 +203,20 @@ int32_t OH_WindowManager_GetWindowProperties( */ int32_t OH_WindowManager_Snapshot(int32_t windowId, OH_PixelmapNative* pixelMap); +/** + * @brief set window touchable status. + * + * @param windowId windowId when window is created. + * @param touchable window touchable status. + * @return Return the result code. + * {@link OK} the function call is successful. + * {@link WINDOW_MANAGER_ERRORCODE_INVALID_PARAM} parameter error. + * {@link WINDOW_MANAGER_ERRORCODE_STATE_ABNORMALLY} this window state is abnormal. + * {@link WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMALLY} the window manager service works abnormal. + * @since 16 + */ +int32_t OH_WindowManager_SetWindowTouchable(int32_t windowId, bool touchable); + /** * @brief Set focusable property of window. * diff --git a/wm/src/oh_window.cpp b/wm/src/oh_window.cpp index 1a464742ef..56a933611f 100644 --- a/wm/src/oh_window.cpp +++ b/wm/src/oh_window.cpp @@ -439,6 +439,26 @@ int32_t OH_WindowManager_GetWindowProperties( return errCode; } +int32_t OH_WindowManager_SetWindowTouchable(int32_t windowId, bool touchable) +{ + auto eventHandler = GetMainEventHandler(); + if (eventHandler == nullptr) { + TLOGE(WmsLogTag::WMS_EVENT, "eventHandler null, windowId:%{public}d", windowId); + return WindowManager_ErrorCode::SERVICE_ERROR; + } + WindowManager_ErrorCode errCode = WindowManager_ErrorCode::SERVICE_ERROR; + eventHandler->PostSyncTask([windowId, touchable, &errCode, where = __func__] { + auto window = Window::GetWindowWithId(windowId); + if (window == nullptr) { + TLOGNE(WmsLogTag::WMS_EVENT, "%{public}s window is null, windowId:%{public}d", where, windowId); + errCode = WindowManager_ErrorCode::INVAILD_WINDOW_ID; + return; + } + errCode = OH_WINDOW_TO_ERROR_CODE_MAP.at(window->SetTouchable(touchable)); + }, __func__); + return errCode; +} + int32_t OH_WindowManager_SetWindowFocusable(int32_t windowId, bool isFocusable) { auto eventHandler = GetMainEventHandler();