From 5cad5ed815f4833eb4c2dc5d5997f9194a0b3a72 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Tue, 22 Jul 2025 20:31:29 +0800 Subject: [PATCH 01/29] =?UTF-8?q?inputConsumer=20arkts=20idl=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- .../ohos.multimodalInput.inputConsumer.taihe | 12 +++- ...hos.multimodalInput.inputConsumer.impl.cpp | 67 +++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/frameworks/ets/input_consumer/idl/ohos.multimodalInput.inputConsumer.taihe b/frameworks/ets/input_consumer/idl/ohos.multimodalInput.inputConsumer.taihe index 3e7fe827d5..a9602d98f8 100644 --- a/frameworks/ets/input_consumer/idl/ohos.multimodalInput.inputConsumer.taihe +++ b/frameworks/ets/input_consumer/idl/ohos.multimodalInput.inputConsumer.taihe @@ -46,6 +46,10 @@ struct InfraredFrequency { min: i32; } +enum ShieldMode: i32 { + FACTORY_MODE = 0 +} + @!sts_inject(""" function on(type: 'key', keyOptions: KeyOptions, callback: (info: KeyOptions) => void) { return onKey(keyOptions, callback, callback); @@ -77,4 +81,10 @@ function offKey(keyOptions: KeyOptions, opq: Optional); function onHotkeyChange(hotkeyOptions: HotkeyOptions, f: (info: HotkeyOptions) => void, opq: Opaque); function offHotkeyChange(hotkeyOptions: HotkeyOptions, opq: Optional); function onKeyPressed(options: KeyPressedConfig, f: (info: KeyEvent) => void, opq: Opaque); -function offKeyPressed(opq: Optional); \ No newline at end of file +function offKeyPressed(opq: Optional); + +function SetShieldStatusSync(shieldMode: ShieldMode, isShield: bool): void; +function GetShieldStatusSync(shieldMode: ShieldMode): bool; + +@gen_promise("getAllSystemHotkeys") +function GetAllSystemHotkeysSync(): Array; \ No newline at end of file diff --git a/frameworks/ets/input_consumer/src/ohos.multimodalInput.inputConsumer.impl.cpp b/frameworks/ets/input_consumer/src/ohos.multimodalInput.inputConsumer.impl.cpp index bf61616d73..c631fae2ab 100644 --- a/frameworks/ets/input_consumer/src/ohos.multimodalInput.inputConsumer.impl.cpp +++ b/frameworks/ets/input_consumer/src/ohos.multimodalInput.inputConsumer.impl.cpp @@ -891,6 +891,70 @@ void offKeyPressed(optional_view opq) UnsubscribeKeyMonitors(); } } + +void SetShieldStatusSync(::ohos::multimodalInput::inputConsumer::ShieldMode shieldMode, bool isShield) +{ + OHOS::MMI::SHIELD_MODE mode = static_cast(shieldMode.get_value()); + if (mode < FACTORY_MODE || mode > OOBE_MODE) { + MMI_HILOGE("Undefined shield mode"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "Shield mode does not exist"); + return; + } + int32_t ret = InputManager::GetInstance()->SetShieldStatus(shieldMode, isShield); + int32_t errorCode = std::abs(ret); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } else if (errorCode == COMMON_PERMISSION_CHECK_ERROR) { + MMI_HILOGE("Shield api need ohos.permission.INPUT_CONTROL_DISPATCHING"); + taihe::set_business_error(COMMON_PERMISSION_CHECK_ERROR, "Shield api need ohos.permission.INPUT_CONTROL_DISPATCHING"); + } else { + MMI_HILOGE("Dispatch control failed"); + } +} + +bool GetShieldStatusSync(::ohos::multimodalInput::inputConsumer::ShieldMode shieldMode) +{ + bool isShield { false }; + OHOS::MMI::SHIELD_MODE mode = static_cast(shieldMode.get_value()); + if (mode < FACTORY_MODE || mode > OOBE_MODE) { + MMI_HILOGE("Undefined shield mode"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "Shield mode does not exist"); + return isShield; + } + + auto ret = InputManager::GetInstance()->GetShieldStatus(shieldMode, isShield); + int32_t errorCode = std::abs(ret); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + return false; + } else if (errorCode == COMMON_PERMISSION_CHECK_ERROR) { + MMI_HILOGE("Shield api need ohos.permission.INPUT_CONTROL_DISPATCHING"); + taihe::set_business_error(COMMON_PERMISSION_CHECK_ERROR, "Shield api need ohos.permission.INPUT_CONTROL_DISPATCHING"); + return false; + } else { + MMI_HILOGE("Dispatch control failed"); + } + return true; +} + +::taihe::array<::ohos::multimodalInput::inputConsumer::HotkeyOptions> GetAllSystemHotkeysSync() +{ + std::vector> keyOptions; + std::vector<::ohos::multimodalInput::inputConsumer::HotkeyOptions> result; + int32_t count = 0; + auto ret = InputManager::GetInstance()->GetAllSystemHotkeys(keyOptions, count); + if (ret != RET_OK) { + taihe::set_business_error(ret, "GetAllSystemHotkeysSync failed"); + } + for (auto &iter : keyOptions) { + auto tmpOpts = ConverTaiheHotkeyOptions(std::move(iter)); + result.emplace_back(tmpOpts); + } + return ::taihe::array<::ohos::multimodalInput::inputConsumer::HotkeyOptions>(taihe::copy_data_t{}, + result.data(), result.size()); +} } // namespace // Since these macros are auto-generate, lint will cause false positive. @@ -901,4 +965,7 @@ TH_EXPORT_CPP_API_onHotkeyChange(onHotkeyChange); TH_EXPORT_CPP_API_offHotkeyChange(offHotkeyChange); TH_EXPORT_CPP_API_onKeyPressed(onKeyPressed); TH_EXPORT_CPP_API_offKeyPressed(offKeyPressed); +TH_EXPORT_CPP_API_SetShieldStatusSync(SetShieldStatusSync); +TH_EXPORT_CPP_API_GetShieldStatusSync(GetShieldStatusSync); +TH_EXPORT_CPP_API_GetAllSystemHotkeysSync(GetAllSystemHotkeysSync); // NOLINTEND \ No newline at end of file -- Gitee From 62c3be1dc88f9ab997f45c59d1cf56f7520c1742 Mon Sep 17 00:00:00 2001 From: KangPeng Date: Wed, 23 Jul 2025 10:27:20 +0800 Subject: [PATCH 02/29] =?UTF-8?q?ztw=20input=5Fmonitor=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: KangPeng --- frameworks/ets/input_monitor/BUILD.gn | 10 ++ .../input_monitor/common/include/ani_common.h | 71 ++++++++ .../input_monitor/common/src/ani_common.cpp | 156 +++++++++++++++++ .../ohos.multimodalInput.inputMonitor.taihe | 158 +++++++++++++++++- .../include/ani_input_monitor_manager.h | 45 +++++ .../src/ani_input_monitor_manager.cpp | 73 ++++++++ 6 files changed, 512 insertions(+), 1 deletion(-) create mode 100644 frameworks/ets/input_monitor/common/include/ani_common.h create mode 100644 frameworks/ets/input_monitor/common/src/ani_common.cpp create mode 100644 frameworks/ets/input_monitor/include/ani_input_monitor_manager.h create mode 100644 frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp diff --git a/frameworks/ets/input_monitor/BUILD.gn b/frameworks/ets/input_monitor/BUILD.gn index 36974c2a89..2e06524b90 100644 --- a/frameworks/ets/input_monitor/BUILD.gn +++ b/frameworks/ets/input_monitor/BUILD.gn @@ -18,6 +18,11 @@ copy_taihe_idl("input_monitor_taihe") { deps = [ "${mmi_path}/frameworks/ets/mouse_event:mouse_event_taihe", "${mmi_path}/frameworks/ets/touch_event:touch_event_taihe", + "${mmi_path}/frameworks/ets/short_key:short_key_taihe", + "${mmi_path}/frameworks/ets/key_code:key_code_taihe", + "${mmi_path}/frameworks/ets/input_event:input_event_taihe", + "${mmi_path}/frameworks/ets/gesture_event:gesture_event_taihe", + "${mmi_path}/frameworks/ets/key_event:key_event_taihe", ] } config("inputMonitor_config") { @@ -27,6 +32,8 @@ config("inputMonitor_config") { "${mmi_path}/interfaces/native/innerkits/proxy/include", "${mmi_path}/service/permission_helper/include", "${mmi_path}/util/common/include", + "${mmi_path}/frameworks/ets/input_monitor/common/include", + "${mmi_path}/frameworks/ets/input_monitor/include" ] } subsystem_name = "multimodalinput" @@ -49,8 +56,11 @@ taihe_shared_library("InputMonitor") { "${mmi_path}:coverage_flags", ":inputMonitor_config", ] + sources += [ + "${mmi_path}/frameworks/ets/input_monitor/common/src/ani_common.cpp", "src/ani_constructor.cpp", + "src/ani_input_monitor_manager.cpp", "src/ohos.multimodalInput.inputMonitor.impl.cpp", ] deps = [ diff --git a/frameworks/ets/input_monitor/common/include/ani_common.h b/frameworks/ets/input_monitor/common/include/ani_common.h new file mode 100644 index 0000000000..999e537c6c --- /dev/null +++ b/frameworks/ets/input_monitor/common/include/ani_common.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANI_INPUT_TAIHE_INPUT_MONITOR_COMMON_H +#define ANI_INPUT_TAIHE_INPUT_MONITOR_COMMON_H + +#include "ohos.multimodalInput.inputMonitor.proj.hpp" +#include "ohos.multimodalInput.mouseEvent.proj.hpp" +#include "ohos.multimodalInput.gestureEvent.proj.hpp" +#include "ohos.multimodalInput.touchEvent.proj.hpp" +#include "taihe/runtime.hpp" + +#include "pointer_event.h" + +namespace OHOS { +namespace MMI { +using TaiheMouseEvent = ohos::multimodalInput::mouseEvent::MouseEvent; +using TaihePinchEvent = ohos::multimodalInput::gestureEvent::Pinch; +using TaiheTouchEvent = ohos::multimodalInput::touchEvent::TouchEvent; +using TaiheTouchEventArray = taihe::array; +using TaiheTouch = ohos::multimodalInput::touchEvent::Touch; +using TaiheTouchAction = ohos::multimodalInput::touchEvent::Action; +using TaiheInputEvent = ohos::multimodalInput::inputEvent::InputEvent; +using TaiheSourceType = ohos::multimodalInput::touchEvent::SourceType; +using TaiheFixedMode = ohos::multimodalInput::touchEvent::FixedMode; +using TaiheToolType = ohos::multimodalInput::touchEvent::ToolType; +/* +using callbackType = std::variant, + taihe::callback, + taihe::callback, taihe::callback>; +*/ +class TaiheConverter { +public: + static TaiheTouchEvent TouchEventToTaihe(const PointerEvent &pointerEvent); + static TaiheInputEvent InputEventToTaihe(const InputEvent &inputEvent); + static TaiheTouchAction TouchActionToTaihe(int32_t action); + static TaiheSourceType SourceTypeToTaihe(int32_t sourceType); + static TaiheFixedMode FixedModeToTaihe(PointerEvent::FixedMode fixedMode); + static TaiheTouch TouchToTaihe(const PointerEvent::PointerItem &item); +}; +/* +struct CallbackObject { + CallbackObject(callbackType cb, ani_ref ref) : callback(cb), ref(ref) + { + } + void Release() + { + taihe::env_guard guard; + if (auto *env = guard.get_env()) { + env->GlobalReference_Delete(ref); + } + } + callbackType callback; + ani_ref ref; +}; +*/ +} // namespace MMI +} // namespace OHOS +#endif // ANI_INPUT_TAIHE_INPUT_MONITOR_COMMON_H \ No newline at end of file diff --git a/frameworks/ets/input_monitor/common/src/ani_common.cpp b/frameworks/ets/input_monitor/common/src/ani_common.cpp new file mode 100644 index 0000000000..cedb571444 --- /dev/null +++ b/frameworks/ets/input_monitor/common/src/ani_common.cpp @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ani_common.h" +#define RET_ERR -1 +namespace OHOS { +namespace MMI { +TaiheTouchEvent TaiheConverter::TouchEventToTaihe(const PointerEvent &pointerEvent) +{ + TaiheTouchEvent result {.action = TaiheTouchAction::key_t::CANCEL, + .touch = TaiheTouch {.toolType = TaiheToolType::key_t::FINGER}, + .sourceType = TaiheSourceType::key_t::TOUCH_SCREEN, + //result.fixedMode = TaiheFixedMode::key_t::NONE, + }; + result.base = InputEventToTaihe(pointerEvent); + result.action = TouchActionToTaihe(pointerEvent.GetPointerAction()); + // 这个需要更新新代码 ---touchEvent taihe定义 + // result.isInject = pointerEventItem->HasFlag(InputEvent::EVENT_FLAG_SIMULATE); + std::vector vecTouches; + for (auto item : pointerEvent.GetPointerIds()) { + PointerEvent::PointerItem pointerItem; + if (!pointerEvent.GetPointerItem(item, pointerItem)) { + // ztw MMI_HILOGE("Get pointer item failed"); + return result; + } + if (pointerItem.GetPointerId() == pointerEvent.GetPointerId()) { + result.touch = TouchToTaihe(pointerItem); + } + vecTouches.push_back(TouchToTaihe(pointerItem)); + } + result.touches = taihe::array(vecTouches); + result.sourceType = SourceTypeToTaihe(pointerEvent.GetSourceType()) ; + result.fixedMode = taihe::optional(std::in_place_t{}, FixedModeToTaihe(pointerEvent.GetFixedMode())); + return result; +} + +TaiheInputEvent TaiheConverter::InputEventToTaihe(const InputEvent &inputEvent) +{ + TaiheInputEvent result{}; + result.id = inputEvent.GetId(); + result.deviceId = inputEvent.GetDeviceId(); + result.actionTime = inputEvent.GetActionTime(); + result.screenId = inputEvent.GetTargetDisplayId(); + result.windowId = inputEvent.GetTargetWindowId(); + return result; +} + +TaiheTouchAction TaiheConverter::TouchActionToTaihe(int32_t action) { + switch (action) { + case PointerEvent::POINTER_ACTION_CANCEL: { + return TaiheTouchAction::key_t::CANCEL; + } + case PointerEvent::POINTER_ACTION_DOWN: { + return TaiheTouchAction::key_t::DOWN; + } + case PointerEvent::POINTER_ACTION_MOVE: { + return TaiheTouchAction::key_t::MOVE; + } + case PointerEvent::POINTER_ACTION_UP: { + return TaiheTouchAction::key_t::UP; + } + // ztw 代码中没有定义 + // case PointerEvent::POINTER_ACTION_PULL_DOWN: { + // return TaiheTouchAction::key_t::PULL_DOWN; + // } + // case PointerEvent::POINTER_ACTION_PULL_MOVE: { + // return TaiheTouchAction::key_t::PULL_MOVE; + // } + // case PointerEvent::POINTER_ACTION_PULL_UP: { + // return TaiheTouchAction::key_t::PULL_UP; + // } + default: { + return TaiheTouchAction(TaiheTouchAction::key_t::CANCEL); + } + } +} + +TaiheSourceType TaiheConverter::SourceTypeToTaihe(int32_t sourceType) { + switch (sourceType) { + case PointerEvent::SOURCE_TYPE_TOUCHSCREEN: { + return TaiheSourceType::key_t::TOUCH_SCREEN; + } + case PointerEvent::SOURCE_TYPE_TOUCHPAD: { + return TaiheSourceType::key_t::TOUCH_PAD; + } + // ztw 代码中少实现 + // case PointerEvent::SOURCE_TYPE_PEN: { + // return TaiheTouchAction::key_t::PEN; + // } + default: { + return TaiheSourceType(TaiheSourceType::key_t::TOUCH_SCREEN); + } + } +} + +TaiheFixedMode TaiheConverter::FixedModeToTaihe(PointerEvent::FixedMode fixedMode) +{ + switch (fixedMode) { + case PointerEvent::SOURCE_TYPE_TOUCHSCREEN: { + return TaiheFixedMode::key_t::NONE; + } + case PointerEvent::SOURCE_TYPE_TOUCHPAD: { + return TaiheFixedMode::key_t::AUTO; + } + // ztw 代码中少实现 + // case PointerEvent::SOURCE_TYPE_TOUCHPAD: { + // return TaiheTouchAction::key_t::PEN; + // } + default: { + return TaiheFixedMode(TaiheFixedMode::key_t::AUTO); + } +} +} + +TaiheTouch TaiheConverter::TouchToTaihe(const PointerEvent::PointerItem &item) +{ + TaiheTouch obj{.toolType = TaiheToolType::key_t::FINGER}; + obj.id = item.GetPointerId(); + obj.pressedTime = item.GetDownTime(); + obj.screenX = item.GetDisplayX(); + obj.screenY = item.GetDisplayY(); + // ztw taihe 中没有定义 + // obj.globalX = static_cast(item.GetGlobalX()); + // obj.globalY = static_cast(item.GetGlobalY()); + obj.windowX = item.GetWindowX(); + obj.windowY = item.GetWindowY(); + obj.pressure = item.GetPressure(); + obj.width = item.GetWidth(); + obj.height = item.GetHeight(); + obj.tiltX = item.GetTiltX(); + obj.tiltY = item.GetTiltY(); + obj.toolX = item.GetToolDisplayX(); + obj.toolY = item.GetToolDisplayY(); + obj.toolWidth = item.GetToolWidth(); + obj.toolHeight = item.GetToolHeight(); + obj.rawX = item.GetRawDx(); + obj.rawY = item.GetRawDy(); + obj.toolType.from_value(item.GetToolType()); + obj.fixedDisplayX = taihe::optional(std::in_place_t{}, item.GetFixedDisplayX()); + obj.fixedDisplayY = taihe::optional(std::in_place_t{}, item.GetFixedDisplayY()); + return obj; +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/input_monitor/idl/ohos.multimodalInput.inputMonitor.taihe b/frameworks/ets/input_monitor/idl/ohos.multimodalInput.inputMonitor.taihe index b99983d27f..2d666de166 100644 --- a/frameworks/ets/input_monitor/idl/ohos.multimodalInput.inputMonitor.taihe +++ b/frameworks/ets/input_monitor/idl/ohos.multimodalInput.inputMonitor.taihe @@ -16,10 +16,166 @@ @!namespace("@ohos.multimodalInput.inputMonitor", "inputMonitor") from ohos.multimodalInput.touchEvent use TouchEvent; from ohos.multimodalInput.mouseEvent use MouseEvent; +from ohos.multimodalInput.gestureEvent use Rotate, Pinch, ThreeFingersSwipe, FourFingersSwipe, SwipeInward; +from ohos.multimodalInput.gestureEvent use ThreeFingersTap, TouchGestureEvent; +from ohos.multimodalInput.shortKey use FingerprintEvent; +from ohos.multimodalInput.keyEvent use KeyEvent; +from ohos.multimodalInput.keyCode use KeyCode; +// from ohos.display use Rect; + + +@!sts_inject_into_module(" + import { TouchEvent } from './@ohos.multimodalInput.touchEvent'; + import { MouseEvent } from './@ohos.multimodalInput.mouseEvent'; + import { Rotate } from './@ohos.multimodalInput.gestureEvent'; + import { Pinch } from './@ohos.multimodalInput.gestureEvent'; + import { ThreeFingersSwipe } from './@ohos.multimodalInput.gestureEvent'; + import { FourFingersSwipe } from './@ohos.multimodalInput.gestureEvent'; + import { SwipeInward } from './@ohos.multimodalInput.gestureEvent'; + import { ThreeFingersTap } from './@ohos.multimodalInput.gestureEvent'; + import { TouchGestureEvent } from './@ohos.multimodalInput.gestureEvent'; + import { ThreeFingersTap, } from './@ohos.multimodalInput.gestureEvent'; + import { FingerprintEvent } from './@ohos.multimodalInput.shortKey'; + import { KeyEvent } from './@ohos.multimodalInput.keyEvent'; + import { KeyCode } from './@ohos.multimodalInput.keyCode'; +") +/* +@!sts_inject(""" +import type display.Rect from '@ohos.display'; +""") */ + + @!sts_inject(""" static { loadLibrary("InputMonitor.z") } """) struct TouchEventReceiver { filter: (touchEvent: TouchEvent) => bool; -} \ No newline at end of file +} + +@gen_promise("queryTouchEvents") +function QueryTouchEventsSync(count: i32) : Array; + +@!sts_inject(""" + type InputOnTypeCallback = 'mouse' | 'pinch' | 'threeFingersSwipe' | 'fourFingersSwipe' + | 'threeFingersTap' |'fingerprint' | 'swipeInward'; + type InputOnTypeCallbackByFingers = 'pinch' | 'rotate' | 'touchscreenSwipe' | 'touchscreenPinch'; + + function on (type: 'touch', receiver: TouchEventReceiver): void { + return onTouch(receiver); + } + + function on (type: InputOnTypeCallback, receiver: Object): void { + switch(type) { + case 'mouse': return onMouse(receiver as (info: MouseEvent) => void, receiver); + case 'pinch': return onPinch(receiver as (info: Pinch) => void, receiver); + case 'threeFingersSwipe': return onThreeFingersSwipe(receiver as (info: ThreeFingersSwipe) => void , receiver); + case 'fourFingersSwipe': return onFourFingersSwipe(receiver as (info: FourFingersSwipe) => void, receiver); + case 'threeFingersTap': return onThreeFingersTap(receiver as (info: ThreeFingersTap) => void, receiver); + case 'fingerprint': return onFingerprint(receiver as (info: FingerprintEvent) => void, receiver); + case 'swipeInward': return onSwipeInward(receiver as (info: SwipeInward) => void, receiver); + } + } + + function on (type: InputOnTypeCallbackByFingers, fingers: int, receiver: Object): void { + switch(type) { + case 'pinch' : return onPinchByNumber(fingers, receiver as (info: Pinch) => void, receiver); + case 'rotate': return onRotateByNumber(fingers, receiver as (info: Rotate) => void, receiver); + case 'touchscreenSwipe': return onTouchscreenSwipeByNumber(fingers, receiver as (info: TouchGestureEvent) => void, receiver); + case 'touchscreenPinch': return onTouchscreenPinch(fingers, receiver as (info: TouchGestureEvent) => void, receiver); + } + } + + function on(type: 'keyPressed', keys: Array, receiver: (info: KeyEvent) => void): void { + return onKeyPressed(keys, receiver, receiver); + } + + + /* 存在外仓引用 + function on(type: 'mouse', rect: Array, receiver: (info: MouseEvent) => void): void { + return onMouseForDisplayRect(rect, receiver, receiver); + } */ + + + function off(type: 'touch', receiver?: TouchEventReceiver): void { + return offTouch(receiver); + } + + function off (type: InputOnTypeCallback|'keyPressed', receiver?: Object): void { + switch(type) { + case 'mouse': offMouse(receiver); + case 'pinch': return offPinch(receiver); + case 'threeFingersSwipe': return offThreeFingersSwipe(receiver); + case 'fourFingersSwipe': return offFourFingersSwipe(receiver); + case 'threeFingersTap': return offThreeFingersTap(receiver); + case 'fingerprint': return offFingerprint(receiver); + case 'swipeInward': return offSwipeInward(receiver); + case 'keyPressed': return offKeyPressed(receiver); + } + } + + function off (type: InputOnTypeCallbackByFingers, fingers: int, receiver: Object): void { + switch(type) { + case 'pinch' : return offPinchByNumber(fingers, receiver); + case 'rotate': return offRotateByNumber(fingers, receiver); + case 'touchscreenSwipe': return offTouchscreenSwipe(fingers, receiver); + case 'touchscreenPinch': return offTouchscreenPinch(fingers, receiver); + } + } +""") + +function onTouch(receiver: TouchEventReceiver): void; + +function onMouse(receiver: (info: MouseEvent) => void, opq: Opaque): void; + +// function onMouseForDisplayRect(rect: Array, receiver: (info: MouseEvent) => void, opq: Opaque): void; + +function onPinch(receiver: (info: Pinch) => void, opq: Opaque): void; + +function onPinchByNumber(fingers: i32, receiver: (info: Pinch) => void, opq: Opaque): void; + +function onRotateByNumber(fingers: i32, receiver: (info: Rotate) => void, opq: Opaque): void; + +function onThreeFingersSwipe(receiver: (info: ThreeFingersSwipe) => void, opq: Opaque): void; + +function onFourFingersSwipe(receiver: (info: FourFingersSwipe) => void, opq: Opaque): void; + +function onThreeFingersTap(receiver: (info: ThreeFingersTap) => void, opq: Opaque): void; + +function onFingerprint(receiver: (info: FingerprintEvent) => void, opq: Opaque): void; + +function onSwipeInward(receiver: (info: SwipeInward) => void, opq: Opaque): void; + +function onTouchscreenSwipeByNumber(fingers: i32, receiver: (info: TouchGestureEvent) => void, opq: Opaque): void; + +function onTouchscreenPinch(fingers: i32, receiver: (info: TouchGestureEvent) => void, opq: Opaque): void; + +function onKeyPressed(keys: Array, receiver: (info: KeyEvent) => void, opq: Opaque): void; + + +function offTouch(receiver: Optional): void; + +function offMouse(receiver: Optional): void; + +function offPinch(receiver: Optional): void; + +function offPinchByNumber(fingers: i32, receiver: Optional): void; + +function offRotateByNumber(fingers: i32, receiver: Optional): void; + +function offThreeFingersSwipe(receiver: Optional): void; + +function offFourFingersSwipe(receiver: Optional): void; + +function offThreeFingersTap(receiver: Optional): void; + +function offFingerprint(receiver: Optional): void; + +function offSwipeInward(receiver: Optional): void; + +function offTouchscreenSwipe(fingers: i32, receiver: Optional): void; + +function offTouchscreenPinch(fingers: i32, receiver: Optional): void; + +function offKeyPressed(receiver: Optional): void; + diff --git a/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h b/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h new file mode 100644 index 0000000000..59cd999a81 --- /dev/null +++ b/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANI_INPUT_MONITOR_MANAGER_H +#define ANI_INPUT_MONITOR_MANAGER_H + +#include +#include + +#include "ani_common.h" +#include "nocopyable.h" + +namespace OHOS { +namespace MMI { +class AniInputMonitorManager final { +public: + static AniInputMonitorManager& GetInstance(); + DISALLOW_COPY_AND_MOVE(AniInputMonitorManager); + ~AniInputMonitorManager() = default; + + TaiheTouchEventArray QueryTouchEvents(int32_t count); +private: + AniInputMonitorManager() = default; +// private: +// int32_t nextId_ { 0 }; +// std::mutex mutex_; +// std::mutex envMutex_; +// +}; +#define ANI_INPUT_MONITOR_MGR AniInputMonitorManager::GetInstance() +} // namespace MMI +} // namespace OHOS +#endif // JS_INPUT_MONITOR_MANAGER_H diff --git a/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp b/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp new file mode 100644 index 0000000000..d80412008d --- /dev/null +++ b/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ani_input_monitor_manager.h" + +#include "ani_common.h" +#include "define_multimodal.h" +#include "input_manager.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "AniInputMonitorManager" + +namespace OHOS { +namespace MMI { +// namespace { +// //constexpr int32_t MONITOR_REGISTER_EXCEED_MAX { 4100001 }; +// } // namespace +// static const std::vector supportedKeyCodes = { +// KeyEvent::KEYCODE_POWER, +// KeyEvent::KEYCODE_META_LEFT, +// KeyEvent::KEYCODE_VOLUME_UP, +// KeyEvent::KEYCODE_VOLUME_DOWN, +// KeyEvent::KEYCODE_META_RIGHT +// }; + +AniInputMonitorManager& AniInputMonitorManager::GetInstance() +{ + static AniInputMonitorManager instance; + return instance; +} + +TaiheTouchEventArray AniInputMonitorManager::QueryTouchEvents(int32_t count) +{ + CALL_DEBUG_ENTER; + std::vector> touchEventList; + TaiheTouchEventArray result{}; + int32_t ret = InputManager::GetInstance()->QueryPointerRecord(count, touchEventList); + if (ret < 0) { + if (ret == ERROR_NO_PERMISSION) { + taihe::set_business_error(-ret, "Permission denied.!"); + return result; + } + return result; + } + if (ret == ERROR_NOT_SYSAPI) { + taihe::set_business_error(ret, "Permission denied, non-system application called system api.!"); + return result; + } + if (ret != 0) { + taihe::set_business_error(ret, "unknown error"); + return result; + } + std::vector vecProperty; + for (const auto &per : touchEventList) { + vecProperty.push_back(TaiheConverter::TouchEventToTaihe(*per)); + } + result = taihe::array(vecProperty); + return result; +} +} // namespace MMI +} // namespace OHOS -- Gitee From 528626a086539341828e2a27b6a44c017a78f404 Mon Sep 17 00:00:00 2001 From: KangPeng Date: Wed, 23 Jul 2025 12:26:48 +0800 Subject: [PATCH 03/29] =?UTF-8?q?ztw=20=E8=A1=A5=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: KangPeng --- frameworks/ets/input_monitor/common/BUILD.gn | 100 +++++++++++ ...ohos.multimodalInput.inputMonitor.impl.cpp | 158 +++++++++++++++--- 2 files changed, 239 insertions(+), 19 deletions(-) create mode 100644 frameworks/ets/input_monitor/common/BUILD.gn diff --git a/frameworks/ets/input_monitor/common/BUILD.gn b/frameworks/ets/input_monitor/common/BUILD.gn new file mode 100644 index 0000000000..c3c0991f0b --- /dev/null +++ b/frameworks/ets/input_monitor/common/BUILD.gn @@ -0,0 +1,100 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/multimodalinput/input/multimodalinput_mini.gni") +copy_taihe_idl("inputani_common_taihe") { + deps = [ + "${mmi_path}/frameworks/ets/mouse_event:mouse_event_taihe", + "${mmi_path}/frameworks/ets/touch_event:touch_event_taihe", + "${mmi_path}/frameworks/ets/short_key:short_key_taihe", + "${mmi_path}/frameworks/ets/key_code:key_code_taihe", + "${mmi_path}/frameworks/ets/input_event:input_event_taihe", + "${mmi_path}/frameworks/ets/gesture_event:gesture_event_taihe", + "${mmi_path}/frameworks/ets/key_event:key_event_taihe", + ] +} +config("inputani_common_config") { + visibility = [ ":*" ] + + include_dirs = [ + "${mmi_path}/interfaces/native/innerkits/proxy/include", + "${mmi_path}/service/permission_helper/include", + "${mmi_path}/util/common/include", + "${mmi_path}/frameworks/ets/input_monitor/common/include", + ] +} +subsystem_name = "multimodalinput" +part_name = "input" +taihe_generated_file_path_inputCommon = "$taihe_file_path/out/$subsystem_name/$part_name/inputani_common" +ohos_taihe("run_taihe") { + taihe_generated_file_path = "${taihe_generated_file_path_inputCommon}" + deps = [ ":inputani_common_taihe" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.multimodalInput.inputCommon.ani.cpp", + "$taihe_generated_file_path/src/ohos.multimodalInput.inputCommon.abi.c", + ] +} +taihe_shared_library("inputani_common") { + taihe_generated_file_path = "${taihe_generated_file_path_inputCommon}" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + configs = [ + "${mmi_path}:coverage_flags", + ":inputani_common_config", + ] + + sources += [ + "${mmi_path}/frameworks/ets/input_monitor/common/src/ani_common.cpp", + "src/ani_constructor.cpp", + ] + deps = [ + ":run_taihe", + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/util:libmmi-util", + ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + branch_protector_ret = "pac_ret" + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } +} +generate_static_abc("inputani_common_abc") { + base_url = "${taihe_generated_file_path_inputMonitor}" + files = [ "${taihe_generated_file_path_inputMonitor}/@ohos.multimodalInput.inputMonitor.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/inputani_common.abc" + dependencies = [ ":run_taihe" ] +} +ohos_prebuilt_etc("inputani_common_etc") { + source = "$target_out_dir/inputani_common.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":inputani_common_abc" ] +} +group("ets_inputcommon_package") { + deps = [ + ":inputani_common_etc", + ":inputani_common", + ] +} \ No newline at end of file diff --git a/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp b/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp index da8107822f..7f0e0a3f72 100644 --- a/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp +++ b/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp @@ -1,29 +1,149 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - #include "ohos.multimodalInput.inputMonitor.proj.hpp" #include "ohos.multimodalInput.inputMonitor.impl.hpp" #include "taihe/runtime.hpp" #include "stdexcept" -using namespace taihe; -using namespace ohos::multimodalInput::inputMonitor; +#include "ani_input_monitor_manager.h" namespace { -} // namespace +// To be implemented. + +::taihe::array<::ohos::multimodalInput::touchEvent::TouchEvent> QueryTouchEventsSync(int32_t count) { + return ANI_INPUT_MONITOR_MGR.QueryTouchEvents(count); +} + +void onTouch(::ohos::multimodalInput::inputMonitor::TouchEventReceiver const& receiver) { + TH_THROW(std::runtime_error, "onTouch not implemented"); +} + +void onMouse(::taihe::callback_view receiver, uintptr_t opq) { + TH_THROW(std::runtime_error, "onMouse not implemented"); +} + +void onPinch(::taihe::callback_view receiver, uintptr_t opq) { + TH_THROW(std::runtime_error, "onPinch not implemented"); +} + +void onPinchByNumber(int32_t fingers, ::taihe::callback_view receiver, uintptr_t opq) { + TH_THROW(std::runtime_error, "onPinchByNumber not implemented"); +} + +void onRotateByNumber(int32_t fingers, ::taihe::callback_view receiver, uintptr_t opq) { + TH_THROW(std::runtime_error, "onRotateByNumber not implemented"); +} + +void onThreeFingersSwipe(::taihe::callback_view receiver, uintptr_t opq) { + TH_THROW(std::runtime_error, "onThreeFingersSwipe not implemented"); +} + +void onFourFingersSwipe(::taihe::callback_view receiver, uintptr_t opq) { + TH_THROW(std::runtime_error, "onFourFingersSwipe not implemented"); +} + +void onThreeFingersTap(::taihe::callback_view receiver, uintptr_t opq) { + TH_THROW(std::runtime_error, "onThreeFingersTap not implemented"); +} + +void onFingerprint(::taihe::callback_view receiver, uintptr_t opq) { + TH_THROW(std::runtime_error, "onFingerprint not implemented"); +} + +void onSwipeInward(::taihe::callback_view receiver, uintptr_t opq) { + TH_THROW(std::runtime_error, "onSwipeInward not implemented"); +} + +void onTouchscreenSwipeByNumber(int32_t fingers, ::taihe::callback_view receiver, uintptr_t opq) { + TH_THROW(std::runtime_error, "onTouchscreenSwipeByNumber not implemented"); +} + +void onTouchscreenPinch(int32_t fingers, ::taihe::callback_view receiver, uintptr_t opq) { + TH_THROW(std::runtime_error, "onTouchscreenPinch not implemented"); +} + +void onKeyPressed(::taihe::array_view<::ohos::multimodalInput::keyCode::KeyCode> keys, ::taihe::callback_view receiver, uintptr_t opq) { + TH_THROW(std::runtime_error, "onKeyPressed not implemented"); +} + +void offTouch(::taihe::optional_view<::ohos::multimodalInput::inputMonitor::TouchEventReceiver> receiver) { + TH_THROW(std::runtime_error, "offTouch not implemented"); +} + +void offMouse(::taihe::optional_view receiver) { + TH_THROW(std::runtime_error, "offMouse not implemented"); +} + +void offPinch(::taihe::optional_view receiver) { + TH_THROW(std::runtime_error, "offPinch not implemented"); +} + +void offPinchByNumber(int32_t fingers, ::taihe::optional_view receiver) { + TH_THROW(std::runtime_error, "offPinchByNumber not implemented"); +} + +void offRotateByNumber(int32_t fingers, ::taihe::optional_view receiver) { + TH_THROW(std::runtime_error, "offRotateByNumber not implemented"); +} + +void offThreeFingersSwipe(::taihe::optional_view receiver) { + TH_THROW(std::runtime_error, "offThreeFingersSwipe not implemented"); +} + +void offFourFingersSwipe(::taihe::optional_view receiver) { + TH_THROW(std::runtime_error, "offFourFingersSwipe not implemented"); +} + +void offThreeFingersTap(::taihe::optional_view receiver) { + TH_THROW(std::runtime_error, "offThreeFingersTap not implemented"); +} + +void offFingerprint(::taihe::optional_view receiver) { + TH_THROW(std::runtime_error, "offFingerprint not implemented"); +} + +void offSwipeInward(::taihe::optional_view receiver) { + TH_THROW(std::runtime_error, "offSwipeInward not implemented"); +} + +void offTouchscreenSwipe(int32_t fingers, ::taihe::optional_view receiver) { + TH_THROW(std::runtime_error, "offTouchscreenSwipe not implemented"); +} + +void offTouchscreenPinch(int32_t fingers, ::taihe::optional_view receiver) { + TH_THROW(std::runtime_error, "offTouchscreenPinch not implemented"); +} + +void offKeyPressed(::taihe::optional_view receiver) { + TH_THROW(std::runtime_error, "offKeyPressed not implemented"); +} +} // namespace // Since these macros are auto-generate, lint will cause false positive. // NOLINTBEGIN -// NOLINTEND \ No newline at end of file +TH_EXPORT_CPP_API_QueryTouchEventsSync(QueryTouchEventsSync); +TH_EXPORT_CPP_API_onTouch(onTouch); +TH_EXPORT_CPP_API_onMouse(onMouse); +TH_EXPORT_CPP_API_onPinch(onPinch); +TH_EXPORT_CPP_API_onPinchByNumber(onPinchByNumber); +TH_EXPORT_CPP_API_onRotateByNumber(onRotateByNumber); +TH_EXPORT_CPP_API_onThreeFingersSwipe(onThreeFingersSwipe); +TH_EXPORT_CPP_API_onFourFingersSwipe(onFourFingersSwipe); +TH_EXPORT_CPP_API_onThreeFingersTap(onThreeFingersTap); +TH_EXPORT_CPP_API_onFingerprint(onFingerprint); +TH_EXPORT_CPP_API_onSwipeInward(onSwipeInward); +TH_EXPORT_CPP_API_onTouchscreenSwipeByNumber(onTouchscreenSwipeByNumber); +TH_EXPORT_CPP_API_onTouchscreenPinch(onTouchscreenPinch); +TH_EXPORT_CPP_API_onKeyPressed(onKeyPressed); +TH_EXPORT_CPP_API_offTouch(offTouch); +TH_EXPORT_CPP_API_offMouse(offMouse); +TH_EXPORT_CPP_API_offPinch(offPinch); +TH_EXPORT_CPP_API_offPinchByNumber(offPinchByNumber); +TH_EXPORT_CPP_API_offRotateByNumber(offRotateByNumber); +TH_EXPORT_CPP_API_offThreeFingersSwipe(offThreeFingersSwipe); +TH_EXPORT_CPP_API_offFourFingersSwipe(offFourFingersSwipe); +TH_EXPORT_CPP_API_offThreeFingersTap(offThreeFingersTap); +TH_EXPORT_CPP_API_offFingerprint(offFingerprint); +TH_EXPORT_CPP_API_offSwipeInward(offSwipeInward); +TH_EXPORT_CPP_API_offTouchscreenSwipe(offTouchscreenSwipe); +TH_EXPORT_CPP_API_offTouchscreenPinch(offTouchscreenPinch); +TH_EXPORT_CPP_API_offKeyPressed(offKeyPressed); +// NOLINTEND -- Gitee From 6a92ccc4743dae1e5fa370676952f189ddfc5734 Mon Sep 17 00:00:00 2001 From: KangPeng Date: Wed, 23 Jul 2025 18:00:05 +0800 Subject: [PATCH 04/29] =?UTF-8?q?ztw=20=E6=8F=90common=20=E5=85=AC?= =?UTF-8?q?=E7=94=A8=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: KangPeng --- BUILD.gn | 1 + .../ets/{input_monitor => }/common/BUILD.gn | 35 ++++++++----------- .../ohos.multimodalInput.inputCommon.taihe | 21 +++++++++++ .../common/include/ani_common.h | 1 - .../common/src/ani_common.cpp | 0 frameworks/ets/input_monitor/BUILD.gn | 7 ++-- .../include/ani_input_monitor_manager.h | 10 +++--- ...ohos.multimodalInput.inputMonitor.impl.cpp | 2 +- 8 files changed, 47 insertions(+), 30 deletions(-) rename frameworks/ets/{input_monitor => }/common/BUILD.gn (76%) create mode 100644 frameworks/ets/common/idl/ohos.multimodalInput.inputCommon.taihe rename frameworks/ets/{input_monitor => }/common/include/ani_common.h (98%) rename frameworks/ets/{input_monitor => }/common/src/ani_common.cpp (100%) diff --git a/BUILD.gn b/BUILD.gn index 028c2514df..1b0eb0e1ac 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -147,6 +147,7 @@ group("input_jsapi_group") { group("input_ets_group") { deps = [ + "frameworks/ets/common:ets_inputcommon_package", "frameworks/ets/input_event:ets_inputEvent_package", "frameworks/ets/intention_code:ets_intentionCode_package", "frameworks/ets/input_monitor:ets_inputMonitor_package", diff --git a/frameworks/ets/input_monitor/common/BUILD.gn b/frameworks/ets/common/BUILD.gn similarity index 76% rename from frameworks/ets/input_monitor/common/BUILD.gn rename to frameworks/ets/common/BUILD.gn index c3c0991f0b..b25a861276 100644 --- a/frameworks/ets/input_monitor/common/BUILD.gn +++ b/frameworks/ets/common/BUILD.gn @@ -14,6 +14,7 @@ import("//build/ohos.gni") import("//build/ohos/taihe_idl/taihe.gni") import("//foundation/multimodalinput/input/multimodalinput_mini.gni") copy_taihe_idl("inputani_common_taihe") { + sources = [ "idl/ohos.multimodalInput.inputCommon.taihe" ] deps = [ "${mmi_path}/frameworks/ets/mouse_event:mouse_event_taihe", "${mmi_path}/frameworks/ets/touch_event:touch_event_taihe", @@ -29,9 +30,9 @@ config("inputani_common_config") { include_dirs = [ "${mmi_path}/interfaces/native/innerkits/proxy/include", - "${mmi_path}/service/permission_helper/include", + "${mmi_path}/interfaces/native/innerkits/event/include", "${mmi_path}/util/common/include", - "${mmi_path}/frameworks/ets/input_monitor/common/include", + "include", ] } subsystem_name = "multimodalinput" @@ -39,7 +40,16 @@ part_name = "input" taihe_generated_file_path_inputCommon = "$taihe_file_path/out/$subsystem_name/$part_name/inputani_common" ohos_taihe("run_taihe") { taihe_generated_file_path = "${taihe_generated_file_path_inputCommon}" - deps = [ ":inputani_common_taihe" ] + deps = [ + "${mmi_path}/frameworks/ets/mouse_event:run_taihe", + "${mmi_path}/frameworks/ets/touch_event:run_taihe", + "${mmi_path}/frameworks/ets/short_key:run_taihe", + "${mmi_path}/frameworks/ets/key_code:run_taihe", + "${mmi_path}/frameworks/ets/input_event:run_taihe", + "${mmi_path}/frameworks/ets/gesture_event:run_taihe", + "${mmi_path}/frameworks/ets/key_event:run_taihe", + ":inputani_common_taihe" + ] outputs = [ "$taihe_generated_file_path/src/ohos.multimodalInput.inputCommon.ani.cpp", "$taihe_generated_file_path/src/ohos.multimodalInput.inputCommon.abi.c", @@ -56,8 +66,7 @@ taihe_shared_library("inputani_common") { ] sources += [ - "${mmi_path}/frameworks/ets/input_monitor/common/src/ani_common.cpp", - "src/ani_constructor.cpp", + "src/ani_common.cpp", ] deps = [ ":run_taihe", @@ -78,23 +87,9 @@ taihe_shared_library("inputani_common") { debug = false } } -generate_static_abc("inputani_common_abc") { - base_url = "${taihe_generated_file_path_inputMonitor}" - files = [ "${taihe_generated_file_path_inputMonitor}/@ohos.multimodalInput.inputMonitor.ets" ] - is_boot_abc = "True" - device_dst_file = "/system/framework/inputani_common.abc" - dependencies = [ ":run_taihe" ] -} -ohos_prebuilt_etc("inputani_common_etc") { - source = "$target_out_dir/inputani_common.abc" - module_install_dir = "framework" - part_name = "$part_name" - subsystem_name = "$subsystem_name" - deps = [ ":inputani_common_abc" ] -} + group("ets_inputcommon_package") { deps = [ - ":inputani_common_etc", ":inputani_common", ] } \ No newline at end of file diff --git a/frameworks/ets/common/idl/ohos.multimodalInput.inputCommon.taihe b/frameworks/ets/common/idl/ohos.multimodalInput.inputCommon.taihe new file mode 100644 index 0000000000..8d20f4568f --- /dev/null +++ b/frameworks/ets/common/idl/ohos.multimodalInput.inputCommon.taihe @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.multimodalInput.inputCommon", "inputCommon") + + +@!sts_inject(""" +static { loadLibrary("InputCommon.z") } +""") diff --git a/frameworks/ets/input_monitor/common/include/ani_common.h b/frameworks/ets/common/include/ani_common.h similarity index 98% rename from frameworks/ets/input_monitor/common/include/ani_common.h rename to frameworks/ets/common/include/ani_common.h index 999e537c6c..0f2f741721 100644 --- a/frameworks/ets/input_monitor/common/include/ani_common.h +++ b/frameworks/ets/common/include/ani_common.h @@ -16,7 +16,6 @@ #ifndef ANI_INPUT_TAIHE_INPUT_MONITOR_COMMON_H #define ANI_INPUT_TAIHE_INPUT_MONITOR_COMMON_H -#include "ohos.multimodalInput.inputMonitor.proj.hpp" #include "ohos.multimodalInput.mouseEvent.proj.hpp" #include "ohos.multimodalInput.gestureEvent.proj.hpp" #include "ohos.multimodalInput.touchEvent.proj.hpp" diff --git a/frameworks/ets/input_monitor/common/src/ani_common.cpp b/frameworks/ets/common/src/ani_common.cpp similarity index 100% rename from frameworks/ets/input_monitor/common/src/ani_common.cpp rename to frameworks/ets/common/src/ani_common.cpp diff --git a/frameworks/ets/input_monitor/BUILD.gn b/frameworks/ets/input_monitor/BUILD.gn index 2e06524b90..3daf6e3f6f 100644 --- a/frameworks/ets/input_monitor/BUILD.gn +++ b/frameworks/ets/input_monitor/BUILD.gn @@ -32,7 +32,7 @@ config("inputMonitor_config") { "${mmi_path}/interfaces/native/innerkits/proxy/include", "${mmi_path}/service/permission_helper/include", "${mmi_path}/util/common/include", - "${mmi_path}/frameworks/ets/input_monitor/common/include", + "${mmi_path}/frameworks/ets/common/include", "${mmi_path}/frameworks/ets/input_monitor/include" ] } @@ -58,15 +58,16 @@ taihe_shared_library("InputMonitor") { ] sources += [ - "${mmi_path}/frameworks/ets/input_monitor/common/src/ani_common.cpp", "src/ani_constructor.cpp", "src/ani_input_monitor_manager.cpp", - "src/ohos.multimodalInput.inputMonitor.impl.cpp", + "src/ohos.multimodalInput.inputMonitor.impl.cpp" ] deps = [ ":run_taihe", "${mmi_path}/frameworks/proxy:libmmi-client", "${mmi_path}/util:libmmi-util", + "${mmi_path}/frameworks/ets/common:ets_inputcommon_package", + ] external_deps = [ "c_utils:utils", diff --git a/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h b/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h index 59cd999a81..1f64220b7c 100644 --- a/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h +++ b/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h @@ -33,11 +33,11 @@ public: TaiheTouchEventArray QueryTouchEvents(int32_t count); private: AniInputMonitorManager() = default; -// private: -// int32_t nextId_ { 0 }; -// std::mutex mutex_; -// std::mutex envMutex_; -// +private: +// int32_t nextId_ { 0 }; +// std::mutex mutex_; +// std::mutex envMutex_; + }; #define ANI_INPUT_MONITOR_MGR AniInputMonitorManager::GetInstance() } // namespace MMI diff --git a/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp b/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp index 7f0e0a3f72..296f9f1502 100644 --- a/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp +++ b/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp @@ -7,7 +7,7 @@ namespace { // To be implemented. - +using namespace OHOS::MMI; ::taihe::array<::ohos::multimodalInput::touchEvent::TouchEvent> QueryTouchEventsSync(int32_t count) { return ANI_INPUT_MONITOR_MGR.QueryTouchEvents(count); } -- Gitee From eb25faf62b790e70e866f6e16e2988e018345230 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Thu, 24 Jul 2025 14:17:33 +0800 Subject: [PATCH 05/29] Implemented 2 methods for infrared_emitter --- BUILD.gn | 1 + frameworks/ets/infrared_emitter/BUILD.gn | 90 +++++++++++++++ ...ohos.multimodalInput.infraredEmitter.taihe | 28 +++++ .../infrared_emitter/src/ani_constructor.cpp | 22 ++++ ...s.multimodalInput.infraredEmitter.impl.cpp | 104 ++++++++++++++++++ 5 files changed, 245 insertions(+) create mode 100644 frameworks/ets/infrared_emitter/BUILD.gn create mode 100644 frameworks/ets/infrared_emitter/idl/ohos.multimodalInput.infraredEmitter.taihe create mode 100644 frameworks/ets/infrared_emitter/src/ani_constructor.cpp create mode 100644 frameworks/ets/infrared_emitter/src/ohos.multimodalInput.infraredEmitter.impl.cpp diff --git a/BUILD.gn b/BUILD.gn index 1b0eb0e1ac..7384e906a1 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -172,6 +172,7 @@ group("input_ets_group") { if (input_feature_short_key) { deps += [ "frameworks/ets/short_key:ets_shortKey_package" ] } + deps += ["frameworks/ets/infrared_emitter:ets_infraredEmitter_package"] } group("mmi_tests") { diff --git a/frameworks/ets/infrared_emitter/BUILD.gn b/frameworks/ets/infrared_emitter/BUILD.gn new file mode 100644 index 0000000000..f0a2de1cbc --- /dev/null +++ b/frameworks/ets/infrared_emitter/BUILD.gn @@ -0,0 +1,90 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/multimodalinput/input/multimodalinput_mini.gni") +copy_taihe_idl("infrared_emitter_taihe") { + sources = [ "idl/ohos.multimodalInput.infraredEmitter.taihe" ] +} +config("infraredEmitter_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + ] +} +subsystem_name = "multimodalinput" +part_name = "input" +taihe_generated_file_path_infraredEmitter = "$taihe_file_path/out/$subsystem_name/$part_name/infraredEmitter" +ohos_taihe("run_taihe") { + taihe_generated_file_path = "${taihe_generated_file_path_infraredEmitter}" + deps = [ ":infrared_emitter_taihe" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.multimodalInput.infraredEmitter.ani.cpp", + "$taihe_generated_file_path/src/ohos.multimodalInput.infraredEmitter.abi.c", + ] +} +taihe_shared_library("InfraredEmitter") { + taihe_generated_file_path = "${taihe_generated_file_path_infraredEmitter}" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + configs = [ + "${mmi_path}:coverage_flags", + ":infraredEmitter_config", + ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + sources += [ + "src/ani_constructor.cpp", + "src/ohos.multimodalInput.infraredEmitter.impl.cpp", + ] + deps = [ + ":run_taihe", + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/util:libmmi-util", + ] + branch_protector_ret = "pac_ret" + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } +} +generate_static_abc("infrared_emitter") { + base_url = "${taihe_generated_file_path_infraredEmitter}" + files = [ "${taihe_generated_file_path_infraredEmitter}/@ohos.multimodalInput.infraredEmitter.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/infrared_emitter.abc" + dependencies = [ ":run_taihe" ] +} +ohos_prebuilt_etc("infrared_emitter_etc") { + source = "$target_out_dir/infrared_emitter.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":infrared_emitter" ] +} +group("ets_infraredEmitter_package") { + deps = [ + ":infrared_emitter_etc", + ":InfraredEmitter", + ] +} \ No newline at end of file diff --git a/frameworks/ets/infrared_emitter/idl/ohos.multimodalInput.infraredEmitter.taihe b/frameworks/ets/infrared_emitter/idl/ohos.multimodalInput.infraredEmitter.taihe new file mode 100644 index 0000000000..c92cdbe4c2 --- /dev/null +++ b/frameworks/ets/infrared_emitter/idl/ohos.multimodalInput.infraredEmitter.taihe @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.multimodalInput.infraredEmitter", "infraredEmitter") +@!sts_inject(""" +static { loadLibrary("InfraredEmitter.z") } +""") + + +struct InfraredFrequency { + max: i64; + min: i64; +} + +function TransmitInfrared(infraredFrequency: i64, pattern: Array): void; +function GetInfraredFrequencies(): Array; diff --git a/frameworks/ets/infrared_emitter/src/ani_constructor.cpp b/frameworks/ets/infrared_emitter/src/ani_constructor.cpp new file mode 100644 index 0000000000..87e388fea4 --- /dev/null +++ b/frameworks/ets/infrared_emitter/src/ani_constructor.cpp @@ -0,0 +1,22 @@ +#include "ohos.multimodalInput.infraredEmitter.ani.hpp" +#include "taihe.platform.ani.ani.hpp" +#if __has_include() +#include +#elif __has_include() +#include +#else +#error "ani.h not found. Please ensure the Ani SDK is correctly installed." +#endif +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) { + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + ani_status status = ANI_OK; + if (ANI_OK != ohos::multimodalInput::infraredEmitter::ANIRegister(env)) { + std::cerr << "Error from ohos::multimodalInput::infraredEmitter::ANIRegister" << std::endl; + status = ANI_ERROR; + } + *result = ANI_VERSION_1; + return status; +} diff --git a/frameworks/ets/infrared_emitter/src/ohos.multimodalInput.infraredEmitter.impl.cpp b/frameworks/ets/infrared_emitter/src/ohos.multimodalInput.infraredEmitter.impl.cpp new file mode 100644 index 0000000000..a60d82f411 --- /dev/null +++ b/frameworks/ets/infrared_emitter/src/ohos.multimodalInput.infraredEmitter.impl.cpp @@ -0,0 +1,104 @@ +#include "ohos.multimodalInput.infraredEmitter.proj.hpp" +#include "ohos.multimodalInput.infraredEmitter.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include "mmi_log.h" +#include "input_manager.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "infrared_emitter_impl" + +namespace { + +enum EtsErrorCode : int32_t { + OTHER_ERROR = -1, + COMMON_PERMISSION_CHECK_ERROR = 201, + COMMON_USE_SYSAPI_ERROR = 202, + COMMON_PARAMETER_ERROR = 401, + INPUT_DEVICE_NOT_SUPPORTED = 801, + COMMON_DEVICE_NOT_EXIST = 3900001, + COMMON_KEYBOARD_DEVICE_NOT_EXIST = 3900002, + COMMON_NON_INPUT_APPLICATION = 3900003, + PRE_KEY_NOT_SUPPORTED = 4100001, + INPUT_OCCUPIED_BY_SYSTEM = 4200002, + INPUT_OCCUPIED_BY_OTHER = 4200003, + ERROR_WINDOW_ID_PERMISSION_DENIED = 26500001, +}; + + + + // qy add + static ::ohos::multimodalInput::infraredEmitter::InfraredFrequency InfraredFrequencyToAni(OHOS::MMI::InfraredFrequency const & value){ + ::ohos::multimodalInput::infraredEmitter::InfraredFrequency frequency = {}; + + frequency.max = value.max_; + frequency.min = value.min_; + + return frequency; + } + + +void TransmitInfrared(int64_t infraredFrequency, ::taihe::array_view pattern) { + CALL_DEBUG_ENTER; + int32_t size = static_cast(pattern.size()); + std::vector vecPattern(pattern.begin(),pattern.end()); + + std::string context = "infraredFrequency:" + std::to_string(infraredFrequency) + "\n;" + "; size=" + std::to_string(size) + ";"; + for (int32_t i = 0; i < size; i++) { + context = context + std::to_string(i) + ": pattern: " + std::to_string(pattern[i]) + ";"; + } + MMI_HILOGD("ohos.multimodalInput.infraredEmitter.TransmitInfrared para size:%{public}s", context.c_str()); + + int32_t ret = OHOS::MMI::InputManager::GetInstance()->TransmitInfrared(infraredFrequency, vecPattern); + + if(ret != RET_OK){ + int32_t errorCode = std::abs(ret); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } else if (errorCode == COMMON_PERMISSION_CHECK_ERROR) { + MMI_HILOGE("Shield api need ohos.permission.INPUT_CONTROL_DISPATCHING"); + taihe::set_business_error(COMMON_PERMISSION_CHECK_ERROR, "Shield api need ohos.permission.INPUT_CONTROL_DISPATCHING"); + } else { + MMI_HILOGE("ohos.multimodalInput.infraredEmitter.TransmitInfrared requst error. returnCode:%{public}d", ret); + } + } +} + +::taihe::array<::ohos::multimodalInput::infraredEmitter::InfraredFrequency> GetInfraredFrequencies() { + CALL_DEBUG_ENTER; + std::vector requencys; + int32_t ret = OHOS::MMI::InputManager::GetInstance()->GetInfraredFrequencies(requencys); + + if(ret != RET_OK){ + int32_t errorCode = std::abs(ret); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } else if (errorCode == COMMON_PERMISSION_CHECK_ERROR) { + MMI_HILOGE("Shield api need ohos.permission.INPUT_CONTROL_DISPATCHING"); + taihe::set_business_error(COMMON_PERMISSION_CHECK_ERROR, "Shield api need ohos.permission.INPUT_CONTROL_DISPATCHING"); + } else { + MMI_HILOGE("ohos.multimodalInput.infraredEmitter.TransmitInfrared requst error. returnCode:%{public}d", ret); + } + + return ::taihe::array<::ohos::multimodalInput::infraredEmitter::InfraredFrequency>(nullptr,0); + } + + ::ohos::multimodalInput::infraredEmitter::InfraredFrequency aniempty = {}; + std::vector<::ohos::multimodalInput::infraredEmitter::InfraredFrequency> resultTemp(requencys.size(), aniempty); + std::transform(requencys.begin(),requencys.end(),resultTemp.begin(),[](OHOS::MMI::InfraredFrequency c){ + ::ohos::multimodalInput::infraredEmitter::InfraredFrequency anitemp = InfraredFrequencyToAni(c); + return anitemp; + }); + + return ::taihe::array<::ohos::multimodalInput::infraredEmitter::InfraredFrequency>(::taihe::copy_data_t{},resultTemp.data(),resultTemp.size()); +} +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +TH_EXPORT_CPP_API_TransmitInfrared(TransmitInfrared); +TH_EXPORT_CPP_API_GetInfraredFrequencies(GetInfraredFrequencies); +// NOLINTEND -- Gitee From 6cf9f6f44b895308729b7085bc90847e0c3a6f3b Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Thu, 24 Jul 2025 15:54:15 +0800 Subject: [PATCH 06/29] =?UTF-8?q?lmq=20=E5=A2=9E=E5=8A=A0common=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2inputDevice=E7=9B=B8=E5=85=B3=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- frameworks/ets/common/BUILD.gn | 8 +- frameworks/ets/common/include/ani_common.h | 799 ++++++++++++++++++ frameworks/ets/common/src/ani_common.cpp | 102 +++ frameworks/ets/input_consumer/BUILD.gn | 3 +- .../include/inputConsumer_keyPressed_impl.h | 1 - .../src/inputConsumer_keyPressed_impl.cpp | 3 +- 6 files changed, 912 insertions(+), 4 deletions(-) diff --git a/frameworks/ets/common/BUILD.gn b/frameworks/ets/common/BUILD.gn index b25a861276..49effe4b75 100644 --- a/frameworks/ets/common/BUILD.gn +++ b/frameworks/ets/common/BUILD.gn @@ -2,7 +2,9 @@ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# http://www.apache.org/licenses/LICENSE-2.0 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,6 +25,8 @@ copy_taihe_idl("inputani_common_taihe") { "${mmi_path}/frameworks/ets/input_event:input_event_taihe", "${mmi_path}/frameworks/ets/gesture_event:gesture_event_taihe", "${mmi_path}/frameworks/ets/key_event:key_event_taihe", + "${mmi_path}/frameworks/ets/input_device:input_device_taihe", + "${mmi_path}/frameworks/ets/input_consumer:input_consumer_taihe", ] } config("inputani_common_config") { @@ -48,6 +52,8 @@ ohos_taihe("run_taihe") { "${mmi_path}/frameworks/ets/input_event:run_taihe", "${mmi_path}/frameworks/ets/gesture_event:run_taihe", "${mmi_path}/frameworks/ets/key_event:run_taihe", + "${mmi_path}/frameworks/ets/input_device:run_taihe", + "${mmi_path}/frameworks/ets/input_consumer:run_taihe", ":inputani_common_taihe" ] outputs = [ diff --git a/frameworks/ets/common/include/ani_common.h b/frameworks/ets/common/include/ani_common.h index 0f2f741721..e3c24240a9 100644 --- a/frameworks/ets/common/include/ani_common.h +++ b/frameworks/ets/common/include/ani_common.h @@ -16,15 +16,40 @@ #ifndef ANI_INPUT_TAIHE_INPUT_MONITOR_COMMON_H #define ANI_INPUT_TAIHE_INPUT_MONITOR_COMMON_H +#include +#include + +#include "securec.h" + +#include "ohos.multimodalInput.inputDevice.proj.hpp" +#include "ohos.multimodalInput.keyCode.proj.hpp" +#include "ohos.multimodalInput.keyCode.impl.hpp" #include "ohos.multimodalInput.mouseEvent.proj.hpp" #include "ohos.multimodalInput.gestureEvent.proj.hpp" #include "ohos.multimodalInput.touchEvent.proj.hpp" #include "taihe/runtime.hpp" #include "pointer_event.h" +#include "input_device.h" + +#include namespace OHOS { namespace MMI { +constexpr uint32_t EVDEV_TAG_KEYBOARD = (1 << 1); +constexpr uint32_t EVDEV_TAG_MOUSE = (1 << 2); +constexpr uint32_t EVDEV_TAG_TOUCHPAD = (1 << 3); +constexpr uint32_t EVDEV_TAG_TOUCHSCREEN = (1 << 4); +constexpr uint32_t EVDEV_TAG_JOYSTICK = (1 << 6); +constexpr uint32_t EVDEV_TAG_TRACKBALL = (1 << 10); + +using namespace ohos::multimodalInput::keyCode; +using TaihesType = ohos::multimodalInput::inputDevice::sourceType; +using TaiheaType = ohos::multimodalInput::inputDevice::axisType; +using TaiheSType = ohos::multimodalInput::inputDevice::SourceType; +using TaiheAType = ohos::multimodalInput::inputDevice::AxisType; +using TaiheAxisRange = ohos::multimodalInput::inputDevice::AxisRange; +using TaiheInputDeviceData = ohos::multimodalInput::inputDevice::InputDeviceData; using TaiheMouseEvent = ohos::multimodalInput::mouseEvent::MouseEvent; using TaihePinchEvent = ohos::multimodalInput::gestureEvent::Pinch; using TaiheTouchEvent = ohos::multimodalInput::touchEvent::TouchEvent; @@ -40,8 +65,782 @@ using callbackType = std::variant, taihe::callback, taihe::callback>; */ + +struct TaiheError { + int32_t errorCode; + std::string msg; +}; + +enum TaiheErrorCode : int32_t { + OTHER_ERROR = -1, + COMMON_PERMISSION_CHECK_ERROR = 201, + COMMON_PARAMETER_ERROR = 401, + COMMON_USE_SYSAPI_ERROR = 202, + INPUT_DEVICE_NOT_SUPPORTED = 801, + INPUT_OCCUPIED_BY_SYSTEM = 4200002, + INPUT_OCCUPIED_BY_OTHER = 4200003, + PRE_KEY_NOT_SUPPORTED = 4100001, + COMMON_DEVICE_NOT_EXIST = 3900001, + COMMON_KEYBOARD_DEVICE_NOT_EXIST = 3900002, + COMMON_NON_INPUT_APPLICATION = 3900003, + ERROR_WINDOW_ID_PERMISSION_DENIED = 26500001, +}; + +const std::map TAIHE_ERRORS = { + { COMMON_PERMISSION_CHECK_ERROR, + { COMMON_PERMISSION_CHECK_ERROR, "Permission denied. An attempt was made to %s forbidden by permission:%s." } }, + { COMMON_USE_SYSAPI_ERROR, + { COMMON_USE_SYSAPI_ERROR, "Permission denied, non-system application called system api." } }, + { COMMON_PARAMETER_ERROR, { COMMON_PARAMETER_ERROR, "Parameter error. The type of %s must be %s." } }, + { COMMON_DEVICE_NOT_EXIST, { COMMON_DEVICE_NOT_EXIST, "The specified device does not exist." } }, + { COMMON_KEYBOARD_DEVICE_NOT_EXIST, + { COMMON_KEYBOARD_DEVICE_NOT_EXIST, "The specified keyboard device does not exist." } }, + { COMMON_NON_INPUT_APPLICATION, { COMMON_NON_INPUT_APPLICATION, "it is prohibited for non-input applications." } }, + { INPUT_DEVICE_NOT_SUPPORTED, { INPUT_DEVICE_NOT_SUPPORTED, "Capability not supported.\n" } }, + { ERROR_WINDOW_ID_PERMISSION_DENIED, { ERROR_WINDOW_ID_PERMISSION_DENIED, + "Invalid windowId. Possible causes: The window id does not belong to the current process.\n" } }, + { PRE_KEY_NOT_SUPPORTED, { PRE_KEY_NOT_SUPPORTED, "Invalid combination of keys." } }, + { INPUT_OCCUPIED_BY_SYSTEM, { INPUT_OCCUPIED_BY_SYSTEM, "The hotkey has been subscribed by system." } }, + { INPUT_OCCUPIED_BY_OTHER, { INPUT_OCCUPIED_BY_OTHER, "The hotkey has been subscribed by other one." } }, +}; + + enum KeyCodeEts { + KEYCODE_FN_ETS = 0, + KEYCODE_UNKNOWN_ETS = -1, + KEYCODE_HOME_ETS = 1, + KEYCODE_BACK_ETS = 2, + KEYCODE_SEARCH_ETS = 9, + KEYCODE_MEDIA_PLAY_PAUSE_ETS = 10, + KEYCODE_MEDIA_STOP_ETS = 11, + KEYCODE_MEDIA_NEXT_ETS = 12, + KEYCODE_MEDIA_PREVIOUS_ETS = 13, + KEYCODE_MEDIA_REWIND_ETS = 14, + KEYCODE_MEDIA_FAST_FORWARD_ETS = 15, + KEYCODE_VOLUME_UP_ETS = 16, + KEYCODE_VOLUME_DOWN_ETS = 17, + KEYCODE_POWER_ETS = 18, + KEYCODE_CAMERA_ETS = 19, + KEYCODE_VOLUME_MUTE_ETS = 22, + KEYCODE_MUTE_ETS = 23, + KEYCODE_BRIGHTNESS_UP_ETS = 40, + KEYCODE_BRIGHTNESS_DOWN_ETS = 41, + KEYCODE_0_ETS = 2000, + KEYCODE_1_ETS = 2001, + KEYCODE_2_ETS = 2002, + KEYCODE_3_ETS = 2003, + KEYCODE_4_ETS = 2004, + KEYCODE_5_ETS = 2005, + KEYCODE_6_ETS = 2006, + KEYCODE_7_ETS = 2007, + KEYCODE_8_ETS = 2008, + KEYCODE_9_ETS = 2009, + KEYCODE_STAR_ETS = 2010, + KEYCODE_POUND_ETS = 2011, + KEYCODE_DPAD_UP_ETS = 2012, + KEYCODE_DPAD_DOWN_ETS = 2013, + KEYCODE_DPAD_LEFT_ETS = 2014, + KEYCODE_DPAD_RIGHT_ETS = 2015, + KEYCODE_DPAD_CENTER_ETS = 2016, + KEYCODE_A_ETS = 2017, + KEYCODE_B_ETS = 2018, + KEYCODE_C_ETS = 2019, + KEYCODE_D_ETS = 2020, + KEYCODE_E_ETS = 2021, + KEYCODE_F_ETS = 2022, + KEYCODE_G_ETS = 2023, + KEYCODE_H_ETS = 2024, + KEYCODE_I_ETS = 2025, + KEYCODE_J_ETS = 2026, + KEYCODE_K_ETS = 2027, + KEYCODE_L_ETS = 2028, + KEYCODE_M_ETS = 2029, + KEYCODE_N_ETS = 2030, + KEYCODE_O_ETS = 2031, + KEYCODE_P_ETS = 2032, + KEYCODE_Q_ETS = 2033, + KEYCODE_R_ETS = 2034, + KEYCODE_S_ETS = 2035, + KEYCODE_T_ETS = 2036, + KEYCODE_U_ETS = 2037, + KEYCODE_V_ETS = 2038, + KEYCODE_W_ETS = 2039, + KEYCODE_X_ETS = 2040, + KEYCODE_Y_ETS = 2041, + KEYCODE_Z_ETS = 2042, + KEYCODE_COMMA_ETS = 2043, + KEYCODE_PERIOD_ETS = 2044, + KEYCODE_ALT_LEFT_ETS = 2045, + KEYCODE_ALT_RIGHT_ETS = 2046, + KEYCODE_SHIFT_LEFT_ETS = 2047, + KEYCODE_SHIFT_RIGHT_ETS = 2048, + KEYCODE_TAB_ETS = 2049, + KEYCODE_SPACE_ETS = 2050, + KEYCODE_SYM_ETS = 2051, + KEYCODE_EXPLORER_ETS = 2052, + KEYCODE_ENVELOPE_ETS = 2053, + KEYCODE_ENTER_ETS = 2054, + KEYCODE_DEL_ETS = 2055, + KEYCODE_GRAVE_ETS = 2056, + KEYCODE_MINUS_ETS = 2057, + KEYCODE_EQUALS_ETS = 2058, + KEYCODE_LEFT_BRACKET_ETS = 2059, + KEYCODE_RIGHT_BRACKET_ETS = 2060, + KEYCODE_BACKSLASH_ETS = 2061, + KEYCODE_SEMICOLON_ETS = 2062, + KEYCODE_APOSTROPHE_ETS = 2063, + KEYCODE_SLASH_ETS = 2064, + KEYCODE_AT_ETS = 2065, + KEYCODE_PLUS_ETS = 2066, + KEYCODE_MENU_ETS = 2067, + KEYCODE_PAGE_UP_ETS = 2068, + KEYCODE_PAGE_DOWN_ETS = 2069, + KEYCODE_ESCAPE_ETS = 2070, + KEYCODE_FORWARD_DEL_ETS = 2071, + KEYCODE_CTRL_LEFT_ETS = 2072, + KEYCODE_CTRL_RIGHT_ETS = 2073, + KEYCODE_CAPS_LOCK_ETS = 2074, + KEYCODE_SCROLL_LOCK_ETS = 2075, + KEYCODE_META_LEFT_ETS = 2076, + KEYCODE_META_RIGHT_ETS = 2077, + KEYCODE_FUNCTION_ETS = 2078, + KEYCODE_SYSRQ_ETS = 2079, + KEYCODE_BREAK_ETS = 2080, + KEYCODE_MOVE_HOME_ETS = 2081, + KEYCODE_MOVE_END_ETS = 2082, + KEYCODE_INSERT_ETS = 2083, + KEYCODE_FORWARD_ETS = 2084, + KEYCODE_MEDIA_PLAY_ETS = 2085, + KEYCODE_MEDIA_PAUSE_ETS = 2086, + KEYCODE_MEDIA_CLOSE_ETS = 2087, + KEYCODE_MEDIA_EJECT_ETS = 2088, + KEYCODE_MEDIA_RECORD_ETS = 2089, + KEYCODE_F1_ETS = 2090, + KEYCODE_F2_ETS = 2091, + KEYCODE_F3_ETS = 2092, + KEYCODE_F4_ETS = 2093, + KEYCODE_F5_ETS = 2094, + KEYCODE_F6_ETS = 2095, + KEYCODE_F7_ETS = 2096, + KEYCODE_F8_ETS = 2097, + KEYCODE_F9_ETS = 2098, + KEYCODE_F10_ETS = 2099, + KEYCODE_F11_ETS = 2100, + KEYCODE_F12_ETS = 2101, + KEYCODE_NUM_LOCK_ETS = 2102, + KEYCODE_NUMPAD_0_ETS = 2103, + KEYCODE_NUMPAD_1_ETS = 2104, + KEYCODE_NUMPAD_2_ETS = 2105, + KEYCODE_NUMPAD_3_ETS = 2106, + KEYCODE_NUMPAD_4_ETS = 2107, + KEYCODE_NUMPAD_5_ETS = 2108, + KEYCODE_NUMPAD_6_ETS = 2109, + KEYCODE_NUMPAD_7_ETS = 2110, + KEYCODE_NUMPAD_8_ETS = 2111, + KEYCODE_NUMPAD_9_ETS = 2112, + KEYCODE_NUMPAD_DIVIDE_ETS = 2113, + KEYCODE_NUMPAD_MULTIPLY_ETS = 2114, + KEYCODE_NUMPAD_SUBTRACT_ETS = 2115, + KEYCODE_NUMPAD_ADD_ETS = 2116, + KEYCODE_NUMPAD_DOT_ETS = 2117, + KEYCODE_NUMPAD_COMMA_ETS = 2118, + KEYCODE_NUMPAD_ENTER_ETS = 2119, + KEYCODE_NUMPAD_EQUALS_ETS = 2120, + KEYCODE_NUMPAD_LEFT_PAREN_ETS = 2121, + KEYCODE_NUMPAD_RIGHT_PAREN_ETS = 2122, + KEYCODE_VIRTUAL_MULTITASK_ETS = 2210, + KEYCODE_BUTTON_A_ETS = 2301, + KEYCODE_BUTTON_B_ETS = 2302, + KEYCODE_BUTTON_X_ETS = 2304, + KEYCODE_BUTTON_Y_ETS = 2305, + KEYCODE_BUTTON_L1_ETS = 2307, + KEYCODE_BUTTON_R1_ETS = 2308, + KEYCODE_BUTTON_L2_ETS = 2309, + KEYCODE_BUTTON_R2_ETS = 2310, + KEYCODE_BUTTON_SELECT_ETS = 2311, + KEYCODE_BUTTON_START_ETS = 2312, + KEYCODE_BUTTON_MODE_ETS = 2313, + KEYCODE_BUTTON_THUMBL_ETS = 2314, + KEYCODE_BUTTON_THUMBR_ETS = 2315, + KEYCODE_SLEEP_ETS = 2600, + KEYCODE_ZENKAKU_HANKAKU_ETS = 2601, + KEYCODE_102ND_ETS = 2602, + KEYCODE_RO_ETS = 2603, + KEYCODE_KATAKANA_ETS = 2604, + KEYCODE_HIRAGANA_ETS = 2605, + KEYCODE_HENKAN_ETS = 2606, + KEYCODE_KATAKANA_HIRAGANA_ETS = 2607, + KEYCODE_MUHENKAN_ETS = 2608, + KEYCODE_LINEFEED_ETS = 2609, + KEYCODE_MACRO_ETS = 2610, + KEYCODE_NUMPAD_PLUSMINUS_ETS = 2611, + KEYCODE_SCALE_ETS = 2612, + KEYCODE_HANGUEL_ETS = 2613, + KEYCODE_HANJA_ETS = 2614, + KEYCODE_YEN_ETS = 2615, + KEYCODE_STOP_ETS = 2616, + KEYCODE_AGAIN_ETS = 2617, + KEYCODE_PROPS_ETS = 2618, + KEYCODE_UNDO_ETS = 2619, + KEYCODE_COPY_ETS = 2620, + KEYCODE_OPEN_ETS = 2621, + KEYCODE_PASTE_ETS = 2622, + KEYCODE_FIND_ETS = 2623, + KEYCODE_CUT_ETS = 2624, + KEYCODE_HELP_ETS = 2625, + KEYCODE_CALC_ETS = 2626, + KEYCODE_FILE_ETS = 2627, + KEYCODE_BOOKMARKS_ETS = 2628, + KEYCODE_NEXT_ETS = 2629, + KEYCODE_PLAYPAUSE_ETS = 2630, + KEYCODE_PREVIOUS_ETS = 2631, + KEYCODE_STOPCD_ETS = 2632, + KEYCODE_CONFIG_ETS = 2634, + KEYCODE_REFRESH_ETS = 2635, + KEYCODE_EXIT_ETS = 2636, + KEYCODE_EDIT_ETS = 2637, + KEYCODE_SCROLLUP_ETS = 2638, + KEYCODE_SCROLLDOWN_ETS = 2639, + KEYCODE_NEW_ETS = 2640, + KEYCODE_REDO_ETS = 2641, + KEYCODE_CLOSE_ETS = 2642, + KEYCODE_PLAY_ETS = 2643, + KEYCODE_BASSBOOST_ETS = 2644, + KEYCODE_PRINT_ETS = 2645, + KEYCODE_CHAT_ETS = 2646, + KEYCODE_FINANCE_ETS = 2647, + KEYCODE_CANCEL_ETS = 2648, + KEYCODE_KBDILLUM_TOGGLE_ETS = 2649, + KEYCODE_KBDILLUM_DOWN_ETS = 2650, + KEYCODE_KBDILLUM_UP_ETS = 2651, + KEYCODE_SEND_ETS = 2652, + KEYCODE_REPLY_ETS = 2653, + KEYCODE_FORWARDMAIL_ETS = 2654, + KEYCODE_SAVE_ETS = 2655, + KEYCODE_DOCUMENTS_ETS = 2656, + KEYCODE_VIDEO_NEXT_ETS = 2657, + KEYCODE_VIDEO_PREV_ETS = 2658, + KEYCODE_BRIGHTNESS_CYCLE_ETS = 2659, + KEYCODE_BRIGHTNESS_ZERO_ETS = 2660, + KEYCODE_DISPLAY_OFF_ETS = 2661, + KEYCODE_BTN_MISC_ETS = 2662, + KEYCODE_GOTO_ETS = 2663, + KEYCODE_INFO_ETS = 2664, + KEYCODE_PROGRAM_ETS = 2665, + KEYCODE_PVR_ETS = 2666, + KEYCODE_SUBTITLE_ETS = 2667, + KEYCODE_FULL_SCREEN_ETS = 2668, + KEYCODE_KEYBOARD_ETS = 2669, + KEYCODE_ASPECT_RATIO_ETS = 2670, + KEYCODE_PC_ETS = 2671, + KEYCODE_TV_ETS = 2672, + KEYCODE_TV2_ETS = 2673, + KEYCODE_VCR_ETS = 2674, + KEYCODE_VCR2_ETS = 2675, + KEYCODE_SAT_ETS = 2676, + KEYCODE_CD_ETS = 2677, + KEYCODE_TAPE_ETS = 2678, + KEYCODE_TUNER_ETS = 2679, + KEYCODE_PLAYER_ETS = 2680, + KEYCODE_DVD_ETS = 2681, + KEYCODE_AUDIO_ETS = 2682, + KEYCODE_VIDEO_ETS = 2683, + KEYCODE_MEMO_ETS = 2684, + KEYCODE_CALENDAR_ETS = 2685, + KEYCODE_RED_ETS = 2686, + KEYCODE_GREEN_ETS = 2687, + KEYCODE_YELLOW_ETS = 2688, + KEYCODE_BLUE_ETS = 2689, + KEYCODE_CHANNELUP_ETS = 2690, + KEYCODE_CHANNELDOWN_ETS = 2691, + KEYCODE_LAST_ETS = 2692, + KEYCODE_RESTART_ETS = 2693, + KEYCODE_SLOW_ETS = 2694, + KEYCODE_SHUFFLE_ETS = 2695, + KEYCODE_VIDEOPHONE_ETS = 2696, + KEYCODE_GAMES_ETS = 2697, + KEYCODE_ZOOMIN_ETS = 2698, + KEYCODE_ZOOMOUT_ETS = 2699, + KEYCODE_ZOOMRESET_ETS = 2700, + KEYCODE_WORDPROCESSOR_ETS = 2701, + KEYCODE_EDITOR_ETS = 2702, + KEYCODE_SPREADSHEET_ETS = 2703, + KEYCODE_GRAPHICSEDITOR_ETS = 2704, + KEYCODE_PRESENTATION_ETS = 2705, + KEYCODE_DATABASE_ETS = 2706, + KEYCODE_NEWS_ETS = 2707, + KEYCODE_VOICEMAIL_ETS = 2708, + KEYCODE_ADDRESSBOOK_ETS = 2709, + KEYCODE_MESSENGER_ETS = 2710, + KEYCODE_BRIGHTNESS_TOGGLE_ETS = 2711, + KEYCODE_SPELLCHECK_ETS = 2712, + KEYCODE_COFFEE_ETS = 2713, + KEYCODE_MEDIA_REPEAT_ETS = 2714, + KEYCODE_IMAGES_ETS = 2715, + KEYCODE_BUTTONCONFIG_ETS = 2716, + KEYCODE_TASKMANAGER_ETS = 2717, + KEYCODE_JOURNAL_ETS = 2718, + KEYCODE_CONTROLPANEL_ETS = 2719, + KEYCODE_APPSELECT_ETS = 2720, + KEYCODE_SCREENSAVER_ETS = 2721, + KEYCODE_ASSISTANT_ETS = 2722, + KEYCODE_KBD_LAYOUT_NEXT_ETS = 2723, + KEYCODE_BRIGHTNESS_MIN_ETS = 2724, + KEYCODE_BRIGHTNESS_MAX_ETS = 2725, + KEYCODE_KBDINPUTASSIST_PREV_ETS = 2726, + KEYCODE_KBDINPUTASSIST_NEXT_ETS = 2727, + KEYCODE_KBDINPUTASSIST_PREVGROUP_ETS = 2728, + KEYCODE_KBDINPUTASSIST_NEXTGROUP_ETS = 2729, + KEYCODE_KBDINPUTASSIST_ACCEPT_ETS = 2730, + KEYCODE_KBDINPUTASSIST_CANCEL_ETS = 2731, + KEYCODE_FRONT_ETS = 2800, + KEYCODE_SETUP_ETS = 2801, + KEYCODE_WAKEUP_ETS = 2802, + KEYCODE_SENDFILE_ETS = 2803, + KEYCODE_DELETEFILE_ETS = 2804, + KEYCODE_XFER_ETS = 2805, + KEYCODE_PROG1_ETS = 2806, + KEYCODE_PROG2_ETS = 2807, + KEYCODE_MSDOS_ETS = 2808, + KEYCODE_SCREENLOCK_ETS = 2809, + KEYCODE_DIRECTION_ROTATE_DISPLAY_ETS = 2810, + KEYCODE_CYCLEWINDOWS_ETS = 2811, + KEYCODE_COMPUTER_ETS = 2812, + KEYCODE_EJECTCLOSECD_ETS = 2813, + KEYCODE_ISO_ETS = 2814, + KEYCODE_MOVE_ETS = 2815, + KEYCODE_F13_ETS = 2816, + KEYCODE_F14_ETS = 2817, + KEYCODE_F15_ETS = 2818, + KEYCODE_F16_ETS = 2819, + KEYCODE_F17_ETS = 2820, + KEYCODE_F18_ETS = 2821, + KEYCODE_F19_ETS = 2822, + KEYCODE_F20_ETS = 2823, + KEYCODE_F21_ETS = 2824, + KEYCODE_F22_ETS = 2825, + KEYCODE_F23_ETS = 2826, + KEYCODE_F24_ETS = 2827, + KEYCODE_PROG3_ETS = 2828, + KEYCODE_PROG4_ETS = 2829, + KEYCODE_DASHBOARD_ETS = 2830, + KEYCODE_SUSPEND_ETS = 2831, + KEYCODE_HP_ETS = 2832, + KEYCODE_SOUND_ETS = 2833, + KEYCODE_QUESTION_ETS = 2834, + KEYCODE_CONNECT_ETS = 2836, + KEYCODE_SPORT_ETS = 2837, + KEYCODE_SHOP_ETS = 2838, + KEYCODE_ALTERASE_ETS = 2839, + KEYCODE_SWITCHVIDEOMODE_ETS = 2841, + KEYCODE_BATTERY_ETS = 2842, + KEYCODE_BLUETOOTH_ETS = 2843, + KEYCODE_WLAN_ETS = 2844, + KEYCODE_UWB_ETS = 2845, + KEYCODE_WWAN_WIMAX_ETS = 2846, + KEYCODE_RFKILL_ETS = 2847, + KEYCODE_CHANNEL_ETS = 3001, + KEYCODE_BTN_0_ETS = 3100, + KEYCODE_BTN_1_ETS = 3101, + KEYCODE_BTN_2_ETS = 3102, + KEYCODE_BTN_3_ETS = 3103, + KEYCODE_BTN_4_ETS = 3104, + KEYCODE_BTN_5_ETS = 3105, + KEYCODE_BTN_6_ETS = 3106, + KEYCODE_BTN_7_ETS = 3107, + KEYCODE_BTN_8_ETS = 3108, + KEYCODE_BTN_9_ETS = 3109, + KEYCODE_DAGGER_CLICK_ETS = 3211, + KEYCODE_DAGGER_DOUBLE_CLICK_ETS = 3212, + KEYCODE_DAGGER_LONG_PRESS_ETS = 3213 +}; + +const std::map KEY_CODE_TRANSFORMATION = { + { KEYCODE_FN_ETS, KeyCode::key_t::KEYCODE_FN }, + { KEYCODE_UNKNOWN_ETS, KeyCode::key_t::KEYCODE_UNKNOWN }, + { KEYCODE_HOME_ETS, KeyCode::key_t::KEYCODE_HOME }, + { KEYCODE_BACK_ETS, KeyCode::key_t::KEYCODE_BACK }, + { KEYCODE_SEARCH_ETS, KeyCode::key_t::KEYCODE_SEARCH }, + { KEYCODE_MEDIA_PLAY_PAUSE_ETS, KeyCode::key_t::KEYCODE_MEDIA_PLAY_PAUSE }, + { KEYCODE_MEDIA_STOP_ETS, KeyCode::key_t::KEYCODE_MEDIA_STOP }, + { KEYCODE_MEDIA_NEXT_ETS, KeyCode::key_t::KEYCODE_MEDIA_NEXT }, + { KEYCODE_MEDIA_PREVIOUS_ETS, KeyCode::key_t::KEYCODE_MEDIA_PREVIOUS }, + { KEYCODE_MEDIA_REWIND_ETS, KeyCode::key_t::KEYCODE_MEDIA_REWIND }, + { KEYCODE_MEDIA_FAST_FORWARD_ETS, KeyCode::key_t::KEYCODE_MEDIA_FAST_FORWARD }, + { KEYCODE_VOLUME_UP_ETS, KeyCode::key_t::KEYCODE_VOLUME_UP }, + { KEYCODE_VOLUME_DOWN_ETS, KeyCode::key_t::KEYCODE_VOLUME_DOWN }, + { KEYCODE_POWER_ETS, KeyCode::key_t::KEYCODE_POWER }, + { KEYCODE_CAMERA_ETS, KeyCode::key_t::KEYCODE_CAMERA }, + { KEYCODE_VOLUME_MUTE_ETS, KeyCode::key_t::KEYCODE_VOLUME_MUTE }, + { KEYCODE_MUTE_ETS, KeyCode::key_t::KEYCODE_MUTE }, + { KEYCODE_BRIGHTNESS_UP_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_UP }, + { KEYCODE_BRIGHTNESS_DOWN_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_DOWN }, + { KEYCODE_0_ETS, KeyCode::key_t::KEYCODE_0 }, + { KEYCODE_1_ETS, KeyCode::key_t::KEYCODE_1 }, + { KEYCODE_2_ETS, KeyCode::key_t::KEYCODE_2 }, + { KEYCODE_3_ETS, KeyCode::key_t::KEYCODE_3 }, + { KEYCODE_4_ETS, KeyCode::key_t::KEYCODE_4 }, + { KEYCODE_5_ETS, KeyCode::key_t::KEYCODE_5 }, + { KEYCODE_6_ETS, KeyCode::key_t::KEYCODE_6 }, + { KEYCODE_7_ETS, KeyCode::key_t::KEYCODE_7 }, + { KEYCODE_8_ETS, KeyCode::key_t::KEYCODE_8 }, + { KEYCODE_9_ETS, KeyCode::key_t::KEYCODE_9 }, + { KEYCODE_STAR_ETS, KeyCode::key_t::KEYCODE_STAR }, + { KEYCODE_POUND_ETS, KeyCode::key_t::KEYCODE_POUND }, + { KEYCODE_DPAD_UP_ETS, KeyCode::key_t::KEYCODE_DPAD_UP }, + { KEYCODE_DPAD_LEFT_ETS, KeyCode::key_t::KEYCODE_DPAD_LEFT }, + { KEYCODE_DPAD_RIGHT_ETS, KeyCode::key_t::KEYCODE_DPAD_RIGHT }, + { KEYCODE_DPAD_CENTER_ETS, KeyCode::key_t::KEYCODE_DPAD_CENTER }, + { KEYCODE_A_ETS, KeyCode::key_t::KEYCODE_A }, + { KEYCODE_B_ETS, KeyCode::key_t::KEYCODE_B }, + { KEYCODE_C_ETS, KeyCode::key_t::KEYCODE_C }, + { KEYCODE_D_ETS, KeyCode::key_t::KEYCODE_D }, + { KEYCODE_E_ETS, KeyCode::key_t::KEYCODE_E }, + { KEYCODE_F_ETS, KeyCode::key_t::KEYCODE_F }, + { KEYCODE_G_ETS, KeyCode::key_t::KEYCODE_G }, + { KEYCODE_H_ETS, KeyCode::key_t::KEYCODE_H }, + { KEYCODE_I_ETS, KeyCode::key_t::KEYCODE_I }, + { KEYCODE_J_ETS, KeyCode::key_t::KEYCODE_J }, + { KEYCODE_K_ETS, KeyCode::key_t::KEYCODE_K }, + { KEYCODE_L_ETS, KeyCode::key_t::KEYCODE_L }, + { KEYCODE_M_ETS, KeyCode::key_t::KEYCODE_M }, + { KEYCODE_N_ETS, KeyCode::key_t::KEYCODE_N }, + { KEYCODE_O_ETS, KeyCode::key_t::KEYCODE_O }, + { KEYCODE_P_ETS, KeyCode::key_t::KEYCODE_P }, + { KEYCODE_Q_ETS, KeyCode::key_t::KEYCODE_Q }, + { KEYCODE_R_ETS, KeyCode::key_t::KEYCODE_R }, + { KEYCODE_S_ETS, KeyCode::key_t::KEYCODE_S }, + { KEYCODE_T_ETS, KeyCode::key_t::KEYCODE_T }, + { KEYCODE_U_ETS, KeyCode::key_t::KEYCODE_U }, + { KEYCODE_V_ETS, KeyCode::key_t::KEYCODE_V }, + { KEYCODE_W_ETS, KeyCode::key_t::KEYCODE_W }, + { KEYCODE_X_ETS, KeyCode::key_t::KEYCODE_X }, + { KEYCODE_Y_ETS, KeyCode::key_t::KEYCODE_Y }, + { KEYCODE_Z_ETS, KeyCode::key_t::KEYCODE_Z }, + { KEYCODE_COMMA_ETS, KeyCode::key_t::KEYCODE_COMMA }, + { KEYCODE_PERIOD_ETS, KeyCode::key_t::KEYCODE_PERIOD }, + { KEYCODE_ALT_LEFT_ETS, KeyCode::key_t::KEYCODE_ALT_LEFT }, + { KEYCODE_ALT_RIGHT_ETS, KeyCode::key_t::KEYCODE_ALT_RIGHT }, + { KEYCODE_SHIFT_LEFT_ETS, KeyCode::key_t::KEYCODE_SHIFT_LEFT }, + { KEYCODE_SHIFT_RIGHT_ETS, KeyCode::key_t::KEYCODE_SHIFT_RIGHT }, + { KEYCODE_TAB_ETS, KeyCode::key_t::KEYCODE_TAB }, + { KEYCODE_SPACE_ETS, KeyCode::key_t::KEYCODE_SPACE }, + { KEYCODE_SYM_ETS, KeyCode::key_t::KEYCODE_SYM }, + { KEYCODE_EXPLORER_ETS, KeyCode::key_t::KEYCODE_EXPLORER }, + { KEYCODE_ENVELOPE_ETS, KeyCode::key_t::KEYCODE_ENVELOPE }, + { KEYCODE_ENTER_ETS, KeyCode::key_t::KEYCODE_ENTER }, + { KEYCODE_DEL_ETS, KeyCode::key_t::KEYCODE_DEL }, + { KEYCODE_GRAVE_ETS, KeyCode::key_t::KEYCODE_GRAVE }, + { KEYCODE_MINUS_ETS, KeyCode::key_t::KEYCODE_MINUS }, + { KEYCODE_EQUALS_ETS, KeyCode::key_t::KEYCODE_EQUALS }, + { KEYCODE_LEFT_BRACKET_ETS, KeyCode::key_t::KEYCODE_LEFT_BRACKET }, + { KEYCODE_RIGHT_BRACKET_ETS, KeyCode::key_t::KEYCODE_RIGHT_BRACKET }, + { KEYCODE_BACKSLASH_ETS, KeyCode::key_t::KEYCODE_BACKSLASH }, + { KEYCODE_SEMICOLON_ETS, KeyCode::key_t::KEYCODE_SEMICOLON }, + { KEYCODE_APOSTROPHE_ETS, KeyCode::key_t::KEYCODE_APOSTROPHE }, + { KEYCODE_SLASH_ETS, KeyCode::key_t::KEYCODE_SLASH }, + { KEYCODE_AT_ETS, KeyCode::key_t::KEYCODE_AT }, + { KEYCODE_PLUS_ETS, KeyCode::key_t::KEYCODE_PLUS }, + { KEYCODE_MENU_ETS, KeyCode::key_t::KEYCODE_MENU }, + { KEYCODE_PAGE_UP_ETS, KeyCode::key_t::KEYCODE_PAGE_UP }, + { KEYCODE_PAGE_DOWN_ETS, KeyCode::key_t::KEYCODE_PAGE_DOWN }, + { KEYCODE_ESCAPE_ETS, KeyCode::key_t::KEYCODE_ESCAPE }, + { KEYCODE_FORWARD_DEL_ETS, KeyCode::key_t::KEYCODE_FORWARD_DEL }, + { KEYCODE_CTRL_LEFT_ETS, KeyCode::key_t::KEYCODE_CTRL_LEFT }, + { KEYCODE_CTRL_RIGHT_ETS, KeyCode::key_t::KEYCODE_CTRL_RIGHT }, + { KEYCODE_CAPS_LOCK_ETS, KeyCode::key_t::KEYCODE_CAPS_LOCK }, + { KEYCODE_SCROLL_LOCK_ETS, KeyCode::key_t::KEYCODE_SCROLL_LOCK }, + { KEYCODE_META_LEFT_ETS, KeyCode::key_t::KEYCODE_META_LEFT }, + { KEYCODE_META_RIGHT_ETS, KeyCode::key_t::KEYCODE_META_RIGHT }, + { KEYCODE_FUNCTION_ETS, KeyCode::key_t::KEYCODE_FUNCTION }, + { KEYCODE_SYSRQ_ETS, KeyCode::key_t::KEYCODE_SYSRQ }, + { KEYCODE_BREAK_ETS, KeyCode::key_t::KEYCODE_BREAK }, + { KEYCODE_MOVE_HOME_ETS, KeyCode::key_t::KEYCODE_MOVE_HOME }, + { KEYCODE_MOVE_END_ETS, KeyCode::key_t::KEYCODE_MOVE_END }, + { KEYCODE_INSERT_ETS, KeyCode::key_t::KEYCODE_INSERT }, + { KEYCODE_FORWARD_ETS, KeyCode::key_t::KEYCODE_FORWARD }, + { KEYCODE_MEDIA_PLAY_ETS, KeyCode::key_t::KEYCODE_MEDIA_PLAY }, + { KEYCODE_MEDIA_PAUSE_ETS, KeyCode::key_t::KEYCODE_MEDIA_PAUSE }, + { KEYCODE_MEDIA_CLOSE_ETS, KeyCode::key_t::KEYCODE_MEDIA_CLOSE }, + { KEYCODE_MEDIA_EJECT_ETS, KeyCode::key_t::KEYCODE_MEDIA_EJECT }, + { KEYCODE_MEDIA_RECORD_ETS, KeyCode::key_t::KEYCODE_MEDIA_RECORD }, + { KEYCODE_F1_ETS, KeyCode::key_t::KEYCODE_F1 }, + { KEYCODE_F2_ETS, KeyCode::key_t::KEYCODE_F2 }, + { KEYCODE_F3_ETS, KeyCode::key_t::KEYCODE_F3 }, + { KEYCODE_F4_ETS, KeyCode::key_t::KEYCODE_F4 }, + { KEYCODE_F5_ETS, KeyCode::key_t::KEYCODE_F5 }, + { KEYCODE_F6_ETS, KeyCode::key_t::KEYCODE_F6 }, + { KEYCODE_F7_ETS, KeyCode::key_t::KEYCODE_F7 }, + { KEYCODE_F8_ETS, KeyCode::key_t::KEYCODE_F8 }, + { KEYCODE_F9_ETS, KeyCode::key_t::KEYCODE_F9 }, + { KEYCODE_F10_ETS, KeyCode::key_t::KEYCODE_F10 }, + { KEYCODE_F11_ETS, KeyCode::key_t::KEYCODE_F11 }, + { KEYCODE_F12_ETS, KeyCode::key_t::KEYCODE_F12 }, + { KEYCODE_NUM_LOCK_ETS, KeyCode::key_t::KEYCODE_NUM_LOCK }, + { KEYCODE_NUMPAD_0_ETS, KeyCode::key_t::KEYCODE_NUMPAD_0 }, + { KEYCODE_NUMPAD_1_ETS, KeyCode::key_t::KEYCODE_NUMPAD_1 }, + { KEYCODE_NUMPAD_2_ETS, KeyCode::key_t::KEYCODE_NUMPAD_2 }, + { KEYCODE_NUMPAD_3_ETS, KeyCode::key_t::KEYCODE_NUMPAD_3 }, + { KEYCODE_NUMPAD_4_ETS, KeyCode::key_t::KEYCODE_NUMPAD_4 }, + { KEYCODE_NUMPAD_5_ETS, KeyCode::key_t::KEYCODE_NUMPAD_5 }, + { KEYCODE_NUMPAD_6_ETS, KeyCode::key_t::KEYCODE_NUMPAD_6 }, + { KEYCODE_NUMPAD_7_ETS, KeyCode::key_t::KEYCODE_NUMPAD_7 }, + { KEYCODE_NUMPAD_8_ETS, KeyCode::key_t::KEYCODE_NUMPAD_8 }, + { KEYCODE_NUMPAD_9_ETS, KeyCode::key_t::KEYCODE_NUMPAD_9 }, + { KEYCODE_NUMPAD_DIVIDE_ETS, KeyCode::key_t::KEYCODE_NUMPAD_DIVIDE }, + { KEYCODE_NUMPAD_MULTIPLY_ETS, KeyCode::key_t::KEYCODE_NUMPAD_MULTIPLY }, + { KEYCODE_NUMPAD_SUBTRACT_ETS, KeyCode::key_t::KEYCODE_NUMPAD_SUBTRACT }, + { KEYCODE_NUMPAD_ADD_ETS, KeyCode::key_t::KEYCODE_NUMPAD_ADD }, + { KEYCODE_NUMPAD_DOT_ETS, KeyCode::key_t::KEYCODE_NUMPAD_DOT }, + { KEYCODE_NUMPAD_COMMA_ETS, KeyCode::key_t::KEYCODE_NUMPAD_COMMA }, + { KEYCODE_NUMPAD_ENTER_ETS, KeyCode::key_t::KEYCODE_NUMPAD_ENTER }, + { KEYCODE_NUMPAD_EQUALS_ETS, KeyCode::key_t::KEYCODE_NUMPAD_EQUALS }, + { KEYCODE_NUMPAD_LEFT_PAREN_ETS, KeyCode::key_t::KEYCODE_NUMPAD_LEFT_PAREN }, + { KEYCODE_NUMPAD_RIGHT_PAREN_ETS, KeyCode::key_t::KEYCODE_NUMPAD_RIGHT_PAREN }, + { KEYCODE_VIRTUAL_MULTITASK_ETS, KeyCode::key_t::KEYCODE_VIRTUAL_MULTITASK }, + { KEYCODE_BUTTON_A_ETS, KeyCode::key_t::KEYCODE_BUTTON_A }, + { KEYCODE_BUTTON_B_ETS, KeyCode::key_t::KEYCODE_BUTTON_B }, + { KEYCODE_BUTTON_X_ETS, KeyCode::key_t::KEYCODE_BUTTON_X }, + { KEYCODE_BUTTON_Y_ETS, KeyCode::key_t::KEYCODE_BUTTON_Y }, + { KEYCODE_BUTTON_L1_ETS, KeyCode::key_t::KEYCODE_BUTTON_L1 }, + { KEYCODE_BUTTON_R1_ETS, KeyCode::key_t::KEYCODE_BUTTON_R1 }, + { KEYCODE_BUTTON_L2_ETS, KeyCode::key_t::KEYCODE_BUTTON_L2 }, + { KEYCODE_BUTTON_R2_ETS, KeyCode::key_t::KEYCODE_BUTTON_R2 }, + { KEYCODE_BUTTON_SELECT_ETS, KeyCode::key_t::KEYCODE_BUTTON_SELECT }, + { KEYCODE_BUTTON_START_ETS, KeyCode::key_t::KEYCODE_BUTTON_START }, + { KEYCODE_BUTTON_MODE_ETS, KeyCode::key_t::KEYCODE_BUTTON_MODE }, + { KEYCODE_BUTTON_THUMBL_ETS, KeyCode::key_t::KEYCODE_BUTTON_THUMBL }, + { KEYCODE_BUTTON_THUMBR_ETS, KeyCode::key_t::KEYCODE_BUTTON_THUMBR }, + { KEYCODE_SLEEP_ETS, KeyCode::key_t::KEYCODE_SLEEP }, + { KEYCODE_ZENKAKU_HANKAKU_ETS, KeyCode::key_t::KEYCODE_ZENKAKU_HANKAKU }, + { KEYCODE_102ND_ETS, KeyCode::key_t::KEYCODE_102ND }, + { KEYCODE_RO_ETS, KeyCode::key_t::KEYCODE_RO }, + { KEYCODE_KATAKANA_ETS, KeyCode::key_t::KEYCODE_KATAKANA }, + { KEYCODE_HIRAGANA_ETS, KeyCode::key_t::KEYCODE_HIRAGANA }, + { KEYCODE_HENKAN_ETS, KeyCode::key_t::KEYCODE_HENKAN }, + { KEYCODE_KATAKANA_HIRAGANA_ETS, KeyCode::key_t::KEYCODE_KATAKANA_HIRAGANA }, + { KEYCODE_MUHENKAN_ETS, KeyCode::key_t::KEYCODE_MUHENKAN }, + { KEYCODE_LINEFEED_ETS, KeyCode::key_t::KEYCODE_LINEFEED }, + { KEYCODE_MACRO_ETS, KeyCode::key_t::KEYCODE_MACRO }, + { KEYCODE_NUMPAD_PLUSMINUS_ETS, KeyCode::key_t::KEYCODE_NUMPAD_PLUSMINUS }, + { KEYCODE_SCALE_ETS, KeyCode::key_t::KEYCODE_SCALE }, + { KEYCODE_HANGUEL_ETS, KeyCode::key_t::KEYCODE_HANGUEL }, + { KEYCODE_HANJA_ETS, KeyCode::key_t::KEYCODE_HANJA }, + { KEYCODE_YEN_ETS, KeyCode::key_t::KEYCODE_YEN }, + { KEYCODE_STOP_ETS, KeyCode::key_t::KEYCODE_STOP }, + { KEYCODE_AGAIN_ETS, KeyCode::key_t::KEYCODE_AGAIN }, + { KEYCODE_PROPS_ETS, KeyCode::key_t::KEYCODE_PROPS }, + { KEYCODE_UNDO_ETS, KeyCode::key_t::KEYCODE_UNDO }, + { KEYCODE_COPY_ETS, KeyCode::key_t::KEYCODE_COPY }, + { KEYCODE_OPEN_ETS, KeyCode::key_t::KEYCODE_OPEN }, + { KEYCODE_PASTE_ETS, KeyCode::key_t::KEYCODE_PASTE }, + { KEYCODE_FIND_ETS, KeyCode::key_t::KEYCODE_FIND }, + { KEYCODE_CUT_ETS, KeyCode::key_t::KEYCODE_CUT }, + { KEYCODE_HELP_ETS, KeyCode::key_t::KEYCODE_HELP }, + { KEYCODE_CALC_ETS, KeyCode::key_t::KEYCODE_CALC }, + { KEYCODE_FILE_ETS, KeyCode::key_t::KEYCODE_FILE }, + { KEYCODE_BOOKMARKS_ETS, KeyCode::key_t::KEYCODE_BOOKMARKS }, + { KEYCODE_NEXT_ETS, KeyCode::key_t::KEYCODE_NEXT }, + { KEYCODE_PLAYPAUSE_ETS, KeyCode::key_t::KEYCODE_PLAYPAUSE }, + { KEYCODE_PREVIOUS_ETS, KeyCode::key_t::KEYCODE_PREVIOUS }, + { KEYCODE_STOPCD_ETS, KeyCode::key_t::KEYCODE_STOPCD }, + { KEYCODE_CONFIG_ETS, KeyCode::key_t::KEYCODE_CONFIG }, + { KEYCODE_REFRESH_ETS, KeyCode::key_t::KEYCODE_REFRESH }, + { KEYCODE_EXIT_ETS, KeyCode::key_t::KEYCODE_EXIT }, + { KEYCODE_EDIT_ETS, KeyCode::key_t::KEYCODE_EDIT }, + { KEYCODE_SCROLLUP_ETS, KeyCode::key_t::KEYCODE_SCROLLUP }, + { KEYCODE_SCROLLDOWN_ETS, KeyCode::key_t::KEYCODE_SCROLLDOWN }, + { KEYCODE_NEW_ETS, KeyCode::key_t::KEYCODE_NEW }, + { KEYCODE_REDO_ETS, KeyCode::key_t::KEYCODE_REDO }, + { KEYCODE_CLOSE_ETS, KeyCode::key_t::KEYCODE_CLOSE }, + { KEYCODE_PLAY_ETS, KeyCode::key_t::KEYCODE_PLAY }, + { KEYCODE_BASSBOOST_ETS, KeyCode::key_t::KEYCODE_BASSBOOST }, + { KEYCODE_PRINT_ETS, KeyCode::key_t::KEYCODE_PRINT }, + { KEYCODE_CHAT_ETS, KeyCode::key_t::KEYCODE_CHAT }, + { KEYCODE_FINANCE_ETS, KeyCode::key_t::KEYCODE_FINANCE }, + { KEYCODE_CANCEL_ETS, KeyCode::key_t::KEYCODE_CANCEL }, + { KEYCODE_KBDILLUM_TOGGLE_ETS, KeyCode::key_t::KEYCODE_KBDILLUM_TOGGLE }, + { KEYCODE_KBDILLUM_DOWN_ETS, KeyCode::key_t::KEYCODE_KBDILLUM_DOWN }, + { KEYCODE_KBDILLUM_UP_ETS, KeyCode::key_t::KEYCODE_KBDILLUM_UP }, + { KEYCODE_SEND_ETS, KeyCode::key_t::KEYCODE_SEND }, + { KEYCODE_REPLY_ETS, KeyCode::key_t::KEYCODE_REPLY }, + { KEYCODE_FORWARDMAIL_ETS, KeyCode::key_t::KEYCODE_FORWARDMAIL }, + { KEYCODE_SAVE_ETS, KeyCode::key_t::KEYCODE_SAVE }, + { KEYCODE_DOCUMENTS_ETS, KeyCode::key_t::KEYCODE_DOCUMENTS }, + { KEYCODE_VIDEO_NEXT_ETS, KeyCode::key_t::KEYCODE_VIDEO_NEXT }, + { KEYCODE_VIDEO_PREV_ETS, KeyCode::key_t::KEYCODE_VIDEO_PREV }, + { KEYCODE_BRIGHTNESS_CYCLE_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_CYCLE }, + { KEYCODE_BRIGHTNESS_ZERO_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_ZERO }, + { KEYCODE_DISPLAY_OFF_ETS, KeyCode::key_t::KEYCODE_DISPLAY_OFF }, + { KEYCODE_BTN_MISC_ETS, KeyCode::key_t::KEYCODE_BTN_MISC }, + { KEYCODE_GOTO_ETS, KeyCode::key_t::KEYCODE_GOTO }, + { KEYCODE_INFO_ETS, KeyCode::key_t::KEYCODE_INFO }, + { KEYCODE_PROGRAM_ETS, KeyCode::key_t::KEYCODE_PROGRAM }, + { KEYCODE_PVR_ETS, KeyCode::key_t::KEYCODE_PVR }, + { KEYCODE_SUBTITLE_ETS, KeyCode::key_t::KEYCODE_SUBTITLE }, + { KEYCODE_FULL_SCREEN_ETS, KeyCode::key_t::KEYCODE_FULL_SCREEN }, + { KEYCODE_KEYBOARD_ETS, KeyCode::key_t::KEYCODE_KEYBOARD }, + { KEYCODE_ASPECT_RATIO_ETS, KeyCode::key_t::KEYCODE_ASPECT_RATIO }, + { KEYCODE_PC_ETS, KeyCode::key_t::KEYCODE_PC }, + { KEYCODE_TV_ETS, KeyCode::key_t::KEYCODE_TV }, + { KEYCODE_TV2_ETS, KeyCode::key_t::KEYCODE_TV2 }, + { KEYCODE_VCR_ETS, KeyCode::key_t::KEYCODE_VCR }, + { KEYCODE_VCR2_ETS, KeyCode::key_t::KEYCODE_VCR2 }, + { KEYCODE_SAT_ETS, KeyCode::key_t::KEYCODE_SAT }, + { KEYCODE_CD_ETS, KeyCode::key_t::KEYCODE_CD }, + { KEYCODE_TAPE_ETS, KeyCode::key_t::KEYCODE_TAPE }, + { KEYCODE_TUNER_ETS, KeyCode::key_t::KEYCODE_TUNER }, + { KEYCODE_PLAYER_ETS, KeyCode::key_t::KEYCODE_PLAYER }, + { KEYCODE_DVD_ETS, KeyCode::key_t::KEYCODE_DVD }, + { KEYCODE_AUDIO_ETS, KeyCode::key_t::KEYCODE_AUDIO }, + { KEYCODE_VIDEO_ETS, KeyCode::key_t::KEYCODE_VIDEO }, + { KEYCODE_MEMO_ETS, KeyCode::key_t::KEYCODE_MEMO }, + { KEYCODE_CALENDAR_ETS, KeyCode::key_t::KEYCODE_CALENDAR }, + { KEYCODE_RED_ETS, KeyCode::key_t::KEYCODE_RED }, + { KEYCODE_GREEN_ETS, KeyCode::key_t::KEYCODE_GREEN }, + { KEYCODE_YELLOW_ETS, KeyCode::key_t::KEYCODE_YELLOW }, + { KEYCODE_BLUE_ETS, KeyCode::key_t::KEYCODE_BLUE }, + { KEYCODE_CHANNELUP_ETS, KeyCode::key_t::KEYCODE_CHANNELUP }, + { KEYCODE_CHANNELDOWN_ETS, KeyCode::key_t::KEYCODE_CHANNELDOWN }, + { KEYCODE_LAST_ETS, KeyCode::key_t::KEYCODE_LAST }, + { KEYCODE_RESTART_ETS, KeyCode::key_t::KEYCODE_RESTART }, + { KEYCODE_SLOW_ETS, KeyCode::key_t::KEYCODE_SLOW }, + { KEYCODE_SHUFFLE_ETS, KeyCode::key_t::KEYCODE_SHUFFLE }, + { KEYCODE_VIDEOPHONE_ETS, KeyCode::key_t::KEYCODE_VIDEOPHONE }, + { KEYCODE_GAMES_ETS, KeyCode::key_t::KEYCODE_GAMES }, + { KEYCODE_ZOOMIN_ETS, KeyCode::key_t::KEYCODE_ZOOMIN }, + { KEYCODE_ZOOMOUT_ETS, KeyCode::key_t::KEYCODE_ZOOMOUT }, + { KEYCODE_ZOOMRESET_ETS, KeyCode::key_t::KEYCODE_ZOOMRESET }, + { KEYCODE_WORDPROCESSOR_ETS, KeyCode::key_t::KEYCODE_WORDPROCESSOR }, + { KEYCODE_EDITOR_ETS, KeyCode::key_t::KEYCODE_EDITOR }, + { KEYCODE_SPREADSHEET_ETS, KeyCode::key_t::KEYCODE_SPREADSHEET }, + { KEYCODE_GRAPHICSEDITOR_ETS, KeyCode::key_t::KEYCODE_GRAPHICSEDITOR }, + { KEYCODE_PRESENTATION_ETS, KeyCode::key_t::KEYCODE_PRESENTATION }, + { KEYCODE_DATABASE_ETS, KeyCode::key_t::KEYCODE_DATABASE }, + { KEYCODE_NEWS_ETS, KeyCode::key_t::KEYCODE_NEWS }, + { KEYCODE_VOICEMAIL_ETS, KeyCode::key_t::KEYCODE_VOICEMAIL }, + { KEYCODE_ADDRESSBOOK_ETS, KeyCode::key_t::KEYCODE_ADDRESSBOOK }, + { KEYCODE_MESSENGER_ETS, KeyCode::key_t::KEYCODE_MESSENGER }, + { KEYCODE_BRIGHTNESS_TOGGLE_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_TOGGLE }, + { KEYCODE_SPELLCHECK_ETS, KeyCode::key_t::KEYCODE_SPELLCHECK }, + { KEYCODE_COFFEE_ETS, KeyCode::key_t::KEYCODE_COFFEE }, + { KEYCODE_MEDIA_REPEAT_ETS, KeyCode::key_t::KEYCODE_MEDIA_REPEAT }, + { KEYCODE_IMAGES_ETS, KeyCode::key_t::KEYCODE_IMAGES }, + { KEYCODE_BUTTONCONFIG_ETS, KeyCode::key_t::KEYCODE_BUTTONCONFIG }, + { KEYCODE_TASKMANAGER_ETS, KeyCode::key_t::KEYCODE_TASKMANAGER }, + { KEYCODE_JOURNAL_ETS, KeyCode::key_t::KEYCODE_JOURNAL }, + { KEYCODE_CONTROLPANEL_ETS, KeyCode::key_t::KEYCODE_CONTROLPANEL }, + { KEYCODE_APPSELECT_ETS, KeyCode::key_t::KEYCODE_APPSELECT }, + { KEYCODE_SCREENSAVER_ETS, KeyCode::key_t::KEYCODE_SCREENSAVER }, + { KEYCODE_ASSISTANT_ETS, KeyCode::key_t::KEYCODE_ASSISTANT }, + { KEYCODE_KBD_LAYOUT_NEXT_ETS, KeyCode::key_t::KEYCODE_KBD_LAYOUT_NEXT }, + { KEYCODE_BRIGHTNESS_MIN_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_MIN }, + { KEYCODE_BRIGHTNESS_MAX_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_MAX }, + { KEYCODE_KBDINPUTASSIST_PREV_ETS, KeyCode::key_t::KEYCODE_KBDINPUTASSIST_PREV }, + { KEYCODE_KBDINPUTASSIST_NEXT_ETS, KeyCode::key_t::KEYCODE_KBDINPUTASSIST_NEXT }, + { KEYCODE_KBDINPUTASSIST_PREVGROUP_ETS, KeyCode::key_t::KEYCODE_KBDINPUTASSIST_PREVGROUP }, + { KEYCODE_KBDINPUTASSIST_NEXTGROUP_ETS, KeyCode::key_t::KEYCODE_KBDINPUTASSIST_NEXTGROUP }, + { KEYCODE_KBDINPUTASSIST_ACCEPT_ETS, KeyCode::key_t::KEYCODE_KBDINPUTASSIST_ACCEPT }, + { KEYCODE_KBDINPUTASSIST_CANCEL_ETS, KeyCode::key_t::KEYCODE_KBDINPUTASSIST_CANCEL }, + { KEYCODE_FRONT_ETS, KeyCode::key_t::KEYCODE_FRONT }, + { KEYCODE_SETUP_ETS, KeyCode::key_t::KEYCODE_SETUP }, + { KEYCODE_WAKEUP_ETS, KeyCode::key_t::KEYCODE_WAKEUP }, + { KEYCODE_SENDFILE_ETS, KeyCode::key_t::KEYCODE_SENDFILE }, + { KEYCODE_DELETEFILE_ETS, KeyCode::key_t::KEYCODE_DELETEFILE }, + { KEYCODE_XFER_ETS, KeyCode::key_t::KEYCODE_XFER }, + { KEYCODE_PROG1_ETS, KeyCode::key_t::KEYCODE_PROG1 }, + { KEYCODE_PROG2_ETS, KeyCode::key_t::KEYCODE_PROG2 }, + { KEYCODE_MSDOS_ETS, KeyCode::key_t::KEYCODE_MSDOS }, + { KEYCODE_SCREENLOCK_ETS, KeyCode::key_t::KEYCODE_SCREENLOCK }, + { KEYCODE_DIRECTION_ROTATE_DISPLAY_ETS, KeyCode::key_t::KEYCODE_DIRECTION_ROTATE_DISPLAY }, + { KEYCODE_CYCLEWINDOWS_ETS, KeyCode::key_t::KEYCODE_CYCLEWINDOWS }, + { KEYCODE_COMPUTER_ETS, KeyCode::key_t::KEYCODE_COMPUTER }, + { KEYCODE_EJECTCLOSECD_ETS, KeyCode::key_t::KEYCODE_EJECTCLOSECD }, + { KEYCODE_ISO_ETS, KeyCode::key_t::KEYCODE_ISO }, + { KEYCODE_MOVE_ETS, KeyCode::key_t::KEYCODE_MOVE }, + { KEYCODE_F13_ETS, KeyCode::key_t::KEYCODE_F13 }, + { KEYCODE_F14_ETS, KeyCode::key_t::KEYCODE_F14 }, + { KEYCODE_F15_ETS, KeyCode::key_t::KEYCODE_F15 }, + { KEYCODE_F16_ETS, KeyCode::key_t::KEYCODE_F16 }, + { KEYCODE_F17_ETS, KeyCode::key_t::KEYCODE_F17 }, + { KEYCODE_F18_ETS, KeyCode::key_t::KEYCODE_F18 }, + { KEYCODE_F19_ETS, KeyCode::key_t::KEYCODE_F19 }, + { KEYCODE_F20_ETS, KeyCode::key_t::KEYCODE_F20 }, + { KEYCODE_F21_ETS, KeyCode::key_t::KEYCODE_F21 }, + { KEYCODE_F22_ETS, KeyCode::key_t::KEYCODE_F22 }, + { KEYCODE_F23_ETS, KeyCode::key_t::KEYCODE_F23 }, + { KEYCODE_F24_ETS, KeyCode::key_t::KEYCODE_F24 }, + { KEYCODE_PROG3_ETS, KeyCode::key_t::KEYCODE_PROG3 }, + { KEYCODE_PROG4_ETS, KeyCode::key_t::KEYCODE_PROG4 }, + { KEYCODE_DASHBOARD_ETS, KeyCode::key_t::KEYCODE_DASHBOARD }, + { KEYCODE_SUSPEND_ETS, KeyCode::key_t::KEYCODE_SUSPEND }, + { KEYCODE_HP_ETS, KeyCode::key_t::KEYCODE_HP }, + { KEYCODE_SOUND_ETS, KeyCode::key_t::KEYCODE_SOUND }, + { KEYCODE_QUESTION_ETS, KeyCode::key_t::KEYCODE_QUESTION }, + { KEYCODE_CONNECT_ETS, KeyCode::key_t::KEYCODE_CONNECT }, + { KEYCODE_SPORT_ETS, KeyCode::key_t::KEYCODE_SPORT }, + { KEYCODE_SHOP_ETS, KeyCode::key_t::KEYCODE_SHOP }, + { KEYCODE_ALTERASE_ETS, KeyCode::key_t::KEYCODE_ALTERASE }, + { KEYCODE_SWITCHVIDEOMODE_ETS, KeyCode::key_t::KEYCODE_SWITCHVIDEOMODE }, + { KEYCODE_BATTERY_ETS, KeyCode::key_t::KEYCODE_BATTERY }, + { KEYCODE_BLUETOOTH_ETS, KeyCode::key_t::KEYCODE_BLUETOOTH }, + { KEYCODE_WLAN_ETS, KeyCode::key_t::KEYCODE_WLAN }, + { KEYCODE_UWB_ETS, KeyCode::key_t::KEYCODE_UWB }, + { KEYCODE_WWAN_WIMAX_ETS, KeyCode::key_t::KEYCODE_WWAN_WIMAX }, + { KEYCODE_RFKILL_ETS, KeyCode::key_t::KEYCODE_RFKILL }, + { KEYCODE_CHANNEL_ETS, KeyCode::key_t::KEYCODE_CHANNEL }, + { KEYCODE_BTN_0_ETS, KeyCode::key_t::KEYCODE_BTN_0 }, + { KEYCODE_BTN_1_ETS, KeyCode::key_t::KEYCODE_BTN_1 }, + { KEYCODE_BTN_2_ETS, KeyCode::key_t::KEYCODE_BTN_2 }, + { KEYCODE_BTN_3_ETS, KeyCode::key_t::KEYCODE_BTN_3 }, + { KEYCODE_BTN_4_ETS, KeyCode::key_t::KEYCODE_BTN_4 }, + { KEYCODE_BTN_5_ETS, KeyCode::key_t::KEYCODE_BTN_5 }, + { KEYCODE_BTN_6_ETS, KeyCode::key_t::KEYCODE_BTN_6 }, + { KEYCODE_BTN_7_ETS, KeyCode::key_t::KEYCODE_BTN_7 }, + { KEYCODE_BTN_8_ETS, KeyCode::key_t::KEYCODE_BTN_8 }, + { KEYCODE_BTN_9_ETS, KeyCode::key_t::KEYCODE_BTN_9 }, + { KEYCODE_DAGGER_CLICK_ETS, KeyCode::key_t::KEYCODE_DAGGER_CLICK }, + { KEYCODE_DAGGER_DOUBLE_CLICK_ETS, KeyCode::key_t::KEYCODE_DAGGER_DOUBLE_CLICK }, + { KEYCODE_DAGGER_LONG_PRESS_ETS, KeyCode::key_t::KEYCODE_DAGGER_LONG_PRESS } +}; + +struct DeviceType { + std::string sourceTypeName; + uint32_t typeBit { 0 }; +}; + +DeviceType g_deviceType[] = { + { "keyboard", EVDEV_TAG_KEYBOARD }, + { "mouse", EVDEV_TAG_MOUSE }, + { "touchpad", EVDEV_TAG_TOUCHPAD }, + { "touchscreen", EVDEV_TAG_TOUCHSCREEN }, + { "joystick", EVDEV_TAG_JOYSTICK }, + { "trackball", EVDEV_TAG_TRACKBALL }, +}; + +std::unordered_map g_axisType = { + { ABS_MT_TOUCH_MAJOR, "touchmajor" }, + { ABS_MT_TOUCH_MINOR, "touchminor" }, + { ABS_MT_ORIENTATION, "orientation" }, + { ABS_MT_POSITION_X, "x" }, + { ABS_MT_POSITION_Y, "y" }, + { ABS_MT_PRESSURE, "pressure" }, + { ABS_MT_WIDTH_MAJOR, "toolmajor" }, + { ABS_MT_WIDTH_MINOR, "toolminor" }, +}; + class TaiheConverter { public: + static bool GetApiError(int32_t code, TaiheError &codeMsg); + static KeyCode ConvertEtsKeyCode(int32_t keyCode); + static KeyCodeEts GetKeyCodeByValue(const std::map& map, KeyCode code); + static TaihesType ConverterSType(const std::string &sourceType); + static TaiheaType ConverterATxis(const std::string &axisType); + static TaiheSType ConverterSourceType(const TaihesType &sType); + static TaiheAType ConverterAxisType(const TaiheaType &aType); + static TaiheAxisRange ConverterAxisRange(const InputDevice::AxisInfo &axisInfo, + const std::string &sourceType, const std::string &axisType); + static TaiheInputDeviceData ConverterInputDeviceType(InputDevice &device); + static TaiheTouchEvent TouchEventToTaihe(const PointerEvent &pointerEvent); static TaiheInputEvent InputEventToTaihe(const InputEvent &inputEvent); static TaiheTouchAction TouchActionToTaihe(int32_t action); diff --git a/frameworks/ets/common/src/ani_common.cpp b/frameworks/ets/common/src/ani_common.cpp index cedb571444..4d40b3a891 100644 --- a/frameworks/ets/common/src/ani_common.cpp +++ b/frameworks/ets/common/src/ani_common.cpp @@ -17,6 +17,108 @@ #define RET_ERR -1 namespace OHOS { namespace MMI { +bool TaiheConverter::GetApiError(int32_t code, TaiheError &codeMsg) +{ + auto iter = TAIHE_ERRORS.find(code); + if (iter == TAIHE_ERRORS.end()) { + return false; + } + codeMsg = iter->second; + return true; +} + +KeyCode TaiheConverter::ConvertEtsKeyCode(int32_t keyCode) +{ + auto iter = KEY_CODE_TRANSFORMATION.find(keyCode); + if (iter == KEY_CODE_TRANSFORMATION.end()) { + return KeyCode::key_t::KEYCODE_UNKNOWN; + } + return iter->second; +} + +KeyCodeEts TaiheConverter::GetKeyCodeByValue(const std::map& map, KeyCode code) +{ + for (const auto& [key, val] : map) { + if (val == code) { + return static_cast(key); + } + } + return KEYCODE_UNKNOWN_ETS; +} + +TaihesType TaiheConverter::ConverterSType(const std::string &sourceType) +{ + return ohos::multimodalInput::inputDevice::sourceType::from_value(sourceType); +} + +TaiheaType TaiheConverter::ConverterATxis(const std::string &axisType) +{ + return ohos::multimodalInput::inputDevice::axisType::from_value(axisType); +} + +TaiheSType TaiheConverter::ConverterSourceType(const TaihesType &sType) +{ + TaiheSType result = TaiheSType::make_type(sType); + return result; +} +TaiheAType TaiheConverter::ConverterAxisType(const TaiheaType &aType) +{ + TaiheAType result = TaiheAType::make_type(aType); + return result; +} + +TaiheAxisRange TaiheConverter::ConverterAxisRange(const InputDevice::AxisInfo &axisInfo, + const std::string &sourceType, const std::string &axisType) +{ + TaiheAxisRange result { + .source = ConverterSourceType(ConverterSType(sourceType)), + .axis = ConverterAxisType(ConverterATxis(axisType)), + }; + result.max = axisInfo.GetMaximum(); + result.min = axisInfo.GetMinimum(); + result.fuzz = axisInfo.GetFuzz(); + result.flat = axisInfo.GetFlat(); + result.resolution = axisInfo.GetResolution(); + return result; +} + +TaiheInputDeviceData TaiheConverter::ConverterInputDeviceType(InputDevice &device) +{ + TaiheInputDeviceData result {}; + result.id = device.GetId(); + result.name = device.GetName(); + std::vector vecSourceTypes; + std::string sourceType = ""; + uint32_t types = static_cast(device.GetType()); + for (auto item : g_deviceType) { + if (types &item.typeBit) { + sourceType = item.sourceTypeName; + vecSourceTypes.push_back(ConverterSourceType(ConverterSType(sourceType))); + } + } + result.sources = taihe::array(vecSourceTypes); + std::string axisType = ""; + std::vector vecAxisRanges; + auto aixsArray = device.GetAxisInfo(); + for (auto item : aixsArray) { + auto iter = g_axisType.find(item.GetAxisType()); + if (iter != g_axisType.end()) { + axisType = iter->second; + } + TaiheAxisRange axisRange = ConverterAxisRange(item, sourceType, axisType); + vecAxisRanges.push_back(axisRange); + } + result.axisRanges = taihe::array(vecAxisRanges); + result.bus = device.GetBus(); + result.product = device.GetProduct(); + result.vendor = device.GetVendor(); + result.version = device.GetVersion(); + result.phys = std::string_view(device.GetPhys()); + result.uniq = std::string_view(device.GetUniq()); + return result; + +} + TaiheTouchEvent TaiheConverter::TouchEventToTaihe(const PointerEvent &pointerEvent) { TaiheTouchEvent result {.action = TaiheTouchAction::key_t::CANCEL, diff --git a/frameworks/ets/input_consumer/BUILD.gn b/frameworks/ets/input_consumer/BUILD.gn index 6977509744..4800ccf02f 100644 --- a/frameworks/ets/input_consumer/BUILD.gn +++ b/frameworks/ets/input_consumer/BUILD.gn @@ -24,7 +24,7 @@ config("inputConsumer_config") { include_dirs = [ "include", - "${mmi_path}/frameworks/ets/key_code/include" + "${mmi_path}/frameworks/ets/common/include" ] } subsystem_name = "multimodalinput" @@ -63,6 +63,7 @@ taihe_shared_library("InputConsumer") { ":run_taihe", "${mmi_path}/frameworks/proxy:libmmi-client", "${mmi_path}/util:libmmi-util", + "${mmi_path}/frameworks/ets/common:ets_inputcommon_package", ] branch_protector_ret = "pac_ret" sanitize = { diff --git a/frameworks/ets/input_consumer/include/inputConsumer_keyPressed_impl.h b/frameworks/ets/input_consumer/include/inputConsumer_keyPressed_impl.h index 3ee7ea743b..ff196ddbf2 100644 --- a/frameworks/ets/input_consumer/include/inputConsumer_keyPressed_impl.h +++ b/frameworks/ets/input_consumer/include/inputConsumer_keyPressed_impl.h @@ -23,7 +23,6 @@ #include "define_multimodal.h" #include "input_manager.h" -#include "ohos.multimodalInput.keyCode.impl.h" namespace OHOS { namespace MMI { diff --git a/frameworks/ets/input_consumer/src/inputConsumer_keyPressed_impl.cpp b/frameworks/ets/input_consumer/src/inputConsumer_keyPressed_impl.cpp index 1a71cae4c5..cd8f32983f 100644 --- a/frameworks/ets/input_consumer/src/inputConsumer_keyPressed_impl.cpp +++ b/frameworks/ets/input_consumer/src/inputConsumer_keyPressed_impl.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "ani_common.h" #include "inputConsumer_keyPressed_impl.h" #undef MMI_LOG_TAG @@ -80,7 +81,7 @@ ohos::multimodalInput::keyEvent::Action ConverKeyAction(EtsKeyAction action) ohos::multimodalInput::keyEvent::Key KeyItemEtsKey(const KeyEvent::KeyItem &keyItem) { return { - ConvertEtsKeyCode(keyItem.GetKeyCode()), + TaiheConverter::ConvertEtsKeyCode(keyItem.GetKeyCode()), keyItem.GetDownTime(), keyItem.GetDeviceId() }; -- Gitee From ff9e77dbbbe0b661a6b65e0a4ac09683a779e1c0 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Thu, 24 Jul 2025 16:25:38 +0800 Subject: [PATCH 07/29] =?UTF-8?q?lmq=E5=A2=9E=E5=8A=A0inputDevice=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- frameworks/ets/common/include/ani_common.h | 4 +- frameworks/ets/common/src/ani_common.cpp | 25 +- frameworks/ets/input_device/BUILD.gn | 4 +- .../ohos.multimodalInput.inputDevice.taihe | 66 ++- .../ohos.multimodalInput.inputDevice.impl.cpp | 510 +++++++++++++++++- 5 files changed, 592 insertions(+), 17 deletions(-) diff --git a/frameworks/ets/common/include/ani_common.h b/frameworks/ets/common/include/ani_common.h index e3c24240a9..e9f441a18b 100644 --- a/frameworks/ets/common/include/ani_common.h +++ b/frameworks/ets/common/include/ani_common.h @@ -104,7 +104,7 @@ const std::map TAIHE_ERRORS = { { INPUT_OCCUPIED_BY_OTHER, { INPUT_OCCUPIED_BY_OTHER, "The hotkey has been subscribed by other one." } }, }; - enum KeyCodeEts { +enum KeyCodeEts { KEYCODE_FN_ETS = 0, KEYCODE_UNKNOWN_ETS = -1, KEYCODE_HOME_ETS = 1, @@ -839,7 +839,7 @@ public: static TaiheAType ConverterAxisType(const TaiheaType &aType); static TaiheAxisRange ConverterAxisRange(const InputDevice::AxisInfo &axisInfo, const std::string &sourceType, const std::string &axisType); - static TaiheInputDeviceData ConverterInputDeviceType(InputDevice &device); + static TaiheInputDeviceData ConverterInputDevice(std::shared_ptr &device); static TaiheTouchEvent TouchEventToTaihe(const PointerEvent &pointerEvent); static TaiheInputEvent InputEventToTaihe(const InputEvent &inputEvent); diff --git a/frameworks/ets/common/src/ani_common.cpp b/frameworks/ets/common/src/ani_common.cpp index 4d40b3a891..2c88b84ff6 100644 --- a/frameworks/ets/common/src/ani_common.cpp +++ b/frameworks/ets/common/src/ani_common.cpp @@ -82,14 +82,17 @@ TaiheAxisRange TaiheConverter::ConverterAxisRange(const InputDevice::AxisInfo &a return result; } -TaiheInputDeviceData TaiheConverter::ConverterInputDeviceType(InputDevice &device) +TaiheInputDeviceData TaiheConverter::ConverterInputDevice(std::shared_ptr &device) { TaiheInputDeviceData result {}; - result.id = device.GetId(); - result.name = device.GetName(); + if (device == nullptr) { + return result; + } + result.id = device->GetId(); + result.name = device->GetName(); std::vector vecSourceTypes; std::string sourceType = ""; - uint32_t types = static_cast(device.GetType()); + uint32_t types = static_cast(device->GetType()); for (auto item : g_deviceType) { if (types &item.typeBit) { sourceType = item.sourceTypeName; @@ -99,7 +102,7 @@ TaiheInputDeviceData TaiheConverter::ConverterInputDeviceType(InputDevice &devic result.sources = taihe::array(vecSourceTypes); std::string axisType = ""; std::vector vecAxisRanges; - auto aixsArray = device.GetAxisInfo(); + auto aixsArray = device->GetAxisInfo(); for (auto item : aixsArray) { auto iter = g_axisType.find(item.GetAxisType()); if (iter != g_axisType.end()) { @@ -109,12 +112,12 @@ TaiheInputDeviceData TaiheConverter::ConverterInputDeviceType(InputDevice &devic vecAxisRanges.push_back(axisRange); } result.axisRanges = taihe::array(vecAxisRanges); - result.bus = device.GetBus(); - result.product = device.GetProduct(); - result.vendor = device.GetVendor(); - result.version = device.GetVersion(); - result.phys = std::string_view(device.GetPhys()); - result.uniq = std::string_view(device.GetUniq()); + result.bus = device->GetBus(); + result.product = device->GetProduct(); + result.vendor = device->GetVendor(); + result.version = device->GetVersion(); + result.phys = std::string_view(device->GetPhys()); + result.uniq = std::string_view(device->GetUniq()); return result; } diff --git a/frameworks/ets/input_device/BUILD.gn b/frameworks/ets/input_device/BUILD.gn index 2992e60576..c6f7a1be96 100644 --- a/frameworks/ets/input_device/BUILD.gn +++ b/frameworks/ets/input_device/BUILD.gn @@ -22,8 +22,7 @@ config("inputDevice_config") { include_dirs = [ "${mmi_path}/util/common/include", "${mmi_path}/util/network/include", - "${mmi_path}/frameworks/proxy/event_handler/include", - "${mmi_path}/frameworks/proxy/moudle_loader/include", + "${mmi_path}/frameworks/ets/common/include" ] } subsystem_name = "multimodalinput" @@ -54,6 +53,7 @@ taihe_shared_library("InputDevice") { ":run_taihe", "${mmi_path}/frameworks/proxy:libmmi-client", "${mmi_path}/util:libmmi-util", + "${mmi_path}/frameworks/ets/common:ets_inputcommon_package", ] external_deps = [ "c_utils:utils", diff --git a/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe b/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe index 9ba237e076..3040093048 100644 --- a/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe +++ b/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe @@ -18,6 +18,8 @@ static { loadLibrary("InputDevice.z") } """) +from ohos.multimodalInput.keyCode use KeyCode; + enum changedType: String { ADD = "add", REMOVE = "remove" @@ -93,4 +95,66 @@ struct InputDeviceData { version: i32; phys: String; uniq: String; -} \ No newline at end of file +} + +// ѷ +@gen_async("getDeviceIds") +@gen_promise("getDeviceIds") +function GetDeviceIdsAsync(): i32; + +// ѷ +@gen_async("getDevice") +@gen_promise("getDevice") +function GetDeviceAsync(deviceId: i32): InputDeviceData; + +@gen_async("getDeviceInfo") +@gen_promise("getDeviceInfo") +function GetDeviceInfoAsync(deviceId: i32): InputDeviceData; + +@gen_async("supportKeys") +@gen_promise("supportKeys") +function SupportKeysAsync(deviceId: i32, keys: Array): Array; + +@gen_async("setKeyboardRepeatDelay") +@gen_promise("setKeyboardRepeatDelay") +function SetKeyboardRepeatDelayAsync(delay: i32): void; + +@gen_async("getKeyboardRepeatDelay") +@gen_promise("getKeyboardRepeatDelay") +function GetKeyboardRepeatDelayAsync(): i32; + +@gen_async("setKeyboardRepeatRate") +@gen_promise("setKeyboardRepeatRate") +function SetKeyboardRepeatRateAsync(rate: i32): void; + +@gen_async("getKeyboardRepeatRate") +@gen_promise("getKeyboardRepeatRate") +function GetKeyboardRepeatRateAsync(): i32; + +@gen_promise("getIntervalSinceLastInput") +function GetIntervalSinceLastInputAsync(): i64; + +@gen_promise("setFunctionKeyEnabled") +function SetFunctionKeyEnabledAsync(functionKey: FunctionKey, enabled: bool): void; + +@gen_promise("setInputDeviceEnabled") +function SetInputDeviceEnabledAsync(deviceId: i32, enabled: bool): void; + +function GetKeyboardTypeSync(deviceId: i32): KeyboardType; + +function SupportKeysSync(deviceId: i32, keys: Array): Array; + +function GetDeviceInfoSync(deviceId: i32): InputDeviceData; + +/* +@!sts_inject(""" + function on(type: 'change', callback: (info: DeviceListener) => void) { + return onKey(callback, callback); + } + function off(type: 'change', callback?: (info: DeviceListener) => void) { + return offKey(callback); + } +""") +function onKey(f: (info: DeviceListener) => void, opq: Opaque); +function offKey(opq: Optional); +*/ \ No newline at end of file diff --git a/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp b/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp index 7abfd2b660..8dbe44f7f7 100644 --- a/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp +++ b/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp @@ -17,13 +17,521 @@ #include "ohos.multimodalInput.inputDevice.impl.hpp" #include "taihe/runtime.hpp" #include "stdexcept" +#include "input_device.h" +#include "define_multimodal.h" +#include "input_manager.h" +#include +#include "ani_common.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "TaiHeInputDeviceImpl" using namespace taihe; +using namespace OHOS::MMI; using namespace ohos::multimodalInput::inputDevice; +using TaiheKeyCode = ohos::multimodalInput::keyCode::KeyCode; +using TaiheFunctionKey = ohos::multimodalInput::inputDevice::FunctionKey; +// using TaiheDeviceListener = ohos::multimodalInput::inputDevice::DeviceListener; on/off use +using InputDevice_t = OHOS::MMI::InputDevice; +using AxisInfo_t = OHOS::MMI::InputDevice::AxisInfo; +using TaiheError_t = OHOS::MMI::TaiheError; +using InputManager_t = OHOS::MMI::InputManager; namespace { -} // namespace +constexpr uint32_t MIN_N_SIZE { 1 }; +constexpr uint32_t MAX_N_SIZE { 5 }; +constexpr int32_t MIN_KEY_REPEAT_DELAY { 300 }; +constexpr int32_t MAX_KEY_REPEAT_DELAY { 1000 }; +constexpr int32_t MIN_KEY_REPEAT_RATE { 36 }; +constexpr int32_t MAX_KEY_REPEAT_RATE { 100 }; + +// lmq on/off use +/* +enum INPUT_DEVICE_CALLBACK_EVENT { + CALLBACK_EVENT_FAILED = -1, + CALLBACK_EVENT_SUCCESS = 1, + CALLBACK_EVENT_EXIST = 2, + CALLBACK_EVENT_NOT_EXIST = 3, +}; + +using callbackType = std::variant>; + +struct CallbackObject { + CallbackObject(callbackType cb, ani_ref ref) : callback(cb), ref(ref) + { + } + void Release() + { + taihe::env_guard guard; + if (auto *env = guard.get_env()) { + env->GlobalReference_Delete(ref); + } + } + callbackType callback; + ani_ref ref; +}; + +std::map>> changeCbMap_; +std::mutex g_mutex; +size_t g_baseId { 0 }; +std::mutex cbMapMutex; +bool isListeningProcess_ { false }; + +class GlobalRefGuard { + ani_env *env_ = nullptr; + ani_ref ref_ = nullptr; + +public: + GlobalRefGuard(ani_env *env, ani_object obj) : env_(env) + { + if (!env_) { + return; + } + if (ANI_OK != env_->GlobalReference_Create(obj, &ref_)) { + ref_ = nullptr; + } + } + explicit operator bool() const + { + return ref_ != nullptr; + } + ani_ref get() const + { + return ref_; + } + ~GlobalRefGuard() + { + if (env_ && ref_) { + env_->GlobalReference_Delete(ref_); + } + } + + GlobalRefGuard(const GlobalRefGuard &) = delete; + GlobalRefGuard &operator=(const GlobalRefGuard &) = delete; +}; + +size_t GenerateId() +{ + return g_baseId++; +} +*/ + +int32_t GetDeviceIdsAsync() +{ + std::vector _ids; + auto callback = [&_ids] (std::vector& ids) { _ids = ids; }; + int32_t ret = InputManager_t::GetInstance()->GetDeviceIds(callback); + if (ret != RET_OK) { + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(ret, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", ret); + } + taihe::set_business_error(ret, codeMsg.msg); + MMI_HILOGE("failed to get Device ids, code:%{public}d message: %{public}s", ret, codeMsg.msg.c_str()); + return ret; + } + return RET_OK; +} + +InputDeviceData GetDeviceAsync(int32_t deviceId) +{ + std::shared_ptr _device = std::make_shared(); + auto callback = [&_device] (std::shared_ptr device) { _device = device; }; + int32_t ret = InputManager_t::GetInstance()->GetDevice(deviceId, callback); + if (ret != OTHER_ERROR && ret != RET_OK) { + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(ret, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", ret); + } + taihe::set_business_error(ret, codeMsg.msg); + MMI_HILOGE("failed to get device, code:%{public}d message: %{public}s", ret, codeMsg.msg.c_str()); + std::shared_ptr errDevice = nullptr; + return TaiheConverter::ConverterInputDevice(errDevice); + } + return TaiheConverter::ConverterInputDevice(_device); +} + +InputDeviceData GetDeviceInfoAsync(int32_t deviceId) +{ + std::shared_ptr _device = std::make_shared(); + auto callback = [&_device] (std::shared_ptr device) { _device = device; }; + int32_t ret = InputManager_t::GetInstance()->GetDevice(deviceId, callback); + if (ret != OTHER_ERROR && ret != RET_OK) { + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(ret, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", ret); + } + taihe::set_business_error(ret, codeMsg.msg); + MMI_HILOGE("failed to get device info, code:%{public}d message: %{public}s", ret, codeMsg.msg.c_str()); + std::shared_ptr errDevice = nullptr; + return TaiheConverter::ConverterInputDevice(errDevice); + } + return TaiheConverter::ConverterInputDevice(_device); +} + +::taihe::array SupportKeysAsync(int32_t deviceId, taihe::array_view keys) +{ + uint32_t size = keys.size(); + if (size < MIN_N_SIZE || size > MAX_N_SIZE) { + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(COMMON_PARAMETER_ERROR, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", COMMON_PARAMETER_ERROR); + } + taihe::set_business_error(COMMON_PARAMETER_ERROR, codeMsg.msg); + return ::taihe::array(nullptr, 0); + } + std::vector keyCodes; + keyCodes.resize(size); + for (auto &key: keys) { + auto value = TaiheConverter::GetKeyCodeByValue(KEY_CODE_TRANSFORMATION, key); + keyCodes.push_back(static_cast(value)); + } + std::vector _keystrokeAbility; + auto callback = [&_keystrokeAbility] (std::vector& keystrokeAbility) { + _keystrokeAbility = keystrokeAbility; + }; + int32_t ret = InputManager_t::GetInstance()->SupportKeys(deviceId, keyCodes, callback); + if (ret != OTHER_ERROR && ret != RET_OK) { + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(ret, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", ret); + } + taihe::set_business_error(ret, codeMsg.msg); + MMI_HILOGE("failed to support keys, code:%{public}d message: %{public}s", ret, codeMsg.msg.c_str()); + return ::taihe::array(nullptr, 0); + } + uint32_t arrayLength = _keystrokeAbility.size(); + ::taihe::array res(arrayLength); + for (uint32_t i = 0; i < arrayLength; i++) { + res[i] = _keystrokeAbility[i]; + } + return res; +} + +void SetKeyboardRepeatDelayAsync(int32_t delay) +{ + if (delay < MIN_KEY_REPEAT_DELAY) { + delay = MIN_KEY_REPEAT_DELAY; + } else if (delay > MAX_KEY_REPEAT_DELAY) { + delay = MAX_KEY_REPEAT_DELAY; + } + int32_t ret = InputManager_t::GetInstance()->SetKeyboardRepeatDelay(delay); + if (ret != RET_OK) { + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(ret, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", ret); + } + taihe::set_business_error(ret, codeMsg.msg); + MMI_HILOGE("failed to set keyboard repeat delay, code:%{public}d message: %{public}s", ret, codeMsg.msg.c_str()); + return; + } +} + +int32_t GetKeyboardRepeatDelayAsync() +{ + int32_t _delay = -1; + auto callback = [&_delay] (int32_t delay) { _delay = delay; }; + int32_t ret = InputManager_t::GetInstance()->GetKeyboardRepeatDelay(callback); + if (ret != RET_OK) { + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(ret, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", ret); + } + taihe::set_business_error(ret, codeMsg.msg); + MMI_HILOGE("failed to get keyboard repeat delay, code:%{public}d message: %{public}s", ret, codeMsg.msg.c_str()); + return ret; + } + return RET_OK; +} + +void SetKeyboardRepeatRateAsync(int32_t rate) +{ + if (rate < MIN_KEY_REPEAT_RATE) { + rate = MIN_KEY_REPEAT_RATE; + } else if (rate > MAX_KEY_REPEAT_RATE) { + rate = MAX_KEY_REPEAT_RATE; + } + int32_t ret = InputManager_t::GetInstance()->SetKeyboardRepeatRate(rate); + if (ret != RET_OK) { + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(ret, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", ret); + } + taihe::set_business_error(ret, codeMsg.msg); + MMI_HILOGE("failed to set keyboard repeat rate, code:%{public}d message: %{public}s", ret, codeMsg.msg.c_str()); + } +} + +int32_t GetKeyboardRepeatRateAsync() +{ + int32_t _rate = -1; + auto callback = [&_rate] (int32_t rate) { _rate = rate; }; + int32_t ret = InputManager_t::GetInstance()->GetKeyboardRepeatRate(callback); + if (ret != RET_OK) { + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(ret, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", ret); + } + taihe::set_business_error(ret, codeMsg.msg); + MMI_HILOGE("failed to get keyboard repeat rate, code:%{public}d message: %{public}s", ret, codeMsg.msg.c_str()); + } + return ret; +} + +int64_t GetIntervalSinceLastInputAsync() +{ + int64_t timeInterval = 0; + int32_t ret = InputManager_t::GetInstance()->GetIntervalSinceLastInput(timeInterval); + if (ret != RET_OK) { + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(ret, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", ret); + } + taihe::set_business_error(ret, codeMsg.msg); + MMI_HILOGE("failed to get interval since last input, code:%{public}d message: %{public}s", ret, codeMsg.msg.c_str()); + } + return timeInterval; +} + +void SetFunctionKeyEnabledAsync(TaiheFunctionKey functionKey, bool enabled) +{ + if (functionKey != OHOS::MMI::FunctionKey::FUNCTION_KEY_CAPSLOCK) { + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(COMMON_PARAMETER_ERROR, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", COMMON_PARAMETER_ERROR); + } + taihe::set_business_error(COMMON_PARAMETER_ERROR, codeMsg.msg); + MMI_HILOGE("First parameter value error"); + return; + } + int32_t ret = InputManager_t::GetInstance()->SetFunctionKeyState(functionKey, enabled); + if (ret != RET_OK) { + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(ret, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", ret); + } + taihe::set_business_error(ret, codeMsg.msg); + MMI_HILOGE("failed to set functionKey state, code:%{public}d message: %{public}s", ret, codeMsg.msg.c_str()); + } +} + +void SetInputDeviceEnabledAsync(int32_t deviceId, bool enabled) +{ + if (deviceId < 0) { + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(COMMON_PARAMETER_ERROR, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", COMMON_PARAMETER_ERROR); + } + taihe::set_business_error(COMMON_PARAMETER_ERROR, codeMsg.msg); + MMI_HILOGE("Invalid deviceId"); + return; + } + std::function callback; + int32_t ret = InputManager_t::GetInstance()->SetInputDeviceEnabled(deviceId, enabled, callback); + if (ret != RET_OK) { + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(ret, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", ret); + } + taihe::set_business_error(ret, codeMsg.msg); + MMI_HILOGE("failed to set functionKey state, code:%{public}d message: %{public}s", ret, codeMsg.msg.c_str()); + } +} + +::ohos::multimodalInput::inputDevice::KeyboardType GetKeyboardTypeSync(int32_t deviceId) +{ + int32_t type = 0; + auto callback = [&type] (int32_t keyboardType) { type = keyboardType; }; + int32_t ret = InputManager_t::GetInstance()->GetKeyboardType(deviceId, callback); + if (ret != OTHER_ERROR && ret != RET_OK) { + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(ret, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", ret); + } + taihe::set_business_error(ret, codeMsg.msg); + MMI_HILOGE("failed to set functionKey state, code:%{public}d message: %{public}s", ret, codeMsg.msg.c_str()); + } + ::ohos::multimodalInput::inputDevice::KeyboardType kType = + static_cast<::ohos::multimodalInput::inputDevice::KeyboardType::key_t>(type); + return kType; +} + +::taihe::array SupportKeysSync(int32_t deviceId, taihe::array_view keys) +{ + uint32_t size = keys.size(); + if (size < MIN_N_SIZE || size > MAX_N_SIZE) { + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(COMMON_PARAMETER_ERROR, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", COMMON_PARAMETER_ERROR); + } + taihe::set_business_error(COMMON_PARAMETER_ERROR, codeMsg.msg); + MMI_HILOGE("param is invaild, code:%{public}d message: %{public}s", COMMON_PARAMETER_ERROR, codeMsg.msg.c_str()); + return ::taihe::array(nullptr, 0); + } + std::vector result {}; + auto callback = [&result] (std::vector &isSupported) { result = isSupported; }; + std::vector keyCodes; + for (uint32_t i = 0; i < size; i++) { + keyCodes.push_back(static_cast(keys[i])); + } + int32_t ret = InputManager_t::GetInstance()->SupportKeys(deviceId, keyCodes, callback); + if (ret != OTHER_ERROR && ret != RET_OK) { + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(ret, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", ret); + } + taihe::set_business_error(ret, codeMsg.msg); + MMI_HILOGE("failed to support keys sync, code:%{public}d message: %{public}s", ret, codeMsg.msg.c_str()); + return ::taihe::array(nullptr, 0); + } + uint32_t arrayLength = result.size(); + ::taihe::array res(arrayLength); + for (uint32_t i = 0; i < arrayLength; i++) { + res[i] = result[i]; + } + return res; +} + +InputDeviceData GetDeviceInfoSync(int32_t deviceId) +{ + std::shared_ptr _device = std::make_shared(); + auto callback = [&_device] (std::shared_ptr device) { _device = device; }; + int32_t ret = InputManager_t::GetInstance()->GetDevice(deviceId, callback); + if (ret != OTHER_ERROR && ret != RET_OK) { + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(ret, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", ret); + } + taihe::set_business_error(ret, codeMsg.msg); + MMI_HILOGE("failed to get device info, code:%{public}d message: %{public}s", ret, codeMsg.msg.c_str()); + std::shared_ptr errDevice = nullptr; + return TaiheConverter::ConverterInputDevice(errDevice); + } + return TaiheConverter::ConverterInputDevice(_device); +} + +// on/off +/* +int32_t RegisterListener(std::string const &type, callbackType &&cb, uintptr_t opq) +{ + std::lock_guard lock(cbMapMutex); + ani_object callbackObj = reinterpret_cast(opq); + ani_ref callbackRef; + ani_env *env = taihe::get_env(); + if (env == nullptr || ANI_OK != env->GlobalReference_Create(callbackObj, &callbackRef)) { + MMI_HILOGE("ani_env is nullptr or GlobalReference_Create failed"); + return CALLBACK_EVENT_FAILED; + } + auto &cbVec = changeCbMap_[type]; + bool isDuplicate = std::any_of(cbVec.begin(), cbVec.end(), + [env, callbackRef](std::shared_ptr &obj) { + ani_boolean isEqual = false; + return (ANI_OK == env->Reference_StrictEquals(callbackRef, obj->ref, &isEqual)) && isEqual; + }); + if (isDuplicate) { + env->GlobalReference_Delete(callbackRef); + MMI_HILOGD("callback already registered"); + return CALLBACK_EVENT_EXIST; + } + cbVec.emplace_back(std::make_shared(cb, callbackRef)); + MMI_HILOGI("register callback success, type: %{public}s", type.c_str()); + return CALLBACK_EVENT_SUCCESS; +} + +void onKey(callbackType &&f, uintptr_t opq) +{ + std::lock_guard guard(g_mutex); + bool isListening { false }; + auto keyMonitorId = GenerateId(); + auto result = RegisterListener(std::to_string(keyMonitorId), f, opq); + if (result == CALLBACK_EVENT_FAILED) { + MMI_HILOGE("Register listener failed"); + return; + } + if (result == CALLBACK_EVENT_EXIST) { + MMI_HILOGE("Callback already exist"); + return; + } + auto &cbVec = changeCbMap_[std::to_string(keyMonitorId)]; + std::shared_ptr listener = + for (auto &cb : cbVec) { + + } + if (!isListening) { + auto ret = InputManager_t::GetInstance()->RegisterDevListener("change", ); + if (ret != RET_OK) { + MMI_HILOGE("RegisterDevListener fail, error:%{public}d", ret); + } else { + std::lock_guard guard(g_mutex); + isListeningProcess_ = true; + } + } +} + +void offKey(taihe::optional_view opq) +{ + std::lock_guard lock(mutex_); + const auto iter = changeCbMap_.find(CHANGED_TYPE); + if (iter == changeCbMap_.end()) { + MMI_HILOGE("change is not registered"); + return; + } + if (!opq.has_value()) { + iter->second.clear(); + goto monitorLabel; + } + ani_env *env = taihe::get_env(); + if (env == nullptr) { + MMI_HILOGE("Failed to unregister change, env is nullptr"); + return; + } + GlobalRefGuard guard(env, reinterpret_cast(opq.value())); + if (!guard) { + MMI_HILOGE("Failed to unregister change, GlobalRefGuard is false!"); + return; + } + + const auto pred = [env, targetRef = guard.get()](std::unique_ptr &obj) { + ani_boolean is_equal = false; + return (ANI_OK == env->Reference_StrictEquals(targetRef, obj->ref, &is_equal)) && is_equal; + }; + auto &callbacks = iter->second; + const auto it = std::find_if(callbacks.begin(), callbacks.end(), pred); + if (it != callbacks.end()) { + callbacks.erase(it); + } + + monitorLabel: + if (isListeningProcess_ && iter->second.empty()) { + needStopListening = true; + isListeningProcess_ = false; + } + if (needStopListening) { + auto ret = InputManager_t::GetInstance()->UnregisterDevListener("change", shared_from_this()); + if (ret != RET_OK) { + MMI_HILOGE("UnregisterDevListener fail, error:%{public}d", ret); + } + } +} +*/ +} // namespace // Since these macros are auto-generate, lint will cause false positive. // NOLINTBEGIN +TH_EXPORT_CPP_API_GetDeviceIdsAsync(GetDeviceIdsAsync); +TH_EXPORT_CPP_API_GetDeviceAsync(GetDeviceAsync); +TH_EXPORT_CPP_API_GetDeviceInfoAsync(GetDeviceInfoAsync); +TH_EXPORT_CPP_API_SupportKeysAsync(SupportKeysAsync); +TH_EXPORT_CPP_API_SetKeyboardRepeatDelayAsync(SetKeyboardRepeatDelayAsync); +TH_EXPORT_CPP_API_GetKeyboardRepeatDelayAsync(GetKeyboardRepeatDelayAsync); +TH_EXPORT_CPP_API_SetKeyboardRepeatRateAsync(SetKeyboardRepeatRateAsync); +TH_EXPORT_CPP_API_GetKeyboardRepeatRateAsync(GetKeyboardRepeatRateAsync); +TH_EXPORT_CPP_API_GetIntervalSinceLastInputAsync(GetIntervalSinceLastInputAsync); +TH_EXPORT_CPP_API_SetFunctionKeyEnabledAsync(SetFunctionKeyEnabledAsync); +TH_EXPORT_CPP_API_SetInputDeviceEnabledAsync(SetInputDeviceEnabledAsync); +TH_EXPORT_CPP_API_GetKeyboardTypeSync(GetKeyboardTypeSync); +TH_EXPORT_CPP_API_SupportKeysSync(SupportKeysSync); +TH_EXPORT_CPP_API_GetDeviceInfoSync(GetDeviceInfoSync); +// TH_EXPORT_CPP_API_onKey(onKey); +// TH_EXPORT_CPP_API_offKey(offKey); // NOLINTEND \ No newline at end of file -- Gitee From fbad34d5abe10c223ef408972d03c45e689f90c2 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Fri, 25 Jul 2025 10:08:11 +0800 Subject: [PATCH 08/29] =?UTF-8?q?lmq=20short=5Fkey=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- frameworks/ets/short_key/BUILD.gn | 2 ++ .../idl/ohos.multimodalInput.shortKey.taihe | 6 +++- .../ohos.multimodalInput.shortKey.impl.cpp | 35 ++++++++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/frameworks/ets/short_key/BUILD.gn b/frameworks/ets/short_key/BUILD.gn index f3bf3d6ebb..40b024080d 100644 --- a/frameworks/ets/short_key/BUILD.gn +++ b/frameworks/ets/short_key/BUILD.gn @@ -22,6 +22,7 @@ config("shortKey_config") { include_dirs = [ "${mmi_path}/util/common/include", "${mmi_path}/util/network/include", + "${mmi_path}/frameworks/ets/common/include" ] } subsystem_name = "multimodalinput" @@ -52,6 +53,7 @@ taihe_shared_library("ShortKey") { ":run_taihe", "${mmi_path}/frameworks/proxy:libmmi-client", "${mmi_path}/util:libmmi-util", + "${mmi_path}/frameworks/ets/common:ets_inputcommon_package", ] external_deps = [ "c_utils:utils", diff --git a/frameworks/ets/short_key/idl/ohos.multimodalInput.shortKey.taihe b/frameworks/ets/short_key/idl/ohos.multimodalInput.shortKey.taihe index 3ee8b31771..a59649fb59 100644 --- a/frameworks/ets/short_key/idl/ohos.multimodalInput.shortKey.taihe +++ b/frameworks/ets/short_key/idl/ohos.multimodalInput.shortKey.taihe @@ -30,4 +30,8 @@ struct FingerprintEvent { action: FingerprintAction; distanceX: f64; distanceY: f64; -} \ No newline at end of file +} + +@gen_async("setKeyDownDuration") +@gen_promise("setKeyDownDuration") +function SetKeyDownDurationAsync(businessKey: String, delay: i32): void; \ No newline at end of file diff --git a/frameworks/ets/short_key/src/ohos.multimodalInput.shortKey.impl.cpp b/frameworks/ets/short_key/src/ohos.multimodalInput.shortKey.impl.cpp index f9a3f29d9c..a85b32e55c 100644 --- a/frameworks/ets/short_key/src/ohos.multimodalInput.shortKey.impl.cpp +++ b/frameworks/ets/short_key/src/ohos.multimodalInput.shortKey.impl.cpp @@ -18,12 +18,45 @@ #include "taihe/runtime.hpp" #include "stdexcept" +#include "ani_common.h" +#include "define_multimodal.h" +#include "input_manager.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "TaiHeShortKeyImpl" + using namespace taihe; +using namespace OHOS::MMI; using namespace ohos::multimodalInput::shortKey; +using TaiheError_t = OHOS::MMI::TaiheError; namespace { -} // namespace +constexpr int32_t MAX_DELAY { 4000 }; +constexpr int32_t MIN_DELAY { 0 }; + +void SetKeyDownDurationAsync(::taihe::string_view businessKey, int32_t delay) { + if (delay < MIN_DELAY || delay > MAX_DELAY) { + MMI_HILOGE("Invalid delay"); + TaiheError_t codeMsg; + if (!TaiheConverter::GetApiError(COMMON_PARAMETER_ERROR, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", COMMON_PARAMETER_ERROR); + } + taihe::set_business_error(COMMON_PARAMETER_ERROR, codeMsg.msg); + } + int32_t ret = InputManager::GetInstance()->SetKeyDownDuration(std::string(businessKey), delay); + if (ret == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + return; + } else if (ret == COMMON_PARAMETER_ERROR) { + MMI_HILOGE("Invalid param"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "param is invalid"); + return; + } +} +} // namespace // Since these macros are auto-generate, lint will cause false positive. // NOLINTBEGIN +TH_EXPORT_CPP_API_SetKeyDownDurationAsync(SetKeyDownDurationAsync); // NOLINTEND \ No newline at end of file -- Gitee From 2a7ca88307b6117d18efaa5472680403a0d03634 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Fri, 25 Jul 2025 14:23:38 +0800 Subject: [PATCH 09/29] =?UTF-8?q?lmq=20short=5Fkey=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- .../src/ohos.multimodalInput.shortKey.impl.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/frameworks/ets/short_key/src/ohos.multimodalInput.shortKey.impl.cpp b/frameworks/ets/short_key/src/ohos.multimodalInput.shortKey.impl.cpp index a85b32e55c..f4efa7475c 100644 --- a/frameworks/ets/short_key/src/ohos.multimodalInput.shortKey.impl.cpp +++ b/frameworks/ets/short_key/src/ohos.multimodalInput.shortKey.impl.cpp @@ -34,14 +34,15 @@ namespace { constexpr int32_t MAX_DELAY { 4000 }; constexpr int32_t MIN_DELAY { 0 }; -void SetKeyDownDurationAsync(::taihe::string_view businessKey, int32_t delay) { +void SetKeyDownDurationAsync(::taihe::string_view businessKey, int32_t delay) +{ + if (businessKey.empty()) { + MMI_HILOGE("Invalid businessId"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "businessId is invalid"); + } if (delay < MIN_DELAY || delay > MAX_DELAY) { MMI_HILOGE("Invalid delay"); - TaiheError_t codeMsg; - if (!TaiheConverter::GetApiError(COMMON_PARAMETER_ERROR, codeMsg)) { - MMI_HILOGE("Error code %{public}d not found", COMMON_PARAMETER_ERROR); - } - taihe::set_business_error(COMMON_PARAMETER_ERROR, codeMsg.msg); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "Delay is invalid"); } int32_t ret = InputManager::GetInstance()->SetKeyDownDuration(std::string(businessKey), delay); if (ret == COMMON_USE_SYSAPI_ERROR) { -- Gitee From 1e1cb68c42103805bb5530996e0e51a171b9e02f Mon Sep 17 00:00:00 2001 From: qinhuangtaotao Date: Fri, 25 Jul 2025 16:42:46 +0800 Subject: [PATCH 10/29] inputEventClient TaiHe Signed-off-by:qianyong325 --- frameworks/ets/input_event_client/BUILD.gn | 1 + .../include/inputEventClient.h | 62 ++++ ....multimodalInput.inputEventClient.impl.cpp | 322 +++++++++++++++++- 3 files changed, 382 insertions(+), 3 deletions(-) create mode 100644 frameworks/ets/input_event_client/include/inputEventClient.h diff --git a/frameworks/ets/input_event_client/BUILD.gn b/frameworks/ets/input_event_client/BUILD.gn index d7cca9bf15..df61aa30f7 100644 --- a/frameworks/ets/input_event_client/BUILD.gn +++ b/frameworks/ets/input_event_client/BUILD.gn @@ -25,6 +25,7 @@ config("inputEventClient_config") { "${mmi_path}/tools/event_inject/include", "${mmi_path}/interfaces/kits/c/input", "${mmi_path}/interfaces/native/innerkits/proxy/include", + "${mmi_path}/frameworks/ets/input_event_client/include", ] } subsystem_name = "multimodalinput" diff --git a/frameworks/ets/input_event_client/include/inputEventClient.h b/frameworks/ets/input_event_client/include/inputEventClient.h new file mode 100644 index 0000000000..3840949a5b --- /dev/null +++ b/frameworks/ets/input_event_client/include/inputEventClient.h @@ -0,0 +1,62 @@ +#ifndef INPUT_EVENT_CLIENT_H +#define INPUT_EVENT_CLIENT_H +#include +#include "pointer_event.h" + +using PointerEvent = OHOS::MMI::PointerEvent; + +enum TAHE_ACTION { + TAHE_CANCEL = 0, + TAHE_MOVE = 1, + TAHE_BUTTON_DOWN = 2, + TAHE_BUTTON_UP = 3, + TAHE_AXIS_BEGIN = 4, + TAHE_AXIS_UPDATE = 5, + TAHE_AXIS_END = 6, + TAHE_ACTION_DOWN = 7, + TAHE_ACTION_UP = 8, +}; + +enum TH_MOUSE_CALLBACK_EVENT { + JS_CALLBACK_MOUSE_ACTION_MOVE = 1, + JS_CALLBACK_MOUSE_ACTION_BUTTON_DOWN = 2, + JS_CALLBACK_MOUSE_ACTION_BUTTON_UP = 3, + JS_CALLBACK_POINTER_ACTION_DOWN = 7, + JS_CALLBACK_POINTER_ACTION_UP = 8, +}; + +enum TH_TOUCH_CALLBACK_EVENT { + JS_CALLBACK_TOUCH_ACTION_DOWN = 1, + JS_CALLBACK_TOUCH_ACTION_MOVE = 2, + JS_CALLBACK_TOUCH_ACTION_UP = 3, +}; + +enum TH_TOUCH_CALLBACK_SOURCETYPE { + TOUCH_SCREEN = 0, + PEN = 1, + TOUCH_PAD = 2 +}; + +enum TH_MOUSE_BUTTON { + JS_MOUSE_BUTTON_LEFT = 0, + JS_MOUSE_BUTTON_MIDDLE = 1, + JS_MOUSE_BUTTON_RIGHT = 2, + JS_MOUSE_BUTTON_SIDE = 3, + JS_MOUSE_BUTTON_EXTRA = 4, + JS_MOUSE_BUTTON_FORWARD = 5, + JS_MOUSE_BUTTON_BACK = 6, + JS_MOUSE_BUTTON_TASK = 7 +}; + +static std::unordered_map THMouseButton2Native = { + { JS_MOUSE_BUTTON_LEFT, PointerEvent::MOUSE_BUTTON_LEFT }, + { JS_MOUSE_BUTTON_RIGHT, PointerEvent::MOUSE_BUTTON_RIGHT }, + { JS_MOUSE_BUTTON_MIDDLE, PointerEvent::MOUSE_BUTTON_MIDDLE }, + { JS_MOUSE_BUTTON_SIDE, PointerEvent::MOUSE_BUTTON_SIDE }, + { JS_MOUSE_BUTTON_EXTRA, PointerEvent::MOUSE_BUTTON_EXTRA }, + { JS_MOUSE_BUTTON_FORWARD, PointerEvent::MOUSE_BUTTON_FORWARD }, + { JS_MOUSE_BUTTON_BACK, PointerEvent::MOUSE_BUTTON_BACK }, + { JS_MOUSE_BUTTON_TASK, PointerEvent::MOUSE_BUTTON_TASK } +}; + +#endif \ No newline at end of file diff --git a/frameworks/ets/input_event_client/src/ohos.multimodalInput.inputEventClient.impl.cpp b/frameworks/ets/input_event_client/src/ohos.multimodalInput.inputEventClient.impl.cpp index 43b394ed24..91538fcccc 100644 --- a/frameworks/ets/input_event_client/src/ohos.multimodalInput.inputEventClient.impl.cpp +++ b/frameworks/ets/input_event_client/src/ohos.multimodalInput.inputEventClient.impl.cpp @@ -17,13 +17,329 @@ #include "ohos.multimodalInput.inputEventClient.impl.hpp" #include "taihe/runtime.hpp" #include "stdexcept" +#include +#include +#include "key_event.h" +#include "input_manager.h" +#include "input_event.h" +#include "oh_input_manager.h" +#include "pointer_event.h" +#include "inputEventClient.h" using namespace taihe; using namespace ohos::multimodalInput::inputEventClient; +using namespace OHOS::MMI; namespace { +#ifdef OHOS_BUILD_ENABLE_VKEYBOARD +void GetInjectionEventDataNative(Input_KeyEvent* keyEventNative, ::ohos::multimodalInput::inputEventClient::KeyEvent const& thKeyEvent) { + auto keyAction = thKeyEvent.isPressed ? Input_KeyEventAction::KEY_ACTION_DOWN : Input_KeyEventAction::KEY_ACTION_UP; + OH_Input_SetKeyEventAction(keyEventNative, keyAction); + OH_Input_SetKeyEventKeyCode(keyEventNative, thKeyEvent.keyCode); + OH_Input_SetKeyEventActionTime(keyEventNative, static_cast(thKeyEvent.keyDownDuration)); + Input_Result result = static_cast(OH_Input_InjectKeyEvent(keyEventNative)); + if (result != INPUT_SUCCESS) { + TH_THROW(std::runtime_error, "OH_Input_InjectKeyEvent error"); + } +} +#else +void GetInjectionEventData(std::shared_ptr keyEventNative, ::ohos::multimodalInput::inputEventClient::KeyEvent const& thKeyEvent) { + keyEventNative->SetRepeat(true); + keyEventNative->AddFlag(OHOS::MMI::InputEvent::EVENT_FLAG_NO_INTERCEPT); + keyEventNative->SetKeyCode(thKeyEvent.keyCode); + auto keyAction = thKeyEvent.isPressed ? OHOS::MMI::KeyEvent::KEY_ACTION_DOWN : OHOS::MMI::KeyEvent::KEY_ACTION_UP; + keyEventNative->SetKeyAction(keyAction); + OHOS::MMI::KeyEvent::KeyItem item; + item.SetKeyCode(thKeyEvent.keyCode); + item.SetPressed(thKeyEvent.isPressed); + item.SetDownTime(static_cast(thKeyEvent.keyDownDuration)); + keyEventNative->AddKeyItem(item); + OHOS::MMI::InputManager::GetInstance()->SimulateInputEvent(keyEventNative); + std::this_thread::sleep_for(std::chrono::milliseconds(thKeyEvent.keyDownDuration)); +} +#endif // OHOS_BUILD_ENABLE_VKEYBOARD + +void injectKeyEvent(::ohos::multimodalInput::inputEventClient::KeyEventData const& keyEvent) { + TH_THROW(std::runtime_error, "injectKeyEvent not implemented"); +#ifdef OHOS_BUILD_ENABLE_VKEYBOARD + Input_KeyEvent* keyEventNative = OH_Input_CreateKeyEvent(); + GetInjectionEventDataNative(keyEventNative,KeyEvent); +#else + auto lkeyEvent = OHOS::MMI::KeyEvent::Create(); + GetInjectionEventData(lkeyEvent,keyEvent.keyEvent); +#endif +} + +void injectEvent(::ohos::multimodalInput::inputEventClient::KeyEvent const& KeyEvent) { + TH_THROW(std::runtime_error, "injectEvent not implemented"); +#ifdef OHOS_BUILD_ENABLE_VKEYBOARD + Input_KeyEvent* keyEventNative = OH_Input_CreateKeyEvent(); + GetInjectionEventDataNative(keyEventNative,KeyEvent); +#else + auto lkeyEvent = OHOS::MMI::KeyEvent::Create(); + GetInjectionEventData(lkeyEvent,KeyEvent); +#endif // OHOS_BUILD_ENABLE_VKEYBOARD +} + +void HandleMouseButton(::ohos::multimodalInput::mouseEvent::MouseEvent mouseEvent, + std::shared_ptr pointerEvent, int32_t action) { + int32_t button = static_cast(mouseEvent.button.get_value()); + if (THMouseButton2Native.find(button) != THMouseButton2Native.end()) { + button = THMouseButton2Native[button]; + } else { + TH_THROW(std::runtime_error, "button is unknown"); + } + pointerEvent->SetButtonId(button); + if (action == TH_MOUSE_CALLBACK_EVENT::JS_CALLBACK_MOUSE_ACTION_BUTTON_DOWN) { + pointerEvent->SetButtonPressed(button); + } else if (action == TH_MOUSE_CALLBACK_EVENT::JS_CALLBACK_MOUSE_ACTION_BUTTON_UP) { + pointerEvent->DeleteReleaseButton(button); + } +} + +void HandleMouseAction(::ohos::multimodalInput::mouseEvent::MouseEvent mouseEvent, + std::shared_ptr pointerEvent, PointerEvent::PointerItem &item) { + int32_t action = static_cast(mouseEvent.action.get_value()); + switch (action) { + case TAHE_MOVE: + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE); + break; + case TAHE_BUTTON_DOWN: + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN); + item.SetPressed(true); + break; + case TAHE_BUTTON_UP: + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_UP); + item.SetPressed(false); + break; + case TAHE_ACTION_DOWN: + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); + item.SetPressed(true); + break; + case TAHE_ACTION_UP: + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP); + item.SetPressed(false); + break; + default: + TH_THROW(std::runtime_error, "action is unknown"); + break; + } + + if (action == TAHE_BUTTON_DOWN || action == TAHE_BUTTON_UP + || action == TAHE_MOVE) { + HandleMouseButton(mouseEvent, pointerEvent, action); + } +} + +void HandleMousePropertyInt32(::ohos::multimodalInput::mouseEvent::MouseEvent mouseEvent, + std::shared_ptr pointerEvent, PointerEvent::PointerItem &item) { + int32_t screenX = mouseEvent.screenX; + int32_t screenY = mouseEvent.screenY; + int32_t toolType = mouseEvent.toolType.get_value(); + double globalX = 0; + if(mouseEvent.globalX.has_value()) { + globalX = mouseEvent.globalX.value(); + } + double globalY = 0; + if(mouseEvent.globalY.has_value()) { + globalY = mouseEvent.globalY.value(); + } + pointerEvent->SetSourceType(toolType); + item.SetPointerId(0); + item.SetDisplayX(screenX); + item.SetDisplayY(screenY); + item.SetDisplayXPos(screenX); + item.SetDisplayYPos(screenY); + if (globalX != DBL_MAX && globalY != DBL_MAX) { + item.SetGlobalX(globalX); + item.SetGlobalY(globalY); + } + pointerEvent->SetPointerId(0); + pointerEvent->AddPointerItem(item); +} + +void HandleMousePressedButtons(::ohos::multimodalInput::mouseEvent::MouseEvent mouseEvent, + std::shared_ptr pointerEvent, PointerEvent::PointerItem &item) { + // CHKPV(pointerEvent); + std::vector jsPressedButtons { }; + + for(auto it = mouseEvent.pressedButtons.begin(); it != mouseEvent.pressedButtons.end(); ++it) { + jsPressedButtons.push_back(static_cast(*it)); + } + + std::vector nativePressedButtons { }; + for (const auto jsButton : jsPressedButtons) { + if (THMouseButton2Native.find(jsButton) == THMouseButton2Native.end()) { + TH_THROW(std::runtime_error, "Unknown jsButton"); + continue; + } + nativePressedButtons.push_back(THMouseButton2Native[jsButton]); + } + + auto buttonId = pointerEvent->GetButtonId(); + auto iter = std::find_if(nativePressedButtons.begin(), nativePressedButtons.end(), + [buttonId] (int32_t elem) { return elem == buttonId; } + ); + if (iter != nativePressedButtons.end()) { + item.SetPressed(true); + } + for (const auto button : nativePressedButtons) { + pointerEvent->SetButtonPressed(button); + } +} + +void injectMouseEvent(::ohos::multimodalInput::inputEventClient::MouseEventData const& mouseEvent) { + + auto pointerEvent = PointerEvent::Create(); + PointerEvent::PointerItem item; + HandleMouseAction(mouseEvent.mouseEvent, pointerEvent, item); + HandleMousePropertyInt32(mouseEvent.mouseEvent, pointerEvent, item); + HandleMousePressedButtons(mouseEvent.mouseEvent, pointerEvent, item); + + int32_t useCoordinate = PointerEvent::DISPLAY_COORDINATE; +// #if 0 // 0702的sdk没有此属性 +// bool useGlobalCoordinate = mouseEvent.useGlobalCoordinate; +// if (useGlobalCoordinate) { +// MMI_HILOGD("useGlobalCoordinate"); +// useCoordinate = PointerEvent::GLOBAL_COORDINATE; +// } +// #endif + InputManager::GetInstance()->SimulateInputEvent(pointerEvent, true, useCoordinate); +} + +int32_t HandleTouchAction(::ohos::multimodalInput::touchEvent::TouchEvent touchEvent, + std::shared_ptr pointerEvent, PointerEvent::PointerItem &item) { + int32_t action = static_cast(touchEvent.action.get_value()); + switch (action) { + case TH_TOUCH_CALLBACK_EVENT::JS_CALLBACK_TOUCH_ACTION_DOWN: + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); + item.SetPressed(true); + break; + case TH_TOUCH_CALLBACK_EVENT::JS_CALLBACK_TOUCH_ACTION_MOVE: + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE); + break; + case TH_TOUCH_CALLBACK_EVENT::JS_CALLBACK_TOUCH_ACTION_UP: + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP); + item.SetPressed(false); + break; + default: + TH_THROW(std::runtime_error, "action is unknown"); + break; + } + return action; +} + +void HandleTouchAttribute(std::shared_ptr pointerEvent, PointerEvent::PointerItem &item, + ::ohos::multimodalInput::touchEvent::Touch& touch, int32_t isTouch) { + int32_t pointerId = touch.id; + int32_t screenX = touch.screenX; + int32_t screenY = touch.screenY; + int64_t pressedTime = touch.pressedTime; + int32_t toolType = static_cast(touch.toolType.get_value()); + double pressure = touch.pressure; +// #ifdef 0 // 0702 SDK 分支无这些字段 +// int32_t globalX = touch.globalX; +// int32_t globalY = touch.globalY; +// #endif + + + item.SetDisplayX(screenX); + item.SetDisplayY(screenY); + item.SetDisplayXPos(screenX); + item.SetDisplayYPos(screenY); + item.SetPointerId(pointerId); + item.SetToolType(toolType); + item.SetPressure(pressure); +// #ifdef 0 // 0702 SDK 分支无此字段 +// if (globalX != INT_MAX && globalY != INT_MAX) { +// item.SetGlobalX(globalX); +// item.SetGlobalY(globalY); +// } +// #endif + if (isTouch) { + pointerEvent->SetPointerId(pointerId); + pointerEvent->SetActionTime(pressedTime); + } +} + +void HandleTouchesProperty(std::shared_ptr pointerEvent, ::taihe::array_view<::ohos::multimodalInput::touchEvent::Touch>& touches, + std::vector& pointerItems) { + for(auto it = touches.begin(); it != touches.end(); ++it) { + PointerEvent::PointerItem pointerItem; + HandleTouchAttribute(pointerEvent, pointerItem, *it, false); + pointerItems.push_back(pointerItem); + } +} + +bool HandleTouchPropertyInt32(::ohos::multimodalInput::touchEvent::TouchEvent touchEvent, + std::shared_ptr pointerEvent, PointerEvent::PointerItem &item, int32_t action) { + int32_t sourceType = touchEvent.sourceType.get_value(); + if (sourceType < 0) { + TH_THROW(std::runtime_error, "sourceType must be greater than or equal to 0"); + } + if (sourceType == TH_TOUCH_CALLBACK_SOURCETYPE::TOUCH_SCREEN || sourceType == TH_TOUCH_CALLBACK_SOURCETYPE::PEN) { + sourceType = PointerEvent::SOURCE_TYPE_TOUCHSCREEN; + } + int32_t screenId = touchEvent.base.screenId; + HandleTouchAttribute(pointerEvent, item, touchEvent.touch, true); + bool autoToVirtualScreen = true; + int32_t fixedMode = 1; + if(touchEvent.fixedMode.has_value()) { + fixedMode = static_cast(touchEvent.fixedMode.value()); + if (fixedMode < static_cast(PointerEvent::FixedMode::NORMAL) || + fixedMode >= static_cast(PointerEvent::FixedMode::SCREEN_MODE_MAX)) { + TH_THROW(std::runtime_error, "fixedMode is not defined"); + return false; + } + if (fixedMode != static_cast(PointerEvent::FixedMode::AUTO)) { + autoToVirtualScreen = false; + } + } + + pointerEvent->AddPointerItem(item); + pointerEvent->SetSourceType(sourceType); + pointerEvent->SetTargetDisplayId(screenId); + pointerEvent->SetAutoToVirtualScreen(autoToVirtualScreen); + + std::vector pointerItems; + HandleTouchesProperty(pointerEvent, touchEvent.touches, pointerItems); + for (auto &pointeritem : pointerItems) { + pointerEvent->AddPointerItem(pointeritem); + } + + if ((action == TH_TOUCH_CALLBACK_EVENT::JS_CALLBACK_TOUCH_ACTION_MOVE) || (action == TH_TOUCH_CALLBACK_EVENT::JS_CALLBACK_TOUCH_ACTION_UP)) { + pointerEvent->UpdatePointerItem(item.GetPointerId(), item); + } + return true; +} + +void injectTouchEvent(::ohos::multimodalInput::inputEventClient::TouchEventData const& touchEvent) { +// #ifdef 0 // 0702的sdk分支没有此字段 useGlobalCoordinate +// bool useGlobalCoordinate = false; +// #endif + auto pointerEvent = PointerEvent::Create(); + PointerEvent::PointerItem item; + int32_t action = HandleTouchAction(touchEvent.touchEvent, pointerEvent, item); + HandleTouchPropertyInt32(touchEvent.touchEvent, pointerEvent, item, action); + + int32_t useCoordinate = PointerEvent::DISPLAY_COORDINATE; +// #ifdef 0 // 0702的sdk分支没有此字段 useGlobalCoordinate +// if (useGlobalCoordinate) { +// TH_THROW(std::runtime_error, "useGlobalCoordinate"); +// useCoordinate = PointerEvent::GLOBAL_COORDINATE; +// } +// #endif + InputManager::GetInstance()->SimulateInputEvent(pointerEvent, pointerEvent->GetAutoToVirtualScreen(), + useCoordinate); +} + +void permitInjection(bool result) { + InputManager::GetInstance()->Authorize(result); +} } // namespace -// Since these macros are auto-generate, lint will cause false positive. -// NOLINTBEGIN -// NOLINTEND \ No newline at end of file +TH_EXPORT_CPP_API_injectKeyEvent(injectKeyEvent); +TH_EXPORT_CPP_API_injectEvent(injectEvent); +TH_EXPORT_CPP_API_injectMouseEvent(injectMouseEvent); +TH_EXPORT_CPP_API_injectTouchEvent(injectTouchEvent); +TH_EXPORT_CPP_API_permitInjection(permitInjection); \ No newline at end of file -- Gitee From 13854885002ec394ed51094efc9de319635d5997 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Fri, 25 Jul 2025 17:01:59 +0800 Subject: [PATCH 11/29] =?UTF-8?q?lmq=20=E5=A2=9E=E5=8A=A0pointer=20taihe?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- .../idl/ohos.multimodalInput.pointer.taihe | 157 +++++++++++++- .../src/ohos.multimodalInput.pointer.impl.cpp | 205 ++++++++++++++++++ 2 files changed, 361 insertions(+), 1 deletion(-) diff --git a/frameworks/ets/pointer/idl/ohos.multimodalInput.pointer.taihe b/frameworks/ets/pointer/idl/ohos.multimodalInput.pointer.taihe index 491665abc4..16f80c8e18 100644 --- a/frameworks/ets/pointer/idl/ohos.multimodalInput.pointer.taihe +++ b/frameworks/ets/pointer/idl/ohos.multimodalInput.pointer.taihe @@ -14,6 +14,7 @@ */ @!namespace("@ohos.multimodalInput.pointer", "pointer") +@!sts_inject_into_module("import image from '@ohos.multimedia.image';") @!sts_inject(""" static { loadLibrary("Pointer.z") } """) @@ -89,4 +90,158 @@ function SetPointerStyleAsync(windowId: i32, pointerStyle: PointerStyle): void; function SetPointerVisibleSync(visible: bool): void; function GetPointerStyleSync(windowId: i32): PointerStyle; -function SetPointerStyleSync(windowId: i32, pointerStyle: PointerStyle): void; \ No newline at end of file +function SetPointerStyleSync(windowId: i32, pointerStyle: PointerStyle): void; + +struct CustomCursor { + pixelMap: @sts_type("image.PixelMap") Opaque; + focusX: Optional; + focusY: Optional; +} + +@gen_async("setPointerVisible") +@gen_promise("setPointerVisible") +function SetPointerVisibleAsync(visible: bool): void; + +@gen_async("setPointerSpeed") +@gen_promise("setPointerSpeed") +function SetPointerSpeedAsync(speed: i32): void; + +@gen_async("getPointerSpeed") +@gen_promise("getPointerSpeed") +function GetPointerSpeedAsync(): i32; + +@gen_async("isPointerVisible") +@gen_promise("isPointerVisible") +function IsPointerVisibleAsync(): bool; + +@gen_async("getPointerStyle") +@gen_promise("getPointerStyle") +function GetPointerStyleAsync(windowId: i32): PointerStyle; + +@gen_async("getTouchpadDoubleTapAndDragState") +@gen_promise("getTouchpadDoubleTapAndDragState") +function GetTouchpadDoubleTapAndDragStateAsync(): bool; + +@gen_async("setTouchpadDoubleTapAndDragState") +@gen_promise("setTouchpadDoubleTapAndDragState") +function SetTouchpadDoubleTapAndDragStateAsync(isOpen: bool): void; + +function SetCustomCursorSync(windowId: i32, pixelMap: @sts_type("image.PixelMap") Opaque, focusX: Optional, focusY: Optional): void; + +@gen_promise("setCustomCursor") +@overload("setCustomCursorAsync") +function SetCustomCursorPixelMapAsync(windowId: i32, pixelMap: @sts_type("image.PixelMap") Opaque, focusX: Optional, focusY: Optional): void; + +@gen_promise("setCustomCursor") +@overload("setCustomCursorAsync") +function SetCustomCursorAsync(windowId: i32, cursor: CustomCursor, config: CursorConfig): void; + +function GetPointerSpeedSync(): i32; + +@gen_async("getTouchpadRightClickType") +@gen_promise("getTouchpadRightClickType") +function GetTouchpadRightClickTypeAsync(): RightClickType; + +@gen_async("setTouchpadRightClickType") +@gen_promise("setTouchpadRightClickType") +function SetTouchpadRightClickTypeAsync(type: RightClickType): void; + +@gen_async("getTouchpadSwipeSwitch") +@gen_promise("getTouchpadSwipeSwitch") +function GetTouchpadSwipeSwitchAsync(): bool; + +@gen_async("setTouchpadSwipeSwitch") +@gen_promise("setTouchpadSwipeSwitch") +function SetTouchpadSwipeSwitchAsync(state: bool): void; + +@gen_async("getTouchpadPinchSwitch") +@gen_promise("getTouchpadPinchSwitch") +function GetTouchpadPinchSwitchAsync(): bool; + +@gen_async("setTouchpadPinchSwitch") +@gen_promise("setTouchpadPinchSwitch") +function SetTouchpadPinchSwitchAsync(state: bool): void; + +@gen_async("getTouchpadPointerSpeed") +@gen_promise("getTouchpadPointerSpeed") +function GetTouchpadPointerSpeedAsync(): bool; + +@gen_async("setTouchpadPointerSpeed") +@gen_promise("setTouchpadPointerSpeed") +function SetTouchpadPointerSpeedAsync(speed: bool): void; + +@gen_async("getTouchpadTapSwitch") +@gen_promise("getTouchpadTapSwitch") +function GetTouchpadTapSwitchAsync(): bool; + +@gen_async("setTouchpadTapSwitch") +@gen_promise("setTouchpadTapSwitch") +function SetTouchpadTapSwitchAsync(state: bool): void; + +@gen_async("getTouchpadScrollDirection") +@gen_promise("getTouchpadScrollDirection") +function GetTouchpadScrollDirectionAsync(): bool; + +@gen_async("setTouchpadScrollDirection") +@gen_promise("setTouchpadScrollDirection") +function SetTouchpadScrollDirectionAsync(state: bool): void; + +@gen_async("getTouchpadScrollSwitch") +@gen_promise("getTouchpadScrollSwitch") +function GetTouchpadScrollSwitchAsync(): bool; + +@gen_async("setTouchpadScrollSwitch") +@gen_promise("setTouchpadScrollSwitch") +function SetTouchpadScrollSwitchAsync(state: bool): void; + +@gen_async("getMouseScrollRows") +@gen_promise("getMouseScrollRows") +function GetMouseScrollRowsAsync(): i32; + +@gen_async("setMouseScrollRows") +@gen_promise("setMouseScrollRows") +function SetMouseScrollRowsAsync(rows: i32): void; + +@gen_async("getHoverScrollState") +@gen_promise("getHoverScrollState") +function GetHoverScrollStateAsync(): bool; + +@gen_async("setHoverScrollState") +@gen_promise("setHoverScrollState") +function SetHoverScrollStateAsync(state: bool): void; + +@gen_async("getMousePrimaryButton") +@gen_promise("getMousePrimaryButton") +function GetMousePrimaryButtonAsync(): PrimaryButton; + +@gen_async("setMousePrimaryButton") +@gen_promise("setMousePrimaryButton") +function SetMousePrimaryButtonAsync(primary: PrimaryButton): void; + +@gen_async("getPointerSize") +@gen_promise("getPointerSize") +function GetPointerSizeAsync(): i32; + +function SetPointerSizeSync(size: i32): void; + +@gen_async("setPointerSize") +@gen_promise("setPointerSize") +function SetPointerSizeAsync(size: i32): void; + +@gen_async("getPointerColor") +@gen_promise("getPointerColor") +function GetPointerColorAsync(): i32; + +function SetPointerColorSync(color: i32): void; + +@gen_async("setPointerColor") +@gen_promise("setPointerColor") +function SetPointerColorAsync(color: i32): void; + +function SetPointerSpeedSync(speed: i32): void; + +function IsPointerVisibleSync(): bool; + +function GetPointerColorSync(): i32; + +function GetPointerSizeSync(): i32; \ No newline at end of file diff --git a/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp b/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp index cc3edfa0ed..404e6fdcac 100644 --- a/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp +++ b/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp @@ -127,6 +127,170 @@ void SetPointerStyleSync(int32_t windowId, PointerStyle pointerStyle) MMI_HILOGE("failed to get default SetPointerStyle!"); } } + +void SetPointerVisibleAsync(bool visible) { + TH_THROW(std::runtime_error, "SetPointerVisibleAsync not implemented"); +} + +void SetPointerSpeedAsync(int32_t speed) { + TH_THROW(std::runtime_error, "SetPointerSpeedAsync not implemented"); +} + +int32_t GetPointerSpeedAsync() { + TH_THROW(std::runtime_error, "GetPointerSpeedAsync not implemented"); +} + +bool IsPointerVisibleAsync() { + TH_THROW(std::runtime_error, "IsPointerVisibleAsync not implemented"); +} + +::ohos::multimodalInput::pointer::PointerStyle GetPointerStyleAsync(int32_t windowId) { + TH_THROW(std::runtime_error, "GetPointerStyleAsync not implemented"); +} + +bool GetTouchpadDoubleTapAndDragStateAsync() { + TH_THROW(std::runtime_error, "GetTouchpadDoubleTapAndDragStateAsync not implemented"); +} + +void SetTouchpadDoubleTapAndDragStateAsync(bool isOpen) { + TH_THROW(std::runtime_error, "SetTouchpadDoubleTapAndDragStateAsync not implemented"); +} + +void SetCustomCursorSync(int32_t windowId, uintptr_t pixelMap, ::taihe::optional_view focusX, ::taihe::optional_view focusY) { + TH_THROW(std::runtime_error, "SetCustomCursorSync not implemented"); +} + +void SetCustomCursorPixelMapAsync(int32_t windowId, uintptr_t pixelMap, ::taihe::optional_view focusX, ::taihe::optional_view focusY) { + TH_THROW(std::runtime_error, "SetCustomCursorPixelMapAsync not implemented"); +} + +void SetCustomCursorAsync(int32_t windowId, ::ohos::multimodalInput::pointer::CustomCursor const& cursor, ::ohos::multimodalInput::pointer::CursorConfig const& config) { + TH_THROW(std::runtime_error, "SetCustomCursorAsync not implemented"); +} + +int32_t GetPointerSpeedSync() { + TH_THROW(std::runtime_error, "GetPointerSpeedSync not implemented"); +} + +::ohos::multimodalInput::pointer::RightClickType GetTouchpadRightClickTypeAsync() { + TH_THROW(std::runtime_error, "GetTouchpadRightClickTypeAsync not implemented"); +} + +void SetTouchpadRightClickTypeAsync(::ohos::multimodalInput::pointer::RightClickType type) { + TH_THROW(std::runtime_error, "SetTouchpadRightClickTypeAsync not implemented"); +} + +bool GetTouchpadSwipeSwitchAsync() { + TH_THROW(std::runtime_error, "GetTouchpadSwipeSwitchAsync not implemented"); +} + +void SetTouchpadSwipeSwitchAsync(bool state) { + TH_THROW(std::runtime_error, "SetTouchpadSwipeSwitchAsync not implemented"); +} + +bool GetTouchpadPinchSwitchAsync() { + TH_THROW(std::runtime_error, "GetTouchpadPinchSwitchAsync not implemented"); +} + +void SetTouchpadPinchSwitchAsync(bool state) { + TH_THROW(std::runtime_error, "SetTouchpadPinchSwitchAsync not implemented"); +} + +bool GetTouchpadPointerSpeedAsync() { + TH_THROW(std::runtime_error, "GetTouchpadPointerSpeedAsync not implemented"); +} + +void SetTouchpadPointerSpeedAsync(bool speed) { + TH_THROW(std::runtime_error, "SetTouchpadPointerSpeedAsync not implemented"); +} + +bool GetTouchpadTapSwitchAsync() { + TH_THROW(std::runtime_error, "GetTouchpadTapSwitchAsync not implemented"); +} + +void SetTouchpadTapSwitchAsync(bool state) { + TH_THROW(std::runtime_error, "SetTouchpadTapSwitchAsync not implemented"); +} + +bool GetTouchpadScrollDirectionAsync() { + TH_THROW(std::runtime_error, "GetTouchpadScrollDirectionAsync not implemented"); +} + +void SetTouchpadScrollDirectionAsync(bool state) { + TH_THROW(std::runtime_error, "SetTouchpadScrollDirectionAsync not implemented"); +} + +bool GetTouchpadScrollSwitchAsync() { + TH_THROW(std::runtime_error, "GetTouchpadScrollSwitchAsync not implemented"); +} + +void SetTouchpadScrollSwitchAsync(bool state) { + TH_THROW(std::runtime_error, "SetTouchpadScrollSwitchAsync not implemented"); +} + +int32_t GetMouseScrollRowsAsync() { + TH_THROW(std::runtime_error, "GetMouseScrollRowsAsync not implemented"); +} + +void SetMouseScrollRowsAsync(int32_t rows) { + TH_THROW(std::runtime_error, "SetMouseScrollRowsAsync not implemented"); +} + +bool GetHoverScrollStateAsync() { + TH_THROW(std::runtime_error, "GetHoverScrollStateAsync not implemented"); +} + +void SetHoverScrollStateAsync(bool state) { + TH_THROW(std::runtime_error, "SetHoverScrollStateAsync not implemented"); +} + +::ohos::multimodalInput::pointer::PrimaryButton GetMousePrimaryButtonAsync() { + TH_THROW(std::runtime_error, "GetMousePrimaryButtonAsync not implemented"); +} + +void SetMousePrimaryButtonAsync(::ohos::multimodalInput::pointer::PrimaryButton primary) { + TH_THROW(std::runtime_error, "SetMousePrimaryButtonAsync not implemented"); +} + +int32_t GetPointerSizeAsync() { + TH_THROW(std::runtime_error, "GetPointerSizeAsync not implemented"); +} + +void SetPointerSizeSync(int32_t size) { + TH_THROW(std::runtime_error, "SetPointerSizeSync not implemented"); +} + +void SetPointerSizeAsync(int32_t size) { + TH_THROW(std::runtime_error, "SetPointerSizeAsync not implemented"); +} + +int32_t GetPointerColorAsync() { + TH_THROW(std::runtime_error, "GetPointerColorAsync not implemented"); +} + +void SetPointerColorSync(int32_t color) { + TH_THROW(std::runtime_error, "SetPointerColorSync not implemented"); +} + +void SetPointerColorAsync(int32_t color) { + TH_THROW(std::runtime_error, "SetPointerColorAsync not implemented"); +} + +void SetPointerSpeedSync(int32_t speed) { + TH_THROW(std::runtime_error, "SetPointerSpeedSync not implemented"); +} + +bool IsPointerVisibleSync() { + TH_THROW(std::runtime_error, "IsPointerVisibleSync not implemented"); +} + +int32_t GetPointerColorSync() { + TH_THROW(std::runtime_error, "GetPointerColorSync not implemented"); +} + +int32_t GetPointerSizeSync() { + TH_THROW(std::runtime_error, "GetPointerSizeSync not implemented"); +} } // namespace // Since these macros are auto-generate, lint will cause false positive. @@ -135,4 +299,45 @@ TH_EXPORT_CPP_API_SetPointerStyleAsync(SetPointerStyleAsync); TH_EXPORT_CPP_API_SetPointerVisibleSync(SetPointerVisibleSync); TH_EXPORT_CPP_API_GetPointerStyleSync(GetPointerStyleSync); TH_EXPORT_CPP_API_SetPointerStyleSync(SetPointerStyleSync); +TH_EXPORT_CPP_API_SetPointerVisibleAsync(SetPointerVisibleAsync); +TH_EXPORT_CPP_API_SetPointerSpeedAsync(SetPointerSpeedAsync); +TH_EXPORT_CPP_API_GetPointerSpeedAsync(GetPointerSpeedAsync); +TH_EXPORT_CPP_API_IsPointerVisibleAsync(IsPointerVisibleAsync); +TH_EXPORT_CPP_API_GetPointerStyleAsync(GetPointerStyleAsync); +TH_EXPORT_CPP_API_GetTouchpadDoubleTapAndDragStateAsync(GetTouchpadDoubleTapAndDragStateAsync); +TH_EXPORT_CPP_API_SetTouchpadDoubleTapAndDragStateAsync(SetTouchpadDoubleTapAndDragStateAsync); +TH_EXPORT_CPP_API_SetCustomCursorSync(SetCustomCursorSync); +TH_EXPORT_CPP_API_SetCustomCursorPixelMapAsync(SetCustomCursorPixelMapAsync); +TH_EXPORT_CPP_API_SetCustomCursorAsync(SetCustomCursorAsync); +TH_EXPORT_CPP_API_GetPointerSpeedSync(GetPointerSpeedSync); +TH_EXPORT_CPP_API_GetTouchpadRightClickTypeAsync(GetTouchpadRightClickTypeAsync); +TH_EXPORT_CPP_API_SetTouchpadRightClickTypeAsync(SetTouchpadRightClickTypeAsync); +TH_EXPORT_CPP_API_GetTouchpadSwipeSwitchAsync(GetTouchpadSwipeSwitchAsync); +TH_EXPORT_CPP_API_SetTouchpadSwipeSwitchAsync(SetTouchpadSwipeSwitchAsync); +TH_EXPORT_CPP_API_GetTouchpadPinchSwitchAsync(GetTouchpadPinchSwitchAsync); +TH_EXPORT_CPP_API_SetTouchpadPinchSwitchAsync(SetTouchpadPinchSwitchAsync); +TH_EXPORT_CPP_API_GetTouchpadPointerSpeedAsync(GetTouchpadPointerSpeedAsync); +TH_EXPORT_CPP_API_SetTouchpadPointerSpeedAsync(SetTouchpadPointerSpeedAsync); +TH_EXPORT_CPP_API_GetTouchpadTapSwitchAsync(GetTouchpadTapSwitchAsync); +TH_EXPORT_CPP_API_SetTouchpadTapSwitchAsync(SetTouchpadTapSwitchAsync); +TH_EXPORT_CPP_API_GetTouchpadScrollDirectionAsync(GetTouchpadScrollDirectionAsync); +TH_EXPORT_CPP_API_SetTouchpadScrollDirectionAsync(SetTouchpadScrollDirectionAsync); +TH_EXPORT_CPP_API_GetTouchpadScrollSwitchAsync(GetTouchpadScrollSwitchAsync); +TH_EXPORT_CPP_API_SetTouchpadScrollSwitchAsync(SetTouchpadScrollSwitchAsync); +TH_EXPORT_CPP_API_GetMouseScrollRowsAsync(GetMouseScrollRowsAsync); +TH_EXPORT_CPP_API_SetMouseScrollRowsAsync(SetMouseScrollRowsAsync); +TH_EXPORT_CPP_API_GetHoverScrollStateAsync(GetHoverScrollStateAsync); +TH_EXPORT_CPP_API_SetHoverScrollStateAsync(SetHoverScrollStateAsync); +TH_EXPORT_CPP_API_GetMousePrimaryButtonAsync(GetMousePrimaryButtonAsync); +TH_EXPORT_CPP_API_SetMousePrimaryButtonAsync(SetMousePrimaryButtonAsync); +TH_EXPORT_CPP_API_GetPointerSizeAsync(GetPointerSizeAsync); +TH_EXPORT_CPP_API_SetPointerSizeSync(SetPointerSizeSync); +TH_EXPORT_CPP_API_SetPointerSizeAsync(SetPointerSizeAsync); +TH_EXPORT_CPP_API_GetPointerColorAsync(GetPointerColorAsync); +TH_EXPORT_CPP_API_SetPointerColorSync(SetPointerColorSync); +TH_EXPORT_CPP_API_SetPointerColorAsync(SetPointerColorAsync); +TH_EXPORT_CPP_API_SetPointerSpeedSync(SetPointerSpeedSync); +TH_EXPORT_CPP_API_IsPointerVisibleSync(IsPointerVisibleSync); +TH_EXPORT_CPP_API_GetPointerColorSync(GetPointerColorSync); +TH_EXPORT_CPP_API_GetPointerSizeSync(GetPointerSizeSync); // NOLINTEND \ No newline at end of file -- Gitee From a6e5e8626790a9becb5739670f4200a6035c2859 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Mon, 28 Jul 2025 15:40:59 +0800 Subject: [PATCH 12/29] =?UTF-8?q?lmq=20=E5=A2=9E=E5=8A=A0pointer=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- .../ohos.multimodalInput.keyCode.impl.h | 386 -------------- .../src/ohos.multimodalInput.keyCode.impl.cpp | 367 +------------ frameworks/ets/pointer/BUILD.gn | 2 + .../idl/ohos.multimodalInput.pointer.taihe | 2 +- .../ohos.multimodalInput.pointer.impl.h | 15 - .../src/ohos.multimodalInput.pointer.impl.cpp | 488 +++++++++++++----- 6 files changed, 379 insertions(+), 881 deletions(-) delete mode 100644 frameworks/ets/key_code/include/ohos.multimodalInput.keyCode.impl.h diff --git a/frameworks/ets/key_code/include/ohos.multimodalInput.keyCode.impl.h b/frameworks/ets/key_code/include/ohos.multimodalInput.keyCode.impl.h deleted file mode 100644 index 0e1a21307e..0000000000 --- a/frameworks/ets/key_code/include/ohos.multimodalInput.keyCode.impl.h +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_MULTIMODALINPUT_KEY_CODE_IMPL_H -#define OHOS_MULTIMODALINPUT_KEY_CODE_IMPL_H - -#include "define_multimodal.h" -#include "input_manager.h" -#include "ohos.multimodalInput.keyCode.proj.hpp" -#include "ohos.multimodalInput.keyCode.impl.hpp" -#include "taihe/runtime.hpp" -#include "stdexcept" - -#include - -namespace OHOS { -namespace MMI { -using namespace ohos::multimodalInput::keyCode; - -enum KeyCodeEts { - KEYCODE_FN_ETS = 0, - KEYCODE_UNKNOWN_ETS = -1, - KEYCODE_HOME_ETS = 1, - KEYCODE_BACK_ETS = 2, - KEYCODE_SEARCH_ETS = 9, - KEYCODE_MEDIA_PLAY_PAUSE_ETS = 10, - KEYCODE_MEDIA_STOP_ETS = 11, - KEYCODE_MEDIA_NEXT_ETS = 12, - KEYCODE_MEDIA_PREVIOUS_ETS = 13, - KEYCODE_MEDIA_REWIND_ETS = 14, - KEYCODE_MEDIA_FAST_FORWARD_ETS = 15, - KEYCODE_VOLUME_UP_ETS = 16, - KEYCODE_VOLUME_DOWN_ETS = 17, - KEYCODE_POWER_ETS = 18, - KEYCODE_CAMERA_ETS = 19, - KEYCODE_VOLUME_MUTE_ETS = 22, - KEYCODE_MUTE_ETS = 23, - KEYCODE_BRIGHTNESS_UP_ETS = 40, - KEYCODE_BRIGHTNESS_DOWN_ETS = 41, - KEYCODE_0_ETS = 2000, - KEYCODE_1_ETS = 2001, - KEYCODE_2_ETS = 2002, - KEYCODE_3_ETS = 2003, - KEYCODE_4_ETS = 2004, - KEYCODE_5_ETS = 2005, - KEYCODE_6_ETS = 2006, - KEYCODE_7_ETS = 2007, - KEYCODE_8_ETS = 2008, - KEYCODE_9_ETS = 2009, - KEYCODE_STAR_ETS = 2010, - KEYCODE_POUND_ETS = 2011, - KEYCODE_DPAD_UP_ETS = 2012, - KEYCODE_DPAD_DOWN_ETS = 2013, - KEYCODE_DPAD_LEFT_ETS = 2014, - KEYCODE_DPAD_RIGHT_ETS = 2015, - KEYCODE_DPAD_CENTER_ETS = 2016, - KEYCODE_A_ETS = 2017, - KEYCODE_B_ETS = 2018, - KEYCODE_C_ETS = 2019, - KEYCODE_D_ETS = 2020, - KEYCODE_E_ETS = 2021, - KEYCODE_F_ETS = 2022, - KEYCODE_G_ETS = 2023, - KEYCODE_H_ETS = 2024, - KEYCODE_I_ETS = 2025, - KEYCODE_J_ETS = 2026, - KEYCODE_K_ETS = 2027, - KEYCODE_L_ETS = 2028, - KEYCODE_M_ETS = 2029, - KEYCODE_N_ETS = 2030, - KEYCODE_O_ETS = 2031, - KEYCODE_P_ETS = 2032, - KEYCODE_Q_ETS = 2033, - KEYCODE_R_ETS = 2034, - KEYCODE_S_ETS = 2035, - KEYCODE_T_ETS = 2036, - KEYCODE_U_ETS = 2037, - KEYCODE_V_ETS = 2038, - KEYCODE_W_ETS = 2039, - KEYCODE_X_ETS = 2040, - KEYCODE_Y_ETS = 2041, - KEYCODE_Z_ETS = 2042, - KEYCODE_COMMA_ETS = 2043, - KEYCODE_PERIOD_ETS = 2044, - KEYCODE_ALT_LEFT_ETS = 2045, - KEYCODE_ALT_RIGHT_ETS = 2046, - KEYCODE_SHIFT_LEFT_ETS = 2047, - KEYCODE_SHIFT_RIGHT_ETS = 2048, - KEYCODE_TAB_ETS = 2049, - KEYCODE_SPACE_ETS = 2050, - KEYCODE_SYM_ETS = 2051, - KEYCODE_EXPLORER_ETS = 2052, - KEYCODE_ENVELOPE_ETS = 2053, - KEYCODE_ENTER_ETS = 2054, - KEYCODE_DEL_ETS = 2055, - KEYCODE_GRAVE_ETS = 2056, - KEYCODE_MINUS_ETS = 2057, - KEYCODE_EQUALS_ETS = 2058, - KEYCODE_LEFT_BRACKET_ETS = 2059, - KEYCODE_RIGHT_BRACKET_ETS = 2060, - KEYCODE_BACKSLASH_ETS = 2061, - KEYCODE_SEMICOLON_ETS = 2062, - KEYCODE_APOSTROPHE_ETS = 2063, - KEYCODE_SLASH_ETS = 2064, - KEYCODE_AT_ETS = 2065, - KEYCODE_PLUS_ETS = 2066, - KEYCODE_MENU_ETS = 2067, - KEYCODE_PAGE_UP_ETS = 2068, - KEYCODE_PAGE_DOWN_ETS = 2069, - KEYCODE_ESCAPE_ETS = 2070, - KEYCODE_FORWARD_DEL_ETS = 2071, - KEYCODE_CTRL_LEFT_ETS = 2072, - KEYCODE_CTRL_RIGHT_ETS = 2073, - KEYCODE_CAPS_LOCK_ETS = 2074, - KEYCODE_SCROLL_LOCK_ETS = 2075, - KEYCODE_META_LEFT_ETS = 2076, - KEYCODE_META_RIGHT_ETS = 2077, - KEYCODE_FUNCTION_ETS = 2078, - KEYCODE_SYSRQ_ETS = 2079, - KEYCODE_BREAK_ETS = 2080, - KEYCODE_MOVE_HOME_ETS = 2081, - KEYCODE_MOVE_END_ETS = 2082, - KEYCODE_INSERT_ETS = 2083, - KEYCODE_FORWARD_ETS = 2084, - KEYCODE_MEDIA_PLAY_ETS = 2085, - KEYCODE_MEDIA_PAUSE_ETS = 2086, - KEYCODE_MEDIA_CLOSE_ETS = 2087, - KEYCODE_MEDIA_EJECT_ETS = 2088, - KEYCODE_MEDIA_RECORD_ETS = 2089, - KEYCODE_F1_ETS = 2090, - KEYCODE_F2_ETS = 2091, - KEYCODE_F3_ETS = 2092, - KEYCODE_F4_ETS = 2093, - KEYCODE_F5_ETS = 2094, - KEYCODE_F6_ETS = 2095, - KEYCODE_F7_ETS = 2096, - KEYCODE_F8_ETS = 2097, - KEYCODE_F9_ETS = 2098, - KEYCODE_F10_ETS = 2099, - KEYCODE_F11_ETS = 2100, - KEYCODE_F12_ETS = 2101, - KEYCODE_NUM_LOCK_ETS = 2102, - KEYCODE_NUMPAD_0_ETS = 2103, - KEYCODE_NUMPAD_1_ETS = 2104, - KEYCODE_NUMPAD_2_ETS = 2105, - KEYCODE_NUMPAD_3_ETS = 2106, - KEYCODE_NUMPAD_4_ETS = 2107, - KEYCODE_NUMPAD_5_ETS = 2108, - KEYCODE_NUMPAD_6_ETS = 2109, - KEYCODE_NUMPAD_7_ETS = 2110, - KEYCODE_NUMPAD_8_ETS = 2111, - KEYCODE_NUMPAD_9_ETS = 2112, - KEYCODE_NUMPAD_DIVIDE_ETS = 2113, - KEYCODE_NUMPAD_MULTIPLY_ETS = 2114, - KEYCODE_NUMPAD_SUBTRACT_ETS = 2115, - KEYCODE_NUMPAD_ADD_ETS = 2116, - KEYCODE_NUMPAD_DOT_ETS = 2117, - KEYCODE_NUMPAD_COMMA_ETS = 2118, - KEYCODE_NUMPAD_ENTER_ETS = 2119, - KEYCODE_NUMPAD_EQUALS_ETS = 2120, - KEYCODE_NUMPAD_LEFT_PAREN_ETS = 2121, - KEYCODE_NUMPAD_RIGHT_PAREN_ETS = 2122, - KEYCODE_VIRTUAL_MULTITASK_ETS = 2210, - KEYCODE_BUTTON_A_ETS = 2301, - KEYCODE_BUTTON_B_ETS = 2302, - KEYCODE_BUTTON_X_ETS = 2304, - KEYCODE_BUTTON_Y_ETS = 2305, - KEYCODE_BUTTON_L1_ETS = 2307, - KEYCODE_BUTTON_R1_ETS = 2308, - KEYCODE_BUTTON_L2_ETS = 2309, - KEYCODE_BUTTON_R2_ETS = 2310, - KEYCODE_BUTTON_SELECT_ETS = 2311, - KEYCODE_BUTTON_START_ETS = 2312, - KEYCODE_BUTTON_MODE_ETS = 2313, - KEYCODE_BUTTON_THUMBL_ETS = 2314, - KEYCODE_BUTTON_THUMBR_ETS = 2315, - KEYCODE_SLEEP_ETS = 2600, - KEYCODE_ZENKAKU_HANKAKU_ETS = 2601, - KEYCODE_102ND_ETS = 2602, - KEYCODE_RO_ETS = 2603, - KEYCODE_KATAKANA_ETS = 2604, - KEYCODE_HIRAGANA_ETS = 2605, - KEYCODE_HENKAN_ETS = 2606, - KEYCODE_KATAKANA_HIRAGANA_ETS = 2607, - KEYCODE_MUHENKAN_ETS = 2608, - KEYCODE_LINEFEED_ETS = 2609, - KEYCODE_MACRO_ETS = 2610, - KEYCODE_NUMPAD_PLUSMINUS_ETS = 2611, - KEYCODE_SCALE_ETS = 2612, - KEYCODE_HANGUEL_ETS = 2613, - KEYCODE_HANJA_ETS = 2614, - KEYCODE_YEN_ETS = 2615, - KEYCODE_STOP_ETS = 2616, - KEYCODE_AGAIN_ETS = 2617, - KEYCODE_PROPS_ETS = 2618, - KEYCODE_UNDO_ETS = 2619, - KEYCODE_COPY_ETS = 2620, - KEYCODE_OPEN_ETS = 2621, - KEYCODE_PASTE_ETS = 2622, - KEYCODE_FIND_ETS = 2623, - KEYCODE_CUT_ETS = 2624, - KEYCODE_HELP_ETS = 2625, - KEYCODE_CALC_ETS = 2626, - KEYCODE_FILE_ETS = 2627, - KEYCODE_BOOKMARKS_ETS = 2628, - KEYCODE_NEXT_ETS = 2629, - KEYCODE_PLAYPAUSE_ETS = 2630, - KEYCODE_PREVIOUS_ETS = 2631, - KEYCODE_STOPCD_ETS = 2632, - KEYCODE_CONFIG_ETS = 2634, - KEYCODE_REFRESH_ETS = 2635, - KEYCODE_EXIT_ETS = 2636, - KEYCODE_EDIT_ETS = 2637, - KEYCODE_SCROLLUP_ETS = 2638, - KEYCODE_SCROLLDOWN_ETS = 2639, - KEYCODE_NEW_ETS = 2640, - KEYCODE_REDO_ETS = 2641, - KEYCODE_CLOSE_ETS = 2642, - KEYCODE_PLAY_ETS = 2643, - KEYCODE_BASSBOOST_ETS = 2644, - KEYCODE_PRINT_ETS = 2645, - KEYCODE_CHAT_ETS = 2646, - KEYCODE_FINANCE_ETS = 2647, - KEYCODE_CANCEL_ETS = 2648, - KEYCODE_KBDILLUM_TOGGLE_ETS = 2649, - KEYCODE_KBDILLUM_DOWN_ETS = 2650, - KEYCODE_KBDILLUM_UP_ETS = 2651, - KEYCODE_SEND_ETS = 2652, - KEYCODE_REPLY_ETS = 2653, - KEYCODE_FORWARDMAIL_ETS = 2654, - KEYCODE_SAVE_ETS = 2655, - KEYCODE_DOCUMENTS_ETS = 2656, - KEYCODE_VIDEO_NEXT_ETS = 2657, - KEYCODE_VIDEO_PREV_ETS = 2658, - KEYCODE_BRIGHTNESS_CYCLE_ETS = 2659, - KEYCODE_BRIGHTNESS_ZERO_ETS = 2660, - KEYCODE_DISPLAY_OFF_ETS = 2661, - KEYCODE_BTN_MISC_ETS = 2662, - KEYCODE_GOTO_ETS = 2663, - KEYCODE_INFO_ETS = 2664, - KEYCODE_PROGRAM_ETS = 2665, - KEYCODE_PVR_ETS = 2666, - KEYCODE_SUBTITLE_ETS = 2667, - KEYCODE_FULL_SCREEN_ETS = 2668, - KEYCODE_KEYBOARD_ETS = 2669, - KEYCODE_ASPECT_RATIO_ETS = 2670, - KEYCODE_PC_ETS = 2671, - KEYCODE_TV_ETS = 2672, - KEYCODE_TV2_ETS = 2673, - KEYCODE_VCR_ETS = 2674, - KEYCODE_VCR2_ETS = 2675, - KEYCODE_SAT_ETS = 2676, - KEYCODE_CD_ETS = 2677, - KEYCODE_TAPE_ETS = 2678, - KEYCODE_TUNER_ETS = 2679, - KEYCODE_PLAYER_ETS = 2680, - KEYCODE_DVD_ETS = 2681, - KEYCODE_AUDIO_ETS = 2682, - KEYCODE_VIDEO_ETS = 2683, - KEYCODE_MEMO_ETS = 2684, - KEYCODE_CALENDAR_ETS = 2685, - KEYCODE_RED_ETS = 2686, - KEYCODE_GREEN_ETS = 2687, - KEYCODE_YELLOW_ETS = 2688, - KEYCODE_BLUE_ETS = 2689, - KEYCODE_CHANNELUP_ETS = 2690, - KEYCODE_CHANNELDOWN_ETS = 2691, - KEYCODE_LAST_ETS = 2692, - KEYCODE_RESTART_ETS = 2693, - KEYCODE_SLOW_ETS = 2694, - KEYCODE_SHUFFLE_ETS = 2695, - KEYCODE_VIDEOPHONE_ETS = 2696, - KEYCODE_GAMES_ETS = 2697, - KEYCODE_ZOOMIN_ETS = 2698, - KEYCODE_ZOOMOUT_ETS = 2699, - KEYCODE_ZOOMRESET_ETS = 2700, - KEYCODE_WORDPROCESSOR_ETS = 2701, - KEYCODE_EDITOR_ETS = 2702, - KEYCODE_SPREADSHEET_ETS = 2703, - KEYCODE_GRAPHICSEDITOR_ETS = 2704, - KEYCODE_PRESENTATION_ETS = 2705, - KEYCODE_DATABASE_ETS = 2706, - KEYCODE_NEWS_ETS = 2707, - KEYCODE_VOICEMAIL_ETS = 2708, - KEYCODE_ADDRESSBOOK_ETS = 2709, - KEYCODE_MESSENGER_ETS = 2710, - KEYCODE_BRIGHTNESS_TOGGLE_ETS = 2711, - KEYCODE_SPELLCHECK_ETS = 2712, - KEYCODE_COFFEE_ETS = 2713, - KEYCODE_MEDIA_REPEAT_ETS = 2714, - KEYCODE_IMAGES_ETS = 2715, - KEYCODE_BUTTONCONFIG_ETS = 2716, - KEYCODE_TASKMANAGER_ETS = 2717, - KEYCODE_JOURNAL_ETS = 2718, - KEYCODE_CONTROLPANEL_ETS = 2719, - KEYCODE_APPSELECT_ETS = 2720, - KEYCODE_SCREENSAVER_ETS = 2721, - KEYCODE_ASSISTANT_ETS = 2722, - KEYCODE_KBD_LAYOUT_NEXT_ETS = 2723, - KEYCODE_BRIGHTNESS_MIN_ETS = 2724, - KEYCODE_BRIGHTNESS_MAX_ETS = 2725, - KEYCODE_KBDINPUTASSIST_PREV_ETS = 2726, - KEYCODE_KBDINPUTASSIST_NEXT_ETS = 2727, - KEYCODE_KBDINPUTASSIST_PREVGROUP_ETS = 2728, - KEYCODE_KBDINPUTASSIST_NEXTGROUP_ETS = 2729, - KEYCODE_KBDINPUTASSIST_ACCEPT_ETS = 2730, - KEYCODE_KBDINPUTASSIST_CANCEL_ETS = 2731, - KEYCODE_FRONT_ETS = 2800, - KEYCODE_SETUP_ETS = 2801, - KEYCODE_WAKEUP_ETS = 2802, - KEYCODE_SENDFILE_ETS = 2803, - KEYCODE_DELETEFILE_ETS = 2804, - KEYCODE_XFER_ETS = 2805, - KEYCODE_PROG1_ETS = 2806, - KEYCODE_PROG2_ETS = 2807, - KEYCODE_MSDOS_ETS = 2808, - KEYCODE_SCREENLOCK_ETS = 2809, - KEYCODE_DIRECTION_ROTATE_DISPLAY_ETS = 2810, - KEYCODE_CYCLEWINDOWS_ETS = 2811, - KEYCODE_COMPUTER_ETS = 2812, - KEYCODE_EJECTCLOSECD_ETS = 2813, - KEYCODE_ISO_ETS = 2814, - KEYCODE_MOVE_ETS = 2815, - KEYCODE_F13_ETS = 2816, - KEYCODE_F14_ETS = 2817, - KEYCODE_F15_ETS = 2818, - KEYCODE_F16_ETS = 2819, - KEYCODE_F17_ETS = 2820, - KEYCODE_F18_ETS = 2821, - KEYCODE_F19_ETS = 2822, - KEYCODE_F20_ETS = 2823, - KEYCODE_F21_ETS = 2824, - KEYCODE_F22_ETS = 2825, - KEYCODE_F23_ETS = 2826, - KEYCODE_F24_ETS = 2827, - KEYCODE_PROG3_ETS = 2828, - KEYCODE_PROG4_ETS = 2829, - KEYCODE_DASHBOARD_ETS = 2830, - KEYCODE_SUSPEND_ETS = 2831, - KEYCODE_HP_ETS = 2832, - KEYCODE_SOUND_ETS = 2833, - KEYCODE_QUESTION_ETS = 2834, - KEYCODE_CONNECT_ETS = 2836, - KEYCODE_SPORT_ETS = 2837, - KEYCODE_SHOP_ETS = 2838, - KEYCODE_ALTERASE_ETS = 2839, - KEYCODE_SWITCHVIDEOMODE_ETS = 2841, - KEYCODE_BATTERY_ETS = 2842, - KEYCODE_BLUETOOTH_ETS = 2843, - KEYCODE_WLAN_ETS = 2844, - KEYCODE_UWB_ETS = 2845, - KEYCODE_WWAN_WIMAX_ETS = 2846, - KEYCODE_RFKILL_ETS = 2847, - KEYCODE_CHANNEL_ETS = 3001, - KEYCODE_BTN_0_ETS = 3100, - KEYCODE_BTN_1_ETS = 3101, - KEYCODE_BTN_2_ETS = 3102, - KEYCODE_BTN_3_ETS = 3103, - KEYCODE_BTN_4_ETS = 3104, - KEYCODE_BTN_5_ETS = 3105, - KEYCODE_BTN_6_ETS = 3106, - KEYCODE_BTN_7_ETS = 3107, - KEYCODE_BTN_8_ETS = 3108, - KEYCODE_BTN_9_ETS = 3109, - KEYCODE_DAGGER_CLICK_ETS = 3211, - KEYCODE_DAGGER_DOUBLE_CLICK_ETS = 3212, - KEYCODE_DAGGER_LONG_PRESS_ETS = 3213 -}; - -KeyCode ConvertEtsKeyCode(int32_t keyCode); - -} // namespace MMI -} // namespace OHOS -#endif // OHOS_MULTIMODALINPUT_KEY_CODE_IMPL_H diff --git a/frameworks/ets/key_code/src/ohos.multimodalInput.keyCode.impl.cpp b/frameworks/ets/key_code/src/ohos.multimodalInput.keyCode.impl.cpp index fdcbf988aa..3a5a9440e7 100644 --- a/frameworks/ets/key_code/src/ohos.multimodalInput.keyCode.impl.cpp +++ b/frameworks/ets/key_code/src/ohos.multimodalInput.keyCode.impl.cpp @@ -13,373 +13,14 @@ * limitations under the License. */ -#include "ohos.multimodalInput.keyCode.impl.h" -#undef MMI_LOG_TAG -#define MMI_LOG_TAG "ohos.multimodalInput.keyCode.impl" +#include "ohos.multimodalInput.keyCode.proj.hpp" +#include "ohos.multimodalInput.keyCode.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" namespace OHOS { namespace MMI { - -const static std::map KEY_CODE_TRANSFORMATION = { - { KEYCODE_FN_ETS, KeyCode::key_t::KEYCODE_FN }, - { KEYCODE_UNKNOWN_ETS, KeyCode::key_t::KEYCODE_UNKNOWN }, - { KEYCODE_HOME_ETS, KeyCode::key_t::KEYCODE_HOME }, - { KEYCODE_BACK_ETS, KeyCode::key_t::KEYCODE_BACK }, - { KEYCODE_SEARCH_ETS, KeyCode::key_t::KEYCODE_SEARCH }, - { KEYCODE_MEDIA_PLAY_PAUSE_ETS, KeyCode::key_t::KEYCODE_MEDIA_PLAY_PAUSE }, - { KEYCODE_MEDIA_STOP_ETS, KeyCode::key_t::KEYCODE_MEDIA_STOP }, - { KEYCODE_MEDIA_NEXT_ETS, KeyCode::key_t::KEYCODE_MEDIA_NEXT }, - { KEYCODE_MEDIA_PREVIOUS_ETS, KeyCode::key_t::KEYCODE_MEDIA_PREVIOUS }, - { KEYCODE_MEDIA_REWIND_ETS, KeyCode::key_t::KEYCODE_MEDIA_REWIND }, - { KEYCODE_MEDIA_FAST_FORWARD_ETS, KeyCode::key_t::KEYCODE_MEDIA_FAST_FORWARD }, - { KEYCODE_VOLUME_UP_ETS, KeyCode::key_t::KEYCODE_VOLUME_UP }, - { KEYCODE_VOLUME_DOWN_ETS, KeyCode::key_t::KEYCODE_VOLUME_DOWN }, - { KEYCODE_POWER_ETS, KeyCode::key_t::KEYCODE_POWER }, - { KEYCODE_CAMERA_ETS, KeyCode::key_t::KEYCODE_CAMERA }, - { KEYCODE_VOLUME_MUTE_ETS, KeyCode::key_t::KEYCODE_VOLUME_MUTE }, - { KEYCODE_MUTE_ETS, KeyCode::key_t::KEYCODE_MUTE }, - { KEYCODE_BRIGHTNESS_UP_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_UP }, - { KEYCODE_BRIGHTNESS_DOWN_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_DOWN }, - { KEYCODE_0_ETS, KeyCode::key_t::KEYCODE_0 }, - { KEYCODE_1_ETS, KeyCode::key_t::KEYCODE_1 }, - { KEYCODE_2_ETS, KeyCode::key_t::KEYCODE_2 }, - { KEYCODE_3_ETS, KeyCode::key_t::KEYCODE_3 }, - { KEYCODE_4_ETS, KeyCode::key_t::KEYCODE_4 }, - { KEYCODE_5_ETS, KeyCode::key_t::KEYCODE_5 }, - { KEYCODE_6_ETS, KeyCode::key_t::KEYCODE_6 }, - { KEYCODE_7_ETS, KeyCode::key_t::KEYCODE_7 }, - { KEYCODE_8_ETS, KeyCode::key_t::KEYCODE_8 }, - { KEYCODE_9_ETS, KeyCode::key_t::KEYCODE_9 }, - { KEYCODE_STAR_ETS, KeyCode::key_t::KEYCODE_STAR }, - { KEYCODE_POUND_ETS, KeyCode::key_t::KEYCODE_POUND }, - { KEYCODE_DPAD_UP_ETS, KeyCode::key_t::KEYCODE_DPAD_UP }, - { KEYCODE_DPAD_LEFT_ETS, KeyCode::key_t::KEYCODE_DPAD_LEFT }, - { KEYCODE_DPAD_RIGHT_ETS, KeyCode::key_t::KEYCODE_DPAD_RIGHT }, - { KEYCODE_DPAD_CENTER_ETS, KeyCode::key_t::KEYCODE_DPAD_CENTER }, - { KEYCODE_A_ETS, KeyCode::key_t::KEYCODE_A }, - { KEYCODE_B_ETS, KeyCode::key_t::KEYCODE_B }, - { KEYCODE_C_ETS, KeyCode::key_t::KEYCODE_C }, - { KEYCODE_D_ETS, KeyCode::key_t::KEYCODE_D }, - { KEYCODE_E_ETS, KeyCode::key_t::KEYCODE_E }, - { KEYCODE_F_ETS, KeyCode::key_t::KEYCODE_F }, - { KEYCODE_G_ETS, KeyCode::key_t::KEYCODE_G }, - { KEYCODE_H_ETS, KeyCode::key_t::KEYCODE_H }, - { KEYCODE_I_ETS, KeyCode::key_t::KEYCODE_I }, - { KEYCODE_J_ETS, KeyCode::key_t::KEYCODE_J }, - { KEYCODE_K_ETS, KeyCode::key_t::KEYCODE_K }, - { KEYCODE_L_ETS, KeyCode::key_t::KEYCODE_L }, - { KEYCODE_M_ETS, KeyCode::key_t::KEYCODE_M }, - { KEYCODE_N_ETS, KeyCode::key_t::KEYCODE_N }, - { KEYCODE_O_ETS, KeyCode::key_t::KEYCODE_O }, - { KEYCODE_P_ETS, KeyCode::key_t::KEYCODE_P }, - { KEYCODE_Q_ETS, KeyCode::key_t::KEYCODE_Q }, - { KEYCODE_R_ETS, KeyCode::key_t::KEYCODE_R }, - { KEYCODE_S_ETS, KeyCode::key_t::KEYCODE_S }, - { KEYCODE_T_ETS, KeyCode::key_t::KEYCODE_T }, - { KEYCODE_U_ETS, KeyCode::key_t::KEYCODE_U }, - { KEYCODE_V_ETS, KeyCode::key_t::KEYCODE_V }, - { KEYCODE_W_ETS, KeyCode::key_t::KEYCODE_W }, - { KEYCODE_X_ETS, KeyCode::key_t::KEYCODE_X }, - { KEYCODE_Y_ETS, KeyCode::key_t::KEYCODE_Y }, - { KEYCODE_Z_ETS, KeyCode::key_t::KEYCODE_Z }, - { KEYCODE_COMMA_ETS, KeyCode::key_t::KEYCODE_COMMA }, - { KEYCODE_PERIOD_ETS, KeyCode::key_t::KEYCODE_PERIOD }, - { KEYCODE_ALT_LEFT_ETS, KeyCode::key_t::KEYCODE_ALT_LEFT }, - { KEYCODE_ALT_RIGHT_ETS, KeyCode::key_t::KEYCODE_ALT_RIGHT }, - { KEYCODE_SHIFT_LEFT_ETS, KeyCode::key_t::KEYCODE_SHIFT_LEFT }, - { KEYCODE_SHIFT_RIGHT_ETS, KeyCode::key_t::KEYCODE_SHIFT_RIGHT }, - { KEYCODE_TAB_ETS, KeyCode::key_t::KEYCODE_TAB }, - { KEYCODE_SPACE_ETS, KeyCode::key_t::KEYCODE_SPACE }, - { KEYCODE_SYM_ETS, KeyCode::key_t::KEYCODE_SYM }, - { KEYCODE_EXPLORER_ETS, KeyCode::key_t::KEYCODE_EXPLORER }, - { KEYCODE_ENVELOPE_ETS, KeyCode::key_t::KEYCODE_ENVELOPE }, - { KEYCODE_ENTER_ETS, KeyCode::key_t::KEYCODE_ENTER }, - { KEYCODE_DEL_ETS, KeyCode::key_t::KEYCODE_DEL }, - { KEYCODE_GRAVE_ETS, KeyCode::key_t::KEYCODE_GRAVE }, - { KEYCODE_MINUS_ETS, KeyCode::key_t::KEYCODE_MINUS }, - { KEYCODE_EQUALS_ETS, KeyCode::key_t::KEYCODE_EQUALS }, - { KEYCODE_LEFT_BRACKET_ETS, KeyCode::key_t::KEYCODE_LEFT_BRACKET }, - { KEYCODE_RIGHT_BRACKET_ETS, KeyCode::key_t::KEYCODE_RIGHT_BRACKET }, - { KEYCODE_BACKSLASH_ETS, KeyCode::key_t::KEYCODE_BACKSLASH }, - { KEYCODE_SEMICOLON_ETS, KeyCode::key_t::KEYCODE_SEMICOLON }, - { KEYCODE_APOSTROPHE_ETS, KeyCode::key_t::KEYCODE_APOSTROPHE }, - { KEYCODE_SLASH_ETS, KeyCode::key_t::KEYCODE_SLASH }, - { KEYCODE_AT_ETS, KeyCode::key_t::KEYCODE_AT }, - { KEYCODE_PLUS_ETS, KeyCode::key_t::KEYCODE_PLUS }, - { KEYCODE_MENU_ETS, KeyCode::key_t::KEYCODE_MENU }, - { KEYCODE_PAGE_UP_ETS, KeyCode::key_t::KEYCODE_PAGE_UP }, - { KEYCODE_PAGE_DOWN_ETS, KeyCode::key_t::KEYCODE_PAGE_DOWN }, - { KEYCODE_ESCAPE_ETS, KeyCode::key_t::KEYCODE_ESCAPE }, - { KEYCODE_FORWARD_DEL_ETS, KeyCode::key_t::KEYCODE_FORWARD_DEL }, - { KEYCODE_CTRL_LEFT_ETS, KeyCode::key_t::KEYCODE_CTRL_LEFT }, - { KEYCODE_CTRL_RIGHT_ETS, KeyCode::key_t::KEYCODE_CTRL_RIGHT }, - { KEYCODE_CAPS_LOCK_ETS, KeyCode::key_t::KEYCODE_CAPS_LOCK }, - { KEYCODE_SCROLL_LOCK_ETS, KeyCode::key_t::KEYCODE_SCROLL_LOCK }, - { KEYCODE_META_LEFT_ETS, KeyCode::key_t::KEYCODE_META_LEFT }, - { KEYCODE_META_RIGHT_ETS, KeyCode::key_t::KEYCODE_META_RIGHT }, - { KEYCODE_FUNCTION_ETS, KeyCode::key_t::KEYCODE_FUNCTION }, - { KEYCODE_SYSRQ_ETS, KeyCode::key_t::KEYCODE_SYSRQ }, - { KEYCODE_BREAK_ETS, KeyCode::key_t::KEYCODE_BREAK }, - { KEYCODE_MOVE_HOME_ETS, KeyCode::key_t::KEYCODE_MOVE_HOME }, - { KEYCODE_MOVE_END_ETS, KeyCode::key_t::KEYCODE_MOVE_END }, - { KEYCODE_INSERT_ETS, KeyCode::key_t::KEYCODE_INSERT }, - { KEYCODE_FORWARD_ETS, KeyCode::key_t::KEYCODE_FORWARD }, - { KEYCODE_MEDIA_PLAY_ETS, KeyCode::key_t::KEYCODE_MEDIA_PLAY }, - { KEYCODE_MEDIA_PAUSE_ETS, KeyCode::key_t::KEYCODE_MEDIA_PAUSE }, - { KEYCODE_MEDIA_CLOSE_ETS, KeyCode::key_t::KEYCODE_MEDIA_CLOSE }, - { KEYCODE_MEDIA_EJECT_ETS, KeyCode::key_t::KEYCODE_MEDIA_EJECT }, - { KEYCODE_MEDIA_RECORD_ETS, KeyCode::key_t::KEYCODE_MEDIA_RECORD }, - { KEYCODE_F1_ETS, KeyCode::key_t::KEYCODE_F1 }, - { KEYCODE_F2_ETS, KeyCode::key_t::KEYCODE_F2 }, - { KEYCODE_F3_ETS, KeyCode::key_t::KEYCODE_F3 }, - { KEYCODE_F4_ETS, KeyCode::key_t::KEYCODE_F4 }, - { KEYCODE_F5_ETS, KeyCode::key_t::KEYCODE_F5 }, - { KEYCODE_F6_ETS, KeyCode::key_t::KEYCODE_F6 }, - { KEYCODE_F7_ETS, KeyCode::key_t::KEYCODE_F7 }, - { KEYCODE_F8_ETS, KeyCode::key_t::KEYCODE_F8 }, - { KEYCODE_F9_ETS, KeyCode::key_t::KEYCODE_F9 }, - { KEYCODE_F10_ETS, KeyCode::key_t::KEYCODE_F10 }, - { KEYCODE_F11_ETS, KeyCode::key_t::KEYCODE_F11 }, - { KEYCODE_F12_ETS, KeyCode::key_t::KEYCODE_F12 }, - { KEYCODE_NUM_LOCK_ETS, KeyCode::key_t::KEYCODE_NUM_LOCK }, - { KEYCODE_NUMPAD_0_ETS, KeyCode::key_t::KEYCODE_NUMPAD_0 }, - { KEYCODE_NUMPAD_1_ETS, KeyCode::key_t::KEYCODE_NUMPAD_1 }, - { KEYCODE_NUMPAD_2_ETS, KeyCode::key_t::KEYCODE_NUMPAD_2 }, - { KEYCODE_NUMPAD_3_ETS, KeyCode::key_t::KEYCODE_NUMPAD_3 }, - { KEYCODE_NUMPAD_4_ETS, KeyCode::key_t::KEYCODE_NUMPAD_4 }, - { KEYCODE_NUMPAD_5_ETS, KeyCode::key_t::KEYCODE_NUMPAD_5 }, - { KEYCODE_NUMPAD_6_ETS, KeyCode::key_t::KEYCODE_NUMPAD_6 }, - { KEYCODE_NUMPAD_7_ETS, KeyCode::key_t::KEYCODE_NUMPAD_7 }, - { KEYCODE_NUMPAD_8_ETS, KeyCode::key_t::KEYCODE_NUMPAD_8 }, - { KEYCODE_NUMPAD_9_ETS, KeyCode::key_t::KEYCODE_NUMPAD_9 }, - { KEYCODE_NUMPAD_DIVIDE_ETS, KeyCode::key_t::KEYCODE_NUMPAD_DIVIDE }, - { KEYCODE_NUMPAD_MULTIPLY_ETS, KeyCode::key_t::KEYCODE_NUMPAD_MULTIPLY }, - { KEYCODE_NUMPAD_SUBTRACT_ETS, KeyCode::key_t::KEYCODE_NUMPAD_SUBTRACT }, - { KEYCODE_NUMPAD_ADD_ETS, KeyCode::key_t::KEYCODE_NUMPAD_ADD }, - { KEYCODE_NUMPAD_DOT_ETS, KeyCode::key_t::KEYCODE_NUMPAD_DOT }, - { KEYCODE_NUMPAD_COMMA_ETS, KeyCode::key_t::KEYCODE_NUMPAD_COMMA }, - { KEYCODE_NUMPAD_ENTER_ETS, KeyCode::key_t::KEYCODE_NUMPAD_ENTER }, - { KEYCODE_NUMPAD_EQUALS_ETS, KeyCode::key_t::KEYCODE_NUMPAD_EQUALS }, - { KEYCODE_NUMPAD_LEFT_PAREN_ETS, KeyCode::key_t::KEYCODE_NUMPAD_LEFT_PAREN }, - { KEYCODE_NUMPAD_RIGHT_PAREN_ETS, KeyCode::key_t::KEYCODE_NUMPAD_RIGHT_PAREN }, - { KEYCODE_VIRTUAL_MULTITASK_ETS, KeyCode::key_t::KEYCODE_VIRTUAL_MULTITASK }, - { KEYCODE_BUTTON_A_ETS, KeyCode::key_t::KEYCODE_BUTTON_A }, - { KEYCODE_BUTTON_B_ETS, KeyCode::key_t::KEYCODE_BUTTON_B }, - { KEYCODE_BUTTON_X_ETS, KeyCode::key_t::KEYCODE_BUTTON_X }, - { KEYCODE_BUTTON_Y_ETS, KeyCode::key_t::KEYCODE_BUTTON_Y }, - { KEYCODE_BUTTON_L1_ETS, KeyCode::key_t::KEYCODE_BUTTON_L1 }, - { KEYCODE_BUTTON_R1_ETS, KeyCode::key_t::KEYCODE_BUTTON_R1 }, - { KEYCODE_BUTTON_L2_ETS, KeyCode::key_t::KEYCODE_BUTTON_L2 }, - { KEYCODE_BUTTON_R2_ETS, KeyCode::key_t::KEYCODE_BUTTON_R2 }, - { KEYCODE_BUTTON_SELECT_ETS, KeyCode::key_t::KEYCODE_BUTTON_SELECT }, - { KEYCODE_BUTTON_START_ETS, KeyCode::key_t::KEYCODE_BUTTON_START }, - { KEYCODE_BUTTON_MODE_ETS, KeyCode::key_t::KEYCODE_BUTTON_MODE }, - { KEYCODE_BUTTON_THUMBL_ETS, KeyCode::key_t::KEYCODE_BUTTON_THUMBL }, - { KEYCODE_BUTTON_THUMBR_ETS, KeyCode::key_t::KEYCODE_BUTTON_THUMBR }, - { KEYCODE_SLEEP_ETS, KeyCode::key_t::KEYCODE_SLEEP }, - { KEYCODE_ZENKAKU_HANKAKU_ETS, KeyCode::key_t::KEYCODE_ZENKAKU_HANKAKU }, - { KEYCODE_102ND_ETS, KeyCode::key_t::KEYCODE_102ND }, - { KEYCODE_RO_ETS, KeyCode::key_t::KEYCODE_RO }, - { KEYCODE_KATAKANA_ETS, KeyCode::key_t::KEYCODE_KATAKANA }, - { KEYCODE_HIRAGANA_ETS, KeyCode::key_t::KEYCODE_HIRAGANA }, - { KEYCODE_HENKAN_ETS, KeyCode::key_t::KEYCODE_HENKAN }, - { KEYCODE_KATAKANA_HIRAGANA_ETS, KeyCode::key_t::KEYCODE_KATAKANA_HIRAGANA }, - { KEYCODE_MUHENKAN_ETS, KeyCode::key_t::KEYCODE_MUHENKAN }, - { KEYCODE_LINEFEED_ETS, KeyCode::key_t::KEYCODE_LINEFEED }, - { KEYCODE_MACRO_ETS, KeyCode::key_t::KEYCODE_MACRO }, - { KEYCODE_NUMPAD_PLUSMINUS_ETS, KeyCode::key_t::KEYCODE_NUMPAD_PLUSMINUS }, - { KEYCODE_SCALE_ETS, KeyCode::key_t::KEYCODE_SCALE }, - { KEYCODE_HANGUEL_ETS, KeyCode::key_t::KEYCODE_HANGUEL }, - { KEYCODE_HANJA_ETS, KeyCode::key_t::KEYCODE_HANJA }, - { KEYCODE_YEN_ETS, KeyCode::key_t::KEYCODE_YEN }, - { KEYCODE_STOP_ETS, KeyCode::key_t::KEYCODE_STOP }, - { KEYCODE_AGAIN_ETS, KeyCode::key_t::KEYCODE_AGAIN }, - { KEYCODE_PROPS_ETS, KeyCode::key_t::KEYCODE_PROPS }, - { KEYCODE_UNDO_ETS, KeyCode::key_t::KEYCODE_UNDO }, - { KEYCODE_COPY_ETS, KeyCode::key_t::KEYCODE_COPY }, - { KEYCODE_OPEN_ETS, KeyCode::key_t::KEYCODE_OPEN }, - { KEYCODE_PASTE_ETS, KeyCode::key_t::KEYCODE_PASTE }, - { KEYCODE_FIND_ETS, KeyCode::key_t::KEYCODE_FIND }, - { KEYCODE_CUT_ETS, KeyCode::key_t::KEYCODE_CUT }, - { KEYCODE_HELP_ETS, KeyCode::key_t::KEYCODE_HELP }, - { KEYCODE_CALC_ETS, KeyCode::key_t::KEYCODE_CALC }, - { KEYCODE_FILE_ETS, KeyCode::key_t::KEYCODE_FILE }, - { KEYCODE_BOOKMARKS_ETS, KeyCode::key_t::KEYCODE_BOOKMARKS }, - { KEYCODE_NEXT_ETS, KeyCode::key_t::KEYCODE_NEXT }, - { KEYCODE_PLAYPAUSE_ETS, KeyCode::key_t::KEYCODE_PLAYPAUSE }, - { KEYCODE_PREVIOUS_ETS, KeyCode::key_t::KEYCODE_PREVIOUS }, - { KEYCODE_STOPCD_ETS, KeyCode::key_t::KEYCODE_STOPCD }, - { KEYCODE_CONFIG_ETS, KeyCode::key_t::KEYCODE_CONFIG }, - { KEYCODE_REFRESH_ETS, KeyCode::key_t::KEYCODE_REFRESH }, - { KEYCODE_EXIT_ETS, KeyCode::key_t::KEYCODE_EXIT }, - { KEYCODE_EDIT_ETS, KeyCode::key_t::KEYCODE_EDIT }, - { KEYCODE_SCROLLUP_ETS, KeyCode::key_t::KEYCODE_SCROLLUP }, - { KEYCODE_SCROLLDOWN_ETS, KeyCode::key_t::KEYCODE_SCROLLDOWN }, - { KEYCODE_NEW_ETS, KeyCode::key_t::KEYCODE_NEW }, - { KEYCODE_REDO_ETS, KeyCode::key_t::KEYCODE_REDO }, - { KEYCODE_CLOSE_ETS, KeyCode::key_t::KEYCODE_CLOSE }, - { KEYCODE_PLAY_ETS, KeyCode::key_t::KEYCODE_PLAY }, - { KEYCODE_BASSBOOST_ETS, KeyCode::key_t::KEYCODE_BASSBOOST }, - { KEYCODE_PRINT_ETS, KeyCode::key_t::KEYCODE_PRINT }, - { KEYCODE_CHAT_ETS, KeyCode::key_t::KEYCODE_CHAT }, - { KEYCODE_FINANCE_ETS, KeyCode::key_t::KEYCODE_FINANCE }, - { KEYCODE_CANCEL_ETS, KeyCode::key_t::KEYCODE_CANCEL }, - { KEYCODE_KBDILLUM_TOGGLE_ETS, KeyCode::key_t::KEYCODE_KBDILLUM_TOGGLE }, - { KEYCODE_KBDILLUM_DOWN_ETS, KeyCode::key_t::KEYCODE_KBDILLUM_DOWN }, - { KEYCODE_KBDILLUM_UP_ETS, KeyCode::key_t::KEYCODE_KBDILLUM_UP }, - { KEYCODE_SEND_ETS, KeyCode::key_t::KEYCODE_SEND }, - { KEYCODE_REPLY_ETS, KeyCode::key_t::KEYCODE_REPLY }, - { KEYCODE_FORWARDMAIL_ETS, KeyCode::key_t::KEYCODE_FORWARDMAIL }, - { KEYCODE_SAVE_ETS, KeyCode::key_t::KEYCODE_SAVE }, - { KEYCODE_DOCUMENTS_ETS, KeyCode::key_t::KEYCODE_DOCUMENTS }, - { KEYCODE_VIDEO_NEXT_ETS, KeyCode::key_t::KEYCODE_VIDEO_NEXT }, - { KEYCODE_VIDEO_PREV_ETS, KeyCode::key_t::KEYCODE_VIDEO_PREV }, - { KEYCODE_BRIGHTNESS_CYCLE_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_CYCLE }, - { KEYCODE_BRIGHTNESS_ZERO_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_ZERO }, - { KEYCODE_DISPLAY_OFF_ETS, KeyCode::key_t::KEYCODE_DISPLAY_OFF }, - { KEYCODE_BTN_MISC_ETS, KeyCode::key_t::KEYCODE_BTN_MISC }, - { KEYCODE_GOTO_ETS, KeyCode::key_t::KEYCODE_GOTO }, - { KEYCODE_INFO_ETS, KeyCode::key_t::KEYCODE_INFO }, - { KEYCODE_PROGRAM_ETS, KeyCode::key_t::KEYCODE_PROGRAM }, - { KEYCODE_PVR_ETS, KeyCode::key_t::KEYCODE_PVR }, - { KEYCODE_SUBTITLE_ETS, KeyCode::key_t::KEYCODE_SUBTITLE }, - { KEYCODE_FULL_SCREEN_ETS, KeyCode::key_t::KEYCODE_FULL_SCREEN }, - { KEYCODE_KEYBOARD_ETS, KeyCode::key_t::KEYCODE_KEYBOARD }, - { KEYCODE_ASPECT_RATIO_ETS, KeyCode::key_t::KEYCODE_ASPECT_RATIO }, - { KEYCODE_PC_ETS, KeyCode::key_t::KEYCODE_PC }, - { KEYCODE_TV_ETS, KeyCode::key_t::KEYCODE_TV }, - { KEYCODE_TV2_ETS, KeyCode::key_t::KEYCODE_TV2 }, - { KEYCODE_VCR_ETS, KeyCode::key_t::KEYCODE_VCR }, - { KEYCODE_VCR2_ETS, KeyCode::key_t::KEYCODE_VCR2 }, - { KEYCODE_SAT_ETS, KeyCode::key_t::KEYCODE_SAT }, - { KEYCODE_CD_ETS, KeyCode::key_t::KEYCODE_CD }, - { KEYCODE_TAPE_ETS, KeyCode::key_t::KEYCODE_TAPE }, - { KEYCODE_TUNER_ETS, KeyCode::key_t::KEYCODE_TUNER }, - { KEYCODE_PLAYER_ETS, KeyCode::key_t::KEYCODE_PLAYER }, - { KEYCODE_DVD_ETS, KeyCode::key_t::KEYCODE_DVD }, - { KEYCODE_AUDIO_ETS, KeyCode::key_t::KEYCODE_AUDIO }, - { KEYCODE_VIDEO_ETS, KeyCode::key_t::KEYCODE_VIDEO }, - { KEYCODE_MEMO_ETS, KeyCode::key_t::KEYCODE_MEMO }, - { KEYCODE_CALENDAR_ETS, KeyCode::key_t::KEYCODE_CALENDAR }, - { KEYCODE_RED_ETS, KeyCode::key_t::KEYCODE_RED }, - { KEYCODE_GREEN_ETS, KeyCode::key_t::KEYCODE_GREEN }, - { KEYCODE_YELLOW_ETS, KeyCode::key_t::KEYCODE_YELLOW }, - { KEYCODE_BLUE_ETS, KeyCode::key_t::KEYCODE_BLUE }, - { KEYCODE_CHANNELUP_ETS, KeyCode::key_t::KEYCODE_CHANNELUP }, - { KEYCODE_CHANNELDOWN_ETS, KeyCode::key_t::KEYCODE_CHANNELDOWN }, - { KEYCODE_LAST_ETS, KeyCode::key_t::KEYCODE_LAST }, - { KEYCODE_RESTART_ETS, KeyCode::key_t::KEYCODE_RESTART }, - { KEYCODE_SLOW_ETS, KeyCode::key_t::KEYCODE_SLOW }, - { KEYCODE_SHUFFLE_ETS, KeyCode::key_t::KEYCODE_SHUFFLE }, - { KEYCODE_VIDEOPHONE_ETS, KeyCode::key_t::KEYCODE_VIDEOPHONE }, - { KEYCODE_GAMES_ETS, KeyCode::key_t::KEYCODE_GAMES }, - { KEYCODE_ZOOMIN_ETS, KeyCode::key_t::KEYCODE_ZOOMIN }, - { KEYCODE_ZOOMOUT_ETS, KeyCode::key_t::KEYCODE_ZOOMOUT }, - { KEYCODE_ZOOMRESET_ETS, KeyCode::key_t::KEYCODE_ZOOMRESET }, - { KEYCODE_WORDPROCESSOR_ETS, KeyCode::key_t::KEYCODE_WORDPROCESSOR }, - { KEYCODE_EDITOR_ETS, KeyCode::key_t::KEYCODE_EDITOR }, - { KEYCODE_SPREADSHEET_ETS, KeyCode::key_t::KEYCODE_SPREADSHEET }, - { KEYCODE_GRAPHICSEDITOR_ETS, KeyCode::key_t::KEYCODE_GRAPHICSEDITOR }, - { KEYCODE_PRESENTATION_ETS, KeyCode::key_t::KEYCODE_PRESENTATION }, - { KEYCODE_DATABASE_ETS, KeyCode::key_t::KEYCODE_DATABASE }, - { KEYCODE_NEWS_ETS, KeyCode::key_t::KEYCODE_NEWS }, - { KEYCODE_VOICEMAIL_ETS, KeyCode::key_t::KEYCODE_VOICEMAIL }, - { KEYCODE_ADDRESSBOOK_ETS, KeyCode::key_t::KEYCODE_ADDRESSBOOK }, - { KEYCODE_MESSENGER_ETS, KeyCode::key_t::KEYCODE_MESSENGER }, - { KEYCODE_BRIGHTNESS_TOGGLE_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_TOGGLE }, - { KEYCODE_SPELLCHECK_ETS, KeyCode::key_t::KEYCODE_SPELLCHECK }, - { KEYCODE_COFFEE_ETS, KeyCode::key_t::KEYCODE_COFFEE }, - { KEYCODE_MEDIA_REPEAT_ETS, KeyCode::key_t::KEYCODE_MEDIA_REPEAT }, - { KEYCODE_IMAGES_ETS, KeyCode::key_t::KEYCODE_IMAGES }, - { KEYCODE_BUTTONCONFIG_ETS, KeyCode::key_t::KEYCODE_BUTTONCONFIG }, - { KEYCODE_TASKMANAGER_ETS, KeyCode::key_t::KEYCODE_TASKMANAGER }, - { KEYCODE_JOURNAL_ETS, KeyCode::key_t::KEYCODE_JOURNAL }, - { KEYCODE_CONTROLPANEL_ETS, KeyCode::key_t::KEYCODE_CONTROLPANEL }, - { KEYCODE_APPSELECT_ETS, KeyCode::key_t::KEYCODE_APPSELECT }, - { KEYCODE_SCREENSAVER_ETS, KeyCode::key_t::KEYCODE_SCREENSAVER }, - { KEYCODE_ASSISTANT_ETS, KeyCode::key_t::KEYCODE_ASSISTANT }, - { KEYCODE_KBD_LAYOUT_NEXT_ETS, KeyCode::key_t::KEYCODE_KBD_LAYOUT_NEXT }, - { KEYCODE_BRIGHTNESS_MIN_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_MIN }, - { KEYCODE_BRIGHTNESS_MAX_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_MAX }, - { KEYCODE_KBDINPUTASSIST_PREV_ETS, KeyCode::key_t::KEYCODE_KBDINPUTASSIST_PREV }, - { KEYCODE_KBDINPUTASSIST_NEXT_ETS, KeyCode::key_t::KEYCODE_KBDINPUTASSIST_NEXT }, - { KEYCODE_KBDINPUTASSIST_PREVGROUP_ETS, KeyCode::key_t::KEYCODE_KBDINPUTASSIST_PREVGROUP }, - { KEYCODE_KBDINPUTASSIST_NEXTGROUP_ETS, KeyCode::key_t::KEYCODE_KBDINPUTASSIST_NEXTGROUP }, - { KEYCODE_KBDINPUTASSIST_ACCEPT_ETS, KeyCode::key_t::KEYCODE_KBDINPUTASSIST_ACCEPT }, - { KEYCODE_KBDINPUTASSIST_CANCEL_ETS, KeyCode::key_t::KEYCODE_KBDINPUTASSIST_CANCEL }, - { KEYCODE_FRONT_ETS, KeyCode::key_t::KEYCODE_FRONT }, - { KEYCODE_SETUP_ETS, KeyCode::key_t::KEYCODE_SETUP }, - { KEYCODE_WAKEUP_ETS, KeyCode::key_t::KEYCODE_WAKEUP }, - { KEYCODE_SENDFILE_ETS, KeyCode::key_t::KEYCODE_SENDFILE }, - { KEYCODE_DELETEFILE_ETS, KeyCode::key_t::KEYCODE_DELETEFILE }, - { KEYCODE_XFER_ETS, KeyCode::key_t::KEYCODE_XFER }, - { KEYCODE_PROG1_ETS, KeyCode::key_t::KEYCODE_PROG1 }, - { KEYCODE_PROG2_ETS, KeyCode::key_t::KEYCODE_PROG2 }, - { KEYCODE_MSDOS_ETS, KeyCode::key_t::KEYCODE_MSDOS }, - { KEYCODE_SCREENLOCK_ETS, KeyCode::key_t::KEYCODE_SCREENLOCK }, - { KEYCODE_DIRECTION_ROTATE_DISPLAY_ETS, KeyCode::key_t::KEYCODE_DIRECTION_ROTATE_DISPLAY }, - { KEYCODE_CYCLEWINDOWS_ETS, KeyCode::key_t::KEYCODE_CYCLEWINDOWS }, - { KEYCODE_COMPUTER_ETS, KeyCode::key_t::KEYCODE_COMPUTER }, - { KEYCODE_EJECTCLOSECD_ETS, KeyCode::key_t::KEYCODE_EJECTCLOSECD }, - { KEYCODE_ISO_ETS, KeyCode::key_t::KEYCODE_ISO }, - { KEYCODE_MOVE_ETS, KeyCode::key_t::KEYCODE_MOVE }, - { KEYCODE_F13_ETS, KeyCode::key_t::KEYCODE_F13 }, - { KEYCODE_F14_ETS, KeyCode::key_t::KEYCODE_F14 }, - { KEYCODE_F15_ETS, KeyCode::key_t::KEYCODE_F15 }, - { KEYCODE_F16_ETS, KeyCode::key_t::KEYCODE_F16 }, - { KEYCODE_F17_ETS, KeyCode::key_t::KEYCODE_F17 }, - { KEYCODE_F18_ETS, KeyCode::key_t::KEYCODE_F18 }, - { KEYCODE_F19_ETS, KeyCode::key_t::KEYCODE_F19 }, - { KEYCODE_F20_ETS, KeyCode::key_t::KEYCODE_F20 }, - { KEYCODE_F21_ETS, KeyCode::key_t::KEYCODE_F21 }, - { KEYCODE_F22_ETS, KeyCode::key_t::KEYCODE_F22 }, - { KEYCODE_F23_ETS, KeyCode::key_t::KEYCODE_F23 }, - { KEYCODE_F24_ETS, KeyCode::key_t::KEYCODE_F24 }, - { KEYCODE_PROG3_ETS, KeyCode::key_t::KEYCODE_PROG3 }, - { KEYCODE_PROG4_ETS, KeyCode::key_t::KEYCODE_PROG4 }, - { KEYCODE_DASHBOARD_ETS, KeyCode::key_t::KEYCODE_DASHBOARD }, - { KEYCODE_SUSPEND_ETS, KeyCode::key_t::KEYCODE_SUSPEND }, - { KEYCODE_HP_ETS, KeyCode::key_t::KEYCODE_HP }, - { KEYCODE_SOUND_ETS, KeyCode::key_t::KEYCODE_SOUND }, - { KEYCODE_QUESTION_ETS, KeyCode::key_t::KEYCODE_QUESTION }, - { KEYCODE_CONNECT_ETS, KeyCode::key_t::KEYCODE_CONNECT }, - { KEYCODE_SPORT_ETS, KeyCode::key_t::KEYCODE_SPORT }, - { KEYCODE_SHOP_ETS, KeyCode::key_t::KEYCODE_SHOP }, - { KEYCODE_ALTERASE_ETS, KeyCode::key_t::KEYCODE_ALTERASE }, - { KEYCODE_SWITCHVIDEOMODE_ETS, KeyCode::key_t::KEYCODE_SWITCHVIDEOMODE }, - { KEYCODE_BATTERY_ETS, KeyCode::key_t::KEYCODE_BATTERY }, - { KEYCODE_BLUETOOTH_ETS, KeyCode::key_t::KEYCODE_BLUETOOTH }, - { KEYCODE_WLAN_ETS, KeyCode::key_t::KEYCODE_WLAN }, - { KEYCODE_UWB_ETS, KeyCode::key_t::KEYCODE_UWB }, - { KEYCODE_WWAN_WIMAX_ETS, KeyCode::key_t::KEYCODE_WWAN_WIMAX }, - { KEYCODE_RFKILL_ETS, KeyCode::key_t::KEYCODE_RFKILL }, - { KEYCODE_CHANNEL_ETS, KeyCode::key_t::KEYCODE_CHANNEL }, - { KEYCODE_BTN_0_ETS, KeyCode::key_t::KEYCODE_BTN_0 }, - { KEYCODE_BTN_1_ETS, KeyCode::key_t::KEYCODE_BTN_1 }, - { KEYCODE_BTN_2_ETS, KeyCode::key_t::KEYCODE_BTN_2 }, - { KEYCODE_BTN_3_ETS, KeyCode::key_t::KEYCODE_BTN_3 }, - { KEYCODE_BTN_4_ETS, KeyCode::key_t::KEYCODE_BTN_4 }, - { KEYCODE_BTN_5_ETS, KeyCode::key_t::KEYCODE_BTN_5 }, - { KEYCODE_BTN_6_ETS, KeyCode::key_t::KEYCODE_BTN_6 }, - { KEYCODE_BTN_7_ETS, KeyCode::key_t::KEYCODE_BTN_7 }, - { KEYCODE_BTN_8_ETS, KeyCode::key_t::KEYCODE_BTN_8 }, - { KEYCODE_BTN_9_ETS, KeyCode::key_t::KEYCODE_BTN_9 }, - { KEYCODE_DAGGER_CLICK_ETS, KeyCode::key_t::KEYCODE_DAGGER_CLICK }, - { KEYCODE_DAGGER_DOUBLE_CLICK_ETS, KeyCode::key_t::KEYCODE_DAGGER_DOUBLE_CLICK }, - { KEYCODE_DAGGER_LONG_PRESS_ETS, KeyCode::key_t::KEYCODE_DAGGER_LONG_PRESS } -}; - -KeyCode ConvertEtsKeyCode(int32_t keyCode) -{ - auto iter = KEY_CODE_TRANSFORMATION.find(keyCode); - if (iter == KEY_CODE_TRANSFORMATION.end()) { - MMI_HILOGE("Find failed, keyCode:%{public}d", keyCode); - return KeyCode::key_t::KEYCODE_UNKNOWN; - } - return iter->second; -} - } // namespace MMI } // namespace OHOS diff --git a/frameworks/ets/pointer/BUILD.gn b/frameworks/ets/pointer/BUILD.gn index bd267e248d..87c15aca82 100644 --- a/frameworks/ets/pointer/BUILD.gn +++ b/frameworks/ets/pointer/BUILD.gn @@ -20,6 +20,7 @@ config("pointer_config") { visibility = [ ":*" ] include_dirs = [ + "${mmi_path}/frameworks/ets/common/include", "${mmi_path}/util/common/include", "${mmi_path}/tools/event_inject/include", "${mmi_path}/interfaces/native/innerkits/proxy/include", @@ -58,6 +59,7 @@ taihe_shared_library("Pointer") { ":run_taihe", "${mmi_path}/frameworks/proxy:libmmi-client", "${mmi_path}/util:libmmi-util", + "${mmi_path}/frameworks/ets/common:ets_inputcommon_package", ] branch_protector_ret = "pac_ret" sanitize = { diff --git a/frameworks/ets/pointer/idl/ohos.multimodalInput.pointer.taihe b/frameworks/ets/pointer/idl/ohos.multimodalInput.pointer.taihe index 16f80c8e18..545489a612 100644 --- a/frameworks/ets/pointer/idl/ohos.multimodalInput.pointer.taihe +++ b/frameworks/ets/pointer/idl/ohos.multimodalInput.pointer.taihe @@ -164,7 +164,7 @@ function SetTouchpadPinchSwitchAsync(state: bool): void; @gen_async("getTouchpadPointerSpeed") @gen_promise("getTouchpadPointerSpeed") -function GetTouchpadPointerSpeedAsync(): bool; +function GetTouchpadPointerSpeedAsync(): i32; @gen_async("setTouchpadPointerSpeed") @gen_promise("setTouchpadPointerSpeed") diff --git a/frameworks/ets/pointer/include/ohos.multimodalInput.pointer.impl.h b/frameworks/ets/pointer/include/ohos.multimodalInput.pointer.impl.h index 2f0dcbca7e..54df377c12 100644 --- a/frameworks/ets/pointer/include/ohos.multimodalInput.pointer.impl.h +++ b/frameworks/ets/pointer/include/ohos.multimodalInput.pointer.impl.h @@ -72,19 +72,4 @@ enum PointerStyleCode { RUNNING_IMPL, MIDDLE_BTN_EAST_WEST_IMPL }; - -enum EtsErrorCode : int32_t { - OTHER_ERROR = -1, - COMMON_PERMISSION_CHECK_ERROR = 201, - COMMON_PARAMETER_ERROR = 401, - COMMON_USE_SYSAPI_ERROR = 202, - INPUT_DEVICE_NOT_SUPPORTED = 801, - INPUT_OCCUPIED_BY_SYSTEM = 4200002, - INPUT_OCCUPIED_BY_OTHER = 4200003, - PRE_KEY_NOT_SUPPORTED = 4100001, - COMMON_DEVICE_NOT_EXIST = 3900001, - COMMON_KEYBOARD_DEVICE_NOT_EXIST = 3900002, - COMMON_NON_INPUT_APPLICATION = 3900003, - ERROR_WINDOW_ID_PERMISSION_DENIED = 26500001, -}; #endif // OHOS_MULTIMODALINPUT_POINTER_IMPL_H diff --git a/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp b/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp index 404e6fdcac..cd3ba4f623 100644 --- a/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp +++ b/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp @@ -15,72 +15,84 @@ #include "ohos.multimodalInput.pointer.impl.h" +#include "ani_common.h" +#include "input_manager.h" +#include "struct_multimodal.h" + #undef MMI_LOG_TAG #define MMI_LOG_TAG "ohos.multimodalInput.pointer" using namespace taihe; +using namespace OHOS::MMI; using namespace ohos::multimodalInput::pointer; +using TaihePointerStyle = ohos::multimodalInput::pointer::PointerStyle; namespace { -const static std::map POINTER_STYLE_TRANSFORMATION = { - { DEFAULT_IMPL, PointerStyle::key_t::DEFAULT }, - { EAST_IMPL, PointerStyle::key_t::EAST }, - { WEST_IMPL, PointerStyle::key_t::WEST }, - { SOUTH_IMPL, PointerStyle::key_t::SOUTH }, - { NORTH_IMPL, PointerStyle::key_t::NORTH }, - { WEST_EAST_IMPL, PointerStyle::key_t::WEST_EAST }, - { NORTH_SOUTH_IMPL, PointerStyle::key_t::NORTH_SOUTH }, - { NORTH_EAST_IMPL, PointerStyle::key_t::NORTH_EAST }, - { SOUTH_EAST_IMPL, PointerStyle::key_t::SOUTH_EAST }, - { SOUTH_WEST_IMPL, PointerStyle::key_t::SOUTH_WEST }, - { NORTH_EAST_SOUTH_WEST_IMPL, PointerStyle::key_t::NORTH_EAST_SOUTH_WEST }, - { NORTH_WEST_SOUTH_EAST_IMPL, PointerStyle::key_t::NORTH_WEST_SOUTH_EAST }, - { CROSS_IMPL, PointerStyle::key_t::CROSS }, - { CURSOR_COPY_IMPL, PointerStyle::key_t::CURSOR_COPY }, - { CURSOR_FORBID_IMPL, PointerStyle::key_t::CURSOR_FORBID }, - { COLOR_SUCKER_IMPL, PointerStyle::key_t::COLOR_SUCKER }, - { HAND_GRABBING_IMPL, PointerStyle::key_t::HAND_GRABBING }, - { HAND_OPEN_IMPL, PointerStyle::key_t::HAND_OPEN }, - { HAND_POINTING_IMPL, PointerStyle::key_t::HAND_POINTING }, - { HELP_IMPL, PointerStyle::key_t::HELP }, - { MOVE_IMPL, PointerStyle::key_t::MOVE }, - { RESIZE_LEFT_RIGHT_IMPL, PointerStyle::key_t::RESIZE_LEFT_RIGHT }, - { RESIZE_UP_DOWN_IMPL, PointerStyle::key_t::RESIZE_UP_DOWN }, - { SCREENSHOT_CHOOSE_IMPL, PointerStyle::key_t::SCREENSHOT_CHOOSE }, - { SCREENSHOT_CURSOR_IMPL, PointerStyle::key_t::SCREENSHOT_CURSOR }, - { TEXT_CURSOR_IMPL, PointerStyle::key_t::TEXT_CURSOR }, - { ZOOM_IN_IMPL, PointerStyle::key_t::ZOOM_IN }, - { ZOOM_OUT_IMPL, PointerStyle::key_t::ZOOM_OUT }, - { MOVE_IMPL, PointerStyle::key_t::MOVE }, - { MIDDLE_BTN_EAST_IMPL, PointerStyle::key_t::MIDDLE_BTN_EAST }, - { MIDDLE_BTN_WEST_IMPL, PointerStyle::key_t::MIDDLE_BTN_WEST }, - { MIDDLE_BTN_SOUTH_IMPL, PointerStyle::key_t::MIDDLE_BTN_SOUTH }, - { MIDDLE_BTN_NORTH_IMPL, PointerStyle::key_t::MIDDLE_BTN_NORTH }, - { MIDDLE_BTN_NORTH_SOUTH_IMPL, PointerStyle::key_t::MIDDLE_BTN_NORTH_SOUTH }, - { MIDDLE_BTN_NORTH_EAST_IMPL, PointerStyle::key_t::MIDDLE_BTN_NORTH_EAST }, - { MIDDLE_BTN_NORTH_WEST_IMPL, PointerStyle::key_t::MIDDLE_BTN_NORTH_WEST }, - { MIDDLE_BTN_SOUTH_EAST_IMPL, PointerStyle::key_t::MIDDLE_BTN_SOUTH_EAST }, - { MIDDLE_BTN_SOUTH_WEST_IMPL, PointerStyle::key_t::MIDDLE_BTN_SOUTH_WEST }, - { MIDDLE_BTN_NORTH_SOUTH_WEST_EAST_IMPL, PointerStyle::key_t::MIDDLE_BTN_NORTH_SOUTH_WEST_EAST }, - { HORIZONTAL_TEXT_CURSOR_IMPL, PointerStyle::key_t::HORIZONTAL_TEXT_CURSOR }, - { CURSOR_CROSS_IMPL, PointerStyle::key_t::CURSOR_CROSS }, - { CURSOR_CIRCLE_IMPL, PointerStyle::key_t::CURSOR_CIRCLE }, - { LOADING_IMPL, PointerStyle::key_t::LOADING }, - { RUNNING_IMPL, PointerStyle::key_t::RUNNING }, - { MIDDLE_BTN_EAST_WEST_IMPL, PointerStyle::key_t::MIDDLE_BTN_EAST_WEST }, +constexpr int32_t MAX_SPEED { 20 }; +constexpr int32_t MIN_SPEED { 1 }; +constexpr int32_t MIN_POINTER_SIZE { 1 }; +constexpr int32_t MAX_POINTER_SIZE { 7 }; +constexpr int32_t MIN_ROWS { 1 }; +constexpr int32_t MAX_ROWS { 100 }; +const static std::map POINTER_STYLE_TRANSFORMATION = { + { DEFAULT_IMPL, TaihePointerStyle::key_t::DEFAULT }, + { EAST_IMPL, TaihePointerStyle::key_t::EAST }, + { WEST_IMPL, TaihePointerStyle::key_t::WEST }, + { SOUTH_IMPL, TaihePointerStyle::key_t::SOUTH }, + { NORTH_IMPL, TaihePointerStyle::key_t::NORTH }, + { WEST_EAST_IMPL, TaihePointerStyle::key_t::WEST_EAST }, + { NORTH_SOUTH_IMPL, TaihePointerStyle::key_t::NORTH_SOUTH }, + { NORTH_EAST_IMPL, TaihePointerStyle::key_t::NORTH_EAST }, + { SOUTH_EAST_IMPL, TaihePointerStyle::key_t::SOUTH_EAST }, + { SOUTH_WEST_IMPL, TaihePointerStyle::key_t::SOUTH_WEST }, + { NORTH_EAST_SOUTH_WEST_IMPL, TaihePointerStyle::key_t::NORTH_EAST_SOUTH_WEST }, + { NORTH_WEST_SOUTH_EAST_IMPL, TaihePointerStyle::key_t::NORTH_WEST_SOUTH_EAST }, + { CROSS_IMPL, TaihePointerStyle::key_t::CROSS }, + { CURSOR_COPY_IMPL, TaihePointerStyle::key_t::CURSOR_COPY }, + { CURSOR_FORBID_IMPL, TaihePointerStyle::key_t::CURSOR_FORBID }, + { COLOR_SUCKER_IMPL, TaihePointerStyle::key_t::COLOR_SUCKER }, + { HAND_GRABBING_IMPL, TaihePointerStyle::key_t::HAND_GRABBING }, + { HAND_OPEN_IMPL, TaihePointerStyle::key_t::HAND_OPEN }, + { HAND_POINTING_IMPL, TaihePointerStyle::key_t::HAND_POINTING }, + { HELP_IMPL, TaihePointerStyle::key_t::HELP }, + { MOVE_IMPL, TaihePointerStyle::key_t::MOVE }, + { RESIZE_LEFT_RIGHT_IMPL, TaihePointerStyle::key_t::RESIZE_LEFT_RIGHT }, + { RESIZE_UP_DOWN_IMPL, TaihePointerStyle::key_t::RESIZE_UP_DOWN }, + { SCREENSHOT_CHOOSE_IMPL, TaihePointerStyle::key_t::SCREENSHOT_CHOOSE }, + { SCREENSHOT_CURSOR_IMPL, TaihePointerStyle::key_t::SCREENSHOT_CURSOR }, + { TEXT_CURSOR_IMPL, TaihePointerStyle::key_t::TEXT_CURSOR }, + { ZOOM_IN_IMPL, TaihePointerStyle::key_t::ZOOM_IN }, + { ZOOM_OUT_IMPL, TaihePointerStyle::key_t::ZOOM_OUT }, + { MOVE_IMPL, TaihePointerStyle::key_t::MOVE }, + { MIDDLE_BTN_EAST_IMPL, TaihePointerStyle::key_t::MIDDLE_BTN_EAST }, + { MIDDLE_BTN_WEST_IMPL, TaihePointerStyle::key_t::MIDDLE_BTN_WEST }, + { MIDDLE_BTN_SOUTH_IMPL, TaihePointerStyle::key_t::MIDDLE_BTN_SOUTH }, + { MIDDLE_BTN_NORTH_IMPL, TaihePointerStyle::key_t::MIDDLE_BTN_NORTH }, + { MIDDLE_BTN_NORTH_SOUTH_IMPL, TaihePointerStyle::key_t::MIDDLE_BTN_NORTH_SOUTH }, + { MIDDLE_BTN_NORTH_EAST_IMPL, TaihePointerStyle::key_t::MIDDLE_BTN_NORTH_EAST }, + { MIDDLE_BTN_NORTH_WEST_IMPL, TaihePointerStyle::key_t::MIDDLE_BTN_NORTH_WEST }, + { MIDDLE_BTN_SOUTH_EAST_IMPL, TaihePointerStyle::key_t::MIDDLE_BTN_SOUTH_EAST }, + { MIDDLE_BTN_SOUTH_WEST_IMPL, TaihePointerStyle::key_t::MIDDLE_BTN_SOUTH_WEST }, + { MIDDLE_BTN_NORTH_SOUTH_WEST_EAST_IMPL, TaihePointerStyle::key_t::MIDDLE_BTN_NORTH_SOUTH_WEST_EAST }, + { HORIZONTAL_TEXT_CURSOR_IMPL, TaihePointerStyle::key_t::HORIZONTAL_TEXT_CURSOR }, + { CURSOR_CROSS_IMPL, TaihePointerStyle::key_t::CURSOR_CROSS }, + { CURSOR_CIRCLE_IMPL, TaihePointerStyle::key_t::CURSOR_CIRCLE }, + { LOADING_IMPL, TaihePointerStyle::key_t::LOADING }, + { RUNNING_IMPL, TaihePointerStyle::key_t::RUNNING }, + { MIDDLE_BTN_EAST_WEST_IMPL, TaihePointerStyle::key_t::MIDDLE_BTN_EAST_WEST }, }; -PointerStyle ConvertPointerStyle(int32_t pointerStyle) +TaihePointerStyle ConvertPointerStyle(int32_t pointerStyle) { auto iter = POINTER_STYLE_TRANSFORMATION.find(pointerStyle); if (iter == POINTER_STYLE_TRANSFORMATION.end()) { MMI_HILOGE("Find failed, pointerStyle:%{public}d", pointerStyle); - return PointerStyle::key_t::DEFAULT; + return TaihePointerStyle::key_t::DEFAULT; } return iter->second; } -void SetPointerStyleAsync(int32_t windowId, PointerStyle pointerStyle) +void SetPointerStyleAsync(int32_t windowId, TaihePointerStyle pointerStyle) { OHOS::MMI::PointerStyle style; style.id = pointerStyle; @@ -100,24 +112,24 @@ void SetPointerVisibleSync(bool visible) } } -PointerStyle GetPointerStyleSync(int32_t windowId) +TaihePointerStyle GetPointerStyleSync(int32_t windowId) { OHOS::MMI::PointerStyle pointerStyle; if (windowId < 0 && windowId != OHOS::MMI::GLOBAL_WINDOW_ID) { MMI_HILOGE("Invalid windowId"); taihe::set_business_error(COMMON_PARAMETER_ERROR, "windowId is invalid"); - return PointerStyle::key_t::DEFAULT; + return TaihePointerStyle::key_t::DEFAULT; } int32_t ret = OHOS::MMI::InputManager::GetInstance()->GetPointerStyle(windowId, pointerStyle); if (ret == COMMON_PARAMETER_ERROR) { taihe::set_business_error(ret, "failed to get default GetPointerStyle!"); MMI_HILOGE("failed to get default GetPointerStyle!"); - return PointerStyle::key_t::DEFAULT; + return TaihePointerStyle::key_t::DEFAULT; } return ConvertPointerStyle(pointerStyle.id); } -void SetPointerStyleSync(int32_t windowId, PointerStyle pointerStyle) +void SetPointerStyleSync(int32_t windowId, TaihePointerStyle pointerStyle) { OHOS::MMI::PointerStyle style; style.id = pointerStyle; @@ -144,7 +156,7 @@ bool IsPointerVisibleAsync() { TH_THROW(std::runtime_error, "IsPointerVisibleAsync not implemented"); } -::ohos::multimodalInput::pointer::PointerStyle GetPointerStyleAsync(int32_t windowId) { +TaihePointerStyle GetPointerStyleAsync(int32_t windowId) { TH_THROW(std::runtime_error, "GetPointerStyleAsync not implemented"); } @@ -168,128 +180,372 @@ void SetCustomCursorAsync(int32_t windowId, ::ohos::multimodalInput::pointer::Cu TH_THROW(std::runtime_error, "SetCustomCursorAsync not implemented"); } -int32_t GetPointerSpeedSync() { - TH_THROW(std::runtime_error, "GetPointerSpeedSync not implemented"); +int32_t GetPointerSpeedSync() +{ + CALL_DEBUG_ENTER; + int32_t pointerSpeed = 0; + InputManager::GetInstance()->GetPointerSpeed(pointerSpeed); + return pointerSpeed; } -::ohos::multimodalInput::pointer::RightClickType GetTouchpadRightClickTypeAsync() { - TH_THROW(std::runtime_error, "GetTouchpadRightClickTypeAsync not implemented"); +::ohos::multimodalInput::pointer::RightClickType GetTouchpadRightClickTypeAsync() +{ + CALL_DEBUG_ENTER; + int32_t type = 1; + auto errorCode = InputManager::GetInstance()->GetTouchpadRightClickType(type); + ohos::multimodalInput::pointer::RightClickType clickType = + static_cast(type); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } + return clickType; } -void SetTouchpadRightClickTypeAsync(::ohos::multimodalInput::pointer::RightClickType type) { - TH_THROW(std::runtime_error, "SetTouchpadRightClickTypeAsync not implemented"); +void SetTouchpadRightClickTypeAsync(::ohos::multimodalInput::pointer::RightClickType type) +{ + CALL_DEBUG_ENTER; + int32_t clickType = static_cast(type); + auto errorCode = InputManager::GetInstance()->SetTouchpadRightClickType(clickType); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } } -bool GetTouchpadSwipeSwitchAsync() { - TH_THROW(std::runtime_error, "GetTouchpadSwipeSwitchAsync not implemented"); +bool GetTouchpadSwipeSwitchAsync() +{ + CALL_DEBUG_ENTER; + bool switchFlag = true; + auto errorCode = InputManager::GetInstance()->GetTouchpadSwipeSwitch(switchFlag); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } + return switchFlag; } -void SetTouchpadSwipeSwitchAsync(bool state) { - TH_THROW(std::runtime_error, "SetTouchpadSwipeSwitchAsync not implemented"); +void SetTouchpadSwipeSwitchAsync(bool state) +{ + CALL_DEBUG_ENTER; + auto errorCode = InputManager::GetInstance()->SetTouchpadSwipeSwitch(state); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } } -bool GetTouchpadPinchSwitchAsync() { - TH_THROW(std::runtime_error, "GetTouchpadPinchSwitchAsync not implemented"); +bool GetTouchpadPinchSwitchAsync() +{ + CALL_DEBUG_ENTER; + bool switchFlag = true; + auto errorCode = InputManager::GetInstance()->GetTouchpadPinchSwitch(switchFlag); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } + return switchFlag; } -void SetTouchpadPinchSwitchAsync(bool state) { - TH_THROW(std::runtime_error, "SetTouchpadPinchSwitchAsync not implemented"); +void SetTouchpadPinchSwitchAsync(bool state) +{ + CALL_DEBUG_ENTER; + auto errorCode = InputManager::GetInstance()->SetTouchpadPinchSwitch(state); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } } -bool GetTouchpadPointerSpeedAsync() { - TH_THROW(std::runtime_error, "GetTouchpadPointerSpeedAsync not implemented"); +int32_t GetTouchpadPointerSpeedAsync() +{ + CALL_DEBUG_ENTER; + int32_t speed = 0; + auto errorCode = InputManager::GetInstance()->GetTouchpadPointerSpeed(speed); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } + return speed; } -void SetTouchpadPointerSpeedAsync(bool speed) { - TH_THROW(std::runtime_error, "SetTouchpadPointerSpeedAsync not implemented"); +void SetTouchpadPointerSpeedAsync(bool speed) +{ + CALL_DEBUG_ENTER; + auto errorCode = InputManager::GetInstance()->SetTouchpadPointerSpeed(speed); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } } -bool GetTouchpadTapSwitchAsync() { - TH_THROW(std::runtime_error, "GetTouchpadTapSwitchAsync not implemented"); +bool GetTouchpadTapSwitchAsync() +{ + CALL_DEBUG_ENTER; + bool switchFlag = true; + auto errorCode = InputManager::GetInstance()->GetTouchpadTapSwitch(switchFlag); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } + return switchFlag; } -void SetTouchpadTapSwitchAsync(bool state) { - TH_THROW(std::runtime_error, "SetTouchpadTapSwitchAsync not implemented"); +void SetTouchpadTapSwitchAsync(bool state) +{ + CALL_DEBUG_ENTER; + auto errorCode = InputManager::GetInstance()->SetTouchpadTapSwitch(state); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } } -bool GetTouchpadScrollDirectionAsync() { - TH_THROW(std::runtime_error, "GetTouchpadScrollDirectionAsync not implemented"); +bool GetTouchpadScrollDirectionAsync() +{ + CALL_DEBUG_ENTER; + bool state = true; + auto errorCode = InputManager::GetInstance()->GetTouchpadScrollDirection(state); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } + return state; } -void SetTouchpadScrollDirectionAsync(bool state) { - TH_THROW(std::runtime_error, "SetTouchpadScrollDirectionAsync not implemented"); +void SetTouchpadScrollDirectionAsync(bool state) +{ + CALL_DEBUG_ENTER; + auto errorCode = InputManager::GetInstance()->SetTouchpadScrollDirection(state); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } } -bool GetTouchpadScrollSwitchAsync() { - TH_THROW(std::runtime_error, "GetTouchpadScrollSwitchAsync not implemented"); +bool GetTouchpadScrollSwitchAsync() +{ + CALL_DEBUG_ENTER; + bool switchFlag = true; + auto errorCode = InputManager::GetInstance()->GetTouchpadScrollSwitch(switchFlag); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } + return switchFlag; } -void SetTouchpadScrollSwitchAsync(bool state) { - TH_THROW(std::runtime_error, "SetTouchpadScrollSwitchAsync not implemented"); +void SetTouchpadScrollSwitchAsync(bool state) +{ + CALL_DEBUG_ENTER; + auto errorCode = InputManager::GetInstance()->SetTouchpadScrollSwitch(state); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } } -int32_t GetMouseScrollRowsAsync() { - TH_THROW(std::runtime_error, "GetMouseScrollRowsAsync not implemented"); +int32_t GetMouseScrollRowsAsync() +{ + CALL_DEBUG_ENTER; + int32_t rows = 3; + auto errorCode = InputManager::GetInstance()->GetMouseScrollRows(rows); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } + return rows; } -void SetMouseScrollRowsAsync(int32_t rows) { - TH_THROW(std::runtime_error, "SetMouseScrollRowsAsync not implemented"); +void SetMouseScrollRowsAsync(int32_t rows) +{ + CALL_DEBUG_ENTER; + if (rows < MIN_ROWS) { + rows = MIN_ROWS; + } else if (rows > MAX_ROWS) { + rows = MAX_ROWS; + } + auto errorCode = InputManager::GetInstance()->SetMouseScrollRows(rows); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } } -bool GetHoverScrollStateAsync() { - TH_THROW(std::runtime_error, "GetHoverScrollStateAsync not implemented"); +bool GetHoverScrollStateAsync() +{ + CALL_DEBUG_ENTER; + bool state = false; + auto errorCode = InputManager::GetInstance()->GetHoverScrollState(state); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } + return state; } -void SetHoverScrollStateAsync(bool state) { - TH_THROW(std::runtime_error, "SetHoverScrollStateAsync not implemented"); +void SetHoverScrollStateAsync(bool state) +{ + CALL_DEBUG_ENTER; + auto errorCode = InputManager::GetInstance()->SetHoverScrollState(state); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } } -::ohos::multimodalInput::pointer::PrimaryButton GetMousePrimaryButtonAsync() { - TH_THROW(std::runtime_error, "GetMousePrimaryButtonAsync not implemented"); +::ohos::multimodalInput::pointer::PrimaryButton GetMousePrimaryButtonAsync() +{ + CALL_DEBUG_ENTER; + int32_t primaryButton = 0; + auto errorCode = InputManager::GetInstance()->GetMousePrimaryButton(primaryButton); + ohos::multimodalInput::pointer::PrimaryButton button = + static_cast(primaryButton); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } + return button; } -void SetMousePrimaryButtonAsync(::ohos::multimodalInput::pointer::PrimaryButton primary) { - TH_THROW(std::runtime_error, "SetMousePrimaryButtonAsync not implemented"); +void SetMousePrimaryButtonAsync(::ohos::multimodalInput::pointer::PrimaryButton primary) +{ + CALL_DEBUG_ENTER; + int32_t primaryButton = static_cast(primary); + if (primaryButton < LEFT_BUTTON || primaryButton > RIGHT_BUTTON) { + MMI_HILOGE("Undefined mouse primary button"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "Mouse primary button does not exist"); + return; + } + auto errorCode = InputManager::GetInstance()->SetMousePrimaryButton(primaryButton); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } } -int32_t GetPointerSizeAsync() { - TH_THROW(std::runtime_error, "GetPointerSizeAsync not implemented"); +int32_t GetPointerSizeAsync() +{ + CALL_DEBUG_ENTER; + int32_t size = 1; + auto errorCode = InputManager::GetInstance()->GetPointerSize(size); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } + return size; } -void SetPointerSizeSync(int32_t size) { - TH_THROW(std::runtime_error, "SetPointerSizeSync not implemented"); +void SetPointerSizeSync(int32_t size) +{ + CALL_DEBUG_ENTER; + if (size < MIN_POINTER_SIZE) { + size = MIN_POINTER_SIZE; + } else if (size > MAX_POINTER_SIZE) { + size = MAX_POINTER_SIZE; + } + auto errorCode = InputManager::GetInstance()->SetPointerSize(size); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } } -void SetPointerSizeAsync(int32_t size) { - TH_THROW(std::runtime_error, "SetPointerSizeAsync not implemented"); +void SetPointerSizeAsync(int32_t size) +{ + CALL_DEBUG_ENTER; + if (size < MIN_POINTER_SIZE) { + size = MIN_POINTER_SIZE; + } else if (size > MAX_POINTER_SIZE) { + size = MAX_POINTER_SIZE; + } + auto errorCode = InputManager::GetInstance()->SetPointerSize(size); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } } -int32_t GetPointerColorAsync() { - TH_THROW(std::runtime_error, "GetPointerColorAsync not implemented"); +int32_t GetPointerColorAsync() +{ + CALL_DEBUG_ENTER; + int32_t color = 1; + auto errorCode = InputManager::GetInstance()->GetPointerColor(color); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } + return color; } -void SetPointerColorSync(int32_t color) { - TH_THROW(std::runtime_error, "SetPointerColorSync not implemented"); +void SetPointerColorSync(int32_t color) +{ + CALL_DEBUG_ENTER; + auto errorCode = InputManager::GetInstance()->SetPointerColor(color); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } } -void SetPointerColorAsync(int32_t color) { - TH_THROW(std::runtime_error, "SetPointerColorAsync not implemented"); +void SetPointerColorAsync(int32_t color) +{ + CALL_DEBUG_ENTER; + auto errorCode = InputManager::GetInstance()->SetPointerColor(color); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } } -void SetPointerSpeedSync(int32_t speed) { - TH_THROW(std::runtime_error, "SetPointerSpeedSync not implemented"); +void SetPointerSpeedSync(int32_t speed) +{ + CALL_DEBUG_ENTER; + if (speed < MIN_SPEED) { + speed = MIN_SPEED; + } else if (speed > MAX_SPEED) { + speed = MAX_SPEED; + } + auto errorCode = InputManager::GetInstance()->SetPointerSpeed(speed); + if (errorCode != RET_OK) { + MMI_HILOGE("Non system applications use system API"); + TaiheError codeMsg; + if (!TaiheConverter::GetApiError(errorCode, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", errorCode); + } + taihe::set_business_error(errorCode, codeMsg.msg); + } } -bool IsPointerVisibleSync() { - TH_THROW(std::runtime_error, "IsPointerVisibleSync not implemented"); +bool IsPointerVisibleSync() +{ + CALL_DEBUG_ENTER; + bool visible = InputManager::GetInstance()->IsPointerVisible(); + return visible; } -int32_t GetPointerColorSync() { - TH_THROW(std::runtime_error, "GetPointerColorSync not implemented"); +int32_t GetPointerColorSync() +{ + CALL_DEBUG_ENTER; + int32_t color = 1; + auto errorCode = InputManager::GetInstance()->GetPointerColor(color); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } + return color; } -int32_t GetPointerSizeSync() { - TH_THROW(std::runtime_error, "GetPointerSizeSync not implemented"); +int32_t GetPointerSizeSync() +{ + CALL_DEBUG_ENTER; + int32_t size = 1; + auto errorCode = InputManager::GetInstance()->GetPointerSize(size); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } + return size; } } // namespace -- Gitee From c8545af5bc73028f492209d883a9edd7248043fb Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Mon, 28 Jul 2025 17:13:51 +0800 Subject: [PATCH 13/29] =?UTF-8?q?lmq=20pointer=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- .../src/ohos.multimodalInput.pointer.impl.cpp | 99 ++++++++++++++++--- 1 file changed, 83 insertions(+), 16 deletions(-) diff --git a/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp b/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp index cd3ba4f623..7c53ba6e70 100644 --- a/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp +++ b/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp @@ -140,36 +140,103 @@ void SetPointerStyleSync(int32_t windowId, TaihePointerStyle pointerStyle) } } -void SetPointerVisibleAsync(bool visible) { - TH_THROW(std::runtime_error, "SetPointerVisibleAsync not implemented"); +void SetPointerVisibleAsync(bool visible) +{ + CALL_DEBUG_ENTER; + auto errorCode = InputManager::GetInstance()->SetPointerVisible(visible); + if (errorCode == COMMON_PARAMETER_ERROR) { + MMI_HILOGE("failed to SetPointerVisible!"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "failed to SetPointerVisible!"); + } } -void SetPointerSpeedAsync(int32_t speed) { - TH_THROW(std::runtime_error, "SetPointerSpeedAsync not implemented"); +void SetPointerSpeedAsync(int32_t speed) +{ + CALL_DEBUG_ENTER; + if (speed < MIN_SPEED) { + speed = MIN_SPEED; + } else if (speed > MAX_SPEED) { + speed = MAX_SPEED; + } + auto errorCode = InputManager::GetInstance()->SetPointerSpeed(speed); + if (errorCode == COMMON_PARAMETER_ERROR) { + MMI_HILOGE("failed to SetPointerSpeed!"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "failed to SetPointerSpeed!"); + } } -int32_t GetPointerSpeedAsync() { - TH_THROW(std::runtime_error, "GetPointerSpeedAsync not implemented"); +int32_t GetPointerSpeedAsync() +{ + CALL_DEBUG_ENTER; + int32_t pointerSpeed = 0; + auto errorCode = InputManager::GetInstance()->GetPointerSpeed(pointerSpeed); + if (errorCode == COMMON_PARAMETER_ERROR) { + MMI_HILOGE("failed to GetPointerSpeed!"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "failed to GetPointerSpeed!"); + } + return pointerSpeed; } -bool IsPointerVisibleAsync() { - TH_THROW(std::runtime_error, "IsPointerVisibleAsync not implemented"); +bool IsPointerVisibleAsync() +{ + CALL_DEBUG_ENTER; + bool visible = InputManager::GetInstance()->IsPointerVisible(); + return visible; } -TaihePointerStyle GetPointerStyleAsync(int32_t windowId) { - TH_THROW(std::runtime_error, "GetPointerStyleAsync not implemented"); +TaihePointerStyle GetPointerStyleAsync(int32_t windowId) +{ + CALL_DEBUG_ENTER; + if (windowId < 0 && windowId != OHOS::MMI::GLOBAL_WINDOW_ID) { + MMI_HILOGE("Invalid windowid"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "Windowid is invalid"); + return TaihePointerStyle::key_t::DEFAULT; + } + OHOS::MMI::PointerStyle pointerStyle; + auto errorCode = InputManager::GetInstance()->GetPointerStyle(windowId, pointerStyle); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("WindowId is negative number and no system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, + "WindowId is negative number and no system applications use system API"); + return TaihePointerStyle::key_t::DEFAULT; + } + return ConvertPointerStyle(pointerStyle.id); } -bool GetTouchpadDoubleTapAndDragStateAsync() { - TH_THROW(std::runtime_error, "GetTouchpadDoubleTapAndDragStateAsync not implemented"); +bool GetTouchpadDoubleTapAndDragStateAsync() +{ + CALL_DEBUG_ENTER; + bool switchFlag = true; + auto errorCode = InputManager::GetInstance()->GetTouchpadDoubleTapAndDragState(switchFlag); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } + return switchFlag; } -void SetTouchpadDoubleTapAndDragStateAsync(bool isOpen) { - TH_THROW(std::runtime_error, "SetTouchpadDoubleTapAndDragStateAsync not implemented"); +void SetTouchpadDoubleTapAndDragStateAsync(bool isOpen) +{ + CALL_DEBUG_ENTER; + auto errorCode = InputManager::GetInstance()->SetTouchpadDoubleTapAndDragState(isOpen); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("Non system applications use system API"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } } -void SetCustomCursorSync(int32_t windowId, uintptr_t pixelMap, ::taihe::optional_view focusX, ::taihe::optional_view focusY) { - TH_THROW(std::runtime_error, "SetCustomCursorSync not implemented"); +void SetCustomCursorSync(int32_t windowId, uintptr_t pixelMap, ::taihe::optional_view focusX, ::taihe::optional_view focusY) +{ + CALL_DEBUG_ENTER; + if (windowId < 0) { + MMI_HILOGE("Invalid windowsId"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "windowId is invalid"); + return; + } + // ani_ref bufferRef; + // ani_env *env = get_env(); + // ani_object object = reinterpret_cast(pixelMap); + // ȡpixelMapϢ } void SetCustomCursorPixelMapAsync(int32_t windowId, uintptr_t pixelMap, ::taihe::optional_view focusX, ::taihe::optional_view focusY) { -- Gitee From 782e13c8e3edf11cd4e0893fedd417143eee57fd Mon Sep 17 00:00:00 2001 From: KangPeng Date: Tue, 29 Jul 2025 11:36:20 +0800 Subject: [PATCH 14/29] =?UTF-8?q?ztw=20Monitor=20=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: KangPeng --- frameworks/ets/common/include/ani_common.h | 124 +++-- frameworks/ets/common/src/ani_common.cpp | 355 +++++++++++++- .../ohos.multimodalInput.inputDevice.taihe | 2 - frameworks/ets/input_monitor/BUILD.gn | 2 + .../include/ani_input_monitor_consumer.h | 118 +++++ .../include/ani_input_monitor_manager.h | 18 +- .../src/ani_input_monitor_consumer.cpp | 434 ++++++++++++++++++ .../src/ani_input_monitor_manager.cpp | 25 +- ...ohos.multimodalInput.inputMonitor.impl.cpp | 6 + .../idl/ohos.multimodalInput.touchEvent.taihe | 1 + .../input_monitor/include/js_input_monitor.h | 6 +- 11 files changed, 1036 insertions(+), 55 deletions(-) create mode 100644 frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h create mode 100644 frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp diff --git a/frameworks/ets/common/include/ani_common.h b/frameworks/ets/common/include/ani_common.h index e9f441a18b..b4e025c324 100644 --- a/frameworks/ets/common/include/ani_common.h +++ b/frameworks/ets/common/include/ani_common.h @@ -27,8 +27,12 @@ #include "ohos.multimodalInput.mouseEvent.proj.hpp" #include "ohos.multimodalInput.gestureEvent.proj.hpp" #include "ohos.multimodalInput.touchEvent.proj.hpp" +#include "ohos.multimodalInput.shortKey.proj.hpp" +#include "ohos.multimodalInput.keyEvent.proj.hpp" #include "taihe/runtime.hpp" +#include "taihe/callback.hpp" +#include "key_event.h" #include "pointer_event.h" #include "input_device.h" @@ -51,7 +55,6 @@ using TaiheAType = ohos::multimodalInput::inputDevice::AxisType; using TaiheAxisRange = ohos::multimodalInput::inputDevice::AxisRange; using TaiheInputDeviceData = ohos::multimodalInput::inputDevice::InputDeviceData; using TaiheMouseEvent = ohos::multimodalInput::mouseEvent::MouseEvent; -using TaihePinchEvent = ohos::multimodalInput::gestureEvent::Pinch; using TaiheTouchEvent = ohos::multimodalInput::touchEvent::TouchEvent; using TaiheTouchEventArray = taihe::array; using TaiheTouch = ohos::multimodalInput::touchEvent::Touch; @@ -60,11 +63,24 @@ using TaiheInputEvent = ohos::multimodalInput::inputEvent::InputEvent; using TaiheSourceType = ohos::multimodalInput::touchEvent::SourceType; using TaiheFixedMode = ohos::multimodalInput::touchEvent::FixedMode; using TaiheToolType = ohos::multimodalInput::touchEvent::ToolType; -/* -using callbackType = std::variant, - taihe::callback, - taihe::callback, taihe::callback>; -*/ + +using TaiheRotate = ohos::multimodalInput::gestureEvent::Rotate; +using TaiheTouchGestureAction = ohos::multimodalInput::gestureEvent::TouchGestureAction; +using TaiheGestureActionType = ohos::multimodalInput::gestureEvent::ActionType; +using TaiheSwipeInward = ohos::multimodalInput::gestureEvent::SwipeInward; +using TaiheThreeFingersSwipe = ohos::multimodalInput::gestureEvent::ThreeFingersSwipe; +using TaihePinchEvent = ohos::multimodalInput::gestureEvent::Pinch; +using TaiheFourFingersSwipe = ohos::multimodalInput::gestureEvent::FourFingersSwipe; +using TaiheThreeFingersTap = ohos::multimodalInput::gestureEvent::ThreeFingersTap; +using TaiheTouchGestureEvent = ohos::multimodalInput::gestureEvent::TouchGestureEvent; + +using TaiheFingerprintAction = ohos::multimodalInput::shortKey::FingerprintAction; +using TaiheFingerprintEvent = ohos::multimodalInput::shortKey::FingerprintEvent; + +using TaiheKeyEventAction = ohos::multimodalInput::keyEvent::Action; +using TaiheKeyEvent = ohos::multimodalInput::keyEvent::KeyEvent; +using TaiheKeyEventKey = ohos::multimodalInput::keyEvent::Key; + struct TaiheError { int32_t errorCode; @@ -808,25 +824,8 @@ struct DeviceType { uint32_t typeBit { 0 }; }; -DeviceType g_deviceType[] = { - { "keyboard", EVDEV_TAG_KEYBOARD }, - { "mouse", EVDEV_TAG_MOUSE }, - { "touchpad", EVDEV_TAG_TOUCHPAD }, - { "touchscreen", EVDEV_TAG_TOUCHSCREEN }, - { "joystick", EVDEV_TAG_JOYSTICK }, - { "trackball", EVDEV_TAG_TRACKBALL }, -}; - -std::unordered_map g_axisType = { - { ABS_MT_TOUCH_MAJOR, "touchmajor" }, - { ABS_MT_TOUCH_MINOR, "touchminor" }, - { ABS_MT_ORIENTATION, "orientation" }, - { ABS_MT_POSITION_X, "x" }, - { ABS_MT_POSITION_Y, "y" }, - { ABS_MT_PRESSURE, "pressure" }, - { ABS_MT_WIDTH_MAJOR, "toolmajor" }, - { ABS_MT_WIDTH_MINOR, "toolminor" }, -}; +extern DeviceType g_taiheDeviceType[]; +extern std::unordered_map g_taiheAxisType; class TaiheConverter { public: @@ -840,15 +839,51 @@ public: static TaiheAxisRange ConverterAxisRange(const InputDevice::AxisInfo &axisInfo, const std::string &sourceType, const std::string &axisType); static TaiheInputDeviceData ConverterInputDevice(std::shared_ptr &device); - + // ztw touchEvent 解析 static TaiheTouchEvent TouchEventToTaihe(const PointerEvent &pointerEvent); static TaiheInputEvent InputEventToTaihe(const InputEvent &inputEvent); static TaiheTouchAction TouchActionToTaihe(int32_t action); static TaiheSourceType SourceTypeToTaihe(int32_t sourceType); static TaiheFixedMode FixedModeToTaihe(PointerEvent::FixedMode fixedMode); static TaiheTouch TouchToTaihe(const PointerEvent::PointerItem &item); + + // ztw gestureEvent + static TaiheTouchGestureAction TouchGestureActionToTaihe(int32_t action); + static TaiheGestureActionType RotateActionToTaihe(int32_t action); + static TaiheGestureActionType PinchActionToTaihe(int32_t action); + static TaiheGestureActionType SwipeInwardActionToTaihe(int32_t action); + static TaiheGestureActionType SwipeActionToTaihe(int32_t action); + static TaiheGestureActionType MultiTapActionToTaihe(int32_t action); + + static TaiheRotate RotateToTaihe(const PointerEvent &pointerEvent); + static TaihePinchEvent PinchToTaihe(const PointerEvent &pointerEvent); + static TaiheSwipeInward SwipeInwardToTaihe(const PointerEvent &pointerEvent); + static TaiheThreeFingersSwipe ThreeFingersSwipeToTaihe(const PointerEvent &pointerEvent); + static TaiheFourFingersSwipe FourFingersSwipeToTaihe(const PointerEvent &pointerEvent); + // ztw touchscreenSwipe, touchscreenPinch + static TaiheTouchGestureEvent TouchGestureEventToTaihe(const PointerEvent &pointerEvent); + static TaiheThreeFingersTap ThreeFingersTapToTaihe(const PointerEvent &pointerEvent); + // ztw Fingerprint +#ifdef OHOS_BUILD_ENABLE_FINGERPRINT + static TaiheFingerprintAction FingerprintActionToTaihe(int32_t action); + static TaiheFingerprintEvent FingerprintEventToTaihe(const PointerEvent &pointerEvent); +#endif + // ztw keyPressed + static bool HasKeyCode(const std::vector& pressedKeys, int32_t keyCode); + TaiheKeyEventAction KeyEventActionToTaihe(int32_t action); + TaiheKeyEvent TaiheKeyEventToTaihe(const KeyEvent &keyEvent); + TaiheKeyEventKey TaiheKeyEventKeyToTaihe(const KeyEvent::KeyItem &keyItem); }; -/* + + +using callbackType = std::variant< + taihe::callback, + taihe::callback, + taihe::callback, + taihe::callback, + taihe::callback, taihe::callback>; + + struct CallbackObject { CallbackObject(callbackType cb, ani_ref ref) : callback(cb), ref(ref) { @@ -863,7 +898,40 @@ struct CallbackObject { callbackType callback; ani_ref ref; }; -*/ + +class GlobalRefGuard { + ani_env *env_ = nullptr; + ani_ref ref_ = nullptr; + +public: + GlobalRefGuard(ani_env *env, ani_object obj) : env_(env) + { + if (!env_) { + return; + } + if (ANI_OK != env_->GlobalReference_Create(obj, &ref_)) { + ref_ = nullptr; + } + } + explicit operator bool() const + { + return ref_ != nullptr; + } + ani_ref get() const + { + return ref_; + } + ~GlobalRefGuard() + { + if (env_ && ref_) { + env_->GlobalReference_Delete(ref_); + } + } + + GlobalRefGuard(const GlobalRefGuard &) = delete; + GlobalRefGuard &operator=(const GlobalRefGuard &) = delete; +}; + } // namespace MMI } // namespace OHOS #endif // ANI_INPUT_TAIHE_INPUT_MONITOR_COMMON_H \ No newline at end of file diff --git a/frameworks/ets/common/src/ani_common.cpp b/frameworks/ets/common/src/ani_common.cpp index 2c88b84ff6..bae7670923 100644 --- a/frameworks/ets/common/src/ani_common.cpp +++ b/frameworks/ets/common/src/ani_common.cpp @@ -14,9 +14,34 @@ */ #include "ani_common.h" -#define RET_ERR -1 + +#include "mmi_log.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "aniCommon" + namespace OHOS { namespace MMI { +DeviceType g_taiheDeviceType[] = { + { "keyboard", EVDEV_TAG_KEYBOARD }, + { "mouse", EVDEV_TAG_MOUSE }, + { "touchpad", EVDEV_TAG_TOUCHPAD }, + { "touchscreen", EVDEV_TAG_TOUCHSCREEN }, + { "joystick", EVDEV_TAG_JOYSTICK }, + { "trackball", EVDEV_TAG_TRACKBALL }, +}; + +std::unordered_map g_taiheAxisType = { + { ABS_MT_TOUCH_MAJOR, "touchmajor" }, + { ABS_MT_TOUCH_MINOR, "touchminor" }, + { ABS_MT_ORIENTATION, "orientation" }, + { ABS_MT_POSITION_X, "x" }, + { ABS_MT_POSITION_Y, "y" }, + { ABS_MT_PRESSURE, "pressure" }, + { ABS_MT_WIDTH_MAJOR, "toolmajor" }, + { ABS_MT_WIDTH_MINOR, "toolminor" }, +}; + bool TaiheConverter::GetApiError(int32_t code, TaiheError &codeMsg) { auto iter = TAIHE_ERRORS.find(code); @@ -93,7 +118,7 @@ TaiheInputDeviceData TaiheConverter::ConverterInputDevice(std::shared_ptr vecSourceTypes; std::string sourceType = ""; uint32_t types = static_cast(device->GetType()); - for (auto item : g_deviceType) { + for (auto item : g_taiheDeviceType) { if (types &item.typeBit) { sourceType = item.sourceTypeName; vecSourceTypes.push_back(ConverterSourceType(ConverterSType(sourceType))); @@ -104,8 +129,8 @@ TaiheInputDeviceData TaiheConverter::ConverterInputDevice(std::shared_ptr vecAxisRanges; auto aixsArray = device->GetAxisInfo(); for (auto item : aixsArray) { - auto iter = g_axisType.find(item.GetAxisType()); - if (iter != g_axisType.end()) { + auto iter = g_taiheAxisType.find(item.GetAxisType()); + if (iter != g_taiheAxisType.end()) { axisType = iter->second; } TaiheAxisRange axisRange = ConverterAxisRange(item, sourceType, axisType); @@ -257,5 +282,327 @@ TaiheTouch TaiheConverter::TouchToTaihe(const PointerEvent::PointerItem &item) obj.fixedDisplayY = taihe::optional(std::in_place_t{}, item.GetFixedDisplayY()); return obj; } + +TaiheTouchGestureAction TaiheConverter::TouchGestureActionToTaihe(int32_t action) +{ + switch (action) { + case PointerEvent::TOUCH_ACTION_SWIPE_DOWN: { + return TaiheTouchGestureAction::key_t::SWIPE_DOWN; + } + case PointerEvent::TOUCH_ACTION_SWIPE_UP: { + return TaiheTouchGestureAction::key_t::SWIPE_UP; + } + case PointerEvent::TOUCH_ACTION_SWIPE_RIGHT: { + return TaiheTouchGestureAction::key_t::SWIPE_RIGHT; + } + case PointerEvent::TOUCH_ACTION_SWIPE_LEFT: { + return TaiheTouchGestureAction::key_t::SWIPE_LEFT; + } + case PointerEvent::TOUCH_ACTION_PINCH_OPENED: { + return TaiheTouchGestureAction::key_t::PINCH_OPENED; + } + case PointerEvent::TOUCH_ACTION_PINCH_CLOSEED: { + return TaiheTouchGestureAction::key_t::PINCH_CLOSED; + } + case PointerEvent::TOUCH_ACTION_GESTURE_END: { + return TaiheTouchGestureAction::key_t::GESTURE_END; + } + default: { + MMI_HILOGW("unknow action, action:%{public}d", action); + return TaiheTouchGestureAction::from_value(-1);; + } +} +} +TaiheGestureActionType TaiheConverter::RotateActionToTaihe(int32_t action) +{ + switch (action) { + case PointerEvent::POINTER_ACTION_ROTATE_BEGIN: { + return TaiheGestureActionType::key_t::BEGIN; + } + case PointerEvent::POINTER_ACTION_ROTATE_UPDATE: { + return TaiheGestureActionType::key_t::UPDATE; + } + case PointerEvent::POINTER_ACTION_ROTATE_END: { + return TaiheGestureActionType::key_t::END; + } + default: { + MMI_HILOGD("Abnormal pointer action in rotate event"); + return TaiheGestureActionType::from_value(-1); + } + } + +} + +TaiheGestureActionType TaiheConverter::PinchActionToTaihe(int32_t action) +{ + switch (action) { + case PointerEvent::POINTER_ACTION_AXIS_BEGIN: { + return TaiheGestureActionType::key_t::BEGIN; + } + case PointerEvent::POINTER_ACTION_AXIS_UPDATE: { + return TaiheGestureActionType::key_t::UPDATE; + } + case PointerEvent::POINTER_ACTION_AXIS_END: { + return TaiheGestureActionType::key_t::END; + } + default: { + MMI_HILOGD("Abnormal pointer action in pinch event"); + return TaiheGestureActionType::from_value(-1); + } + } + +} + +TaiheGestureActionType TaiheConverter::SwipeInwardActionToTaihe(int32_t action) +{ + switch (action) { + case PointerEvent::POINTER_ACTION_DOWN: { + return TaiheGestureActionType::key_t::BEGIN; + break; + } + case PointerEvent::POINTER_ACTION_MOVE: { + return TaiheGestureActionType::key_t::UPDATE; + break; + } + case PointerEvent::POINTER_ACTION_UP: + case PointerEvent::POINTER_ACTION_CANCEL: { + return TaiheGestureActionType::key_t::END; + break; + } + default: { + MMI_HILOGE("Abnormal pointer action in swipe event"); + return TaiheGestureActionType::from_value(-1); + } + } + +} + +TaiheGestureActionType TaiheConverter::SwipeActionToTaihe(int32_t action) +{ + switch (action) { + case PointerEvent::POINTER_ACTION_SWIPE_BEGIN: { + return TaiheGestureActionType::key_t::BEGIN; + } + case PointerEvent::POINTER_ACTION_SWIPE_UPDATE: { + return TaiheGestureActionType::key_t::UPDATE; + } + case PointerEvent::POINTER_ACTION_SWIPE_END: { + return TaiheGestureActionType::key_t::END; + } + default: { + MMI_HILOGD("Abnormal pointer action in swipe event"); + return TaiheGestureActionType::from_value(-1); + } + } + +} + +TaiheGestureActionType TaiheConverter::MultiTapActionToTaihe(int32_t action) +{ + switch (action) { + case PointerEvent::POINTER_ACTION_TRIPTAP: { + return TaiheGestureActionType::key_t::END; + } + default: { + MMI_HILOGD("Abnormal pointer action in multi tap event"); + return TaiheGestureActionType::from_value(-1); + } + } +} + +TaiheRotate TaiheConverter::RotateToTaihe(const PointerEvent &pointerEvent) +{ + TaiheRotate obj {.type = RotateActionToTaihe(pointerEvent.GetPointerAction())}; + obj.angle = pointerEvent.GetAxisValue(PointerEvent::AXIS_TYPE_ROTATE); + return obj; + +} + +TaihePinchEvent TaiheConverter::PinchToTaihe(const PointerEvent &pointerEvent) +{ + TaihePinchEvent obj {.type = PinchActionToTaihe(pointerEvent.GetPointerAction())}; + obj.scale = pointerEvent.GetAxisValue(PointerEvent::AXIS_TYPE_PINCH); + return obj; + +} + +TaiheSwipeInward TaiheConverter::SwipeInwardToTaihe(const PointerEvent &pointerEvent) +{ + TaiheSwipeInward obj {.type = SwipeActionToTaihe(pointerEvent.GetPointerAction())}; + PointerEvent::PointerItem pointeritem; + int32_t pointerId = 0; + if (!pointerEvent.GetPointerItem(pointerId, pointeritem)) { + MMI_HILOGE("Can't find this pointerItem"); + return obj; + } + obj.x = pointeritem.GetDisplayX(); + obj.y = pointeritem.GetDisplayY(); + return obj; + +} + +TaiheThreeFingersSwipe TaiheConverter::ThreeFingersSwipeToTaihe(const PointerEvent &pointerEvent) +{ + TaiheThreeFingersSwipe obj {.type = SwipeActionToTaihe(pointerEvent.GetPointerAction())}; + PointerEvent::PointerItem pointeritem; + int32_t pointerId = 0; + if (!pointerEvent.GetPointerItem(pointerId, pointeritem)) { + MMI_HILOGE("Can't find this pointerItem"); + return obj; + } + obj.x = pointeritem.GetDisplayX(); + obj.y = pointeritem.GetDisplayY(); + return obj; +} + +TaiheFourFingersSwipe TaiheConverter::FourFingersSwipeToTaihe(const PointerEvent &pointerEvent) +{ + TaiheFourFingersSwipe obj {.type = SwipeActionToTaihe(pointerEvent.GetPointerAction())}; + PointerEvent::PointerItem pointeritem; + int32_t pointerId = 0; + if (!pointerEvent.GetPointerItem(pointerId, pointeritem)) { + MMI_HILOGE("Can't find this pointerItem"); + return obj; + } + obj.x = pointeritem.GetDisplayX(); + obj.y = pointeritem.GetDisplayY(); + return obj; +} + +TaiheTouchGestureEvent TaiheConverter::TouchGestureEventToTaihe(const PointerEvent &pointerEvent) +{ + TaiheTouchGestureEvent obj {.action = TouchGestureActionToTaihe(pointerEvent.GetPointerAction())}; + std::vector vecTouches; + for (auto item : pointerEvent.GetPointerIds()) { + PointerEvent::PointerItem pointerItem; + if (!pointerEvent.GetPointerItem(item, pointerItem)) { + MMI_HILOGE("Get pointer item failed"); + return obj; + } + vecTouches.push_back(TouchToTaihe(pointerItem)); + } + obj.touches = taihe::array(vecTouches); + return obj; +} + +TaiheThreeFingersTap TaiheConverter::ThreeFingersTapToTaihe(const PointerEvent &pointerEvent) +{ + TaiheThreeFingersTap obj {.type = MultiTapActionToTaihe(pointerEvent.GetPointerAction()) }; + return obj; +} + +#ifdef OHOS_BUILD_ENABLE_FINGERPRINT +TaiheFingerprintAction TaiheConverter::FingerprintActionToTaihe(int32_t action) +{ + switch (action) { + case PointerEvent::POINTER_ACTION_FINGERPRINT_DOWN: { + return TaiheFingerprintAction::key_t::DOWN; + } + case PointerEvent::POINTER_ACTION_FINGERPRINT_UP: { + return TaiheFingerprintAction::key_t::UP; + } + case PointerEvent::POINTER_ACTION_FINGERPRINT_SLIDE: { + return TaiheFingerprintAction::key_t::SLIDE; + } + case PointerEvent::POINTER_ACTION_FINGERPRINT_RETOUCH: { + return TaiheFingerprintAction::key_t::RETOUCH; + } + case PointerEvent::POINTER_ACTION_FINGERPRINT_CLICK: { + return TaiheFingerprintAction::key_t::CLICK; + } + /* // ztw 接口定义中没找到 + case PointerEvent::POINTER_ACTION_FINGERPRINT_CANCEL: { + return FINGERPRINT_CANCEL; + } + case PointerEvent::POINTER_ACTION_FINGERPRINT_HOLD: { + return FINGERPRINT_HOLD; + } + case PointerEvent::POINTER_ACTION_FINGERPRINT_TOUCH: { + return FINGERPRINT_TOUCH; + } */ + default: { + MMI_HILOGE("Wrong action is %{public}d", action); + return TaiheFingerprintAction::from_value(-1); + } + } +} + +TaiheFingerprintEvent TaiheConverter::FingerprintEventToTaihe(const PointerEvent &pointerEvent) +{ + TaiheFingerprintEvent obj {.action = FingerprintActionToTaihe(pointerEvent.GetPointerAction())}; + obj.distanceX = pointerEvent.GetFingerprintDistanceX(); + obj.distanceY = pointerEvent.GetFingerprintDistanceY(); + return obj; +} +#endif + +bool TaiheConverter::HasKeyCode(const std::vector& pressedKeys, int32_t keyCode) +{ + return std::find(pressedKeys.begin(), pressedKeys.end(), keyCode) != pressedKeys.end(); +} + +TaiheKeyEventAction TaiheConverter::KeyEventActionToTaihe(int32_t action) +{ + if (KeyEvent::KEY_ACTION_CANCEL == action) { + return TaiheKeyEventAction::key_t::CANCEL; + } else if (KeyEvent::KEY_ACTION_DOWN == action) { + return TaiheKeyEventAction::key_t::DOWN; + } else if (KeyEvent::KEY_ACTION_UP == action) { + return TaiheKeyEventAction::key_t::UP; + } else { + return TaiheKeyEventAction::from_value(-1); + } + +} + +TaiheKeyEvent TaiheConverter::TaiheKeyEventToTaihe(const KeyEvent &keyEvent) +{ + TaiheKeyEvent obj {.action = KeyEventActionToTaihe(keyEvent.GetKeyAction()), + .key = { + .code = KeyCode::key_t::KEYCODE_UNKNOWN, + } }; + std::optional keyItem = keyEvent.GetKeyItem(); + if (!keyItem) { + MMI_HILOGE("The keyItem is nullopt"); + return obj; + } + obj.key = TaiheKeyEventKeyToTaihe(keyItem.value()); + obj.unicodeChar = keyItem->GetUnicode(); + std::vector pressedKeys = keyEvent.GetPressedKeys(); + std::vector keys; + for (const auto &pressedKeyCode : pressedKeys) { + std::optional pressedKeyItem = keyEvent.GetKeyItem(pressedKeyCode); + if (!pressedKeyItem) { + MMI_HILOGE("The pressedKeyItem is nullopt"); + return obj; + } + auto taiheKey = TaiheKeyEventKeyToTaihe(pressedKeyItem.value()); + keys.push_back(taiheKey); + } + obj.keys = taihe::array(keys); + obj.base = InputEventToTaihe(keyEvent); + obj.ctrlKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_LEFT) + || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_RIGHT); + obj.altKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_ALT_LEFT) + || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_ALT_RIGHT);; + obj.shiftKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_SHIFT_LEFT) + || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_SHIFT_RIGHT); + obj.logoKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_META_LEFT) + || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_META_RIGHT); + obj.fnKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_FN); + obj.capsLock = keyEvent.GetFunctionKey(KeyEvent::CAPS_LOCK_FUNCTION_KEY); + obj.numLock = keyEvent.GetFunctionKey(KeyEvent::NUM_LOCK_FUNCTION_KEY); + obj.scrollLock = keyEvent.GetFunctionKey(KeyEvent::SCROLL_LOCK_FUNCTION_KEY); + return obj; + +} + +TaiheKeyEventKey TaiheConverter::TaiheKeyEventKeyToTaihe(const KeyEvent::KeyItem &keyItem) +{ + TaiheKeyEventKey obj {.code = ConvertEtsKeyCode(keyItem.GetKeyCode()) }; + obj.pressedTime = keyItem.GetDownTime(); + obj.deviceId = keyItem.GetDeviceId(); + return obj; +} } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe b/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe index 3040093048..4fd4d90cc4 100644 --- a/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe +++ b/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe @@ -97,12 +97,10 @@ struct InputDeviceData { uniq: String; } -// ѷ @gen_async("getDeviceIds") @gen_promise("getDeviceIds") function GetDeviceIdsAsync(): i32; -// ѷ @gen_async("getDevice") @gen_promise("getDevice") function GetDeviceAsync(deviceId: i32): InputDeviceData; diff --git a/frameworks/ets/input_monitor/BUILD.gn b/frameworks/ets/input_monitor/BUILD.gn index 3daf6e3f6f..2c4407a9b2 100644 --- a/frameworks/ets/input_monitor/BUILD.gn +++ b/frameworks/ets/input_monitor/BUILD.gn @@ -30,6 +30,7 @@ config("inputMonitor_config") { include_dirs = [ "${mmi_path}/interfaces/native/innerkits/proxy/include", + "${mmi_path}/interfaces/native/innerkits/event/include", "${mmi_path}/service/permission_helper/include", "${mmi_path}/util/common/include", "${mmi_path}/frameworks/ets/common/include", @@ -59,6 +60,7 @@ taihe_shared_library("InputMonitor") { sources += [ "src/ani_constructor.cpp", + "src/ani_input_monitor_consumer.cpp", "src/ani_input_monitor_manager.cpp", "src/ohos.multimodalInput.inputMonitor.impl.cpp" ] diff --git a/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h b/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h new file mode 100644 index 0000000000..b623ec49d8 --- /dev/null +++ b/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INPUT_ANI_MONITOR_CONSUMER_H +#define INPUT_ANI_MONITOR_CONSUMER_H + +#include +#include + +#include "window_info.h" + +#include "axis_event.h" +#include "ani_common.h" +#include "i_input_event_consumer.h" +#include "key_event.h" +#include "pointer_event.h" +#include "nocopyable.h" + +namespace OHOS { +namespace MMI { +enum class MONITORFUNTYPE: int32_t { + ON_TOUCH, + ON_MOUSE, + ON_MOUSE_RECT, + ON_PINCH, + ON_PINCH_FINGERS, + ON_ROTATE_FINGERS, + ON_THREEFINGERSWIPE, + ON_FOURFINGERSWIPE, + ON_THREEFINGERSTAP, + ON_FINGERPRINT, + ON_SWIPEINWARD, + ON_TOUCHSCREENSWIPE_FINGERS, + ON_TOUCHSCREENPINCH_FINGERS, + ON_KEYPRESSED_KEYS, + + OFF_TOUCH, + OFF_MOUSE, + OFF_PINCH, + OFF_PINCH_FINGERS, + OFF_ROTATE_FINGERS, + OFF_THREEFINGERSWIPE, + OFF_FOURFINGERSWIPE, + OFF_THREEFINGERSTAP, + OFF_FINGERPRINT, + OFF_SWIPEINWARD, + OFF_TOUCHSCREENSWIPE_FINGERS, + OFF_TOUCHSCREENPINCH_FINGERS, + OFF_KEYPRESSED_KEYS +}; + +using ConsumerParmType = std::variant, std::vector>; +class AniInputMonitorConsumer: public IInputEventConsumer, public std::enable_shared_from_this { +public: + AniInputMonitorConsumer(MONITORFUNTYPE funType, int32_t fingers, std::vector hotRectArea, + std::vector keys, std::shared_ptr &aniCallback): funType_(funType), + fingers_(fingers), keys_(keys), hotRectArea_(hotRectArea), aniCallback_(aniCallback) { + } + ~AniInputMonitorConsumer() override = default; + int32_t GetId() const; + int32_t GetFingers() const; + std::string GetTypeName() const; + bool IsOnFunc() const; + int32_t Start(); + void Stop(); + static std::shared_ptr CreateAniInputMonitorConsumer(MONITORFUNTYPE funType, + const ConsumerParmType ¶m, callbackType &&cb, uintptr_t opq); + static bool IsOnFunc(MONITORFUNTYPE funType) { + if (funType >= MONITORFUNTYPE::ON_TOUCH && funType <= MONITORFUNTYPE::ON_KEYPRESSED_KEYS) { + return true; + } + return false; + } + +protected: + static bool CreateCallback(callbackType &&cb, uintptr_t opq, std::shared_ptr &callback); + static bool ReleaseCallback(std::shared_ptr &callback, taihe::optional_view opq); + void OnInputEvent(std::shared_ptr keyEvent) const override; + void OnInputEvent(std::shared_ptr pointerEvent) const override; + void OnInputEvent(std::shared_ptr axisEvent) const override; + // 处理Taihe数据 + void OnAniPointerEvent(std::shared_ptr pointerEvent); + + void OnAniKeyEvent(std::shared_ptr keyEvent) { + + } + void SetConsumeState(std::shared_ptr pointerEvent) const; + bool IsGestureEvent(std::shared_ptr pointerEvent) const; +private: + MONITORFUNTYPE funType_; + int32_t fingers_ { 0 }; + std::vector keys_; + std::vector hotRectArea_; + std::shared_ptr aniCallback_ { nullptr }; + + int32_t monitorId_ { -1 }; + // bool isMonitoring_ { false }; // 是否正在订阅 + // uint32_t rectTotal_ { 0 }; + mutable bool consumed_ { false }; // 什么含义 + mutable std::mutex mutex_; + mutable int32_t flowCtrl_ { 0 }; +}; +} // namespace MMI +} // namespace OHOS +#endif // INPUT_ANI_MONITOR_CONSUMER_H + diff --git a/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h b/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h index 1f64220b7c..5d1e9a1ca3 100644 --- a/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h +++ b/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h @@ -16,10 +16,11 @@ #ifndef ANI_INPUT_MONITOR_MANAGER_H #define ANI_INPUT_MONITOR_MANAGER_H +#include +#include #include -#include -#include "ani_common.h" +#include "ani_input_monitor_consumer.h" #include "nocopyable.h" namespace OHOS { @@ -31,15 +32,18 @@ public: ~AniInputMonitorManager() = default; TaiheTouchEventArray QueryTouchEvents(int32_t count); + bool AddMonitor(MONITORFUNTYPE funType, const ConsumerParmType ¶m, + callbackType &cb, uintptr_t opq); + + private: AniInputMonitorManager() = default; private: -// int32_t nextId_ { 0 }; -// std::mutex mutex_; -// std::mutex envMutex_; - + //int32_t monitorId_ { 0 }; + std::mutex mutex_; + std::map> monitors_; }; -#define ANI_INPUT_MONITOR_MGR AniInputMonitorManager::GetInstance() +#define ANI_INPUT_MONITOR_MGR ::OHOS::MMI::AniInputMonitorManager::GetInstance() } // namespace MMI } // namespace OHOS #endif // JS_INPUT_MONITOR_MANAGER_H diff --git a/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp b/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp new file mode 100644 index 0000000000..093c332078 --- /dev/null +++ b/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp @@ -0,0 +1,434 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ani_input_monitor_consumer.h" + +#include "input_manager.h" +#include "mmi_log.h" + + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "AniInputMonitorConsumer" + +namespace OHOS { +namespace MMI { +namespace { + static std::mutex jsCbMapMutex; + std::map FUNCTTOYPENAME = { + { MONITORFUNTYPE::ON_TOUCH,"touch" }, + { MONITORFUNTYPE::ON_MOUSE, "mouse"}, + { MONITORFUNTYPE::ON_MOUSE_RECT, "mouse" }, + { MONITORFUNTYPE::ON_PINCH, "pinch" }, + { MONITORFUNTYPE::ON_PINCH_FINGERS, "pinch" }, + { MONITORFUNTYPE::ON_ROTATE_FINGERS, "rotate" }, + { MONITORFUNTYPE::ON_THREEFINGERSWIPE, "threeFingersSwipe" }, + { MONITORFUNTYPE::ON_FOURFINGERSWIPE, "fourFingersSwipe" }, + { MONITORFUNTYPE::ON_THREEFINGERSTAP, "threeFingersTap" }, + { MONITORFUNTYPE::ON_FINGERPRINT, "fingerprint" }, + { MONITORFUNTYPE::ON_SWIPEINWARD, "swipeInward" }, + { MONITORFUNTYPE::ON_TOUCHSCREENSWIPE_FINGERS, "touchscreenSwipe" }, + { MONITORFUNTYPE::ON_TOUCHSCREENPINCH_FINGERS, "touchscreenPinch" }, + { MONITORFUNTYPE::ON_KEYPRESSED_KEYS, "keyPressed" }, + + { MONITORFUNTYPE::OFF_TOUCH, "touch" }, + { MONITORFUNTYPE::OFF_MOUSE, "mouse" }, + { MONITORFUNTYPE::OFF_PINCH, "pinch" }, + { MONITORFUNTYPE::OFF_PINCH_FINGERS, "pinch" }, + { MONITORFUNTYPE::OFF_ROTATE_FINGERS, "rotate" }, + { MONITORFUNTYPE::OFF_THREEFINGERSWIPE, "threeFingersSwipe" }, + { MONITORFUNTYPE::OFF_FOURFINGERSWIPE, "fourFingersSwipe" }, + { MONITORFUNTYPE::OFF_THREEFINGERSTAP, "threeFingersTap" }, + { MONITORFUNTYPE::OFF_FINGERPRINT, "fingerprint" }, + { MONITORFUNTYPE::OFF_SWIPEINWARD, "swipeInward" }, + { MONITORFUNTYPE::OFF_TOUCHSCREENSWIPE_FINGERS, "touchscreenSwipe" }, + { MONITORFUNTYPE::OFF_TOUCHSCREENPINCH_FINGERS, "touchscreenPinch" }, + { MONITORFUNTYPE::OFF_KEYPRESSED_KEYS, "keyPressed" }, + }; + +constexpr int32_t MOUSE_FLOW { 10 }; +const std::string INVALID_TYPE_NAME { "" }; + +inline const std::string TOUCH_SWIPE_GESTURE = "touchscreenSwipe"; +inline const std::string TOUCH_PINCH_GESTURE = "touchscreenPinch"; +inline const std::string TOUCH_ALL_GESTURE = "touchAllGesture"; + +std::map TO_GESTURE_TYPE = { + { TOUCH_PINCH_GESTURE, TOUCH_GESTURE_TYPE_PINCH }, + { TOUCH_SWIPE_GESTURE, TOUCH_GESTURE_TYPE_SWIPE }, + { TOUCH_ALL_GESTURE, TOUCH_GESTURE_TYPE_ALL }, +}; + +std::map TO_HANDLE_EVENT_TYPE = { + { "none", HANDLE_EVENT_TYPE_NONE }, + { "key", HANDLE_EVENT_TYPE_KEY }, + { "pointer", HANDLE_EVENT_TYPE_POINTER }, + { "touch", HANDLE_EVENT_TYPE_TOUCH }, + { "mouse", HANDLE_EVENT_TYPE_MOUSE }, + { "pinch", HANDLE_EVENT_TYPE_PINCH }, + { "threeFingersSwipe", HANDLE_EVENT_TYPE_THREEFINGERSSWIP }, + { "fourFingersSwipe", HANDLE_EVENT_TYPE_FOURFINGERSSWIP }, + { "swipeInward", HANDLE_EVENT_TYPE_SWIPEINWARD }, + { "rotate", HANDLE_EVENT_TYPE_ROTATE }, + { "threeFingersTap", HANDLE_EVENT_TYPE_THREEFINGERSTAP }, + { "fingerprint", HANDLE_EVENT_TYPE_FINGERPRINT }, + { "xKey", HANDLE_EVENT_TYPE_X_KEY }, +}; + +std::map TO_HANDLE_PRE_EVENT_TYPE = { + { "keyPressed", HANDLE_EVENT_TYPE_PRE_KEY }, +}; +} +int32_t AniInputMonitorConsumer::GetId() const +{ + return monitorId_; +} + +int32_t AniInputMonitorConsumer::GetFingers() const +{ + return fingers_; +} + +std::string AniInputMonitorConsumer::GetTypeName() const +{ + auto itFind = FUNCTTOYPENAME.find(funType_); + if (itFind != FUNCTTOYPENAME.end()) { + return itFind->second; + } + return ""; +} + +bool AniInputMonitorConsumer::IsOnFunc() const +{ + if (funType_ >= MONITORFUNTYPE::ON_TOUCH && funType_ <= MONITORFUNTYPE::ON_KEYPRESSED_KEYS) { + return true; + } + return false; + +} + +int32_t AniInputMonitorConsumer::Start() +{ + CALL_DEBUG_ENTER; + auto typeName = GetTypeName(); + std::lock_guard guard(mutex_); + if (monitorId_ < 0) { + auto iter = TO_HANDLE_PRE_EVENT_TYPE.find(typeName.c_str()); + if (iter != TO_HANDLE_PRE_EVENT_TYPE.end()) { + monitorId_ = InputManager::GetInstance()->AddPreMonitor(shared_from_this(), iter->second, keys_); + return monitorId_; + } + + auto it = TO_GESTURE_TYPE.find(typeName); + if (it != TO_GESTURE_TYPE.end()) { + monitorId_ = InputManager::GetInstance()->AddGestureMonitor(shared_from_this(), it->second, fingers_); + } else { + int32_t eventType = 0; + auto it = TO_HANDLE_EVENT_TYPE.find(typeName.c_str()); + if (it != TO_HANDLE_EVENT_TYPE.end()) { + eventType = it->second; + } + monitorId_ = InputManager::GetInstance()->AddMonitor(shared_from_this(), eventType); + } + } + return monitorId_; +} + +void AniInputMonitorConsumer::Stop() +{ + CALL_DEBUG_ENTER; + std::lock_guard guard(mutex_); + if (monitorId_ < 0) { + MMI_HILOGE("Invalid values"); + return; + } + + auto iter = TO_HANDLE_PRE_EVENT_TYPE.find(GetTypeName().c_str()); + if (iter != TO_HANDLE_PRE_EVENT_TYPE.end()) { + InputManager::GetInstance()->RemovePreMonitor(monitorId_); + monitorId_ = -1; + return; + } + + auto it = TO_GESTURE_TYPE.find(GetTypeName()); + if (it != TO_GESTURE_TYPE.end()) { + InputManager::GetInstance()->RemoveGestureMonitor(monitorId_); + } else { + InputManager::GetInstance()->RemoveMonitor(monitorId_); + } + monitorId_ = -1; +} + +std::shared_ptr AniInputMonitorConsumer::CreateAniInputMonitorConsumer(MONITORFUNTYPE funType, + const ConsumerParmType ¶m, callbackType &&cb, uintptr_t opq) +{ + CALL_DEBUG_ENTER; + std::shared_ptr ret = { nullptr }; + if (!IsOnFunc(funType)) { + return ret; + } + int32_t fingers { 0 }; + std::vector rect; + std::vector keys; + switch (funType) { + case MONITORFUNTYPE::ON_PINCH_FINGERS: + case MONITORFUNTYPE::ON_ROTATE_FINGERS: + case MONITORFUNTYPE::ON_TOUCHSCREENSWIPE_FINGERS: + case MONITORFUNTYPE::ON_TOUCHSCREENPINCH_FINGERS: { + auto *pVal = std::get_if(¶m); + if (pVal == nullptr) { + return ret; + } + fingers = *pVal; + break; + } + case MONITORFUNTYPE::ON_MOUSE_RECT: { + auto *pVal = std::get_if>(¶m); + if (pVal == nullptr) { + return ret; + } + rect = *pVal; + break; + } + case MONITORFUNTYPE::ON_KEYPRESSED_KEYS: { + auto *pVal = std::get_if>(¶m); + if (pVal == nullptr) { + return ret; + } + keys = *pVal; + break; + + } + default: + break; + } + std::shared_ptr callback; + if (!CreateCallback(std::move(cb), opq, callback)) { + return ret; + } + ret = std::make_shared(funType, fingers, rect, keys, callback); + return ret; +} + +bool AniInputMonitorConsumer::CreateCallback(callbackType &&cb, uintptr_t opq, std::shared_ptr &callback) +{ + std::lock_guard lock(jsCbMapMutex); + ani_object callbackObj = reinterpret_cast(opq); + ani_ref callbackRef; + ani_env *env = taihe::get_env(); + if (env == nullptr || ANI_OK != env->GlobalReference_Create(callbackObj, &callbackRef)) { + MMI_HILOGE("ani_env is nullptr or GlobalReference_Create failed"); + return false; + } + ani_boolean isEqual = false; + auto result = ANI_OK;// env->Reference_StrictEquals(callbackRef, obj->ref, &isEqual); ztw 这块有疑问 + if (result != ANI_OK) { + MMI_HILOGE("ani_env Reference_StrictEquals failed"); + return false; + } + if (isEqual) { + env->GlobalReference_Delete(callbackRef); + MMI_HILOGD("callback already registered"); + return false; + } + callback = std::make_shared(cb, callbackRef); + return true; +} + +bool AniInputMonitorConsumer::ReleaseCallback(std::shared_ptr &callback, taihe::optional_view opq) +{ + std::lock_guard lock(jsCbMapMutex); + if (!opq.has_value()) { + MMI_HILOGE("callback is nullptr!"); + return false; + } + ani_env *env = taihe::get_env(); + if (env == nullptr) { + MMI_HILOGE("ani_env is nullptr!"); + return false; + } + GlobalRefGuard guard(env, reinterpret_cast(opq.value())); + if (!guard) { + MMI_HILOGE("GlobalRefGuard is false!"); + return false; + } + ani_boolean isEqual = false; + auto result = env->Reference_StrictEquals(guard.get(), callback->ref, &isEqual); + if (result != ANI_OK) { + MMI_HILOGE("ani_env Reference_StrictEquals failed"); + return false; + } + MMI_HILOGI("ReleaseCallback callback success."); + return true; +} + +void AniInputMonitorConsumer::OnInputEvent(std::shared_ptr keyEvent) const +{ + CALL_DEBUG_ENTER; + CHKPV(keyEvent); + std::function)> callback; + { + std::lock_guard guard(mutex_); + // ztw + //auto typeName = ANI_INPUT_MONITOR_MGR.GetPreMonitorTypeName(id_); + if (GetTypeName() == INVALID_TYPE_NAME || GetTypeName() != "keyPressed") { + MMI_HILOGE("Failed to process key event."); + return; + } + // ztw + //callback = keyCallback_; + } + // ztw + CHKPV(callback); + callback(keyEvent); +} + +void AniInputMonitorConsumer::OnInputEvent(std::shared_ptr pointerEvent) const +{ + CALL_DEBUG_ENTER; + CHKPV(pointerEvent); + if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE + && pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_MOVE) { + if (++flowCtrl_ < MOUSE_FLOW) { + return; + } else { + flowCtrl_ = 0; + } + } + std::function)> callback; + { + std::lock_guard guard(mutex_); + auto typeName = GetTypeName(); // ANI_INPUT_MONITOR_MGR.GetMonitorTypeName(id_, fingers_); ztw + if (typeName == INVALID_TYPE_NAME) { + MMI_HILOGE("Failed to process pointer event"); + return; + } + if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) { + if (typeName != "touch" && typeName != TOUCH_SWIPE_GESTURE && + typeName != TOUCH_PINCH_GESTURE && typeName != TOUCH_ALL_GESTURE) { + return; + } + // SetConsumeState(pointerEvent); // ztw + } + if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE) { + if (typeName != "mouse" && typeName != "pinch" && typeName != "rotate") { + return; + } + // SetConsumeState(pointerEvent); // ztw + } + if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHPAD) { + // ztw if (!IsGestureEvent(pointerEvent)) + { + return; + } + } + if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_JOYSTICK) { + // ztw if (ANI_INPUT_MONITOR_MGR.GetMonitor(id_, fingers_)->GetTypeName() != "joystick") + { + MMI_HILOGE("Failed to process joystick event"); + return; + } + } + // ztw + // callback = callback_; + } + // CHKPV(callback); + // callback(pointerEvent); +} + +void AniInputMonitorConsumer::OnInputEvent(std::shared_ptr axisEvent) const +{ + CALL_DEBUG_ENTER; +} + +void AniInputMonitorConsumer::SetConsumeState(std::shared_ptr pointerEvent) const +{ + CHKPV(pointerEvent); + if (pointerEvent->GetPointerIds().size() == 1) { + if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_DOWN) { + consumed_ = false; + } + } +} + +bool AniInputMonitorConsumer::IsGestureEvent(std::shared_ptr pointerEvent) const +{ + // ztw + /* + CHKPF(pointerEvent); + auto jsMonitor = JS_INPUT_MONITOR_MGR.GetMonitor(id_, fingers_); + CHKPF(jsMonitor); + auto ret = jsMonitor->GetTypeName(); + if (ret != "pinch" && ret != "threeFingersSwipe" && + ret != "fourFingersSwipe" && ret != "threeFingersTap" && + ret != "swipeInward") { + return false; + } + if (pointerEvent->GetPointerIds().size() == 1) { + if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_AXIS_BEGIN || + PointerEvent::POINTER_ACTION_SWIPE_BEGIN) { + consumed_ = false; + } + } + */ + return true; +} + +void AniInputMonitorConsumer::OnAniPointerEvent(std::shared_ptr pointerEvent) +{ + LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerEvent->GetPointerAction()); + switch (funType_) { + case MONITORFUNTYPE::ON_TOUCH: { + /* ztw 先屏蔽掉 + auto &func = std::get>(aniCallback_.get()); + auto result = TaiheConverter::TouchEventToTaihe(*pointerEvent); + func(result); + */ + break; + } + + case MONITORFUNTYPE::ON_MOUSE: { + break; + } + case MONITORFUNTYPE::ON_MOUSE_RECT: + break; + case MONITORFUNTYPE::ON_PINCH: + case MONITORFUNTYPE::ON_PINCH_FINGERS: + break; + case MONITORFUNTYPE::ON_ROTATE_FINGERS: + break; + case MONITORFUNTYPE::ON_THREEFINGERSWIPE: + break; + case MONITORFUNTYPE::ON_FOURFINGERSWIPE: + break; + case MONITORFUNTYPE::ON_THREEFINGERSTAP: + break; + case MONITORFUNTYPE::ON_FINGERPRINT: + break; + case MONITORFUNTYPE::ON_SWIPEINWARD: + break; + case MONITORFUNTYPE::ON_TOUCHSCREENSWIPE_FINGERS: + break; + case MONITORFUNTYPE::ON_TOUCHSCREENPINCH_FINGERS: + break; + case MONITORFUNTYPE::ON_KEYPRESSED_KEYS: + break; + /* code */ + break; + default: + break; + } + } +} // namespace MMI +} // namespace OHOS diff --git a/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp b/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp index d80412008d..6e6563d437 100644 --- a/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp +++ b/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp @@ -15,7 +15,6 @@ #include "ani_input_monitor_manager.h" -#include "ani_common.h" #include "define_multimodal.h" #include "input_manager.h" @@ -24,16 +23,6 @@ namespace OHOS { namespace MMI { -// namespace { -// //constexpr int32_t MONITOR_REGISTER_EXCEED_MAX { 4100001 }; -// } // namespace -// static const std::vector supportedKeyCodes = { -// KeyEvent::KEYCODE_POWER, -// KeyEvent::KEYCODE_META_LEFT, -// KeyEvent::KEYCODE_VOLUME_UP, -// KeyEvent::KEYCODE_VOLUME_DOWN, -// KeyEvent::KEYCODE_META_RIGHT -// }; AniInputMonitorManager& AniInputMonitorManager::GetInstance() { @@ -69,5 +58,19 @@ TaiheTouchEventArray AniInputMonitorManager::QueryTouchEvents(int32_t count) result = taihe::array(vecProperty); return result; } + +bool AniInputMonitorManager::AddMonitor(MONITORFUNTYPE funType, + const ConsumerParmType ¶m, callbackType &cb, uintptr_t opq) +{ + CALL_DEBUG_ENTER; + std::shared_ptr consumer = AniInputMonitorConsumer::CreateAniInputMonitorConsumer(funType, param, + std::move(cb), opq); + if (!consumer) { + return false; + } + std::lock_guard guard(mutex_); + consumer->Start(); + return true; +} } // namespace MMI } // namespace OHOS diff --git a/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp b/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp index 296f9f1502..f5a71c4b34 100644 --- a/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp +++ b/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp @@ -13,6 +13,12 @@ using namespace OHOS::MMI; } void onTouch(::ohos::multimodalInput::inputMonitor::TouchEventReceiver const& receiver) { + /* ztw error + if (receiver.filter == nullptr) { + taihe::set_business_error(401, "Parameter error."); + return; + } + */ TH_THROW(std::runtime_error, "onTouch not implemented"); } diff --git a/frameworks/ets/touch_event/idl/ohos.multimodalInput.touchEvent.taihe b/frameworks/ets/touch_event/idl/ohos.multimodalInput.touchEvent.taihe index 2e3ad462e9..018e7227f1 100644 --- a/frameworks/ets/touch_event/idl/ohos.multimodalInput.touchEvent.taihe +++ b/frameworks/ets/touch_event/idl/ohos.multimodalInput.touchEvent.taihe @@ -78,4 +78,5 @@ struct TouchEvent { touches: Array; sourceType: SourceType; fixedMode: Optional; + isInject: Optional; } \ No newline at end of file diff --git a/frameworks/napi/input_monitor/include/js_input_monitor.h b/frameworks/napi/input_monitor/include/js_input_monitor.h index 821d55f9c1..bda4c26b8a 100644 --- a/frameworks/napi/input_monitor/include/js_input_monitor.h +++ b/frameworks/napi/input_monitor/include/js_input_monitor.h @@ -61,8 +61,8 @@ private: private: std::function)> callback_; std::function)> keyCallback_; - int32_t id_ { -1 }; - int32_t monitorId_ { -1 }; + int32_t id_ { -1 }; // 本地自增请求id + int32_t monitorId_ { -1 }; // 订阅id,服务器生成 int32_t fingers_ { 0 }; std::vector hotRectArea_; uint32_t rectTotal_ { 0 }; @@ -197,7 +197,7 @@ private: napi_ref receiver_ { nullptr }; napi_env jsEnv_ { nullptr }; std::string typeName_; - int32_t monitorId_ { 0 }; + int32_t monitorId_ { 0 }; // 本地请求id int32_t fingers_ { 0 }; bool isMonitoring_ { false }; std::mutex mutex_; -- Gitee From e56675398d2f07eb7f4dde0aa5c7e9a8fed9d438 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Tue, 29 Jul 2025 15:35:44 +0800 Subject: [PATCH 15/29] inputEventClient Signed-off-by: qianyong325 --- frameworks/ets/common/src/ani_common.cpp | 1 + frameworks/ets/input_event_client/BUILD.gn | 5 +++- ...hos.multimodalInput.inputEventClient.taihe | 22 +++++++++++++++++ ....multimodalInput.inputEventClient.impl.cpp | 24 +++++++++---------- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/frameworks/ets/common/src/ani_common.cpp b/frameworks/ets/common/src/ani_common.cpp index bae7670923..e11db49f56 100644 --- a/frameworks/ets/common/src/ani_common.cpp +++ b/frameworks/ets/common/src/ani_common.cpp @@ -149,6 +149,7 @@ TaiheInputDeviceData TaiheConverter::ConverterInputDevice(std::shared_ptrSetSourceType(toolType); item.SetPointerId(0); item.SetDisplayX(screenX); item.SetDisplayY(screenY); item.SetDisplayXPos(screenX); item.SetDisplayYPos(screenY); - if (globalX != DBL_MAX && globalY != DBL_MAX) { - item.SetGlobalX(globalX); - item.SetGlobalY(globalY); - } + // if (globalX != DBL_MAX && globalY != DBL_MAX) { + // item.SetGlobalX(globalX); + // item.SetGlobalY(globalY); + // } pointerEvent->SetPointerId(0); pointerEvent->AddPointerItem(item); } -- Gitee From c3d86906f4dd999fe26859747249f073340515ab Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Tue, 29 Jul 2025 18:13:28 +0800 Subject: [PATCH 16/29] =?UTF-8?q?lmq=20pointer=20=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- frameworks/ets/common/BUILD.gn | 4 + frameworks/ets/common/include/ani_common.h | 5 + frameworks/ets/common/src/ani_common.cpp | 34 ++++++ frameworks/ets/input_device/BUILD.gn | 1 + .../ohos.multimodalInput.inputDevice.impl.cpp | 2 +- frameworks/ets/pointer/BUILD.gn | 2 + .../src/ohos.multimodalInput.pointer.impl.cpp | 108 ++++++++++++++++-- 7 files changed, 146 insertions(+), 10 deletions(-) diff --git a/frameworks/ets/common/BUILD.gn b/frameworks/ets/common/BUILD.gn index 49effe4b75..5019653e0a 100644 --- a/frameworks/ets/common/BUILD.gn +++ b/frameworks/ets/common/BUILD.gn @@ -27,6 +27,7 @@ copy_taihe_idl("inputani_common_taihe") { "${mmi_path}/frameworks/ets/key_event:key_event_taihe", "${mmi_path}/frameworks/ets/input_device:input_device_taihe", "${mmi_path}/frameworks/ets/input_consumer:input_consumer_taihe", + "${mmi_path}/frameworks/ets/pointer:pointer_taihe", ] } config("inputani_common_config") { @@ -54,6 +55,7 @@ ohos_taihe("run_taihe") { "${mmi_path}/frameworks/ets/key_event:run_taihe", "${mmi_path}/frameworks/ets/input_device:run_taihe", "${mmi_path}/frameworks/ets/input_consumer:run_taihe", + "${mmi_path}/frameworks/ets/pointer:run_taihe", ":inputani_common_taihe" ] outputs = [ @@ -82,6 +84,8 @@ taihe_shared_library("inputani_common") { external_deps = [ "c_utils:utils", "hilog:libhilog", + "image_framework:image_taihe", + "image_framework:image_native", ] branch_protector_ret = "pac_ret" sanitize = { diff --git a/frameworks/ets/common/include/ani_common.h b/frameworks/ets/common/include/ani_common.h index b4e025c324..734a12c3d8 100644 --- a/frameworks/ets/common/include/ani_common.h +++ b/frameworks/ets/common/include/ani_common.h @@ -29,12 +29,15 @@ #include "ohos.multimodalInput.touchEvent.proj.hpp" #include "ohos.multimodalInput.shortKey.proj.hpp" #include "ohos.multimodalInput.keyEvent.proj.hpp" +#include "ohos.multimodalInput.pointer.proj.hpp" +#include "ohos.multimodalInput.pointer.impl.hpp" #include "taihe/runtime.hpp" #include "taihe/callback.hpp" #include "key_event.h" #include "pointer_event.h" #include "input_device.h" +#include "pointer_style.h" #include @@ -839,6 +842,8 @@ public: static TaiheAxisRange ConverterAxisRange(const InputDevice::AxisInfo &axisInfo, const std::string &sourceType, const std::string &axisType); static TaiheInputDeviceData ConverterInputDevice(std::shared_ptr &device); + static CustomCursor ConverterToCustomCursor(const ohos::multimodalInput::pointer::CustomCursor &value); + static CursorOptions ConverterToCursorConfig(const ohos::multimodalInput::pointer::CursorConfig &value); // ztw touchEvent 解析 static TaiheTouchEvent TouchEventToTaihe(const PointerEvent &pointerEvent); static TaiheInputEvent InputEventToTaihe(const InputEvent &inputEvent); diff --git a/frameworks/ets/common/src/ani_common.cpp b/frameworks/ets/common/src/ani_common.cpp index e11db49f56..58361d9a42 100644 --- a/frameworks/ets/common/src/ani_common.cpp +++ b/frameworks/ets/common/src/ani_common.cpp @@ -147,6 +147,40 @@ TaiheInputDeviceData TaiheConverter::ConverterInputDevice(std::shared_ptr(value.pixelMap); + ani_ref pixelMapAni; + if (ANI_OK != env->Object_GetPropertyByName_Ref(obj, "pixelMap", &pixelMapAni)) { + // MMI_HILOGE("AceDrag, get pixelMap failed."); + return cursor; + } + + auto pixelMap = OHOS::Media::PixelMapTaiheAni::GetNativePixelMap(taihe::get_env(), + reinterpret_cast(pixelMapAni)); + if (pixelMap == nullptr) { + // MMI_HILOGE("Get pixelMap failed"); + return cursor; + } + cursor.pixelMap = (void *)pixelMap.get(); + if (value.focusX.has_value()) { + cursor.focusX = static_cast (value.focusX.value()); + } + if (value.focusY.has_value()) { + cursor.focusY = static_cast (value.focusY.value()); + } + return cursor; +} + +CursorOptions TaiheConverter::ConverterToCursorConfig(const ohos::multimodalInput::pointer::CursorConfig &value) +{ + CursorOptions opts; + opts.followSystem = value.followSystem; + return opts; +} + TaiheTouchEvent TaiheConverter::TouchEventToTaihe(const PointerEvent &pointerEvent) { bool flag =true; diff --git a/frameworks/ets/input_device/BUILD.gn b/frameworks/ets/input_device/BUILD.gn index c6f7a1be96..4d0ba31904 100644 --- a/frameworks/ets/input_device/BUILD.gn +++ b/frameworks/ets/input_device/BUILD.gn @@ -15,6 +15,7 @@ import("//build/ohos/taihe_idl/taihe.gni") import("//foundation/multimodalinput/input/multimodalinput_mini.gni") copy_taihe_idl("input_device_taihe") { sources = [ "idl/ohos.multimodalInput.inputDevice.taihe" ] + deps = [ "${mmi_path}/frameworks/ets/pointer:pointer_taihe" ] } config("inputDevice_config") { visibility = [ ":*" ] diff --git a/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp b/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp index 8dbe44f7f7..fa37e9eb72 100644 --- a/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp +++ b/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp @@ -20,8 +20,8 @@ #include "input_device.h" #include "define_multimodal.h" #include "input_manager.h" -#include #include "ani_common.h" +#include #undef MMI_LOG_TAG #define MMI_LOG_TAG "TaiHeInputDeviceImpl" diff --git a/frameworks/ets/pointer/BUILD.gn b/frameworks/ets/pointer/BUILD.gn index 87c15aca82..a5711751b0 100644 --- a/frameworks/ets/pointer/BUILD.gn +++ b/frameworks/ets/pointer/BUILD.gn @@ -50,6 +50,8 @@ taihe_shared_library("Pointer") { external_deps = [ "c_utils:utils", "hilog:libhilog", + "image_framework:image_taihe", + "image_framework:image_native", ] sources += [ "src/ani_constructor.cpp", diff --git a/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp b/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp index 7c53ba6e70..a8cdf55aab 100644 --- a/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp +++ b/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp @@ -14,10 +14,12 @@ */ #include "ohos.multimodalInput.pointer.impl.h" +#include "mmi_log.h" #include "ani_common.h" #include "input_manager.h" #include "struct_multimodal.h" +#include "pixel_map_taihe_ani.h" #undef MMI_LOG_TAG #define MMI_LOG_TAG "ohos.multimodalInput.pointer" @@ -34,6 +36,9 @@ constexpr int32_t MIN_POINTER_SIZE { 1 }; constexpr int32_t MAX_POINTER_SIZE { 7 }; constexpr int32_t MIN_ROWS { 1 }; constexpr int32_t MAX_ROWS { 100 }; +constexpr int32_t INVALID_VALUE { -2 }; +constexpr int32_t MAX_PIXELMAP_SIZE { 256 }; + const static std::map POINTER_STYLE_TRANSFORMATION = { { DEFAULT_IMPL, TaihePointerStyle::key_t::DEFAULT }, { EAST_IMPL, TaihePointerStyle::key_t::EAST }, @@ -82,6 +87,25 @@ const static std::map POINTER_STYLE_TRANSFORMATION = { MIDDLE_BTN_EAST_WEST_IMPL, TaihePointerStyle::key_t::MIDDLE_BTN_EAST_WEST }, }; +bool CheckCustomCursor(OHOS::MMI::CustomCursor &cursor) +{ + if (cursor.pixelMap == nullptr) { + MMI_HILOGE("pxielMap is invalid"); + return false; + } + OHOS::Media::PixelMap* newPixelMap = static_cast(cursor.pixelMap); + if (newPixelMap->GetWidth() > MAX_PIXELMAP_SIZE || newPixelMap->GetHeight() > MAX_PIXELMAP_SIZE) { + return false; + } + if (cursor.focusX < 0 || cursor.focusX > newPixelMap->GetWidth()) { + return false; + } + if (cursor.focusY < 0 || cursor.focusY > newPixelMap->GetHeight()) { + return false; + } + return true; +} + TaihePointerStyle ConvertPointerStyle(int32_t pointerStyle) { auto iter = POINTER_STYLE_TRANSFORMATION.find(pointerStyle); @@ -228,23 +252,89 @@ void SetTouchpadDoubleTapAndDragStateAsync(bool isOpen) void SetCustomCursorSync(int32_t windowId, uintptr_t pixelMap, ::taihe::optional_view focusX, ::taihe::optional_view focusY) { CALL_DEBUG_ENTER; - if (windowId < 0) { + if (windowId == INVALID_VALUE) { MMI_HILOGE("Invalid windowsId"); taihe::set_business_error(COMMON_PARAMETER_ERROR, "windowId is invalid"); return; } - // ani_ref bufferRef; - // ani_env *env = get_env(); - // ani_object object = reinterpret_cast(pixelMap); - // ȡpixelMapϢ + ani_object object = reinterpret_cast(pixelMap); + auto newPixelMap = OHOS::Media::PixelMapTaiheAni::GetNativePixelMap(taihe::get_env(), object); + if (newPixelMap == nullptr) { + MMI_HILOGE("Get pixelMap failed"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "pixelMap is invalid"); + return; + } + CursorFocus cursorFocus; + cursorFocus.x = focusX.has_value() ? focusX.value() : 0; + cursorFocus.y = focusY.has_value() ? focusY.value() : 0; + if ((cursorFocus.x == INVALID_VALUE) || (cursorFocus.y == INVALID_VALUE)) { + MMI_HILOGE("focusX or focusY is invalid"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "focusX or focusY is invalid"); + return; + } + InputManager::GetInstance()->SetCustomCursor(windowId, + (void *)newPixelMap.get(), cursorFocus.x, cursorFocus.y); } -void SetCustomCursorPixelMapAsync(int32_t windowId, uintptr_t pixelMap, ::taihe::optional_view focusX, ::taihe::optional_view focusY) { - TH_THROW(std::runtime_error, "SetCustomCursorPixelMapAsync not implemented"); +void SetCustomCursorPixelMapAsync(int32_t windowId, uintptr_t pixelMap, ::taihe::optional_view focusX, ::taihe::optional_view focusY) +{ + CALL_DEBUG_ENTER; + if (windowId < 0) { + MMI_HILOGE("Invalid windowsId"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "windowId is invalid"); + return; + } + ani_object object = reinterpret_cast(pixelMap); + auto newPixelMap = OHOS::Media::PixelMapTaiheAni::GetNativePixelMap(taihe::get_env(), object); + if (newPixelMap == nullptr) { + MMI_HILOGE("Get pixelMap failed"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "pixelMap is invalid"); + return; + } + CursorFocus cursorFocus; + cursorFocus.x = focusX.has_value() ? focusX.value() : 0; + cursorFocus.y = focusY.has_value() ? focusY.value() : 0; + if ((cursorFocus.x == INVALID_VALUE) || (cursorFocus.y == INVALID_VALUE)) { + MMI_HILOGE("focusX or focusY is invalid"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "focusX or focusY is invalid"); + return; + } + auto errorCode = InputManager::GetInstance()->SetCustomCursor(windowId, + (void *)newPixelMap.get(), cursorFocus.x, cursorFocus.y); + if (errorCode == COMMON_USE_SYSAPI_ERROR) { + MMI_HILOGE("SetCustomCursor is failed"); + taihe::set_business_error(COMMON_USE_SYSAPI_ERROR, "Non system applications use system API"); + } } -void SetCustomCursorAsync(int32_t windowId, ::ohos::multimodalInput::pointer::CustomCursor const& cursor, ::ohos::multimodalInput::pointer::CursorConfig const& config) { - TH_THROW(std::runtime_error, "SetCustomCursorAsync not implemented"); +void SetCustomCursorAsync(int32_t windowId, ::ohos::multimodalInput::pointer::CustomCursor const& cursor, ::ohos::multimodalInput::pointer::CursorConfig const& config) +{ + CALL_DEBUG_ENTER; + if (windowId < 0) { + MMI_HILOGE("Invalid windowsId"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "windowId is invalid"); + return; + } + auto newCursor = TaiheConverter::ConverterToCustomCursor(cursor); + if (!CheckCustomCursor(newCursor)) { + MMI_HILOGE("cursor is invalid"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "cursor is invalid"); + return; + } + auto options = TaiheConverter::ConverterToCursorConfig(config); + auto errorCode = InputManager::GetInstance()->SetCustomCursor(windowId, newCursor, options); + if (errorCode != RET_OK) { + if (errorCode == RET_ERR) { + MMI_HILOGE("Other errors"); + return; + } + TaiheError codeMsg; + if (!TaiheConverter::GetApiError(errorCode, codeMsg)) { + MMI_HILOGE("Error code %{public}d not found", errorCode); + return; + } + taihe::set_business_error(errorCode, codeMsg.msg); + } } int32_t GetPointerSpeedSync() -- Gitee From 2cec43d980a1309cb5d5e8432c0502bc095266d9 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Tue, 29 Jul 2025 18:28:25 +0800 Subject: [PATCH 17/29] =?UTF-8?q?lmq=20=E8=A7=A3=E5=86=B3=E6=8A=A5?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- frameworks/ets/common/src/ani_common.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/ets/common/src/ani_common.cpp b/frameworks/ets/common/src/ani_common.cpp index 58361d9a42..ce14d3a2a6 100644 --- a/frameworks/ets/common/src/ani_common.cpp +++ b/frameworks/ets/common/src/ani_common.cpp @@ -16,6 +16,7 @@ #include "ani_common.h" #include "mmi_log.h" +#include "pixel_map_taihe_ani.h" #undef MMI_LOG_TAG #define MMI_LOG_TAG "aniCommon" @@ -154,14 +155,14 @@ CustomCursor TaiheConverter::ConverterToCustomCursor(const ohos::multimodalInput ani_object obj = reinterpret_cast(value.pixelMap); ani_ref pixelMapAni; if (ANI_OK != env->Object_GetPropertyByName_Ref(obj, "pixelMap", &pixelMapAni)) { - // MMI_HILOGE("AceDrag, get pixelMap failed."); + MMI_HILOGE("get pixelMap failed."); return cursor; } auto pixelMap = OHOS::Media::PixelMapTaiheAni::GetNativePixelMap(taihe::get_env(), reinterpret_cast(pixelMapAni)); if (pixelMap == nullptr) { - // MMI_HILOGE("Get pixelMap failed"); + MMI_HILOGE("pixelMap is null"); return cursor; } cursor.pixelMap = (void *)pixelMap.get(); @@ -183,7 +184,6 @@ CursorOptions TaiheConverter::ConverterToCursorConfig(const ohos::multimodalInpu TaiheTouchEvent TaiheConverter::TouchEventToTaihe(const PointerEvent &pointerEvent) { - bool flag =true; TaiheTouchEvent result {.action = TaiheTouchAction::key_t::CANCEL, .touch = TaiheTouch {.toolType = TaiheToolType::key_t::FINGER}, .sourceType = TaiheSourceType::key_t::TOUCH_SCREEN, -- Gitee From 86f61644af81962bb4a7ebd5fe56c02dde1cd47e Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Wed, 30 Jul 2025 11:15:13 +0800 Subject: [PATCH 18/29] =?UTF-8?q?lmq=20=E4=BF=AE=E6=94=B9=E6=8A=A5?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- frameworks/ets/common/BUILD.gn | 4 ++-- frameworks/ets/input_consumer/BUILD.gn | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/frameworks/ets/common/BUILD.gn b/frameworks/ets/common/BUILD.gn index 5019653e0a..9dec947b3d 100644 --- a/frameworks/ets/common/BUILD.gn +++ b/frameworks/ets/common/BUILD.gn @@ -18,6 +18,7 @@ import("//foundation/multimodalinput/input/multimodalinput_mini.gni") copy_taihe_idl("inputani_common_taihe") { sources = [ "idl/ohos.multimodalInput.inputCommon.taihe" ] deps = [ + "${mmi_path}/frameworks/ets/pointer:pointer_taihe", "${mmi_path}/frameworks/ets/mouse_event:mouse_event_taihe", "${mmi_path}/frameworks/ets/touch_event:touch_event_taihe", "${mmi_path}/frameworks/ets/short_key:short_key_taihe", @@ -27,7 +28,6 @@ copy_taihe_idl("inputani_common_taihe") { "${mmi_path}/frameworks/ets/key_event:key_event_taihe", "${mmi_path}/frameworks/ets/input_device:input_device_taihe", "${mmi_path}/frameworks/ets/input_consumer:input_consumer_taihe", - "${mmi_path}/frameworks/ets/pointer:pointer_taihe", ] } config("inputani_common_config") { @@ -46,6 +46,7 @@ taihe_generated_file_path_inputCommon = "$taihe_file_path/out/$subsystem_name/$p ohos_taihe("run_taihe") { taihe_generated_file_path = "${taihe_generated_file_path_inputCommon}" deps = [ + "${mmi_path}/frameworks/ets/pointer:run_taihe", "${mmi_path}/frameworks/ets/mouse_event:run_taihe", "${mmi_path}/frameworks/ets/touch_event:run_taihe", "${mmi_path}/frameworks/ets/short_key:run_taihe", @@ -55,7 +56,6 @@ ohos_taihe("run_taihe") { "${mmi_path}/frameworks/ets/key_event:run_taihe", "${mmi_path}/frameworks/ets/input_device:run_taihe", "${mmi_path}/frameworks/ets/input_consumer:run_taihe", - "${mmi_path}/frameworks/ets/pointer:run_taihe", ":inputani_common_taihe" ] outputs = [ diff --git a/frameworks/ets/input_consumer/BUILD.gn b/frameworks/ets/input_consumer/BUILD.gn index 4800ccf02f..4620959994 100644 --- a/frameworks/ets/input_consumer/BUILD.gn +++ b/frameworks/ets/input_consumer/BUILD.gn @@ -17,7 +17,10 @@ import("//build/ohos/taihe_idl/taihe.gni") import("//foundation/multimodalinput/input/multimodalinput_mini.gni") copy_taihe_idl("input_consumer_taihe") { sources = [ "idl/ohos.multimodalInput.inputConsumer.taihe" ] - deps = [ "${mmi_path}/frameworks/ets/key_event:key_event_taihe" ] + deps = [ + "${mmi_path}/frameworks/ets/key_event:key_event_taihe", + #"${mmi_path}/frameworks/ets/pointer:pointer_taihe" + ] } config("inputConsumer_config") { visibility = [ ":*" ] -- Gitee From 0f94ecfc0ed4ed27f9581d5b7b9a00978e1a3ac0 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Wed, 30 Jul 2025 15:01:07 +0800 Subject: [PATCH 19/29] =?UTF-8?q?lmq=20inputdevice=E5=A2=9E=E5=8A=A0log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- frameworks/ets/common/BUILD.gn | 6 +- frameworks/ets/common/include/ani_common.h | 2 +- frameworks/ets/input_consumer/BUILD.gn | 5 +- frameworks/ets/input_device/BUILD.gn | 2 +- .../ohos.multimodalInput.inputDevice.impl.cpp | 191 ++---------------- 5 files changed, 19 insertions(+), 187 deletions(-) diff --git a/frameworks/ets/common/BUILD.gn b/frameworks/ets/common/BUILD.gn index 9dec947b3d..78761f5435 100644 --- a/frameworks/ets/common/BUILD.gn +++ b/frameworks/ets/common/BUILD.gn @@ -18,7 +18,6 @@ import("//foundation/multimodalinput/input/multimodalinput_mini.gni") copy_taihe_idl("inputani_common_taihe") { sources = [ "idl/ohos.multimodalInput.inputCommon.taihe" ] deps = [ - "${mmi_path}/frameworks/ets/pointer:pointer_taihe", "${mmi_path}/frameworks/ets/mouse_event:mouse_event_taihe", "${mmi_path}/frameworks/ets/touch_event:touch_event_taihe", "${mmi_path}/frameworks/ets/short_key:short_key_taihe", @@ -27,7 +26,7 @@ copy_taihe_idl("inputani_common_taihe") { "${mmi_path}/frameworks/ets/gesture_event:gesture_event_taihe", "${mmi_path}/frameworks/ets/key_event:key_event_taihe", "${mmi_path}/frameworks/ets/input_device:input_device_taihe", - "${mmi_path}/frameworks/ets/input_consumer:input_consumer_taihe", + "${mmi_path}/frameworks/ets/pointer:pointer_taihe", ] } config("inputani_common_config") { @@ -46,7 +45,6 @@ taihe_generated_file_path_inputCommon = "$taihe_file_path/out/$subsystem_name/$p ohos_taihe("run_taihe") { taihe_generated_file_path = "${taihe_generated_file_path_inputCommon}" deps = [ - "${mmi_path}/frameworks/ets/pointer:run_taihe", "${mmi_path}/frameworks/ets/mouse_event:run_taihe", "${mmi_path}/frameworks/ets/touch_event:run_taihe", "${mmi_path}/frameworks/ets/short_key:run_taihe", @@ -55,7 +53,7 @@ ohos_taihe("run_taihe") { "${mmi_path}/frameworks/ets/gesture_event:run_taihe", "${mmi_path}/frameworks/ets/key_event:run_taihe", "${mmi_path}/frameworks/ets/input_device:run_taihe", - "${mmi_path}/frameworks/ets/input_consumer:run_taihe", + "${mmi_path}/frameworks/ets/pointer:run_taihe", ":inputani_common_taihe" ] outputs = [ diff --git a/frameworks/ets/common/include/ani_common.h b/frameworks/ets/common/include/ani_common.h index 734a12c3d8..7a02d717af 100644 --- a/frameworks/ets/common/include/ani_common.h +++ b/frameworks/ets/common/include/ani_common.h @@ -21,7 +21,6 @@ #include "securec.h" -#include "ohos.multimodalInput.inputDevice.proj.hpp" #include "ohos.multimodalInput.keyCode.proj.hpp" #include "ohos.multimodalInput.keyCode.impl.hpp" #include "ohos.multimodalInput.mouseEvent.proj.hpp" @@ -29,6 +28,7 @@ #include "ohos.multimodalInput.touchEvent.proj.hpp" #include "ohos.multimodalInput.shortKey.proj.hpp" #include "ohos.multimodalInput.keyEvent.proj.hpp" +#include "ohos.multimodalInput.inputDevice.proj.hpp" #include "ohos.multimodalInput.pointer.proj.hpp" #include "ohos.multimodalInput.pointer.impl.hpp" #include "taihe/runtime.hpp" diff --git a/frameworks/ets/input_consumer/BUILD.gn b/frameworks/ets/input_consumer/BUILD.gn index 4620959994..4800ccf02f 100644 --- a/frameworks/ets/input_consumer/BUILD.gn +++ b/frameworks/ets/input_consumer/BUILD.gn @@ -17,10 +17,7 @@ import("//build/ohos/taihe_idl/taihe.gni") import("//foundation/multimodalinput/input/multimodalinput_mini.gni") copy_taihe_idl("input_consumer_taihe") { sources = [ "idl/ohos.multimodalInput.inputConsumer.taihe" ] - deps = [ - "${mmi_path}/frameworks/ets/key_event:key_event_taihe", - #"${mmi_path}/frameworks/ets/pointer:pointer_taihe" - ] + deps = [ "${mmi_path}/frameworks/ets/key_event:key_event_taihe" ] } config("inputConsumer_config") { visibility = [ ":*" ] diff --git a/frameworks/ets/input_device/BUILD.gn b/frameworks/ets/input_device/BUILD.gn index 4d0ba31904..84400c63e8 100644 --- a/frameworks/ets/input_device/BUILD.gn +++ b/frameworks/ets/input_device/BUILD.gn @@ -15,7 +15,7 @@ import("//build/ohos/taihe_idl/taihe.gni") import("//foundation/multimodalinput/input/multimodalinput_mini.gni") copy_taihe_idl("input_device_taihe") { sources = [ "idl/ohos.multimodalInput.inputDevice.taihe" ] - deps = [ "${mmi_path}/frameworks/ets/pointer:pointer_taihe" ] + deps = [ "${mmi_path}/frameworks/ets/key_code:key_code_taihe" ] } config("inputDevice_config") { visibility = [ ":*" ] diff --git a/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp b/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp index fa37e9eb72..687140246a 100644 --- a/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp +++ b/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp @@ -31,7 +31,6 @@ using namespace OHOS::MMI; using namespace ohos::multimodalInput::inputDevice; using TaiheKeyCode = ohos::multimodalInput::keyCode::KeyCode; using TaiheFunctionKey = ohos::multimodalInput::inputDevice::FunctionKey; -// using TaiheDeviceListener = ohos::multimodalInput::inputDevice::DeviceListener; on/off use using InputDevice_t = OHOS::MMI::InputDevice; using AxisInfo_t = OHOS::MMI::InputDevice::AxisInfo; using TaiheError_t = OHOS::MMI::TaiheError; @@ -45,79 +44,9 @@ constexpr int32_t MAX_KEY_REPEAT_DELAY { 1000 }; constexpr int32_t MIN_KEY_REPEAT_RATE { 36 }; constexpr int32_t MAX_KEY_REPEAT_RATE { 100 }; -// lmq on/off use -/* -enum INPUT_DEVICE_CALLBACK_EVENT { - CALLBACK_EVENT_FAILED = -1, - CALLBACK_EVENT_SUCCESS = 1, - CALLBACK_EVENT_EXIST = 2, - CALLBACK_EVENT_NOT_EXIST = 3, -}; - -using callbackType = std::variant>; - -struct CallbackObject { - CallbackObject(callbackType cb, ani_ref ref) : callback(cb), ref(ref) - { - } - void Release() - { - taihe::env_guard guard; - if (auto *env = guard.get_env()) { - env->GlobalReference_Delete(ref); - } - } - callbackType callback; - ani_ref ref; -}; - -std::map>> changeCbMap_; -std::mutex g_mutex; -size_t g_baseId { 0 }; -std::mutex cbMapMutex; -bool isListeningProcess_ { false }; - -class GlobalRefGuard { - ani_env *env_ = nullptr; - ani_ref ref_ = nullptr; - -public: - GlobalRefGuard(ani_env *env, ani_object obj) : env_(env) - { - if (!env_) { - return; - } - if (ANI_OK != env_->GlobalReference_Create(obj, &ref_)) { - ref_ = nullptr; - } - } - explicit operator bool() const - { - return ref_ != nullptr; - } - ani_ref get() const - { - return ref_; - } - ~GlobalRefGuard() - { - if (env_ && ref_) { - env_->GlobalReference_Delete(ref_); - } - } - - GlobalRefGuard(const GlobalRefGuard &) = delete; - GlobalRefGuard &operator=(const GlobalRefGuard &) = delete; -}; - -size_t GenerateId() -{ - return g_baseId++; -} -*/ - int32_t GetDeviceIdsAsync() { + CALL_DEBUG_ENTER; std::vector _ids; auto callback = [&_ids] (std::vector& ids) { _ids = ids; }; int32_t ret = InputManager_t::GetInstance()->GetDeviceIds(callback); @@ -135,6 +64,7 @@ int32_t GetDeviceIdsAsync() InputDeviceData GetDeviceAsync(int32_t deviceId) { + CALL_DEBUG_ENTER; std::shared_ptr _device = std::make_shared(); auto callback = [&_device] (std::shared_ptr device) { _device = device; }; int32_t ret = InputManager_t::GetInstance()->GetDevice(deviceId, callback); @@ -153,6 +83,7 @@ InputDeviceData GetDeviceAsync(int32_t deviceId) InputDeviceData GetDeviceInfoAsync(int32_t deviceId) { + CALL_DEBUG_ENTER; std::shared_ptr _device = std::make_shared(); auto callback = [&_device] (std::shared_ptr device) { _device = device; }; int32_t ret = InputManager_t::GetInstance()->GetDevice(deviceId, callback); @@ -171,6 +102,7 @@ InputDeviceData GetDeviceInfoAsync(int32_t deviceId) ::taihe::array SupportKeysAsync(int32_t deviceId, taihe::array_view keys) { + CALL_DEBUG_ENTER; uint32_t size = keys.size(); if (size < MIN_N_SIZE || size > MAX_N_SIZE) { TaiheError_t codeMsg; @@ -210,6 +142,7 @@ InputDeviceData GetDeviceInfoAsync(int32_t deviceId) void SetKeyboardRepeatDelayAsync(int32_t delay) { + CALL_DEBUG_ENTER; if (delay < MIN_KEY_REPEAT_DELAY) { delay = MIN_KEY_REPEAT_DELAY; } else if (delay > MAX_KEY_REPEAT_DELAY) { @@ -229,6 +162,7 @@ void SetKeyboardRepeatDelayAsync(int32_t delay) int32_t GetKeyboardRepeatDelayAsync() { + CALL_DEBUG_ENTER; int32_t _delay = -1; auto callback = [&_delay] (int32_t delay) { _delay = delay; }; int32_t ret = InputManager_t::GetInstance()->GetKeyboardRepeatDelay(callback); @@ -246,6 +180,7 @@ int32_t GetKeyboardRepeatDelayAsync() void SetKeyboardRepeatRateAsync(int32_t rate) { + CALL_DEBUG_ENTER; if (rate < MIN_KEY_REPEAT_RATE) { rate = MIN_KEY_REPEAT_RATE; } else if (rate > MAX_KEY_REPEAT_RATE) { @@ -264,6 +199,7 @@ void SetKeyboardRepeatRateAsync(int32_t rate) int32_t GetKeyboardRepeatRateAsync() { + CALL_DEBUG_ENTER; int32_t _rate = -1; auto callback = [&_rate] (int32_t rate) { _rate = rate; }; int32_t ret = InputManager_t::GetInstance()->GetKeyboardRepeatRate(callback); @@ -280,6 +216,7 @@ int32_t GetKeyboardRepeatRateAsync() int64_t GetIntervalSinceLastInputAsync() { + CALL_DEBUG_ENTER; int64_t timeInterval = 0; int32_t ret = InputManager_t::GetInstance()->GetIntervalSinceLastInput(timeInterval); if (ret != RET_OK) { @@ -295,6 +232,7 @@ int64_t GetIntervalSinceLastInputAsync() void SetFunctionKeyEnabledAsync(TaiheFunctionKey functionKey, bool enabled) { + CALL_DEBUG_ENTER; if (functionKey != OHOS::MMI::FunctionKey::FUNCTION_KEY_CAPSLOCK) { TaiheError_t codeMsg; if (!TaiheConverter::GetApiError(COMMON_PARAMETER_ERROR, codeMsg)) { @@ -317,6 +255,7 @@ void SetFunctionKeyEnabledAsync(TaiheFunctionKey functionKey, bool enabled) void SetInputDeviceEnabledAsync(int32_t deviceId, bool enabled) { + CALL_DEBUG_ENTER; if (deviceId < 0) { TaiheError_t codeMsg; if (!TaiheConverter::GetApiError(COMMON_PARAMETER_ERROR, codeMsg)) { @@ -340,6 +279,7 @@ void SetInputDeviceEnabledAsync(int32_t deviceId, bool enabled) ::ohos::multimodalInput::inputDevice::KeyboardType GetKeyboardTypeSync(int32_t deviceId) { + CALL_DEBUG_ENTER; int32_t type = 0; auto callback = [&type] (int32_t keyboardType) { type = keyboardType; }; int32_t ret = InputManager_t::GetInstance()->GetKeyboardType(deviceId, callback); @@ -358,6 +298,7 @@ void SetInputDeviceEnabledAsync(int32_t deviceId, bool enabled) ::taihe::array SupportKeysSync(int32_t deviceId, taihe::array_view keys) { + CALL_DEBUG_ENTER; uint32_t size = keys.size(); if (size < MIN_N_SIZE || size > MAX_N_SIZE) { TaiheError_t codeMsg; @@ -394,6 +335,7 @@ void SetInputDeviceEnabledAsync(int32_t deviceId, bool enabled) InputDeviceData GetDeviceInfoSync(int32_t deviceId) { + CALL_DEBUG_ENTER; std::shared_ptr _device = std::make_shared(); auto callback = [&_device] (std::shared_ptr device) { _device = device; }; int32_t ret = InputManager_t::GetInstance()->GetDevice(deviceId, callback); @@ -409,111 +351,6 @@ InputDeviceData GetDeviceInfoSync(int32_t deviceId) } return TaiheConverter::ConverterInputDevice(_device); } - -// on/off -/* -int32_t RegisterListener(std::string const &type, callbackType &&cb, uintptr_t opq) -{ - std::lock_guard lock(cbMapMutex); - ani_object callbackObj = reinterpret_cast(opq); - ani_ref callbackRef; - ani_env *env = taihe::get_env(); - if (env == nullptr || ANI_OK != env->GlobalReference_Create(callbackObj, &callbackRef)) { - MMI_HILOGE("ani_env is nullptr or GlobalReference_Create failed"); - return CALLBACK_EVENT_FAILED; - } - auto &cbVec = changeCbMap_[type]; - bool isDuplicate = std::any_of(cbVec.begin(), cbVec.end(), - [env, callbackRef](std::shared_ptr &obj) { - ani_boolean isEqual = false; - return (ANI_OK == env->Reference_StrictEquals(callbackRef, obj->ref, &isEqual)) && isEqual; - }); - if (isDuplicate) { - env->GlobalReference_Delete(callbackRef); - MMI_HILOGD("callback already registered"); - return CALLBACK_EVENT_EXIST; - } - cbVec.emplace_back(std::make_shared(cb, callbackRef)); - MMI_HILOGI("register callback success, type: %{public}s", type.c_str()); - return CALLBACK_EVENT_SUCCESS; -} - -void onKey(callbackType &&f, uintptr_t opq) -{ - std::lock_guard guard(g_mutex); - bool isListening { false }; - auto keyMonitorId = GenerateId(); - auto result = RegisterListener(std::to_string(keyMonitorId), f, opq); - if (result == CALLBACK_EVENT_FAILED) { - MMI_HILOGE("Register listener failed"); - return; - } - if (result == CALLBACK_EVENT_EXIST) { - MMI_HILOGE("Callback already exist"); - return; - } - auto &cbVec = changeCbMap_[std::to_string(keyMonitorId)]; - std::shared_ptr listener = - for (auto &cb : cbVec) { - - } - if (!isListening) { - auto ret = InputManager_t::GetInstance()->RegisterDevListener("change", ); - if (ret != RET_OK) { - MMI_HILOGE("RegisterDevListener fail, error:%{public}d", ret); - } else { - std::lock_guard guard(g_mutex); - isListeningProcess_ = true; - } - } -} - -void offKey(taihe::optional_view opq) -{ - std::lock_guard lock(mutex_); - const auto iter = changeCbMap_.find(CHANGED_TYPE); - if (iter == changeCbMap_.end()) { - MMI_HILOGE("change is not registered"); - return; - } - if (!opq.has_value()) { - iter->second.clear(); - goto monitorLabel; - } - ani_env *env = taihe::get_env(); - if (env == nullptr) { - MMI_HILOGE("Failed to unregister change, env is nullptr"); - return; - } - GlobalRefGuard guard(env, reinterpret_cast(opq.value())); - if (!guard) { - MMI_HILOGE("Failed to unregister change, GlobalRefGuard is false!"); - return; - } - - const auto pred = [env, targetRef = guard.get()](std::unique_ptr &obj) { - ani_boolean is_equal = false; - return (ANI_OK == env->Reference_StrictEquals(targetRef, obj->ref, &is_equal)) && is_equal; - }; - auto &callbacks = iter->second; - const auto it = std::find_if(callbacks.begin(), callbacks.end(), pred); - if (it != callbacks.end()) { - callbacks.erase(it); - } - - monitorLabel: - if (isListeningProcess_ && iter->second.empty()) { - needStopListening = true; - isListeningProcess_ = false; - } - if (needStopListening) { - auto ret = InputManager_t::GetInstance()->UnregisterDevListener("change", shared_from_this()); - if (ret != RET_OK) { - MMI_HILOGE("UnregisterDevListener fail, error:%{public}d", ret); - } - } -} -*/ } // namespace // Since these macros are auto-generate, lint will cause false positive. -- Gitee From f04cde16f89c4e70ed4376e101f62282b1b88076 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Wed, 30 Jul 2025 15:45:18 +0800 Subject: [PATCH 20/29] ani_common Signed-off-by: qianyong325 --- frameworks/ets/common/include/ani_common.h | 32 +++- frameworks/ets/common/src/ani_common.cpp | 182 +++++++++++++++++++++ 2 files changed, 213 insertions(+), 1 deletion(-) diff --git a/frameworks/ets/common/include/ani_common.h b/frameworks/ets/common/include/ani_common.h index 734a12c3d8..61e9eee8f7 100644 --- a/frameworks/ets/common/include/ani_common.h +++ b/frameworks/ets/common/include/ani_common.h @@ -43,6 +43,11 @@ namespace OHOS { namespace MMI { +using MapFun = std::map>; + +constexpr int32_t AXIS_TYPE_SCROLL_VERTICAL { 0 }; +constexpr int32_t AXIS_TYPE_SCROLL_HORIZONTAL { 1 }; +constexpr int32_t AXIS_TYPE_PINCH { 2 }; constexpr uint32_t EVDEV_TAG_KEYBOARD = (1 << 1); constexpr uint32_t EVDEV_TAG_MOUSE = (1 << 2); constexpr uint32_t EVDEV_TAG_TOUCHPAD = (1 << 3); @@ -51,6 +56,12 @@ constexpr uint32_t EVDEV_TAG_JOYSTICK = (1 << 6); constexpr uint32_t EVDEV_TAG_TRACKBALL = (1 << 10); using namespace ohos::multimodalInput::keyCode; +using TaiheAxisValue = ::ohos::multimodalInput::mouseEvent::AxisValue; +using TaiheAxis = ::ohos::multimodalInput::mouseEvent::Axis; +using TaiheInputEvent = ohos::multimodalInput::inputEvent::InputEvent; +using TaiheMouseToolType = ohos::multimodalInput::mouseEvent::ToolType; +using TaiheMouseButton = ::ohos::multimodalInput::mouseEvent::Button; +using TaiheKeyCode = ::ohos::multimodalInput::keyCode::KeyCode; using TaihesType = ohos::multimodalInput::inputDevice::sourceType; using TaiheaType = ohos::multimodalInput::inputDevice::axisType; using TaiheSType = ohos::multimodalInput::inputDevice::SourceType; @@ -62,6 +73,7 @@ using TaiheTouchEvent = ohos::multimodalInput::touchEvent::TouchEvent; using TaiheTouchEventArray = taihe::array; using TaiheTouch = ohos::multimodalInput::touchEvent::Touch; using TaiheTouchAction = ohos::multimodalInput::touchEvent::Action; +using TaiheMouseAction = ohos::multimodalInput::mouseEvent::Action; using TaiheInputEvent = ohos::multimodalInput::inputEvent::InputEvent; using TaiheSourceType = ohos::multimodalInput::touchEvent::SourceType; using TaiheFixedMode = ohos::multimodalInput::touchEvent::FixedMode; @@ -105,6 +117,17 @@ enum TaiheErrorCode : int32_t { ERROR_WINDOW_ID_PERMISSION_DENIED = 26500001, }; +enum TH_MOUSE_BUTTON { + JS_MOUSE_BUTTON_LEFT = 0, + JS_MOUSE_BUTTON_MIDDLE = 1, + JS_MOUSE_BUTTON_RIGHT = 2, + JS_MOUSE_BUTTON_SIDE = 3, + JS_MOUSE_BUTTON_EXTRA = 4, + JS_MOUSE_BUTTON_FORWARD = 5, + JS_MOUSE_BUTTON_BACK = 6, + JS_MOUSE_BUTTON_TASK = 7 +}; + const std::map TAIHE_ERRORS = { { COMMON_PERMISSION_CHECK_ERROR, { COMMON_PERMISSION_CHECK_ERROR, "Permission denied. An attempt was made to %s forbidden by permission:%s." } }, @@ -831,7 +854,7 @@ extern DeviceType g_taiheDeviceType[]; extern std::unordered_map g_taiheAxisType; class TaiheConverter { -public: +public: static bool GetApiError(int32_t code, TaiheError &codeMsg); static KeyCode ConvertEtsKeyCode(int32_t keyCode); static KeyCodeEts GetKeyCodeByValue(const std::map& map, KeyCode code); @@ -878,6 +901,13 @@ public: TaiheKeyEventAction KeyEventActionToTaihe(int32_t action); TaiheKeyEvent TaiheKeyEventToTaihe(const KeyEvent &keyEvent); TaiheKeyEventKey TaiheKeyEventKeyToTaihe(const KeyEvent::KeyItem &keyItem); + static TaiheMouseEvent MouseEventToTaihe(std::shared_ptr pointerEvent); + static TaiheMouseAction MouseActionToTaihe(int32_t action); +private: + static bool GetMousePointerItem(std::shared_ptr pointerEvent, TaiheMouseEvent &mouseEvent); + static bool SetMouseProperty(std::shared_ptr& pointerEvent, const PointerEvent::PointerItem& item, TaiheMouseEvent &mouseEvent); + static bool GetAxesValue(const std::shared_ptr pointerEvent, TaiheAxisValue& value); + static bool GetPressedKey(const std::vector& pressedKeys, TaiheMouseEvent &mouseEvent); }; diff --git a/frameworks/ets/common/src/ani_common.cpp b/frameworks/ets/common/src/ani_common.cpp index ce14d3a2a6..d18f84e52b 100644 --- a/frameworks/ets/common/src/ani_common.cpp +++ b/frameworks/ets/common/src/ani_common.cpp @@ -639,5 +639,187 @@ TaiheKeyEventKey TaiheConverter::TaiheKeyEventKeyToTaihe(const KeyEvent::KeyItem obj.deviceId = keyItem.GetDeviceId(); return obj; } + +bool TaiheConverter::SetMouseProperty(std::shared_ptr& pointerEvent, const PointerEvent::PointerItem& item, TaiheMouseEvent &mouseEvent) +{ + bool result = true; + int32_t buttonId = pointerEvent->GetButtonId(); + if (buttonId == PointerEvent::MOUSE_BUTTON_MIDDLE) { + buttonId = TH_MOUSE_BUTTON::JS_MOUSE_BUTTON_MIDDLE; + } else if (buttonId == PointerEvent::MOUSE_BUTTON_RIGHT) { + buttonId = TH_MOUSE_BUTTON::JS_MOUSE_BUTTON_RIGHT; + } + + mouseEvent.button = TaiheMouseButton::key_t(buttonId); + mouseEvent.base.actionTime = pointerEvent->GetActionTime(); + mouseEvent.base.deviceId = item.GetDeviceId(); + mouseEvent.base.screenId = pointerEvent->GetTargetDisplayId(); + mouseEvent.base.windowId = pointerEvent->GetTargetWindowId(); + mouseEvent.base.deviceId = item.GetDeviceId(); + mouseEvent.windowX = item.GetWindowX(); + mouseEvent.windowY = item.GetWindowY(); + // mouseEvent.globalX = optional<>(std::in_place, static_cast(item.GetGlobalX())); + // mouseEvent.globalY = optional<>(std::in_place, static_cast(item.GetGlobalY())); + + return result; +} + +// MapFun TaiheConverter::GetFuns(const std::shared_ptr pointerEvent, const PointerEvent::PointerItem& item) +// { +// MapFun mapFun; +// mapFun["actionTime"] = [pointerEvent] { return pointerEvent->GetActionTime(); }; +// mapFun["screenId"] = [pointerEvent] { return pointerEvent->GetTargetDisplayId(); }; +// mapFun["windowId"] = [pointerEvent] { return pointerEvent->GetTargetWindowId(); }; +// mapFun["deviceId"] = [item] { return item.GetDeviceId(); }; +// mapFun["windowX"] = [item] { return item.GetWindowX(); }; +// mapFun["windowY"] = [item] { return item.GetWindowY(); }; +// mapFun["screenX"] = [item] { return item.GetDisplayX(); }; +// mapFun["screenY"] = [item] { return item.GetDisplayY(); }; +// mapFun["globalX"] = [item] { return static_cast(item.GetGlobalX()); }; +// mapFun["globalY"] = [item] { return static_cast(item.GetGlobalY()); }; +// mapFun["rawDeltaX"] = [item] { return item.GetRawDx(); }; +// mapFun["rawDeltaY"] = [item] { return item.GetRawDy(); }; +// return mapFun; +// } + +bool TaiheConverter::GetAxesValue(const std::shared_ptr pointerEvent, TaiheAxisValue& value) +{ + double axisValue = -1.0; + int32_t axis = -1; + if (pointerEvent->HasAxis(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL)) { + axisValue = pointerEvent->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL); + axis = AXIS_TYPE_SCROLL_VERTICAL; + } + if (pointerEvent->HasAxis(PointerEvent::AXIS_TYPE_SCROLL_HORIZONTAL)) { + axisValue = pointerEvent->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_HORIZONTAL); + axis = AXIS_TYPE_SCROLL_HORIZONTAL; + } + if (pointerEvent->HasAxis(PointerEvent::AXIS_TYPE_PINCH)) { + axisValue = pointerEvent->GetAxisValue(PointerEvent::AXIS_TYPE_PINCH); + axis = AXIS_TYPE_PINCH; + } + + value.axis = TaiheAxis::key_t(axis) ; + value.value = axisValue; + + return true; +} + +bool TaiheConverter::GetMousePointerItem(std::shared_ptr pointerEvent, TaiheMouseEvent &mouseEvent) +{ + bool result = true; + int32_t currentPointerId = pointerEvent->GetPointerId(); + std::vector axisValueVec; + std::vector pointerIds { pointerEvent->GetPointerIds() }; + for (const auto& pointerId : pointerIds) { + if (pointerId == currentPointerId) { + PointerEvent::PointerItem item; + if (!pointerEvent->GetPointerItem(pointerId, item)) { + MMI_HILOGE("Invalid pointer:%{public}d", pointerId); + return false; + } + mouseEvent.base.id = currentPointerId; + SetMouseProperty(pointerEvent, item, mouseEvent); + } + + TaiheAxisValue value = {.axis = TaiheAxis::key_t(0), .value = 0}; + GetAxesValue(pointerEvent, value); + axisValueVec.push_back(value); + } + + mouseEvent.axes = taihe::array(axisValueVec); + return result; +} + +bool TaiheConverter::GetPressedKey(const std::vector& pressedKeys, TaiheMouseEvent &mouseEvent) +{ + bool result = true; + bool isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_LEFT) + || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_RIGHT); + mouseEvent.ctrlKey = isExists; + + isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_ALT_LEFT) + || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_ALT_RIGHT); + mouseEvent.altKey = isExists; + + isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_SHIFT_LEFT) + || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_SHIFT_RIGHT); + mouseEvent.shiftKey = isExists; + + isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_META_LEFT) + || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_META_RIGHT); + mouseEvent.logoKey = isExists; + + isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_FN); + mouseEvent.fnKey = isExists; + + return result; +} + +// bool TaiheConverter::GetPressedButtons(std::shared_ptr pointerEvent, TaiheMouseEvent &mouseEvent) +// { + +// } + +TaiheMouseAction TaiheConverter::MouseActionToTaihe(int32_t action) { + switch (action) { + case PointerEvent::POINTER_ACTION_CANCEL: { + return TaiheMouseAction::key_t::CANCEL; + } + case PointerEvent::POINTER_ACTION_DOWN: { + return TaiheMouseAction::key_t::ACTION_DOWN; + } + case PointerEvent::POINTER_ACTION_MOVE: { + return TaiheMouseAction::key_t::MOVE; + } + case PointerEvent::POINTER_ACTION_UP: { + return TaiheMouseAction::key_t::ACTION_UP; + } + // ztw 代码中没有定义 + // case PointerEvent::POINTER_ACTION_PULL_DOWN: { + // return TaiheTouchAction::key_t::PULL_DOWN; + // } + // case PointerEvent::POINTER_ACTION_PULL_MOVE: { + // return TaiheTouchAction::key_t::PULL_MOVE; + // } + // case PointerEvent::POINTER_ACTION_PULL_UP: { + // return TaiheTouchAction::key_t::PULL_UP; + // } + default: { + return TaiheMouseAction(TaiheMouseAction::key_t::CANCEL); + } + } +} + +TaiheMouseEvent TaiheConverter::MouseEventToTaihe(std::shared_ptr pointerEvent) +{ + TaiheMouseEvent result {.action = TaiheMouseAction::key_t::CANCEL, + .button = TaiheMouseButton::key_t::LEFT, + .toolType = TaiheMouseToolType::key_t::UNKNOWN, + }; + + result.action = MouseActionToTaihe(pointerEvent->GetPointerAction()); + // 这个需要更新新代码 ---touchEvent taihe定义 + // result.isInject = pointerEventItem->HasFlag(InputEvent::EVENT_FLAG_SIMULATE); + std::vector pressedKeys = pointerEvent->GetPressedKeys(); + std::vector pressedKeysVec; + for(auto& value: pressedKeys) { + TaiheKeyCode code = TaiheKeyCode::key_t(value); + pressedKeysVec.push_back(code); + } + result.pressedKeys = taihe::array(pressedKeysVec); + + GetPressedKey(pressedKeys, result); + GetMousePointerItem(pointerEvent, result); + std::set pressedButtons = pointerEvent->GetPressedButtons(); + std::vector pressedButtonsVec; + for(auto& value : pressedButtons) { + pressedButtonsVec.push_back(TaiheMouseButton::key_t(value)); + } + + result.pressedButtons = taihe::array(pressedButtonsVec); + return result; +} + } // namespace MMI } // namespace OHOS \ No newline at end of file -- Gitee From 603603322225d4eb137a7c0954ea9c41058e1f4c Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Wed, 30 Jul 2025 16:47:10 +0800 Subject: [PATCH 21/29] =?UTF-8?q?lmq=20inputdevice=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- .../idl/ohos.multimodalInput.inputDevice.taihe | 2 +- .../src/ohos.multimodalInput.inputDevice.impl.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe b/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe index 4fd4d90cc4..9d207f6ee2 100644 --- a/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe +++ b/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe @@ -99,7 +99,7 @@ struct InputDeviceData { @gen_async("getDeviceIds") @gen_promise("getDeviceIds") -function GetDeviceIdsAsync(): i32; +function GetDeviceIdsAsync(): Array; @gen_async("getDevice") @gen_promise("getDevice") diff --git a/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp b/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp index 687140246a..b177f7899a 100644 --- a/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp +++ b/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp @@ -44,7 +44,7 @@ constexpr int32_t MAX_KEY_REPEAT_DELAY { 1000 }; constexpr int32_t MIN_KEY_REPEAT_RATE { 36 }; constexpr int32_t MAX_KEY_REPEAT_RATE { 100 }; -int32_t GetDeviceIdsAsync() +::taihe::array GetDeviceIdsAsync() { CALL_DEBUG_ENTER; std::vector _ids; @@ -57,9 +57,14 @@ int32_t GetDeviceIdsAsync() } taihe::set_business_error(ret, codeMsg.msg); MMI_HILOGE("failed to get Device ids, code:%{public}d message: %{public}s", ret, codeMsg.msg.c_str()); - return ret; + return ::taihe::array(nullptr, 0); } - return RET_OK; + uint32_t size = _ids.size(); + ::taihe::array res(size); + for (uint32_t i = 0; i < size; i++) { + res[i] = _ids[i]; + } + return res; } InputDeviceData GetDeviceAsync(int32_t deviceId) -- Gitee From c07e12f70a5de0df3ebd49a05592d63de3fc234e Mon Sep 17 00:00:00 2001 From: KangPeng Date: Wed, 30 Jul 2025 18:55:36 +0800 Subject: [PATCH 22/29] =?UTF-8?q?ztw=20=E4=BF=AE=E6=94=B9=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E8=BD=ACTaihe=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: KangPeng --- frameworks/ets/common/include/ani_common.h | 63 +- frameworks/ets/common/src/ani_common.cpp | 541 +++++++++++------- .../ohos.multimodalInput.inputMonitor.taihe | 19 +- .../include/ani_input_monitor_consumer.h | 5 +- .../src/ani_input_monitor_consumer.cpp | 93 +-- .../src/ani_input_monitor_manager.cpp | 18 +- 6 files changed, 456 insertions(+), 283 deletions(-) diff --git a/frameworks/ets/common/include/ani_common.h b/frameworks/ets/common/include/ani_common.h index de6d09888f..2f364d3424 100644 --- a/frameworks/ets/common/include/ani_common.h +++ b/frameworks/ets/common/include/ani_common.h @@ -43,7 +43,7 @@ namespace OHOS { namespace MMI { -using MapFun = std::map>; +using MapFun = std::map>; constexpr int32_t AXIS_TYPE_SCROLL_VERTICAL { 0 }; constexpr int32_t AXIS_TYPE_SCROLL_HORIZONTAL { 1 }; @@ -854,7 +854,7 @@ extern DeviceType g_taiheDeviceType[]; extern std::unordered_map g_taiheAxisType; class TaiheConverter { -public: +public: static bool GetApiError(int32_t code, TaiheError &codeMsg); static KeyCode ConvertEtsKeyCode(int32_t keyCode); static KeyCodeEts GetKeyCodeByValue(const std::map& map, KeyCode code); @@ -868,39 +868,39 @@ public: static CustomCursor ConverterToCustomCursor(const ohos::multimodalInput::pointer::CustomCursor &value); static CursorOptions ConverterToCursorConfig(const ohos::multimodalInput::pointer::CursorConfig &value); // ztw touchEvent 解析 - static TaiheTouchEvent TouchEventToTaihe(const PointerEvent &pointerEvent); - static TaiheInputEvent InputEventToTaihe(const InputEvent &inputEvent); - static TaiheTouchAction TouchActionToTaihe(int32_t action); - static TaiheSourceType SourceTypeToTaihe(int32_t sourceType); - static TaiheFixedMode FixedModeToTaihe(PointerEvent::FixedMode fixedMode); - static TaiheTouch TouchToTaihe(const PointerEvent::PointerItem &item); + static int32_t TouchEventToTaihe(const PointerEvent &pointerEvent, TaiheTouchEvent &out); + static int32_t InputEventToTaihe(const InputEvent &inputEvent, TaiheInputEvent &out); + static int32_t TouchActionToTaihe(int32_t action, TaiheTouchAction &out); + static int32_t SourceTypeToTaihe(int32_t sourceType, TaiheSourceType &out); + static int32_t FixedModeToTaihe(PointerEvent::FixedMode fixedMode, TaiheFixedMode &out); + static int32_t TouchToTaihe(const PointerEvent::PointerItem &item, TaiheTouch &out); // ztw gestureEvent - static TaiheTouchGestureAction TouchGestureActionToTaihe(int32_t action); - static TaiheGestureActionType RotateActionToTaihe(int32_t action); - static TaiheGestureActionType PinchActionToTaihe(int32_t action); - static TaiheGestureActionType SwipeInwardActionToTaihe(int32_t action); - static TaiheGestureActionType SwipeActionToTaihe(int32_t action); - static TaiheGestureActionType MultiTapActionToTaihe(int32_t action); - - static TaiheRotate RotateToTaihe(const PointerEvent &pointerEvent); - static TaihePinchEvent PinchToTaihe(const PointerEvent &pointerEvent); - static TaiheSwipeInward SwipeInwardToTaihe(const PointerEvent &pointerEvent); - static TaiheThreeFingersSwipe ThreeFingersSwipeToTaihe(const PointerEvent &pointerEvent); - static TaiheFourFingersSwipe FourFingersSwipeToTaihe(const PointerEvent &pointerEvent); + static int32_t TouchGestureActionToTaihe(int32_t action, TaiheTouchGestureAction &out); + static int32_t RotateActionToTaihe(int32_t action, TaiheGestureActionType &out); + static int32_t PinchActionToTaihe(int32_t action, TaiheGestureActionType &out); + static int32_t SwipeInwardActionToTaihe(int32_t action, TaiheGestureActionType &out); + static int32_t SwipeActionToTaihe(int32_t action, TaiheGestureActionType &out); + static int32_t MultiTapActionToTaihe(int32_t action, TaiheGestureActionType &out); + + static int32_t RotateToTaihe(const PointerEvent &pointerEvent, TaiheRotate &out); + static int32_t PinchToTaihe(const PointerEvent &pointerEvent, TaihePinchEvent &out); + static int32_t SwipeInwardToTaihe(const PointerEvent &pointerEvent, TaiheSwipeInward &out); + static int32_t ThreeFingersSwipeToTaihe(const PointerEvent &pointerEvent, TaiheThreeFingersSwipe &out); + static int32_t FourFingersSwipeToTaihe(const PointerEvent &pointerEvent, TaiheFourFingersSwipe &out); // ztw touchscreenSwipe, touchscreenPinch - static TaiheTouchGestureEvent TouchGestureEventToTaihe(const PointerEvent &pointerEvent); - static TaiheThreeFingersTap ThreeFingersTapToTaihe(const PointerEvent &pointerEvent); + static int32_t TouchGestureEventToTaihe(const PointerEvent &pointerEvent, TaiheTouchGestureEvent &out); + static int32_t ThreeFingersTapToTaihe(const PointerEvent &pointerEvent, TaiheThreeFingersTap &out); // ztw Fingerprint #ifdef OHOS_BUILD_ENABLE_FINGERPRINT - static TaiheFingerprintAction FingerprintActionToTaihe(int32_t action); - static TaiheFingerprintEvent FingerprintEventToTaihe(const PointerEvent &pointerEvent); + static int32_t FingerprintActionToTaihe(int32_t action, TaiheFingerprintAction &out); + static int32_t FingerprintEventToTaihe(const PointerEvent &pointerEvent, TaiheFingerprintEvent &out); #endif // ztw keyPressed static bool HasKeyCode(const std::vector& pressedKeys, int32_t keyCode); - TaiheKeyEventAction KeyEventActionToTaihe(int32_t action); - TaiheKeyEvent TaiheKeyEventToTaihe(const KeyEvent &keyEvent); - TaiheKeyEventKey TaiheKeyEventKeyToTaihe(const KeyEvent::KeyItem &keyItem); + static int32_t KeyEventActionToTaihe(int32_t action, TaiheKeyEventAction &out); + static int32_t TaiheKeyEventToTaihe(const KeyEvent &keyEvent, TaiheKeyEvent &out); + static int32_t TaiheKeyEventKeyToTaihe(const KeyEvent::KeyItem &keyItem, TaiheKeyEventKey &out); static TaiheMouseEvent MouseEventToTaihe(std::shared_ptr pointerEvent); static TaiheMouseAction MouseActionToTaihe(int32_t action); private: @@ -920,13 +920,10 @@ using callbackType = std::variant< struct CallbackObject { - CallbackObject(callbackType cb, ani_ref ref) : callback(cb), ref(ref) - { - } - void Release() + CallbackObject(callbackType cb, ani_ref ref) : callback(cb), ref(ref) {} + ~CallbackObject() { - taihe::env_guard guard; - if (auto *env = guard.get_env()) { + if (auto *env = taihe::get_env()) { env->GlobalReference_Delete(ref); } } diff --git a/frameworks/ets/common/src/ani_common.cpp b/frameworks/ets/common/src/ani_common.cpp index d18f84e52b..157d9b42bb 100644 --- a/frameworks/ets/common/src/ani_common.cpp +++ b/frameworks/ets/common/src/ani_common.cpp @@ -15,6 +15,7 @@ #include "ani_common.h" +#include "define_multimodal.h" #include "mmi_log.h" #include "pixel_map_taihe_ani.h" @@ -182,59 +183,87 @@ CursorOptions TaiheConverter::ConverterToCursorConfig(const ohos::multimodalInpu return opts; } -TaiheTouchEvent TaiheConverter::TouchEventToTaihe(const PointerEvent &pointerEvent) +int32_t TaiheConverter::TouchEventToTaihe(const PointerEvent &pointerEvent, TaiheTouchEvent &out) { - TaiheTouchEvent result {.action = TaiheTouchAction::key_t::CANCEL, - .touch = TaiheTouch {.toolType = TaiheToolType::key_t::FINGER}, - .sourceType = TaiheSourceType::key_t::TOUCH_SCREEN, - //result.fixedMode = TaiheFixedMode::key_t::NONE, - }; - result.base = InputEventToTaihe(pointerEvent); - result.action = TouchActionToTaihe(pointerEvent.GetPointerAction()); + CALL_DEBUG_ENTER; + auto ret = InputEventToTaihe(pointerEvent, out.base); + if (ret != RET_OK) { + MMI_HILOGE("InputEventToTaihe failed"); + return RET_ERR; + } + ret = TouchActionToTaihe(pointerEvent.GetPointerAction(), out.action); + if (ret!= RET_OK) { + MMI_HILOGE("TouchActionToTaihe failed"); + return RET_ERR; + } // 这个需要更新新代码 ---touchEvent taihe定义 // result.isInject = pointerEventItem->HasFlag(InputEvent::EVENT_FLAG_SIMULATE); std::vector vecTouches; for (auto item : pointerEvent.GetPointerIds()) { PointerEvent::PointerItem pointerItem; if (!pointerEvent.GetPointerItem(item, pointerItem)) { - // ztw MMI_HILOGE("Get pointer item failed"); - return result; + MMI_HILOGE("Get pointer item failed"); + return ret; } if (pointerItem.GetPointerId() == pointerEvent.GetPointerId()) { - result.touch = TouchToTaihe(pointerItem); + ret = TouchToTaihe(pointerItem, out.touch); + if (ret!= RET_OK) { + MMI_HILOGE("TouchToTaihe failed"); + return RET_ERR; + } } - vecTouches.push_back(TouchToTaihe(pointerItem)); + auto taiheTouch = TaiheTouch {.toolType = TaiheToolType::key_t::FINGER}; + ret = TouchToTaihe(pointerItem, taiheTouch); + if (ret!= RET_OK) { + MMI_HILOGE("TouchToTaihe failed"); + return RET_ERR; + } + vecTouches.push_back(taiheTouch); } - result.touches = taihe::array(vecTouches); - result.sourceType = SourceTypeToTaihe(pointerEvent.GetSourceType()) ; - result.fixedMode = taihe::optional(std::in_place_t{}, FixedModeToTaihe(pointerEvent.GetFixedMode())); - return result; + out.touches = taihe::array(vecTouches); + ret = SourceTypeToTaihe(pointerEvent.GetSourceType(), out.sourceType); + if (ret!= RET_OK) { + MMI_HILOGE("SourceTypeToTaihe failed"); + return RET_ERR; + } + auto fixedmode = TaiheFixedMode::from_value(RET_ERR); + ret = FixedModeToTaihe(pointerEvent.GetFixedMode(), fixedmode); + if (ret!= RET_OK) { + MMI_HILOGE("FixedModeToTaihe failed"); + return RET_ERR; + } + out.fixedMode = taihe::optional(std::in_place_t{}, fixedmode); + return ret; } -TaiheInputEvent TaiheConverter::InputEventToTaihe(const InputEvent &inputEvent) +int32_t TaiheConverter::InputEventToTaihe(const InputEvent &inputEvent, TaiheInputEvent &out) { - TaiheInputEvent result{}; - result.id = inputEvent.GetId(); - result.deviceId = inputEvent.GetDeviceId(); - result.actionTime = inputEvent.GetActionTime(); - result.screenId = inputEvent.GetTargetDisplayId(); - result.windowId = inputEvent.GetTargetWindowId(); - return result; + out.id = inputEvent.GetId(); + out.deviceId = inputEvent.GetDeviceId(); + out.actionTime = inputEvent.GetActionTime(); + out.screenId = inputEvent.GetTargetDisplayId(); + out.windowId = inputEvent.GetTargetWindowId(); + return RET_OK; } -TaiheTouchAction TaiheConverter::TouchActionToTaihe(int32_t action) { +int32_t TaiheConverter::TouchActionToTaihe(int32_t action, TaiheTouchAction &out) { + bool ret = RET_OK; switch (action) { case PointerEvent::POINTER_ACTION_CANCEL: { - return TaiheTouchAction::key_t::CANCEL; + out = TaiheTouchAction::key_t::CANCEL; + break; } case PointerEvent::POINTER_ACTION_DOWN: { - return TaiheTouchAction::key_t::DOWN; + out = TaiheTouchAction::key_t::DOWN; + break; } case PointerEvent::POINTER_ACTION_MOVE: { - return TaiheTouchAction::key_t::MOVE; + out = TaiheTouchAction::key_t::MOVE; + break; } case PointerEvent::POINTER_ACTION_UP: { - return TaiheTouchAction::key_t::UP; + out = TaiheTouchAction::key_t::UP; + break; } // ztw 代码中没有定义 // case PointerEvent::POINTER_ACTION_PULL_DOWN: { @@ -247,303 +276,399 @@ TaiheTouchAction TaiheConverter::TouchActionToTaihe(int32_t action) { // return TaiheTouchAction::key_t::PULL_UP; // } default: { - return TaiheTouchAction(TaiheTouchAction::key_t::CANCEL); + ret = RET_ERR; } } + return ret; } -TaiheSourceType TaiheConverter::SourceTypeToTaihe(int32_t sourceType) { +int32_t TaiheConverter::SourceTypeToTaihe(int32_t sourceType, TaiheSourceType &out) +{ + auto ret = RET_OK; switch (sourceType) { case PointerEvent::SOURCE_TYPE_TOUCHSCREEN: { - return TaiheSourceType::key_t::TOUCH_SCREEN; + out = TaiheSourceType::key_t::TOUCH_SCREEN; + break; } case PointerEvent::SOURCE_TYPE_TOUCHPAD: { - return TaiheSourceType::key_t::TOUCH_PAD; + out = TaiheSourceType::key_t::TOUCH_PAD; + break; } // ztw 代码中少实现 // case PointerEvent::SOURCE_TYPE_PEN: { // return TaiheTouchAction::key_t::PEN; // } default: { - return TaiheSourceType(TaiheSourceType::key_t::TOUCH_SCREEN); + ret = RET_ERR; } } + return ret; } -TaiheFixedMode TaiheConverter::FixedModeToTaihe(PointerEvent::FixedMode fixedMode) +int32_t TaiheConverter::FixedModeToTaihe(PointerEvent::FixedMode fixedMode, TaiheFixedMode &out) { + auto ret = RET_OK; switch (fixedMode) { - case PointerEvent::SOURCE_TYPE_TOUCHSCREEN: { - return TaiheFixedMode::key_t::NONE; + case PointerEvent::FixedMode::SCREEN_MODE_UNKNOWN: { + out = TaiheFixedMode::key_t::NONE; + break; } - case PointerEvent::SOURCE_TYPE_TOUCHPAD: { - return TaiheFixedMode::key_t::AUTO; + case PointerEvent::FixedMode::AUTO: { + out = TaiheFixedMode::key_t::AUTO; + break; } // ztw 代码中少实现 // case PointerEvent::SOURCE_TYPE_TOUCHPAD: { // return TaiheTouchAction::key_t::PEN; // } default: { - return TaiheFixedMode(TaiheFixedMode::key_t::AUTO); + ret = RET_ERR; } -} + } + return ret; } -TaiheTouch TaiheConverter::TouchToTaihe(const PointerEvent::PointerItem &item) +// TaiheTouch obj{.toolType = TaiheToolType::key_t::FINGER}; +int32_t TaiheConverter::TouchToTaihe(const PointerEvent::PointerItem &item, TaiheTouch &out) { - TaiheTouch obj{.toolType = TaiheToolType::key_t::FINGER}; - obj.id = item.GetPointerId(); - obj.pressedTime = item.GetDownTime(); - obj.screenX = item.GetDisplayX(); - obj.screenY = item.GetDisplayY(); + out.id = item.GetPointerId(); + out.pressedTime = item.GetDownTime(); + out.screenX = item.GetDisplayX(); + out.screenY = item.GetDisplayY(); // ztw taihe 中没有定义 // obj.globalX = static_cast(item.GetGlobalX()); // obj.globalY = static_cast(item.GetGlobalY()); - obj.windowX = item.GetWindowX(); - obj.windowY = item.GetWindowY(); - obj.pressure = item.GetPressure(); - obj.width = item.GetWidth(); - obj.height = item.GetHeight(); - obj.tiltX = item.GetTiltX(); - obj.tiltY = item.GetTiltY(); - obj.toolX = item.GetToolDisplayX(); - obj.toolY = item.GetToolDisplayY(); - obj.toolWidth = item.GetToolWidth(); - obj.toolHeight = item.GetToolHeight(); - obj.rawX = item.GetRawDx(); - obj.rawY = item.GetRawDy(); - obj.toolType.from_value(item.GetToolType()); - obj.fixedDisplayX = taihe::optional(std::in_place_t{}, item.GetFixedDisplayX()); - obj.fixedDisplayY = taihe::optional(std::in_place_t{}, item.GetFixedDisplayY()); - return obj; -} - -TaiheTouchGestureAction TaiheConverter::TouchGestureActionToTaihe(int32_t action) -{ + out.windowX = item.GetWindowX(); + out.windowY = item.GetWindowY(); + out.pressure = item.GetPressure(); + out.width = item.GetWidth(); + out.height = item.GetHeight(); + out.tiltX = item.GetTiltX(); + out.tiltY = item.GetTiltY(); + out.toolX = item.GetToolDisplayX(); + out.toolY = item.GetToolDisplayY(); + out.toolWidth = item.GetToolWidth(); + out.toolHeight = item.GetToolHeight(); + out.rawX = item.GetRawDx(); + out.rawY = item.GetRawDy(); + out.toolType.from_value(item.GetToolType()); + out.fixedDisplayX = taihe::optional(std::in_place_t{}, item.GetFixedDisplayX()); + out.fixedDisplayY = taihe::optional(std::in_place_t{}, item.GetFixedDisplayY()); + return RET_OK; +} + +int32_t TaiheConverter::TouchGestureActionToTaihe(int32_t action, TaiheTouchGestureAction &out) +{ + auto ret = RET_OK; switch (action) { case PointerEvent::TOUCH_ACTION_SWIPE_DOWN: { - return TaiheTouchGestureAction::key_t::SWIPE_DOWN; + out = TaiheTouchGestureAction::key_t::SWIPE_DOWN; + break; } case PointerEvent::TOUCH_ACTION_SWIPE_UP: { - return TaiheTouchGestureAction::key_t::SWIPE_UP; + out = TaiheTouchGestureAction::key_t::SWIPE_UP; + break; } case PointerEvent::TOUCH_ACTION_SWIPE_RIGHT: { - return TaiheTouchGestureAction::key_t::SWIPE_RIGHT; + out = TaiheTouchGestureAction::key_t::SWIPE_RIGHT; + break; } case PointerEvent::TOUCH_ACTION_SWIPE_LEFT: { - return TaiheTouchGestureAction::key_t::SWIPE_LEFT; + out = TaiheTouchGestureAction::key_t::SWIPE_LEFT; + break; } case PointerEvent::TOUCH_ACTION_PINCH_OPENED: { - return TaiheTouchGestureAction::key_t::PINCH_OPENED; + out = TaiheTouchGestureAction::key_t::PINCH_OPENED; + break; } case PointerEvent::TOUCH_ACTION_PINCH_CLOSEED: { - return TaiheTouchGestureAction::key_t::PINCH_CLOSED; + out = TaiheTouchGestureAction::key_t::PINCH_CLOSED; + break; } case PointerEvent::TOUCH_ACTION_GESTURE_END: { - return TaiheTouchGestureAction::key_t::GESTURE_END; + out = TaiheTouchGestureAction::key_t::GESTURE_END; + break; } default: { MMI_HILOGW("unknow action, action:%{public}d", action); - return TaiheTouchGestureAction::from_value(-1);; + ret = RET_ERR; } + } + return ret; } -} -TaiheGestureActionType TaiheConverter::RotateActionToTaihe(int32_t action) + +int32_t TaiheConverter::RotateActionToTaihe(int32_t action, TaiheGestureActionType &out) { + auto ret = RET_OK; switch (action) { case PointerEvent::POINTER_ACTION_ROTATE_BEGIN: { - return TaiheGestureActionType::key_t::BEGIN; + out = TaiheGestureActionType::key_t::BEGIN; + break; } case PointerEvent::POINTER_ACTION_ROTATE_UPDATE: { - return TaiheGestureActionType::key_t::UPDATE; + out = TaiheGestureActionType::key_t::UPDATE; + break; } case PointerEvent::POINTER_ACTION_ROTATE_END: { - return TaiheGestureActionType::key_t::END; + out = TaiheGestureActionType::key_t::END; + break; } default: { MMI_HILOGD("Abnormal pointer action in rotate event"); - return TaiheGestureActionType::from_value(-1); + ret = RET_ERR; } } - + return ret; } -TaiheGestureActionType TaiheConverter::PinchActionToTaihe(int32_t action) +int32_t TaiheConverter::PinchActionToTaihe(int32_t action, TaiheGestureActionType &out) { + auto ret = RET_OK; switch (action) { case PointerEvent::POINTER_ACTION_AXIS_BEGIN: { - return TaiheGestureActionType::key_t::BEGIN; + out = TaiheGestureActionType::key_t::BEGIN; + break; } case PointerEvent::POINTER_ACTION_AXIS_UPDATE: { - return TaiheGestureActionType::key_t::UPDATE; + out = TaiheGestureActionType::key_t::UPDATE; + break; } case PointerEvent::POINTER_ACTION_AXIS_END: { - return TaiheGestureActionType::key_t::END; + out = TaiheGestureActionType::key_t::END; + break; } default: { MMI_HILOGD("Abnormal pointer action in pinch event"); - return TaiheGestureActionType::from_value(-1); + ret = RET_ERR; } } - + return ret; } -TaiheGestureActionType TaiheConverter::SwipeInwardActionToTaihe(int32_t action) +int32_t TaiheConverter::SwipeInwardActionToTaihe(int32_t action, TaiheGestureActionType &out) { + auto ret = RET_OK; switch (action) { case PointerEvent::POINTER_ACTION_DOWN: { - return TaiheGestureActionType::key_t::BEGIN; + out = TaiheGestureActionType::key_t::BEGIN; break; } case PointerEvent::POINTER_ACTION_MOVE: { - return TaiheGestureActionType::key_t::UPDATE; + out = TaiheGestureActionType::key_t::UPDATE; break; } case PointerEvent::POINTER_ACTION_UP: case PointerEvent::POINTER_ACTION_CANCEL: { - return TaiheGestureActionType::key_t::END; + out = TaiheGestureActionType::key_t::END; break; } default: { MMI_HILOGE("Abnormal pointer action in swipe event"); - return TaiheGestureActionType::from_value(-1); + ret = RET_ERR; } } - + return ret; } -TaiheGestureActionType TaiheConverter::SwipeActionToTaihe(int32_t action) +int32_t TaiheConverter::SwipeActionToTaihe(int32_t action, TaiheGestureActionType &out) { + auto ret = RET_OK; switch (action) { case PointerEvent::POINTER_ACTION_SWIPE_BEGIN: { - return TaiheGestureActionType::key_t::BEGIN; + out = TaiheGestureActionType::key_t::BEGIN; + break; } case PointerEvent::POINTER_ACTION_SWIPE_UPDATE: { - return TaiheGestureActionType::key_t::UPDATE; + out = TaiheGestureActionType::key_t::UPDATE; + break; } case PointerEvent::POINTER_ACTION_SWIPE_END: { - return TaiheGestureActionType::key_t::END; + out = TaiheGestureActionType::key_t::END; + break; } default: { MMI_HILOGD("Abnormal pointer action in swipe event"); - return TaiheGestureActionType::from_value(-1); + ret = RET_ERR; } } - + return ret; } -TaiheGestureActionType TaiheConverter::MultiTapActionToTaihe(int32_t action) +int32_t TaiheConverter::MultiTapActionToTaihe(int32_t action, TaiheGestureActionType &out) { + auto ret = RET_OK; switch (action) { case PointerEvent::POINTER_ACTION_TRIPTAP: { - return TaiheGestureActionType::key_t::END; + out = TaiheGestureActionType::key_t::END; + break; } default: { MMI_HILOGD("Abnormal pointer action in multi tap event"); - return TaiheGestureActionType::from_value(-1); + ret = RET_ERR; } } + return ret; } -TaiheRotate TaiheConverter::RotateToTaihe(const PointerEvent &pointerEvent) +// TaiheRotate obj {.type = RotateActionToTaihe(pointerEvent.GetPointerAction())}; +int32_t TaiheConverter::RotateToTaihe(const PointerEvent &pointerEvent, TaiheRotate &out) { - TaiheRotate obj {.type = RotateActionToTaihe(pointerEvent.GetPointerAction())}; - obj.angle = pointerEvent.GetAxisValue(PointerEvent::AXIS_TYPE_ROTATE); - return obj; + auto type = TaiheGestureActionType::from_value(RET_ERR); + auto ret = RotateActionToTaihe(pointerEvent.GetPointerAction(), type); + if (ret != RET_OK) { + return ret; + } + out.type = type; + out.angle = pointerEvent.GetAxisValue(PointerEvent::AXIS_TYPE_ROTATE); + return ret; } -TaihePinchEvent TaiheConverter::PinchToTaihe(const PointerEvent &pointerEvent) +int32_t TaiheConverter::PinchToTaihe(const PointerEvent &pointerEvent, TaihePinchEvent &out) { - TaihePinchEvent obj {.type = PinchActionToTaihe(pointerEvent.GetPointerAction())}; - obj.scale = pointerEvent.GetAxisValue(PointerEvent::AXIS_TYPE_PINCH); - return obj; + auto type = TaiheGestureActionType::from_value(RET_ERR); + auto ret = PinchActionToTaihe(pointerEvent.GetPointerAction(), type); + if (ret != RET_OK) { + return ret; + } + out.type = type; + out.scale = pointerEvent.GetAxisValue(PointerEvent::AXIS_TYPE_PINCH); + return ret; } -TaiheSwipeInward TaiheConverter::SwipeInwardToTaihe(const PointerEvent &pointerEvent) +int32_t TaiheConverter::SwipeInwardToTaihe(const PointerEvent &pointerEvent, TaiheSwipeInward &out) { - TaiheSwipeInward obj {.type = SwipeActionToTaihe(pointerEvent.GetPointerAction())}; + //TaiheSwipeInward obj {.type = SwipeActionToTaihe(pointerEvent.GetPointerAction())}; + auto type = TaiheGestureActionType::from_value(RET_ERR); + auto ret = SwipeActionToTaihe(pointerEvent.GetPointerAction(), type); + if (ret != RET_OK) { + return ret; + } + out.type = type; PointerEvent::PointerItem pointeritem; int32_t pointerId = 0; - if (!pointerEvent.GetPointerItem(pointerId, pointeritem)) { + ret = pointerEvent.GetPointerItem(pointerId, pointeritem); + if (ret != RET_OK) { MMI_HILOGE("Can't find this pointerItem"); - return obj; + return ret; } - obj.x = pointeritem.GetDisplayX(); - obj.y = pointeritem.GetDisplayY(); - return obj; + out.x = pointeritem.GetDisplayX(); + out.y = pointeritem.GetDisplayY(); + return ret; } -TaiheThreeFingersSwipe TaiheConverter::ThreeFingersSwipeToTaihe(const PointerEvent &pointerEvent) +int32_t TaiheConverter::ThreeFingersSwipeToTaihe(const PointerEvent &pointerEvent, TaiheThreeFingersSwipe &out) { - TaiheThreeFingersSwipe obj {.type = SwipeActionToTaihe(pointerEvent.GetPointerAction())}; + //TaiheThreeFingersSwipe obj {.type = }; + auto type = TaiheGestureActionType::from_value(RET_ERR); + auto ret = SwipeActionToTaihe(pointerEvent.GetPointerAction(), type); + if (ret != RET_OK) { + MMI_HILOGE("SwipeActionToTaihe error"); + return ret; + } + out.type = type; PointerEvent::PointerItem pointeritem; int32_t pointerId = 0; - if (!pointerEvent.GetPointerItem(pointerId, pointeritem)) { + ret = pointerEvent.GetPointerItem(pointerId, pointeritem); + if (ret != RET_OK) { MMI_HILOGE("Can't find this pointerItem"); - return obj; + return ret; } - obj.x = pointeritem.GetDisplayX(); - obj.y = pointeritem.GetDisplayY(); - return obj; + out.x = pointeritem.GetDisplayX(); + out.y = pointeritem.GetDisplayY(); + return ret; } -TaiheFourFingersSwipe TaiheConverter::FourFingersSwipeToTaihe(const PointerEvent &pointerEvent) +int32_t TaiheConverter::FourFingersSwipeToTaihe(const PointerEvent &pointerEvent, TaiheFourFingersSwipe &out) { - TaiheFourFingersSwipe obj {.type = SwipeActionToTaihe(pointerEvent.GetPointerAction())}; + // TaiheFourFingersSwipe obj {.type = SwipeActionToTaihe(pointerEvent.GetPointerAction())}; + auto type = TaiheGestureActionType::from_value(RET_ERR); + auto ret = SwipeActionToTaihe(pointerEvent.GetPointerAction(), type); + if (ret != RET_OK) { + MMI_HILOGE("SwipeActionToTaihe error"); + return ret; + } + out.type = type; PointerEvent::PointerItem pointeritem; int32_t pointerId = 0; - if (!pointerEvent.GetPointerItem(pointerId, pointeritem)) { + ret = pointerEvent.GetPointerItem(pointerId, pointeritem); + if (ret != RET_OK) { MMI_HILOGE("Can't find this pointerItem"); - return obj; + return ret; } - obj.x = pointeritem.GetDisplayX(); - obj.y = pointeritem.GetDisplayY(); - return obj; + out.x = pointeritem.GetDisplayX(); + out.y = pointeritem.GetDisplayY(); + return ret; } -TaiheTouchGestureEvent TaiheConverter::TouchGestureEventToTaihe(const PointerEvent &pointerEvent) +int32_t TaiheConverter::TouchGestureEventToTaihe(const PointerEvent &pointerEvent, TaiheTouchGestureEvent &out) { - TaiheTouchGestureEvent obj {.action = TouchGestureActionToTaihe(pointerEvent.GetPointerAction())}; + //TaiheTouchGestureEvent obj {.action = TouchGestureActionToTaihe(pointerEvent.GetPointerAction())}; + auto action = TaiheTouchGestureAction::from_value(RET_ERR); + auto ret = TouchGestureActionToTaihe(pointerEvent.GetPointerAction(), action); + if (ret != RET_OK) { + MMI_HILOGE("TouchGestureActionToTaihe error"); + return ret; + } + out.action = action; std::vector vecTouches; for (auto item : pointerEvent.GetPointerIds()) { PointerEvent::PointerItem pointerItem; - if (!pointerEvent.GetPointerItem(item, pointerItem)) { + ret = pointerEvent.GetPointerItem(item, pointerItem); + if (ret != RET_OK) { MMI_HILOGE("Get pointer item failed"); - return obj; + return ret; + } + TaiheTouch per {.toolType = TaiheToolType::key_t::FINGER}; + ret = TouchToTaihe(pointerItem, per); + if (ret != RET_OK) { + MMI_HILOGE("TouchToTaihe failed"); + return ret; } - vecTouches.push_back(TouchToTaihe(pointerItem)); + vecTouches.push_back(per); } - obj.touches = taihe::array(vecTouches); - return obj; + out.touches = taihe::array(vecTouches); + return ret; } -TaiheThreeFingersTap TaiheConverter::ThreeFingersTapToTaihe(const PointerEvent &pointerEvent) +int32_t TaiheConverter::ThreeFingersTapToTaihe(const PointerEvent &pointerEvent, TaiheThreeFingersTap &out) { - TaiheThreeFingersTap obj {.type = MultiTapActionToTaihe(pointerEvent.GetPointerAction()) }; - return obj; + auto type = TaiheGestureActionType::from_value(RET_ERR); + auto ret = MultiTapActionToTaihe(pointerEvent.GetPointerAction(), type); + if (ret != RET_OK) { + MMI_HILOGE("SwipeActionToTaihe error"); + return ret; + } + out.type = type; + return ret; } #ifdef OHOS_BUILD_ENABLE_FINGERPRINT -TaiheFingerprintAction TaiheConverter::FingerprintActionToTaihe(int32_t action) +int32_t TaiheConverter::FingerprintActionToTaihe(int32_t action, TaiheFingerprintAction &out) { + auto ret = RET_OK; switch (action) { case PointerEvent::POINTER_ACTION_FINGERPRINT_DOWN: { - return TaiheFingerprintAction::key_t::DOWN; + out = TaiheFingerprintAction::key_t::DOWN; + break; } case PointerEvent::POINTER_ACTION_FINGERPRINT_UP: { - return TaiheFingerprintAction::key_t::UP; + out = TaiheFingerprintAction::key_t::UP; + break; } case PointerEvent::POINTER_ACTION_FINGERPRINT_SLIDE: { - return TaiheFingerprintAction::key_t::SLIDE; + out = TaiheFingerprintAction::key_t::SLIDE; + break; } case PointerEvent::POINTER_ACTION_FINGERPRINT_RETOUCH: { - return TaiheFingerprintAction::key_t::RETOUCH; + out = TaiheFingerprintAction::key_t::RETOUCH; + break; } case PointerEvent::POINTER_ACTION_FINGERPRINT_CLICK: { - return TaiheFingerprintAction::key_t::CLICK; + out = TaiheFingerprintAction::key_t::CLICK; + break; } /* // ztw 接口定义中没找到 case PointerEvent::POINTER_ACTION_FINGERPRINT_CANCEL: { @@ -557,17 +682,23 @@ TaiheFingerprintAction TaiheConverter::FingerprintActionToTaihe(int32_t action) } */ default: { MMI_HILOGE("Wrong action is %{public}d", action); - return TaiheFingerprintAction::from_value(-1); + ret = RET_ERR; } } } -TaiheFingerprintEvent TaiheConverter::FingerprintEventToTaihe(const PointerEvent &pointerEvent) +int32_t TaiheConverter::FingerprintEventToTaihe(const PointerEvent &pointerEvent, TaiheFingerprintEvent &out) { - TaiheFingerprintEvent obj {.action = FingerprintActionToTaihe(pointerEvent.GetPointerAction())}; - obj.distanceX = pointerEvent.GetFingerprintDistanceX(); - obj.distanceY = pointerEvent.GetFingerprintDistanceY(); - return obj; + // TaiheFingerprintEvent obj {.action = FingerprintActionToTaihe(pointerEvent.GetPointerAction())}; + auto type = TaiheFingerprintAction::from_value(RET_ERR); + auto ret = FingerprintActionToTaihe(pointerEvent.GetPointerAction(), type); + if (ret != RET_OK) { + MMI_HILOGE("TouchGestureActionToTaihe error"); + return ret; + } + out.distanceX = pointerEvent.GetFingerprintDistanceX(); + out.distanceY = pointerEvent.GetFingerprintDistanceY(); + return ret; } #endif @@ -576,68 +707,96 @@ bool TaiheConverter::HasKeyCode(const std::vector& pressedKeys, int32_t return std::find(pressedKeys.begin(), pressedKeys.end(), keyCode) != pressedKeys.end(); } -TaiheKeyEventAction TaiheConverter::KeyEventActionToTaihe(int32_t action) +int32_t TaiheConverter::KeyEventActionToTaihe(int32_t action, TaiheKeyEventAction &out) { + auto ret = RET_OK; if (KeyEvent::KEY_ACTION_CANCEL == action) { - return TaiheKeyEventAction::key_t::CANCEL; + out = TaiheKeyEventAction::key_t::CANCEL; } else if (KeyEvent::KEY_ACTION_DOWN == action) { - return TaiheKeyEventAction::key_t::DOWN; + out = TaiheKeyEventAction::key_t::DOWN; } else if (KeyEvent::KEY_ACTION_UP == action) { - return TaiheKeyEventAction::key_t::UP; + out = TaiheKeyEventAction::key_t::UP; } else { - return TaiheKeyEventAction::from_value(-1); + ret = RET_ERR; } - + return ret; } -TaiheKeyEvent TaiheConverter::TaiheKeyEventToTaihe(const KeyEvent &keyEvent) +int32_t TaiheConverter::TaiheKeyEventToTaihe(const KeyEvent &keyEvent, TaiheKeyEvent &out) { - TaiheKeyEvent obj {.action = KeyEventActionToTaihe(keyEvent.GetKeyAction()), - .key = { - .code = KeyCode::key_t::KEYCODE_UNKNOWN, - } }; + // TaiheKeyEvent obj {.action = KeyEventActionToTaihe(keyEvent.GetKeyAction()), + // .key = { + // .code = KeyCode::key_t::KEYCODE_UNKNOWN, + // + auto action = TaiheKeyEventAction::from_value(RET_ERR); + auto ret = KeyEventActionToTaihe(keyEvent.GetKeyAction(), action); + if (ret != RET_OK) { + MMI_HILOGE("TaiheKeyEventToTaihe error"); + return ret; + } std::optional keyItem = keyEvent.GetKeyItem(); if (!keyItem) { MMI_HILOGE("The keyItem is nullopt"); - return obj; + ret = RET_ERR; + return ret; + } + ret = TaiheKeyEventKeyToTaihe(keyItem.value(), out.key); + if (ret != RET_OK) { + MMI_HILOGE("TaiheKeyEventKeyToTaihe error"); + return ret; } - obj.key = TaiheKeyEventKeyToTaihe(keyItem.value()); - obj.unicodeChar = keyItem->GetUnicode(); + out.unicodeChar = keyItem->GetUnicode(); std::vector pressedKeys = keyEvent.GetPressedKeys(); std::vector keys; for (const auto &pressedKeyCode : pressedKeys) { std::optional pressedKeyItem = keyEvent.GetKeyItem(pressedKeyCode); if (!pressedKeyItem) { + ret = RET_ERR; MMI_HILOGE("The pressedKeyItem is nullopt"); - return obj; + return ret; + } + auto taiheKey = TaiheKeyEventKey{ .code = KeyCode::key_t::KEYCODE_UNKNOWN }; + ret = TaiheKeyEventKeyToTaihe(pressedKeyItem.value(), taiheKey); + if (ret != RET_OK) { + MMI_HILOGE("TaiheKeyEventKeyToTaihe error"); + return ret; } - auto taiheKey = TaiheKeyEventKeyToTaihe(pressedKeyItem.value()); keys.push_back(taiheKey); } - obj.keys = taihe::array(keys); - obj.base = InputEventToTaihe(keyEvent); - obj.ctrlKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_LEFT) + out.keys = taihe::array(keys); + ret = InputEventToTaihe(keyEvent, out.base); + if (ret != RET_OK) { + MMI_HILOGE("TaiheKeyEventKeyToTaihe error"); + return ret; + } + ret = InputEventToTaihe(keyEvent, out.base); + if (ret != RET_OK) { + MMI_HILOGE("InputEventToTaihe error"); + return ret; + } + out.ctrlKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_LEFT) || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_RIGHT); - obj.altKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_ALT_LEFT) + out.altKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_ALT_LEFT) || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_ALT_RIGHT);; - obj.shiftKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_SHIFT_LEFT) + out.shiftKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_SHIFT_LEFT) || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_SHIFT_RIGHT); - obj.logoKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_META_LEFT) + out.logoKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_META_LEFT) || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_META_RIGHT); - obj.fnKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_FN); - obj.capsLock = keyEvent.GetFunctionKey(KeyEvent::CAPS_LOCK_FUNCTION_KEY); - obj.numLock = keyEvent.GetFunctionKey(KeyEvent::NUM_LOCK_FUNCTION_KEY); - obj.scrollLock = keyEvent.GetFunctionKey(KeyEvent::SCROLL_LOCK_FUNCTION_KEY); - return obj; + out.fnKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_FN); + out.capsLock = keyEvent.GetFunctionKey(KeyEvent::CAPS_LOCK_FUNCTION_KEY); + out.numLock = keyEvent.GetFunctionKey(KeyEvent::NUM_LOCK_FUNCTION_KEY); + out.scrollLock = keyEvent.GetFunctionKey(KeyEvent::SCROLL_LOCK_FUNCTION_KEY); + return ret; } -TaiheKeyEventKey TaiheConverter::TaiheKeyEventKeyToTaihe(const KeyEvent::KeyItem &keyItem) +int32_t TaiheConverter::TaiheKeyEventKeyToTaihe(const KeyEvent::KeyItem &keyItem, TaiheKeyEventKey &out) { - TaiheKeyEventKey obj {.code = ConvertEtsKeyCode(keyItem.GetKeyCode()) }; - obj.pressedTime = keyItem.GetDownTime(); - obj.deviceId = keyItem.GetDeviceId(); - return obj; + auto ret = RET_OK; + out.code = ConvertEtsKeyCode(keyItem.GetKeyCode()); + out.pressedTime = keyItem.GetDownTime(); + out.deviceId = keyItem.GetDeviceId(); + return ret; } bool TaiheConverter::SetMouseProperty(std::shared_ptr& pointerEvent, const PointerEvent::PointerItem& item, TaiheMouseEvent &mouseEvent) @@ -653,7 +812,7 @@ bool TaiheConverter::SetMouseProperty(std::shared_ptr& pointerEven mouseEvent.button = TaiheMouseButton::key_t(buttonId); mouseEvent.base.actionTime = pointerEvent->GetActionTime(); mouseEvent.base.deviceId = item.GetDeviceId(); - mouseEvent.base.screenId = pointerEvent->GetTargetDisplayId(); + mouseEvent.base.screenId = pointerEvent->GetTargetDisplayId(); mouseEvent.base.windowId = pointerEvent->GetTargetWindowId(); mouseEvent.base.deviceId = item.GetDeviceId(); mouseEvent.windowX = item.GetWindowX(); @@ -707,7 +866,7 @@ bool TaiheConverter::GetAxesValue(const std::shared_ptr pointerEve bool TaiheConverter::GetMousePointerItem(std::shared_ptr pointerEvent, TaiheMouseEvent &mouseEvent) { - bool result = true; + bool result = true; int32_t currentPointerId = pointerEvent->GetPointerId(); std::vector axisValueVec; std::vector pointerIds { pointerEvent->GetPointerIds() }; @@ -737,7 +896,7 @@ bool TaiheConverter::GetPressedKey(const std::vector& pressedKeys, Taih bool isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_LEFT) || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_RIGHT); mouseEvent.ctrlKey = isExists; - + isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_ALT_LEFT) || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_ALT_RIGHT); mouseEvent.altKey = isExists; @@ -797,7 +956,7 @@ TaiheMouseEvent TaiheConverter::MouseEventToTaihe(std::shared_ptr .button = TaiheMouseButton::key_t::LEFT, .toolType = TaiheMouseToolType::key_t::UNKNOWN, }; - + result.action = MouseActionToTaihe(pointerEvent->GetPointerAction()); // 这个需要更新新代码 ---touchEvent taihe定义 // result.isInject = pointerEventItem->HasFlag(InputEvent::EVENT_FLAG_SIMULATE); diff --git a/frameworks/ets/input_monitor/idl/ohos.multimodalInput.inputMonitor.taihe b/frameworks/ets/input_monitor/idl/ohos.multimodalInput.inputMonitor.taihe index 2d666de166..4a74f5f73e 100644 --- a/frameworks/ets/input_monitor/idl/ohos.multimodalInput.inputMonitor.taihe +++ b/frameworks/ets/input_monitor/idl/ohos.multimodalInput.inputMonitor.taihe @@ -21,8 +21,6 @@ from ohos.multimodalInput.gestureEvent use ThreeFingersTap, TouchGestureEvent; from ohos.multimodalInput.shortKey use FingerprintEvent; from ohos.multimodalInput.keyEvent use KeyEvent; from ohos.multimodalInput.keyCode use KeyCode; -// from ohos.display use Rect; - @!sts_inject_into_module(" import { TouchEvent } from './@ohos.multimodalInput.touchEvent'; @@ -38,12 +36,8 @@ from ohos.multimodalInput.keyCode use KeyCode; import { FingerprintEvent } from './@ohos.multimodalInput.shortKey'; import { KeyEvent } from './@ohos.multimodalInput.keyEvent'; import { KeyCode } from './@ohos.multimodalInput.keyCode'; + // import display from './@ohos.display'; ") -/* -@!sts_inject(""" -import type display.Rect from '@ohos.display'; -""") */ - @!sts_inject(""" static { loadLibrary("InputMonitor.z") } @@ -90,12 +84,11 @@ function QueryTouchEventsSync(count: i32) : Array; return onKeyPressed(keys, receiver, receiver); } - - /* 存在外仓引用 - function on(type: 'mouse', rect: Array, receiver: (info: MouseEvent) => void): void { + /* + function on(type: 'mouse', rect: Array, receiver: (info: MouseEvent) => void): void { return onMouseForDisplayRect(rect, receiver, receiver); - } */ - + } + */ function off(type: 'touch', receiver?: TouchEventReceiver): void { return offTouch(receiver); @@ -128,7 +121,7 @@ function onTouch(receiver: TouchEventReceiver): void; function onMouse(receiver: (info: MouseEvent) => void, opq: Opaque): void; -// function onMouseForDisplayRect(rect: Array, receiver: (info: MouseEvent) => void, opq: Opaque): void; +// function onMouseForDisplayRect(rect: Array<@sts_type("display.Rect") Opaque>, receiver: (info: MouseEvent) => void, opq: Opaque): void; function onPinch(receiver: (info: Pinch) => void, opq: Opaque): void; diff --git a/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h b/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h index b623ec49d8..e13a061698 100644 --- a/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h +++ b/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h @@ -91,7 +91,7 @@ protected: void OnInputEvent(std::shared_ptr pointerEvent) const override; void OnInputEvent(std::shared_ptr axisEvent) const override; // 处理Taihe数据 - void OnAniPointerEvent(std::shared_ptr pointerEvent); + void OnAniPointerEvent(std::shared_ptr pointerEvent) const; void OnAniKeyEvent(std::shared_ptr keyEvent) { @@ -106,8 +106,7 @@ private: std::shared_ptr aniCallback_ { nullptr }; int32_t monitorId_ { -1 }; - // bool isMonitoring_ { false }; // 是否正在订阅 - // uint32_t rectTotal_ { 0 }; + [[ maybe_unused ]] bool isMonitoring_ { false }; // 是否正在订阅 mutable bool consumed_ { false }; // 什么含义 mutable std::mutex mutex_; mutable int32_t flowCtrl_ { 0 }; diff --git a/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp b/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp index 093c332078..0f41c887f1 100644 --- a/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp +++ b/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp @@ -123,26 +123,37 @@ int32_t AniInputMonitorConsumer::Start() CALL_DEBUG_ENTER; auto typeName = GetTypeName(); std::lock_guard guard(mutex_); - if (monitorId_ < 0) { - auto iter = TO_HANDLE_PRE_EVENT_TYPE.find(typeName.c_str()); - if (iter != TO_HANDLE_PRE_EVENT_TYPE.end()) { - monitorId_ = InputManager::GetInstance()->AddPreMonitor(shared_from_this(), iter->second, keys_); - return monitorId_; - } + int32_t ret = RET_ERR; + bool bFindType = false; + auto iter = TO_HANDLE_PRE_EVENT_TYPE.find(typeName.c_str()); + if (iter != TO_HANDLE_PRE_EVENT_TYPE.end()) { + ret = InputManager::GetInstance()->AddPreMonitor(shared_from_this(), iter->second, keys_); + bFindType = true; + } - auto it = TO_GESTURE_TYPE.find(typeName); - if (it != TO_GESTURE_TYPE.end()) { - monitorId_ = InputManager::GetInstance()->AddGestureMonitor(shared_from_this(), it->second, fingers_); - } else { - int32_t eventType = 0; - auto it = TO_HANDLE_EVENT_TYPE.find(typeName.c_str()); - if (it != TO_HANDLE_EVENT_TYPE.end()) { - eventType = it->second; - } - monitorId_ = InputManager::GetInstance()->AddMonitor(shared_from_this(), eventType); - } + auto it = TO_GESTURE_TYPE.find(typeName); + if (it != TO_GESTURE_TYPE.end()) { + ret = InputManager::GetInstance()->AddGestureMonitor(shared_from_this(), it->second, fingers_); + bFindType = true; } - return monitorId_; + + int32_t eventType = 0; + auto itFind = TO_HANDLE_EVENT_TYPE.find(typeName); + if (itFind != TO_HANDLE_EVENT_TYPE.end()) { + eventType = itFind->second; + ret = InputManager::GetInstance()->AddMonitor(shared_from_this(), eventType); + bFindType = true; + } + + if (!bFindType) { + MMI_HILOGE("not found type:%{public}s", typeName.c_str()); + return ret; + } + if (ret >= 0) { + monitorId_ = ret; + isMonitoring_ = true; + } + return ret; } void AniInputMonitorConsumer::Stop() @@ -306,7 +317,7 @@ void AniInputMonitorConsumer::OnInputEvent(std::shared_ptr pointer flowCtrl_ = 0; } } - std::function)> callback; + //std::function)> callback; { std::lock_guard guard(mutex_); auto typeName = GetTypeName(); // ANI_INPUT_MONITOR_MGR.GetMonitorTypeName(id_, fingers_); ztw @@ -319,32 +330,27 @@ void AniInputMonitorConsumer::OnInputEvent(std::shared_ptr pointer typeName != TOUCH_PINCH_GESTURE && typeName != TOUCH_ALL_GESTURE) { return; } - // SetConsumeState(pointerEvent); // ztw + SetConsumeState(pointerEvent); } if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE) { if (typeName != "mouse" && typeName != "pinch" && typeName != "rotate") { return; } - // SetConsumeState(pointerEvent); // ztw + SetConsumeState(pointerEvent); } if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHPAD) { - // ztw if (!IsGestureEvent(pointerEvent)) - { + if (!IsGestureEvent(pointerEvent)) { return; - } + } } if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_JOYSTICK) { - // ztw if (ANI_INPUT_MONITOR_MGR.GetMonitor(id_, fingers_)->GetTypeName() != "joystick") - { + if (GetTypeName() != "joystick") { MMI_HILOGE("Failed to process joystick event"); return; } } - // ztw - // callback = callback_; } - // CHKPV(callback); - // callback(pointerEvent); + OnAniPointerEvent(pointerEvent); } void AniInputMonitorConsumer::OnInputEvent(std::shared_ptr axisEvent) const @@ -364,12 +370,8 @@ void AniInputMonitorConsumer::SetConsumeState(std::shared_ptr poin bool AniInputMonitorConsumer::IsGestureEvent(std::shared_ptr pointerEvent) const { - // ztw - /* CHKPF(pointerEvent); - auto jsMonitor = JS_INPUT_MONITOR_MGR.GetMonitor(id_, fingers_); - CHKPF(jsMonitor); - auto ret = jsMonitor->GetTypeName(); + auto ret = GetTypeName(); if (ret != "pinch" && ret != "threeFingersSwipe" && ret != "fourFingersSwipe" && ret != "threeFingersTap" && ret != "swipeInward") { @@ -381,20 +383,29 @@ bool AniInputMonitorConsumer::IsGestureEvent(std::shared_ptr point consumed_ = false; } } - */ return true; } -void AniInputMonitorConsumer::OnAniPointerEvent(std::shared_ptr pointerEvent) +void AniInputMonitorConsumer::OnAniPointerEvent(std::shared_ptr pointerEvent) const { + CALL_DEBUG_ENTER; + std::lock_guard guard(mutex_); + if (!isMonitoring_) { + MMI_HILOGE("AniInputMonitorConsumer stop"); + return; + } LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerEvent->GetPointerAction()); switch (funType_) { case MONITORFUNTYPE::ON_TOUCH: { - /* ztw 先屏蔽掉 - auto &func = std::get>(aniCallback_.get()); - auto result = TaiheConverter::TouchEventToTaihe(*pointerEvent); + TaiheTouchEvent result {.action = TaiheTouchAction::key_t::CANCEL, + .touch = TaiheTouch {.toolType = TaiheToolType::key_t::FINGER}, + .sourceType = TaiheSourceType::key_t::TOUCH_SCREEN }; + auto &func = std::get>(aniCallback_->callback); + auto ret = TaiheConverter::TouchEventToTaihe(*pointerEvent, result); + if (ret != RET_OK) { + break; + } func(result); - */ break; } diff --git a/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp b/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp index 6e6563d437..3ea40cc493 100644 --- a/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp +++ b/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp @@ -53,7 +53,15 @@ TaiheTouchEventArray AniInputMonitorManager::QueryTouchEvents(int32_t count) } std::vector vecProperty; for (const auto &per : touchEventList) { - vecProperty.push_back(TaiheConverter::TouchEventToTaihe(*per)); + TaiheTouchEvent taiheItem {.action = TaiheTouchAction::key_t::CANCEL, + .touch = TaiheTouch {.toolType = TaiheToolType::key_t::FINGER}, + .sourceType = TaiheSourceType::key_t::TOUCH_SCREEN }; + auto ret = TaiheConverter::TouchEventToTaihe(*per, taiheItem); + if (ret != RET_OK) { + taihe::set_business_error(ret, "unknown error"); + return result; + } + vecProperty.push_back(taiheItem); } result = taihe::array(vecProperty); return result; @@ -66,10 +74,16 @@ bool AniInputMonitorManager::AddMonitor(MONITORFUNTYPE funType, std::shared_ptr consumer = AniInputMonitorConsumer::CreateAniInputMonitorConsumer(funType, param, std::move(cb), opq); if (!consumer) { + MMI_HILOGE("ani create consumer failed"); return false; } std::lock_guard guard(mutex_); - consumer->Start(); + int32_t retStart = consumer->Start(); + if (retStart < 0) { + MMI_HILOGE("ani monitor startup failed"); + return false; + } + monitors_.emplace(retStart, consumer); return true; } } // namespace MMI -- Gitee From f67ec073dc652665c589681c93e27bf36926824c Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Thu, 31 Jul 2025 19:57:57 +0800 Subject: [PATCH 23/29] =?UTF-8?q?lmq=20inputDevice=E5=AE=9E=E7=8E=B0on?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- frameworks/ets/input_device/BUILD.gn | 3 + .../ohos.multimodalInput.inputDevice.taihe | 2 - .../ohos.multimodalInput.inputDevice.impl.h | 82 ++++++++++ .../ets/input_device/include/taihe_event.h | 42 +++++ .../ohos.multimodalInput.inputDevice.impl.cpp | 25 ++- .../ets/input_device/src/taihe_event.cpp | 149 ++++++++++++++++++ 6 files changed, 298 insertions(+), 5 deletions(-) create mode 100644 frameworks/ets/input_device/include/ohos.multimodalInput.inputDevice.impl.h create mode 100644 frameworks/ets/input_device/include/taihe_event.h create mode 100644 frameworks/ets/input_device/src/taihe_event.cpp diff --git a/frameworks/ets/input_device/BUILD.gn b/frameworks/ets/input_device/BUILD.gn index 84400c63e8..f0a5c128dd 100644 --- a/frameworks/ets/input_device/BUILD.gn +++ b/frameworks/ets/input_device/BUILD.gn @@ -16,11 +16,13 @@ import("//foundation/multimodalinput/input/multimodalinput_mini.gni") copy_taihe_idl("input_device_taihe") { sources = [ "idl/ohos.multimodalInput.inputDevice.taihe" ] deps = [ "${mmi_path}/frameworks/ets/key_code:key_code_taihe" ] + deps += [ "${mmi_path}/frameworks/ets/gesture_event:gesture_event_taihe" ] } config("inputDevice_config") { visibility = [ ":*" ] include_dirs = [ + "./include", "${mmi_path}/util/common/include", "${mmi_path}/util/network/include", "${mmi_path}/frameworks/ets/common/include" @@ -49,6 +51,7 @@ taihe_shared_library("InputDevice") { sources += [ "src/ani_constructor.cpp", "src/ohos.multimodalInput.inputDevice.impl.cpp", + "src/taihe_event.cpp" ] deps = [ ":run_taihe", diff --git a/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe b/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe index 9d207f6ee2..d25bdfe76c 100644 --- a/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe +++ b/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe @@ -144,7 +144,6 @@ function SupportKeysSync(deviceId: i32, keys: Array): Array; function GetDeviceInfoSync(deviceId: i32): InputDeviceData; -/* @!sts_inject(""" function on(type: 'change', callback: (info: DeviceListener) => void) { return onKey(callback, callback); @@ -155,4 +154,3 @@ function GetDeviceInfoSync(deviceId: i32): InputDeviceData; """) function onKey(f: (info: DeviceListener) => void, opq: Opaque); function offKey(opq: Optional); -*/ \ No newline at end of file diff --git a/frameworks/ets/input_device/include/ohos.multimodalInput.inputDevice.impl.h b/frameworks/ets/input_device/include/ohos.multimodalInput.inputDevice.impl.h new file mode 100644 index 0000000000..2b5c0b20a4 --- /dev/null +++ b/frameworks/ets/input_device/include/ohos.multimodalInput.inputDevice.impl.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TAIHE_INPUT_DEVICE_IMPL_H +#define TAIHE_INPUT_DEVICE_IMPL_H + +#include "ohos.multimodalInput.inputDevice.proj.hpp" +#include "ohos.multimodalInput.inputDevice.impl.hpp" +#include "define_multimodal.h" +#include "input_manager.h" +#include +#include "taihe/runtime.hpp" +#include "stdexcept" + +namespace OHOS { +namespace MMI { +using TaiheDeviceListener = ohos::multimodalInput::inputDevice::DeviceListener; +using callbackTypes = std::variant>; +using TaihecType = ohos::multimodalInput::inputDevice::changedType; +using TaiheChangedType = ohos::multimodalInput::inputDevice::ChangedType; + +struct CallbackObjects { + CallbackObjects(callbackTypes cb, ani_ref ref) : callback(cb), ref(ref) + { + } + ~CallbackObjects() + { + if (auto *env = taihe::get_env()) { + env->GlobalReference_Delete(ref); + } + } + callbackTypes callback; + ani_ref ref; +}; + +class GlobalRefGuards { + ani_env *env_ = nullptr; + ani_ref ref_ = nullptr; + +public: + GlobalRefGuards(ani_env *env, ani_object obj) : env_(env) + { + if (!env_) { + return; + } + if (ANI_OK != env_->GlobalReference_Create(obj, &ref_)) { + ref_ = nullptr; + } + } + explicit operator bool() const + { + return ref_ != nullptr; + } + ani_ref get() const + { + return ref_; + } + ~GlobalRefGuards() + { + if (env_ && ref_) { + env_->GlobalReference_Delete(ref_); + } + } + + GlobalRefGuards(const GlobalRefGuards &) = delete; + GlobalRefGuards &operator=(const GlobalRefGuards &) = delete; +}; +} // namespace MMI +} // namespace OHOS +#endif // TAIHE_INPUT_DEVICE_IMPL_H \ No newline at end of file diff --git a/frameworks/ets/input_device/include/taihe_event.h b/frameworks/ets/input_device/include/taihe_event.h new file mode 100644 index 0000000000..9d257402ac --- /dev/null +++ b/frameworks/ets/input_device/include/taihe_event.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TAIHE_EVENT_H +#define TAIHE_EVENT_H + +#include "ohos.multimodalInput.inputDevice.impl.h" +#include "define_multimodal.h" +#include "input_manager.h" + +namespace OHOS { +namespace MMI { +class TaiheEvent : public IInputDeviceListener, public std::enable_shared_from_this { +public: + static TaiheEvent &GetInstance(); + int32_t IsSameCaLLback(std::string const &type, callbackTypes &&cb, uintptr_t opq); + TaiheEvent(); + ~TaiheEvent(); + DISALLOW_COPY_AND_MOVE(TaiheEvent); + void RegisterListener(std::string const &type, callbackTypes &&cb, uintptr_t opq); + void OnDeviceAdded(int32_t deviceId, const std::string &type) override; + void OnDeviceRemoved(int32_t deviceId, const std::string &type) override; +private: + std::map>> devListener_; + bool isListeningProcess_ { false }; + std::mutex mutex_; +}; +} // namespace OHOS +} // namespace MMI +#endif // TAIHE_EVENT_H \ No newline at end of file diff --git a/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp b/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp index b177f7899a..29dc5fee22 100644 --- a/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp +++ b/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp @@ -22,9 +22,12 @@ #include "input_manager.h" #include "ani_common.h" #include +#include +#include "ohos.multimodalInput.inputDevice.impl.h" +#include "taihe_event.h" #undef MMI_LOG_TAG -#define MMI_LOG_TAG "TaiHeInputDeviceImpl" +#define MMI_LOG_TAG "TaiheInputDeviceImpl" using namespace taihe; using namespace OHOS::MMI; @@ -43,6 +46,7 @@ constexpr int32_t MIN_KEY_REPEAT_DELAY { 300 }; constexpr int32_t MAX_KEY_REPEAT_DELAY { 1000 }; constexpr int32_t MIN_KEY_REPEAT_RATE { 36 }; constexpr int32_t MAX_KEY_REPEAT_RATE { 100 }; +const std::string CHANGED_TYPE = "change"; ::taihe::array GetDeviceIdsAsync() { @@ -356,6 +360,21 @@ InputDeviceData GetDeviceInfoSync(int32_t deviceId) } return TaiheConverter::ConverterInputDevice(_device); } + + +// type: "change" , callback: DeviceListener -> map +// callback : changeType: add/remove dedviceId : id -> map +void onKey(::taihe::callback_view f, uintptr_t opq) +{ + CALL_DEBUG_ENTER; + TaiheEvent::GetInstance().RegisterListener(CHANGED_TYPE, std::forward(f), opq); +} + +void offKey(taihe::optional_view opq) +{ + CALL_DEBUG_ENTER; + +} } // namespace // Since these macros are auto-generate, lint will cause false positive. @@ -374,6 +393,6 @@ TH_EXPORT_CPP_API_SetInputDeviceEnabledAsync(SetInputDeviceEnabledAsync); TH_EXPORT_CPP_API_GetKeyboardTypeSync(GetKeyboardTypeSync); TH_EXPORT_CPP_API_SupportKeysSync(SupportKeysSync); TH_EXPORT_CPP_API_GetDeviceInfoSync(GetDeviceInfoSync); -// TH_EXPORT_CPP_API_onKey(onKey); -// TH_EXPORT_CPP_API_offKey(offKey); +TH_EXPORT_CPP_API_onKey(onKey); +TH_EXPORT_CPP_API_offKey(offKey); // NOLINTEND \ No newline at end of file diff --git a/frameworks/ets/input_device/src/taihe_event.cpp b/frameworks/ets/input_device/src/taihe_event.cpp new file mode 100644 index 0000000000..acc7814180 --- /dev/null +++ b/frameworks/ets/input_device/src/taihe_event.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "taihe_event.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "TaiheEvent" + +enum INPUT_DEVICE_CALLBACK_EVENT { + CALLBACK_EVENT_FAILED = -1, + CALLBACK_EVENT_SUCCESS = 1, + CALLBACK_EVENT_EXIST = 2, + CALLBACK_EVENT_NOT_EXIST = 3, +}; + +namespace OHOS { +namespace MMI { + +std::mutex taiheCbMapMutex; +const std::string CHANGED_TYPE = "change"; + +TaiheEvent &TaiheEvent::GetInstance() +{ + static TaiheEvent instance; + return instance; +} + +int32_t TaiheEvent::IsSameCaLLback(std::string const &type, callbackTypes &&cb, uintptr_t opq) +{ + std::lock_guard lock(taiheCbMapMutex); + ani_object callbackObj = reinterpret_cast(opq); + ani_ref callbackRef; + ani_env *env = taihe::get_env(); + if (env == nullptr || ANI_OK != env->GlobalReference_Create(callbackObj, &callbackRef)) { + MMI_HILOGE("ani_env is nullptr or GlobalReference_Create failed"); + return CALLBACK_EVENT_FAILED; + } + auto &cbVec = devListener_[type]; + bool isDuplicate = std::any_of(cbVec.begin(), cbVec.end(), + [env, callbackRef](std::shared_ptr &obj) { + ani_boolean isEqual = false; + return (ANI_OK == env->Reference_StrictEquals(callbackRef, obj->ref, &isEqual)) && isEqual; + }); + if (isDuplicate) { + env->GlobalReference_Delete(callbackRef); + MMI_HILOGD("callback already registered"); + return CALLBACK_EVENT_EXIST; + } + cbVec.emplace_back(std::make_shared(cb, callbackRef)); + MMI_HILOGI("register callback success, type: %{public}s", type.c_str()); + return CALLBACK_EVENT_SUCCESS; +} + +void TaiheEvent::RegisterListener(std::string const &type, callbackTypes &&f, uintptr_t opq) +{ + CALL_DEBUG_ENTER; + bool isListening {false}; + std::lock_guard guard(mutex_); + auto iter = devListener_.find(type); + if (iter == devListener_.end()) { + MMI_HILOGE("Find %{public}s failed", type.c_str()); + return; + } + // 检测是否相同,不相同则存入 + auto result = IsSameCaLLback(type, std::forward(f), opq); + if (result == CALLBACK_EVENT_FAILED) { + MMI_HILOGE("Register listener failed"); + return; + } + if (result == CALLBACK_EVENT_EXIST) { + MMI_HILOGE("Callback already exist"); + return; + } + if (result == CALLBACK_EVENT_SUCCESS) { + isListening = isListeningProcess_; + } + + // 注册回调 + if (!isListening) { + auto ret = InputManager::GetInstance()->RegisterDevListener("change", shared_from_this()); + if (ret != RET_OK) { + MMI_HILOGE("RegisterDevListener fail, error:%{public}d", ret); + } else { + std::lock_guard guard(mutex_); + isListeningProcess_ = true; + MMI_HILOGE("Registered success"); + } + } +} + +TaiheEvent::TaiheEvent() +{ + CALL_DEBUG_ENTER; + std::lock_guard lock(mutex_); + auto ret = devListener_.insert({ CHANGED_TYPE, std::vector>() }); + CK(ret.second, VAL_NOT_EXP); +} + +TaiheEvent::~TaiheEvent() +{ + CALL_DEBUG_ENTER; + std::lock_guard guard(mutex_); + devListener_.clear(); + auto ret = InputManager::GetInstance()->UnregisterDevListener("change", shared_from_this()); + if (ret != RET_OK) { + MMI_HILOGE("UnregisterDevListener fail, error:%{public}d", ret); + } +} + +// 执行动作 +void TaiheEvent::OnDeviceAdded(int32_t deviceId, const std::string &type) +{ + CALL_DEBUG_ENTER; + std::lock_guard guard(mutex_); + auto changeEvent = devListener_.find(CHANGED_TYPE); + if (changeEvent == devListener_.end()) { + MMI_HILOGE("%{public}s: Find %{public}s failed", __func__, CHANGED_TYPE.c_str()); + return; + } + for (auto &cb : changeEvent->second) { + CHKPC(cb); + auto &func = std::get>(cb->callback); + TaihecType tmpType = TaihecType::from_value(type); + TaiheChangedType cType = TaiheChangedType::make_type(tmpType); + TaiheDeviceListener listener{ .type = cType, .deviceId = deviceId }; + func(listener); + } +} + +void TaiheEvent::OnDeviceRemoved(int32_t deviceId, const std::string &type) +{ + +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file -- Gitee From bcc373f3a636d14639fedd20d531cb5b000b35d2 Mon Sep 17 00:00:00 2001 From: KangPeng Date: Fri, 1 Aug 2025 09:45:25 +0800 Subject: [PATCH 24/29] =?UTF-8?q?ztw=20pointevent=20=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: KangPeng --- frameworks/ets/common/include/ani_common.h | 28 +- frameworks/ets/common/src/ani_common.cpp | 158 ++++---- .../include/ani_input_monitor_consumer.h | 15 + .../include/ani_input_monitor_manager.h | 1 - .../src/ani_input_monitor_consumer.cpp | 375 ++++++++++++++++-- 5 files changed, 459 insertions(+), 118 deletions(-) diff --git a/frameworks/ets/common/include/ani_common.h b/frameworks/ets/common/include/ani_common.h index 2f364d3424..03917559d0 100644 --- a/frameworks/ets/common/include/ani_common.h +++ b/frameworks/ets/common/include/ani_common.h @@ -18,6 +18,7 @@ #include #include +#include #include "securec.h" @@ -888,10 +889,11 @@ public: static int32_t SwipeInwardToTaihe(const PointerEvent &pointerEvent, TaiheSwipeInward &out); static int32_t ThreeFingersSwipeToTaihe(const PointerEvent &pointerEvent, TaiheThreeFingersSwipe &out); static int32_t FourFingersSwipeToTaihe(const PointerEvent &pointerEvent, TaiheFourFingersSwipe &out); - // ztw touchscreenSwipe, touchscreenPinch + // ztw touchscreenSwipe, touchscreenPinch static int32_t TouchGestureEventToTaihe(const PointerEvent &pointerEvent, TaiheTouchGestureEvent &out); + // ztw fingersTap static int32_t ThreeFingersTapToTaihe(const PointerEvent &pointerEvent, TaiheThreeFingersTap &out); - // ztw Fingerprint + // ztw fingerprint #ifdef OHOS_BUILD_ENABLE_FINGERPRINT static int32_t FingerprintActionToTaihe(int32_t action, TaiheFingerprintAction &out); static int32_t FingerprintEventToTaihe(const PointerEvent &pointerEvent, TaiheFingerprintEvent &out); @@ -901,13 +903,13 @@ public: static int32_t KeyEventActionToTaihe(int32_t action, TaiheKeyEventAction &out); static int32_t TaiheKeyEventToTaihe(const KeyEvent &keyEvent, TaiheKeyEvent &out); static int32_t TaiheKeyEventKeyToTaihe(const KeyEvent::KeyItem &keyItem, TaiheKeyEventKey &out); - static TaiheMouseEvent MouseEventToTaihe(std::shared_ptr pointerEvent); - static TaiheMouseAction MouseActionToTaihe(int32_t action); + static int32_t MouseEventToTaihe(std::shared_ptr pointerEvent, TaiheMouseEvent &out); + static int32_t MouseActionToTaihe(int32_t action, TaiheMouseAction &out); private: - static bool GetMousePointerItem(std::shared_ptr pointerEvent, TaiheMouseEvent &mouseEvent); - static bool SetMouseProperty(std::shared_ptr& pointerEvent, const PointerEvent::PointerItem& item, TaiheMouseEvent &mouseEvent); - static bool GetAxesValue(const std::shared_ptr pointerEvent, TaiheAxisValue& value); - static bool GetPressedKey(const std::vector& pressedKeys, TaiheMouseEvent &mouseEvent); + static int32_t GetMousePointerItem(std::shared_ptr pointerEvent, TaiheMouseEvent &mouseEvent); + static int32_t SetMouseProperty(std::shared_ptr& pointerEvent, const PointerEvent::PointerItem& item, TaiheMouseEvent &mouseEvent); + static int32_t GetAxesValue(const std::shared_ptr pointerEvent, TaiheAxisValue& value); + static int32_t GetPressedKey(const std::vector& pressedKeys, TaiheMouseEvent &mouseEvent); }; @@ -916,7 +918,15 @@ using callbackType = std::variant< taihe::callback, taihe::callback, taihe::callback, - taihe::callback, taihe::callback>; + taihe::callback, + taihe::callback, + taihe::callback, + taihe::callback, + taihe::callback, + taihe::callback, + taihe::callback, + taihe::callback + >; struct CallbackObject { diff --git a/frameworks/ets/common/src/ani_common.cpp b/frameworks/ets/common/src/ani_common.cpp index 157d9b42bb..f6b35b7ae5 100644 --- a/frameworks/ets/common/src/ani_common.cpp +++ b/frameworks/ets/common/src/ani_common.cpp @@ -539,7 +539,6 @@ int32_t TaiheConverter::PinchToTaihe(const PointerEvent &pointerEvent, TaihePinc int32_t TaiheConverter::SwipeInwardToTaihe(const PointerEvent &pointerEvent, TaiheSwipeInward &out) { - //TaiheSwipeInward obj {.type = SwipeActionToTaihe(pointerEvent.GetPointerAction())}; auto type = TaiheGestureActionType::from_value(RET_ERR); auto ret = SwipeActionToTaihe(pointerEvent.GetPointerAction(), type); if (ret != RET_OK) { @@ -696,6 +695,7 @@ int32_t TaiheConverter::FingerprintEventToTaihe(const PointerEvent &pointerEvent MMI_HILOGE("TouchGestureActionToTaihe error"); return ret; } + out.action = type; out.distanceX = pointerEvent.GetFingerprintDistanceX(); out.distanceY = pointerEvent.GetFingerprintDistanceY(); return ret; @@ -724,10 +724,6 @@ int32_t TaiheConverter::KeyEventActionToTaihe(int32_t action, TaiheKeyEventActio int32_t TaiheConverter::TaiheKeyEventToTaihe(const KeyEvent &keyEvent, TaiheKeyEvent &out) { - // TaiheKeyEvent obj {.action = KeyEventActionToTaihe(keyEvent.GetKeyAction()), - // .key = { - // .code = KeyCode::key_t::KEYCODE_UNKNOWN, - // auto action = TaiheKeyEventAction::from_value(RET_ERR); auto ret = KeyEventActionToTaihe(keyEvent.GetKeyAction(), action); if (ret != RET_OK) { @@ -799,9 +795,9 @@ int32_t TaiheConverter::TaiheKeyEventKeyToTaihe(const KeyEvent::KeyItem &keyItem return ret; } -bool TaiheConverter::SetMouseProperty(std::shared_ptr& pointerEvent, const PointerEvent::PointerItem& item, TaiheMouseEvent &mouseEvent) +int32_t TaiheConverter::SetMouseProperty(std::shared_ptr& pointerEvent, const PointerEvent::PointerItem& item, TaiheMouseEvent &mouseEvent) { - bool result = true; + int32_t ret = RET_OK; int32_t buttonId = pointerEvent->GetButtonId(); if (buttonId == PointerEvent::MOUSE_BUTTON_MIDDLE) { buttonId = TH_MOUSE_BUTTON::JS_MOUSE_BUTTON_MIDDLE; @@ -815,33 +811,25 @@ bool TaiheConverter::SetMouseProperty(std::shared_ptr& pointerEven mouseEvent.base.screenId = pointerEvent->GetTargetDisplayId(); mouseEvent.base.windowId = pointerEvent->GetTargetWindowId(); mouseEvent.base.deviceId = item.GetDeviceId(); + mouseEvent.screenX = item.GetDisplayX(); + mouseEvent.screenY = item.GetDisplayY(); mouseEvent.windowX = item.GetWindowX(); mouseEvent.windowY = item.GetWindowY(); + mouseEvent.rawDeltaX = item.GetRawDx(); + mouseEvent.rawDeltaY = item.GetRawDy(); + // ztw 接口没有定义 // mouseEvent.globalX = optional<>(std::in_place, static_cast(item.GetGlobalX())); // mouseEvent.globalY = optional<>(std::in_place, static_cast(item.GetGlobalY())); + // ztw 多模代码中没找实现 + // mouseEvent.capsLock = HasKeyCode(pressedKeys, KeyEvent::CAPS_LOCK_FUNCTION_KEY); + // mouseEvent.numLock = HasKeyCode(pressedKeys, KeyEvent::NUM_LOCK_FUNCTION_KEY); + // mouseEvent.scrollLock = HasKeyCode(pressedKeys, KeyEvent::SCROLL_LOCK_FUNCTION_KEY); + // mouseEvent.toolType - return result; + return ret; } -// MapFun TaiheConverter::GetFuns(const std::shared_ptr pointerEvent, const PointerEvent::PointerItem& item) -// { -// MapFun mapFun; -// mapFun["actionTime"] = [pointerEvent] { return pointerEvent->GetActionTime(); }; -// mapFun["screenId"] = [pointerEvent] { return pointerEvent->GetTargetDisplayId(); }; -// mapFun["windowId"] = [pointerEvent] { return pointerEvent->GetTargetWindowId(); }; -// mapFun["deviceId"] = [item] { return item.GetDeviceId(); }; -// mapFun["windowX"] = [item] { return item.GetWindowX(); }; -// mapFun["windowY"] = [item] { return item.GetWindowY(); }; -// mapFun["screenX"] = [item] { return item.GetDisplayX(); }; -// mapFun["screenY"] = [item] { return item.GetDisplayY(); }; -// mapFun["globalX"] = [item] { return static_cast(item.GetGlobalX()); }; -// mapFun["globalY"] = [item] { return static_cast(item.GetGlobalY()); }; -// mapFun["rawDeltaX"] = [item] { return item.GetRawDx(); }; -// mapFun["rawDeltaY"] = [item] { return item.GetRawDy(); }; -// return mapFun; -// } - -bool TaiheConverter::GetAxesValue(const std::shared_ptr pointerEvent, TaiheAxisValue& value) +int32_t TaiheConverter::GetAxesValue(const std::shared_ptr pointerEvent, TaiheAxisValue& value) { double axisValue = -1.0; int32_t axis = -1; @@ -861,12 +849,12 @@ bool TaiheConverter::GetAxesValue(const std::shared_ptr pointerEve value.axis = TaiheAxis::key_t(axis) ; value.value = axisValue; - return true; + return RET_OK; } -bool TaiheConverter::GetMousePointerItem(std::shared_ptr pointerEvent, TaiheMouseEvent &mouseEvent) +int32_t TaiheConverter::GetMousePointerItem(std::shared_ptr pointerEvent, TaiheMouseEvent &mouseEvent) { - bool result = true; + int32_t ret = RET_OK; int32_t currentPointerId = pointerEvent->GetPointerId(); std::vector axisValueVec; std::vector pointerIds { pointerEvent->GetPointerIds() }; @@ -875,7 +863,8 @@ bool TaiheConverter::GetMousePointerItem(std::shared_ptr pointerEv PointerEvent::PointerItem item; if (!pointerEvent->GetPointerItem(pointerId, item)) { MMI_HILOGE("Invalid pointer:%{public}d", pointerId); - return false; + ret = RET_ERR; + return ret; } mouseEvent.base.id = currentPointerId; SetMouseProperty(pointerEvent, item, mouseEvent); @@ -887,12 +876,12 @@ bool TaiheConverter::GetMousePointerItem(std::shared_ptr pointerEv } mouseEvent.axes = taihe::array(axisValueVec); - return result; + return ret; } -bool TaiheConverter::GetPressedKey(const std::vector& pressedKeys, TaiheMouseEvent &mouseEvent) +int32_t TaiheConverter::GetPressedKey(const std::vector& pressedKeys, TaiheMouseEvent &mouseEvent) { - bool result = true; + int32_t ret = RET_OK; bool isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_LEFT) || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_RIGHT); mouseEvent.ctrlKey = isExists; @@ -911,73 +900,90 @@ bool TaiheConverter::GetPressedKey(const std::vector& pressedKeys, Taih isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_FN); mouseEvent.fnKey = isExists; - - return result; + return ret; } -// bool TaiheConverter::GetPressedButtons(std::shared_ptr pointerEvent, TaiheMouseEvent &mouseEvent) -// { - -// } - -TaiheMouseAction TaiheConverter::MouseActionToTaihe(int32_t action) { +int32_t TaiheConverter::MouseActionToTaihe(int32_t action, TaiheMouseAction &out) { + int32_t ret = RET_OK; switch (action) { case PointerEvent::POINTER_ACTION_CANCEL: { - return TaiheMouseAction::key_t::CANCEL; + out = TaiheMouseAction::key_t::CANCEL; + break; } - case PointerEvent::POINTER_ACTION_DOWN: { - return TaiheMouseAction::key_t::ACTION_DOWN; + case PointerEvent::POINTER_ACTION_MOVE: + case PointerEvent::POINTER_ACTION_PULL_MOVE: { + out = TaiheMouseAction::key_t::MOVE; + break; } - case PointerEvent::POINTER_ACTION_MOVE: { - return TaiheMouseAction::key_t::MOVE; + case PointerEvent::POINTER_ACTION_BUTTON_DOWN: + case PointerEvent::POINTER_ACTION_PULL_DOWN: { + out = TaiheMouseAction::key_t::BUTTON_DOWN; + break; } - case PointerEvent::POINTER_ACTION_UP: { - return TaiheMouseAction::key_t::ACTION_UP; + case PointerEvent::POINTER_ACTION_BUTTON_UP: + case PointerEvent::POINTER_ACTION_PULL_UP: { + out = TaiheMouseAction::key_t::BUTTON_UP; + break; + } + case PointerEvent::POINTER_ACTION_AXIS_BEGIN: { + out = TaiheMouseAction::key_t::AXIS_BEGIN; + break; + } + case PointerEvent::POINTER_ACTION_AXIS_UPDATE: { + out = TaiheMouseAction::key_t::AXIS_UPDATE; + break; + } + case PointerEvent::POINTER_ACTION_AXIS_END: { + out = TaiheMouseAction::key_t::AXIS_END; + break; } - // ztw 代码中没有定义 - // case PointerEvent::POINTER_ACTION_PULL_DOWN: { - // return TaiheTouchAction::key_t::PULL_DOWN; - // } - // case PointerEvent::POINTER_ACTION_PULL_MOVE: { - // return TaiheTouchAction::key_t::PULL_MOVE; - // } - // case PointerEvent::POINTER_ACTION_PULL_UP: { - // return TaiheTouchAction::key_t::PULL_UP; - // } default: { - return TaiheMouseAction(TaiheMouseAction::key_t::CANCEL); + MMI_HILOGD("Abnormal pointer action"); + ret = RET_ERR; } + // ztw 少了 接口层ACTION_DOWN, ACTION_UP, } + return ret; } -TaiheMouseEvent TaiheConverter::MouseEventToTaihe(std::shared_ptr pointerEvent) +int32_t TaiheConverter::MouseEventToTaihe(std::shared_ptr pointerEvent, TaiheMouseEvent &out) { - TaiheMouseEvent result {.action = TaiheMouseAction::key_t::CANCEL, - .button = TaiheMouseButton::key_t::LEFT, - .toolType = TaiheMouseToolType::key_t::UNKNOWN, - }; - - result.action = MouseActionToTaihe(pointerEvent->GetPointerAction()); - // 这个需要更新新代码 ---touchEvent taihe定义 - // result.isInject = pointerEventItem->HasFlag(InputEvent::EVENT_FLAG_SIMULATE); + int32_t ret = MouseActionToTaihe(pointerEvent->GetPointerAction(), out.action); + if (ret != RET_OK) { + return ret; + } std::vector pressedKeys = pointerEvent->GetPressedKeys(); std::vector pressedKeysVec; for(auto& value: pressedKeys) { TaiheKeyCode code = TaiheKeyCode::key_t(value); pressedKeysVec.push_back(code); } - result.pressedKeys = taihe::array(pressedKeysVec); + out.pressedKeys = taihe::array(pressedKeysVec); - GetPressedKey(pressedKeys, result); - GetMousePointerItem(pointerEvent, result); + ret = GetPressedKey(pressedKeys, out); + if (ret != RET_OK) { + MMI_HILOGE("Get singlePressedKey failed"); + return ret; + } + ret = GetMousePointerItem(pointerEvent, out); + if (ret != RET_OK) { + MMI_HILOGE("Get item of mousePointer failed"); + return ret; + } std::set pressedButtons = pointerEvent->GetPressedButtons(); std::vector pressedButtonsVec; - for(auto& value : pressedButtons) { - pressedButtonsVec.push_back(TaiheMouseButton::key_t(value)); + for(auto& item : pressedButtons) { + auto buttonId = TaiheMouseButton::key_t(item); + if (item == PointerEvent::MOUSE_BUTTON_MIDDLE) { + buttonId = TaiheMouseButton::key_t::MIDDLE; + } else if (item == PointerEvent::MOUSE_BUTTON_RIGHT) { + buttonId = TaiheMouseButton::key_t::RIGHT; + } + pressedButtonsVec.push_back(buttonId); } - result.pressedButtons = taihe::array(pressedButtonsVec); - return result; + out.pressedButtons = taihe::array(pressedButtonsVec); + return ret; } } // namespace MMI diff --git a/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h b/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h index e13a061698..948f892f40 100644 --- a/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h +++ b/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h @@ -32,6 +32,7 @@ namespace OHOS { namespace MMI { enum class MONITORFUNTYPE: int32_t { ON_TOUCH, + ON_TOUCH_BOOL, ON_MOUSE, ON_MOUSE_RECT, ON_PINCH, @@ -96,8 +97,22 @@ protected: void OnAniKeyEvent(std::shared_ptr keyEvent) { } + void SetConsumeState(std::shared_ptr pointerEvent) const; + bool IsPinch(std::shared_ptr pointerEvent, const int32_t fingers) const; bool IsGestureEvent(std::shared_ptr pointerEvent) const; + bool IsRotate(std::shared_ptr pointerEvent) const; + bool IsThreeFingersSwipe(std::shared_ptr pointerEvent) const; + bool IsFourFingersSwipe(std::shared_ptr pointerEvent) const; + bool IsThreeFingersTap(std::shared_ptr pointerEvent) const; + bool IsJoystick(std::shared_ptr pointerEvent) const; + bool IsSwipeInward(std::shared_ptr pointerEvent) const; + bool IsFingerprint(std::shared_ptr pointerEvent) const; + bool IsLocaledWithinRect(std::shared_ptr pointerEvent, std::vector hotRectArea) const; + + void CheckConsumed(bool retValue, std::shared_ptr pointerEvent); + void MarkConsumed(int32_t eventId); + private: MONITORFUNTYPE funType_; int32_t fingers_ { 0 }; diff --git a/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h b/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h index 5d1e9a1ca3..bc93b9a1e7 100644 --- a/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h +++ b/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h @@ -39,7 +39,6 @@ public: private: AniInputMonitorManager() = default; private: - //int32_t monitorId_ { 0 }; std::mutex mutex_; std::map> monitors_; }; diff --git a/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp b/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp index 0f41c887f1..20318cf6bb 100644 --- a/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp +++ b/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp @@ -27,7 +27,8 @@ namespace MMI { namespace { static std::mutex jsCbMapMutex; std::map FUNCTTOYPENAME = { - { MONITORFUNTYPE::ON_TOUCH,"touch" }, + { MONITORFUNTYPE::ON_TOUCH, "touch" }, + { MONITORFUNTYPE::ON_TOUCH_BOOL, "touch"}, { MONITORFUNTYPE::ON_MOUSE, "mouse"}, { MONITORFUNTYPE::ON_MOUSE_RECT, "mouse" }, { MONITORFUNTYPE::ON_PINCH, "pinch" }, @@ -59,6 +60,9 @@ namespace { constexpr int32_t MOUSE_FLOW { 10 }; const std::string INVALID_TYPE_NAME { "" }; +constexpr int32_t ONE_FINGERS { 1 }; +constexpr int32_t THREE_FINGERS { 3 }; +constexpr int32_t FOUR_FINGERS { 4 }; inline const std::string TOUCH_SWIPE_GESTURE = "touchscreenSwipe"; inline const std::string TOUCH_PINCH_GESTURE = "touchscreenPinch"; @@ -83,7 +87,7 @@ std::map TO_HANDLE_EVENT_TYPE = { { "rotate", HANDLE_EVENT_TYPE_ROTATE }, { "threeFingersTap", HANDLE_EVENT_TYPE_THREEFINGERSTAP }, { "fingerprint", HANDLE_EVENT_TYPE_FINGERPRINT }, - { "xKey", HANDLE_EVENT_TYPE_X_KEY }, + { "xKey", HANDLE_EVENT_TYPE_X_KEY }, // ztw 确定接口目前不支持 }; std::map TO_HANDLE_PRE_EVENT_TYPE = { @@ -386,6 +390,189 @@ bool AniInputMonitorConsumer::IsGestureEvent(std::shared_ptr point return true; } +bool AniInputMonitorConsumer::IsPinch(std::shared_ptr pointerEvent, const int32_t fingers) const +{ + CHKPF(pointerEvent); + if ((fingers > 0 && ((pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_MOUSE && + pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_TOUCHPAD) || + pointerEvent->GetFingerCount() != fingers)) || + (fingers == 0 && (pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_TOUCHPAD || + pointerEvent->GetFingerCount() < THREE_FINGERS))) { + return false; + } + if ((pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_AXIS_BEGIN && + pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_AXIS_UPDATE && + pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_AXIS_END)) { + return false; + } + return true; +} + +bool AniInputMonitorConsumer::IsRotate(std::shared_ptr pointerEvent) const +{ + CHKPF(pointerEvent); + if (pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_MOUSE || + (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_ROTATE_BEGIN && + pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_ROTATE_UPDATE && + pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_ROTATE_END)) { + return false; + } + return true; +} + +bool AniInputMonitorConsumer::IsThreeFingersSwipe(std::shared_ptr pointerEvent) const +{ + CHKPF(pointerEvent); + if (pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_TOUCHPAD || + pointerEvent->GetFingerCount() != THREE_FINGERS || + (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_SWIPE_BEGIN && + pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_SWIPE_UPDATE && + pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_SWIPE_END)) { + return false; + } + return true; +} + +bool AniInputMonitorConsumer::IsFourFingersSwipe(std::shared_ptr pointerEvent) const +{ + CHKPF(pointerEvent); + if (pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_TOUCHPAD || + pointerEvent->GetFingerCount() != FOUR_FINGERS || + (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_SWIPE_BEGIN && + pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_SWIPE_UPDATE && + pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_SWIPE_END)) { + return false; + } + return true; +} + +bool AniInputMonitorConsumer::IsThreeFingersTap(std::shared_ptr pointerEvent) const +{ + CHKPF(pointerEvent); + if (pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_TOUCHPAD || + pointerEvent->GetFingerCount() != THREE_FINGERS || + (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_TRIPTAP)) { + return false; + } + return true; +} + +bool AniInputMonitorConsumer::IsJoystick(std::shared_ptr pointerEvent) const +{ + CHKPR(pointerEvent, ERROR_NULL_POINTER); + + return (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_JOYSTICK && + (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_BUTTON_UP || + pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_BUTTON_DOWN || + pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_AXIS_UPDATE)); +} + +bool AniInputMonitorConsumer::IsSwipeInward(std::shared_ptr pointerEvent) const +{ + CHKPF(pointerEvent); + if (pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_TOUCHPAD) { + MMI_HILOGE("Failed to do swipe inward, wrong source:%{public}d ", pointerEvent->GetSourceType()); + return false; + } else if (pointerEvent->GetFingerCount() != ONE_FINGERS) { + MMI_HILOGE("Failed to do swipe inward, more than one finger"); + return false; + } else if (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_DOWN && + pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_MOVE && + pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_UP && + pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_CANCEL) { + MMI_HILOGE("Failed to do swipe inward, wrong action"); + return false; + } + return true; +} + +bool AniInputMonitorConsumer::IsFingerprint(std::shared_ptr pointerEvent) const +{ + CHKPR(pointerEvent, ERROR_NULL_POINTER); + if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_FINGERPRINT && + ((PointerEvent::POINTER_ACTION_FINGERPRINT_DOWN <= pointerEvent->GetPointerAction() && + pointerEvent->GetPointerAction() <= PointerEvent::POINTER_ACTION_FINGERPRINT_CLICK) || + pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_FINGERPRINT_CANCEL || + pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_FINGERPRINT_HOLD || + pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_FINGERPRINT_TOUCH)) { + return true; + } + MMI_HILOGD("Not fingerprint event"); + return false; +} + +#ifdef OHOS_BUILD_ENABLE_X_KEY +bool AniInputMonitorConsumer::IsXKey(std::shared_ptr pointerEvent) const +{ + CHKPR(pointerEvent, ERROR_NULL_POINTER); + if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_X_KEY) { + return true; + } + MMI_HILOGD("Not X-key event."); + return false; +} +#endif // OHOS_BUILD_ENABLE_X_KEY + +void AniInputMonitorConsumer::CheckConsumed(bool retValue, std::shared_ptr pointerEvent) +{ + CALL_DEBUG_ENTER; + CHKPV(pointerEvent); + if (retValue) { + auto eventId = pointerEvent->GetId(); + MarkConsumed(eventId); + } +} + +void AniInputMonitorConsumer::MarkConsumed(int32_t eventId) +{ + //ztw 注意锁的问题 + if (consumed_) { + MMI_HILOGD("The consumed_ is true"); + return; + } + if (monitorId_ < 0) { + MMI_HILOGE("Invalid values"); + return; + } + InputManager::GetInstance()->MarkConsumed(monitorId_, eventId); + consumed_ = true; +} + +bool AniInputMonitorConsumer::IsLocaledWithinRect(std::shared_ptr pointerEvent, std::vector hotRectArea) const +{ + bool bFind = false; + int32_t currentPointerId = pointerEvent->GetPointerId(); + std::vector pointerIds { pointerEvent->GetPointerIds() }; + PointerEvent::PointerItem item; + for (const auto& pointerId : pointerIds) { + if (pointerId == currentPointerId) { + if (!pointerEvent->GetPointerItem(pointerId, item)) { + MMI_HILOGE("Invalid pointer:%{public}d", pointerId); + return false; + } + bFind = true; + break; + } + } + if (!bFind) { + return false; + } + auto xInt = item.GetDisplayX(); + auto yInt = item.GetDisplayY(); + for (uint32_t i = 0; i < hotRectArea.size(); i++) { + int32_t hotAreaX = hotRectArea.at(i).x; + int32_t hotAreaY = hotRectArea.at(i).y; + int32_t hotAreaWidth = hotRectArea.at(i).width; + int32_t hotAreaHeight = hotRectArea.at(i).height; + if ((xInt >= hotAreaX) && (xInt <= hotAreaX + hotAreaWidth) + && (yInt >= hotAreaY) && (yInt <= hotAreaY + hotAreaHeight)) { + return true; + } + } + + return false; +} + void AniInputMonitorConsumer::OnAniPointerEvent(std::shared_ptr pointerEvent) const { CALL_DEBUG_ENTER; @@ -395,51 +582,175 @@ void AniInputMonitorConsumer::OnAniPointerEvent(std::shared_ptr po return; } LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerEvent->GetPointerAction()); + auto pointerEventItem = pointerEvent; + auto ret = RET_ERR; + bool retValue = false; switch (funType_) { case MONITORFUNTYPE::ON_TOUCH: { TaiheTouchEvent result {.action = TaiheTouchAction::key_t::CANCEL, .touch = TaiheTouch {.toolType = TaiheToolType::key_t::FINGER}, .sourceType = TaiheSourceType::key_t::TOUCH_SCREEN }; - auto &func = std::get>(aniCallback_->callback); - auto ret = TaiheConverter::TouchEventToTaihe(*pointerEvent, result); - if (ret != RET_OK) { + auto &func = std::get>(aniCallback_->callback); + ret = TaiheConverter::TouchEventToTaihe(*pointerEventItem, result); + if (ret == RET_OK) { + func(result); + } + break; + } + case MONITORFUNTYPE::ON_TOUCH_BOOL: { + TaiheTouchEvent result {.action = TaiheTouchAction::key_t::CANCEL, + .touch = TaiheTouch {.toolType = TaiheToolType::key_t::FINGER}, + .sourceType = TaiheSourceType::key_t::TOUCH_SCREEN }; + auto &func = std::get>(aniCallback_->callback); + ret = TaiheConverter::TouchEventToTaihe(*pointerEventItem, result); + if (ret == RET_OK) { + retValue = func(result); + } + break; + } + case MONITORFUNTYPE::ON_MOUSE: + case MONITORFUNTYPE::ON_MOUSE_RECT: { + if (funType_ == MONITORFUNTYPE::ON_MOUSE_RECT && IsLocaledWithinRect(pointerEvent, hotRectArea_)) { + break; + } + TaiheMouseEvent result {.action = TaiheMouseAction::key_t::CANCEL, + .button = TaiheMouseButton::key_t::LEFT, + .toolType = TaiheMouseToolType::key_t::UNKNOWN, }; + auto &func = std::get>(aniCallback_->callback); + ret = TaiheConverter::MouseEventToTaihe(pointerEventItem, result); + if (ret == RET_OK) { + func(result); + } + break; + } + case MONITORFUNTYPE::ON_PINCH: { + case MONITORFUNTYPE::ON_PINCH_FINGERS: { + if (!IsPinch(pointerEventItem, fingers_)) { break; } - func(result); + TaihePinchEvent result {.type = TaiheGestureActionType::from_value(RET_ERR)}; + ret = TaiheConverter::PinchToTaihe(*pointerEventItem, result); + if (ret == RET_OK) { + auto &func = std::get>(aniCallback_->callback); + func(result); + } break; } - - case MONITORFUNTYPE::ON_MOUSE: { + case MONITORFUNTYPE::ON_ROTATE_FINGERS: { + if (!IsRotate(pointerEventItem)) { + break; + } + TaiheRotate result{.type = TaiheGestureActionType::from_value(RET_ERR)}; + ret = TaiheConverter::RotateToTaihe(*pointerEventItem, result); + if (ret == RET_OK) { + auto &func = std::get>(aniCallback_->callback); + func(result); + } + break; + } + case MONITORFUNTYPE::ON_THREEFINGERSWIPE: { + if (!IsThreeFingersSwipe(pointerEventItem)) { + break; + } + TaiheThreeFingersSwipe result{.type = TaiheGestureActionType::from_value(RET_ERR)}; + ret = TaiheConverter::ThreeFingersSwipeToTaihe(*pointerEventItem, result); + if (ret == RET_OK) { + auto &func = std::get>(aniCallback_->callback); + func(result); + } + break; + } + case MONITORFUNTYPE::ON_FOURFINGERSWIPE: { + if (!IsFourFingersSwipe(pointerEventItem)) { + break; + } + TaiheFourFingersSwipe result{.type = TaiheGestureActionType::from_value(RET_ERR)}; + ret = TaiheConverter::FourFingersSwipeToTaihe(*pointerEventItem, result); + if (ret == RET_OK) { + auto &func = std::get>(aniCallback_->callback); + func(result); + } + break; + } + case MONITORFUNTYPE::ON_THREEFINGERSTAP: { + if (!IsThreeFingersTap(pointerEventItem)) { + break; + } + TaiheThreeFingersTap result{.type = TaiheGestureActionType::from_value(RET_ERR)}; + ret = TaiheConverter::ThreeFingersTapToTaihe(*pointerEventItem, result); + if (ret == RET_OK) { + auto &func = std::get>(aniCallback_->callback); + func(result); + } + break; + } +#ifdef OHOS_BUILD_ENABLE_FINGERPRINT + case MONITORFUNTYPE::ON_FINGERPRINT: { + if (!IsFingerprint(pointerEventItem)) { + break; + } + TaiheFingerprintEvent result{.action = TaiheFingerprintAction::from_value(RET_ERR)}; + ret = TaiheConverter::FingerprintEventToTaihe(*pointerEventItem, result); + if (ret == RET_OK) { + auto &func = std::get>(aniCallback_->callback); + func(result); + } + break; + } +#endif // OHOS_BUILD_ENABLE_FINGERPRINT + case MONITORFUNTYPE::ON_SWIPEINWARD: { + if (!IsSwipeInward(pointerEventItem)) { + break; + } + TaiheSwipeInward result{.type = TaiheGestureActionType::from_value(RET_ERR)}; + ret = TaiheConverter::SwipeInwardToTaihe(*pointerEventItem, result); + if (ret == RET_OK) { + auto &func = std::get>(aniCallback_->callback); + func(result); + } break; } - case MONITORFUNTYPE::ON_MOUSE_RECT: - break; - case MONITORFUNTYPE::ON_PINCH: - case MONITORFUNTYPE::ON_PINCH_FINGERS: - break; - case MONITORFUNTYPE::ON_ROTATE_FINGERS: - break; - case MONITORFUNTYPE::ON_THREEFINGERSWIPE: - break; - case MONITORFUNTYPE::ON_FOURFINGERSWIPE: - break; - case MONITORFUNTYPE::ON_THREEFINGERSTAP: - break; - case MONITORFUNTYPE::ON_FINGERPRINT: - break; - case MONITORFUNTYPE::ON_SWIPEINWARD: - break; case MONITORFUNTYPE::ON_TOUCHSCREENSWIPE_FINGERS: - break; - case MONITORFUNTYPE::ON_TOUCHSCREENPINCH_FINGERS: - break; - case MONITORFUNTYPE::ON_KEYPRESSED_KEYS: - break; - /* code */ + case MONITORFUNTYPE::ON_TOUCHSCREENPINCH_FINGERS: { + TaiheTouchGestureEvent result{.action = TaiheTouchGestureAction::from_value(RET_ERR)}; + ret = TaiheConverter::TouchGestureEventToTaihe(*pointerEventItem, result); + if (ret == RET_OK) { + auto &func = std::get>(aniCallback_->callback); + func(result); + } break; - default: + } +#ifdef OHOS_BUILD_ENABLE_X_KEY + case MONITORFUNTYPE::ON_KEYPRESSED_KEYS: { + if (!IsXKey(pointerEventItem)) { + break; + } + // ztw 这块Taihe定义没有 break; } +#endif // OHOS_BUILD_ENABLE_X_KEY + default: + MMI_HILOGE("This event is invalid"); + break; + } } + // 感觉是除了mouse外的其他类型 + auto typeName = GetTypeName(); + bool typeNameFlag = typeName == "touch" || typeName == "pinch" || typeName == "threeFingersSwipe" || + typeName == "fourFingersSwipe" || typeName == "rotate" || typeName == "threeFingersTap" || + typeName == "joystick" || typeName == "fingerprint" || typeName == "swipeInward" || + typeName == TOUCH_SWIPE_GESTURE || typeName == TOUCH_PINCH_GESTURE || typeName == TOUCH_ALL_GESTURE || + typeName == "xKey"; + if (typeNameFlag) { + if (pointerEventItem->GetPointerAction() != PointerEvent::POINTER_ACTION_SWIPE_UPDATE && + pointerEventItem->GetPointerAction() != PointerEvent::POINTER_ACTION_PULL_MOVE) { + MMI_HILOGI("PointerId:%{public}d, PointerAction:%{public}s", pointerEventItem->GetPointerId(), + pointerEventItem->DumpPointerAction()); + } + // ztw 需要修改 获取回调处理成功函数 + // CHKRV_SCOPE(jsEnv_, napi_get_value_bool(jsEnv_, result, &retValue), GET_VALUE_BOOL, scope); + // CheckConsumed(retValue, pointerEventItem); + } +} } // namespace MMI } // namespace OHOS -- Gitee From bf2479d9f24e67601aac535435f69764cf5fe77d Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Fri, 1 Aug 2025 14:19:11 +0800 Subject: [PATCH 25/29] =?UTF-8?q?lmq=20inputdevice=20=E5=A2=9E=E5=8A=A0off?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- .../ets/input_device/include/taihe_event.h | 5 +- .../ohos.multimodalInput.inputDevice.impl.cpp | 5 + .../ets/input_device/src/taihe_event.cpp | 117 +++++++++++++++--- 3 files changed, 110 insertions(+), 17 deletions(-) diff --git a/frameworks/ets/input_device/include/taihe_event.h b/frameworks/ets/input_device/include/taihe_event.h index 9d257402ac..03117df12e 100644 --- a/frameworks/ets/input_device/include/taihe_event.h +++ b/frameworks/ets/input_device/include/taihe_event.h @@ -25,11 +25,14 @@ namespace MMI { class TaiheEvent : public IInputDeviceListener, public std::enable_shared_from_this { public: static TaiheEvent &GetInstance(); - int32_t IsSameCaLLback(std::string const &type, callbackTypes &&cb, uintptr_t opq); + bool AddCallback(std::string const &type, callbackTypes &&cb, uintptr_t opq); + bool RemoveCallback(std::string const &type, uintptr_t opq); TaiheEvent(); ~TaiheEvent(); DISALLOW_COPY_AND_MOVE(TaiheEvent); void RegisterListener(std::string const &type, callbackTypes &&cb, uintptr_t opq); + void UnregisterListener(std::string const &type, uintptr_t opq); + void UnregisterAllListener(std::string const &type); void OnDeviceAdded(int32_t deviceId, const std::string &type) override; void OnDeviceRemoved(int32_t deviceId, const std::string &type) override; private: diff --git a/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp b/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp index 29dc5fee22..6409ee4adc 100644 --- a/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp +++ b/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp @@ -373,6 +373,11 @@ void onKey(::taihe::callback_view f, uint void offKey(taihe::optional_view opq) { CALL_DEBUG_ENTER; + if (opq.has_value()) { + TaiheEvent::GetInstance().UnregisterListener(CHANGED_TYPE, opq.value()); + } else { + TaiheEvent::GetInstance().UnregisterAllListener(CHANGED_TYPE); + } } } // namespace diff --git a/frameworks/ets/input_device/src/taihe_event.cpp b/frameworks/ets/input_device/src/taihe_event.cpp index acc7814180..6e52a7193a 100644 --- a/frameworks/ets/input_device/src/taihe_event.cpp +++ b/frameworks/ets/input_device/src/taihe_event.cpp @@ -39,7 +39,7 @@ TaiheEvent &TaiheEvent::GetInstance() return instance; } -int32_t TaiheEvent::IsSameCaLLback(std::string const &type, callbackTypes &&cb, uintptr_t opq) +bool TaiheEvent::AddCallback(std::string const &type, callbackTypes &&cb, uintptr_t opq) { std::lock_guard lock(taiheCbMapMutex); ani_object callbackObj = reinterpret_cast(opq); @@ -47,7 +47,7 @@ int32_t TaiheEvent::IsSameCaLLback(std::string const &type, callbackTypes &&cb, ani_env *env = taihe::get_env(); if (env == nullptr || ANI_OK != env->GlobalReference_Create(callbackObj, &callbackRef)) { MMI_HILOGE("ani_env is nullptr or GlobalReference_Create failed"); - return CALLBACK_EVENT_FAILED; + return false; } auto &cbVec = devListener_[type]; bool isDuplicate = std::any_of(cbVec.begin(), cbVec.end(), @@ -58,11 +58,40 @@ int32_t TaiheEvent::IsSameCaLLback(std::string const &type, callbackTypes &&cb, if (isDuplicate) { env->GlobalReference_Delete(callbackRef); MMI_HILOGD("callback already registered"); - return CALLBACK_EVENT_EXIST; + return false; } cbVec.emplace_back(std::make_shared(cb, callbackRef)); MMI_HILOGI("register callback success, type: %{public}s", type.c_str()); - return CALLBACK_EVENT_SUCCESS; + return true; +} + +bool TaiheEvent::RemoveCallback(std::string const &type, uintptr_t opq) +{ + std::lock_guard lock(taiheCbMapMutex); + ani_object callbackObj = reinterpret_cast(opq); + ani_env *env = taihe::get_env(); + if (env == nullptr) { + MMI_HILOGE("Failed to unregister %{public}s, env is nullptr", type.c_str()); + return false; + } + GlobalRefGuards guard(env, callbackObj); + if (!guard) { + MMI_HILOGE("Failed to unregister %{public}s, GlobalRefGuard is false!", type.c_str()); + return false; + } + const auto pred = [env, targetRef = guard.get()](std::shared_ptr &obj) { + ani_boolean isEqual = false; + return (ANI_OK == env->Reference_StrictEquals(targetRef, obj->ref, &isEqual)) && isEqual; + }; + auto &cbVec = devListener_[type]; + const auto it = std::find_if(cbVec.begin(), cbVec.end(), pred); + if (it == cbVec.end()) { + MMI_HILOGE("Failed to unregister %{public}s, GlobalRefGuard is false!", type.c_str()); + return false; + } + cbVec.erase(it); + MMI_HILOGI("unregister callback success, type: %{public}s", type.c_str()); + return true; } void TaiheEvent::RegisterListener(std::string const &type, callbackTypes &&f, uintptr_t opq) @@ -75,21 +104,12 @@ void TaiheEvent::RegisterListener(std::string const &type, callbackTypes &&f, ui MMI_HILOGE("Find %{public}s failed", type.c_str()); return; } - // 检测是否相同,不相同则存入 - auto result = IsSameCaLLback(type, std::forward(f), opq); - if (result == CALLBACK_EVENT_FAILED) { + if (!AddCallback(type, std::forward(f), opq)) { MMI_HILOGE("Register listener failed"); return; } - if (result == CALLBACK_EVENT_EXIST) { - MMI_HILOGE("Callback already exist"); - return; - } - if (result == CALLBACK_EVENT_SUCCESS) { - isListening = isListeningProcess_; - } + isListening = isListeningProcess_; - // 注册回调 if (!isListening) { auto ret = InputManager::GetInstance()->RegisterDevListener("change", shared_from_this()); if (ret != RET_OK) { @@ -102,6 +122,57 @@ void TaiheEvent::RegisterListener(std::string const &type, callbackTypes &&f, ui } } +void TaiheEvent::UnregisterListener(std::string const &type, uintptr_t opq) +{ + CALL_DEBUG_ENTER; + bool needStopListening { false }; + std::lock_guard guard(mutex_); + auto iter = devListener_.find(type); + if (iter == devListener_.end()) { + MMI_HILOGE("Find %{public}s failed", type.c_str()); + return; + } + if (!RemoveCallback(type, opq)) { + MMI_HILOGE("Unregister listener failed"); + return; + } + needStopListening = isListeningProcess_; + + if (isListeningProcess_ && iter->second.empty()) { + needStopListening = true; + isListeningProcess_ = false; + } + if (needStopListening) { + auto ret = InputManager::GetInstance()->UnregisterDevListener("change", shared_from_this()); + if (ret != RET_OK) { + MMI_HILOGE("UnregisterDevListener fail, error:%{public}d", ret); + } + } +} + +void TaiheEvent::UnregisterAllListener(std::string const &type) +{ + CALL_DEBUG_ENTER; + bool needStopListening { false }; + std::lock_guard guard(mutex_); + auto iter = devListener_.find(type); + if (iter == devListener_.end()) { + MMI_HILOGE("Find %{public}s failed", type.c_str()); + return; + } + iter->second.clear(); + if (isListeningProcess_ && iter->second.empty()) { + needStopListening = true; + isListeningProcess_ = false; + } + if (needStopListening) { + auto ret = InputManager::GetInstance()->UnregisterDevListener("change", shared_from_this()); + if (ret != RET_OK) { + MMI_HILOGE("UnregisterDevListener fail, error:%{public}d", ret); + } + } +} + TaiheEvent::TaiheEvent() { CALL_DEBUG_ENTER; @@ -143,7 +214,21 @@ void TaiheEvent::OnDeviceAdded(int32_t deviceId, const std::string &type) void TaiheEvent::OnDeviceRemoved(int32_t deviceId, const std::string &type) { - + CALL_DEBUG_ENTER; + std::lock_guard guard(mutex_); + auto changeEvent = devListener_.find(CHANGED_TYPE); + if (changeEvent == devListener_.end()) { + MMI_HILOGE("%{public}s: Find %{public}s failed", __func__, CHANGED_TYPE.c_str()); + return; + } + for (auto &cb : changeEvent->second) { + CHKPC(cb); + auto &func = std::get>(cb->callback); + TaihecType tmpType = TaihecType::from_value(type); + TaiheChangedType cType = TaiheChangedType::make_type(tmpType); + TaiheDeviceListener listener{ .type = cType, .deviceId = deviceId }; + func(listener); + } } } // namespace MMI } // namespace OHOS \ No newline at end of file -- Gitee From c1eb62247a97be465c9991db075c16290643ad04 Mon Sep 17 00:00:00 2001 From: KangPeng Date: Mon, 4 Aug 2025 18:35:36 +0800 Subject: [PATCH 26/29] =?UTF-8?q?ztw=20=E6=B7=BB=E5=8A=A0=E4=BA=86uv=20wor?= =?UTF-8?q?k=E8=A1=A5=E9=BD=90=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: KangPeng --- bundle.json | 3 +- frameworks/ets/common/include/ani_common.h | 3 +- frameworks/ets/common/src/ani_common.cpp | 1 - frameworks/ets/input_monitor/BUILD.gn | 1 + .../ohos.multimodalInput.inputMonitor.taihe | 12 +- .../include/ani_input_monitor_consumer.h | 33 +- .../include/ani_input_monitor_manager.h | 9 +- .../src/ani_input_monitor_consumer.cpp | 290 ++++++++++++------ .../src/ani_input_monitor_manager.cpp | 117 ++++++- ...ohos.multimodalInput.inputMonitor.impl.cpp | 78 +++-- 10 files changed, 395 insertions(+), 152 deletions(-) diff --git a/bundle.json b/bundle.json index 76bc50fe08..fd82bfd6f5 100644 --- a/bundle.json +++ b/bundle.json @@ -103,7 +103,8 @@ "ipc", "sensor", "idl_tool", - "runtime_core" + "runtime_core", + "libuv" ], "third_party": [ "libuv", diff --git a/frameworks/ets/common/include/ani_common.h b/frameworks/ets/common/include/ani_common.h index 03917559d0..5e1be382de 100644 --- a/frameworks/ets/common/include/ani_common.h +++ b/frameworks/ets/common/include/ani_common.h @@ -914,7 +914,8 @@ private: using callbackType = std::variant< - taihe::callback, + taihe::callback, + //taihe::callback, taihe::callback, taihe::callback, taihe::callback, diff --git a/frameworks/ets/common/src/ani_common.cpp b/frameworks/ets/common/src/ani_common.cpp index f6b35b7ae5..763ebc345d 100644 --- a/frameworks/ets/common/src/ani_common.cpp +++ b/frameworks/ets/common/src/ani_common.cpp @@ -604,7 +604,6 @@ int32_t TaiheConverter::FourFingersSwipeToTaihe(const PointerEvent &pointerEvent int32_t TaiheConverter::TouchGestureEventToTaihe(const PointerEvent &pointerEvent, TaiheTouchGestureEvent &out) { - //TaiheTouchGestureEvent obj {.action = TouchGestureActionToTaihe(pointerEvent.GetPointerAction())}; auto action = TaiheTouchGestureAction::from_value(RET_ERR); auto ret = TouchGestureActionToTaihe(pointerEvent.GetPointerAction(), action); if (ret != RET_OK) { diff --git a/frameworks/ets/input_monitor/BUILD.gn b/frameworks/ets/input_monitor/BUILD.gn index 2c4407a9b2..c44a3f170a 100644 --- a/frameworks/ets/input_monitor/BUILD.gn +++ b/frameworks/ets/input_monitor/BUILD.gn @@ -74,6 +74,7 @@ taihe_shared_library("InputMonitor") { external_deps = [ "c_utils:utils", "hilog:libhilog", + "libuv:uv", ] branch_protector_ret = "pac_ret" sanitize = { diff --git a/frameworks/ets/input_monitor/idl/ohos.multimodalInput.inputMonitor.taihe b/frameworks/ets/input_monitor/idl/ohos.multimodalInput.inputMonitor.taihe index 4a74f5f73e..bf2cc1a0db 100644 --- a/frameworks/ets/input_monitor/idl/ohos.multimodalInput.inputMonitor.taihe +++ b/frameworks/ets/input_monitor/idl/ohos.multimodalInput.inputMonitor.taihe @@ -56,7 +56,7 @@ function QueryTouchEventsSync(count: i32) : Array; type InputOnTypeCallbackByFingers = 'pinch' | 'rotate' | 'touchscreenSwipe' | 'touchscreenPinch'; function on (type: 'touch', receiver: TouchEventReceiver): void { - return onTouch(receiver); + return onTouch(receiver.filter as (touchEvent: _taihe__ohos_multimodalInput_touchEvent.TouchEvent) => boolean, receiver.filter); } function on (type: InputOnTypeCallback, receiver: Object): void { @@ -91,7 +91,11 @@ function QueryTouchEventsSync(count: i32) : Array; */ function off(type: 'touch', receiver?: TouchEventReceiver): void { - return offTouch(receiver); + if (receiver) { + offTouch(receiver.filter); + } else { + offTouch(undefined); + } } function off (type: InputOnTypeCallback|'keyPressed', receiver?: Object): void { @@ -117,7 +121,7 @@ function QueryTouchEventsSync(count: i32) : Array; } """) -function onTouch(receiver: TouchEventReceiver): void; +function onTouch(receiver: (touchEvent: TouchEvent) => bool, opq: Opaque): void; function onMouse(receiver: (info: MouseEvent) => void, opq: Opaque): void; @@ -146,7 +150,7 @@ function onTouchscreenPinch(fingers: i32, receiver: (info: TouchGestureEvent) => function onKeyPressed(keys: Array, receiver: (info: KeyEvent) => void, opq: Opaque): void; -function offTouch(receiver: Optional): void; +function offTouch(receiver: Optional): void; function offMouse(receiver: Optional): void; diff --git a/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h b/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h index 948f892f40..394834fe11 100644 --- a/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h +++ b/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h @@ -18,6 +18,8 @@ #include #include +#include +#include #include "window_info.h" @@ -73,6 +75,11 @@ public: int32_t GetId() const; int32_t GetFingers() const; std::string GetTypeName() const; + MONITORFUNTYPE GetFunType() const; + bool CheckOffFuncParam(MONITORFUNTYPE funType, int32_t fingers = 0) const; + std::shared_ptr GetCallback() const { + return aniCallback_; + } bool IsOnFunc() const; int32_t Start(); void Stop(); @@ -85,19 +92,22 @@ public: return false; } + static bool IsOffFunc(MONITORFUNTYPE funType) { + if (funType >= MONITORFUNTYPE::OFF_TOUCH && funType <= MONITORFUNTYPE::OFF_KEYPRESSED_KEYS) { + return true; + } + return false; + } + protected: - static bool CreateCallback(callbackType &&cb, uintptr_t opq, std::shared_ptr &callback); - static bool ReleaseCallback(std::shared_ptr &callback, taihe::optional_view opq); void OnInputEvent(std::shared_ptr keyEvent) const override; void OnInputEvent(std::shared_ptr pointerEvent) const override; void OnInputEvent(std::shared_ptr axisEvent) const override; - // 处理Taihe数据 - void OnAniPointerEvent(std::shared_ptr pointerEvent) const; - - void OnAniKeyEvent(std::shared_ptr keyEvent) { - - } + static void AniWorkCallback(uv_work_t *work, int32_t status); + void OnPointerEventInEvThread(); + void OnAniKeyEvent(std::shared_ptr keyEvent) const; + bool IsBeginAndEnd(std::shared_ptr pointerEvent) const; void SetConsumeState(std::shared_ptr pointerEvent) const; bool IsPinch(std::shared_ptr pointerEvent, const int32_t fingers) const; bool IsGestureEvent(std::shared_ptr pointerEvent) const; @@ -114,6 +124,7 @@ protected: void MarkConsumed(int32_t eventId); private: + void OnPerPointerEvent(std::shared_ptr pointerEvent); MONITORFUNTYPE funType_; int32_t fingers_ { 0 }; std::vector keys_; @@ -121,10 +132,12 @@ private: std::shared_ptr aniCallback_ { nullptr }; int32_t monitorId_ { -1 }; - [[ maybe_unused ]] bool isMonitoring_ { false }; // 是否正在订阅 - mutable bool consumed_ { false }; // 什么含义 + [[ maybe_unused ]] bool isMonitoring_ { false }; + mutable bool consumed_ { false }; mutable std::mutex mutex_; mutable int32_t flowCtrl_ { 0 }; + + mutable std::queue> evQueue_; }; } // namespace MMI } // namespace OHOS diff --git a/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h b/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h index bc93b9a1e7..71d48adaed 100644 --- a/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h +++ b/frameworks/ets/input_monitor/include/ani_input_monitor_manager.h @@ -31,16 +31,23 @@ public: DISALLOW_COPY_AND_MOVE(AniInputMonitorManager); ~AniInputMonitorManager() = default; + std::shared_ptr GetMonitor(int32_t monitorId); TaiheTouchEventArray QueryTouchEvents(int32_t count); + + bool CreateCallback(callbackType &&cb, uintptr_t opq, std::shared_ptr &callback); + bool IsExistCallback(const std::shared_ptr &callback, taihe::optional_view opq); + bool AddMonitor(MONITORFUNTYPE funType, const ConsumerParmType ¶m, - callbackType &cb, uintptr_t opq); + callbackType &&cb, uintptr_t opq); + bool RemoveMonitor(MONITORFUNTYPE funType, taihe::optional_view opq, int32_t fingers = 0); private: AniInputMonitorManager() = default; private: std::mutex mutex_; std::map> monitors_; + std::mutex jsCbMapMutex; }; #define ANI_INPUT_MONITOR_MGR ::OHOS::MMI::AniInputMonitorManager::GetInstance() } // namespace MMI diff --git a/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp b/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp index 20318cf6bb..d93feaad12 100644 --- a/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp +++ b/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp @@ -15,6 +15,9 @@ #include "ani_input_monitor_consumer.h" +#include + +#include "ani_input_monitor_manager.h" #include "input_manager.h" #include "mmi_log.h" @@ -25,7 +28,6 @@ namespace OHOS { namespace MMI { namespace { - static std::mutex jsCbMapMutex; std::map FUNCTTOYPENAME = { { MONITORFUNTYPE::ON_TOUCH, "touch" }, { MONITORFUNTYPE::ON_TOUCH_BOOL, "touch"}, @@ -94,6 +96,23 @@ std::map TO_HANDLE_PRE_EVENT_TYPE = { { "keyPressed", HANDLE_EVENT_TYPE_PRE_KEY }, }; } + +struct MonitorInfo { + int32_t monitorId; +}; + +void CleanData(MonitorInfo** monitorInfo, uv_work_t** work) +{ + if (*monitorInfo != nullptr) { + delete *monitorInfo; + *monitorInfo = nullptr; + } + if (*work != nullptr) { + delete *work; + *work = nullptr; + } +} + int32_t AniInputMonitorConsumer::GetId() const { return monitorId_; @@ -113,6 +132,11 @@ std::string AniInputMonitorConsumer::GetTypeName() const return ""; } +MONITORFUNTYPE AniInputMonitorConsumer::GetFunType() const +{ + return funType_; +} + bool AniInputMonitorConsumer::IsOnFunc() const { if (funType_ >= MONITORFUNTYPE::ON_TOUCH && funType_ <= MONITORFUNTYPE::ON_KEYPRESSED_KEYS) { @@ -122,6 +146,22 @@ bool AniInputMonitorConsumer::IsOnFunc() const } +bool AniInputMonitorConsumer::CheckOffFuncParam(MONITORFUNTYPE funType, int32_t fingers) const +{ + bool bCheck = false; + if (GetFunType() == funType) { + if (funType == MONITORFUNTYPE::OFF_TOUCHSCREENPINCH_FINGERS || + funType == MONITORFUNTYPE::OFF_TOUCHSCREENPINCH_FINGERS) { + if (fingers == GetFingers()) { + bCheck = true; + } + } else { + bCheck = true; + } + } + return bCheck; +} + int32_t AniInputMonitorConsumer::Start() { CALL_DEBUG_ENTER; @@ -164,6 +204,11 @@ void AniInputMonitorConsumer::Stop() { CALL_DEBUG_ENTER; std::lock_guard guard(mutex_); + if (!isMonitoring_) { + MMI_HILOGE("not start"); + return; + } + isMonitoring_ = false; if (monitorId_ < 0) { MMI_HILOGE("Invalid values"); return; @@ -229,84 +274,36 @@ std::shared_ptr AniInputMonitorConsumer::CreateAniInput break; } std::shared_ptr callback; - if (!CreateCallback(std::move(cb), opq, callback)) { + if (!ANI_INPUT_MONITOR_MGR.CreateCallback(std::move(cb), opq, callback)) { return ret; } ret = std::make_shared(funType, fingers, rect, keys, callback); return ret; } -bool AniInputMonitorConsumer::CreateCallback(callbackType &&cb, uintptr_t opq, std::shared_ptr &callback) -{ - std::lock_guard lock(jsCbMapMutex); - ani_object callbackObj = reinterpret_cast(opq); - ani_ref callbackRef; - ani_env *env = taihe::get_env(); - if (env == nullptr || ANI_OK != env->GlobalReference_Create(callbackObj, &callbackRef)) { - MMI_HILOGE("ani_env is nullptr or GlobalReference_Create failed"); - return false; - } - ani_boolean isEqual = false; - auto result = ANI_OK;// env->Reference_StrictEquals(callbackRef, obj->ref, &isEqual); ztw 这块有疑问 - if (result != ANI_OK) { - MMI_HILOGE("ani_env Reference_StrictEquals failed"); - return false; - } - if (isEqual) { - env->GlobalReference_Delete(callbackRef); - MMI_HILOGD("callback already registered"); - return false; - } - callback = std::make_shared(cb, callbackRef); - return true; -} - -bool AniInputMonitorConsumer::ReleaseCallback(std::shared_ptr &callback, taihe::optional_view opq) -{ - std::lock_guard lock(jsCbMapMutex); - if (!opq.has_value()) { - MMI_HILOGE("callback is nullptr!"); - return false; - } - ani_env *env = taihe::get_env(); - if (env == nullptr) { - MMI_HILOGE("ani_env is nullptr!"); - return false; - } - GlobalRefGuard guard(env, reinterpret_cast(opq.value())); - if (!guard) { - MMI_HILOGE("GlobalRefGuard is false!"); - return false; - } - ani_boolean isEqual = false; - auto result = env->Reference_StrictEquals(guard.get(), callback->ref, &isEqual); - if (result != ANI_OK) { - MMI_HILOGE("ani_env Reference_StrictEquals failed"); - return false; - } - MMI_HILOGI("ReleaseCallback callback success."); - return true; -} - void AniInputMonitorConsumer::OnInputEvent(std::shared_ptr keyEvent) const { CALL_DEBUG_ENTER; CHKPV(keyEvent); - std::function)> callback; { std::lock_guard guard(mutex_); - // ztw - //auto typeName = ANI_INPUT_MONITOR_MGR.GetPreMonitorTypeName(id_); - if (GetTypeName() == INVALID_TYPE_NAME || GetTypeName() != "keyPressed") { + auto typeName = GetTypeName(); + if (typeName== INVALID_TYPE_NAME || typeName != "keyPressed") { MMI_HILOGE("Failed to process key event."); return; } - // ztw - //callback = keyCallback_; } - // ztw - CHKPV(callback); - callback(keyEvent); + +} + +bool AniInputMonitorConsumer::IsBeginAndEnd(std::shared_ptr pointerEvent) const +{ + CHKPF(pointerEvent); + bool res = pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_DOWN || + pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_UP || + pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_SWIPE_BEGIN || + pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_SWIPE_END; + return res; } void AniInputMonitorConsumer::OnInputEvent(std::shared_ptr pointerEvent) const @@ -321,40 +318,114 @@ void AniInputMonitorConsumer::OnInputEvent(std::shared_ptr pointer flowCtrl_ = 0; } } - //std::function)> callback; - { - std::lock_guard guard(mutex_); - auto typeName = GetTypeName(); // ANI_INPUT_MONITOR_MGR.GetMonitorTypeName(id_, fingers_); ztw - if (typeName == INVALID_TYPE_NAME) { - MMI_HILOGE("Failed to process pointer event"); + // 过滤数据 + + std::lock_guard guard(mutex_); + auto typeName = GetTypeName(); + if (typeName == INVALID_TYPE_NAME) { + MMI_HILOGE("Failed to process pointer event"); + return; + } + if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) { + if (typeName != "touch" && typeName != TOUCH_SWIPE_GESTURE && + typeName != TOUCH_PINCH_GESTURE && typeName != TOUCH_ALL_GESTURE) { return; } - if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) { - if (typeName != "touch" && typeName != TOUCH_SWIPE_GESTURE && - typeName != TOUCH_PINCH_GESTURE && typeName != TOUCH_ALL_GESTURE) { - return; - } - SetConsumeState(pointerEvent); + SetConsumeState(pointerEvent); + } + if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE) { + if (typeName != "mouse" && typeName != "pinch" && typeName != "rotate") { + return; } - if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE) { - if (typeName != "mouse" && typeName != "pinch" && typeName != "rotate") { - return; - } - SetConsumeState(pointerEvent); + SetConsumeState(pointerEvent); + } + if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHPAD) { + if (!IsGestureEvent(pointerEvent)) { + return; } - if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHPAD) { - if (!IsGestureEvent(pointerEvent)) { - return; - } + } + if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_JOYSTICK) { + if (GetTypeName() != "joystick") { + MMI_HILOGE("Failed to process joystick event"); + return; } - if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_JOYSTICK) { - if (GetTypeName() != "joystick") { - MMI_HILOGE("Failed to process joystick event"); - return; - } + } + + // 放入队列 + if (!evQueue_.empty()) { + if (IsBeginAndEnd(pointerEvent)) { + std::queue> tmp; + std::swap(evQueue_, tmp); + } + } + evQueue_.push(pointerEvent); + + if (!evQueue_.empty()) { + uv_work_t *work = new (std::nothrow) uv_work_t; + CHKPV(work); + MonitorInfo *monitorInfo = new (std::nothrow) MonitorInfo(); + if (monitorInfo == nullptr) { + MMI_HILOGE("The monitorInfo is nullptr"); + delete work; + work = nullptr; + return; + } + monitorInfo->monitorId = monitorId_; + work->data = monitorInfo; + uv_loop_s *loop = uv_default_loop(); + int32_t ret = uv_queue_work_with_qos( + loop, work, + [](uv_work_t *work) { + MMI_HILOGD("uv_queue_work callback function is called"); + }, + &AniInputMonitorConsumer::AniWorkCallback, + uv_qos_user_initiated); + if (ret != 0) { + MMI_HILOGE("Add uv_queue failed, ret is %{public}d", ret); + CleanData(&monitorInfo, &work); + } + } + +} + +void AniInputMonitorConsumer::AniWorkCallback(uv_work_t *work, int32_t status) +{ + CALL_DEBUG_ENTER; + CHKPV(work); + auto temp = static_cast(work->data); + delete work; + work = nullptr; + //OnPointerEventInJsThread(jsMonitor->GetTypeName(), temp->fingers); + auto monitor = ANI_INPUT_MONITOR_MGR.GetMonitor(temp->monitorId); + if (monitor) { + monitor->OnPointerEventInEvThread(); + } + delete temp; + temp = nullptr; + +} + +void AniInputMonitorConsumer::OnPointerEventInEvThread() +{ + CALL_DEBUG_ENTER; + std::lock_guard guard(mutex_); + if (!isMonitoring_) { + MMI_HILOGE("Js monitor stop"); + return; + } + while (!evQueue_.empty()) { + if (!isMonitoring_) { + MMI_HILOGE("Js monitor stop handle callback"); + break; + } + auto pointerEvent = evQueue_.front(); + if (pointerEvent == nullptr) { + MMI_HILOGE("Scope is nullptr"); + continue; } + OnPerPointerEvent(pointerEvent); + evQueue_.pop(); } - OnAniPointerEvent(pointerEvent); } void AniInputMonitorConsumer::OnInputEvent(std::shared_ptr axisEvent) const @@ -573,11 +644,10 @@ bool AniInputMonitorConsumer::IsLocaledWithinRect(std::shared_ptr return false; } -void AniInputMonitorConsumer::OnAniPointerEvent(std::shared_ptr pointerEvent) const +void AniInputMonitorConsumer::OnPerPointerEvent(std::shared_ptr pointerEvent) { CALL_DEBUG_ENTER; - std::lock_guard guard(mutex_); - if (!isMonitoring_) { + if (!isMonitoring_) { MMI_HILOGE("AniInputMonitorConsumer stop"); return; } @@ -623,7 +693,7 @@ void AniInputMonitorConsumer::OnAniPointerEvent(std::shared_ptr po } break; } - case MONITORFUNTYPE::ON_PINCH: { + case MONITORFUNTYPE::ON_PINCH: case MONITORFUNTYPE::ON_PINCH_FINGERS: { if (!IsPinch(pointerEventItem, fingers_)) { break; @@ -732,10 +802,9 @@ void AniInputMonitorConsumer::OnAniPointerEvent(std::shared_ptr po default: MMI_HILOGE("This event is invalid"); break; - } } // 感觉是除了mouse外的其他类型 - auto typeName = GetTypeName(); + std::string typeName = GetTypeName(); bool typeNameFlag = typeName == "touch" || typeName == "pinch" || typeName == "threeFingersSwipe" || typeName == "fourFingersSwipe" || typeName == "rotate" || typeName == "threeFingersTap" || typeName == "joystick" || typeName == "fingerprint" || typeName == "swipeInward" || @@ -752,5 +821,34 @@ void AniInputMonitorConsumer::OnAniPointerEvent(std::shared_ptr po // CheckConsumed(retValue, pointerEventItem); } } + +void AniInputMonitorConsumer::OnAniKeyEvent(std::shared_ptr keyEvent) const +{ + CALL_DEBUG_ENTER; + std::lock_guard guard(mutex_); + if (!isMonitoring_) { + MMI_HILOGE("Js monitor stop"); + return; + } + auto typeName = GetTypeName(); + int32_t ret = RET_ERR; + switch (funType_) { + case MONITORFUNTYPE::ON_KEYPRESSED_KEYS: { + TaiheKeyEvent result{.action = TaiheKeyEventAction::from_value(RET_ERR), + .key = {.code = KeyCode::key_t::KEYCODE_UNKNOWN}}; + ret = TaiheConverter::TaiheKeyEventToTaihe(*keyEvent, result); + if (ret == RET_OK) { + auto &func = std::get>(aniCallback_->callback); + func(result); + } + break; + } + default: { + MMI_HILOGE("This event is invalid"); + break; + } + } + +} } // namespace MMI } // namespace OHOS diff --git a/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp b/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp index 3ea40cc493..ff2afba208 100644 --- a/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp +++ b/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp @@ -12,9 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "ani_input_monitor_manager.h" - #include "define_multimodal.h" #include "input_manager.h" @@ -30,6 +30,17 @@ AniInputMonitorManager& AniInputMonitorManager::GetInstance() return instance; } +std::shared_ptr AniInputMonitorManager::GetMonitor(int32_t monitorId) +{ + std::lock_guard guard(mutex_); + auto itFind = monitors_.find(monitorId); + if (itFind != monitors_.end()) { + return itFind->second; + } + return nullptr; +} + + TaiheTouchEventArray AniInputMonitorManager::QueryTouchEvents(int32_t count) { CALL_DEBUG_ENTER; @@ -67,24 +78,122 @@ TaiheTouchEventArray AniInputMonitorManager::QueryTouchEvents(int32_t count) return result; } +bool AniInputMonitorManager::CreateCallback(callbackType &&cb, uintptr_t opq, std::shared_ptr &callback) +{ + CALL_DEBUG_ENTER; + std::lock_guard guard(mutex_); // map 锁加在外面 + std::lock_guard lock(jsCbMapMutex); + ani_object callbackObj = reinterpret_cast(opq); + ani_ref callbackRef; + ani_env *env = taihe::get_env(); + if (env == nullptr || ANI_OK != env->GlobalReference_Create(callbackObj, &callbackRef)) { + MMI_HILOGE("ani_env is nullptr or GlobalReference_Create failed"); + return false; + } + bool isDuplicate = std::any_of(monitors_.begin(), monitors_.end(), + [env, callbackRef](const auto& it) { + ani_boolean isEqual = false; + if (ANI_OK != env->Reference_StrictEquals(callbackRef, it.second->GetCallback()->ref, &isEqual)) { + MMI_HILOGD("Reference_StrictEquals error"); + return isEqual; + } + return isEqual; + }); + if (isDuplicate) { + env->GlobalReference_Delete(callbackRef); + MMI_HILOGD("callback already registered"); + return false; + } + callback = std::make_shared(cb, callbackRef); + return true; +} + +bool AniInputMonitorManager::IsExistCallback(const std::shared_ptr &callback, taihe::optional_view opq) +{ + CALL_DEBUG_ENTER; + std::lock_guard lock(jsCbMapMutex); + if (!opq.has_value()) { + MMI_HILOGE("callback is nullptr!"); + return false; + } + ani_env *env = taihe::get_env(); + if (env == nullptr) { + MMI_HILOGE("ani_env is nullptr!"); + return false; + } + GlobalRefGuard guard(env, reinterpret_cast(opq.value())); + if (!guard) { + MMI_HILOGE("GlobalRefGuard is false!"); + return false; + } + ani_boolean isEqual = false; + auto result = env->Reference_StrictEquals(guard.get(), callback->ref, &isEqual); + if (result != ANI_OK) { + MMI_HILOGE("ani_env Reference_StrictEquals failed"); + return false; + } + MMI_HILOGI("ReleaseCallback callback success."); + return true; +} + bool AniInputMonitorManager::AddMonitor(MONITORFUNTYPE funType, - const ConsumerParmType ¶m, callbackType &cb, uintptr_t opq) + const ConsumerParmType ¶m, callbackType &&cb, uintptr_t opq) { CALL_DEBUG_ENTER; std::shared_ptr consumer = AniInputMonitorConsumer::CreateAniInputMonitorConsumer(funType, param, std::move(cb), opq); if (!consumer) { - MMI_HILOGE("ani create consumer failed"); + MMI_HILOGE("ani create consumer failed"); return false; } - std::lock_guard guard(mutex_); int32_t retStart = consumer->Start(); if (retStart < 0) { MMI_HILOGE("ani monitor startup failed"); return false; } + std::lock_guard guard(mutex_); monitors_.emplace(retStart, consumer); return true; } + +bool AniInputMonitorManager::RemoveMonitor(MONITORFUNTYPE funType, taihe::optional_view opq, int32_t fingers) +{ + CALL_DEBUG_ENTER; + std::lock_guard guard(mutex_); + bool checkFuncName = AniInputMonitorConsumer::IsOnFunc(funType); + if (true == checkFuncName) { + MMI_HILOGE("func check error!"); + return false; + } + if (false == opq.has_value()) { + for (auto it = monitors_.begin(); it != monitors_.end();) { + auto monitor = it->second; + if (monitor->CheckOffFuncParam(funType, fingers)) { + monitor->Stop(); + it = monitors_.erase(it); + } else { + ++it; + } + } + return true; + } + + for (auto it = monitors_.begin(); it != monitors_.end();) { + auto monitor = it->second; + bool needDel = false; + if (monitor->CheckOffFuncParam(funType, fingers)) { + if (IsExistCallback(monitor->GetCallback(), opq)) { + needDel = true; + } + } + if (needDel) { + monitor->Stop(); + it = monitors_.erase(it); + } else { + ++it; + } + } + return false; +} } // namespace MMI } // namespace OHOS diff --git a/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp b/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp index f5a71c4b34..9510fb85c4 100644 --- a/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp +++ b/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp @@ -12,114 +12,124 @@ using namespace OHOS::MMI; return ANI_INPUT_MONITOR_MGR.QueryTouchEvents(count); } -void onTouch(::ohos::multimodalInput::inputMonitor::TouchEventReceiver const& receiver) { - /* ztw error - if (receiver.filter == nullptr) { - taihe::set_business_error(401, "Parameter error."); - return; - } - */ - TH_THROW(std::runtime_error, "onTouch not implemented"); +void onTouch(::taihe::callback_view receiver, uintptr_t opq) { + ConsumerParmType param; + ANI_INPUT_MONITOR_MGR.AddMonitor(MONITORFUNTYPE::ON_TOUCH_BOOL, param, receiver, opq); } void onMouse(::taihe::callback_view receiver, uintptr_t opq) { - TH_THROW(std::runtime_error, "onMouse not implemented"); + ConsumerParmType param; + ANI_INPUT_MONITOR_MGR.AddMonitor(MONITORFUNTYPE::ON_MOUSE, param, receiver, opq); } void onPinch(::taihe::callback_view receiver, uintptr_t opq) { - TH_THROW(std::runtime_error, "onPinch not implemented"); + ConsumerParmType param; + ANI_INPUT_MONITOR_MGR.AddMonitor(MONITORFUNTYPE::ON_PINCH, param, receiver, opq); } void onPinchByNumber(int32_t fingers, ::taihe::callback_view receiver, uintptr_t opq) { - TH_THROW(std::runtime_error, "onPinchByNumber not implemented"); + ConsumerParmType param = fingers; + ANI_INPUT_MONITOR_MGR.AddMonitor(MONITORFUNTYPE::ON_PINCH_FINGERS, param, receiver, opq); } void onRotateByNumber(int32_t fingers, ::taihe::callback_view receiver, uintptr_t opq) { - TH_THROW(std::runtime_error, "onRotateByNumber not implemented"); + ConsumerParmType param = fingers; + ANI_INPUT_MONITOR_MGR.AddMonitor(MONITORFUNTYPE::ON_ROTATE_FINGERS, param, receiver, opq); } void onThreeFingersSwipe(::taihe::callback_view receiver, uintptr_t opq) { - TH_THROW(std::runtime_error, "onThreeFingersSwipe not implemented"); + ConsumerParmType param; + ANI_INPUT_MONITOR_MGR.AddMonitor(MONITORFUNTYPE::ON_THREEFINGERSWIPE, param, receiver, opq); } void onFourFingersSwipe(::taihe::callback_view receiver, uintptr_t opq) { - TH_THROW(std::runtime_error, "onFourFingersSwipe not implemented"); + ConsumerParmType param; + ANI_INPUT_MONITOR_MGR.AddMonitor(MONITORFUNTYPE::ON_FOURFINGERSWIPE, param, receiver, opq); } void onThreeFingersTap(::taihe::callback_view receiver, uintptr_t opq) { - TH_THROW(std::runtime_error, "onThreeFingersTap not implemented"); + ConsumerParmType param; + ANI_INPUT_MONITOR_MGR.AddMonitor(MONITORFUNTYPE::ON_THREEFINGERSTAP, param, receiver, opq); } void onFingerprint(::taihe::callback_view receiver, uintptr_t opq) { - TH_THROW(std::runtime_error, "onFingerprint not implemented"); + ConsumerParmType param; + ANI_INPUT_MONITOR_MGR.AddMonitor(MONITORFUNTYPE::ON_FINGERPRINT, param, receiver, opq); } void onSwipeInward(::taihe::callback_view receiver, uintptr_t opq) { - TH_THROW(std::runtime_error, "onSwipeInward not implemented"); + ConsumerParmType param; + ANI_INPUT_MONITOR_MGR.AddMonitor(MONITORFUNTYPE::ON_SWIPEINWARD, param, receiver, opq); } void onTouchscreenSwipeByNumber(int32_t fingers, ::taihe::callback_view receiver, uintptr_t opq) { - TH_THROW(std::runtime_error, "onTouchscreenSwipeByNumber not implemented"); + ConsumerParmType param = fingers; + ANI_INPUT_MONITOR_MGR.AddMonitor(MONITORFUNTYPE::ON_TOUCHSCREENSWIPE_FINGERS, param, receiver, opq); } void onTouchscreenPinch(int32_t fingers, ::taihe::callback_view receiver, uintptr_t opq) { - TH_THROW(std::runtime_error, "onTouchscreenPinch not implemented"); + ConsumerParmType param = fingers; + ANI_INPUT_MONITOR_MGR.AddMonitor(MONITORFUNTYPE::ON_TOUCHSCREENPINCH_FINGERS, param, receiver, opq); } void onKeyPressed(::taihe::array_view<::ohos::multimodalInput::keyCode::KeyCode> keys, ::taihe::callback_view receiver, uintptr_t opq) { - TH_THROW(std::runtime_error, "onKeyPressed not implemented"); + std::vector inputkeys; + for (auto it = keys.begin(); it != keys.end(); ++it) { + inputkeys.push_back(static_cast(*it)); + } + ANI_INPUT_MONITOR_MGR.AddMonitor(MONITORFUNTYPE::ON_KEYPRESSED_KEYS, inputkeys, receiver, opq); } -void offTouch(::taihe::optional_view<::ohos::multimodalInput::inputMonitor::TouchEventReceiver> receiver) { - TH_THROW(std::runtime_error, "offTouch not implemented"); +void offTouch(::taihe::optional_view receiver) { + ANI_INPUT_MONITOR_MGR.RemoveMonitor(MONITORFUNTYPE::OFF_TOUCH, receiver); } void offMouse(::taihe::optional_view receiver) { - TH_THROW(std::runtime_error, "offMouse not implemented"); + ANI_INPUT_MONITOR_MGR.RemoveMonitor(MONITORFUNTYPE::OFF_MOUSE, receiver); } void offPinch(::taihe::optional_view receiver) { - TH_THROW(std::runtime_error, "offPinch not implemented"); + ANI_INPUT_MONITOR_MGR.RemoveMonitor(MONITORFUNTYPE::OFF_PINCH, receiver); } void offPinchByNumber(int32_t fingers, ::taihe::optional_view receiver) { - TH_THROW(std::runtime_error, "offPinchByNumber not implemented"); + ANI_INPUT_MONITOR_MGR.RemoveMonitor(MONITORFUNTYPE::OFF_MOUSE, receiver); } void offRotateByNumber(int32_t fingers, ::taihe::optional_view receiver) { - TH_THROW(std::runtime_error, "offRotateByNumber not implemented"); + ANI_INPUT_MONITOR_MGR.RemoveMonitor(MONITORFUNTYPE::OFF_MOUSE, receiver, fingers); } void offThreeFingersSwipe(::taihe::optional_view receiver) { - TH_THROW(std::runtime_error, "offThreeFingersSwipe not implemented"); + ANI_INPUT_MONITOR_MGR.RemoveMonitor(MONITORFUNTYPE::OFF_MOUSE, receiver); } void offFourFingersSwipe(::taihe::optional_view receiver) { - TH_THROW(std::runtime_error, "offFourFingersSwipe not implemented"); + ANI_INPUT_MONITOR_MGR.RemoveMonitor(MONITORFUNTYPE::OFF_MOUSE, receiver); } void offThreeFingersTap(::taihe::optional_view receiver) { - TH_THROW(std::runtime_error, "offThreeFingersTap not implemented"); + ANI_INPUT_MONITOR_MGR.RemoveMonitor(MONITORFUNTYPE::OFF_MOUSE, receiver); } void offFingerprint(::taihe::optional_view receiver) { - TH_THROW(std::runtime_error, "offFingerprint not implemented"); + ANI_INPUT_MONITOR_MGR.RemoveMonitor(MONITORFUNTYPE::OFF_MOUSE, receiver); } void offSwipeInward(::taihe::optional_view receiver) { - TH_THROW(std::runtime_error, "offSwipeInward not implemented"); + ANI_INPUT_MONITOR_MGR.RemoveMonitor(MONITORFUNTYPE::OFF_MOUSE, receiver); } void offTouchscreenSwipe(int32_t fingers, ::taihe::optional_view receiver) { - TH_THROW(std::runtime_error, "offTouchscreenSwipe not implemented"); + ANI_INPUT_MONITOR_MGR.RemoveMonitor(MONITORFUNTYPE::OFF_MOUSE, receiver); } void offTouchscreenPinch(int32_t fingers, ::taihe::optional_view receiver) { - TH_THROW(std::runtime_error, "offTouchscreenPinch not implemented"); + ANI_INPUT_MONITOR_MGR.RemoveMonitor(MONITORFUNTYPE::OFF_MOUSE, receiver); } void offKeyPressed(::taihe::optional_view receiver) { - TH_THROW(std::runtime_error, "offKeyPressed not implemented"); + ANI_INPUT_MONITOR_MGR.RemoveMonitor(MONITORFUNTYPE::OFF_MOUSE, receiver); } } // namespace -- Gitee From f115d733daee363faf47c0e9579f98767b4bb640 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Tue, 5 Aug 2025 19:24:27 +0800 Subject: [PATCH 27/29] =?UTF-8?q?lmq=20device=E4=B8=8Epointer=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E6=8F=90=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- frameworks/ets/common/BUILD.gn | 13 -- frameworks/ets/common/include/ani_common.h | 38 +---- frameworks/ets/common/src/ani_common.cpp | 131 ------------------ frameworks/ets/input_consumer/BUILD.gn | 1 + frameworks/ets/input_device/BUILD.gn | 4 +- .../include/taihe_inputdevice_utils.h | 54 ++++++++ .../ohos.multimodalInput.inputDevice.impl.cpp | 13 +- .../src/taihe_inputdevice_utils.cpp | 127 +++++++++++++++++ frameworks/ets/pointer/BUILD.gn | 4 +- .../ohos.multimodalInput.pointer.impl.h | 1 + .../ets/pointer/include/taihe_pointer_utils.h | 33 +++++ .../src/ohos.multimodalInput.pointer.impl.cpp | 7 +- .../ets/pointer/src/taihe_pointer_utils.cpp | 61 ++++++++ .../ohos.multimodalInput.shortKey.impl.cpp | 1 - 14 files changed, 295 insertions(+), 193 deletions(-) create mode 100644 frameworks/ets/input_device/include/taihe_inputdevice_utils.h create mode 100644 frameworks/ets/input_device/src/taihe_inputdevice_utils.cpp create mode 100644 frameworks/ets/pointer/include/taihe_pointer_utils.h create mode 100644 frameworks/ets/pointer/src/taihe_pointer_utils.cpp diff --git a/frameworks/ets/common/BUILD.gn b/frameworks/ets/common/BUILD.gn index 78761f5435..c4ec63f58b 100644 --- a/frameworks/ets/common/BUILD.gn +++ b/frameworks/ets/common/BUILD.gn @@ -25,8 +25,6 @@ copy_taihe_idl("inputani_common_taihe") { "${mmi_path}/frameworks/ets/input_event:input_event_taihe", "${mmi_path}/frameworks/ets/gesture_event:gesture_event_taihe", "${mmi_path}/frameworks/ets/key_event:key_event_taihe", - "${mmi_path}/frameworks/ets/input_device:input_device_taihe", - "${mmi_path}/frameworks/ets/pointer:pointer_taihe", ] } config("inputani_common_config") { @@ -45,15 +43,6 @@ taihe_generated_file_path_inputCommon = "$taihe_file_path/out/$subsystem_name/$p ohos_taihe("run_taihe") { taihe_generated_file_path = "${taihe_generated_file_path_inputCommon}" deps = [ - "${mmi_path}/frameworks/ets/mouse_event:run_taihe", - "${mmi_path}/frameworks/ets/touch_event:run_taihe", - "${mmi_path}/frameworks/ets/short_key:run_taihe", - "${mmi_path}/frameworks/ets/key_code:run_taihe", - "${mmi_path}/frameworks/ets/input_event:run_taihe", - "${mmi_path}/frameworks/ets/gesture_event:run_taihe", - "${mmi_path}/frameworks/ets/key_event:run_taihe", - "${mmi_path}/frameworks/ets/input_device:run_taihe", - "${mmi_path}/frameworks/ets/pointer:run_taihe", ":inputani_common_taihe" ] outputs = [ @@ -82,8 +71,6 @@ taihe_shared_library("inputani_common") { external_deps = [ "c_utils:utils", "hilog:libhilog", - "image_framework:image_taihe", - "image_framework:image_native", ] branch_protector_ret = "pac_ret" sanitize = { diff --git a/frameworks/ets/common/include/ani_common.h b/frameworks/ets/common/include/ani_common.h index 5e1be382de..87a6da67e9 100644 --- a/frameworks/ets/common/include/ani_common.h +++ b/frameworks/ets/common/include/ani_common.h @@ -29,18 +29,12 @@ #include "ohos.multimodalInput.touchEvent.proj.hpp" #include "ohos.multimodalInput.shortKey.proj.hpp" #include "ohos.multimodalInput.keyEvent.proj.hpp" -#include "ohos.multimodalInput.inputDevice.proj.hpp" -#include "ohos.multimodalInput.pointer.proj.hpp" -#include "ohos.multimodalInput.pointer.impl.hpp" #include "taihe/runtime.hpp" #include "taihe/callback.hpp" #include "key_event.h" -#include "pointer_event.h" -#include "input_device.h" #include "pointer_style.h" - -#include +#include "pointer_event.h" namespace OHOS { namespace MMI { @@ -49,12 +43,6 @@ using MapFun = std::map>; constexpr int32_t AXIS_TYPE_SCROLL_VERTICAL { 0 }; constexpr int32_t AXIS_TYPE_SCROLL_HORIZONTAL { 1 }; constexpr int32_t AXIS_TYPE_PINCH { 2 }; -constexpr uint32_t EVDEV_TAG_KEYBOARD = (1 << 1); -constexpr uint32_t EVDEV_TAG_MOUSE = (1 << 2); -constexpr uint32_t EVDEV_TAG_TOUCHPAD = (1 << 3); -constexpr uint32_t EVDEV_TAG_TOUCHSCREEN = (1 << 4); -constexpr uint32_t EVDEV_TAG_JOYSTICK = (1 << 6); -constexpr uint32_t EVDEV_TAG_TRACKBALL = (1 << 10); using namespace ohos::multimodalInput::keyCode; using TaiheAxisValue = ::ohos::multimodalInput::mouseEvent::AxisValue; @@ -63,12 +51,7 @@ using TaiheInputEvent = ohos::multimodalInput::inputEvent::InputEvent; using TaiheMouseToolType = ohos::multimodalInput::mouseEvent::ToolType; using TaiheMouseButton = ::ohos::multimodalInput::mouseEvent::Button; using TaiheKeyCode = ::ohos::multimodalInput::keyCode::KeyCode; -using TaihesType = ohos::multimodalInput::inputDevice::sourceType; -using TaiheaType = ohos::multimodalInput::inputDevice::axisType; -using TaiheSType = ohos::multimodalInput::inputDevice::SourceType; -using TaiheAType = ohos::multimodalInput::inputDevice::AxisType; -using TaiheAxisRange = ohos::multimodalInput::inputDevice::AxisRange; -using TaiheInputDeviceData = ohos::multimodalInput::inputDevice::InputDeviceData; + using TaiheMouseEvent = ohos::multimodalInput::mouseEvent::MouseEvent; using TaiheTouchEvent = ohos::multimodalInput::touchEvent::TouchEvent; using TaiheTouchEventArray = taihe::array; @@ -846,28 +829,11 @@ const std::map KEY_CODE_TRANSFORMATION = { { KEYCODE_DAGGER_LONG_PRESS_ETS, KeyCode::key_t::KEYCODE_DAGGER_LONG_PRESS } }; -struct DeviceType { - std::string sourceTypeName; - uint32_t typeBit { 0 }; -}; - -extern DeviceType g_taiheDeviceType[]; -extern std::unordered_map g_taiheAxisType; - class TaiheConverter { public: static bool GetApiError(int32_t code, TaiheError &codeMsg); static KeyCode ConvertEtsKeyCode(int32_t keyCode); static KeyCodeEts GetKeyCodeByValue(const std::map& map, KeyCode code); - static TaihesType ConverterSType(const std::string &sourceType); - static TaiheaType ConverterATxis(const std::string &axisType); - static TaiheSType ConverterSourceType(const TaihesType &sType); - static TaiheAType ConverterAxisType(const TaiheaType &aType); - static TaiheAxisRange ConverterAxisRange(const InputDevice::AxisInfo &axisInfo, - const std::string &sourceType, const std::string &axisType); - static TaiheInputDeviceData ConverterInputDevice(std::shared_ptr &device); - static CustomCursor ConverterToCustomCursor(const ohos::multimodalInput::pointer::CustomCursor &value); - static CursorOptions ConverterToCursorConfig(const ohos::multimodalInput::pointer::CursorConfig &value); // ztw touchEvent 解析 static int32_t TouchEventToTaihe(const PointerEvent &pointerEvent, TaiheTouchEvent &out); static int32_t InputEventToTaihe(const InputEvent &inputEvent, TaiheInputEvent &out); diff --git a/frameworks/ets/common/src/ani_common.cpp b/frameworks/ets/common/src/ani_common.cpp index 763ebc345d..ff5cd1b3a0 100644 --- a/frameworks/ets/common/src/ani_common.cpp +++ b/frameworks/ets/common/src/ani_common.cpp @@ -17,33 +17,12 @@ #include "define_multimodal.h" #include "mmi_log.h" -#include "pixel_map_taihe_ani.h" #undef MMI_LOG_TAG #define MMI_LOG_TAG "aniCommon" namespace OHOS { namespace MMI { -DeviceType g_taiheDeviceType[] = { - { "keyboard", EVDEV_TAG_KEYBOARD }, - { "mouse", EVDEV_TAG_MOUSE }, - { "touchpad", EVDEV_TAG_TOUCHPAD }, - { "touchscreen", EVDEV_TAG_TOUCHSCREEN }, - { "joystick", EVDEV_TAG_JOYSTICK }, - { "trackball", EVDEV_TAG_TRACKBALL }, -}; - -std::unordered_map g_taiheAxisType = { - { ABS_MT_TOUCH_MAJOR, "touchmajor" }, - { ABS_MT_TOUCH_MINOR, "touchminor" }, - { ABS_MT_ORIENTATION, "orientation" }, - { ABS_MT_POSITION_X, "x" }, - { ABS_MT_POSITION_Y, "y" }, - { ABS_MT_PRESSURE, "pressure" }, - { ABS_MT_WIDTH_MAJOR, "toolmajor" }, - { ABS_MT_WIDTH_MINOR, "toolminor" }, -}; - bool TaiheConverter::GetApiError(int32_t code, TaiheError &codeMsg) { auto iter = TAIHE_ERRORS.find(code); @@ -73,116 +52,6 @@ KeyCodeEts TaiheConverter::GetKeyCodeByValue(const std::map& m return KEYCODE_UNKNOWN_ETS; } -TaihesType TaiheConverter::ConverterSType(const std::string &sourceType) -{ - return ohos::multimodalInput::inputDevice::sourceType::from_value(sourceType); -} - -TaiheaType TaiheConverter::ConverterATxis(const std::string &axisType) -{ - return ohos::multimodalInput::inputDevice::axisType::from_value(axisType); -} - -TaiheSType TaiheConverter::ConverterSourceType(const TaihesType &sType) -{ - TaiheSType result = TaiheSType::make_type(sType); - return result; -} -TaiheAType TaiheConverter::ConverterAxisType(const TaiheaType &aType) -{ - TaiheAType result = TaiheAType::make_type(aType); - return result; -} - -TaiheAxisRange TaiheConverter::ConverterAxisRange(const InputDevice::AxisInfo &axisInfo, - const std::string &sourceType, const std::string &axisType) -{ - TaiheAxisRange result { - .source = ConverterSourceType(ConverterSType(sourceType)), - .axis = ConverterAxisType(ConverterATxis(axisType)), - }; - result.max = axisInfo.GetMaximum(); - result.min = axisInfo.GetMinimum(); - result.fuzz = axisInfo.GetFuzz(); - result.flat = axisInfo.GetFlat(); - result.resolution = axisInfo.GetResolution(); - return result; -} - -TaiheInputDeviceData TaiheConverter::ConverterInputDevice(std::shared_ptr &device) -{ - TaiheInputDeviceData result {}; - if (device == nullptr) { - return result; - } - result.id = device->GetId(); - result.name = device->GetName(); - std::vector vecSourceTypes; - std::string sourceType = ""; - uint32_t types = static_cast(device->GetType()); - for (auto item : g_taiheDeviceType) { - if (types &item.typeBit) { - sourceType = item.sourceTypeName; - vecSourceTypes.push_back(ConverterSourceType(ConverterSType(sourceType))); - } - } - result.sources = taihe::array(vecSourceTypes); - std::string axisType = ""; - std::vector vecAxisRanges; - auto aixsArray = device->GetAxisInfo(); - for (auto item : aixsArray) { - auto iter = g_taiheAxisType.find(item.GetAxisType()); - if (iter != g_taiheAxisType.end()) { - axisType = iter->second; - } - TaiheAxisRange axisRange = ConverterAxisRange(item, sourceType, axisType); - vecAxisRanges.push_back(axisRange); - } - result.axisRanges = taihe::array(vecAxisRanges); - result.bus = device->GetBus(); - result.product = device->GetProduct(); - result.vendor = device->GetVendor(); - result.version = device->GetVersion(); - result.phys = std::string_view(device->GetPhys()); - result.uniq = std::string_view(device->GetUniq()); - return result; - -} - -CustomCursor TaiheConverter::ConverterToCustomCursor(const ohos::multimodalInput::pointer::CustomCursor &value) -{ - CustomCursor cursor; - ani_env *env = taihe::get_env(); - ani_object obj = reinterpret_cast(value.pixelMap); - ani_ref pixelMapAni; - if (ANI_OK != env->Object_GetPropertyByName_Ref(obj, "pixelMap", &pixelMapAni)) { - MMI_HILOGE("get pixelMap failed."); - return cursor; - } - - auto pixelMap = OHOS::Media::PixelMapTaiheAni::GetNativePixelMap(taihe::get_env(), - reinterpret_cast(pixelMapAni)); - if (pixelMap == nullptr) { - MMI_HILOGE("pixelMap is null"); - return cursor; - } - cursor.pixelMap = (void *)pixelMap.get(); - if (value.focusX.has_value()) { - cursor.focusX = static_cast (value.focusX.value()); - } - if (value.focusY.has_value()) { - cursor.focusY = static_cast (value.focusY.value()); - } - return cursor; -} - -CursorOptions TaiheConverter::ConverterToCursorConfig(const ohos::multimodalInput::pointer::CursorConfig &value) -{ - CursorOptions opts; - opts.followSystem = value.followSystem; - return opts; -} - int32_t TaiheConverter::TouchEventToTaihe(const PointerEvent &pointerEvent, TaiheTouchEvent &out) { CALL_DEBUG_ENTER; diff --git a/frameworks/ets/input_consumer/BUILD.gn b/frameworks/ets/input_consumer/BUILD.gn index 4800ccf02f..4c9ab6be77 100644 --- a/frameworks/ets/input_consumer/BUILD.gn +++ b/frameworks/ets/input_consumer/BUILD.gn @@ -18,6 +18,7 @@ import("//foundation/multimodalinput/input/multimodalinput_mini.gni") copy_taihe_idl("input_consumer_taihe") { sources = [ "idl/ohos.multimodalInput.inputConsumer.taihe" ] deps = [ "${mmi_path}/frameworks/ets/key_event:key_event_taihe" ] + deps += [ "${mmi_path}/frameworks/ets/gesture_event:gesture_event_taihe" ] } config("inputConsumer_config") { visibility = [ ":*" ] diff --git a/frameworks/ets/input_device/BUILD.gn b/frameworks/ets/input_device/BUILD.gn index f0a5c128dd..a6a4f792b5 100644 --- a/frameworks/ets/input_device/BUILD.gn +++ b/frameworks/ets/input_device/BUILD.gn @@ -16,7 +16,6 @@ import("//foundation/multimodalinput/input/multimodalinput_mini.gni") copy_taihe_idl("input_device_taihe") { sources = [ "idl/ohos.multimodalInput.inputDevice.taihe" ] deps = [ "${mmi_path}/frameworks/ets/key_code:key_code_taihe" ] - deps += [ "${mmi_path}/frameworks/ets/gesture_event:gesture_event_taihe" ] } config("inputDevice_config") { visibility = [ ":*" ] @@ -51,7 +50,8 @@ taihe_shared_library("InputDevice") { sources += [ "src/ani_constructor.cpp", "src/ohos.multimodalInput.inputDevice.impl.cpp", - "src/taihe_event.cpp" + "src/taihe_event.cpp", + "src/taihe_inputdevice_utils.cpp", ] deps = [ ":run_taihe", diff --git a/frameworks/ets/input_device/include/taihe_inputdevice_utils.h b/frameworks/ets/input_device/include/taihe_inputdevice_utils.h new file mode 100644 index 0000000000..18dd0f88b4 --- /dev/null +++ b/frameworks/ets/input_device/include/taihe_inputdevice_utils.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TAIHE_INPUTDEVICE_UTILS_H +#define TAIHE_INPUTDEVICE_UTILS_H + +#include "ohos.multimodalInput.inputDevice.proj.hpp" +#include "ohos.multimodalInput.inputDevice.impl.hpp" +#include "taihe/runtime.hpp" +#include "taihe/callback.hpp" + +#include "input_device.h" +#include + +namespace OHOS { +namespace MMI { +using TaihesType = ohos::multimodalInput::inputDevice::sourceType; +using TaiheaType = ohos::multimodalInput::inputDevice::axisType; +using TaiheSType = ohos::multimodalInput::inputDevice::SourceType; +using TaiheAType = ohos::multimodalInput::inputDevice::AxisType; +using TaiheAxisRange = ohos::multimodalInput::inputDevice::AxisRange; +using TaiheInputDeviceData = ohos::multimodalInput::inputDevice::InputDeviceData; + +struct DeviceType { + std::string sourceTypeName; + uint32_t typeBit { 0 }; +}; + +class TaiheInputDeviceUtils { +public: + static TaihesType ConverterSType(const std::string &sourceType); + static TaiheaType ConverterATxis(const std::string &axisType); + static TaiheSType ConverterSourceType(const TaihesType &sType); + static TaiheAType ConverterAxisType(const TaiheaType &aType); + static TaiheAxisRange ConverterAxisRange(const InputDevice::AxisInfo &axisInfo, + const std::string &sourceType, const std::string &axisType); + static TaiheInputDeviceData ConverterInputDevice(std::shared_ptr &device); +}; + +} // namespace MMI +} // namespace OHOS + #endif // TAIHE_INPUTDEVICE_UTILS_H \ No newline at end of file diff --git a/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp b/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp index 6409ee4adc..28ce40189d 100644 --- a/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp +++ b/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp @@ -25,6 +25,7 @@ #include #include "ohos.multimodalInput.inputDevice.impl.h" #include "taihe_event.h" +#include "taihe_inputdevice_utils.h" #undef MMI_LOG_TAG #define MMI_LOG_TAG "TaiheInputDeviceImpl" @@ -85,9 +86,9 @@ InputDeviceData GetDeviceAsync(int32_t deviceId) taihe::set_business_error(ret, codeMsg.msg); MMI_HILOGE("failed to get device, code:%{public}d message: %{public}s", ret, codeMsg.msg.c_str()); std::shared_ptr errDevice = nullptr; - return TaiheConverter::ConverterInputDevice(errDevice); + return TaiheInputDeviceUtils::ConverterInputDevice(errDevice); } - return TaiheConverter::ConverterInputDevice(_device); + return TaiheInputDeviceUtils::ConverterInputDevice(_device); } InputDeviceData GetDeviceInfoAsync(int32_t deviceId) @@ -104,9 +105,9 @@ InputDeviceData GetDeviceInfoAsync(int32_t deviceId) taihe::set_business_error(ret, codeMsg.msg); MMI_HILOGE("failed to get device info, code:%{public}d message: %{public}s", ret, codeMsg.msg.c_str()); std::shared_ptr errDevice = nullptr; - return TaiheConverter::ConverterInputDevice(errDevice); + return TaiheInputDeviceUtils::ConverterInputDevice(errDevice); } - return TaiheConverter::ConverterInputDevice(_device); + return TaiheInputDeviceUtils::ConverterInputDevice(_device); } ::taihe::array SupportKeysAsync(int32_t deviceId, taihe::array_view keys) @@ -356,9 +357,9 @@ InputDeviceData GetDeviceInfoSync(int32_t deviceId) taihe::set_business_error(ret, codeMsg.msg); MMI_HILOGE("failed to get device info, code:%{public}d message: %{public}s", ret, codeMsg.msg.c_str()); std::shared_ptr errDevice = nullptr; - return TaiheConverter::ConverterInputDevice(errDevice); + return TaiheInputDeviceUtils::ConverterInputDevice(errDevice); } - return TaiheConverter::ConverterInputDevice(_device); + return TaiheInputDeviceUtils::ConverterInputDevice(_device); } diff --git a/frameworks/ets/input_device/src/taihe_inputdevice_utils.cpp b/frameworks/ets/input_device/src/taihe_inputdevice_utils.cpp new file mode 100644 index 0000000000..5eafc91ac2 --- /dev/null +++ b/frameworks/ets/input_device/src/taihe_inputdevice_utils.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "taihe_inputdevice_utils.h" +#include "define_multimodal.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "TaiheInputDeviceUtils" + +namespace OHOS { +namespace MMI { +constexpr uint32_t EVDEV_TAG_KEYBOARD = (1 << 1); +constexpr uint32_t EVDEV_TAG_MOUSE = (1 << 2); +constexpr uint32_t EVDEV_TAG_TOUCHPAD = (1 << 3); +constexpr uint32_t EVDEV_TAG_TOUCHSCREEN = (1 << 4); +constexpr uint32_t EVDEV_TAG_JOYSTICK = (1 << 6); +constexpr uint32_t EVDEV_TAG_TRACKBALL = (1 << 10); + +DeviceType g_taiheDeviceType[] = { + { "keyboard", EVDEV_TAG_KEYBOARD }, + { "mouse", EVDEV_TAG_MOUSE }, + { "touchpad", EVDEV_TAG_TOUCHPAD }, + { "touchscreen", EVDEV_TAG_TOUCHSCREEN }, + { "joystick", EVDEV_TAG_JOYSTICK }, + { "trackball", EVDEV_TAG_TRACKBALL }, +}; + +std::unordered_map g_taiheAxisType = { + { ABS_MT_TOUCH_MAJOR, "touchmajor" }, + { ABS_MT_TOUCH_MINOR, "touchminor" }, + { ABS_MT_ORIENTATION, "orientation" }, + { ABS_MT_POSITION_X, "x" }, + { ABS_MT_POSITION_Y, "y" }, + { ABS_MT_PRESSURE, "pressure" }, + { ABS_MT_WIDTH_MAJOR, "toolmajor" }, + { ABS_MT_WIDTH_MINOR, "toolminor" }, +}; + +TaihesType TaiheInputDeviceUtils::ConverterSType(const std::string &sourceType) +{ + return ohos::multimodalInput::inputDevice::sourceType::from_value(sourceType); +} + +TaiheaType TaiheInputDeviceUtils::ConverterATxis(const std::string &axisType) +{ + return ohos::multimodalInput::inputDevice::axisType::from_value(axisType); +} + +TaiheSType TaiheInputDeviceUtils::ConverterSourceType(const TaihesType &sType) +{ + TaiheSType result = TaiheSType::make_type(sType); + return result; +} +TaiheAType TaiheInputDeviceUtils::ConverterAxisType(const TaiheaType &aType) +{ + TaiheAType result = TaiheAType::make_type(aType); + return result; +} + +TaiheAxisRange TaiheInputDeviceUtils::ConverterAxisRange(const InputDevice::AxisInfo &axisInfo, + const std::string &sourceType, const std::string &axisType) +{ + TaiheAxisRange result { + .source = ConverterSourceType(ConverterSType(sourceType)), + .axis = ConverterAxisType(ConverterATxis(axisType)), + }; + result.max = axisInfo.GetMaximum(); + result.min = axisInfo.GetMinimum(); + result.fuzz = axisInfo.GetFuzz(); + result.flat = axisInfo.GetFlat(); + result.resolution = axisInfo.GetResolution(); + return result; +} + +TaiheInputDeviceData TaiheInputDeviceUtils::ConverterInputDevice(std::shared_ptr &device) +{ + TaiheInputDeviceData result {}; + if (device == nullptr) { + return result; + } + result.id = device->GetId(); + result.name = device->GetName(); + std::vector vecSourceTypes; + std::string sourceType = ""; + uint32_t types = static_cast(device->GetType()); + for (auto item : g_taiheDeviceType) { + if (types &item.typeBit) { + sourceType = item.sourceTypeName; + vecSourceTypes.push_back(ConverterSourceType(ConverterSType(sourceType))); + } + } + result.sources = taihe::array(vecSourceTypes); + std::string axisType = ""; + std::vector vecAxisRanges; + auto aixsArray = device->GetAxisInfo(); + for (auto item : aixsArray) { + auto iter = g_taiheAxisType.find(item.GetAxisType()); + if (iter != g_taiheAxisType.end()) { + axisType = iter->second; + } + TaiheAxisRange axisRange = ConverterAxisRange(item, sourceType, axisType); + vecAxisRanges.push_back(axisRange); + } + result.axisRanges = taihe::array(vecAxisRanges); + result.bus = device->GetBus(); + result.product = device->GetProduct(); + result.vendor = device->GetVendor(); + result.version = device->GetVersion(); + result.phys = std::string_view(device->GetPhys()); + result.uniq = std::string_view(device->GetUniq()); + return result; +} + +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/pointer/BUILD.gn b/frameworks/ets/pointer/BUILD.gn index a5711751b0..b0445bbd94 100644 --- a/frameworks/ets/pointer/BUILD.gn +++ b/frameworks/ets/pointer/BUILD.gn @@ -15,6 +15,7 @@ import("//build/ohos/taihe_idl/taihe.gni") import("//foundation/multimodalinput/input/multimodalinput_mini.gni") copy_taihe_idl("pointer_taihe") { sources = [ "idl/ohos.multimodalInput.pointer.taihe" ] + deps = [ "${mmi_path}/frameworks/ets/input_device:input_device_taihe", ] } config("pointer_config") { visibility = [ ":*" ] @@ -56,12 +57,13 @@ taihe_shared_library("Pointer") { sources += [ "src/ani_constructor.cpp", "src/ohos.multimodalInput.pointer.impl.cpp", + "src/taihe_pointer_utils.cpp", + "${mmi_path}/frameworks/ets/common/src/ani_common.cpp" ] deps = [ ":run_taihe", "${mmi_path}/frameworks/proxy:libmmi-client", "${mmi_path}/util:libmmi-util", - "${mmi_path}/frameworks/ets/common:ets_inputcommon_package", ] branch_protector_ret = "pac_ret" sanitize = { diff --git a/frameworks/ets/pointer/include/ohos.multimodalInput.pointer.impl.h b/frameworks/ets/pointer/include/ohos.multimodalInput.pointer.impl.h index 54df377c12..5bfc675a3d 100644 --- a/frameworks/ets/pointer/include/ohos.multimodalInput.pointer.impl.h +++ b/frameworks/ets/pointer/include/ohos.multimodalInput.pointer.impl.h @@ -22,6 +22,7 @@ #include "ohos.multimodalInput.pointer.impl.hpp" #include "stdexcept" #include "taihe/runtime.hpp" +#include "ani_common.h" #include diff --git a/frameworks/ets/pointer/include/taihe_pointer_utils.h b/frameworks/ets/pointer/include/taihe_pointer_utils.h new file mode 100644 index 0000000000..3805ba3f0e --- /dev/null +++ b/frameworks/ets/pointer/include/taihe_pointer_utils.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TAIHE_POINTER_UTILS_H +#define TAIHE_POINTER_UTILS_H +#include "ohos.multimodalInput.pointer.proj.hpp" +#include "ohos.multimodalInput.pointer.impl.hpp" +#include "taihe/runtime.hpp" + +#include "pointer_style.h" +namespace OHOS { +namespace MMI { +class TaihePointerUtils { +public: + static CustomCursor ConverterToCustomCursor(const ohos::multimodalInput::pointer::CustomCursor &value); + static CursorOptions ConverterToCursorConfig(const ohos::multimodalInput::pointer::CursorConfig &value); +}; + +} // namespace MMI +} // namespace OHOS +#endif // TAIHE_POINTER_UTILS_H \ No newline at end of file diff --git a/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp b/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp index a8cdf55aab..e18bed1407 100644 --- a/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp +++ b/frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp @@ -16,10 +16,11 @@ #include "ohos.multimodalInput.pointer.impl.h" #include "mmi_log.h" -#include "ani_common.h" +#include "taihe_pointer_utils.h" #include "input_manager.h" #include "struct_multimodal.h" #include "pixel_map_taihe_ani.h" +#include "ani_common.h" #undef MMI_LOG_TAG #define MMI_LOG_TAG "ohos.multimodalInput.pointer" @@ -315,13 +316,13 @@ void SetCustomCursorAsync(int32_t windowId, ::ohos::multimodalInput::pointer::Cu taihe::set_business_error(COMMON_PARAMETER_ERROR, "windowId is invalid"); return; } - auto newCursor = TaiheConverter::ConverterToCustomCursor(cursor); + auto newCursor = TaihePointerUtils::ConverterToCustomCursor(cursor); if (!CheckCustomCursor(newCursor)) { MMI_HILOGE("cursor is invalid"); taihe::set_business_error(COMMON_PARAMETER_ERROR, "cursor is invalid"); return; } - auto options = TaiheConverter::ConverterToCursorConfig(config); + auto options = TaihePointerUtils::ConverterToCursorConfig(config); auto errorCode = InputManager::GetInstance()->SetCustomCursor(windowId, newCursor, options); if (errorCode != RET_OK) { if (errorCode == RET_ERR) { diff --git a/frameworks/ets/pointer/src/taihe_pointer_utils.cpp b/frameworks/ets/pointer/src/taihe_pointer_utils.cpp new file mode 100644 index 0000000000..76faf6e5b8 --- /dev/null +++ b/frameworks/ets/pointer/src/taihe_pointer_utils.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "taihe_pointer_utils.h" +#include "define_multimodal.h" +#include "mmi_log.h" +#include "pixel_map_taihe_ani.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "TaihePointerUtils" + +namespace OHOS { +namespace MMI { +CustomCursor TaihePointerUtils::ConverterToCustomCursor(const ohos::multimodalInput::pointer::CustomCursor &value) +{ + CustomCursor cursor; + ani_env *env = taihe::get_env(); + ani_object obj = reinterpret_cast(value.pixelMap); + ani_ref pixelMapAni; + if (ANI_OK != env->Object_GetPropertyByName_Ref(obj, "pixelMap", &pixelMapAni)) { + MMI_HILOGE("get pixelMap failed."); + return cursor; + } + + auto pixelMap = OHOS::Media::PixelMapTaiheAni::GetNativePixelMap(taihe::get_env(), + reinterpret_cast(pixelMapAni)); + if (pixelMap == nullptr) { + MMI_HILOGE("pixelMap is null"); + return cursor; + } + cursor.pixelMap = (void *)pixelMap.get(); + if (value.focusX.has_value()) { + cursor.focusX = static_cast (value.focusX.value()); + } + if (value.focusY.has_value()) { + cursor.focusY = static_cast (value.focusY.value()); + } + return cursor; +} + +CursorOptions TaihePointerUtils::ConverterToCursorConfig(const ohos::multimodalInput::pointer::CursorConfig &value) +{ + CursorOptions opts; + opts.followSystem = value.followSystem; + return opts; +} + +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/short_key/src/ohos.multimodalInput.shortKey.impl.cpp b/frameworks/ets/short_key/src/ohos.multimodalInput.shortKey.impl.cpp index f4efa7475c..b45ecf63d9 100644 --- a/frameworks/ets/short_key/src/ohos.multimodalInput.shortKey.impl.cpp +++ b/frameworks/ets/short_key/src/ohos.multimodalInput.shortKey.impl.cpp @@ -28,7 +28,6 @@ using namespace taihe; using namespace OHOS::MMI; using namespace ohos::multimodalInput::shortKey; -using TaiheError_t = OHOS::MMI::TaiheError; namespace { constexpr int32_t MAX_DELAY { 4000 }; -- Gitee From 443ca605f12f1104f56af59cfed5989a28ea2e3a Mon Sep 17 00:00:00 2001 From: KangPeng Date: Wed, 6 Aug 2025 11:29:55 +0800 Subject: [PATCH 28/29] ztwfix input build bug Signed-off-by: KangPeng --- BUILD.gn | 1 - frameworks/ets/common/BUILD.gn | 90 -- .../ohos.multimodalInput.inputCommon.taihe | 21 - frameworks/ets/common/include/ani_common.h | 153 +--- frameworks/ets/common/src/ani_common.cpp | 805 ----------------- frameworks/ets/input_consumer/BUILD.gn | 5 +- frameworks/ets/input_device/BUILD.gn | 4 +- frameworks/ets/input_monitor/BUILD.gn | 9 +- .../common/include/ani_input_monitor_common.h | 193 ++++ .../common/src/ani_input_monitor_common.cpp | 830 ++++++++++++++++++ .../include/ani_input_monitor_consumer.h | 2 +- .../src/ani_input_monitor_consumer.cpp | 24 +- .../src/ani_input_monitor_manager.cpp | 2 +- frameworks/ets/pointer/BUILD.gn | 1 - frameworks/ets/short_key/BUILD.gn | 5 +- 15 files changed, 1052 insertions(+), 1093 deletions(-) delete mode 100644 frameworks/ets/common/BUILD.gn delete mode 100644 frameworks/ets/common/idl/ohos.multimodalInput.inputCommon.taihe create mode 100644 frameworks/ets/input_monitor/common/include/ani_input_monitor_common.h create mode 100644 frameworks/ets/input_monitor/common/src/ani_input_monitor_common.cpp diff --git a/BUILD.gn b/BUILD.gn index 7384e906a1..d0e458941e 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -147,7 +147,6 @@ group("input_jsapi_group") { group("input_ets_group") { deps = [ - "frameworks/ets/common:ets_inputcommon_package", "frameworks/ets/input_event:ets_inputEvent_package", "frameworks/ets/intention_code:ets_intentionCode_package", "frameworks/ets/input_monitor:ets_inputMonitor_package", diff --git a/frameworks/ets/common/BUILD.gn b/frameworks/ets/common/BUILD.gn deleted file mode 100644 index c4ec63f58b..0000000000 --- a/frameworks/ets/common/BUILD.gn +++ /dev/null @@ -1,90 +0,0 @@ -# Copyright (c) 2025 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/components/ets_frontend/ets2abc_config.gni") -import("//build/ohos.gni") -import("//build/ohos/taihe_idl/taihe.gni") -import("//foundation/multimodalinput/input/multimodalinput_mini.gni") -copy_taihe_idl("inputani_common_taihe") { - sources = [ "idl/ohos.multimodalInput.inputCommon.taihe" ] - deps = [ - "${mmi_path}/frameworks/ets/mouse_event:mouse_event_taihe", - "${mmi_path}/frameworks/ets/touch_event:touch_event_taihe", - "${mmi_path}/frameworks/ets/short_key:short_key_taihe", - "${mmi_path}/frameworks/ets/key_code:key_code_taihe", - "${mmi_path}/frameworks/ets/input_event:input_event_taihe", - "${mmi_path}/frameworks/ets/gesture_event:gesture_event_taihe", - "${mmi_path}/frameworks/ets/key_event:key_event_taihe", - ] -} -config("inputani_common_config") { - visibility = [ ":*" ] - - include_dirs = [ - "${mmi_path}/interfaces/native/innerkits/proxy/include", - "${mmi_path}/interfaces/native/innerkits/event/include", - "${mmi_path}/util/common/include", - "include", - ] -} -subsystem_name = "multimodalinput" -part_name = "input" -taihe_generated_file_path_inputCommon = "$taihe_file_path/out/$subsystem_name/$part_name/inputani_common" -ohos_taihe("run_taihe") { - taihe_generated_file_path = "${taihe_generated_file_path_inputCommon}" - deps = [ - ":inputani_common_taihe" - ] - outputs = [ - "$taihe_generated_file_path/src/ohos.multimodalInput.inputCommon.ani.cpp", - "$taihe_generated_file_path/src/ohos.multimodalInput.inputCommon.abi.c", - ] -} -taihe_shared_library("inputani_common") { - taihe_generated_file_path = "${taihe_generated_file_path_inputCommon}" - part_name = "$part_name" - subsystem_name = "$subsystem_name" - sources = get_target_outputs(":run_taihe") - configs = [ - "${mmi_path}:coverage_flags", - ":inputani_common_config", - ] - - sources += [ - "src/ani_common.cpp", - ] - deps = [ - ":run_taihe", - "${mmi_path}/frameworks/proxy:libmmi-client", - "${mmi_path}/util:libmmi-util", - ] - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - ] - branch_protector_ret = "pac_ret" - sanitize = { - integer_overflow = true - ubsan = true - boundary_sanitize = true - cfi = true - cfi_cross_dso = true - debug = false - } -} - -group("ets_inputcommon_package") { - deps = [ - ":inputani_common", - ] -} \ No newline at end of file diff --git a/frameworks/ets/common/idl/ohos.multimodalInput.inputCommon.taihe b/frameworks/ets/common/idl/ohos.multimodalInput.inputCommon.taihe deleted file mode 100644 index 8d20f4568f..0000000000 --- a/frameworks/ets/common/idl/ohos.multimodalInput.inputCommon.taihe +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@!namespace("@ohos.multimodalInput.inputCommon", "inputCommon") - - -@!sts_inject(""" -static { loadLibrary("InputCommon.z") } -""") diff --git a/frameworks/ets/common/include/ani_common.h b/frameworks/ets/common/include/ani_common.h index 87a6da67e9..320355ec06 100644 --- a/frameworks/ets/common/include/ani_common.h +++ b/frameworks/ets/common/include/ani_common.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef ANI_INPUT_TAIHE_INPUT_MONITOR_COMMON_H -#define ANI_INPUT_TAIHE_INPUT_MONITOR_COMMON_H +#ifndef ANI_INPUT_TAIHE_COMMON_H +#define ANI_INPUT_TAIHE_COMMON_H #include #include @@ -24,11 +24,7 @@ #include "ohos.multimodalInput.keyCode.proj.hpp" #include "ohos.multimodalInput.keyCode.impl.hpp" -#include "ohos.multimodalInput.mouseEvent.proj.hpp" -#include "ohos.multimodalInput.gestureEvent.proj.hpp" -#include "ohos.multimodalInput.touchEvent.proj.hpp" -#include "ohos.multimodalInput.shortKey.proj.hpp" -#include "ohos.multimodalInput.keyEvent.proj.hpp" + #include "taihe/runtime.hpp" #include "taihe/callback.hpp" @@ -38,49 +34,11 @@ namespace OHOS { namespace MMI { -using MapFun = std::map>; -constexpr int32_t AXIS_TYPE_SCROLL_VERTICAL { 0 }; -constexpr int32_t AXIS_TYPE_SCROLL_HORIZONTAL { 1 }; -constexpr int32_t AXIS_TYPE_PINCH { 2 }; using namespace ohos::multimodalInput::keyCode; -using TaiheAxisValue = ::ohos::multimodalInput::mouseEvent::AxisValue; -using TaiheAxis = ::ohos::multimodalInput::mouseEvent::Axis; -using TaiheInputEvent = ohos::multimodalInput::inputEvent::InputEvent; -using TaiheMouseToolType = ohos::multimodalInput::mouseEvent::ToolType; -using TaiheMouseButton = ::ohos::multimodalInput::mouseEvent::Button; using TaiheKeyCode = ::ohos::multimodalInput::keyCode::KeyCode; -using TaiheMouseEvent = ohos::multimodalInput::mouseEvent::MouseEvent; -using TaiheTouchEvent = ohos::multimodalInput::touchEvent::TouchEvent; -using TaiheTouchEventArray = taihe::array; -using TaiheTouch = ohos::multimodalInput::touchEvent::Touch; -using TaiheTouchAction = ohos::multimodalInput::touchEvent::Action; -using TaiheMouseAction = ohos::multimodalInput::mouseEvent::Action; -using TaiheInputEvent = ohos::multimodalInput::inputEvent::InputEvent; -using TaiheSourceType = ohos::multimodalInput::touchEvent::SourceType; -using TaiheFixedMode = ohos::multimodalInput::touchEvent::FixedMode; -using TaiheToolType = ohos::multimodalInput::touchEvent::ToolType; - -using TaiheRotate = ohos::multimodalInput::gestureEvent::Rotate; -using TaiheTouchGestureAction = ohos::multimodalInput::gestureEvent::TouchGestureAction; -using TaiheGestureActionType = ohos::multimodalInput::gestureEvent::ActionType; -using TaiheSwipeInward = ohos::multimodalInput::gestureEvent::SwipeInward; -using TaiheThreeFingersSwipe = ohos::multimodalInput::gestureEvent::ThreeFingersSwipe; -using TaihePinchEvent = ohos::multimodalInput::gestureEvent::Pinch; -using TaiheFourFingersSwipe = ohos::multimodalInput::gestureEvent::FourFingersSwipe; -using TaiheThreeFingersTap = ohos::multimodalInput::gestureEvent::ThreeFingersTap; -using TaiheTouchGestureEvent = ohos::multimodalInput::gestureEvent::TouchGestureEvent; - -using TaiheFingerprintAction = ohos::multimodalInput::shortKey::FingerprintAction; -using TaiheFingerprintEvent = ohos::multimodalInput::shortKey::FingerprintEvent; - -using TaiheKeyEventAction = ohos::multimodalInput::keyEvent::Action; -using TaiheKeyEvent = ohos::multimodalInput::keyEvent::KeyEvent; -using TaiheKeyEventKey = ohos::multimodalInput::keyEvent::Key; - - struct TaiheError { int32_t errorCode; std::string msg; @@ -834,111 +792,6 @@ public: static bool GetApiError(int32_t code, TaiheError &codeMsg); static KeyCode ConvertEtsKeyCode(int32_t keyCode); static KeyCodeEts GetKeyCodeByValue(const std::map& map, KeyCode code); - // ztw touchEvent 解析 - static int32_t TouchEventToTaihe(const PointerEvent &pointerEvent, TaiheTouchEvent &out); - static int32_t InputEventToTaihe(const InputEvent &inputEvent, TaiheInputEvent &out); - static int32_t TouchActionToTaihe(int32_t action, TaiheTouchAction &out); - static int32_t SourceTypeToTaihe(int32_t sourceType, TaiheSourceType &out); - static int32_t FixedModeToTaihe(PointerEvent::FixedMode fixedMode, TaiheFixedMode &out); - static int32_t TouchToTaihe(const PointerEvent::PointerItem &item, TaiheTouch &out); - - // ztw gestureEvent - static int32_t TouchGestureActionToTaihe(int32_t action, TaiheTouchGestureAction &out); - static int32_t RotateActionToTaihe(int32_t action, TaiheGestureActionType &out); - static int32_t PinchActionToTaihe(int32_t action, TaiheGestureActionType &out); - static int32_t SwipeInwardActionToTaihe(int32_t action, TaiheGestureActionType &out); - static int32_t SwipeActionToTaihe(int32_t action, TaiheGestureActionType &out); - static int32_t MultiTapActionToTaihe(int32_t action, TaiheGestureActionType &out); - - static int32_t RotateToTaihe(const PointerEvent &pointerEvent, TaiheRotate &out); - static int32_t PinchToTaihe(const PointerEvent &pointerEvent, TaihePinchEvent &out); - static int32_t SwipeInwardToTaihe(const PointerEvent &pointerEvent, TaiheSwipeInward &out); - static int32_t ThreeFingersSwipeToTaihe(const PointerEvent &pointerEvent, TaiheThreeFingersSwipe &out); - static int32_t FourFingersSwipeToTaihe(const PointerEvent &pointerEvent, TaiheFourFingersSwipe &out); - // ztw touchscreenSwipe, touchscreenPinch - static int32_t TouchGestureEventToTaihe(const PointerEvent &pointerEvent, TaiheTouchGestureEvent &out); - // ztw fingersTap - static int32_t ThreeFingersTapToTaihe(const PointerEvent &pointerEvent, TaiheThreeFingersTap &out); - // ztw fingerprint -#ifdef OHOS_BUILD_ENABLE_FINGERPRINT - static int32_t FingerprintActionToTaihe(int32_t action, TaiheFingerprintAction &out); - static int32_t FingerprintEventToTaihe(const PointerEvent &pointerEvent, TaiheFingerprintEvent &out); -#endif - // ztw keyPressed - static bool HasKeyCode(const std::vector& pressedKeys, int32_t keyCode); - static int32_t KeyEventActionToTaihe(int32_t action, TaiheKeyEventAction &out); - static int32_t TaiheKeyEventToTaihe(const KeyEvent &keyEvent, TaiheKeyEvent &out); - static int32_t TaiheKeyEventKeyToTaihe(const KeyEvent::KeyItem &keyItem, TaiheKeyEventKey &out); - static int32_t MouseEventToTaihe(std::shared_ptr pointerEvent, TaiheMouseEvent &out); - static int32_t MouseActionToTaihe(int32_t action, TaiheMouseAction &out); -private: - static int32_t GetMousePointerItem(std::shared_ptr pointerEvent, TaiheMouseEvent &mouseEvent); - static int32_t SetMouseProperty(std::shared_ptr& pointerEvent, const PointerEvent::PointerItem& item, TaiheMouseEvent &mouseEvent); - static int32_t GetAxesValue(const std::shared_ptr pointerEvent, TaiheAxisValue& value); - static int32_t GetPressedKey(const std::vector& pressedKeys, TaiheMouseEvent &mouseEvent); -}; - - -using callbackType = std::variant< - taihe::callback, - //taihe::callback, - taihe::callback, - taihe::callback, - taihe::callback, - taihe::callback, - taihe::callback, - taihe::callback, - taihe::callback, - taihe::callback, - taihe::callback, - taihe::callback, - taihe::callback - >; - - -struct CallbackObject { - CallbackObject(callbackType cb, ani_ref ref) : callback(cb), ref(ref) {} - ~CallbackObject() - { - if (auto *env = taihe::get_env()) { - env->GlobalReference_Delete(ref); - } - } - callbackType callback; - ani_ref ref; -}; - -class GlobalRefGuard { - ani_env *env_ = nullptr; - ani_ref ref_ = nullptr; - -public: - GlobalRefGuard(ani_env *env, ani_object obj) : env_(env) - { - if (!env_) { - return; - } - if (ANI_OK != env_->GlobalReference_Create(obj, &ref_)) { - ref_ = nullptr; - } - } - explicit operator bool() const - { - return ref_ != nullptr; - } - ani_ref get() const - { - return ref_; - } - ~GlobalRefGuard() - { - if (env_ && ref_) { - env_->GlobalReference_Delete(ref_); - } - } - - GlobalRefGuard(const GlobalRefGuard &) = delete; - GlobalRefGuard &operator=(const GlobalRefGuard &) = delete; }; } // namespace MMI diff --git a/frameworks/ets/common/src/ani_common.cpp b/frameworks/ets/common/src/ani_common.cpp index ff5cd1b3a0..67c68391f3 100644 --- a/frameworks/ets/common/src/ani_common.cpp +++ b/frameworks/ets/common/src/ani_common.cpp @@ -14,8 +14,6 @@ */ #include "ani_common.h" - -#include "define_multimodal.h" #include "mmi_log.h" #undef MMI_LOG_TAG @@ -51,808 +49,5 @@ KeyCodeEts TaiheConverter::GetKeyCodeByValue(const std::map& m } return KEYCODE_UNKNOWN_ETS; } - -int32_t TaiheConverter::TouchEventToTaihe(const PointerEvent &pointerEvent, TaiheTouchEvent &out) -{ - CALL_DEBUG_ENTER; - auto ret = InputEventToTaihe(pointerEvent, out.base); - if (ret != RET_OK) { - MMI_HILOGE("InputEventToTaihe failed"); - return RET_ERR; - } - ret = TouchActionToTaihe(pointerEvent.GetPointerAction(), out.action); - if (ret!= RET_OK) { - MMI_HILOGE("TouchActionToTaihe failed"); - return RET_ERR; - } - // 这个需要更新新代码 ---touchEvent taihe定义 - // result.isInject = pointerEventItem->HasFlag(InputEvent::EVENT_FLAG_SIMULATE); - std::vector vecTouches; - for (auto item : pointerEvent.GetPointerIds()) { - PointerEvent::PointerItem pointerItem; - if (!pointerEvent.GetPointerItem(item, pointerItem)) { - MMI_HILOGE("Get pointer item failed"); - return ret; - } - if (pointerItem.GetPointerId() == pointerEvent.GetPointerId()) { - ret = TouchToTaihe(pointerItem, out.touch); - if (ret!= RET_OK) { - MMI_HILOGE("TouchToTaihe failed"); - return RET_ERR; - } - } - auto taiheTouch = TaiheTouch {.toolType = TaiheToolType::key_t::FINGER}; - ret = TouchToTaihe(pointerItem, taiheTouch); - if (ret!= RET_OK) { - MMI_HILOGE("TouchToTaihe failed"); - return RET_ERR; - } - vecTouches.push_back(taiheTouch); - } - out.touches = taihe::array(vecTouches); - ret = SourceTypeToTaihe(pointerEvent.GetSourceType(), out.sourceType); - if (ret!= RET_OK) { - MMI_HILOGE("SourceTypeToTaihe failed"); - return RET_ERR; - } - auto fixedmode = TaiheFixedMode::from_value(RET_ERR); - ret = FixedModeToTaihe(pointerEvent.GetFixedMode(), fixedmode); - if (ret!= RET_OK) { - MMI_HILOGE("FixedModeToTaihe failed"); - return RET_ERR; - } - out.fixedMode = taihe::optional(std::in_place_t{}, fixedmode); - return ret; -} - -int32_t TaiheConverter::InputEventToTaihe(const InputEvent &inputEvent, TaiheInputEvent &out) -{ - out.id = inputEvent.GetId(); - out.deviceId = inputEvent.GetDeviceId(); - out.actionTime = inputEvent.GetActionTime(); - out.screenId = inputEvent.GetTargetDisplayId(); - out.windowId = inputEvent.GetTargetWindowId(); - return RET_OK; -} - -int32_t TaiheConverter::TouchActionToTaihe(int32_t action, TaiheTouchAction &out) { - bool ret = RET_OK; - switch (action) { - case PointerEvent::POINTER_ACTION_CANCEL: { - out = TaiheTouchAction::key_t::CANCEL; - break; - } - case PointerEvent::POINTER_ACTION_DOWN: { - out = TaiheTouchAction::key_t::DOWN; - break; - } - case PointerEvent::POINTER_ACTION_MOVE: { - out = TaiheTouchAction::key_t::MOVE; - break; - } - case PointerEvent::POINTER_ACTION_UP: { - out = TaiheTouchAction::key_t::UP; - break; - } - // ztw 代码中没有定义 - // case PointerEvent::POINTER_ACTION_PULL_DOWN: { - // return TaiheTouchAction::key_t::PULL_DOWN; - // } - // case PointerEvent::POINTER_ACTION_PULL_MOVE: { - // return TaiheTouchAction::key_t::PULL_MOVE; - // } - // case PointerEvent::POINTER_ACTION_PULL_UP: { - // return TaiheTouchAction::key_t::PULL_UP; - // } - default: { - ret = RET_ERR; - } - } - return ret; -} - -int32_t TaiheConverter::SourceTypeToTaihe(int32_t sourceType, TaiheSourceType &out) -{ - auto ret = RET_OK; - switch (sourceType) { - case PointerEvent::SOURCE_TYPE_TOUCHSCREEN: { - out = TaiheSourceType::key_t::TOUCH_SCREEN; - break; - } - case PointerEvent::SOURCE_TYPE_TOUCHPAD: { - out = TaiheSourceType::key_t::TOUCH_PAD; - break; - } - // ztw 代码中少实现 - // case PointerEvent::SOURCE_TYPE_PEN: { - // return TaiheTouchAction::key_t::PEN; - // } - default: { - ret = RET_ERR; - } - } - return ret; -} - -int32_t TaiheConverter::FixedModeToTaihe(PointerEvent::FixedMode fixedMode, TaiheFixedMode &out) -{ - auto ret = RET_OK; - switch (fixedMode) { - case PointerEvent::FixedMode::SCREEN_MODE_UNKNOWN: { - out = TaiheFixedMode::key_t::NONE; - break; - } - case PointerEvent::FixedMode::AUTO: { - out = TaiheFixedMode::key_t::AUTO; - break; - } - // ztw 代码中少实现 - // case PointerEvent::SOURCE_TYPE_TOUCHPAD: { - // return TaiheTouchAction::key_t::PEN; - // } - default: { - ret = RET_ERR; - } - } - return ret; -} - -// TaiheTouch obj{.toolType = TaiheToolType::key_t::FINGER}; -int32_t TaiheConverter::TouchToTaihe(const PointerEvent::PointerItem &item, TaiheTouch &out) -{ - out.id = item.GetPointerId(); - out.pressedTime = item.GetDownTime(); - out.screenX = item.GetDisplayX(); - out.screenY = item.GetDisplayY(); - // ztw taihe 中没有定义 - // obj.globalX = static_cast(item.GetGlobalX()); - // obj.globalY = static_cast(item.GetGlobalY()); - out.windowX = item.GetWindowX(); - out.windowY = item.GetWindowY(); - out.pressure = item.GetPressure(); - out.width = item.GetWidth(); - out.height = item.GetHeight(); - out.tiltX = item.GetTiltX(); - out.tiltY = item.GetTiltY(); - out.toolX = item.GetToolDisplayX(); - out.toolY = item.GetToolDisplayY(); - out.toolWidth = item.GetToolWidth(); - out.toolHeight = item.GetToolHeight(); - out.rawX = item.GetRawDx(); - out.rawY = item.GetRawDy(); - out.toolType.from_value(item.GetToolType()); - out.fixedDisplayX = taihe::optional(std::in_place_t{}, item.GetFixedDisplayX()); - out.fixedDisplayY = taihe::optional(std::in_place_t{}, item.GetFixedDisplayY()); - return RET_OK; -} - -int32_t TaiheConverter::TouchGestureActionToTaihe(int32_t action, TaiheTouchGestureAction &out) -{ - auto ret = RET_OK; - switch (action) { - case PointerEvent::TOUCH_ACTION_SWIPE_DOWN: { - out = TaiheTouchGestureAction::key_t::SWIPE_DOWN; - break; - } - case PointerEvent::TOUCH_ACTION_SWIPE_UP: { - out = TaiheTouchGestureAction::key_t::SWIPE_UP; - break; - } - case PointerEvent::TOUCH_ACTION_SWIPE_RIGHT: { - out = TaiheTouchGestureAction::key_t::SWIPE_RIGHT; - break; - } - case PointerEvent::TOUCH_ACTION_SWIPE_LEFT: { - out = TaiheTouchGestureAction::key_t::SWIPE_LEFT; - break; - } - case PointerEvent::TOUCH_ACTION_PINCH_OPENED: { - out = TaiheTouchGestureAction::key_t::PINCH_OPENED; - break; - } - case PointerEvent::TOUCH_ACTION_PINCH_CLOSEED: { - out = TaiheTouchGestureAction::key_t::PINCH_CLOSED; - break; - } - case PointerEvent::TOUCH_ACTION_GESTURE_END: { - out = TaiheTouchGestureAction::key_t::GESTURE_END; - break; - } - default: { - MMI_HILOGW("unknow action, action:%{public}d", action); - ret = RET_ERR; - } - } - return ret; -} - -int32_t TaiheConverter::RotateActionToTaihe(int32_t action, TaiheGestureActionType &out) -{ - auto ret = RET_OK; - switch (action) { - case PointerEvent::POINTER_ACTION_ROTATE_BEGIN: { - out = TaiheGestureActionType::key_t::BEGIN; - break; - } - case PointerEvent::POINTER_ACTION_ROTATE_UPDATE: { - out = TaiheGestureActionType::key_t::UPDATE; - break; - } - case PointerEvent::POINTER_ACTION_ROTATE_END: { - out = TaiheGestureActionType::key_t::END; - break; - } - default: { - MMI_HILOGD("Abnormal pointer action in rotate event"); - ret = RET_ERR; - } - } - return ret; -} - -int32_t TaiheConverter::PinchActionToTaihe(int32_t action, TaiheGestureActionType &out) -{ - auto ret = RET_OK; - switch (action) { - case PointerEvent::POINTER_ACTION_AXIS_BEGIN: { - out = TaiheGestureActionType::key_t::BEGIN; - break; - } - case PointerEvent::POINTER_ACTION_AXIS_UPDATE: { - out = TaiheGestureActionType::key_t::UPDATE; - break; - } - case PointerEvent::POINTER_ACTION_AXIS_END: { - out = TaiheGestureActionType::key_t::END; - break; - } - default: { - MMI_HILOGD("Abnormal pointer action in pinch event"); - ret = RET_ERR; - } - } - return ret; -} - -int32_t TaiheConverter::SwipeInwardActionToTaihe(int32_t action, TaiheGestureActionType &out) -{ - auto ret = RET_OK; - switch (action) { - case PointerEvent::POINTER_ACTION_DOWN: { - out = TaiheGestureActionType::key_t::BEGIN; - break; - } - case PointerEvent::POINTER_ACTION_MOVE: { - out = TaiheGestureActionType::key_t::UPDATE; - break; - } - case PointerEvent::POINTER_ACTION_UP: - case PointerEvent::POINTER_ACTION_CANCEL: { - out = TaiheGestureActionType::key_t::END; - break; - } - default: { - MMI_HILOGE("Abnormal pointer action in swipe event"); - ret = RET_ERR; - } - } - return ret; -} - -int32_t TaiheConverter::SwipeActionToTaihe(int32_t action, TaiheGestureActionType &out) -{ - auto ret = RET_OK; - switch (action) { - case PointerEvent::POINTER_ACTION_SWIPE_BEGIN: { - out = TaiheGestureActionType::key_t::BEGIN; - break; - } - case PointerEvent::POINTER_ACTION_SWIPE_UPDATE: { - out = TaiheGestureActionType::key_t::UPDATE; - break; - } - case PointerEvent::POINTER_ACTION_SWIPE_END: { - out = TaiheGestureActionType::key_t::END; - break; - } - default: { - MMI_HILOGD("Abnormal pointer action in swipe event"); - ret = RET_ERR; - } - } - return ret; -} - -int32_t TaiheConverter::MultiTapActionToTaihe(int32_t action, TaiheGestureActionType &out) -{ - auto ret = RET_OK; - switch (action) { - case PointerEvent::POINTER_ACTION_TRIPTAP: { - out = TaiheGestureActionType::key_t::END; - break; - } - default: { - MMI_HILOGD("Abnormal pointer action in multi tap event"); - ret = RET_ERR; - } - } - return ret; -} - -// TaiheRotate obj {.type = RotateActionToTaihe(pointerEvent.GetPointerAction())}; -int32_t TaiheConverter::RotateToTaihe(const PointerEvent &pointerEvent, TaiheRotate &out) -{ - auto type = TaiheGestureActionType::from_value(RET_ERR); - auto ret = RotateActionToTaihe(pointerEvent.GetPointerAction(), type); - if (ret != RET_OK) { - return ret; - } - out.type = type; - out.angle = pointerEvent.GetAxisValue(PointerEvent::AXIS_TYPE_ROTATE); - return ret; - -} - -int32_t TaiheConverter::PinchToTaihe(const PointerEvent &pointerEvent, TaihePinchEvent &out) -{ - auto type = TaiheGestureActionType::from_value(RET_ERR); - auto ret = PinchActionToTaihe(pointerEvent.GetPointerAction(), type); - if (ret != RET_OK) { - return ret; - } - out.type = type; - out.scale = pointerEvent.GetAxisValue(PointerEvent::AXIS_TYPE_PINCH); - return ret; - -} - -int32_t TaiheConverter::SwipeInwardToTaihe(const PointerEvent &pointerEvent, TaiheSwipeInward &out) -{ - auto type = TaiheGestureActionType::from_value(RET_ERR); - auto ret = SwipeActionToTaihe(pointerEvent.GetPointerAction(), type); - if (ret != RET_OK) { - return ret; - } - out.type = type; - PointerEvent::PointerItem pointeritem; - int32_t pointerId = 0; - ret = pointerEvent.GetPointerItem(pointerId, pointeritem); - if (ret != RET_OK) { - MMI_HILOGE("Can't find this pointerItem"); - return ret; - } - out.x = pointeritem.GetDisplayX(); - out.y = pointeritem.GetDisplayY(); - return ret; - -} - -int32_t TaiheConverter::ThreeFingersSwipeToTaihe(const PointerEvent &pointerEvent, TaiheThreeFingersSwipe &out) -{ - //TaiheThreeFingersSwipe obj {.type = }; - auto type = TaiheGestureActionType::from_value(RET_ERR); - auto ret = SwipeActionToTaihe(pointerEvent.GetPointerAction(), type); - if (ret != RET_OK) { - MMI_HILOGE("SwipeActionToTaihe error"); - return ret; - } - out.type = type; - PointerEvent::PointerItem pointeritem; - int32_t pointerId = 0; - ret = pointerEvent.GetPointerItem(pointerId, pointeritem); - if (ret != RET_OK) { - MMI_HILOGE("Can't find this pointerItem"); - return ret; - } - out.x = pointeritem.GetDisplayX(); - out.y = pointeritem.GetDisplayY(); - return ret; -} - -int32_t TaiheConverter::FourFingersSwipeToTaihe(const PointerEvent &pointerEvent, TaiheFourFingersSwipe &out) -{ - // TaiheFourFingersSwipe obj {.type = SwipeActionToTaihe(pointerEvent.GetPointerAction())}; - auto type = TaiheGestureActionType::from_value(RET_ERR); - auto ret = SwipeActionToTaihe(pointerEvent.GetPointerAction(), type); - if (ret != RET_OK) { - MMI_HILOGE("SwipeActionToTaihe error"); - return ret; - } - out.type = type; - PointerEvent::PointerItem pointeritem; - int32_t pointerId = 0; - ret = pointerEvent.GetPointerItem(pointerId, pointeritem); - if (ret != RET_OK) { - MMI_HILOGE("Can't find this pointerItem"); - return ret; - } - out.x = pointeritem.GetDisplayX(); - out.y = pointeritem.GetDisplayY(); - return ret; -} - -int32_t TaiheConverter::TouchGestureEventToTaihe(const PointerEvent &pointerEvent, TaiheTouchGestureEvent &out) -{ - auto action = TaiheTouchGestureAction::from_value(RET_ERR); - auto ret = TouchGestureActionToTaihe(pointerEvent.GetPointerAction(), action); - if (ret != RET_OK) { - MMI_HILOGE("TouchGestureActionToTaihe error"); - return ret; - } - out.action = action; - std::vector vecTouches; - for (auto item : pointerEvent.GetPointerIds()) { - PointerEvent::PointerItem pointerItem; - ret = pointerEvent.GetPointerItem(item, pointerItem); - if (ret != RET_OK) { - MMI_HILOGE("Get pointer item failed"); - return ret; - } - TaiheTouch per {.toolType = TaiheToolType::key_t::FINGER}; - ret = TouchToTaihe(pointerItem, per); - if (ret != RET_OK) { - MMI_HILOGE("TouchToTaihe failed"); - return ret; - } - vecTouches.push_back(per); - } - out.touches = taihe::array(vecTouches); - return ret; -} - -int32_t TaiheConverter::ThreeFingersTapToTaihe(const PointerEvent &pointerEvent, TaiheThreeFingersTap &out) -{ - auto type = TaiheGestureActionType::from_value(RET_ERR); - auto ret = MultiTapActionToTaihe(pointerEvent.GetPointerAction(), type); - if (ret != RET_OK) { - MMI_HILOGE("SwipeActionToTaihe error"); - return ret; - } - out.type = type; - return ret; -} - -#ifdef OHOS_BUILD_ENABLE_FINGERPRINT -int32_t TaiheConverter::FingerprintActionToTaihe(int32_t action, TaiheFingerprintAction &out) -{ - auto ret = RET_OK; - switch (action) { - case PointerEvent::POINTER_ACTION_FINGERPRINT_DOWN: { - out = TaiheFingerprintAction::key_t::DOWN; - break; - } - case PointerEvent::POINTER_ACTION_FINGERPRINT_UP: { - out = TaiheFingerprintAction::key_t::UP; - break; - } - case PointerEvent::POINTER_ACTION_FINGERPRINT_SLIDE: { - out = TaiheFingerprintAction::key_t::SLIDE; - break; - } - case PointerEvent::POINTER_ACTION_FINGERPRINT_RETOUCH: { - out = TaiheFingerprintAction::key_t::RETOUCH; - break; - } - case PointerEvent::POINTER_ACTION_FINGERPRINT_CLICK: { - out = TaiheFingerprintAction::key_t::CLICK; - break; - } - /* // ztw 接口定义中没找到 - case PointerEvent::POINTER_ACTION_FINGERPRINT_CANCEL: { - return FINGERPRINT_CANCEL; - } - case PointerEvent::POINTER_ACTION_FINGERPRINT_HOLD: { - return FINGERPRINT_HOLD; - } - case PointerEvent::POINTER_ACTION_FINGERPRINT_TOUCH: { - return FINGERPRINT_TOUCH; - } */ - default: { - MMI_HILOGE("Wrong action is %{public}d", action); - ret = RET_ERR; - } - } -} - -int32_t TaiheConverter::FingerprintEventToTaihe(const PointerEvent &pointerEvent, TaiheFingerprintEvent &out) -{ - // TaiheFingerprintEvent obj {.action = FingerprintActionToTaihe(pointerEvent.GetPointerAction())}; - auto type = TaiheFingerprintAction::from_value(RET_ERR); - auto ret = FingerprintActionToTaihe(pointerEvent.GetPointerAction(), type); - if (ret != RET_OK) { - MMI_HILOGE("TouchGestureActionToTaihe error"); - return ret; - } - out.action = type; - out.distanceX = pointerEvent.GetFingerprintDistanceX(); - out.distanceY = pointerEvent.GetFingerprintDistanceY(); - return ret; -} -#endif - -bool TaiheConverter::HasKeyCode(const std::vector& pressedKeys, int32_t keyCode) -{ - return std::find(pressedKeys.begin(), pressedKeys.end(), keyCode) != pressedKeys.end(); -} - -int32_t TaiheConverter::KeyEventActionToTaihe(int32_t action, TaiheKeyEventAction &out) -{ - auto ret = RET_OK; - if (KeyEvent::KEY_ACTION_CANCEL == action) { - out = TaiheKeyEventAction::key_t::CANCEL; - } else if (KeyEvent::KEY_ACTION_DOWN == action) { - out = TaiheKeyEventAction::key_t::DOWN; - } else if (KeyEvent::KEY_ACTION_UP == action) { - out = TaiheKeyEventAction::key_t::UP; - } else { - ret = RET_ERR; - } - return ret; -} - -int32_t TaiheConverter::TaiheKeyEventToTaihe(const KeyEvent &keyEvent, TaiheKeyEvent &out) -{ - auto action = TaiheKeyEventAction::from_value(RET_ERR); - auto ret = KeyEventActionToTaihe(keyEvent.GetKeyAction(), action); - if (ret != RET_OK) { - MMI_HILOGE("TaiheKeyEventToTaihe error"); - return ret; - } - std::optional keyItem = keyEvent.GetKeyItem(); - if (!keyItem) { - MMI_HILOGE("The keyItem is nullopt"); - ret = RET_ERR; - return ret; - } - ret = TaiheKeyEventKeyToTaihe(keyItem.value(), out.key); - if (ret != RET_OK) { - MMI_HILOGE("TaiheKeyEventKeyToTaihe error"); - return ret; - } - out.unicodeChar = keyItem->GetUnicode(); - std::vector pressedKeys = keyEvent.GetPressedKeys(); - std::vector keys; - for (const auto &pressedKeyCode : pressedKeys) { - std::optional pressedKeyItem = keyEvent.GetKeyItem(pressedKeyCode); - if (!pressedKeyItem) { - ret = RET_ERR; - MMI_HILOGE("The pressedKeyItem is nullopt"); - return ret; - } - auto taiheKey = TaiheKeyEventKey{ .code = KeyCode::key_t::KEYCODE_UNKNOWN }; - ret = TaiheKeyEventKeyToTaihe(pressedKeyItem.value(), taiheKey); - if (ret != RET_OK) { - MMI_HILOGE("TaiheKeyEventKeyToTaihe error"); - return ret; - } - keys.push_back(taiheKey); - } - out.keys = taihe::array(keys); - ret = InputEventToTaihe(keyEvent, out.base); - if (ret != RET_OK) { - MMI_HILOGE("TaiheKeyEventKeyToTaihe error"); - return ret; - } - ret = InputEventToTaihe(keyEvent, out.base); - if (ret != RET_OK) { - MMI_HILOGE("InputEventToTaihe error"); - return ret; - } - out.ctrlKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_LEFT) - || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_RIGHT); - out.altKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_ALT_LEFT) - || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_ALT_RIGHT);; - out.shiftKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_SHIFT_LEFT) - || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_SHIFT_RIGHT); - out.logoKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_META_LEFT) - || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_META_RIGHT); - out.fnKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_FN); - out.capsLock = keyEvent.GetFunctionKey(KeyEvent::CAPS_LOCK_FUNCTION_KEY); - out.numLock = keyEvent.GetFunctionKey(KeyEvent::NUM_LOCK_FUNCTION_KEY); - out.scrollLock = keyEvent.GetFunctionKey(KeyEvent::SCROLL_LOCK_FUNCTION_KEY); - return ret; - -} - -int32_t TaiheConverter::TaiheKeyEventKeyToTaihe(const KeyEvent::KeyItem &keyItem, TaiheKeyEventKey &out) -{ - auto ret = RET_OK; - out.code = ConvertEtsKeyCode(keyItem.GetKeyCode()); - out.pressedTime = keyItem.GetDownTime(); - out.deviceId = keyItem.GetDeviceId(); - return ret; -} - -int32_t TaiheConverter::SetMouseProperty(std::shared_ptr& pointerEvent, const PointerEvent::PointerItem& item, TaiheMouseEvent &mouseEvent) -{ - int32_t ret = RET_OK; - int32_t buttonId = pointerEvent->GetButtonId(); - if (buttonId == PointerEvent::MOUSE_BUTTON_MIDDLE) { - buttonId = TH_MOUSE_BUTTON::JS_MOUSE_BUTTON_MIDDLE; - } else if (buttonId == PointerEvent::MOUSE_BUTTON_RIGHT) { - buttonId = TH_MOUSE_BUTTON::JS_MOUSE_BUTTON_RIGHT; - } - - mouseEvent.button = TaiheMouseButton::key_t(buttonId); - mouseEvent.base.actionTime = pointerEvent->GetActionTime(); - mouseEvent.base.deviceId = item.GetDeviceId(); - mouseEvent.base.screenId = pointerEvent->GetTargetDisplayId(); - mouseEvent.base.windowId = pointerEvent->GetTargetWindowId(); - mouseEvent.base.deviceId = item.GetDeviceId(); - mouseEvent.screenX = item.GetDisplayX(); - mouseEvent.screenY = item.GetDisplayY(); - mouseEvent.windowX = item.GetWindowX(); - mouseEvent.windowY = item.GetWindowY(); - mouseEvent.rawDeltaX = item.GetRawDx(); - mouseEvent.rawDeltaY = item.GetRawDy(); - // ztw 接口没有定义 - // mouseEvent.globalX = optional<>(std::in_place, static_cast(item.GetGlobalX())); - // mouseEvent.globalY = optional<>(std::in_place, static_cast(item.GetGlobalY())); - // ztw 多模代码中没找实现 - // mouseEvent.capsLock = HasKeyCode(pressedKeys, KeyEvent::CAPS_LOCK_FUNCTION_KEY); - // mouseEvent.numLock = HasKeyCode(pressedKeys, KeyEvent::NUM_LOCK_FUNCTION_KEY); - // mouseEvent.scrollLock = HasKeyCode(pressedKeys, KeyEvent::SCROLL_LOCK_FUNCTION_KEY); - // mouseEvent.toolType - - return ret; -} - -int32_t TaiheConverter::GetAxesValue(const std::shared_ptr pointerEvent, TaiheAxisValue& value) -{ - double axisValue = -1.0; - int32_t axis = -1; - if (pointerEvent->HasAxis(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL)) { - axisValue = pointerEvent->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL); - axis = AXIS_TYPE_SCROLL_VERTICAL; - } - if (pointerEvent->HasAxis(PointerEvent::AXIS_TYPE_SCROLL_HORIZONTAL)) { - axisValue = pointerEvent->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_HORIZONTAL); - axis = AXIS_TYPE_SCROLL_HORIZONTAL; - } - if (pointerEvent->HasAxis(PointerEvent::AXIS_TYPE_PINCH)) { - axisValue = pointerEvent->GetAxisValue(PointerEvent::AXIS_TYPE_PINCH); - axis = AXIS_TYPE_PINCH; - } - - value.axis = TaiheAxis::key_t(axis) ; - value.value = axisValue; - - return RET_OK; -} - -int32_t TaiheConverter::GetMousePointerItem(std::shared_ptr pointerEvent, TaiheMouseEvent &mouseEvent) -{ - int32_t ret = RET_OK; - int32_t currentPointerId = pointerEvent->GetPointerId(); - std::vector axisValueVec; - std::vector pointerIds { pointerEvent->GetPointerIds() }; - for (const auto& pointerId : pointerIds) { - if (pointerId == currentPointerId) { - PointerEvent::PointerItem item; - if (!pointerEvent->GetPointerItem(pointerId, item)) { - MMI_HILOGE("Invalid pointer:%{public}d", pointerId); - ret = RET_ERR; - return ret; - } - mouseEvent.base.id = currentPointerId; - SetMouseProperty(pointerEvent, item, mouseEvent); - } - - TaiheAxisValue value = {.axis = TaiheAxis::key_t(0), .value = 0}; - GetAxesValue(pointerEvent, value); - axisValueVec.push_back(value); - } - - mouseEvent.axes = taihe::array(axisValueVec); - return ret; -} - -int32_t TaiheConverter::GetPressedKey(const std::vector& pressedKeys, TaiheMouseEvent &mouseEvent) -{ - int32_t ret = RET_OK; - bool isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_LEFT) - || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_RIGHT); - mouseEvent.ctrlKey = isExists; - - isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_ALT_LEFT) - || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_ALT_RIGHT); - mouseEvent.altKey = isExists; - - isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_SHIFT_LEFT) - || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_SHIFT_RIGHT); - mouseEvent.shiftKey = isExists; - - isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_META_LEFT) - || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_META_RIGHT); - mouseEvent.logoKey = isExists; - - isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_FN); - mouseEvent.fnKey = isExists; - return ret; -} - -int32_t TaiheConverter::MouseActionToTaihe(int32_t action, TaiheMouseAction &out) { - int32_t ret = RET_OK; - switch (action) { - case PointerEvent::POINTER_ACTION_CANCEL: { - out = TaiheMouseAction::key_t::CANCEL; - break; - } - case PointerEvent::POINTER_ACTION_MOVE: - case PointerEvent::POINTER_ACTION_PULL_MOVE: { - out = TaiheMouseAction::key_t::MOVE; - break; - } - case PointerEvent::POINTER_ACTION_BUTTON_DOWN: - case PointerEvent::POINTER_ACTION_PULL_DOWN: { - out = TaiheMouseAction::key_t::BUTTON_DOWN; - break; - } - case PointerEvent::POINTER_ACTION_BUTTON_UP: - case PointerEvent::POINTER_ACTION_PULL_UP: { - out = TaiheMouseAction::key_t::BUTTON_UP; - break; - } - case PointerEvent::POINTER_ACTION_AXIS_BEGIN: { - out = TaiheMouseAction::key_t::AXIS_BEGIN; - break; - } - case PointerEvent::POINTER_ACTION_AXIS_UPDATE: { - out = TaiheMouseAction::key_t::AXIS_UPDATE; - break; - } - case PointerEvent::POINTER_ACTION_AXIS_END: { - out = TaiheMouseAction::key_t::AXIS_END; - break; - } - default: { - MMI_HILOGD("Abnormal pointer action"); - ret = RET_ERR; - } - // ztw 少了 接口层ACTION_DOWN, ACTION_UP, - } - return ret; -} - -int32_t TaiheConverter::MouseEventToTaihe(std::shared_ptr pointerEvent, TaiheMouseEvent &out) -{ - int32_t ret = MouseActionToTaihe(pointerEvent->GetPointerAction(), out.action); - if (ret != RET_OK) { - return ret; - } - std::vector pressedKeys = pointerEvent->GetPressedKeys(); - std::vector pressedKeysVec; - for(auto& value: pressedKeys) { - TaiheKeyCode code = TaiheKeyCode::key_t(value); - pressedKeysVec.push_back(code); - } - out.pressedKeys = taihe::array(pressedKeysVec); - - ret = GetPressedKey(pressedKeys, out); - if (ret != RET_OK) { - MMI_HILOGE("Get singlePressedKey failed"); - return ret; - } - ret = GetMousePointerItem(pointerEvent, out); - if (ret != RET_OK) { - MMI_HILOGE("Get item of mousePointer failed"); - return ret; - } - std::set pressedButtons = pointerEvent->GetPressedButtons(); - std::vector pressedButtonsVec; - for(auto& item : pressedButtons) { - auto buttonId = TaiheMouseButton::key_t(item); - if (item == PointerEvent::MOUSE_BUTTON_MIDDLE) { - buttonId = TaiheMouseButton::key_t::MIDDLE; - } else if (item == PointerEvent::MOUSE_BUTTON_RIGHT) { - buttonId = TaiheMouseButton::key_t::RIGHT; - } - pressedButtonsVec.push_back(buttonId); - } - - out.pressedButtons = taihe::array(pressedButtonsVec); - return ret; -} - } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/input_consumer/BUILD.gn b/frameworks/ets/input_consumer/BUILD.gn index 4c9ab6be77..d4b9ef6bf1 100644 --- a/frameworks/ets/input_consumer/BUILD.gn +++ b/frameworks/ets/input_consumer/BUILD.gn @@ -18,7 +18,6 @@ import("//foundation/multimodalinput/input/multimodalinput_mini.gni") copy_taihe_idl("input_consumer_taihe") { sources = [ "idl/ohos.multimodalInput.inputConsumer.taihe" ] deps = [ "${mmi_path}/frameworks/ets/key_event:key_event_taihe" ] - deps += [ "${mmi_path}/frameworks/ets/gesture_event:gesture_event_taihe" ] } config("inputConsumer_config") { visibility = [ ":*" ] @@ -58,13 +57,13 @@ taihe_shared_library("InputConsumer") { "src/inputConsumer_keyOptions_impl.cpp", "src/inputConsumer_hotkeyOptions_impl.cpp", "src/inputConsumer_keyPressed_impl.cpp", + "${mmi_path}/frameworks/ets/common/src/ani_common.cpp", "${mmi_path}/frameworks/ets/key_code/src/ohos.multimodalInput.keyCode.impl.cpp", ] deps = [ ":run_taihe", "${mmi_path}/frameworks/proxy:libmmi-client", - "${mmi_path}/util:libmmi-util", - "${mmi_path}/frameworks/ets/common:ets_inputcommon_package", + "${mmi_path}/util:libmmi-util" ] branch_protector_ret = "pac_ret" sanitize = { diff --git a/frameworks/ets/input_device/BUILD.gn b/frameworks/ets/input_device/BUILD.gn index a6a4f792b5..884e1625d1 100644 --- a/frameworks/ets/input_device/BUILD.gn +++ b/frameworks/ets/input_device/BUILD.gn @@ -52,12 +52,12 @@ taihe_shared_library("InputDevice") { "src/ohos.multimodalInput.inputDevice.impl.cpp", "src/taihe_event.cpp", "src/taihe_inputdevice_utils.cpp", + "${mmi_path}/frameworks/ets/common/src/ani_common.cpp" ] deps = [ ":run_taihe", "${mmi_path}/frameworks/proxy:libmmi-client", - "${mmi_path}/util:libmmi-util", - "${mmi_path}/frameworks/ets/common:ets_inputcommon_package", + "${mmi_path}/util:libmmi-util" ] external_deps = [ "c_utils:utils", diff --git a/frameworks/ets/input_monitor/BUILD.gn b/frameworks/ets/input_monitor/BUILD.gn index c44a3f170a..59f4d56505 100644 --- a/frameworks/ets/input_monitor/BUILD.gn +++ b/frameworks/ets/input_monitor/BUILD.gn @@ -29,6 +29,7 @@ config("inputMonitor_config") { visibility = [ ":*" ] include_dirs = [ + "common/include", "${mmi_path}/interfaces/native/innerkits/proxy/include", "${mmi_path}/interfaces/native/innerkits/event/include", "${mmi_path}/service/permission_helper/include", @@ -59,17 +60,17 @@ taihe_shared_library("InputMonitor") { ] sources += [ + "common/src/ani_input_monitor_common.cpp", + "${mmi_path}/frameworks/ets/common/src/ani_common.cpp", "src/ani_constructor.cpp", "src/ani_input_monitor_consumer.cpp", "src/ani_input_monitor_manager.cpp", - "src/ohos.multimodalInput.inputMonitor.impl.cpp" + "src/ohos.multimodalInput.inputMonitor.impl.cpp", ] deps = [ ":run_taihe", "${mmi_path}/frameworks/proxy:libmmi-client", - "${mmi_path}/util:libmmi-util", - "${mmi_path}/frameworks/ets/common:ets_inputcommon_package", - + "${mmi_path}/util:libmmi-util" ] external_deps = [ "c_utils:utils", diff --git a/frameworks/ets/input_monitor/common/include/ani_input_monitor_common.h b/frameworks/ets/input_monitor/common/include/ani_input_monitor_common.h new file mode 100644 index 0000000000..15608368a5 --- /dev/null +++ b/frameworks/ets/input_monitor/common/include/ani_input_monitor_common.h @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANI_INPUT_TAIHE_INPUT_MONITOR_COMMON_H +#define ANI_INPUT_TAIHE_INPUT_MONITOR_COMMON_H + +#include +#include +#include + +#include "ani_common.h" +#include "securec.h" + +#include "ohos.multimodalInput.mouseEvent.proj.hpp" +#include "ohos.multimodalInput.gestureEvent.proj.hpp" +#include "ohos.multimodalInput.touchEvent.proj.hpp" +#include "ohos.multimodalInput.shortKey.proj.hpp" +#include "ohos.multimodalInput.keyEvent.proj.hpp" +#include "taihe/runtime.hpp" +#include "taihe/callback.hpp" + +#include "key_event.h" +#include "pointer_style.h" +#include "pointer_event.h" + +namespace OHOS { +namespace MMI { + +constexpr int32_t AXIS_TYPE_SCROLL_VERTICAL { 0 }; +constexpr int32_t AXIS_TYPE_SCROLL_HORIZONTAL { 1 }; +constexpr int32_t AXIS_TYPE_PINCH { 2 }; + +using namespace ohos::multimodalInput::keyCode; +using TaiheAxisValue = ::ohos::multimodalInput::mouseEvent::AxisValue; +using TaiheAxis = ::ohos::multimodalInput::mouseEvent::Axis; +using TaiheInputEvent = ohos::multimodalInput::inputEvent::InputEvent; +using TaiheMouseToolType = ohos::multimodalInput::mouseEvent::ToolType; +using TaiheMouseButton = ::ohos::multimodalInput::mouseEvent::Button; +using TaiheKeyCode = ::ohos::multimodalInput::keyCode::KeyCode; + +using TaiheMouseEvent = ohos::multimodalInput::mouseEvent::MouseEvent; +using TaiheTouchEvent = ohos::multimodalInput::touchEvent::TouchEvent; +using TaiheTouchEventArray = taihe::array; +using TaiheTouch = ohos::multimodalInput::touchEvent::Touch; +using TaiheTouchAction = ohos::multimodalInput::touchEvent::Action; +using TaiheMouseAction = ohos::multimodalInput::mouseEvent::Action; +using TaiheInputEvent = ohos::multimodalInput::inputEvent::InputEvent; +using TaiheSourceType = ohos::multimodalInput::touchEvent::SourceType; +using TaiheFixedMode = ohos::multimodalInput::touchEvent::FixedMode; +using TaiheToolType = ohos::multimodalInput::touchEvent::ToolType; + +using TaiheRotate = ohos::multimodalInput::gestureEvent::Rotate; +using TaiheTouchGestureAction = ohos::multimodalInput::gestureEvent::TouchGestureAction; +using TaiheGestureActionType = ohos::multimodalInput::gestureEvent::ActionType; +using TaiheSwipeInward = ohos::multimodalInput::gestureEvent::SwipeInward; +using TaiheThreeFingersSwipe = ohos::multimodalInput::gestureEvent::ThreeFingersSwipe; +using TaihePinchEvent = ohos::multimodalInput::gestureEvent::Pinch; +using TaiheFourFingersSwipe = ohos::multimodalInput::gestureEvent::FourFingersSwipe; +using TaiheThreeFingersTap = ohos::multimodalInput::gestureEvent::ThreeFingersTap; +using TaiheTouchGestureEvent = ohos::multimodalInput::gestureEvent::TouchGestureEvent; + +using TaiheFingerprintAction = ohos::multimodalInput::shortKey::FingerprintAction; +using TaiheFingerprintEvent = ohos::multimodalInput::shortKey::FingerprintEvent; + +using TaiheKeyEventAction = ohos::multimodalInput::keyEvent::Action; +using TaiheKeyEvent = ohos::multimodalInput::keyEvent::KeyEvent; +using TaiheKeyEventKey = ohos::multimodalInput::keyEvent::Key; + + +class TaiheMonitorConverter { +public: + // ztw touchEvent 解析 + static int32_t TouchEventToTaihe(const PointerEvent &pointerEvent, TaiheTouchEvent &out); + static int32_t InputEventToTaihe(const InputEvent &inputEvent, TaiheInputEvent &out); + static int32_t TouchActionToTaihe(int32_t action, TaiheTouchAction &out); + static int32_t SourceTypeToTaihe(int32_t sourceType, TaiheSourceType &out); + static int32_t FixedModeToTaihe(PointerEvent::FixedMode fixedMode, TaiheFixedMode &out); + static int32_t TouchToTaihe(const PointerEvent::PointerItem &item, TaiheTouch &out); + + // ztw gestureEvent + static int32_t TouchGestureActionToTaihe(int32_t action, TaiheTouchGestureAction &out); + static int32_t RotateActionToTaihe(int32_t action, TaiheGestureActionType &out); + static int32_t PinchActionToTaihe(int32_t action, TaiheGestureActionType &out); + static int32_t SwipeInwardActionToTaihe(int32_t action, TaiheGestureActionType &out); + static int32_t SwipeActionToTaihe(int32_t action, TaiheGestureActionType &out); + static int32_t MultiTapActionToTaihe(int32_t action, TaiheGestureActionType &out); + + static int32_t RotateToTaihe(const PointerEvent &pointerEvent, TaiheRotate &out); + static int32_t PinchToTaihe(const PointerEvent &pointerEvent, TaihePinchEvent &out); + static int32_t SwipeInwardToTaihe(const PointerEvent &pointerEvent, TaiheSwipeInward &out); + static int32_t ThreeFingersSwipeToTaihe(const PointerEvent &pointerEvent, TaiheThreeFingersSwipe &out); + static int32_t FourFingersSwipeToTaihe(const PointerEvent &pointerEvent, TaiheFourFingersSwipe &out); + // ztw touchscreenSwipe, touchscreenPinch + static int32_t TouchGestureEventToTaihe(const PointerEvent &pointerEvent, TaiheTouchGestureEvent &out); + // ztw fingersTap + static int32_t ThreeFingersTapToTaihe(const PointerEvent &pointerEvent, TaiheThreeFingersTap &out); + // ztw fingerprint +#ifdef OHOS_BUILD_ENABLE_FINGERPRINT + static int32_t FingerprintActionToTaihe(int32_t action, TaiheFingerprintAction &out); + static int32_t FingerprintEventToTaihe(const PointerEvent &pointerEvent, TaiheFingerprintEvent &out); +#endif + // ztw keyPressed + static bool HasKeyCode(const std::vector& pressedKeys, int32_t keyCode); + static int32_t KeyEventActionToTaihe(int32_t action, TaiheKeyEventAction &out); + static int32_t TaiheKeyEventToTaihe(const KeyEvent &keyEvent, TaiheKeyEvent &out); + static int32_t TaiheKeyEventKeyToTaihe(const KeyEvent::KeyItem &keyItem, TaiheKeyEventKey &out); + static int32_t MouseEventToTaihe(std::shared_ptr pointerEvent, TaiheMouseEvent &out); + static int32_t MouseActionToTaihe(int32_t action, TaiheMouseAction &out); +private: + static int32_t GetMousePointerItem(std::shared_ptr pointerEvent, TaiheMouseEvent &mouseEvent); + static int32_t SetMouseProperty(std::shared_ptr& pointerEvent, const PointerEvent::PointerItem& item, TaiheMouseEvent &mouseEvent); + static int32_t GetAxesValue(const std::shared_ptr pointerEvent, TaiheAxisValue& value); + static int32_t GetPressedKey(const std::vector& pressedKeys, TaiheMouseEvent &mouseEvent); +}; + + +using callbackType = std::variant< + taihe::callback, + //taihe::callback, + taihe::callback, + taihe::callback, + taihe::callback, + taihe::callback, + taihe::callback, + taihe::callback, + taihe::callback, + taihe::callback, + taihe::callback, + taihe::callback, + taihe::callback + >; + + +struct CallbackObject { + CallbackObject(callbackType cb, ani_ref ref) : callback(cb), ref(ref) {} + ~CallbackObject() + { + if (auto *env = taihe::get_env()) { + env->GlobalReference_Delete(ref); + } + } + callbackType callback; + ani_ref ref; +}; + +class GlobalRefGuard { + ani_env *env_ = nullptr; + ani_ref ref_ = nullptr; + +public: + GlobalRefGuard(ani_env *env, ani_object obj) : env_(env) + { + if (!env_) { + return; + } + if (ANI_OK != env_->GlobalReference_Create(obj, &ref_)) { + ref_ = nullptr; + } + } + explicit operator bool() const + { + return ref_ != nullptr; + } + ani_ref get() const + { + return ref_; + } + ~GlobalRefGuard() + { + if (env_ && ref_) { + env_->GlobalReference_Delete(ref_); + } + } + + GlobalRefGuard(const GlobalRefGuard &) = delete; + GlobalRefGuard &operator=(const GlobalRefGuard &) = delete; +}; + +} // namespace MMI +} // namespace OHOS +#endif // ANI_INPUT_TAIHE_INPUT_MONITOR_COMMON_H \ No newline at end of file diff --git a/frameworks/ets/input_monitor/common/src/ani_input_monitor_common.cpp b/frameworks/ets/input_monitor/common/src/ani_input_monitor_common.cpp new file mode 100644 index 0000000000..9fb6220d80 --- /dev/null +++ b/frameworks/ets/input_monitor/common/src/ani_input_monitor_common.cpp @@ -0,0 +1,830 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ani_input_monitor_common.h" + +#include "define_multimodal.h" +#include "mmi_log.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "aniMonitorCommon" + +namespace OHOS { +namespace MMI { + +int32_t TaiheMonitorConverter::TouchEventToTaihe(const PointerEvent &pointerEvent, TaiheTouchEvent &out) +{ + CALL_DEBUG_ENTER; + auto ret = InputEventToTaihe(pointerEvent, out.base); + if (ret != RET_OK) { + MMI_HILOGE("InputEventToTaihe failed"); + return RET_ERR; + } + ret = TouchActionToTaihe(pointerEvent.GetPointerAction(), out.action); + if (ret!= RET_OK) { + MMI_HILOGE("TouchActionToTaihe failed"); + return RET_ERR; + } + // 这个需要更新新代码 ---touchEvent taihe定义 + // result.isInject = pointerEventItem->HasFlag(InputEvent::EVENT_FLAG_SIMULATE); + std::vector vecTouches; + for (auto item : pointerEvent.GetPointerIds()) { + PointerEvent::PointerItem pointerItem; + if (!pointerEvent.GetPointerItem(item, pointerItem)) { + MMI_HILOGE("Get pointer item failed"); + return ret; + } + if (pointerItem.GetPointerId() == pointerEvent.GetPointerId()) { + ret = TouchToTaihe(pointerItem, out.touch); + if (ret!= RET_OK) { + MMI_HILOGE("TouchToTaihe failed"); + return RET_ERR; + } + } + auto taiheTouch = TaiheTouch {.toolType = TaiheToolType::key_t::FINGER}; + ret = TouchToTaihe(pointerItem, taiheTouch); + if (ret!= RET_OK) { + MMI_HILOGE("TouchToTaihe failed"); + return RET_ERR; + } + vecTouches.push_back(taiheTouch); + } + out.touches = taihe::array(vecTouches); + ret = SourceTypeToTaihe(pointerEvent.GetSourceType(), out.sourceType); + if (ret!= RET_OK) { + MMI_HILOGE("SourceTypeToTaihe failed"); + return RET_ERR; + } + auto fixedmode = TaiheFixedMode::from_value(RET_ERR); + ret = FixedModeToTaihe(pointerEvent.GetFixedMode(), fixedmode); + if (ret!= RET_OK) { + MMI_HILOGE("FixedModeToTaihe failed"); + return RET_ERR; + } + out.fixedMode = taihe::optional(std::in_place_t{}, fixedmode); + return ret; +} + +int32_t TaiheMonitorConverter::InputEventToTaihe(const InputEvent &inputEvent, TaiheInputEvent &out) +{ + out.id = inputEvent.GetId(); + out.deviceId = inputEvent.GetDeviceId(); + out.actionTime = inputEvent.GetActionTime(); + out.screenId = inputEvent.GetTargetDisplayId(); + out.windowId = inputEvent.GetTargetWindowId(); + return RET_OK; +} + +int32_t TaiheMonitorConverter::TouchActionToTaihe(int32_t action, TaiheTouchAction &out) { + bool ret = RET_OK; + switch (action) { + case PointerEvent::POINTER_ACTION_CANCEL: { + out = TaiheTouchAction::key_t::CANCEL; + break; + } + case PointerEvent::POINTER_ACTION_DOWN: { + out = TaiheTouchAction::key_t::DOWN; + break; + } + case PointerEvent::POINTER_ACTION_MOVE: { + out = TaiheTouchAction::key_t::MOVE; + break; + } + case PointerEvent::POINTER_ACTION_UP: { + out = TaiheTouchAction::key_t::UP; + break; + } + // ztw 代码中没有定义 + // case PointerEvent::POINTER_ACTION_PULL_DOWN: { + // return TaiheTouchAction::key_t::PULL_DOWN; + // } + // case PointerEvent::POINTER_ACTION_PULL_MOVE: { + // return TaiheTouchAction::key_t::PULL_MOVE; + // } + // case PointerEvent::POINTER_ACTION_PULL_UP: { + // return TaiheTouchAction::key_t::PULL_UP; + // } + default: { + ret = RET_ERR; + } + } + return ret; +} + +int32_t TaiheMonitorConverter::SourceTypeToTaihe(int32_t sourceType, TaiheSourceType &out) +{ + auto ret = RET_OK; + switch (sourceType) { + case PointerEvent::SOURCE_TYPE_TOUCHSCREEN: { + out = TaiheSourceType::key_t::TOUCH_SCREEN; + break; + } + case PointerEvent::SOURCE_TYPE_TOUCHPAD: { + out = TaiheSourceType::key_t::TOUCH_PAD; + break; + } + // ztw 代码中少实现 + // case PointerEvent::SOURCE_TYPE_PEN: { + // return TaiheTouchAction::key_t::PEN; + // } + default: { + ret = RET_ERR; + } + } + return ret; +} + +int32_t TaiheMonitorConverter::FixedModeToTaihe(PointerEvent::FixedMode fixedMode, TaiheFixedMode &out) +{ + auto ret = RET_OK; + switch (fixedMode) { + case PointerEvent::FixedMode::SCREEN_MODE_UNKNOWN: { + out = TaiheFixedMode::key_t::NONE; + break; + } + case PointerEvent::FixedMode::AUTO: { + out = TaiheFixedMode::key_t::AUTO; + break; + } + // ztw 代码中少实现 + // case PointerEvent::SOURCE_TYPE_TOUCHPAD: { + // return TaiheTouchAction::key_t::PEN; + // } + default: { + ret = RET_ERR; + } + } + return ret; +} + +// TaiheTouch obj{.toolType = TaiheToolType::key_t::FINGER}; +int32_t TaiheMonitorConverter::TouchToTaihe(const PointerEvent::PointerItem &item, TaiheTouch &out) +{ + out.id = item.GetPointerId(); + out.pressedTime = item.GetDownTime(); + out.screenX = item.GetDisplayX(); + out.screenY = item.GetDisplayY(); + // ztw taihe 中没有定义 + // obj.globalX = static_cast(item.GetGlobalX()); + // obj.globalY = static_cast(item.GetGlobalY()); + out.windowX = item.GetWindowX(); + out.windowY = item.GetWindowY(); + out.pressure = item.GetPressure(); + out.width = item.GetWidth(); + out.height = item.GetHeight(); + out.tiltX = item.GetTiltX(); + out.tiltY = item.GetTiltY(); + out.toolX = item.GetToolDisplayX(); + out.toolY = item.GetToolDisplayY(); + out.toolWidth = item.GetToolWidth(); + out.toolHeight = item.GetToolHeight(); + out.rawX = item.GetRawDx(); + out.rawY = item.GetRawDy(); + out.toolType.from_value(item.GetToolType()); + out.fixedDisplayX = taihe::optional(std::in_place_t{}, item.GetFixedDisplayX()); + out.fixedDisplayY = taihe::optional(std::in_place_t{}, item.GetFixedDisplayY()); + return RET_OK; +} + +int32_t TaiheMonitorConverter::TouchGestureActionToTaihe(int32_t action, TaiheTouchGestureAction &out) +{ + auto ret = RET_OK; + switch (action) { + case PointerEvent::TOUCH_ACTION_SWIPE_DOWN: { + out = TaiheTouchGestureAction::key_t::SWIPE_DOWN; + break; + } + case PointerEvent::TOUCH_ACTION_SWIPE_UP: { + out = TaiheTouchGestureAction::key_t::SWIPE_UP; + break; + } + case PointerEvent::TOUCH_ACTION_SWIPE_RIGHT: { + out = TaiheTouchGestureAction::key_t::SWIPE_RIGHT; + break; + } + case PointerEvent::TOUCH_ACTION_SWIPE_LEFT: { + out = TaiheTouchGestureAction::key_t::SWIPE_LEFT; + break; + } + case PointerEvent::TOUCH_ACTION_PINCH_OPENED: { + out = TaiheTouchGestureAction::key_t::PINCH_OPENED; + break; + } + case PointerEvent::TOUCH_ACTION_PINCH_CLOSEED: { + out = TaiheTouchGestureAction::key_t::PINCH_CLOSED; + break; + } + case PointerEvent::TOUCH_ACTION_GESTURE_END: { + out = TaiheTouchGestureAction::key_t::GESTURE_END; + break; + } + default: { + MMI_HILOGW("unknow action, action:%{public}d", action); + ret = RET_ERR; + } + } + return ret; +} + +int32_t TaiheMonitorConverter::RotateActionToTaihe(int32_t action, TaiheGestureActionType &out) +{ + auto ret = RET_OK; + switch (action) { + case PointerEvent::POINTER_ACTION_ROTATE_BEGIN: { + out = TaiheGestureActionType::key_t::BEGIN; + break; + } + case PointerEvent::POINTER_ACTION_ROTATE_UPDATE: { + out = TaiheGestureActionType::key_t::UPDATE; + break; + } + case PointerEvent::POINTER_ACTION_ROTATE_END: { + out = TaiheGestureActionType::key_t::END; + break; + } + default: { + MMI_HILOGD("Abnormal pointer action in rotate event"); + ret = RET_ERR; + } + } + return ret; +} + +int32_t TaiheMonitorConverter::PinchActionToTaihe(int32_t action, TaiheGestureActionType &out) +{ + auto ret = RET_OK; + switch (action) { + case PointerEvent::POINTER_ACTION_AXIS_BEGIN: { + out = TaiheGestureActionType::key_t::BEGIN; + break; + } + case PointerEvent::POINTER_ACTION_AXIS_UPDATE: { + out = TaiheGestureActionType::key_t::UPDATE; + break; + } + case PointerEvent::POINTER_ACTION_AXIS_END: { + out = TaiheGestureActionType::key_t::END; + break; + } + default: { + MMI_HILOGD("Abnormal pointer action in pinch event"); + ret = RET_ERR; + } + } + return ret; +} + +int32_t TaiheMonitorConverter::SwipeInwardActionToTaihe(int32_t action, TaiheGestureActionType &out) +{ + auto ret = RET_OK; + switch (action) { + case PointerEvent::POINTER_ACTION_DOWN: { + out = TaiheGestureActionType::key_t::BEGIN; + break; + } + case PointerEvent::POINTER_ACTION_MOVE: { + out = TaiheGestureActionType::key_t::UPDATE; + break; + } + case PointerEvent::POINTER_ACTION_UP: + case PointerEvent::POINTER_ACTION_CANCEL: { + out = TaiheGestureActionType::key_t::END; + break; + } + default: { + MMI_HILOGE("Abnormal pointer action in swipe event"); + ret = RET_ERR; + } + } + return ret; +} + +int32_t TaiheMonitorConverter::SwipeActionToTaihe(int32_t action, TaiheGestureActionType &out) +{ + auto ret = RET_OK; + switch (action) { + case PointerEvent::POINTER_ACTION_SWIPE_BEGIN: { + out = TaiheGestureActionType::key_t::BEGIN; + break; + } + case PointerEvent::POINTER_ACTION_SWIPE_UPDATE: { + out = TaiheGestureActionType::key_t::UPDATE; + break; + } + case PointerEvent::POINTER_ACTION_SWIPE_END: { + out = TaiheGestureActionType::key_t::END; + break; + } + default: { + MMI_HILOGD("Abnormal pointer action in swipe event"); + ret = RET_ERR; + } + } + return ret; +} + +int32_t TaiheMonitorConverter::MultiTapActionToTaihe(int32_t action, TaiheGestureActionType &out) +{ + auto ret = RET_OK; + switch (action) { + case PointerEvent::POINTER_ACTION_TRIPTAP: { + out = TaiheGestureActionType::key_t::END; + break; + } + default: { + MMI_HILOGD("Abnormal pointer action in multi tap event"); + ret = RET_ERR; + } + } + return ret; +} + +// TaiheRotate obj {.type = RotateActionToTaihe(pointerEvent.GetPointerAction())}; +int32_t TaiheMonitorConverter::RotateToTaihe(const PointerEvent &pointerEvent, TaiheRotate &out) +{ + auto type = TaiheGestureActionType::from_value(RET_ERR); + auto ret = RotateActionToTaihe(pointerEvent.GetPointerAction(), type); + if (ret != RET_OK) { + return ret; + } + out.type = type; + out.angle = pointerEvent.GetAxisValue(PointerEvent::AXIS_TYPE_ROTATE); + return ret; + +} + +int32_t TaiheMonitorConverter::PinchToTaihe(const PointerEvent &pointerEvent, TaihePinchEvent &out) +{ + auto type = TaiheGestureActionType::from_value(RET_ERR); + auto ret = PinchActionToTaihe(pointerEvent.GetPointerAction(), type); + if (ret != RET_OK) { + return ret; + } + out.type = type; + out.scale = pointerEvent.GetAxisValue(PointerEvent::AXIS_TYPE_PINCH); + return ret; + +} + +int32_t TaiheMonitorConverter::SwipeInwardToTaihe(const PointerEvent &pointerEvent, TaiheSwipeInward &out) +{ + auto type = TaiheGestureActionType::from_value(RET_ERR); + auto ret = SwipeActionToTaihe(pointerEvent.GetPointerAction(), type); + if (ret != RET_OK) { + return ret; + } + out.type = type; + PointerEvent::PointerItem pointeritem; + int32_t pointerId = 0; + ret = pointerEvent.GetPointerItem(pointerId, pointeritem); + if (ret != RET_OK) { + MMI_HILOGE("Can't find this pointerItem"); + return ret; + } + out.x = pointeritem.GetDisplayX(); + out.y = pointeritem.GetDisplayY(); + return ret; + +} + +int32_t TaiheMonitorConverter::ThreeFingersSwipeToTaihe(const PointerEvent &pointerEvent, TaiheThreeFingersSwipe &out) +{ + //TaiheThreeFingersSwipe obj {.type = }; + auto type = TaiheGestureActionType::from_value(RET_ERR); + auto ret = SwipeActionToTaihe(pointerEvent.GetPointerAction(), type); + if (ret != RET_OK) { + MMI_HILOGE("SwipeActionToTaihe error"); + return ret; + } + out.type = type; + PointerEvent::PointerItem pointeritem; + int32_t pointerId = 0; + ret = pointerEvent.GetPointerItem(pointerId, pointeritem); + if (ret != RET_OK) { + MMI_HILOGE("Can't find this pointerItem"); + return ret; + } + out.x = pointeritem.GetDisplayX(); + out.y = pointeritem.GetDisplayY(); + return ret; +} + +int32_t TaiheMonitorConverter::FourFingersSwipeToTaihe(const PointerEvent &pointerEvent, TaiheFourFingersSwipe &out) +{ + // TaiheFourFingersSwipe obj {.type = SwipeActionToTaihe(pointerEvent.GetPointerAction())}; + auto type = TaiheGestureActionType::from_value(RET_ERR); + auto ret = SwipeActionToTaihe(pointerEvent.GetPointerAction(), type); + if (ret != RET_OK) { + MMI_HILOGE("SwipeActionToTaihe error"); + return ret; + } + out.type = type; + PointerEvent::PointerItem pointeritem; + int32_t pointerId = 0; + ret = pointerEvent.GetPointerItem(pointerId, pointeritem); + if (ret != RET_OK) { + MMI_HILOGE("Can't find this pointerItem"); + return ret; + } + out.x = pointeritem.GetDisplayX(); + out.y = pointeritem.GetDisplayY(); + return ret; +} + +int32_t TaiheMonitorConverter::TouchGestureEventToTaihe(const PointerEvent &pointerEvent, TaiheTouchGestureEvent &out) +{ + auto action = TaiheTouchGestureAction::from_value(RET_ERR); + auto ret = TouchGestureActionToTaihe(pointerEvent.GetPointerAction(), action); + if (ret != RET_OK) { + MMI_HILOGE("TouchGestureActionToTaihe error"); + return ret; + } + out.action = action; + std::vector vecTouches; + for (auto item : pointerEvent.GetPointerIds()) { + PointerEvent::PointerItem pointerItem; + ret = pointerEvent.GetPointerItem(item, pointerItem); + if (ret != RET_OK) { + MMI_HILOGE("Get pointer item failed"); + return ret; + } + TaiheTouch per {.toolType = TaiheToolType::key_t::FINGER}; + ret = TouchToTaihe(pointerItem, per); + if (ret != RET_OK) { + MMI_HILOGE("TouchToTaihe failed"); + return ret; + } + vecTouches.push_back(per); + } + out.touches = taihe::array(vecTouches); + return ret; +} + +int32_t TaiheMonitorConverter::ThreeFingersTapToTaihe(const PointerEvent &pointerEvent, TaiheThreeFingersTap &out) +{ + auto type = TaiheGestureActionType::from_value(RET_ERR); + auto ret = MultiTapActionToTaihe(pointerEvent.GetPointerAction(), type); + if (ret != RET_OK) { + MMI_HILOGE("SwipeActionToTaihe error"); + return ret; + } + out.type = type; + return ret; +} + +#ifdef OHOS_BUILD_ENABLE_FINGERPRINT +int32_t TaiheMonitorConverter::FingerprintActionToTaihe(int32_t action, TaiheFingerprintAction &out) +{ + auto ret = RET_OK; + switch (action) { + case PointerEvent::POINTER_ACTION_FINGERPRINT_DOWN: { + out = TaiheFingerprintAction::key_t::DOWN; + break; + } + case PointerEvent::POINTER_ACTION_FINGERPRINT_UP: { + out = TaiheFingerprintAction::key_t::UP; + break; + } + case PointerEvent::POINTER_ACTION_FINGERPRINT_SLIDE: { + out = TaiheFingerprintAction::key_t::SLIDE; + break; + } + case PointerEvent::POINTER_ACTION_FINGERPRINT_RETOUCH: { + out = TaiheFingerprintAction::key_t::RETOUCH; + break; + } + case PointerEvent::POINTER_ACTION_FINGERPRINT_CLICK: { + out = TaiheFingerprintAction::key_t::CLICK; + break; + } + /* // ztw 接口定义中没找到 + case PointerEvent::POINTER_ACTION_FINGERPRINT_CANCEL: { + return FINGERPRINT_CANCEL; + } + case PointerEvent::POINTER_ACTION_FINGERPRINT_HOLD: { + return FINGERPRINT_HOLD; + } + case PointerEvent::POINTER_ACTION_FINGERPRINT_TOUCH: { + return FINGERPRINT_TOUCH; + } */ + default: { + MMI_HILOGE("Wrong action is %{public}d", action); + ret = RET_ERR; + } + } +} + +int32_t TaiheMonitorConverter::FingerprintEventToTaihe(const PointerEvent &pointerEvent, TaiheFingerprintEvent &out) +{ + // TaiheFingerprintEvent obj {.action = FingerprintActionToTaihe(pointerEvent.GetPointerAction())}; + auto type = TaiheFingerprintAction::from_value(RET_ERR); + auto ret = FingerprintActionToTaihe(pointerEvent.GetPointerAction(), type); + if (ret != RET_OK) { + MMI_HILOGE("TouchGestureActionToTaihe error"); + return ret; + } + out.action = type; + out.distanceX = pointerEvent.GetFingerprintDistanceX(); + out.distanceY = pointerEvent.GetFingerprintDistanceY(); + return ret; +} +#endif + +bool TaiheMonitorConverter::HasKeyCode(const std::vector& pressedKeys, int32_t keyCode) +{ + return std::find(pressedKeys.begin(), pressedKeys.end(), keyCode) != pressedKeys.end(); +} + +int32_t TaiheMonitorConverter::KeyEventActionToTaihe(int32_t action, TaiheKeyEventAction &out) +{ + auto ret = RET_OK; + if (KeyEvent::KEY_ACTION_CANCEL == action) { + out = TaiheKeyEventAction::key_t::CANCEL; + } else if (KeyEvent::KEY_ACTION_DOWN == action) { + out = TaiheKeyEventAction::key_t::DOWN; + } else if (KeyEvent::KEY_ACTION_UP == action) { + out = TaiheKeyEventAction::key_t::UP; + } else { + ret = RET_ERR; + } + return ret; +} + +int32_t TaiheMonitorConverter::TaiheKeyEventToTaihe(const KeyEvent &keyEvent, TaiheKeyEvent &out) +{ + auto action = TaiheKeyEventAction::from_value(RET_ERR); + auto ret = KeyEventActionToTaihe(keyEvent.GetKeyAction(), action); + if (ret != RET_OK) { + MMI_HILOGE("TaiheKeyEventToTaihe error"); + return ret; + } + std::optional keyItem = keyEvent.GetKeyItem(); + if (!keyItem) { + MMI_HILOGE("The keyItem is nullopt"); + ret = RET_ERR; + return ret; + } + ret = TaiheKeyEventKeyToTaihe(keyItem.value(), out.key); + if (ret != RET_OK) { + MMI_HILOGE("TaiheKeyEventKeyToTaihe error"); + return ret; + } + out.unicodeChar = keyItem->GetUnicode(); + std::vector pressedKeys = keyEvent.GetPressedKeys(); + std::vector keys; + for (const auto &pressedKeyCode : pressedKeys) { + std::optional pressedKeyItem = keyEvent.GetKeyItem(pressedKeyCode); + if (!pressedKeyItem) { + ret = RET_ERR; + MMI_HILOGE("The pressedKeyItem is nullopt"); + return ret; + } + auto taiheKey = TaiheKeyEventKey{ .code = KeyCode::key_t::KEYCODE_UNKNOWN }; + ret = TaiheKeyEventKeyToTaihe(pressedKeyItem.value(), taiheKey); + if (ret != RET_OK) { + MMI_HILOGE("TaiheKeyEventKeyToTaihe error"); + return ret; + } + keys.push_back(taiheKey); + } + out.keys = taihe::array(keys); + ret = InputEventToTaihe(keyEvent, out.base); + if (ret != RET_OK) { + MMI_HILOGE("TaiheKeyEventKeyToTaihe error"); + return ret; + } + ret = InputEventToTaihe(keyEvent, out.base); + if (ret != RET_OK) { + MMI_HILOGE("InputEventToTaihe error"); + return ret; + } + out.ctrlKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_LEFT) + || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_RIGHT); + out.altKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_ALT_LEFT) + || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_ALT_RIGHT);; + out.shiftKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_SHIFT_LEFT) + || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_SHIFT_RIGHT); + out.logoKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_META_LEFT) + || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_META_RIGHT); + out.fnKey = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_FN); + out.capsLock = keyEvent.GetFunctionKey(KeyEvent::CAPS_LOCK_FUNCTION_KEY); + out.numLock = keyEvent.GetFunctionKey(KeyEvent::NUM_LOCK_FUNCTION_KEY); + out.scrollLock = keyEvent.GetFunctionKey(KeyEvent::SCROLL_LOCK_FUNCTION_KEY); + return ret; + +} + +int32_t TaiheMonitorConverter::TaiheKeyEventKeyToTaihe(const KeyEvent::KeyItem &keyItem, TaiheKeyEventKey &out) +{ + auto ret = RET_OK; + out.code = TaiheConverter::ConvertEtsKeyCode(keyItem.GetKeyCode()); + out.pressedTime = keyItem.GetDownTime(); + out.deviceId = keyItem.GetDeviceId(); + return ret; +} + +int32_t TaiheMonitorConverter::SetMouseProperty(std::shared_ptr& pointerEvent, const PointerEvent::PointerItem& item, TaiheMouseEvent &mouseEvent) +{ + int32_t ret = RET_OK; + int32_t buttonId = pointerEvent->GetButtonId(); + if (buttonId == PointerEvent::MOUSE_BUTTON_MIDDLE) { + buttonId = TH_MOUSE_BUTTON::JS_MOUSE_BUTTON_MIDDLE; + } else if (buttonId == PointerEvent::MOUSE_BUTTON_RIGHT) { + buttonId = TH_MOUSE_BUTTON::JS_MOUSE_BUTTON_RIGHT; + } + + mouseEvent.button = TaiheMouseButton::key_t(buttonId); + mouseEvent.base.actionTime = pointerEvent->GetActionTime(); + mouseEvent.base.deviceId = item.GetDeviceId(); + mouseEvent.base.screenId = pointerEvent->GetTargetDisplayId(); + mouseEvent.base.windowId = pointerEvent->GetTargetWindowId(); + mouseEvent.base.deviceId = item.GetDeviceId(); + mouseEvent.screenX = item.GetDisplayX(); + mouseEvent.screenY = item.GetDisplayY(); + mouseEvent.windowX = item.GetWindowX(); + mouseEvent.windowY = item.GetWindowY(); + mouseEvent.rawDeltaX = item.GetRawDx(); + mouseEvent.rawDeltaY = item.GetRawDy(); + // ztw 接口没有定义 + // mouseEvent.globalX = optional<>(std::in_place, static_cast(item.GetGlobalX())); + // mouseEvent.globalY = optional<>(std::in_place, static_cast(item.GetGlobalY())); + // ztw 多模代码中没找实现 + // mouseEvent.capsLock = HasKeyCode(pressedKeys, KeyEvent::CAPS_LOCK_FUNCTION_KEY); + // mouseEvent.numLock = HasKeyCode(pressedKeys, KeyEvent::NUM_LOCK_FUNCTION_KEY); + // mouseEvent.scrollLock = HasKeyCode(pressedKeys, KeyEvent::SCROLL_LOCK_FUNCTION_KEY); + // mouseEvent.toolType + + return ret; +} + +int32_t TaiheMonitorConverter::GetAxesValue(const std::shared_ptr pointerEvent, TaiheAxisValue& value) +{ + double axisValue = -1.0; + int32_t axis = -1; + if (pointerEvent->HasAxis(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL)) { + axisValue = pointerEvent->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL); + axis = AXIS_TYPE_SCROLL_VERTICAL; + } + if (pointerEvent->HasAxis(PointerEvent::AXIS_TYPE_SCROLL_HORIZONTAL)) { + axisValue = pointerEvent->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_HORIZONTAL); + axis = AXIS_TYPE_SCROLL_HORIZONTAL; + } + if (pointerEvent->HasAxis(PointerEvent::AXIS_TYPE_PINCH)) { + axisValue = pointerEvent->GetAxisValue(PointerEvent::AXIS_TYPE_PINCH); + axis = AXIS_TYPE_PINCH; + } + + value.axis = TaiheAxis::key_t(axis) ; + value.value = axisValue; + + return RET_OK; +} + +int32_t TaiheMonitorConverter::GetMousePointerItem(std::shared_ptr pointerEvent, TaiheMouseEvent &mouseEvent) +{ + int32_t ret = RET_OK; + int32_t currentPointerId = pointerEvent->GetPointerId(); + std::vector axisValueVec; + std::vector pointerIds { pointerEvent->GetPointerIds() }; + for (const auto& pointerId : pointerIds) { + if (pointerId == currentPointerId) { + PointerEvent::PointerItem item; + if (!pointerEvent->GetPointerItem(pointerId, item)) { + MMI_HILOGE("Invalid pointer:%{public}d", pointerId); + ret = RET_ERR; + return ret; + } + mouseEvent.base.id = currentPointerId; + SetMouseProperty(pointerEvent, item, mouseEvent); + } + + TaiheAxisValue value = {.axis = TaiheAxis::key_t(0), .value = 0}; + GetAxesValue(pointerEvent, value); + axisValueVec.push_back(value); + } + + mouseEvent.axes = taihe::array(axisValueVec); + return ret; +} + +int32_t TaiheMonitorConverter::GetPressedKey(const std::vector& pressedKeys, TaiheMouseEvent &mouseEvent) +{ + int32_t ret = RET_OK; + bool isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_LEFT) + || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_CTRL_RIGHT); + mouseEvent.ctrlKey = isExists; + + isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_ALT_LEFT) + || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_ALT_RIGHT); + mouseEvent.altKey = isExists; + + isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_SHIFT_LEFT) + || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_SHIFT_RIGHT); + mouseEvent.shiftKey = isExists; + + isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_META_LEFT) + || HasKeyCode(pressedKeys, KeyEvent::KEYCODE_META_RIGHT); + mouseEvent.logoKey = isExists; + + isExists = HasKeyCode(pressedKeys, KeyEvent::KEYCODE_FN); + mouseEvent.fnKey = isExists; + return ret; +} + +int32_t TaiheMonitorConverter::MouseActionToTaihe(int32_t action, TaiheMouseAction &out) { + int32_t ret = RET_OK; + switch (action) { + case PointerEvent::POINTER_ACTION_CANCEL: { + out = TaiheMouseAction::key_t::CANCEL; + break; + } + case PointerEvent::POINTER_ACTION_MOVE: + case PointerEvent::POINTER_ACTION_PULL_MOVE: { + out = TaiheMouseAction::key_t::MOVE; + break; + } + case PointerEvent::POINTER_ACTION_BUTTON_DOWN: + case PointerEvent::POINTER_ACTION_PULL_DOWN: { + out = TaiheMouseAction::key_t::BUTTON_DOWN; + break; + } + case PointerEvent::POINTER_ACTION_BUTTON_UP: + case PointerEvent::POINTER_ACTION_PULL_UP: { + out = TaiheMouseAction::key_t::BUTTON_UP; + break; + } + case PointerEvent::POINTER_ACTION_AXIS_BEGIN: { + out = TaiheMouseAction::key_t::AXIS_BEGIN; + break; + } + case PointerEvent::POINTER_ACTION_AXIS_UPDATE: { + out = TaiheMouseAction::key_t::AXIS_UPDATE; + break; + } + case PointerEvent::POINTER_ACTION_AXIS_END: { + out = TaiheMouseAction::key_t::AXIS_END; + break; + } + default: { + MMI_HILOGD("Abnormal pointer action"); + ret = RET_ERR; + } + // ztw 少了 接口层ACTION_DOWN, ACTION_UP, + } + return ret; +} + +int32_t TaiheMonitorConverter::MouseEventToTaihe(std::shared_ptr pointerEvent, TaiheMouseEvent &out) +{ + int32_t ret = MouseActionToTaihe(pointerEvent->GetPointerAction(), out.action); + if (ret != RET_OK) { + return ret; + } + std::vector pressedKeys = pointerEvent->GetPressedKeys(); + std::vector pressedKeysVec; + for(auto& value: pressedKeys) { + TaiheKeyCode code = TaiheKeyCode::key_t(value); + pressedKeysVec.push_back(code); + } + out.pressedKeys = taihe::array(pressedKeysVec); + + ret = GetPressedKey(pressedKeys, out); + if (ret != RET_OK) { + MMI_HILOGE("Get singlePressedKey failed"); + return ret; + } + ret = GetMousePointerItem(pointerEvent, out); + if (ret != RET_OK) { + MMI_HILOGE("Get item of mousePointer failed"); + return ret; + } + std::set pressedButtons = pointerEvent->GetPressedButtons(); + std::vector pressedButtonsVec; + for(auto& item : pressedButtons) { + auto buttonId = TaiheMouseButton::key_t(item); + if (item == PointerEvent::MOUSE_BUTTON_MIDDLE) { + buttonId = TaiheMouseButton::key_t::MIDDLE; + } else if (item == PointerEvent::MOUSE_BUTTON_RIGHT) { + buttonId = TaiheMouseButton::key_t::RIGHT; + } + pressedButtonsVec.push_back(buttonId); + } + + out.pressedButtons = taihe::array(pressedButtonsVec); + return ret; +} + +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h b/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h index 394834fe11..cbca2fa3be 100644 --- a/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h +++ b/frameworks/ets/input_monitor/include/ani_input_monitor_consumer.h @@ -24,7 +24,7 @@ #include "window_info.h" #include "axis_event.h" -#include "ani_common.h" +#include "ani_input_monitor_common.h" #include "i_input_event_consumer.h" #include "key_event.h" #include "pointer_event.h" diff --git a/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp b/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp index d93feaad12..3df163397d 100644 --- a/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp +++ b/frameworks/ets/input_monitor/src/ani_input_monitor_consumer.cpp @@ -661,7 +661,7 @@ void AniInputMonitorConsumer::OnPerPointerEvent(std::shared_ptr po .touch = TaiheTouch {.toolType = TaiheToolType::key_t::FINGER}, .sourceType = TaiheSourceType::key_t::TOUCH_SCREEN }; auto &func = std::get>(aniCallback_->callback); - ret = TaiheConverter::TouchEventToTaihe(*pointerEventItem, result); + ret = TaiheMonitorConverter::TouchEventToTaihe(*pointerEventItem, result); if (ret == RET_OK) { func(result); } @@ -672,7 +672,7 @@ void AniInputMonitorConsumer::OnPerPointerEvent(std::shared_ptr po .touch = TaiheTouch {.toolType = TaiheToolType::key_t::FINGER}, .sourceType = TaiheSourceType::key_t::TOUCH_SCREEN }; auto &func = std::get>(aniCallback_->callback); - ret = TaiheConverter::TouchEventToTaihe(*pointerEventItem, result); + ret = TaiheMonitorConverter::TouchEventToTaihe(*pointerEventItem, result); if (ret == RET_OK) { retValue = func(result); } @@ -687,7 +687,7 @@ void AniInputMonitorConsumer::OnPerPointerEvent(std::shared_ptr po .button = TaiheMouseButton::key_t::LEFT, .toolType = TaiheMouseToolType::key_t::UNKNOWN, }; auto &func = std::get>(aniCallback_->callback); - ret = TaiheConverter::MouseEventToTaihe(pointerEventItem, result); + ret = TaiheMonitorConverter::MouseEventToTaihe(pointerEventItem, result); if (ret == RET_OK) { func(result); } @@ -699,7 +699,7 @@ void AniInputMonitorConsumer::OnPerPointerEvent(std::shared_ptr po break; } TaihePinchEvent result {.type = TaiheGestureActionType::from_value(RET_ERR)}; - ret = TaiheConverter::PinchToTaihe(*pointerEventItem, result); + ret = TaiheMonitorConverter::PinchToTaihe(*pointerEventItem, result); if (ret == RET_OK) { auto &func = std::get>(aniCallback_->callback); func(result); @@ -711,7 +711,7 @@ void AniInputMonitorConsumer::OnPerPointerEvent(std::shared_ptr po break; } TaiheRotate result{.type = TaiheGestureActionType::from_value(RET_ERR)}; - ret = TaiheConverter::RotateToTaihe(*pointerEventItem, result); + ret = TaiheMonitorConverter::RotateToTaihe(*pointerEventItem, result); if (ret == RET_OK) { auto &func = std::get>(aniCallback_->callback); func(result); @@ -723,7 +723,7 @@ void AniInputMonitorConsumer::OnPerPointerEvent(std::shared_ptr po break; } TaiheThreeFingersSwipe result{.type = TaiheGestureActionType::from_value(RET_ERR)}; - ret = TaiheConverter::ThreeFingersSwipeToTaihe(*pointerEventItem, result); + ret = TaiheMonitorConverter::ThreeFingersSwipeToTaihe(*pointerEventItem, result); if (ret == RET_OK) { auto &func = std::get>(aniCallback_->callback); func(result); @@ -735,7 +735,7 @@ void AniInputMonitorConsumer::OnPerPointerEvent(std::shared_ptr po break; } TaiheFourFingersSwipe result{.type = TaiheGestureActionType::from_value(RET_ERR)}; - ret = TaiheConverter::FourFingersSwipeToTaihe(*pointerEventItem, result); + ret = TaiheMonitorConverter::FourFingersSwipeToTaihe(*pointerEventItem, result); if (ret == RET_OK) { auto &func = std::get>(aniCallback_->callback); func(result); @@ -747,7 +747,7 @@ void AniInputMonitorConsumer::OnPerPointerEvent(std::shared_ptr po break; } TaiheThreeFingersTap result{.type = TaiheGestureActionType::from_value(RET_ERR)}; - ret = TaiheConverter::ThreeFingersTapToTaihe(*pointerEventItem, result); + ret = TaiheMonitorConverter::ThreeFingersTapToTaihe(*pointerEventItem, result); if (ret == RET_OK) { auto &func = std::get>(aniCallback_->callback); func(result); @@ -760,7 +760,7 @@ void AniInputMonitorConsumer::OnPerPointerEvent(std::shared_ptr po break; } TaiheFingerprintEvent result{.action = TaiheFingerprintAction::from_value(RET_ERR)}; - ret = TaiheConverter::FingerprintEventToTaihe(*pointerEventItem, result); + ret = TaiheMonitorConverter::FingerprintEventToTaihe(*pointerEventItem, result); if (ret == RET_OK) { auto &func = std::get>(aniCallback_->callback); func(result); @@ -773,7 +773,7 @@ void AniInputMonitorConsumer::OnPerPointerEvent(std::shared_ptr po break; } TaiheSwipeInward result{.type = TaiheGestureActionType::from_value(RET_ERR)}; - ret = TaiheConverter::SwipeInwardToTaihe(*pointerEventItem, result); + ret = TaiheMonitorConverter::SwipeInwardToTaihe(*pointerEventItem, result); if (ret == RET_OK) { auto &func = std::get>(aniCallback_->callback); func(result); @@ -783,7 +783,7 @@ void AniInputMonitorConsumer::OnPerPointerEvent(std::shared_ptr po case MONITORFUNTYPE::ON_TOUCHSCREENSWIPE_FINGERS: case MONITORFUNTYPE::ON_TOUCHSCREENPINCH_FINGERS: { TaiheTouchGestureEvent result{.action = TaiheTouchGestureAction::from_value(RET_ERR)}; - ret = TaiheConverter::TouchGestureEventToTaihe(*pointerEventItem, result); + ret = TaiheMonitorConverter::TouchGestureEventToTaihe(*pointerEventItem, result); if (ret == RET_OK) { auto &func = std::get>(aniCallback_->callback); func(result); @@ -836,7 +836,7 @@ void AniInputMonitorConsumer::OnAniKeyEvent(std::shared_ptr keyEvent) case MONITORFUNTYPE::ON_KEYPRESSED_KEYS: { TaiheKeyEvent result{.action = TaiheKeyEventAction::from_value(RET_ERR), .key = {.code = KeyCode::key_t::KEYCODE_UNKNOWN}}; - ret = TaiheConverter::TaiheKeyEventToTaihe(*keyEvent, result); + ret = TaiheMonitorConverter::TaiheKeyEventToTaihe(*keyEvent, result); if (ret == RET_OK) { auto &func = std::get>(aniCallback_->callback); func(result); diff --git a/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp b/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp index ff2afba208..1a19c56f22 100644 --- a/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp +++ b/frameworks/ets/input_monitor/src/ani_input_monitor_manager.cpp @@ -67,7 +67,7 @@ TaiheTouchEventArray AniInputMonitorManager::QueryTouchEvents(int32_t count) TaiheTouchEvent taiheItem {.action = TaiheTouchAction::key_t::CANCEL, .touch = TaiheTouch {.toolType = TaiheToolType::key_t::FINGER}, .sourceType = TaiheSourceType::key_t::TOUCH_SCREEN }; - auto ret = TaiheConverter::TouchEventToTaihe(*per, taiheItem); + auto ret = TaiheMonitorConverter::TouchEventToTaihe(*per, taiheItem); if (ret != RET_OK) { taihe::set_business_error(ret, "unknown error"); return result; diff --git a/frameworks/ets/pointer/BUILD.gn b/frameworks/ets/pointer/BUILD.gn index b0445bbd94..1376f4a250 100644 --- a/frameworks/ets/pointer/BUILD.gn +++ b/frameworks/ets/pointer/BUILD.gn @@ -15,7 +15,6 @@ import("//build/ohos/taihe_idl/taihe.gni") import("//foundation/multimodalinput/input/multimodalinput_mini.gni") copy_taihe_idl("pointer_taihe") { sources = [ "idl/ohos.multimodalInput.pointer.taihe" ] - deps = [ "${mmi_path}/frameworks/ets/input_device:input_device_taihe", ] } config("pointer_config") { visibility = [ ":*" ] diff --git a/frameworks/ets/short_key/BUILD.gn b/frameworks/ets/short_key/BUILD.gn index 40b024080d..a61608370e 100644 --- a/frameworks/ets/short_key/BUILD.gn +++ b/frameworks/ets/short_key/BUILD.gn @@ -15,6 +15,7 @@ import("//build/ohos/taihe_idl/taihe.gni") import("//foundation/multimodalinput/input/multimodalinput_mini.gni") copy_taihe_idl("short_key_taihe") { sources = [ "idl/ohos.multimodalInput.shortKey.taihe" ] + deps = ["${mmi_path}/frameworks/ets/key_code:key_code_taihe"] } config("shortKey_config") { visibility = [ ":*" ] @@ -48,12 +49,12 @@ taihe_shared_library("ShortKey") { sources += [ "src/ani_constructor.cpp", "src/ohos.multimodalInput.shortKey.impl.cpp", + "${mmi_path}/frameworks/ets/common/src/ani_common.cpp", ] deps = [ ":run_taihe", "${mmi_path}/frameworks/proxy:libmmi-client", - "${mmi_path}/util:libmmi-util", - "${mmi_path}/frameworks/ets/common:ets_inputcommon_package", + "${mmi_path}/util:libmmi-util" ] external_deps = [ "c_utils:utils", -- Gitee From 2d77ffa83e6f627b749c3cb9a94be4f5dac29c9c Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Thu, 7 Aug 2025 10:51:06 +0800 Subject: [PATCH 29/29] input event client taiHe Signed-off-by: qianyong325 --- frameworks/ets/input_event_client/BUILD.gn | 9 +++++++++ frameworks/ets/input_event_client/user/main.ets | 3 +++ 2 files changed, 12 insertions(+) create mode 100644 frameworks/ets/input_event_client/user/main.ets diff --git a/frameworks/ets/input_event_client/BUILD.gn b/frameworks/ets/input_event_client/BUILD.gn index 7c4758cfaf..7793df5e12 100644 --- a/frameworks/ets/input_event_client/BUILD.gn +++ b/frameworks/ets/input_event_client/BUILD.gn @@ -88,9 +88,18 @@ ohos_prebuilt_etc("input_event_client_etc") { subsystem_name = "$subsystem_name" deps = [ ":input_event_client" ] } + +generate_static_abc("input_event_client_test") { + base_url = "${mmi_path}/frameworks/ets/input_event_client/user" + files = [ "${mmi_path}/frameworks/ets/input_event_client/user/main.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/input_event_client_test.abc" +} + group("ets_inputEventClient_package") { deps = [ ":input_event_client_etc", ":InputEventClient", + ":input_event_client_test", ] } \ No newline at end of file diff --git a/frameworks/ets/input_event_client/user/main.ets b/frameworks/ets/input_event_client/user/main.ets new file mode 100644 index 0000000000..fc09e6c61a --- /dev/null +++ b/frameworks/ets/input_event_client/user/main.ets @@ -0,0 +1,3 @@ +function main() { + console.log("hello,workd") +} \ No newline at end of file -- Gitee