!12268 焦点接口SetFocusable新增ndk接口

Merge pull request !12268 from 胡晗/SetFocusable_ndk
This commit is contained in:
openharmony_ci 2025-01-21 02:42:45 +00:00 committed by Gitee
commit 765b28642f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 38 additions and 0 deletions

View File

@ -70,5 +70,9 @@
{
"first_instroduced":"16",
"name":"OH_WindowManager_Snapshot"
},
{
"first_instroduced":"16",
"name":"OH_WindowManager_SetWindowFocusable"
}
]

View File

@ -203,6 +203,20 @@ int32_t OH_WindowManager_GetWindowProperties(
*/
int32_t OH_WindowManager_Snapshot(int32_t windowId, OH_PixelmapNative* pixelMap);
/**
* @brief Set focusable property of window.
*
* @param windowId WindowId when window is created.
* @param isFocusable Window can be focused or not.
* @return Returns 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 abnormally.
* @since 16
*/
int32_t OH_WindowManager_SetWindowFocusable(int32_t windowId, bool isFocusable);
#ifdef __cplusplus
}
#endif

View File

@ -437,4 +437,24 @@ int32_t OH_WindowManager_GetWindowProperties(
TransformedToWindowManagerRect(drawableRect, windowProperties->drawableRect);
}, __func__);
return errCode;
}
int32_t OH_WindowManager_SetWindowFocusable(int32_t windowId, bool isFocusable)
{
auto eventHandler = GetMainEventHandler();
if (eventHandler == nullptr) {
TLOGE(WmsLogTag::WMS_FOCUS, "eventHandler is null, windowId:%{public}d", windowId);
return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMALLY;
}
WindowManager_ErrorCode errCode = WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMALLY;
eventHandler->PostSyncTask([windowId, isFocusable, &errCode, where = __func__] {
auto window = Window::GetWindowWithId(windowId);
if (window == nullptr) {
TLOGNE(WmsLogTag::WMS_FOCUS, "%{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->SetFocusable(isFocusable));
}, __func__);
return errCode;
}