From 7b6a51c6b862d26e1653c00999ec2008f9b586b7 Mon Sep 17 00:00:00 2001 From: wangdi119 Date: Wed, 27 Jul 2022 14:38:38 +0800 Subject: [PATCH 001/360] =?UTF-8?q?=E2=80=9C=E9=BC=A0=E6=A0=87=E6=8D=95?= =?UTF-8?q?=E8=8E=B7=E6=A8=A1=E5=BC=8F=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangdi119 --- .../napi/mouse/include/js_mouse_context.h | 2 + .../napi/mouse/include/js_mouse_manager.h | 2 + .../napi/mouse/src/js_mouse_context.cpp | 64 +++++++++++++++++++ .../napi/mouse/src/js_mouse_manager.cpp | 46 +++++++++++++ 4 files changed, 114 insertions(+) diff --git a/frameworks/napi/mouse/include/js_mouse_context.h b/frameworks/napi/mouse/include/js_mouse_context.h index 264ea7a629..f1dce376c7 100755 --- a/frameworks/napi/mouse/include/js_mouse_context.h +++ b/frameworks/napi/mouse/include/js_mouse_context.h @@ -27,6 +27,8 @@ public: static napi_value Export(napi_env env, napi_value exports); static napi_value SetPointerVisible(napi_env env, napi_callback_info info); static napi_value IsPointerVisible(napi_env env, napi_callback_info info); + static napi_value EnterCaptureMode(napi_env env, napi_callback_info info); + static napi_value LeaveCaptureMode(napi_env env, napi_callback_info info); std::shared_ptr GetJsMouseMgr() const; private: diff --git a/frameworks/napi/mouse/include/js_mouse_manager.h b/frameworks/napi/mouse/include/js_mouse_manager.h index 0a0d84c580..4ecaedba2f 100755 --- a/frameworks/napi/mouse/include/js_mouse_manager.h +++ b/frameworks/napi/mouse/include/js_mouse_manager.h @@ -83,6 +83,8 @@ public: void ResetEnv(); napi_value SetPointerVisible(napi_env env, bool visible, napi_value handle = nullptr); napi_value IsPointerVisible(napi_env env, napi_value handle = nullptr); + napi_value EnterCaptureMode(napi_env env, int32_t windowId, napi_value handle = nullptr); + napi_value LeaveCaptureMode(napi_env env, int32_t windowId, napi_value handle = nullptr); }; } // namespace MMI } // namespace OHOS diff --git a/frameworks/napi/mouse/src/js_mouse_context.cpp b/frameworks/napi/mouse/src/js_mouse_context.cpp index 9618b7df75..a20600511a 100755 --- a/frameworks/napi/mouse/src/js_mouse_context.cpp +++ b/frameworks/napi/mouse/src/js_mouse_context.cpp @@ -164,6 +164,68 @@ napi_value JsMouseContext::IsPointerVisible(napi_env env, napi_callback_info inf return jsmouseMgr->IsPointerVisible(env, argv[0]); } +napi_value JsMouseContext::EnterCaptureMode(napi_env env, napi_callback_info info) +{ + CALL_DEBUG_ENTER; + size_t argc = 2; + napi_value argv[2]; + CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + if (argc < 1 || argc > 2) { + THROWERR(env, "the number of parameters is not as expected"); + return nullptr; + } + if (!JsCommon::TypeOf(env, argv[0], napi_number)) { + THROWERR(env, "The first parameter type is wrong"); + return nullptr; + } + + int32_t windowId = 0; + CHKRP(env, napi_get_value_int32(env, argv[0], &windowId), GET_BOOL); + + JsMouseContext *jsPointer = JsMouseContext::GetInstance(env); + auto jsmouseMgr = jsPointer->GetJsMouseMgr(); + if(argc == 1) + { + return jsmouseMgr->EnterCaptureMode(env,windowId); + } + if (!JsCommon::TypeOf(env, argv[1], napi_function)) { + THROWERR(env, "The second parameter type is wrong"); + return nullptr; + } + return jsmouseMgr->EnterCaptureMode(env, windowId, argv[1]); +} + +napi_value JsMouseContext::LeaveCaptureMode(napi_env env, napi_callback_info info) +{ + CALL_DEBUG_ENTER; + size_t argc = 2; + napi_value argv[2]; + CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + if (argc < 1 || argc > 2) { + THROWERR(env, "the number of parameters is not as expected"); + return nullptr; + } + if (!JsCommon::TypeOf(env, argv[0], napi_number)) { + THROWERR(env, "The first parameter type is wrong"); + return nullptr; + } + + int32_t windowId = 0; + CHKRP(env, napi_get_value_int32(env, argv[0], &windowId), GET_BOOL); + + JsMouseContext *jsPointer = JsMouseContext::GetInstance(env); + auto jsmouseMgr = jsPointer->GetJsMouseMgr(); + if(argc == 1) + { + return jsmouseMgr->LeaveCaptureMode(env,windowId); + } + if (!JsCommon::TypeOf(env, argv[1], napi_function)) { + THROWERR(env, "The second parameter type is wrong"); + return nullptr; + } + return jsmouseMgr->LeaveCaptureMode(env, windowId, argv[1]); +} + napi_value JsMouseContext::Export(napi_env env, napi_value exports) { CALL_DEBUG_ENTER; @@ -175,6 +237,8 @@ napi_value JsMouseContext::Export(napi_env env, napi_value exports) napi_property_descriptor desc[] = { DECLARE_NAPI_STATIC_FUNCTION("setPointerVisible", SetPointerVisible), DECLARE_NAPI_STATIC_FUNCTION("isPointerVisible", IsPointerVisible), + DECLARE_NAPI_STATIC_FUNCTION("setCaptureMode", EnterCaptureMode), + DECLARE_NAPI_STATIC_FUNCTION("setCaptureMode", LeaveCaptureMode), }; CHKRP(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc), DEFINE_PROPERTIES); return exports; diff --git a/frameworks/napi/mouse/src/js_mouse_manager.cpp b/frameworks/napi/mouse/src/js_mouse_manager.cpp index 59aab03d86..aee740251e 100755 --- a/frameworks/napi/mouse/src/js_mouse_manager.cpp +++ b/frameworks/napi/mouse/src/js_mouse_manager.cpp @@ -157,5 +157,51 @@ napi_value JsMouseManager::IsPointerVisible(napi_env env, napi_value handle) AsyncCallbackWork(asyncContext); return promise; } + +napi_value JsMouseManager::EnterCaptureMode(napi_env env, int32_t windowId, napi_value handle) +{ + CALL_DEBUG_ENTER; + sptr asyncContext = new (std::nothrow) AsyncContext(env); + if(asyncContext == nullptr) { + THROWERR(env,"create AsyncContext failed"); + return nullptr; + } + + asyncContext->errorCode = InputManager::GetInstance()->EnterCaptureMode(windowId); + asyncContext->reserve << ReturnType::VOID; + + napi_value promise = nullptr; + if(handle != nullptr) { + CHKRP(env, napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE); + CHKRP(env, napi_get_undefined(env, &promise), GET_UNDEFINED); + } else { + CHKRP(env, napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); + } + AsyncCallbackWork(asyncContext); + return promise; +} + +napi_value JsMouseManager::LeaveCaptureMode(napi_env env, int32_t windowId, napi_value handle) +{ + CALL_DEBUG_ENTER; + sptr asyncContext = new (std::nothrow) AsyncContext(env); + if(asyncContext == nullptr) { + THROWERR(env,"create AsyncContext failed"); + return nullptr; + } + + asyncContext->errorCode = InputManager::GetInstance()->LeaveCaptureMode(windowId); + asyncContext->reserve << ReturnType::VOID; + + napi_value promise = nullptr; + if(handle != nullptr) { + CHKRP(env, napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE); + CHKRP(env, napi_get_undefined(env, &promise), GET_UNDEFINED); + } else { + CHKRP(env, napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); + } + AsyncCallbackWork(asyncContext); + return promise; +} } // namespace MMI } // namespace OHOS \ No newline at end of file -- Gitee From 621bcadbab795d869eafeeda0693dacb7823cf1c Mon Sep 17 00:00:00 2001 From: wangdi119 Date: Wed, 27 Jul 2022 14:41:13 +0800 Subject: [PATCH 002/360] =?UTF-8?q?=E2=80=9C=E5=9B=9E=E9=80=80=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangdi119 --- .../napi/mouse/include/js_mouse_context.h | 2 - .../napi/mouse/include/js_mouse_manager.h | 2 - .../napi/mouse/src/js_mouse_context.cpp | 64 ------------------- .../napi/mouse/src/js_mouse_manager.cpp | 45 ------------- 4 files changed, 113 deletions(-) diff --git a/frameworks/napi/mouse/include/js_mouse_context.h b/frameworks/napi/mouse/include/js_mouse_context.h index f1dce376c7..264ea7a629 100755 --- a/frameworks/napi/mouse/include/js_mouse_context.h +++ b/frameworks/napi/mouse/include/js_mouse_context.h @@ -27,8 +27,6 @@ public: static napi_value Export(napi_env env, napi_value exports); static napi_value SetPointerVisible(napi_env env, napi_callback_info info); static napi_value IsPointerVisible(napi_env env, napi_callback_info info); - static napi_value EnterCaptureMode(napi_env env, napi_callback_info info); - static napi_value LeaveCaptureMode(napi_env env, napi_callback_info info); std::shared_ptr GetJsMouseMgr() const; private: diff --git a/frameworks/napi/mouse/include/js_mouse_manager.h b/frameworks/napi/mouse/include/js_mouse_manager.h index 4ecaedba2f..0a0d84c580 100755 --- a/frameworks/napi/mouse/include/js_mouse_manager.h +++ b/frameworks/napi/mouse/include/js_mouse_manager.h @@ -83,8 +83,6 @@ public: void ResetEnv(); napi_value SetPointerVisible(napi_env env, bool visible, napi_value handle = nullptr); napi_value IsPointerVisible(napi_env env, napi_value handle = nullptr); - napi_value EnterCaptureMode(napi_env env, int32_t windowId, napi_value handle = nullptr); - napi_value LeaveCaptureMode(napi_env env, int32_t windowId, napi_value handle = nullptr); }; } // namespace MMI } // namespace OHOS diff --git a/frameworks/napi/mouse/src/js_mouse_context.cpp b/frameworks/napi/mouse/src/js_mouse_context.cpp index a20600511a..9618b7df75 100755 --- a/frameworks/napi/mouse/src/js_mouse_context.cpp +++ b/frameworks/napi/mouse/src/js_mouse_context.cpp @@ -164,68 +164,6 @@ napi_value JsMouseContext::IsPointerVisible(napi_env env, napi_callback_info inf return jsmouseMgr->IsPointerVisible(env, argv[0]); } -napi_value JsMouseContext::EnterCaptureMode(napi_env env, napi_callback_info info) -{ - CALL_DEBUG_ENTER; - size_t argc = 2; - napi_value argv[2]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); - if (argc < 1 || argc > 2) { - THROWERR(env, "the number of parameters is not as expected"); - return nullptr; - } - if (!JsCommon::TypeOf(env, argv[0], napi_number)) { - THROWERR(env, "The first parameter type is wrong"); - return nullptr; - } - - int32_t windowId = 0; - CHKRP(env, napi_get_value_int32(env, argv[0], &windowId), GET_BOOL); - - JsMouseContext *jsPointer = JsMouseContext::GetInstance(env); - auto jsmouseMgr = jsPointer->GetJsMouseMgr(); - if(argc == 1) - { - return jsmouseMgr->EnterCaptureMode(env,windowId); - } - if (!JsCommon::TypeOf(env, argv[1], napi_function)) { - THROWERR(env, "The second parameter type is wrong"); - return nullptr; - } - return jsmouseMgr->EnterCaptureMode(env, windowId, argv[1]); -} - -napi_value JsMouseContext::LeaveCaptureMode(napi_env env, napi_callback_info info) -{ - CALL_DEBUG_ENTER; - size_t argc = 2; - napi_value argv[2]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); - if (argc < 1 || argc > 2) { - THROWERR(env, "the number of parameters is not as expected"); - return nullptr; - } - if (!JsCommon::TypeOf(env, argv[0], napi_number)) { - THROWERR(env, "The first parameter type is wrong"); - return nullptr; - } - - int32_t windowId = 0; - CHKRP(env, napi_get_value_int32(env, argv[0], &windowId), GET_BOOL); - - JsMouseContext *jsPointer = JsMouseContext::GetInstance(env); - auto jsmouseMgr = jsPointer->GetJsMouseMgr(); - if(argc == 1) - { - return jsmouseMgr->LeaveCaptureMode(env,windowId); - } - if (!JsCommon::TypeOf(env, argv[1], napi_function)) { - THROWERR(env, "The second parameter type is wrong"); - return nullptr; - } - return jsmouseMgr->LeaveCaptureMode(env, windowId, argv[1]); -} - napi_value JsMouseContext::Export(napi_env env, napi_value exports) { CALL_DEBUG_ENTER; @@ -237,8 +175,6 @@ napi_value JsMouseContext::Export(napi_env env, napi_value exports) napi_property_descriptor desc[] = { DECLARE_NAPI_STATIC_FUNCTION("setPointerVisible", SetPointerVisible), DECLARE_NAPI_STATIC_FUNCTION("isPointerVisible", IsPointerVisible), - DECLARE_NAPI_STATIC_FUNCTION("setCaptureMode", EnterCaptureMode), - DECLARE_NAPI_STATIC_FUNCTION("setCaptureMode", LeaveCaptureMode), }; CHKRP(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc), DEFINE_PROPERTIES); return exports; diff --git a/frameworks/napi/mouse/src/js_mouse_manager.cpp b/frameworks/napi/mouse/src/js_mouse_manager.cpp index aee740251e..575dc7aa27 100755 --- a/frameworks/napi/mouse/src/js_mouse_manager.cpp +++ b/frameworks/napi/mouse/src/js_mouse_manager.cpp @@ -158,50 +158,5 @@ napi_value JsMouseManager::IsPointerVisible(napi_env env, napi_value handle) return promise; } -napi_value JsMouseManager::EnterCaptureMode(napi_env env, int32_t windowId, napi_value handle) -{ - CALL_DEBUG_ENTER; - sptr asyncContext = new (std::nothrow) AsyncContext(env); - if(asyncContext == nullptr) { - THROWERR(env,"create AsyncContext failed"); - return nullptr; - } - - asyncContext->errorCode = InputManager::GetInstance()->EnterCaptureMode(windowId); - asyncContext->reserve << ReturnType::VOID; - - napi_value promise = nullptr; - if(handle != nullptr) { - CHKRP(env, napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE); - CHKRP(env, napi_get_undefined(env, &promise), GET_UNDEFINED); - } else { - CHKRP(env, napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); - } - AsyncCallbackWork(asyncContext); - return promise; -} - -napi_value JsMouseManager::LeaveCaptureMode(napi_env env, int32_t windowId, napi_value handle) -{ - CALL_DEBUG_ENTER; - sptr asyncContext = new (std::nothrow) AsyncContext(env); - if(asyncContext == nullptr) { - THROWERR(env,"create AsyncContext failed"); - return nullptr; - } - - asyncContext->errorCode = InputManager::GetInstance()->LeaveCaptureMode(windowId); - asyncContext->reserve << ReturnType::VOID; - - napi_value promise = nullptr; - if(handle != nullptr) { - CHKRP(env, napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE); - CHKRP(env, napi_get_undefined(env, &promise), GET_UNDEFINED); - } else { - CHKRP(env, napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); - } - AsyncCallbackWork(asyncContext); - return promise; -} } // namespace MMI } // namespace OHOS \ No newline at end of file -- Gitee From 5822d9f6fb9a8acd477229369fedaf1ba4bcfd89 Mon Sep 17 00:00:00 2001 From: yangli198 Date: Wed, 17 Aug 2022 11:23:42 +0800 Subject: [PATCH 003/360] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8C=87=E9=92=88?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangli198 --- service/BUILD.gn | 1 + service/event_handler/include/device_config.h | 73 ++++++++ .../include/input_event_normalize_handler.h | 1 + service/event_handler/src/device_config.cpp | 172 ++++++++++++++++++ .../src/input_event_normalize_handler.cpp | 3 + .../include/mouse_event_handler.h | 10 +- .../src/mouse_event_handler.cpp | 63 ++++++- 7 files changed, 314 insertions(+), 9 deletions(-) create mode 100644 service/event_handler/include/device_config.h create mode 100644 service/event_handler/src/device_config.cpp diff --git a/service/BUILD.gn b/service/BUILD.gn index a24bd5dc3b..501aacf269 100644 --- a/service/BUILD.gn +++ b/service/BUILD.gn @@ -141,6 +141,7 @@ ohos_shared_library("libmmi-server") { "event_handler/src/key_auto_repeat.cpp", "event_handler/src/key_event_value_transformation.cpp", "event_handler/src/key_map_manager.cpp", + "event_handler/src/device_config.cpp", "libinput_adapter/src/libinput_adapter.cpp", "message_handle/src/server_msg_handler.cpp", "module_loader/src/mmi_service.cpp", diff --git a/service/event_handler/include/device_config.h b/service/event_handler/include/device_config.h new file mode 100644 index 0000000000..8af261bcfb --- /dev/null +++ b/service/event_handler/include/device_config.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2022 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 DEVICE_CONFIG_H +#define DEVICE_CONFIG_H + +#include +#include +struct libinput_device; + +namespace OHOS { +namespace MMI { + +enum ConfigFileItem +{ + INVALID = -1, + POINTER_BASE = 0, + POINTER_SPEED, + KEYBOARD_BASE = 1000, + KEY_XXXX, +}; + +class DeviceConfigManagement { +public: + DeviceConfigManagement() = default; + ~DeviceConfigManagement() = default; + /* +/etc/mouse/common.conf +button_count = TTTTTTT + +/etc/mouse/1a-2b-3c-d.conf => device id: 30, 35 +include /etc/mouse/common.conf +speed = 100 +30 => {1 => 100, 2 => 3, } +/etc/mouse/1a-2b-3c-e.conf => device id: 40 +speed = 200 + +/etc/keyboard/01-20-3c-k.conf => device id: 10, 15 +layout = 104 +/etc/keyboard/01-24-3c-l.conf => device id: 20 +layout = 110 + */ + +public: + + int32_t AddDeviceProfile(struct libinput_device *device); + void RemoveDeviceProfile(struct libinput_device *device); + std::string GetEventFileName(struct libinput_device *device); +private: + typedef int32_t DeviceId; + std::map> deviceListConfig; + +private: + int32_t DeviceClassification(struct libinput_device *device, DeviceId deviceId); + int32_t DeviceConfiguration(struct libinput_device *device, DeviceId deviceId); + std::map ReadConfigFile(const std::string &filePath); + ConfigFileItem ConfigItemName2Id(const std::string &name); +}; +} // namespace MMI +} // namespace OHOS +#endif // DEVICE_CONFIG_H \ No newline at end of file diff --git a/service/event_handler/include/input_event_normalize_handler.h b/service/event_handler/include/input_event_normalize_handler.h index 48fa123fb4..757136068c 100755 --- a/service/event_handler/include/input_event_normalize_handler.h +++ b/service/event_handler/include/input_event_normalize_handler.h @@ -50,6 +50,7 @@ private: #ifdef OHOS_BUILD_ENABLE_KEYBOARD KeyEventHandler keyEventHandler_; #endif // OHOS_BUILD_ENABLE_KEYBOARD + DeviceConfigManagement configManagement_; }; } // namespace MMI } // namespace OHOS diff --git a/service/event_handler/src/device_config.cpp b/service/event_handler/src/device_config.cpp new file mode 100644 index 0000000000..3c42e9b3e8 --- /dev/null +++ b/service/event_handler/src/device_config.cpp @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2022 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 "device_config.h" + +#include "libinput.h" +#include "input_device.h" +#include "error_multimodal.h" +#include "mouse_event_handler.h" +#include "input_device_manager.h" + +namespace OHOS { +namespace MMI { +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "DeviceConfigManagement" }; +constexpr int32_t INVALID_DEVICE_ID = -1; + + +inline bool IsNumqq(const std::string &str) +{ + std::istringstream sin(str); + double num; + sin >> num; + return num; +} +} // namespace + +enum evdev_device_udev_tags { + EVDEV_UDEV_TAG_INPUT = 1 << 0, + EVDEV_UDEV_TAG_KEYBOARD = 1 << 1, + EVDEV_UDEV_TAG_MOUSE = 1 << 2, + EVDEV_UDEV_TAG_TOUCHPAD = 1 << 3, + EVDEV_UDEV_TAG_TOUCHSCREEN = 1 << 4, + EVDEV_UDEV_TAG_TABLET = 1 << 5, + EVDEV_UDEV_TAG_JOYSTICK = 1 << 6, + EVDEV_UDEV_TAG_ACCELEROMETER = 1 << 7, + EVDEV_UDEV_TAG_TABLET_PAD = 1 << 8, + EVDEV_UDEV_TAG_POINTINGSTICK = 1 << 9, + EVDEV_UDEV_TAG_TRACKBALL = 1 << 10, + EVDEV_UDEV_TAG_SWITCH = 1 << 11, +}; + +std::string DeviceConfigManagement::GetEventFileName(struct libinput_device *device) +{ + CALL_DEBUG_ENTER; + CHKPS(device); + uint32_t vendor = libinput_device_get_id_vendor(device); + uint32_t product = libinput_device_get_id_product(device); + uint32_t version = libinput_device_get_id_version(device); + const char *name = libinput_device_get_name(device); + CHKPS(name); + std::string fileName = std::to_string(vendor) + "_" + std::to_string(product) + "_" + + std::to_string(version) + "_" + name; + RemoveSpace(fileName); + return fileName; +} + +ConfigFileItem DeviceConfigManagement::ConfigItemName2Id(const std::string &name) +{ + static const std::map configList = { + {"speed", POINTER_SPEED}, + }; + + auto iter = configList.find(name); + if (iter == configList.end()) { + MMI_HILOGE("Device config file remove failed"); + return INVALID; + } + return configList.at(name); +} + +std::map DeviceConfigManagement::ReadConfigFile(const std::string &filePath) +{ + std::map configList; + FILE* fp = fopen(filePath.c_str(), "r"); + if (fp == nullptr) { + MMI_HILOGE("Config file open failed"); + return configList; + } + char buf[256] = {}; + std::string dataStr; + + while (fgets(buf, sizeof(buf), fp) != nullptr) { + dataStr = buf; + int32_t keyLen = dataStr.find_first_of(":"); + std::string key = dataStr.substr(0 , keyLen); + std::string value = dataStr.substr(keyLen + 1); + if (!IsNumqq(value)) { + continue; + } + configList[ConfigItemName2Id(key)] = std::stoi(value); + } + if (fclose(fp) != 0) { + MMI_HILOGW("Close file failed"); + } + return configList; +} + +int32_t DeviceConfigManagement::DeviceConfiguration(struct libinput_device *device, DeviceId deviceId) +{ + CALL_DEBUG_ENTER; + std::string fileName = "/vendor/etc/pointer/" + GetEventFileName(device) + ".TOML"; + auto configList = ReadConfigFile(fileName); + if (configList.empty()) { + MMI_HILOGE("configList is empty"); + return RET_ERR; + } + deviceListConfig[deviceId] = configList; + int32_t ret = MouseEventHdr->SetPointerSpeedWithDeviceId(deviceId, configList[POINTER_SPEED]); + if (ret != RET_OK) { + MMI_HILOGE("Pointer speed set failed, ret : %{public}d", ret); + } + return ret; +} + +int32_t DeviceConfigManagement::DeviceClassification(struct libinput_device *device, DeviceId deviceId) +{ + CHKPR(device, ERROR_NULL_POINTER); + uint32_t udevTags = static_cast(libinput_device_get_tags(device)); + if (udevTags & (EVDEV_UDEV_TAG_MOUSE | + EVDEV_UDEV_TAG_TRACKBALL | + EVDEV_UDEV_TAG_POINTINGSTICK | + EVDEV_UDEV_TAG_TOUCHPAD | + EVDEV_UDEV_TAG_TABLET_PAD)) { + return DeviceConfiguration(device, deviceId); + } + MMI_HILOGE("Device config set failed"); + return RET_ERR; +} + +int32_t DeviceConfigManagement::AddDeviceProfile(struct libinput_device *device) +{ + CALL_DEBUG_ENTER; + CHKPR(device, ERROR_NULL_POINTER); + int32_t deviceId = InputDevMgr->FindInputDeviceId(device); + if (deviceId == INVALID_DEVICE_ID) { + MMI_HILOGE("Find to device failed"); + return RET_ERR; + } + return DeviceClassification(device, deviceId); +} + +void DeviceConfigManagement::RemoveDeviceProfile(struct libinput_device *device) +{ + CALL_DEBUG_ENTER; + CHKPV(device); + int32_t deviceId = InputDevMgr->FindInputDeviceId(device); + auto iter = deviceListConfig.find(deviceId); + if (iter == deviceListConfig.end()) { + MMI_HILOGE("Device config file remove failed"); + return; + } + int32_t ret = MouseEventHdr->RemovePointerSpeed(deviceId); + if (ret != RET_OK) { + MMI_HILOGE("Pointer speed set failed, ret : %{public}d", ret); + } + deviceListConfig.erase(iter); +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/service/event_handler/src/input_event_normalize_handler.cpp b/service/event_handler/src/input_event_normalize_handler.cpp index 50da0f4996..13f5c9379f 100644 --- a/service/event_handler/src/input_event_normalize_handler.cpp +++ b/service/event_handler/src/input_event_normalize_handler.cpp @@ -28,6 +28,7 @@ #include "time_cost_chk.h" #include "timer_manager.h" #include "touch_transform_point_manager.h" +#include "device_config.h" namespace OHOS { namespace MMI { @@ -114,6 +115,7 @@ int32_t InputEventNormalizeHandler::OnEventDeviceAdded(libinput_event *event) InputDevMgr->OnInputDeviceAdded(device); KeyMapMgr->ParseDeviceConfigFile(device); KeyRepeat->AddDeviceConfig(device); + configManagement_.AddDeviceProfile(device); return RET_OK; } @@ -125,6 +127,7 @@ int32_t InputEventNormalizeHandler::OnEventDeviceRemoved(libinput_event *event) KeyMapMgr->RemoveKeyValue(device); KeyRepeat->RemoveDeviceConfig(device); InputDevMgr->OnInputDeviceRemoved(device); + configManagement_.RemoveDeviceProfile(device); return RET_OK; } diff --git a/service/mouse_event_handler/include/mouse_event_handler.h b/service/mouse_event_handler/include/mouse_event_handler.h index a77cea1e71..d7bbc82d2b 100644 --- a/service/mouse_event_handler/include/mouse_event_handler.h +++ b/service/mouse_event_handler/include/mouse_event_handler.h @@ -23,6 +23,7 @@ #include "singleton.h" #include "pointer_event.h" +#include namespace OHOS { namespace MMI { @@ -42,10 +43,13 @@ public: bool NormalizeMoveMouse(int32_t offsetX, int32_t offsetY); #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING int32_t SetPointerSpeed(int32_t speed); + int32_t SetPointerSpeedWithDeviceId(int32_t deviceId, int32_t speed); + int32_t RemovePointerSpeed(int32_t deviceId); int32_t GetPointerSpeed() const; + int32_t GetPointerSpeedWithDeviceId(int32_t deviceId) const; private: - int32_t HandleMotionInner(libinput_event_pointer* data); + int32_t HandleMotionInner(libinput_event_pointer* data, int32_t deviceId); int32_t HandleButtonInner(libinput_event_pointer* data); int32_t HandleAxisInner(libinput_event_pointer* data); void HandlePostInner(libinput_event_pointer* data, int32_t deviceId, PointerEvent::PointerItem& pointerItem); @@ -54,7 +58,7 @@ private: void HandlePostMoveMouse(PointerEvent::PointerItem& pointerItem); #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING int32_t HandleButtonValueInner(libinput_event_pointer* data); - int32_t HandleMotionCorrection(libinput_event_pointer* data); + int32_t HandleMotionCorrection(libinput_event_pointer* data, int32_t deviceId); bool GetSpeedGain(const double &vin, double& gain) const; void DumpInner(); void InitAbsolution(); @@ -68,6 +72,8 @@ private: bool isPressed_ { false }; int32_t currentDisplayId_ { -1 }; int32_t speed_ { DEFAULT_SPEED }; + std::map pointerDeviceSpeeds; + bool isJsPointerSpeed_ { false }; }; #define MouseEventHdr MouseEventHandler::GetInstance() diff --git a/service/mouse_event_handler/src/mouse_event_handler.cpp b/service/mouse_event_handler/src/mouse_event_handler.cpp index 49da40a579..d7b7486edc 100644 --- a/service/mouse_event_handler/src/mouse_event_handler.cpp +++ b/service/mouse_event_handler/src/mouse_event_handler.cpp @@ -67,7 +67,7 @@ bool MouseEventHandler::GetSpeedGain(const double& vin, double& gain) const return true; } -int32_t MouseEventHandler::HandleMotionInner(libinput_event_pointer* data) +int32_t MouseEventHandler::HandleMotionInner(libinput_event_pointer* data, int32_t deviceId) { CALL_DEBUG_ENTER; CHKPR(data, ERROR_NULL_POINTER); @@ -83,7 +83,7 @@ int32_t MouseEventHandler::HandleMotionInner(libinput_event_pointer* data) return RET_ERR; } - int32_t ret = HandleMotionCorrection(data); + int32_t ret = HandleMotionCorrection(data, deviceId); if (ret != RET_OK) { MMI_HILOGE("Failed to handle motion correction"); return ret; @@ -95,7 +95,7 @@ int32_t MouseEventHandler::HandleMotionInner(libinput_event_pointer* data) return RET_OK; } -int32_t MouseEventHandler::HandleMotionCorrection(libinput_event_pointer* data) +int32_t MouseEventHandler::HandleMotionCorrection(libinput_event_pointer* data, int32_t deviceId) { CALL_DEBUG_ENTER; CHKPR(data, ERROR_NULL_POINTER); @@ -107,8 +107,14 @@ int32_t MouseEventHandler::HandleMotionCorrection(libinput_event_pointer* data) MMI_HILOGE("Get speed gain failed"); return RET_ERR; } - double correctionX = dx * gain * static_cast(speed_) / 10.0; - double correctionY = dy * gain * static_cast(speed_) / 10.0; + int32_t speedTmp = 0; + if (isJsPointerSpeed_){ + speedTmp = speed_; + } else { + speedTmp = GetPointerSpeedWithDeviceId(deviceId); + } + double correctionX = dx * gain * static_cast(speedTmp) / 10.0; + double correctionY = dy * gain * static_cast(speedTmp) / 10.0; MMI_HILOGD("Get and process the movement coordinates, dx:%{public}lf, dy:%{public}lf," "correctionX:%{public}lf, correctionY:%{public}lf, gain:%{public}lf", dx, dy, correctionX, correctionY, gain); @@ -269,10 +275,11 @@ int32_t MouseEventHandler::Normalize(struct libinput_event *event) pointerEvent_->ClearAxisValue(); int32_t result; const int32_t type = libinput_event_get_type(event); + int32_t deviceId = InputDevMgr->FindInputDeviceId(libinput_event_get_device(event)); switch (type) { case LIBINPUT_EVENT_POINTER_MOTION: case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: { - result = HandleMotionInner(data); + result = HandleMotionInner(data, deviceId); break; } case LIBINPUT_EVENT_POINTER_BUTTON: { @@ -288,7 +295,7 @@ int32_t MouseEventHandler::Normalize(struct libinput_event *event) return RET_ERR; } } - int32_t deviceId = InputDevMgr->FindInputDeviceId(libinput_event_get_device(event)); + PointerEvent::PointerItem pointerItem; HandlePostInner(data, deviceId, pointerItem); WinMgr->UpdateTargetPointer(pointerEvent_); @@ -387,9 +394,51 @@ int32_t MouseEventHandler::SetPointerSpeed(int32_t speed) speed_ = speed; } MMI_HILOGD("Set pointer speed:%{public}d", speed_); + isJsPointerSpeed_ = true; + return RET_OK; +} + +int32_t MouseEventHandler::SetPointerSpeedWithDeviceId(int32_t deviceId, int32_t speed) +{ + CALL_DEBUG_ENTER; + int32_t speedTmp = speed; + if (speed < MIN_SPEED) { + speedTmp = MIN_SPEED; + } else if (speed > MAX_SPEED) { + speedTmp = MAX_SPEED; + } else { + speedTmp = speed; + } + MMI_HILOGD("Set pointer speed:%{public}d", speedTmp); + pointerDeviceSpeeds[deviceId] = speedTmp; + // Notify + return RET_OK; +} + +int32_t MouseEventHandler::RemovePointerSpeed(int32_t deviceId) +{ + CALL_DEBUG_ENTER; + auto it = pointerDeviceSpeeds.find(deviceId); + if (it == pointerDeviceSpeeds.end()) { + pointerDeviceSpeeds.erase(it); + MMI_HILOGD("remove pointer speed with deviceId:%{public}d", deviceId); + } + // notify return RET_OK; } +int32_t MouseEventHandler::GetPointerSpeedWithDeviceId(int32_t deviceId) const +{ + CALL_DEBUG_ENTER; + auto it = pointerDeviceSpeeds.find(deviceId); + if (it == pointerDeviceSpeeds.end()) { + MMI_HILOGD("Not find speed with deviceId:%{public}d", deviceId); + return speed_; + } + MMI_HILOGD("Get pointer speed:%{public}d", speed_); + return pointerDeviceSpeeds.at(deviceId); +} + int32_t MouseEventHandler::GetPointerSpeed() const { CALL_DEBUG_ENTER; -- Gitee From 93209cd1bfdd25f00d654538a2b1aa7fa3a51421 Mon Sep 17 00:00:00 2001 From: yangli198 Date: Thu, 18 Aug 2022 11:29:50 +0800 Subject: [PATCH 004/360] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8C=87=E9=92=88?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangli198 --- service/BUILD.gn | 2 +- ...e_config.h => device_config_file_parser.h} | 21 +++--- .../include/input_event_normalize_handler.h | 1 - ...nfig.cpp => device_config_file_parser.cpp} | 71 +++++++++---------- .../src/input_event_normalize_handler.cpp | 7 +- .../include/mouse_event_handler.h | 5 +- .../src/mouse_event_handler.cpp | 58 ++++++++------- 7 files changed, 82 insertions(+), 83 deletions(-) rename service/event_handler/include/{device_config.h => device_config_file_parser.h} (83%) rename service/event_handler/src/{device_config.cpp => device_config_file_parser.cpp} (75%) diff --git a/service/BUILD.gn b/service/BUILD.gn index 501aacf269..ca6da310f3 100644 --- a/service/BUILD.gn +++ b/service/BUILD.gn @@ -141,7 +141,7 @@ ohos_shared_library("libmmi-server") { "event_handler/src/key_auto_repeat.cpp", "event_handler/src/key_event_value_transformation.cpp", "event_handler/src/key_map_manager.cpp", - "event_handler/src/device_config.cpp", + "event_handler/src/device_config_file_parser.cpp", "libinput_adapter/src/libinput_adapter.cpp", "message_handle/src/server_msg_handler.cpp", "module_loader/src/mmi_service.cpp", diff --git a/service/event_handler/include/device_config.h b/service/event_handler/include/device_config_file_parser.h similarity index 83% rename from service/event_handler/include/device_config.h rename to service/event_handler/include/device_config_file_parser.h index 8af261bcfb..58f4137e61 100644 --- a/service/event_handler/include/device_config.h +++ b/service/event_handler/include/device_config_file_parser.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef DEVICE_CONFIG_H -#define DEVICE_CONFIG_H +#ifndef DEVICE_CONFIG_FILE_PARSER_H +#define DEVICE_CONFIG_FILE_PARSER_H #include #include @@ -22,8 +22,7 @@ struct libinput_device; namespace OHOS { namespace MMI { - -enum ConfigFileItem +enum class ConfigFileItem { INVALID = -1, POINTER_BASE = 0, @@ -31,7 +30,6 @@ enum ConfigFileItem KEYBOARD_BASE = 1000, KEY_XXXX, }; - class DeviceConfigManagement { public: DeviceConfigManagement() = default; @@ -54,13 +52,12 @@ layout = 110 */ public: - - int32_t AddDeviceProfile(struct libinput_device *device); - void RemoveDeviceProfile(struct libinput_device *device); - std::string GetEventFileName(struct libinput_device *device); + int32_t OnDeviceAdd(struct libinput_device *device); + void OnDeviceRemove(struct libinput_device *device); + std::string CombDeviceFileName(struct libinput_device *device); private: - typedef int32_t DeviceId; - std::map> deviceListConfig; + using DeviceId = int32_t; + std::map> deviceConfigs_; private: int32_t DeviceClassification(struct libinput_device *device, DeviceId deviceId); @@ -70,4 +67,4 @@ private: }; } // namespace MMI } // namespace OHOS -#endif // DEVICE_CONFIG_H \ No newline at end of file +#endif // DEVICE_CONFIG_FILE_PARSER_H \ No newline at end of file diff --git a/service/event_handler/include/input_event_normalize_handler.h b/service/event_handler/include/input_event_normalize_handler.h index 757136068c..48fa123fb4 100755 --- a/service/event_handler/include/input_event_normalize_handler.h +++ b/service/event_handler/include/input_event_normalize_handler.h @@ -50,7 +50,6 @@ private: #ifdef OHOS_BUILD_ENABLE_KEYBOARD KeyEventHandler keyEventHandler_; #endif // OHOS_BUILD_ENABLE_KEYBOARD - DeviceConfigManagement configManagement_; }; } // namespace MMI } // namespace OHOS diff --git a/service/event_handler/src/device_config.cpp b/service/event_handler/src/device_config_file_parser.cpp similarity index 75% rename from service/event_handler/src/device_config.cpp rename to service/event_handler/src/device_config_file_parser.cpp index 3c42e9b3e8..f87a0b5115 100644 --- a/service/event_handler/src/device_config.cpp +++ b/service/event_handler/src/device_config_file_parser.cpp @@ -13,8 +13,8 @@ * limitations under the License. */ -#include "device_config.h" - +#include "device_config_file_parser.h" +#include #include "libinput.h" #include "input_device.h" #include "error_multimodal.h" @@ -26,15 +26,7 @@ namespace MMI { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "DeviceConfigManagement" }; constexpr int32_t INVALID_DEVICE_ID = -1; - - -inline bool IsNumqq(const std::string &str) -{ - std::istringstream sin(str); - double num; - sin >> num; - return num; -} +constexpr int32_t COMMENT_SUBSCRIPT = 0; } // namespace enum evdev_device_udev_tags { @@ -52,7 +44,7 @@ enum evdev_device_udev_tags { EVDEV_UDEV_TAG_SWITCH = 1 << 11, }; -std::string DeviceConfigManagement::GetEventFileName(struct libinput_device *device) +std::string DeviceConfigManagement::CombDeviceFileName(struct libinput_device *device) { CALL_DEBUG_ENTER; CHKPS(device); @@ -70,13 +62,13 @@ std::string DeviceConfigManagement::GetEventFileName(struct libinput_device *dev ConfigFileItem DeviceConfigManagement::ConfigItemName2Id(const std::string &name) { static const std::map configList = { - {"speed", POINTER_SPEED}, + {"speed", ConfigFileItem::POINTER_SPEED}, }; auto iter = configList.find(name); if (iter == configList.end()) { MMI_HILOGE("Device config file remove failed"); - return INVALID; + return ConfigFileItem::INVALID; } return configList.at(name); } @@ -84,41 +76,46 @@ ConfigFileItem DeviceConfigManagement::ConfigItemName2Id(const std::string &name std::map DeviceConfigManagement::ReadConfigFile(const std::string &filePath) { std::map configList; - FILE* fp = fopen(filePath.c_str(), "r"); - if (fp == nullptr) { - MMI_HILOGE("Config file open failed"); + std::ifstream cfgFile(filePath); + if (!cfgFile.is_open()) { + MMI_HILOGE("Failed to open config file"); return configList; } - char buf[256] = {}; - std::string dataStr; + std::string tmp; - while (fgets(buf, sizeof(buf), fp) != nullptr) { - dataStr = buf; - int32_t keyLen = dataStr.find_first_of(":"); - std::string key = dataStr.substr(0 , keyLen); - std::string value = dataStr.substr(keyLen + 1); - if (!IsNumqq(value)) { - continue; + while (std::getline(cfgFile, tmp)) { + RemoveSpace(tmp); + size_t pos = tmp.find('#'); + if (pos != tmp.npos && pos != COMMENT_SUBSCRIPT) { + continue; + } + if (tmp.empty() || tmp.front() == '#') { + continue; } + pos = tmp.find('='); + if (pos == (tmp.size() - 1) || pos == tmp.npos) { + continue; + } + std::string key = tmp.substr(0, pos); + std::string value = tmp.substr(pos + 1); configList[ConfigItemName2Id(key)] = std::stoi(value); } - if (fclose(fp) != 0) { - MMI_HILOGW("Close file failed"); - } + cfgFile.close(); return configList; } int32_t DeviceConfigManagement::DeviceConfiguration(struct libinput_device *device, DeviceId deviceId) { CALL_DEBUG_ENTER; - std::string fileName = "/vendor/etc/pointer/" + GetEventFileName(device) + ".TOML"; + std::string fileName = "/vendor/etc/pointer/" + CombDeviceFileName(device) + ".TOML"; auto configList = ReadConfigFile(fileName); if (configList.empty()) { MMI_HILOGE("configList is empty"); return RET_ERR; } - deviceListConfig[deviceId] = configList; - int32_t ret = MouseEventHdr->SetPointerSpeedWithDeviceId(deviceId, configList[POINTER_SPEED]); + deviceConfigs_[deviceId] = configList; + int32_t ret = MouseEventHdr->SetPointerSpeedWithDeviceId(deviceId, + configList[ConfigFileItem::POINTER_SPEED]); if (ret != RET_OK) { MMI_HILOGE("Pointer speed set failed, ret : %{public}d", ret); } @@ -140,7 +137,7 @@ int32_t DeviceConfigManagement::DeviceClassification(struct libinput_device *dev return RET_ERR; } -int32_t DeviceConfigManagement::AddDeviceProfile(struct libinput_device *device) +int32_t DeviceConfigManagement::OnDeviceAdd(struct libinput_device *device) { CALL_DEBUG_ENTER; CHKPR(device, ERROR_NULL_POINTER); @@ -152,13 +149,13 @@ int32_t DeviceConfigManagement::AddDeviceProfile(struct libinput_device *device) return DeviceClassification(device, deviceId); } -void DeviceConfigManagement::RemoveDeviceProfile(struct libinput_device *device) +void DeviceConfigManagement::OnDeviceRemove(struct libinput_device *device) { CALL_DEBUG_ENTER; CHKPV(device); int32_t deviceId = InputDevMgr->FindInputDeviceId(device); - auto iter = deviceListConfig.find(deviceId); - if (iter == deviceListConfig.end()) { + auto iter = deviceConfigs_.find(deviceId); + if (iter == deviceConfigs_.end()) { MMI_HILOGE("Device config file remove failed"); return; } @@ -166,7 +163,7 @@ void DeviceConfigManagement::RemoveDeviceProfile(struct libinput_device *device) if (ret != RET_OK) { MMI_HILOGE("Pointer speed set failed, ret : %{public}d", ret); } - deviceListConfig.erase(iter); + deviceConfigs_.erase(iter); } } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/service/event_handler/src/input_event_normalize_handler.cpp b/service/event_handler/src/input_event_normalize_handler.cpp index 13f5c9379f..ff457ce78a 100644 --- a/service/event_handler/src/input_event_normalize_handler.cpp +++ b/service/event_handler/src/input_event_normalize_handler.cpp @@ -28,12 +28,13 @@ #include "time_cost_chk.h" #include "timer_manager.h" #include "touch_transform_point_manager.h" -#include "device_config.h" +#include "device_config_file_parser.h" namespace OHOS { namespace MMI { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputEventNormalizeHandler" }; +DeviceConfigManagement configManagement_; } void InputEventNormalizeHandler::HandleEvent(libinput_event* event) @@ -115,7 +116,7 @@ int32_t InputEventNormalizeHandler::OnEventDeviceAdded(libinput_event *event) InputDevMgr->OnInputDeviceAdded(device); KeyMapMgr->ParseDeviceConfigFile(device); KeyRepeat->AddDeviceConfig(device); - configManagement_.AddDeviceProfile(device); + configManagement_.OnDeviceAdd(device); return RET_OK; } @@ -127,7 +128,7 @@ int32_t InputEventNormalizeHandler::OnEventDeviceRemoved(libinput_event *event) KeyMapMgr->RemoveKeyValue(device); KeyRepeat->RemoveDeviceConfig(device); InputDevMgr->OnInputDeviceRemoved(device); - configManagement_.RemoveDeviceProfile(device); + configManagement_.OnDeviceRemove(device); return RET_OK; } diff --git a/service/mouse_event_handler/include/mouse_event_handler.h b/service/mouse_event_handler/include/mouse_event_handler.h index d7bbc82d2b..a484d7929d 100644 --- a/service/mouse_event_handler/include/mouse_event_handler.h +++ b/service/mouse_event_handler/include/mouse_event_handler.h @@ -46,7 +46,7 @@ public: int32_t SetPointerSpeedWithDeviceId(int32_t deviceId, int32_t speed); int32_t RemovePointerSpeed(int32_t deviceId); int32_t GetPointerSpeed() const; - int32_t GetPointerSpeedWithDeviceId(int32_t deviceId) const; + int32_t GetPointerSpeedByDeviceId(int32_t deviceId) const; private: int32_t HandleMotionInner(libinput_event_pointer* data, int32_t deviceId); @@ -62,6 +62,7 @@ private: bool GetSpeedGain(const double &vin, double& gain) const; void DumpInner(); void InitAbsolution(); + int32_t GetSpeed(int32_t deviceId); private: std::shared_ptr pointerEvent_ { nullptr }; @@ -73,7 +74,7 @@ private: int32_t currentDisplayId_ { -1 }; int32_t speed_ { DEFAULT_SPEED }; std::map pointerDeviceSpeeds; - bool isJsPointerSpeed_ { false }; + bool isSpeedSetByUser_ { false }; }; #define MouseEventHdr MouseEventHandler::GetInstance() diff --git a/service/mouse_event_handler/src/mouse_event_handler.cpp b/service/mouse_event_handler/src/mouse_event_handler.cpp index d7b7486edc..ac9c9166ef 100644 --- a/service/mouse_event_handler/src/mouse_event_handler.cpp +++ b/service/mouse_event_handler/src/mouse_event_handler.cpp @@ -38,7 +38,21 @@ const std::array SPEED_DIFF_NUMS { 0.0, -2.0, -5.0, -19.0, -28.6, -57 constexpr double DOUBLE_ZERO = 1e-6; constexpr int32_t MIN_SPEED = 1; constexpr int32_t MAX_SPEED = 11; +int32_t PointerSpeedCheck(int32_t speed) +{ + if (speed < MIN_SPEED) { + MMI_HILOGW("Set pointer speed less than minimum speed:%{public}d", speed); + return MIN_SPEED; + } else if (speed > MAX_SPEED) { + MMI_HILOGW("Set pointer speed greater than the maximum value speed:%{public}d", speed); + return MAX_SPEED; + } else { + return speed; + } +} } // namespace + + MouseEventHandler::MouseEventHandler() { pointerEvent_ = PointerEvent::Create(); @@ -50,6 +64,15 @@ std::shared_ptr MouseEventHandler::GetPointerEvent() const return pointerEvent_; } +int32_t MouseEventHandler::GetSpeed(int32_t deviceId) +{ + if (isSpeedSetByUser_) { + return speed_; + } else { + return GetPointerSpeedByDeviceId(deviceId); + } +} + bool MouseEventHandler::GetSpeedGain(const double& vin, double& gain) const { if (abs(vin) < DOUBLE_ZERO) { @@ -107,14 +130,9 @@ int32_t MouseEventHandler::HandleMotionCorrection(libinput_event_pointer* data, MMI_HILOGE("Get speed gain failed"); return RET_ERR; } - int32_t speedTmp = 0; - if (isJsPointerSpeed_){ - speedTmp = speed_; - } else { - speedTmp = GetPointerSpeedWithDeviceId(deviceId); - } - double correctionX = dx * gain * static_cast(speedTmp) / 10.0; - double correctionY = dy * gain * static_cast(speedTmp) / 10.0; + int32_t speed = GetSpeed(deviceId); + double correctionX = dx * gain * static_cast(speed) / 10.0; + double correctionY = dy * gain * static_cast(speed) / 10.0; MMI_HILOGD("Get and process the movement coordinates, dx:%{public}lf, dy:%{public}lf," "correctionX:%{public}lf, correctionY:%{public}lf, gain:%{public}lf", dx, dy, correctionX, correctionY, gain); @@ -386,31 +404,17 @@ void MouseEventHandler::Dump(int32_t fd, const std::vector &args) int32_t MouseEventHandler::SetPointerSpeed(int32_t speed) { CALL_DEBUG_ENTER; - if (speed < MIN_SPEED) { - speed_ = MIN_SPEED; - } else if (speed > MAX_SPEED) { - speed_ = MAX_SPEED; - } else { - speed_ = speed; - } + speed_ = PointerSpeedCheck(speed); MMI_HILOGD("Set pointer speed:%{public}d", speed_); - isJsPointerSpeed_ = true; + isSpeedSetByUser_ = true; return RET_OK; } int32_t MouseEventHandler::SetPointerSpeedWithDeviceId(int32_t deviceId, int32_t speed) { CALL_DEBUG_ENTER; - int32_t speedTmp = speed; - if (speed < MIN_SPEED) { - speedTmp = MIN_SPEED; - } else if (speed > MAX_SPEED) { - speedTmp = MAX_SPEED; - } else { - speedTmp = speed; - } - MMI_HILOGD("Set pointer speed:%{public}d", speedTmp); - pointerDeviceSpeeds[deviceId] = speedTmp; + pointerDeviceSpeeds[deviceId] = PointerSpeedCheck(speed); + MMI_HILOGD("Set pointer speed:%{public}d", pointerDeviceSpeeds[deviceId]); // Notify return RET_OK; } @@ -427,7 +431,7 @@ int32_t MouseEventHandler::RemovePointerSpeed(int32_t deviceId) return RET_OK; } -int32_t MouseEventHandler::GetPointerSpeedWithDeviceId(int32_t deviceId) const +int32_t MouseEventHandler::GetPointerSpeedByDeviceId(int32_t deviceId) const { CALL_DEBUG_ENTER; auto it = pointerDeviceSpeeds.find(deviceId); -- Gitee From 85d9677a00ead1912b1b97a0950823c2d76ee19e Mon Sep 17 00:00:00 2001 From: yangli198 Date: Thu, 18 Aug 2022 16:54:37 +0800 Subject: [PATCH 005/360] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8C=87=E9=92=88?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangli198 --- service/BUILD.gn | 3 ++- .../include/device_config_file_parser.h | 20 ------------------- .../src/device_config_file_parser.cpp | 0 3 files changed, 2 insertions(+), 21 deletions(-) rename service/{event_handler => device_config}/include/device_config_file_parser.h (80%) rename service/{event_handler => device_config}/src/device_config_file_parser.cpp (100%) diff --git a/service/BUILD.gn b/service/BUILD.gn index ca6da310f3..b98f6d92e2 100644 --- a/service/BUILD.gn +++ b/service/BUILD.gn @@ -17,6 +17,7 @@ mmi_service_path = "${mmi_path}/service" config("libmmi_server_config") { include_dirs = [ + "device_config/include", "device_manager/include", "device_scalability/include", "delegate_task/include", @@ -131,6 +132,7 @@ ohos_shared_library("libmmi-server") { sources = [ "//foundation/multimodalinput/input/frameworks/proxy/event_handler/src/bytrace_adapter.cpp", "delegate_task/src/delegate_tasks.cpp", + "device_config/src/device_config_file_parser.cpp", "device_manager/src/input_device_manager.cpp", "dfx/src/dfx_hisysevent.cpp", "event_dispatch/src/event_dispatch.cpp", @@ -141,7 +143,6 @@ ohos_shared_library("libmmi-server") { "event_handler/src/key_auto_repeat.cpp", "event_handler/src/key_event_value_transformation.cpp", "event_handler/src/key_map_manager.cpp", - "event_handler/src/device_config_file_parser.cpp", "libinput_adapter/src/libinput_adapter.cpp", "message_handle/src/server_msg_handler.cpp", "module_loader/src/mmi_service.cpp", diff --git a/service/event_handler/include/device_config_file_parser.h b/service/device_config/include/device_config_file_parser.h similarity index 80% rename from service/event_handler/include/device_config_file_parser.h rename to service/device_config/include/device_config_file_parser.h index 58f4137e61..887943fecd 100644 --- a/service/event_handler/include/device_config_file_parser.h +++ b/service/device_config/include/device_config_file_parser.h @@ -27,30 +27,11 @@ enum class ConfigFileItem INVALID = -1, POINTER_BASE = 0, POINTER_SPEED, - KEYBOARD_BASE = 1000, - KEY_XXXX, }; class DeviceConfigManagement { public: DeviceConfigManagement() = default; ~DeviceConfigManagement() = default; - /* -/etc/mouse/common.conf -button_count = TTTTTTT - -/etc/mouse/1a-2b-3c-d.conf => device id: 30, 35 -include /etc/mouse/common.conf -speed = 100 -30 => {1 => 100, 2 => 3, } -/etc/mouse/1a-2b-3c-e.conf => device id: 40 -speed = 200 - -/etc/keyboard/01-20-3c-k.conf => device id: 10, 15 -layout = 104 -/etc/keyboard/01-24-3c-l.conf => device id: 20 -layout = 110 - */ - public: int32_t OnDeviceAdd(struct libinput_device *device); void OnDeviceRemove(struct libinput_device *device); @@ -58,7 +39,6 @@ public: private: using DeviceId = int32_t; std::map> deviceConfigs_; - private: int32_t DeviceClassification(struct libinput_device *device, DeviceId deviceId); int32_t DeviceConfiguration(struct libinput_device *device, DeviceId deviceId); diff --git a/service/event_handler/src/device_config_file_parser.cpp b/service/device_config/src/device_config_file_parser.cpp similarity index 100% rename from service/event_handler/src/device_config_file_parser.cpp rename to service/device_config/src/device_config_file_parser.cpp -- Gitee From 3f1f0eeb1b6d2b51189098f50378840ba07aff93 Mon Sep 17 00:00:00 2001 From: yangli198 Date: Tue, 23 Aug 2022 11:16:57 +0800 Subject: [PATCH 006/360] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8D=95=E8=8E=B7?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangli198 --- .../include/input_manager_impl.h | 4 ++- .../event_handler/src/input_manager_impl.cpp | 34 +++++++++++++++++++ frameworks/proxy/events/src/input_manager.cpp | 10 ++++++ frameworks/proxy/events/src/pointer_event.cpp | 28 +++++++++++++-- .../innerkits/event/include/pointer_event.h | 33 ++++++++++++++++++ .../innerkits/proxy/include/input_manager.h | 18 +++++++++- .../include/i_multimodal_input_connect.h | 2 ++ .../multimodal_input_connect_manager.h | 1 + .../include/multimodal_input_connect_proxy.h | 1 + .../include/multimodal_input_connect_stub.h | 1 + .../src/multimodal_input_connect_manager.cpp | 6 ++++ .../src/multimodal_input_connect_proxy.cpp | 21 ++++++++++++ .../src/multimodal_input_connect_stub.cpp | 17 +++++++++- service/module_loader/include/mmi_service.h | 1 + service/module_loader/src/mmi_service.cpp | 11 ++++++ .../src/mouse_event_handler.cpp | 10 ++++-- .../include/input_windows_manager.h | 7 +++- .../src/input_windows_manager.cpp | 25 ++++++++++++++ test/unittest/common/src/event_util_test.cpp | 3 +- 19 files changed, 224 insertions(+), 9 deletions(-) diff --git a/frameworks/proxy/event_handler/include/input_manager_impl.h b/frameworks/proxy/event_handler/include/input_manager_impl.h index e0bd698a85..ecd127556c 100644 --- a/frameworks/proxy/event_handler/include/input_manager_impl.h +++ b/frameworks/proxy/event_handler/include/input_manager_impl.h @@ -108,7 +108,7 @@ public: void SetAnrObserver(std::shared_ptr observer); void OnAnr(int32_t pid); - + int32_t SetPointerLocation(int32_t x, int32_t y); using DeviceUniqId = std::tuple; int32_t SetInputDeviceSeatName(const std::string& seatName, DeviceUniqId& deviceUniqId); @@ -118,6 +118,8 @@ public: int32_t UnprepareRemoteInput(const std::string& deviceId, std::function callback); int32_t StartRemoteInput(const std::string& deviceId, uint32_t inputAbility, std::function callback); int32_t StopRemoteInput(const std::string& deviceId, uint32_t inputAbility, std::function callback); + int32_t EnterCaptureMode(int32_t windowId); + int32_t LeaveCaptureMode(int32_t windowId); private: int32_t PackWindowInfo(NetPacket &pkt); diff --git a/frameworks/proxy/event_handler/src/input_manager_impl.cpp b/frameworks/proxy/event_handler/src/input_manager_impl.cpp index c4cc6b3e35..6ca059ca23 100644 --- a/frameworks/proxy/event_handler/src/input_manager_impl.cpp +++ b/frameworks/proxy/event_handler/src/input_manager_impl.cpp @@ -534,6 +534,7 @@ int32_t InputManagerImpl::SetPointerVisible(bool visible) { #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) CALL_DEBUG_ENTER; + std::lock_guard guard(mtx_); int32_t ret = MultimodalInputConnMgr->SetPointerVisible(visible); if (ret != RET_OK) { MMI_HILOGE("Set pointer visible failed, ret:%{public}d", ret); @@ -549,6 +550,7 @@ bool InputManagerImpl::IsPointerVisible() { #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) CALL_DEBUG_ENTER; + std::lock_guard guard(mtx_); bool visible; int32_t ret = MultimodalInputConnMgr->IsPointerVisible(visible); if (ret != 0) { @@ -913,5 +915,37 @@ int32_t InputManagerImpl::StopRemoteInput(const std::string& deviceId, return RET_OK; #endif // OHOS_DISTRIBUTED_INPUT_MODEL } + +int32_t InputManagerImpl::EnterCaptureMode(int32_t windowId) +{ +#if defined(OHOS_BUILD_ENABLE_POINTER) + CALL_DEBUG_ENTER; + std::lock_guard guard(mtx_); + int32_t ret = MultimodalInputConnMgr->SetMouseCaptureMode(windowId, true); + if (ret != RET_OK) { + MMI_HILOGE("Enter captrue mode failed"); + } + return ret; +#else + MMI_HILOGW("Pointer device module does not support"); + return ERROR_UNSUPPORT; +#endif // OHOS_BUILD_ENABLE_POINTER +} + +int32_t InputManagerImpl::LeaveCaptureMode(int32_t windowId) +{ +#if defined(OHOS_BUILD_ENABLE_POINTER) + CALL_DEBUG_ENTER; + std::lock_guard guard(mtx_); + int32_t ret = MultimodalInputConnMgr->SetMouseCaptureMode(windowId, false); + if (ret != RET_OK) { + MMI_HILOGE("Leave captrue mode failed"); + } + return ret; +#else + MMI_HILOGW("Pointer device module does not support"); + return ERROR_UNSUPPORT; +#endif // OHOS_BUILD_ENABLE_POINTER +} } // namespace MMI } // namespace OHOS diff --git a/frameworks/proxy/events/src/input_manager.cpp b/frameworks/proxy/events/src/input_manager.cpp index c20a0a7747..4255f82bea 100644 --- a/frameworks/proxy/events/src/input_manager.cpp +++ b/frameworks/proxy/events/src/input_manager.cpp @@ -223,5 +223,15 @@ int32_t InputManager::StopRemoteInput(const std::string& deviceId, uint32_t inpu { return InputManagerImpl::GetInstance()->StopRemoteInput(deviceId, inputAbility, callback); } + +int32_t InputManager::EnterCaptureMode(int32_t windowId) +{ + return InputMgrImpl->EnterCaptureMode(windowId); +} + +int32_t InputManager::LeaveCaptureMode(int32_t windowId) +{ + return InputMgrImpl->LeaveCaptureMode(windowId); +} } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/frameworks/proxy/events/src/pointer_event.cpp b/frameworks/proxy/events/src/pointer_event.cpp index db85473235..92c1fa6906 100644 --- a/frameworks/proxy/events/src/pointer_event.cpp +++ b/frameworks/proxy/events/src/pointer_event.cpp @@ -266,6 +266,26 @@ void PointerEvent::PointerItem::SetTargetWindowId(int32_t windowId) targetWindowId_ = windowId; } +int32_t PointerEvent::PointerItem::GetRawDeltaX() const +{ + return rawDeltaX_; +} + +void PointerEvent::PointerItem::SetRawDeltaX(int32_t rawDeltaX) +{ + rawDeltaX_ = rawDeltaX; +} + +int32_t PointerEvent::PointerItem::GetRawDeltaY() const +{ + return rawDeltaY_; +} + +void PointerEvent::PointerItem::SetRawDeltaY(int32_t rawDeltaY) +{ + rawDeltaY_ = rawDeltaY; +} + bool PointerEvent::PointerItem::WriteToParcel(Parcel &out) const { return ( @@ -290,7 +310,9 @@ bool PointerEvent::PointerItem::WriteToParcel(Parcel &out) const out.WriteInt32(longAxis_) && out.WriteInt32(shortAxis_) && out.WriteInt32(toolType_) && - out.WriteInt32(deviceId_) + out.WriteInt32(deviceId_) && + out.WriteInt32(rawDeltaX_) && + out.WriteInt32(rawDeltaY_) ); } @@ -318,7 +340,9 @@ bool PointerEvent::PointerItem::ReadFromParcel(Parcel &in) in.ReadInt32(longAxis_) && in.ReadInt32(shortAxis_) && in.ReadInt32(toolType_) && - in.ReadInt32(deviceId_) + in.ReadInt32(deviceId_)&& + in.ReadInt32(rawDeltaX_) && + in.ReadInt32(rawDeltaY_) ); } diff --git a/interfaces/native/innerkits/event/include/pointer_event.h b/interfaces/native/innerkits/event/include/pointer_event.h index 6c758d8585..4e04469239 100644 --- a/interfaces/native/innerkits/event/include/pointer_event.h +++ b/interfaces/native/innerkits/event/include/pointer_event.h @@ -689,6 +689,37 @@ public: */ bool ReadFromParcel(Parcel &in); + /** + * @brief 获取 x 坐标的偏移量。 + * 对于指针输入事件,该值为目标屏幕上的 x 坐标相对偏移量。 + * @return x 坐标相对偏移量。 + * @since 9 + */ + int32_t GetRawDeltaX() const; + + /** + * @brief 设置 x 坐标相对偏移量。 + * @param rawDeltaX 表示要设置的 x 坐标相对偏移量。 + * @return 无 + * @since 9 + */ + void SetRawDeltaX(int32_t rawDeltaX); + /** + * @brief 获取 y 坐标的偏移量。 + * 对于指针输入事件,该值为目标屏幕上的 y 坐标相对偏移量。 + * @return y 坐标相对偏移量。 + * @since 9 + */ + int32_t GetRawDeltaY() const; + + /** + * @brief 设置 y 坐标相对偏移量。 + * @param rawDeltaY 表示要设置的 y 坐标相对偏移量。 + * @return 无效 + * @since 9 + */ + void SetRawDeltaY(int32_t rawDeltaY); + private: int32_t pointerId_ {}; bool pressed_ { false }; @@ -713,6 +744,8 @@ public: int64_t downTime_ {}; int32_t toolType_ {}; int32_t targetWindowId_ { -1 }; + int32_t rawDeltaX_ {}; + int32_t rawDeltaY_ {}; }; public: diff --git a/interfaces/native/innerkits/proxy/include/input_manager.h b/interfaces/native/innerkits/proxy/include/input_manager.h index 5233fbb9ea..98753d27ce 100644 --- a/interfaces/native/innerkits/proxy/include/input_manager.h +++ b/interfaces/native/innerkits/proxy/include/input_manager.h @@ -363,7 +363,7 @@ public: * 否则返回小于 0 的值 */ int32_t StopRemoteInput(const std::string& deviceId, uint32_t inputAbility, std::function callback); - + /** * @brief 设定输入设备的席位名称. * @param seatName 席位名称 @@ -374,6 +374,22 @@ public: using DeviceUniqId = std::tuple; int32_t SetInputDeviceSeatName(const std::string& seatName, DeviceUniqId& deviceUniqId); + /** + * @brief 进入捕获模式 + * @param windowId 窗口id. + * @return 进入捕获模式成功或失败. + * @since 9 + */ + + int32_t EnterCaptureMode(int32_t windowId); + /** + * @brief 退出捕获模式 + * @param windowId 窗口id. + * @return 退出捕获模式成功或失败. + * @since 9 + */ + int32_t LeaveCaptureMode(int32_t windowId); + private: InputManager() = default; DISALLOW_COPY_AND_MOVE(InputManager); diff --git a/service/connect_manager/include/i_multimodal_input_connect.h b/service/connect_manager/include/i_multimodal_input_connect.h index 3896116c56..6dda86c52b 100644 --- a/service/connect_manager/include/i_multimodal_input_connect.h +++ b/service/connect_manager/include/i_multimodal_input_connect.h @@ -61,6 +61,7 @@ public: virtual int32_t StopRemoteCooperate() = 0; virtual int32_t StopRemoteCooperateResult(bool isSucess) = 0; virtual int32_t StartCooperateOtherResult(const std::string &srcNetworkId) = 0; + virtual int32_t SetMouseCaptureMode(int32_t windowId, bool isCaptureMode) = 0; enum { ALLOC_SOCKET_FD = 0, ADD_INPUT_EVENT_FILTER = 1, @@ -85,6 +86,7 @@ public: GET_POINTER_SPEED = 22, SET_POINTER_STYLE = 23, GET_POINTER_STYLE = 24, + SET_CAPTURE_MODE = 25, REMOTE_COOPERATE_START = 35, REMOTE_COOPERATE_START_RES = 36, REMOTE_COOPERATE_STOP = 37, diff --git a/service/connect_manager/include/multimodal_input_connect_manager.h b/service/connect_manager/include/multimodal_input_connect_manager.h index 5a91c608ac..b16b33d746 100644 --- a/service/connect_manager/include/multimodal_input_connect_manager.h +++ b/service/connect_manager/include/multimodal_input_connect_manager.h @@ -59,6 +59,7 @@ public: int32_t UnsubscribeKeyEvent(int32_t subscribeId); int32_t InjectPointerEvent(const std::shared_ptr pointerEvent); int32_t SetAnrObserver(); + int32_t SetMouseCaptureMode(int32_t windowId, bool isCaptureMode); private: MultimodalInputConnectManager() = default; DISALLOW_COPY_AND_MOVE(MultimodalInputConnectManager); diff --git a/service/connect_manager/include/multimodal_input_connect_proxy.h b/service/connect_manager/include/multimodal_input_connect_proxy.h index 5fe6b9468f..59eac79caa 100644 --- a/service/connect_manager/include/multimodal_input_connect_proxy.h +++ b/service/connect_manager/include/multimodal_input_connect_proxy.h @@ -60,6 +60,7 @@ public: virtual int32_t StopRemoteCooperate() override; virtual int32_t StopRemoteCooperateResult(bool isSucess) override; virtual int32_t StartCooperateOtherResult(const std::string &srcNetworkId) override; + virtual int32_t SetMouseCaptureMode(int32_t windowId, bool isCaptureMode) override; private: static inline BrokerDelegator delegator_; }; diff --git a/service/connect_manager/include/multimodal_input_connect_stub.h b/service/connect_manager/include/multimodal_input_connect_stub.h index a55c1aea61..bf091a8c99 100644 --- a/service/connect_manager/include/multimodal_input_connect_stub.h +++ b/service/connect_manager/include/multimodal_input_connect_stub.h @@ -65,6 +65,7 @@ protected: int32_t StubStopRemoteCooperate(MessageParcel& data, MessageParcel& reply); int32_t StubStopRemoteCooperateRes(MessageParcel& data, MessageParcel& reply); int32_t StubStartCooperateOtherRes(MessageParcel& data, MessageParcel& reply); + int32_t StubSetMouseCaptureMode(MessageParcel& data, MessageParcel& reply); }; } // namespace MMI } // namespace OHOS diff --git a/service/connect_manager/src/multimodal_input_connect_manager.cpp b/service/connect_manager/src/multimodal_input_connect_manager.cpp index bc60e19f16..897263ca1a 100644 --- a/service/connect_manager/src/multimodal_input_connect_manager.cpp +++ b/service/connect_manager/src/multimodal_input_connect_manager.cpp @@ -282,5 +282,11 @@ void MultimodalInputConnectManager::NotifyDeath() } } while (--retryCount > 0); } + +int32_t MultimodalInputConnectManager::SetMouseCaptureMode(int32_t windowId, bool isCaptureMode) +{ + CHKPR(multimodalInputConnectService_, INVALID_HANDLER_ID); + return multimodalInputConnectService_->SetMouseCaptureMode(windowId, isCaptureMode); +} } // namespace MMI } // namespace OHOS diff --git a/service/connect_manager/src/multimodal_input_connect_proxy.cpp b/service/connect_manager/src/multimodal_input_connect_proxy.cpp index 88e3761644..acfbd6bc2d 100644 --- a/service/connect_manager/src/multimodal_input_connect_proxy.cpp +++ b/service/connect_manager/src/multimodal_input_connect_proxy.cpp @@ -671,5 +671,26 @@ int32_t MultimodalInputConnectProxy::StartCooperateOtherResult(const std::string } return ret; } + +int32_t MultimodalInputConnectProxy::SetMouseCaptureMode(int32_t windowId, bool isCaptureMode) +{ + CALL_DEBUG_ENTER; + MessageParcel data; + if (!data.WriteInterfaceToken(MultimodalInputConnectProxy::GetDescriptor())) { + MMI_HILOGE("Failed to write descriptor"); + return ERR_INVALID_VALUE; + } + WRITEINT32(data, windowId, ERR_INVALID_VALUE); + WRITEBOOL(data, isCaptureMode, ERR_INVALID_VALUE); + MessageParcel reply; + MessageOption option; + sptr remote = Remote(); + CHKPR(remote, RET_ERR); + int32_t ret = remote->SendRequest(SET_CAPTURE_MODE, data, reply, option); + if (ret != RET_OK) { + MMI_HILOGE("Send request fail, ret:%{public}d", ret); + } + return ret; +} } // namespace MMI } // namespace OHOS diff --git a/service/connect_manager/src/multimodal_input_connect_stub.cpp b/service/connect_manager/src/multimodal_input_connect_stub.cpp index e78453305a..dc7c929789 100644 --- a/service/connect_manager/src/multimodal_input_connect_stub.cpp +++ b/service/connect_manager/src/multimodal_input_connect_stub.cpp @@ -76,7 +76,8 @@ int32_t MultimodalInputConnectStub::OnRemoteRequest( {IMultimodalInputConnect::REMOTE_COOPERATE_STOP, &MultimodalInputConnectStub::StubStopRemoteCooperate}, {IMultimodalInputConnect::REMOTE_COOPERATE_STOP_RES, &MultimodalInputConnectStub::StubStopRemoteCooperateRes}, {IMultimodalInputConnect::REMOTE_COOPERATE_STOP_OTHER_RES, - &MultimodalInputConnectStub::StubStartCooperateOtherRes} + &MultimodalInputConnectStub::StubStartCooperateOtherRes}, + {IMultimodalInputConnect::SET_CAPTURE_MODE, &MultimodalInputConnectStub::StubSetMouseCaptureMode}, }; auto it = mapConnFunc.find(code); if (it != mapConnFunc.end()) { @@ -641,5 +642,19 @@ int32_t MultimodalInputConnectStub::StubStartCooperateOtherRes(MessageParcel& da } return ret; } + +int32_t MultimodalInputConnectStub::StubSetMouseCaptureMode(MessageParcel& data, MessageParcel& reply) +{ + CALL_DEBUG_ENTER; + int32_t windowId = -1; + bool isCaptureMode = false; + READINT32(data, windowId, IPC_PROXY_DEAD_OBJECT_ERR); + READBOOL(data, isCaptureMode, IPC_PROXY_DEAD_OBJECT_ERR); + int32_t ret = SetMouseCaptureMode(windowId, isCaptureMode); + if (ret != RET_OK) { + MMI_HILOGE("Fail to call SetMouseCaptureMode, ret:%{public}d", ret); + } + return ret; +} } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/service/module_loader/include/mmi_service.h b/service/module_loader/include/mmi_service.h index ad2831e8bb..5744b95787 100644 --- a/service/module_loader/include/mmi_service.h +++ b/service/module_loader/include/mmi_service.h @@ -78,6 +78,7 @@ public: virtual int32_t StopRemoteCooperate() override; virtual int32_t StopRemoteCooperateResult(bool isSucess) override; virtual int32_t StartCooperateOtherResult(const std::string& srcNetworkId) override; + virtual int32_t SetMouseCaptureMode(int32_t windowId, bool isCaptureMode) override; #ifdef OHOS_RSS_CLIENT virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; diff --git a/service/module_loader/src/mmi_service.cpp b/service/module_loader/src/mmi_service.cpp index 0d42a6411d..e33ad7cab3 100644 --- a/service/module_loader/src/mmi_service.cpp +++ b/service/module_loader/src/mmi_service.cpp @@ -1081,5 +1081,16 @@ int32_t MMIService::StartCooperateOtherResult(const std::string& srcNetworkId) #endif // OHOS_BUILD_ENABLE_COOPERATE return RET_OK; } + +int32_t MMIService::SetMouseCaptureMode(int32_t windowId, bool isCaptureMode) +{ + CALL_DEBUG_ENTER; + int32_t ret = delegateTasks_.PostSyncTask(std::bind(&InputWindowsManager::SetMouseCaptureMode, + InputWindowsManager::GetInstance(), windowId, isCaptureMode)); + if (ret != RET_OK) { + MMI_HILOGE("Set capture failed,return %{public}d", ret); + } + return ret;; +} } // namespace MMI } // namespace OHOS diff --git a/service/mouse_event_handler/src/mouse_event_handler.cpp b/service/mouse_event_handler/src/mouse_event_handler.cpp index d0ad9473e0..a65d3cb7ec 100644 --- a/service/mouse_event_handler/src/mouse_event_handler.cpp +++ b/service/mouse_event_handler/src/mouse_event_handler.cpp @@ -126,8 +126,10 @@ int32_t MouseEventHandler::HandleMotionAccelerate(struct libinput_event_pointer* MMI_HILOGD("Get and process the movement coordinates, dx:%{public}lf, dy:%{public}lf," "correctionX:%{public}lf, correctionY:%{public}lf, gain:%{public}lf", dx, dy, correctionX, correctionY, gain); - absolutionX_ += correctionX; - absolutionY_ += correctionY; + if (!WinMgr->GetMouseIsCaptureMode()) { + absolutionX_ += correctionX; + absolutionY_ += correctionY; + } return RET_OK; } @@ -246,6 +248,10 @@ void MouseEventHandler::HandlePostInner(struct libinput_event_pointer* data, int CHKPV(data); auto mouseInfo = WinMgr->GetMouseInfo(); MouseState->SetMouseCoords(mouseInfo.physicalX, mouseInfo.physicalY); + if (WinMgr->GetMouseIsCaptureMode()) { + pointerItem.SetRawDeltaX(static_cast(libinput_event_pointer_get_dx(data))); + pointerItem.SetRawDeltaY(static_cast(libinput_event_pointer_get_dy(data))); + } pointerItem.SetDisplayX(mouseInfo.physicalX); pointerItem.SetDisplayY(mouseInfo.physicalY); pointerItem.SetWindowX(0); diff --git a/service/window_manager/include/input_windows_manager.h b/service/window_manager/include/input_windows_manager.h index 6be3a1a239..b4ad509ba7 100644 --- a/service/window_manager/include/input_windows_manager.h +++ b/service/window_manager/include/input_windows_manager.h @@ -80,7 +80,8 @@ public: void DispatchPointer(int32_t pointerAction); void SendPointerEvent(int32_t pointerAction); #endif // OHOS_BUILD_ENABLE_POINTER - + int32_t SetMouseCaptureMode(int32_t windowId, bool isCaptureMode); + bool GetMouseIsCaptureMode() const; private: #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) bool IsInHotArea(int32_t x, int32_t y, const std::vector &rects) const; @@ -131,6 +132,10 @@ private: #endif // OHOS_BUILD_ENABLE_POINTER DisplayGroupInfo displayGroupInfo_; MouseLocation mouseLocation_ = {-1, -1}; // physical coord + struct CaptureModeInfo { + int32_t windowId { -1 }; + bool isCaptureMode { false }; + } captureModeInfo_; }; } // namespace MMI } // namespace OHOS diff --git a/service/window_manager/src/input_windows_manager.cpp b/service/window_manager/src/input_windows_manager.cpp index 7cb19498ec..d080683373 100644 --- a/service/window_manager/src/input_windows_manager.cpp +++ b/service/window_manager/src/input_windows_manager.cpp @@ -171,6 +171,11 @@ void InputWindowsManager::UpdateDisplayInfo(const DisplayGroupInfo &displayGroup CALL_DEBUG_ENTER; CheckFocusWindowChange(displayGroupInfo); CheckZorderWindowChange(displayGroupInfo); + if (captureModeInfo_.isCaptureMode && + ((displayGroupInfo_.focusWindowId != displayGroupInfo.focusWindowId) || + (displayGroupInfo_.windowsInfo[0].id != displayGroupInfo.windowsInfo[0].id))) { + captureModeInfo_.isCaptureMode = false; + } displayGroupInfo_ = displayGroupInfo; if (!displayGroupInfo.displaysInfo.empty()) { #ifdef OHOS_BUILD_ENABLE_POINTER @@ -615,6 +620,9 @@ int32_t InputWindowsManager::UpdateMouseTarget(std::shared_ptr poi MMI_HILOGE("touchWindow is nullptr, targetWindow:%{public}d", pointerEvent->GetTargetWindowId()); return RET_ERR; } + if (captureModeInfo_.isCaptureMode && (touchWindow->id != captureModeInfo_.windowId)) { + captureModeInfo_.isCaptureMode = false; + } pointerEvent->SetTargetWindowId(touchWindow->id); pointerEvent->SetAgentWindowId(touchWindow->agentWindowId); int32_t windowX = logicalX - touchWindow->area.x; @@ -639,6 +647,23 @@ int32_t InputWindowsManager::UpdateMouseTarget(std::shared_ptr poi } #endif // OHOS_BUILD_ENABLE_POINTER +int32_t InputWindowsManager::SetMouseCaptureMode(int32_t windowId, bool isCaptureMode) +{ + if (windowId < 0) { + MMI_HILOGE("Windowid(%{public}d) is invalid", windowId); + return RET_ERR; + } + captureModeInfo_.windowId = windowId; + captureModeInfo_.isCaptureMode = isCaptureMode; + MMI_HILOGI("Windowid:(%{public}d) is (%{public}d)", windowId, isCaptureMode); + return RET_OK; +} + +bool InputWindowsManager::GetMouseIsCaptureMode() const +{ + return captureModeInfo_.isCaptureMode; +} + #ifdef OHOS_BUILD_ENABLE_TOUCH int32_t InputWindowsManager::UpdateTouchScreenTarget(std::shared_ptr pointerEvent) { diff --git a/test/unittest/common/src/event_util_test.cpp b/test/unittest/common/src/event_util_test.cpp index cd5711100f..8bca323014 100644 --- a/test/unittest/common/src/event_util_test.cpp +++ b/test/unittest/common/src/event_util_test.cpp @@ -167,7 +167,8 @@ std::string EventUtilTest::DumpInputEvent(const std::shared_ptr& p << ",ToolWindowX:" << item.GetToolWindowX() << ",ToolWindowY:" << item.GetToolWindowY() << ",ToolWidth:" << item.GetToolWidth() << ",ToolHeight:" << item.GetToolHeight() << ",Pressure:" << item.GetPressure() << ",ToolType:" << item.GetToolType() - << ",LongAxis:" << item.GetLongAxis() << ",ShortAxis:" << item.GetShortAxis(); + << ",LongAxis:" << item.GetLongAxis() << ",ShortAxis:" << item.GetShortAxis() + << ",RawDeltaX:" << item.GetRawDeltaX() << ",RawDeltaY:" << item.GetRawDeltaY(); } return ostream.str(); } -- Gitee From 8ca2f7d3251c81d35a2919f73a8f82ee86ac2c58 Mon Sep 17 00:00:00 2001 From: wangdi119 Date: Tue, 23 Aug 2022 15:30:54 +0800 Subject: [PATCH 007/360] =?UTF-8?q?=E2=80=9C=E9=BC=A0=E6=A0=87=E6=8D=95?= =?UTF-8?q?=E8=8E=B7=E6=A8=A1=E5=BC=8FJS=E6=8E=A5=E5=8F=A3=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangdi119 --- .../napi/pointer/include/js_pointer_context.h | 2 + .../napi/pointer/include/js_pointer_manager.h | 2 + .../napi/pointer/src/js_pointer_context.cpp | 61 +++++++++++++++++++ .../napi/pointer/src/js_pointer_manager.cpp | 45 ++++++++++++++ 4 files changed, 110 insertions(+) diff --git a/frameworks/napi/pointer/include/js_pointer_context.h b/frameworks/napi/pointer/include/js_pointer_context.h index b9c8f1f4d5..48510e3769 100644 --- a/frameworks/napi/pointer/include/js_pointer_context.h +++ b/frameworks/napi/pointer/include/js_pointer_context.h @@ -33,6 +33,8 @@ public: static napi_value SetPointerSpeed(napi_env env, napi_callback_info info); static napi_value GetPointerSpeed(napi_env env, napi_callback_info info); static napi_value SetPointerLocation(napi_env env, napi_callback_info info); + static napi_value EnterCaptureMode(napi_env env, napi_callback_info info); + static napi_value LeaveCaptureMode(napi_env env, napi_callback_info info); private: static napi_value CreateInstance(napi_env env); diff --git a/frameworks/napi/pointer/include/js_pointer_manager.h b/frameworks/napi/pointer/include/js_pointer_manager.h index 9e45e43008..77c9bb7dc4 100644 --- a/frameworks/napi/pointer/include/js_pointer_manager.h +++ b/frameworks/napi/pointer/include/js_pointer_manager.h @@ -90,6 +90,8 @@ public: napi_value SetPointerStyle(napi_env env, int32_t windowid, int32_t pointerStyle, napi_value handle = nullptr); napi_value GetPointerStyle(napi_env env, int32_t windowid, napi_value handle = nullptr); napi_value SetPointerLocation(napi_env env, napi_value handle, int32_t x, int32_t y); + napi_value EnterCaptureMode(napi_env env, int32_t windowId, napi_value handle = nullptr); + napi_value LeaveCaptureMode(napi_env env, int32_t windowId, napi_value handle = nullptr); }; } // namespace MMI } // namespace OHOS diff --git a/frameworks/napi/pointer/src/js_pointer_context.cpp b/frameworks/napi/pointer/src/js_pointer_context.cpp index 8cfc0d2778..7bb5b6018c 100644 --- a/frameworks/napi/pointer/src/js_pointer_context.cpp +++ b/frameworks/napi/pointer/src/js_pointer_context.cpp @@ -430,6 +430,67 @@ napi_value JsPointerContext::EnumConstructor(napi_env env, napi_callback_info in return ret; } +napi_value JsPointerContext::EnterCaptureMode(napi_env env, napi_callback_info info) +{ + CALL_DEBUG_ENTER; + size_t argc = 2; + napi_value argv[2]; + CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + if (argc < 1 || argc > 2) { + THROWERR(env, "the number of parameters is not as expected"); + return nullptr; + } + if (!JsCommon::TypeOf(env, argv[0], napi_number)) { + THROWERR(env, "The first parameter type is wrong"); + return nullptr; + } + + int32_t windowId = 0; + CHKRP(env, napi_get_value_int32(env, argv[0], &windowId), GET_BOOL); + JsPointerContext *jsPointer = JsPointerContext::GetInstance(env); + auto jsPointerMgr = jsPointer->GetJsPointerMgr(); + if(argc == 1) + { + return jsPointerMgr->EnterCaptureMode(env,windowId); + } + if (!JsCommon::TypeOf(env, argv[1], napi_function)) { + THROWERR(env, "The second parameter type is wrong"); + return nullptr; + } + return jsPointerMgr->EnterCaptureMode(env, windowId, argv[1]); +} + +napi_value JsPointerContext::LeaveCaptureMode(napi_env env, napi_callback_info info) +{ + CALL_DEBUG_ENTER; + size_t argc = 2; + napi_value argv[2]; + CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + if (argc < 1 || argc > 2) { + THROWERR(env, "the number of parameters is not as expected"); + return nullptr; + } + if (!JsCommon::TypeOf(env, argv[0], napi_number)) { + THROWERR(env, "The first parameter type is wrong"); + return nullptr; + } + + int32_t windowId = 0; + CHKRP(env, napi_get_value_int32(env, argv[0], &windowId), GET_BOOL); + + JsPointerContext *jsPointer = JsPointerContext::GetInstance(env); + auto jsPointerMgr = jsPointer->GetJsPointerMgr(); + if(argc == 1) + { + return jsPointerMgr->LeaveCaptureMode(env,windowId); + } + if (!JsCommon::TypeOf(env, argv[1], napi_function)) { + THROWERR(env, "The second parameter type is wrong"); + return nullptr; + } + return jsPointerMgr ->LeaveCaptureMode(env, windowId, argv[1]); +} + napi_value JsPointerContext::Export(napi_env env, napi_value exports) { CALL_DEBUG_ENTER; diff --git a/frameworks/napi/pointer/src/js_pointer_manager.cpp b/frameworks/napi/pointer/src/js_pointer_manager.cpp index 23702cfb3d..3602d47765 100644 --- a/frameworks/napi/pointer/src/js_pointer_manager.cpp +++ b/frameworks/napi/pointer/src/js_pointer_manager.cpp @@ -276,5 +276,50 @@ napi_value JsPointerManager::GetPointerStyle(napi_env env, int32_t windowid, nap AsyncCallbackWork(asyncContext); return promise; } + +napi_value JsPointerManager::EnterCaptureMode(napi_env env, int32_t windowId, napi_value handle) +{ + CALL_DEBUG_ENTER; + sptr asyncContext = new (std::nothrow) AsyncContext(env); + if(asyncContext == nullptr) { + THROWERR(env,"create AsyncContext failed"); + return nullptr; + } + asyncContext->errorCode = InputManager::GetInstance()->EnterCaptureMode(windowId); + asyncContext->reserve << ReturnType::VOID; + + napi_value promise = nullptr; + if(handle != nullptr) { + CHKRP(env, napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE); + CHKRP(env, napi_get_undefined(env, &promise), GET_UNDEFINED); + } else { + CHKRP(env, napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); + } + AsyncCallbackWork(asyncContext); + return promise; +} + +napi_value JsPointerManager::LeaveCaptureMode(napi_env env, int32_t windowId, napi_value handle) +{ + CALL_DEBUG_ENTER; + sptr asyncContext = new (std::nothrow) AsyncContext(env); + if(asyncContext == nullptr) { + THROWERR(env,"create AsyncContext failed"); + return nullptr; + } + + asyncContext->errorCode = InputManager::GetInstance()->LeaveCaptureMode(windowId); + asyncContext->reserve << ReturnType::VOID; + + napi_value promise = nullptr; + if(handle != nullptr) { + CHKRP(env, napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE); + CHKRP(env, napi_get_undefined(env, &promise), GET_UNDEFINED); + } else { + CHKRP(env, napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); + } + AsyncCallbackWork(asyncContext); + return promise; +} } // namespace MMI } // namespace OHOS \ No newline at end of file -- Gitee From c6bce3fa2a415b6d5c5ac0287440a684b14a2c47 Mon Sep 17 00:00:00 2001 From: wangdi119 Date: Thu, 25 Aug 2022 09:34:52 +0800 Subject: [PATCH 008/360] =?UTF-8?q?"=E9=BC=A0=E6=A0=87=E6=8D=95=E8=8E=B7js?= =?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: wangdi119 --- frameworks/napi/pointer/src/js_pointer_context.cpp | 10 ++++++---- frameworks/napi/pointer/src/js_pointer_manager.cpp | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/frameworks/napi/pointer/src/js_pointer_context.cpp b/frameworks/napi/pointer/src/js_pointer_context.cpp index 7bb5b6018c..79fc5c59f1 100644 --- a/frameworks/napi/pointer/src/js_pointer_context.cpp +++ b/frameworks/napi/pointer/src/js_pointer_context.cpp @@ -433,11 +433,11 @@ napi_value JsPointerContext::EnumConstructor(napi_env env, napi_callback_info in napi_value JsPointerContext::EnterCaptureMode(napi_env env, napi_callback_info info) { CALL_DEBUG_ENTER; - size_t argc = 2; - napi_value argv[2]; + size_t argc = 1; + napi_value argv[1]; CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc < 1 || argc > 2) { - THROWERR(env, "the number of parameters is not as expected"); + THROWERR(env, "The number of parameters is not as expected"); return nullptr; } if (!JsCommon::TypeOf(env, argv[0], napi_number)) { @@ -488,7 +488,7 @@ napi_value JsPointerContext::LeaveCaptureMode(napi_env env, napi_callback_info i THROWERR(env, "The second parameter type is wrong"); return nullptr; } - return jsPointerMgr ->LeaveCaptureMode(env, windowId, argv[1]); + return jsPointerMgr->LeaveCaptureMode(env, windowId, argv[1]); } napi_value JsPointerContext::Export(napi_env env, napi_value exports) @@ -506,6 +506,8 @@ napi_value JsPointerContext::Export(napi_env env, napi_value exports) DECLARE_NAPI_STATIC_FUNCTION("getPointerSpeed", GetPointerSpeed), DECLARE_NAPI_STATIC_FUNCTION("setPointerStyle", SetPointerStyle), DECLARE_NAPI_STATIC_FUNCTION("getPointerStyle", GetPointerStyle), + DECLARE_NAPI_STATIC_FUNCTION("enterCaptureMode", EnterCaptureMode), + DECLARE_NAPI_STATIC_FUNCTION("leaveCaptureMode", LeaveCaptureMode), }; CHKRP(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc), DEFINE_PROPERTIES); if (CreatePointerStyle(env, exports) == nullptr) { diff --git a/frameworks/napi/pointer/src/js_pointer_manager.cpp b/frameworks/napi/pointer/src/js_pointer_manager.cpp index 3602d47765..cd25e0982a 100644 --- a/frameworks/napi/pointer/src/js_pointer_manager.cpp +++ b/frameworks/napi/pointer/src/js_pointer_manager.cpp @@ -282,7 +282,7 @@ napi_value JsPointerManager::EnterCaptureMode(napi_env env, int32_t windowId, na CALL_DEBUG_ENTER; sptr asyncContext = new (std::nothrow) AsyncContext(env); if(asyncContext == nullptr) { - THROWERR(env,"create AsyncContext failed"); + THROWERR(env, "create AsyncContext failed"); return nullptr; } asyncContext->errorCode = InputManager::GetInstance()->EnterCaptureMode(windowId); @@ -304,7 +304,7 @@ napi_value JsPointerManager::LeaveCaptureMode(napi_env env, int32_t windowId, na CALL_DEBUG_ENTER; sptr asyncContext = new (std::nothrow) AsyncContext(env); if(asyncContext == nullptr) { - THROWERR(env,"create AsyncContext failed"); + THROWERR(env, "Create AsyncContext failed"); return nullptr; } -- Gitee From 9b41ab10a370254795c8ac43cdecdda28551e9aa Mon Sep 17 00:00:00 2001 From: wangdi119 Date: Thu, 25 Aug 2022 09:35:54 +0800 Subject: [PATCH 009/360] =?UTF-8?q?=E2=80=9C=E9=BC=A0=E6=A0=87=E6=8D=95?= =?UTF-8?q?=E8=8E=B7js=E6=8E=A5=E5=8F=A3=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangdi119 --- frameworks/napi/pointer/src/js_pointer_context.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/napi/pointer/src/js_pointer_context.cpp b/frameworks/napi/pointer/src/js_pointer_context.cpp index 79fc5c59f1..1536d1ec02 100644 --- a/frameworks/napi/pointer/src/js_pointer_context.cpp +++ b/frameworks/napi/pointer/src/js_pointer_context.cpp @@ -433,8 +433,8 @@ napi_value JsPointerContext::EnumConstructor(napi_env env, napi_callback_info in napi_value JsPointerContext::EnterCaptureMode(napi_env env, napi_callback_info info) { CALL_DEBUG_ENTER; - size_t argc = 1; - napi_value argv[1]; + size_t argc = 2; + napi_value argv[2]; CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc < 1 || argc > 2) { THROWERR(env, "The number of parameters is not as expected"); -- Gitee From c3eec7cbac070935a42f2d151d46f9932abbe430 Mon Sep 17 00:00:00 2001 From: wangdi119 Date: Thu, 25 Aug 2022 09:42:57 +0800 Subject: [PATCH 010/360] =?UTF-8?q?=E2=80=9C=E9=BC=A0=E6=A0=87=E6=8D=95?= =?UTF-8?q?=E8=8E=B7js=E6=8E=A5=E5=8F=A3=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangdi119 --- frameworks/napi/pointer/src/js_pointer_context.cpp | 2 +- frameworks/napi/pointer/src/js_pointer_manager.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/napi/pointer/src/js_pointer_context.cpp b/frameworks/napi/pointer/src/js_pointer_context.cpp index 1536d1ec02..110ae8aaf8 100644 --- a/frameworks/napi/pointer/src/js_pointer_context.cpp +++ b/frameworks/napi/pointer/src/js_pointer_context.cpp @@ -467,7 +467,7 @@ napi_value JsPointerContext::LeaveCaptureMode(napi_env env, napi_callback_info i napi_value argv[2]; CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc < 1 || argc > 2) { - THROWERR(env, "the number of parameters is not as expected"); + THROWERR(env, "The number of parameters is not as expected"); return nullptr; } if (!JsCommon::TypeOf(env, argv[0], napi_number)) { diff --git a/frameworks/napi/pointer/src/js_pointer_manager.cpp b/frameworks/napi/pointer/src/js_pointer_manager.cpp index cd25e0982a..1e46e1b4aa 100644 --- a/frameworks/napi/pointer/src/js_pointer_manager.cpp +++ b/frameworks/napi/pointer/src/js_pointer_manager.cpp @@ -282,7 +282,7 @@ napi_value JsPointerManager::EnterCaptureMode(napi_env env, int32_t windowId, na CALL_DEBUG_ENTER; sptr asyncContext = new (std::nothrow) AsyncContext(env); if(asyncContext == nullptr) { - THROWERR(env, "create AsyncContext failed"); + THROWERR(env, "Create AsyncContext failed"); return nullptr; } asyncContext->errorCode = InputManager::GetInstance()->EnterCaptureMode(windowId); -- Gitee From 49478f1b4ba7355efb6fa138aeb165d97de0d7a7 Mon Sep 17 00:00:00 2001 From: wangdi119 Date: Fri, 26 Aug 2022 14:11:32 +0800 Subject: [PATCH 011/360] =?UTF-8?q?=E2=80=9C=E6=8C=87=E9=92=88=E6=8D=95?= =?UTF-8?q?=E8=8E=B7=E6=A8=A1=E5=BC=8Fjs=E6=8E=A5=E5=8F=A3=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangdi119 --- frameworks/napi/pointer/src/js_pointer_context.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/frameworks/napi/pointer/src/js_pointer_context.cpp b/frameworks/napi/pointer/src/js_pointer_context.cpp index 110ae8aaf8..c5f966d1a5 100644 --- a/frameworks/napi/pointer/src/js_pointer_context.cpp +++ b/frameworks/napi/pointer/src/js_pointer_context.cpp @@ -449,9 +449,8 @@ napi_value JsPointerContext::EnterCaptureMode(napi_env env, napi_callback_info i CHKRP(env, napi_get_value_int32(env, argv[0], &windowId), GET_BOOL); JsPointerContext *jsPointer = JsPointerContext::GetInstance(env); auto jsPointerMgr = jsPointer->GetJsPointerMgr(); - if(argc == 1) - { - return jsPointerMgr->EnterCaptureMode(env,windowId); + if(argc == 1) { + return jsPointerMgr->EnterCaptureMode(env, windowId); } if (!JsCommon::TypeOf(env, argv[1], napi_function)) { THROWERR(env, "The second parameter type is wrong"); @@ -480,9 +479,8 @@ napi_value JsPointerContext::LeaveCaptureMode(napi_env env, napi_callback_info i JsPointerContext *jsPointer = JsPointerContext::GetInstance(env); auto jsPointerMgr = jsPointer->GetJsPointerMgr(); - if(argc == 1) - { - return jsPointerMgr->LeaveCaptureMode(env,windowId); + if(argc == 1) { + return jsPointerMgr->LeaveCaptureMode(env, windowId); } if (!JsCommon::TypeOf(env, argv[1], napi_function)) { THROWERR(env, "The second parameter type is wrong"); -- Gitee From 4cd2a42b2964924e7fc8127f30c7ec69f5242090 Mon Sep 17 00:00:00 2001 From: yangli198 Date: Mon, 29 Aug 2022 17:09:10 +0800 Subject: [PATCH 012/360] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8D=95=E8=8E=B7?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangli198 --- interfaces/native/innerkits/event/include/pointer_event.h | 2 +- test/unittest/common/src/event_util_test.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/interfaces/native/innerkits/event/include/pointer_event.h b/interfaces/native/innerkits/event/include/pointer_event.h index ea599d5563..22a14b9580 100644 --- a/interfaces/native/innerkits/event/include/pointer_event.h +++ b/interfaces/native/innerkits/event/include/pointer_event.h @@ -722,6 +722,7 @@ public: */ void SetRawDy(int32_t rawDy); #endif // OHOS_BUILD_ENABLE_COOPERATE + /** * @brief 获取 x 坐标的偏移量。 * 对于指针输入事件,该值为目标屏幕上的 x 坐标相对偏移量。 @@ -752,7 +753,6 @@ public: * @since 9 */ void SetRawDeltaY(int32_t rawDeltaY); - private: int32_t pointerId_ {}; bool pressed_ { false }; diff --git a/test/unittest/common/src/event_util_test.cpp b/test/unittest/common/src/event_util_test.cpp index ef72186c42..de5961ec6d 100644 --- a/test/unittest/common/src/event_util_test.cpp +++ b/test/unittest/common/src/event_util_test.cpp @@ -166,8 +166,7 @@ std::string EventUtilTest::DumpInputEvent(const std::shared_ptr& p << ",ToolWindowX:" << item.GetToolWindowX() << ",ToolWindowY:" << item.GetToolWindowY() << ",ToolWidth:" << item.GetToolWidth() << ",ToolHeight:" << item.GetToolHeight() << ",Pressure:" << item.GetPressure() << ",ToolType:" << item.GetToolType() - << ",LongAxis:" << item.GetLongAxis() << ",ShortAxis:" << item.GetShortAxis() - << ",RawDeltaX:" << item.GetRawDeltaX() << ",RawDeltaY:" << item.GetRawDeltaY(); + << ",LongAxis:" << item.GetLongAxis() << ",ShortAxis:" << item.GetShortAxis(); } return ostream.str(); } -- Gitee From bf7d9ec4a758a5e77d47104543cf2f63a7ac5876 Mon Sep 17 00:00:00 2001 From: yangli198 Date: Mon, 29 Aug 2022 17:16:49 +0800 Subject: [PATCH 013/360] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8C=87=E9=92=88?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangli198 --- service/mouse_event_handler/include/mouse_event_handler.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/service/mouse_event_handler/include/mouse_event_handler.h b/service/mouse_event_handler/include/mouse_event_handler.h index 878cade9e9..0874412a9d 100644 --- a/service/mouse_event_handler/include/mouse_event_handler.h +++ b/service/mouse_event_handler/include/mouse_event_handler.h @@ -70,7 +70,8 @@ private: #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING int32_t HandleButtonValueInner(struct libinput_event_pointer* data); int32_t HandleMotionAccelerate(struct libinput_event_pointer* data, int32_t deviceId); - bool GetSpeedGain(double vin, double& gain, int32_t deviceId) const; void DumpInner(); + bool GetSpeedGain(double vin, double& gain, int32_t deviceId) const; + void DumpInner(); void InitAbsolution(); #ifdef OHOS_BUILD_ENABLE_COOPERATE void SetDxDyForDInput(PointerEvent::PointerItem& pointerItem, libinput_event_pointer* data); -- Gitee From 101f40b9c007fb6020bf8a78d3330dc5ebada009 Mon Sep 17 00:00:00 2001 From: yangli198 Date: Tue, 6 Sep 2022 15:16:05 +0800 Subject: [PATCH 014/360] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangli198 --- frameworks/proxy/events/src/pointer_event.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/proxy/events/src/pointer_event.cpp b/frameworks/proxy/events/src/pointer_event.cpp index d92dae3248..3f746e691b 100644 --- a/frameworks/proxy/events/src/pointer_event.cpp +++ b/frameworks/proxy/events/src/pointer_event.cpp @@ -334,7 +334,7 @@ bool PointerEvent::PointerItem::WriteToParcel(Parcel &out) const out.WriteInt32(toolType_) && out.WriteInt32(deviceId_) && out.WriteInt32(rawDx_) && - out.WriteInt32(rawDy_)&& + out.WriteInt32(rawDy_) && out.WriteInt32(rawDeltaX_) && out.WriteInt32(rawDeltaY_) ); @@ -366,7 +366,7 @@ bool PointerEvent::PointerItem::ReadFromParcel(Parcel &in) in.ReadInt32(toolType_) && in.ReadInt32(deviceId_) && in.ReadInt32(rawDx_) && - in.ReadInt32(rawDy_)&& + in.ReadInt32(rawDy_) && in.ReadInt32(rawDeltaX_) && in.ReadInt32(rawDeltaY_) ); -- Gitee From a64dc11694c792d58d7b633283e5f630bb6237e7 Mon Sep 17 00:00:00 2001 From: yangli198 Date: Thu, 8 Sep 2022 17:06:28 +0800 Subject: [PATCH 015/360] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangli198 --- .../proxy/events/include/event_log_helper.h | 5 +-- frameworks/proxy/events/src/pointer_event.cpp | 28 ++-------------- .../innerkits/event/include/pointer_event.h | 33 ------------------- .../src/mouse_event_handler.cpp | 4 +-- 4 files changed, 7 insertions(+), 63 deletions(-) diff --git a/frameworks/proxy/events/include/event_log_helper.h b/frameworks/proxy/events/include/event_log_helper.h index a987a4d6c3..f2ea7480bf 100644 --- a/frameworks/proxy/events/include/event_log_helper.h +++ b/frameworks/proxy/events/include/event_log_helper.h @@ -88,12 +88,13 @@ private: "DisplayY:%{public}d,WindowX:%{public}d,WindowY:%{public}d,Width:%{public}d,Height:%{public}d," "TiltX:%{public}.2f,TiltY:%{public}.2f,ToolDisplayX:%{public}d,ToolDisplayY:%{public}d," "ToolWindowX:%{public}d,ToolWindowY:%{public}d,ToolWidth:%{public}d,ToolHeight:%{public}d," - "Pressure:%{public}.2f,ToolType:%{public}d,LongAxis:%{public}d,ShortAxis:%{public}d", + "Pressure:%{public}.2f,ToolType:%{public}d,LongAxis:%{public}d,ShortAxis:%{public}d,RawDx:%{public}d," + "RawDy:%{public}d", pointerId, item.GetDownTime(), item.IsPressed(), item.GetDisplayX(), item.GetDisplayY(), item.GetWindowX(), item.GetWindowY(), item.GetWidth(), item.GetHeight(), item.GetTiltX(), item.GetTiltY(), item.GetToolDisplayX(), item.GetToolDisplayY(), item.GetToolWindowX(), item.GetToolWindowY(), item.GetToolWidth(), item.GetToolHeight(), item.GetPressure(), item.GetToolType(), - item.GetLongAxis(), item.GetShortAxis()); + item.GetLongAxis(), item.GetShortAxis(), item.GetRawDx(), item.GetRawDy()); } std::vector pressedKeys = event->GetPressedKeys(); std::vector::const_iterator cItr = pressedKeys.cbegin(); diff --git a/frameworks/proxy/events/src/pointer_event.cpp b/frameworks/proxy/events/src/pointer_event.cpp index 387a89d0e6..d3f44a5ace 100644 --- a/frameworks/proxy/events/src/pointer_event.cpp +++ b/frameworks/proxy/events/src/pointer_event.cpp @@ -288,26 +288,6 @@ void PointerEvent::PointerItem::SetRawDy(int32_t rawDy) rawDy_ = rawDy; } -int32_t PointerEvent::PointerItem::GetRawDeltaX() const -{ - return rawDeltaX_; -} - -void PointerEvent::PointerItem::SetRawDeltaX(int32_t rawDeltaX) -{ - rawDeltaX_ = rawDeltaX; -} - -int32_t PointerEvent::PointerItem::GetRawDeltaY() const -{ - return rawDeltaY_; -} - -void PointerEvent::PointerItem::SetRawDeltaY(int32_t rawDeltaY) -{ - rawDeltaY_ = rawDeltaY; -} - bool PointerEvent::PointerItem::WriteToParcel(Parcel &out) const { return ( @@ -334,9 +314,7 @@ bool PointerEvent::PointerItem::WriteToParcel(Parcel &out) const out.WriteInt32(toolType_) && out.WriteInt32(deviceId_) && out.WriteInt32(rawDx_) && - out.WriteInt32(rawDy_) && - out.WriteInt32(rawDeltaX_) && - out.WriteInt32(rawDeltaY_) + out.WriteInt32(rawDy_) ); } @@ -366,9 +344,7 @@ bool PointerEvent::PointerItem::ReadFromParcel(Parcel &in) in.ReadInt32(toolType_) && in.ReadInt32(deviceId_) && in.ReadInt32(rawDx_) && - in.ReadInt32(rawDy_) && - in.ReadInt32(rawDeltaX_) && - in.ReadInt32(rawDeltaY_) + in.ReadInt32(rawDy_) ); } diff --git a/interfaces/native/innerkits/event/include/pointer_event.h b/interfaces/native/innerkits/event/include/pointer_event.h index c2c168128b..107ed9a2fa 100644 --- a/interfaces/native/innerkits/event/include/pointer_event.h +++ b/interfaces/native/innerkits/event/include/pointer_event.h @@ -717,37 +717,6 @@ public: * @since 9 */ void SetRawDy(int32_t rawDy); - - /** - * @brief 获取 x 坐标的偏移量。 - * 对于指针输入事件,该值为目标屏幕上的 x 坐标相对偏移量。 - * @return x 坐标相对偏移量。 - * @since 9 - */ - int32_t GetRawDeltaX() const; - - /** - * @brief 设置 x 坐标相对偏移量。 - * @param rawDeltaX 表示要设置的 x 坐标相对偏移量。 - * @return 无 - * @since 9 - */ - void SetRawDeltaX(int32_t rawDeltaX); - /** - * @brief 获取 y 坐标的偏移量。 - * 对于指针输入事件,该值为目标屏幕上的 y 坐标相对偏移量。 - * @return y 坐标相对偏移量。 - * @since 9 - */ - int32_t GetRawDeltaY() const; - - /** - * @brief 设置 y 坐标相对偏移量。 - * @param rawDeltaY 表示要设置的 y 坐标相对偏移量。 - * @return 无效 - * @since 9 - */ - void SetRawDeltaY(int32_t rawDeltaY); private: int32_t pointerId_ {}; bool pressed_ { false }; @@ -774,8 +743,6 @@ public: int32_t targetWindowId_ { -1 }; int32_t rawDx_ {}; int32_t rawDy_ {}; - int32_t rawDeltaX_ {}; - int32_t rawDeltaY_ {}; }; public: diff --git a/service/mouse_event_handler/src/mouse_event_handler.cpp b/service/mouse_event_handler/src/mouse_event_handler.cpp index a70ff7d438..e930eda33c 100644 --- a/service/mouse_event_handler/src/mouse_event_handler.cpp +++ b/service/mouse_event_handler/src/mouse_event_handler.cpp @@ -256,8 +256,8 @@ void MouseEventHandler::HandlePostInner(struct libinput_event_pointer* data, int auto mouseInfo = WinMgr->GetMouseInfo(); MouseState->SetMouseCoords(mouseInfo.physicalX, mouseInfo.physicalY); if (WinMgr->GetMouseIsCaptureMode()) { - pointerItem.SetRawDeltaX(static_cast(libinput_event_pointer_get_dx(data))); - pointerItem.SetRawDeltaY(static_cast(libinput_event_pointer_get_dy(data))); + pointerItem.SetRawDx(static_cast(libinput_event_pointer_get_dx(data))); + pointerItem.SetRawDy(static_cast(libinput_event_pointer_get_dy(data))); } pointerItem.SetDisplayX(mouseInfo.physicalX); pointerItem.SetDisplayY(mouseInfo.physicalY); -- Gitee From ff731b1ca966a2ffb92fc4a271436a8c032e4f9e Mon Sep 17 00:00:00 2001 From: lisong Date: Wed, 14 Sep 2022 11:29:46 +0800 Subject: [PATCH 016/360] =?UTF-8?q?=E5=8E=9F=E5=A7=8B=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E4=BA=A4=E4=BA=92=E6=84=8F=E5=9B=BE=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lisong --- frameworks/proxy/events/src/key_event.cpp | 42 ++++++++++++++ .../innerkits/event/include/key_event.h | 36 ++++++++++++ .../include/key_event_value_transformation.h | 4 ++ .../src/key_event_value_transformation.cpp | 55 +++++++++++++++++++ .../src/key_event_handler.cpp | 2 + 5 files changed, 139 insertions(+) diff --git a/frameworks/proxy/events/src/key_event.cpp b/frameworks/proxy/events/src/key_event.cpp index 2789b50546..1cbaaf6085 100644 --- a/frameworks/proxy/events/src/key_event.cpp +++ b/frameworks/proxy/events/src/key_event.cpp @@ -424,6 +424,38 @@ const int32_t KeyEvent::KEY_ACTION_CANCEL = 0X00000001; const int32_t KeyEvent::KEY_ACTION_DOWN = 0x00000002; const int32_t KeyEvent::KEY_ACTION_UP = 0X00000003; +const int32_t KeyEvent::INTENTION_UNKNOWN = -1; +const int32_t KeyEvent::INTENTION_UP = 1; +const int32_t KeyEvent::INTENTION_DOWN = 2; +const int32_t KeyEvent::INTENTION_LEFT = 3; +const int32_t KeyEvent::INTENTION_RIGHT = 4; +const int32_t KeyEvent::INTENTION_SELECT = 5; +const int32_t KeyEvent::INTENTION_ESCAPE = 6; +const int32_t KeyEvent::INTENTION_BACK = 7; +const int32_t KeyEvent::INTENTION_FORWARD = 8; +const int32_t KeyEvent::INTENTION_MENU = 9; +const int32_t KeyEvent::INTENTION_HOME = 10; +const int32_t KeyEvent::INTENTION_PAGE_UP = 11; +const int32_t KeyEvent::INTENTION_PAGE_DOWN = 12; +const int32_t KeyEvent::INTENTION_ZOOM_OUT = 13; +const int32_t KeyEvent::INTENTION_ZOOM_IN = 14; + +const int32_t KeyEvent::INTENTION_MEDIA_PLAY_PAUSE = 100; +const int32_t KeyEvent::INTENTION_MEDIA_FAST_FORWARD = 101; +const int32_t KeyEvent::INTENTION_MEDIA_FAST_REWIND = 102; +const int32_t KeyEvent::INTENTION_MEDIA_FAST_PLAYBACK = 103; +const int32_t KeyEvent::INTENTION_MEDIA_NEXT = 104; +const int32_t KeyEvent::INTENTION_MEDIA_PREVIOUS = 105; +const int32_t KeyEvent::INTENTION_MEDIA_MUTE = 106; +const int32_t KeyEvent::INTENTION_VOLUTE_UP = 107; +const int32_t KeyEvent::INTENTION_VOLUTE_DOWN = 108; + +const int32_t KeyEvent::INTENTION_CALL = 200; +const int32_t KeyEvent::INTENTION_ENDCALL = 201; +const int32_t KeyEvent::INTENTION_REJECTCALL = 202; + +const int32_t KeyEvent::INTENTION_CAMERA = 300; + KeyEvent::KeyItem::KeyItem() {} KeyEvent::KeyItem::~KeyItem() {} @@ -1222,5 +1254,15 @@ int32_t KeyEvent::SetFunctionKey(int32_t funcKey, int32_t value) } } } + +int32_t KeyEvent::GetKeyIntention() +{ + return keyIntention_; +} + +void KeyEvent::SetKeyIntention(int32_t keyIntention) +{ + keyIntention_ = keyIntention; +} } // namespace MMI } // namespace OHOS diff --git a/interfaces/native/innerkits/event/include/key_event.h b/interfaces/native/innerkits/event/include/key_event.h index ca2dbcef52..438d5d872a 100644 --- a/interfaces/native/innerkits/event/include/key_event.h +++ b/interfaces/native/innerkits/event/include/key_event.h @@ -2858,6 +2858,38 @@ public: */ static const int32_t KEY_ACTION_UP; + static const int32_t INTENTION_UNKNOWN; + static const int32_t INTENTION_UP; + static const int32_t INTENTION_DOWN; + static const int32_t INTENTION_LEFT; + static const int32_t INTENTION_RIGHT; + static const int32_t INTENTION_SELECT; + static const int32_t INTENTION_ESCAPE; + static const int32_t INTENTION_BACK; + static const int32_t INTENTION_FORWARD; + static const int32_t INTENTION_MENU; + static const int32_t INTENTION_HOME; + static const int32_t INTENTION_PAGE_UP; + static const int32_t INTENTION_PAGE_DOWN; + static const int32_t INTENTION_ZOOM_OUT; + static const int32_t INTENTION_ZOOM_IN; + + static const int32_t INTENTION_MEDIA_PLAY_PAUSE; + static const int32_t INTENTION_MEDIA_FAST_FORWARD; + static const int32_t INTENTION_MEDIA_FAST_REWIND; + static const int32_t INTENTION_MEDIA_FAST_PLAYBACK; + static const int32_t INTENTION_MEDIA_NEXT; + static const int32_t INTENTION_MEDIA_PREVIOUS; + static const int32_t INTENTION_MEDIA_MUTE; + static const int32_t INTENTION_VOLUTE_UP; + static const int32_t INTENTION_VOLUTE_DOWN; + + static const int32_t INTENTION_CALL; + static const int32_t INTENTION_ENDCALL; + static const int32_t INTENTION_REJECTCALL; + + static const int32_t INTENTION_CAMERA; + public: class KeyItem { public: @@ -3124,6 +3156,9 @@ public: */ bool GetFunctionKey(int32_t funcKey) const; + int32_t GetKeyIntention(); + void SetKeyIntention(int32_t keyIntention); + public: /** * @brief Writes data to a Parcel object. @@ -3159,6 +3194,7 @@ private: bool numLock_ { false }; bool capsLock_ { false }; bool scrollLock_ { false }; + int32_t keyIntention_ = -1; }; std::ostream& operator<<(std::ostream&, KeyEvent&); diff --git a/service/event_handler/include/key_event_value_transformation.h b/service/event_handler/include/key_event_value_transformation.h index d6c23856e2..bb5401f705 100644 --- a/service/event_handler/include/key_event_value_transformation.h +++ b/service/event_handler/include/key_event_value_transformation.h @@ -18,6 +18,8 @@ #include +#include "key_event.h" + namespace OHOS { namespace MMI { struct KeyEventValueTransformation { @@ -29,6 +31,8 @@ struct KeyEventValueTransformation { KeyEventValueTransformation TransferKeyValue(int32_t keyValueOfInput); int32_t InputTransformationKeyValue(int32_t keyCode); +int32_t GetKeyIntentionByKeyCode(int64_t keyCodes); +int32_t GetKeyIntentionByItems(std::shared_ptr keyEvent); } // namespace MMI } // namespace OHOS #endif // KEY_EVENT_VALUE_TRANSFORMATION_H \ No newline at end of file diff --git a/service/event_handler/src/key_event_value_transformation.cpp b/service/event_handler/src/key_event_value_transformation.cpp index 52b7b3cbcf..56bd332b34 100644 --- a/service/event_handler/src/key_event_value_transformation.cpp +++ b/service/event_handler/src/key_event_value_transformation.cpp @@ -459,5 +459,60 @@ int32_t InputTransformationKeyValue(int32_t keyCode) } return INVALID_KEY_CODE; } + +std::map KeyIntentionMap = { + {(int64_t)KeyEvent::KEYCODE_DPAD_UP, KeyEvent::INTENTION_UP}, + {(int64_t)KeyEvent::KEYCODE_DPAD_DOWN, KeyEvent::INTENTION_DOWN}, + {(int64_t)KeyEvent::KEYCODE_DPAD_LEFT, KeyEvent::INTENTION_LEFT}, + {(int64_t)KeyEvent::KEYCODE_DPAD_RIGHT, KeyEvent::INTENTION_RIGHT}, + {(int64_t)KeyEvent::KEYCODE_SPACE, KeyEvent::INTENTION_SELECT}, + {(int64_t)KeyEvent::KEYCODE_ESCAPE, KeyEvent::INTENTION_ESCAPE}, + {((int64_t)KeyEvent::KEYCODE_ALT_LEFT<<16) + KeyEvent::KEYCODE_DPAD_LEFT, KeyEvent::INTENTION_BACK}, + {((int64_t)KeyEvent::KEYCODE_ALT_LEFT<<16) + KeyEvent::KEYCODE_DPAD_RIGHT, KeyEvent::INTENTION_FORWARD}, + {((int64_t)KeyEvent::KEYCODE_ALT_RIGHT<<16) + KeyEvent::KEYCODE_DPAD_LEFT, KeyEvent::INTENTION_BACK}, + {((int64_t)KeyEvent::KEYCODE_ALT_RIGHT<<16) + KeyEvent::KEYCODE_DPAD_RIGHT, KeyEvent::INTENTION_FORWARD}, + {((int64_t)KeyEvent::KEYCODE_SHIFT_LEFT<<16) + KeyEvent::KEYCODE_F10, KeyEvent::INTENTION_MENU}, + {((int64_t)KeyEvent::KEYCODE_SHIFT_RIGHT<<16) + KeyEvent::KEYCODE_F10, KeyEvent::INTENTION_MENU}, + {(int64_t)KeyEvent::KEYCODE_MENU, KeyEvent::INTENTION_MENU}, + {(int64_t)KeyEvent::KEYCODE_PAGE_UP, KeyEvent::INTENTION_PAGE_UP}, + {(int64_t)KeyEvent::KEYCODE_PAGE_DOWN, KeyEvent::INTENTION_PAGE_DOWN}, + {((int64_t)KeyEvent::KEYCODE_CTRL_LEFT<<16) + KeyEvent::KEYCODE_PLUS, KeyEvent::INTENTION_ZOOM_OUT}, + {((int64_t)KeyEvent::KEYCODE_CTRL_RIGHT<<16) + KeyEvent::KEYCODE_PLUS, KeyEvent::INTENTION_ZOOM_OUT}, + {((int64_t)KeyEvent::KEYCODE_CTRL_LEFT<<16) + KeyEvent::KEYCODE_NUMPAD_ADD, KeyEvent::INTENTION_ZOOM_OUT}, + {((int64_t)KeyEvent::KEYCODE_CTRL_RIGHT<<16) + KeyEvent::KEYCODE_NUMPAD_ADD, KeyEvent::INTENTION_ZOOM_OUT}, + {((int64_t)KeyEvent::KEYCODE_CTRL_LEFT<<16) + KeyEvent::KEYCODE_MINUS, KeyEvent::INTENTION_ZOOM_IN}, + {((int64_t)KeyEvent::KEYCODE_CTRL_RIGHT<<16) + KeyEvent::KEYCODE_MINUS, KeyEvent::INTENTION_ZOOM_IN}, + {((int64_t)KeyEvent::KEYCODE_CTRL_LEFT<<16) + KeyEvent::KEYCODE_NUMPAD_SUBTRACT, KeyEvent::INTENTION_ZOOM_IN}, + {((int64_t)KeyEvent::KEYCODE_CTRL_RIGHT<<16) + KeyEvent::KEYCODE_NUMPAD_SUBTRACT, KeyEvent::INTENTION_ZOOM_IN}, + {(int64_t)KeyEvent::KEYCODE_VOLUME_MUTE, KeyEvent::INTENTION_MEDIA_MUTE}, + {(int64_t)KeyEvent::KEYCODE_MUTE, KeyEvent::INTENTION_MEDIA_MUTE}, + {(int64_t)KeyEvent::KEYCODE_VOLUME_UP, KeyEvent::INTENTION_VOLUTE_UP}, + {(int64_t)KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::INTENTION_VOLUTE_DOWN}, + {(int64_t)KeyEvent::KEYCODE_APPSELECT, KeyEvent::INTENTION_SELECT}, + {(int64_t)KeyEvent::KEYCODE_BACK, KeyEvent::INTENTION_BACK}, +}; + +int32_t GetKeyIntentionByKeyCode(int64_t keyCodes) +{ + auto iter = KeyIntentionMap.find(keyCodes); + if (iter == KeyIntentionMap.end()) { + return KeyEvent::INTENTION_UNKNOWN; + } + return iter->second; +} + +int32_t GetKeyIntentionByItems(std::shared_ptr keyEvent) +{ + std::vector items = keyEvent->GetKeyItems(); + if (items.size() > 3) { + return KeyEvent::INTENTION_UNKNOWN; + } + + int64_t keyCodes = 0; + for (const auto &item : items) { + keyCodes = (keyCodes<<16) + item.GetKeyCode(); + } + return GetKeyIntentionByKeyCode(keyCodes); +} } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/service/key_event_handler/src/key_event_handler.cpp b/service/key_event_handler/src/key_event_handler.cpp index 19fbf2cdae..dc20b12174 100644 --- a/service/key_event_handler/src/key_event_handler.cpp +++ b/service/key_event_handler/src/key_event_handler.cpp @@ -100,6 +100,8 @@ int32_t KeyEventHandler::Normalize(struct libinput_event *event, std::shared_ptr keyEvent->RemoveReleasedKeyItems(item); keyEvent->AddPressedKeyItems(item); } + int32_t keyIntention = GetKeyIntentionByItems(keyEvent); + keyEvent->SetKeyIntention(keyIntention); return RET_OK; } -- Gitee From 2a3310be6b31995b210cf32592c03c2db7d604f9 Mon Sep 17 00:00:00 2001 From: lisong Date: Wed, 14 Sep 2022 11:34:59 +0800 Subject: [PATCH 017/360] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AE=9A=E4=BD=8D?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lisong --- service/event_handler/src/key_event_value_transformation.cpp | 2 ++ service/key_event_handler/src/key_event_handler.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/service/event_handler/src/key_event_value_transformation.cpp b/service/event_handler/src/key_event_value_transformation.cpp index 56bd332b34..3c1df8c131 100644 --- a/service/event_handler/src/key_event_value_transformation.cpp +++ b/service/event_handler/src/key_event_value_transformation.cpp @@ -510,8 +510,10 @@ int32_t GetKeyIntentionByItems(std::shared_ptr keyEvent) int64_t keyCodes = 0; for (const auto &item : items) { + MMI_HILOGE("****************keyCode:%{public}d", item.GetKeyCode()); keyCodes = (keyCodes<<16) + item.GetKeyCode(); } + MMI_HILOGE("****************KeyCodes Sum:%{public}u", keyCodes); return GetKeyIntentionByKeyCode(keyCodes); } } // namespace MMI diff --git a/service/key_event_handler/src/key_event_handler.cpp b/service/key_event_handler/src/key_event_handler.cpp index dc20b12174..53c7d6f802 100644 --- a/service/key_event_handler/src/key_event_handler.cpp +++ b/service/key_event_handler/src/key_event_handler.cpp @@ -101,6 +101,7 @@ int32_t KeyEventHandler::Normalize(struct libinput_event *event, std::shared_ptr keyEvent->AddPressedKeyItems(item); } int32_t keyIntention = GetKeyIntentionByItems(keyEvent); + MMI_HILOGE("****************KeyEventHandler::Normalize, keyIntention:%{public}d", keyIntention); keyEvent->SetKeyIntention(keyIntention); return RET_OK; } -- Gitee From 89cbe838d80e6469c96f0ed0d20d233e2ce9fb0b Mon Sep 17 00:00:00 2001 From: lisong Date: Wed, 14 Sep 2022 14:22:22 +0800 Subject: [PATCH 018/360] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lisong --- service/event_handler/src/key_event_value_transformation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/event_handler/src/key_event_value_transformation.cpp b/service/event_handler/src/key_event_value_transformation.cpp index 3c1df8c131..b36eab09c8 100644 --- a/service/event_handler/src/key_event_value_transformation.cpp +++ b/service/event_handler/src/key_event_value_transformation.cpp @@ -513,7 +513,7 @@ int32_t GetKeyIntentionByItems(std::shared_ptr keyEvent) MMI_HILOGE("****************keyCode:%{public}d", item.GetKeyCode()); keyCodes = (keyCodes<<16) + item.GetKeyCode(); } - MMI_HILOGE("****************KeyCodes Sum:%{public}u", keyCodes); + MMI_HILOGE("****************KeyCodes Sum:%{public}lld", keyCodes); return GetKeyIntentionByKeyCode(keyCodes); } } // namespace MMI -- Gitee From 972a00a054c8884a00c113170491397ea8b4e741 Mon Sep 17 00:00:00 2001 From: lisong Date: Wed, 14 Sep 2022 15:15:20 +0800 Subject: [PATCH 019/360] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E5=85=B3=E9=94=AE=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lisong --- service/event_handler/src/key_event_value_transformation.cpp | 4 ++-- service/key_event_handler/src/key_event_handler.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/service/event_handler/src/key_event_value_transformation.cpp b/service/event_handler/src/key_event_value_transformation.cpp index b36eab09c8..f9c5094615 100644 --- a/service/event_handler/src/key_event_value_transformation.cpp +++ b/service/event_handler/src/key_event_value_transformation.cpp @@ -510,10 +510,10 @@ int32_t GetKeyIntentionByItems(std::shared_ptr keyEvent) int64_t keyCodes = 0; for (const auto &item : items) { - MMI_HILOGE("****************keyCode:%{public}d", item.GetKeyCode()); + MMI_HILOGE("songliy keyCode:%{public}d", item.GetKeyCode()); keyCodes = (keyCodes<<16) + item.GetKeyCode(); } - MMI_HILOGE("****************KeyCodes Sum:%{public}lld", keyCodes); + MMI_HILOGE("songliy KeyCodes Sum:%{public}lld", keyCodes); return GetKeyIntentionByKeyCode(keyCodes); } } // namespace MMI diff --git a/service/key_event_handler/src/key_event_handler.cpp b/service/key_event_handler/src/key_event_handler.cpp index 53c7d6f802..d226a2d327 100644 --- a/service/key_event_handler/src/key_event_handler.cpp +++ b/service/key_event_handler/src/key_event_handler.cpp @@ -101,7 +101,7 @@ int32_t KeyEventHandler::Normalize(struct libinput_event *event, std::shared_ptr keyEvent->AddPressedKeyItems(item); } int32_t keyIntention = GetKeyIntentionByItems(keyEvent); - MMI_HILOGE("****************KeyEventHandler::Normalize, keyIntention:%{public}d", keyIntention); + MMI_HILOGE("songliy KeyEventHandler::Normalize, keyIntention:%{public}d", keyIntention); keyEvent->SetKeyIntention(keyIntention); return RET_OK; } -- Gitee From 2dde97523300f0033a099634a3c29cb2460f5cc2 Mon Sep 17 00:00:00 2001 From: lisong Date: Wed, 14 Sep 2022 15:32:01 +0800 Subject: [PATCH 020/360] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=94=AE=E7=9B=98?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lisong --- frameworks/proxy/events/src/key_event.cpp | 1 + interfaces/native/innerkits/event/include/key_event.h | 7 +++++++ .../event_handler/src/key_event_value_transformation.cpp | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/frameworks/proxy/events/src/key_event.cpp b/frameworks/proxy/events/src/key_event.cpp index 1cbaaf6085..92906b229f 100644 --- a/frameworks/proxy/events/src/key_event.cpp +++ b/frameworks/proxy/events/src/key_event.cpp @@ -211,6 +211,7 @@ const int32_t KeyEvent::KEYCODE_BUTTON_BASE7 = 2413; const int32_t KeyEvent::KEYCODE_BUTTON_BASE8 = 2414; const int32_t KeyEvent::KEYCODE_BUTTON_BASE9 = 2415; const int32_t KeyEvent::KEYCODE_BUTTON_DEAD = 2416; +const int32_t KeyEvent::KEYCODE_COMPOSE = 2466; const int32_t KeyEvent::KEYCODE_SLEEP = 2600; const int32_t KeyEvent::KEYCODE_ZENKAKU_HANKAKU = 2601; const int32_t KeyEvent::KEYCODE_102ND = 2602; diff --git a/interfaces/native/innerkits/event/include/key_event.h b/interfaces/native/innerkits/event/include/key_event.h index 438d5d872a..d791106ac8 100644 --- a/interfaces/native/innerkits/event/include/key_event.h +++ b/interfaces/native/innerkits/event/include/key_event.h @@ -1368,6 +1368,13 @@ public: */ static const int32_t KEYCODE_BUTTON_DEAD; + /** + * Keyboard menu key + * + * @since 9 + */ + static const int32_t KEYCODE_COMPOSE; + /** * Sleep key * diff --git a/service/event_handler/src/key_event_value_transformation.cpp b/service/event_handler/src/key_event_value_transformation.cpp index f9c5094615..eef6691186 100644 --- a/service/event_handler/src/key_event_value_transformation.cpp +++ b/service/event_handler/src/key_event_value_transformation.cpp @@ -473,7 +473,7 @@ std::map KeyIntentionMap = { {((int64_t)KeyEvent::KEYCODE_ALT_RIGHT<<16) + KeyEvent::KEYCODE_DPAD_RIGHT, KeyEvent::INTENTION_FORWARD}, {((int64_t)KeyEvent::KEYCODE_SHIFT_LEFT<<16) + KeyEvent::KEYCODE_F10, KeyEvent::INTENTION_MENU}, {((int64_t)KeyEvent::KEYCODE_SHIFT_RIGHT<<16) + KeyEvent::KEYCODE_F10, KeyEvent::INTENTION_MENU}, - {(int64_t)KeyEvent::KEYCODE_MENU, KeyEvent::INTENTION_MENU}, + {(int64_t)KeyEvent::KEYCODE_COMPOSE, KeyEvent::INTENTION_MENU}, {(int64_t)KeyEvent::KEYCODE_PAGE_UP, KeyEvent::INTENTION_PAGE_UP}, {(int64_t)KeyEvent::KEYCODE_PAGE_DOWN, KeyEvent::INTENTION_PAGE_DOWN}, {((int64_t)KeyEvent::KEYCODE_CTRL_LEFT<<16) + KeyEvent::KEYCODE_PLUS, KeyEvent::INTENTION_ZOOM_OUT}, -- Gitee From 1480c4c923a4f91c54d769ab5ccf54c62556fbd2 Mon Sep 17 00:00:00 2001 From: lisong Date: Thu, 15 Sep 2022 10:00:38 +0800 Subject: [PATCH 021/360] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=84=8F=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lisong --- service/event_handler/src/key_event_value_transformation.cpp | 3 ++- service/key_event_handler/src/key_event_handler.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/service/event_handler/src/key_event_value_transformation.cpp b/service/event_handler/src/key_event_value_transformation.cpp index eef6691186..8fe40b446e 100644 --- a/service/event_handler/src/key_event_value_transformation.cpp +++ b/service/event_handler/src/key_event_value_transformation.cpp @@ -466,6 +466,7 @@ std::map KeyIntentionMap = { {(int64_t)KeyEvent::KEYCODE_DPAD_LEFT, KeyEvent::INTENTION_LEFT}, {(int64_t)KeyEvent::KEYCODE_DPAD_RIGHT, KeyEvent::INTENTION_RIGHT}, {(int64_t)KeyEvent::KEYCODE_SPACE, KeyEvent::INTENTION_SELECT}, + {(int64_t)KeyEvent::KEYCODE_NUMPAD_ENTER, KeyEvent::INTENTION_SELECT}, {(int64_t)KeyEvent::KEYCODE_ESCAPE, KeyEvent::INTENTION_ESCAPE}, {((int64_t)KeyEvent::KEYCODE_ALT_LEFT<<16) + KeyEvent::KEYCODE_DPAD_LEFT, KeyEvent::INTENTION_BACK}, {((int64_t)KeyEvent::KEYCODE_ALT_LEFT<<16) + KeyEvent::KEYCODE_DPAD_RIGHT, KeyEvent::INTENTION_FORWARD}, @@ -490,6 +491,7 @@ std::map KeyIntentionMap = { {(int64_t)KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::INTENTION_VOLUTE_DOWN}, {(int64_t)KeyEvent::KEYCODE_APPSELECT, KeyEvent::INTENTION_SELECT}, {(int64_t)KeyEvent::KEYCODE_BACK, KeyEvent::INTENTION_BACK}, + {(int64_t)KeyEvent::KEYCODE_MOVE_HOME, KeyEvent::INTENTION_HOME}, }; int32_t GetKeyIntentionByKeyCode(int64_t keyCodes) @@ -513,7 +515,6 @@ int32_t GetKeyIntentionByItems(std::shared_ptr keyEvent) MMI_HILOGE("songliy keyCode:%{public}d", item.GetKeyCode()); keyCodes = (keyCodes<<16) + item.GetKeyCode(); } - MMI_HILOGE("songliy KeyCodes Sum:%{public}lld", keyCodes); return GetKeyIntentionByKeyCode(keyCodes); } } // namespace MMI diff --git a/service/key_event_handler/src/key_event_handler.cpp b/service/key_event_handler/src/key_event_handler.cpp index d226a2d327..a3fc1ab737 100644 --- a/service/key_event_handler/src/key_event_handler.cpp +++ b/service/key_event_handler/src/key_event_handler.cpp @@ -101,7 +101,7 @@ int32_t KeyEventHandler::Normalize(struct libinput_event *event, std::shared_ptr keyEvent->AddPressedKeyItems(item); } int32_t keyIntention = GetKeyIntentionByItems(keyEvent); - MMI_HILOGE("songliy KeyEventHandler::Normalize, keyIntention:%{public}d", keyIntention); + MMI_HILOGE("songliy KeyEventHandler:: Normalize, keyIntention:%{public}d", keyIntention); keyEvent->SetKeyIntention(keyIntention); return RET_OK; } -- Gitee From b9efed804a74aca0ec685a5a04d44cf31f2b8fbd Mon Sep 17 00:00:00 2001 From: lilong Date: Thu, 15 Sep 2022 14:32:15 +0800 Subject: [PATCH 022/360] =?UTF-8?q?uinput=E6=B3=A8=E5=85=A5=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E6=96=B0=E5=8A=9F=E8=83=BD=EF=BC=9A=E9=BC=A0=E6=A0=87?= =?UTF-8?q?=E5=B9=B3=E6=BB=91=E6=8B=96=E6=8B=BD=E4=BB=A5=E5=8F=8A=E9=BC=A0?= =?UTF-8?q?=E6=A0=87=E5=B9=B3=E6=BB=91=E6=8B=96=E6=8B=BD=E6=B5=8B=E8=AF=95?= =?UTF-8?q?UT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lilong --- .../src/input_manager_command.cpp | 97 ++++++++++++++++++- tools/inject_event/test/inject_event_test.cpp | 23 +++++ 2 files changed, 119 insertions(+), 1 deletion(-) diff --git a/tools/inject_event/src/input_manager_command.cpp b/tools/inject_event/src/input_manager_command.cpp index 8085c710c4..2e98ffeb01 100755 --- a/tools/inject_event/src/input_manager_command.cpp +++ b/tools/inject_event/src/input_manager_command.cpp @@ -116,6 +116,7 @@ int32_t InputManagerCommand::ParseCommand(int32_t argc, char *argv[]) {"down", required_argument, NULL, 'd'}, {"up", required_argument, NULL, 'u'}, {"scroll", required_argument, NULL, 's'}, + {"drag", required_argument, NULL, 'g'}, {"interval", required_argument, NULL, 'i'}, {NULL, 0, NULL, 0} }; @@ -145,7 +146,7 @@ int32_t InputManagerCommand::ParseCommand(int32_t argc, char *argv[]) int32_t py = 0; int32_t buttonId; int32_t scrollValue; - while ((c = getopt_long(argc, argv, "m:d:u:c:b:s:i:", mouseSensorOptions, &optionIndex)) != -1) { + while ((c = getopt_long(argc, argv, "m:d:u:c:b:s:g:i:", mouseSensorOptions, &optionIndex)) != -1) { switch (c) { case 'm': { if (argc - optind < 1) { @@ -528,6 +529,97 @@ int32_t InputManagerCommand::ParseCommand(int32_t argc, char *argv[]) InputMgr->SimulateInputEvent(pointerEvent); break; } + case 'g': { + int32_t px1 = 0; + int32_t py1 = 0; + int32_t px2 = 0; + int32_t py2 = 0; + int32_t buttonId = 0; + int32_t totalTimeMs = 1000; + if (argc < 7) { + std::cout << "argc:" << argc << std::endl; + std::cout << "Wrong number of parameters" << std::endl; + return RET_ERR; + } + if (argc >= 7) { + if ((!StrToInt(optarg, px1)) || + (!StrToInt(argv[optind], py1)) || + (!StrToInt(argv[optind + 1], px2)) || + (!StrToInt(argv[optind + 2], py2))) { + std::cout << "Invalid coordinate value" << std::endl; + return RET_ERR; + } + } + if ((px1 < 0) || (py1 < 0) || (px2 < 0) || (py2 < 0)) { + std::cout << "Coordinate value must be greater than 0" << std::endl; + return RET_ERR; + } + if (argc >= 8) { + if (!StrToInt(argv[optind + 3], totalTimeMs)) { + std::cout << "Invalid total times" << std::endl; + return RET_ERR; + } + } + static const int64_t minTotalTimeMs = 1; + static const int64_t maxTotalTimeMs = 15000; + if ((totalTimeMs < minTotalTimeMs) || (totalTimeMs > maxTotalTimeMs)) { + std::cout << "Total time is out of range:" + << minTotalTimeMs << "ms" << " <= " << totalTimeMs << "ms" << " <= " + << maxTotalTimeMs << "ms" << std::endl; + return RET_ERR; + } + std::cout << "start coordinate: (" << px1 << ", " << py1 << ")" << std::endl; + std::cout << " end coordinate: (" << px2 << ", " << py2 << ")" << std::endl; + std::cout << " total time: " << totalTimeMs << "ms" << std::endl; + auto pointerEvent = PointerEvent::Create(); + CHKPR(pointerEvent, ERROR_NULL_POINTER); + PointerEvent::PointerItem item; + item.SetPointerId(0); + item.SetDisplayX(px1); + item.SetDisplayY(py1); + item.SetPressed(false); + pointerEvent->SetPointerId(0); + pointerEvent->AddPointerItem(item); + pointerEvent->SetButtonPressed(0); + pointerEvent->SetButtonId(buttonId); + pointerEvent->SetButtonPressed(buttonId); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN); + pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); + InputMgr->SimulateInputEvent(pointerEvent); + + int64_t startTimeMs = GetSysClockTime() / 1000; + int64_t endTimeMs = 0; + if (!AddInt64(startTimeMs, totalTimeMs, endTimeMs)) { + std::cout << "System time error" << std::endl; + return RET_ERR; + } + int64_t currentTimeMs = startTimeMs; + while (currentTimeMs < endTimeMs) { + item.SetDisplayX(NextPos(startTimeMs, currentTimeMs, totalTimeMs, px1, px2)); + item.SetDisplayY(NextPos(startTimeMs, currentTimeMs, totalTimeMs, py1, py2)); + pointerEvent->SetActionTime(currentTimeMs); + pointerEvent->UpdatePointerItem(0, item); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE); + InputMgr->SimulateInputEvent(pointerEvent); + SleepAndUpdateTime(currentTimeMs); + } + item.SetDisplayX(px2); + item.SetDisplayY(py2); + pointerEvent->SetActionTime(endTimeMs); + pointerEvent->UpdatePointerItem(0, item); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE); + InputMgr->SimulateInputEvent(pointerEvent); + std::this_thread::sleep_for(std::chrono::milliseconds(BLOCK_TIME_MS)); + + item.SetDisplayX(px2); + item.SetDisplayY(py2); + item.SetPressed(true); + pointerEvent->SetActionTime(endTimeMs); + pointerEvent->UpdatePointerItem(0, item); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_UP); + InputMgr->SimulateInputEvent(pointerEvent); + break; + } case 'i': { int32_t taktTime = 0; if (!StrToInt(optarg, taktTime)) { @@ -1100,6 +1192,9 @@ void InputManagerCommand::ShowUsage() std::cout << " key value:6 - button back" << std::endl; std::cout << " key value:7 - button task" << std::endl; std::cout << "-s --scroll -positive values are sliding backwards" << std::endl; + std::cout << "-g [total time] --drag [total time],"; + std::cout << std::endl; + std::cout << " dx1 dy1 to dx2 dy2 smooth drag" << std::endl; std::cout << "-i