From 47e696a5777a610f29de1fca7b3a09157eb7e669 Mon Sep 17 00:00:00 2001 From: Zhen Li Date: Mon, 14 Jul 2025 16:44:36 -0400 Subject: [PATCH 01/11] fix caps sync Signed-off-by: Zhen Li --- service/BUILD.gn | 2 + .../src/key_event_normalize.cpp | 30 +++- .../test/key_event_normalize_test.cpp | 136 ++++++++++++++---- .../libinput_adapter/src/libinput_adapter.cpp | 50 +++++-- .../include/libinput_interface.h | 2 + .../src/libinput_interface.cpp | 15 +- test/facility/mock/include/libinput_mock.h | 2 + 7 files changed, 183 insertions(+), 54 deletions(-) diff --git a/service/BUILD.gn b/service/BUILD.gn index c243474dfe..bbdb2829a4 100644 --- a/service/BUILD.gn +++ b/service/BUILD.gn @@ -2063,12 +2063,14 @@ ohos_unittest("KeyEventNormalizeTest") { "${mmi_path}/service:libmmi-server", "${mmi_path}/test/facility/libinput_wrapper:libinput_wrapper_sources", "${mmi_path}/test/facility/virtual_device:virtual_device_sources", + "${mmi_path}/test/facility/mock:mmi_mock_sources", "${mmi_path}/util:libmmi-util", ] external_deps = [ "cJSON:cjson", "c_utils:utilsbase", + "googletest:gmock_main", "googletest:gtest_main", "graphic_2d:2d_graphics", "graphic_2d:librender_service_client", diff --git a/service/key_event_normalize/src/key_event_normalize.cpp b/service/key_event_normalize/src/key_event_normalize.cpp index 6ce27f8a08..b8ce62298a 100644 --- a/service/key_event_normalize/src/key_event_normalize.cpp +++ b/service/key_event_normalize/src/key_event_normalize.cpp @@ -166,19 +166,35 @@ void KeyEventNormalize::HandleKeyAction(struct libinput_device* device, KeyEvent void KeyEventNormalize::ResetKeyEvent(struct libinput_device* device) { if (INPUT_DEV_MGR->IsKeyboardDevice(device) || INPUT_DEV_MGR->IsPointerDevice(device)) { + bool newKeyEventJustCreated = false; if (keyEvent_ == nullptr) { keyEvent_ = KeyEvent::Create(); + newKeyEventJustCreated = true; } - if (libinput_has_event_led_type(device)) { - CHKPV(keyEvent_); - const std::vector funcKeys = { - KeyEvent::NUM_LOCK_FUNCTION_KEY, - KeyEvent::CAPS_LOCK_FUNCTION_KEY, - KeyEvent::SCROLL_LOCK_FUNCTION_KEY - }; + CHKPV(keyEvent_); + + if (!libinput_has_event_led_type(device)) { + // skip if this device does not have led lights. + return; + } + + const std::vector funcKeys = { + KeyEvent::NUM_LOCK_FUNCTION_KEY, + KeyEvent::CAPS_LOCK_FUNCTION_KEY, + KeyEvent::SCROLL_LOCK_FUNCTION_KEY + }; + if (newKeyEventJustCreated) { + // if key event just created, set keyevent from this new device. + MMI_HILOGI("Reset key event function key state based on the new added device's led"); for (const auto &funcKey : funcKeys) { keyEvent_->SetFunctionKey(funcKey, libinput_get_funckey_state(device, funcKey)); } + } else { + // otherwise, set this new device's function key state based on the key event. + MMI_HILOGI("Reset new added device's led based on the key event"); + for (const auto &funcKey : funcKeys) { + libinput_set_led_state(device, funcKey, keyEvent_->GetFunctionKey(funcKey)); + } } } } diff --git a/service/key_event_normalize/test/key_event_normalize_test.cpp b/service/key_event_normalize/test/key_event_normalize_test.cpp index d467a58da7..08ecaeb487 100644 --- a/service/key_event_normalize/test/key_event_normalize_test.cpp +++ b/service/key_event_normalize/test/key_event_normalize_test.cpp @@ -23,6 +23,7 @@ #include "i_input_windows_manager.h" #include "key_event_normalize.h" #include "libinput_wrapper.h" +#include "libinput_mock.h" #include "pointer_event.h" #undef MMI_LOG_TAG @@ -258,51 +259,124 @@ HWTEST_F(KeyEventNormalizeTest, KeyEventNormalizeTest_HandleKeyAction_003, TestS /** * @tc.name: KeyEventNormalizeTest_ResetKeyEvent_001 - * @tc.desc: Test ResetKeyEvent + * @tc.desc: Test ResetKeyEvent with a device without led and null keyEvent. * @tc.type: FUNC * @tc.require: */ -HWTEST_F(KeyEventNormalizeTest, KeyEventNormalizeTest_ResetKeyEvent_001, TestSize.Level1) +HWTEST_F(KeyEventNormalizeTest, KeyEventNormalizeTest_ResetKeyEvent_LedOff_001, TestSize.Level1) { CALL_TEST_DEBUG; - vKeyboard_.SendEvent(EV_KEY, 29, 1); - vKeyboard_.SendEvent(EV_KEY, KEY_C, 1); - vKeyboard_.SendEvent(EV_SYN, SYN_REPORT, 0); - vKeyboard_.SendEvent(EV_KEY, KEY_C, 0); - vKeyboard_.SendEvent(EV_KEY, 29, 0); - vKeyboard_.SendEvent(EV_SYN, SYN_REPORT, 0); - libinput_event *event = libinput_.Dispatch(); - ASSERT_TRUE(event != nullptr); - struct libinput_device *dev = libinput_event_get_device(event); - ASSERT_TRUE(dev != nullptr); - std::cout << "keyboard device: " << libinput_device_get_name(dev) << std::endl; - std::shared_ptr keyEvent = nullptr; - EXPECT_NO_FATAL_FAILURE(KeyEventHdr->ResetKeyEvent(dev)); + testing::NiceMock libinputMock; + // create a node for keyboard. + struct libinput_device libDev { + .udevDev { 2 }, + .busType = 1, + .version = 1, + .product = 1, + .vendor = 1, + .name = "test", + }; + std::cout << "keyboard device: " << libinput_device_get_name(&libDev) << std::endl; + EXPECT_EQ(INPUT_DEV_MGR->IsKeyboardDevice(&libDev), true); + KeyEventHdr->keyEvent_ = nullptr; + EXPECT_CALL(libinputMock, HasEventLedType).WillOnce(testing::Return(0)); + EXPECT_NO_FATAL_FAILURE(KeyEventHdr->ResetKeyEvent(&libDev)); } /** * @tc.name: KeyEventNormalizeTest_ResetKeyEvent_002 - * @tc.desc: Test ResetKeyEvent + * @tc.desc: Test ResetKeyEvent with a device without led and valid keyEvent. * @tc.type: FUNC * @tc.require: */ -HWTEST_F(KeyEventNormalizeTest, KeyEventNormalizeTest_ResetKeyEvent_002, TestSize.Level1) +HWTEST_F(KeyEventNormalizeTest, KeyEventNormalizeTest_ResetKeyEvent_LedOff_002, TestSize.Level1) { CALL_TEST_DEBUG; - vKeyboard_.SendEvent(EV_KEY, 29, 1); - vKeyboard_.SendEvent(EV_KEY, KEY_C, 1); - vKeyboard_.SendEvent(EV_SYN, SYN_REPORT, 0); - vKeyboard_.SendEvent(EV_KEY, KEY_C, 0); - vKeyboard_.SendEvent(EV_KEY, 29, 0); - vKeyboard_.SendEvent(EV_SYN, SYN_REPORT, 0); - libinput_event *event = libinput_.Dispatch(); - ASSERT_TRUE(event != nullptr); - struct libinput_device *dev = libinput_event_get_device(event); - ASSERT_TRUE(dev != nullptr); - std::cout << "keyboard device: " << libinput_device_get_name(dev) << std::endl; - std::shared_ptr keyEvent = KeyEvent::Create(); - ASSERT_TRUE(keyEvent != nullptr); - EXPECT_NO_FATAL_FAILURE(KeyEventHdr->ResetKeyEvent(dev)); + testing::NiceMock libinputMock; + // create a node for keyboard. + struct libinput_device libDev { + .udevDev { 2 }, + .busType = 1, + .version = 1, + .product = 1, + .vendor = 1, + .name = "test", + }; + std::cout << "keyboard device: " << libinput_device_get_name(&libDev) << std::endl; + EXPECT_EQ(INPUT_DEV_MGR->IsKeyboardDevice(&libDev), true); + KeyEventHdr->keyEvent_ = KeyEvent::Create(); + ASSERT_TRUE(KeyEventHdr->keyEvent_ != nullptr); + EXPECT_CALL(libinputMock, HasEventLedType).WillOnce(testing::Return(0)); + EXPECT_NO_FATAL_FAILURE(KeyEventHdr->ResetKeyEvent(&libDev)); +} + +/** + * @tc.name: KeyEventNormalizeTest_ResetKeyEvent_003 + * @tc.desc: Test ResetKeyEvent with a device with led and null keyEvent. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(KeyEventNormalizeTest, KeyEventNormalizeTest_ResetKeyEvent_LedOn_003, TestSize.Level1) +{ + CALL_TEST_DEBUG; + testing::NiceMock libinputMock; + // create a node for keyboard. + struct libinput_device libDev { + .udevDev { 2 }, + .busType = 1, + .version = 1, + .product = 1, + .vendor = 1, + .name = "test", + }; + std::cout << "keyboard device: " << libinput_device_get_name(&libDev) << std::endl; + EXPECT_EQ(INPUT_DEV_MGR->IsKeyboardDevice(&libDev), true); + KeyEventHdr->keyEvent_ = nullptr; + EXPECT_CALL(libinputMock, HasEventLedType).WillOnce(testing::Return(1)); + // mock: all lights on. + EXPECT_CALL(libinputMock, GetFuncKeyState).WillRepeatedly(testing::Return(1)); + EXPECT_NO_FATAL_FAILURE(KeyEventHdr->ResetKeyEvent(&libDev)); + ASSERT_TRUE(KeyEventHdr->keyEvent_ != nullptr); + EXPECT_EQ(KeyEventHdr->keyEvent_->GetFunctionKey(KeyEvent::NUM_LOCK_FUNCTION_KEY), true); + EXPECT_EQ(KeyEventHdr->keyEvent_->GetFunctionKey(KeyEvent::CAPS_LOCK_FUNCTION_KEY), true); + EXPECT_EQ(KeyEventHdr->keyEvent_->GetFunctionKey(KeyEvent::SCROLL_LOCK_FUNCTION_KEY), true); +} + +/** + * @tc.name: KeyEventNormalizeTest_ResetKeyEvent_004 + * @tc.desc: Test ResetKeyEvent with a device with led and valid keyEvent. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(KeyEventNormalizeTest, KeyEventNormalizeTest_ResetKeyEvent_LedOn_004, TestSize.Level1) +{ + CALL_TEST_DEBUG; + testing::NiceMock libinputMock; + // create a node for keyboard. + struct libinput_device libDev { + .udevDev { 2 }, + .busType = 1, + .version = 1, + .product = 1, + .vendor = 1, + .name = "test", + }; + std::cout << "keyboard device: " << libinput_device_get_name(&libDev) << std::endl; + EXPECT_EQ(INPUT_DEV_MGR->IsKeyboardDevice(&libDev), true); + KeyEventHdr->keyEvent_ = KeyEvent::Create(); + ASSERT_TRUE(KeyEventHdr->keyEvent_ != nullptr); + // original: 0, 1, 0. + KeyEventHdr->keyEvent_->SetFunctionKey(KeyEvent::NUM_LOCK_FUNCTION_KEY, 0); + KeyEventHdr->keyEvent_->SetFunctionKey(KeyEvent::CAPS_LOCK_FUNCTION_KEY, 1); + KeyEventHdr->keyEvent_->SetFunctionKey(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, 0); + EXPECT_CALL(libinputMock, HasEventLedType).WillOnce(testing::Return(1)); + // mock: all lights on. + EXPECT_CALL(libinputMock, GetFuncKeyState).WillRepeatedly(testing::Return(1)); + EXPECT_NO_FATAL_FAILURE(KeyEventHdr->ResetKeyEvent(&libDev)); + // keyEvent unchanged: 0, 1, 0 + EXPECT_EQ(KeyEventHdr->keyEvent_->GetFunctionKey(KeyEvent::NUM_LOCK_FUNCTION_KEY), false); + EXPECT_EQ(KeyEventHdr->keyEvent_->GetFunctionKey(KeyEvent::CAPS_LOCK_FUNCTION_KEY), true); + EXPECT_EQ(KeyEventHdr->keyEvent_->GetFunctionKey(KeyEvent::SCROLL_LOCK_FUNCTION_KEY), false); } /** diff --git a/service/libinput_adapter/src/libinput_adapter.cpp b/service/libinput_adapter/src/libinput_adapter.cpp index ed331b7440..8299f2a267 100644 --- a/service/libinput_adapter/src/libinput_adapter.cpp +++ b/service/libinput_adapter/src/libinput_adapter.cpp @@ -424,25 +424,50 @@ void LibinputAdapter::HandleVKeyboardMessage(VKeyboardEventType eventType, switch (eventType) { case VKeyboardEventType::NormalKeyboardEvent: { for (auto event : keyEvents) { - funInputEvent_(event, frameTime); + // sync system keyevent caps value to libinput value. + std::shared_ptr sharedKeyEvent = KeyEventHdr->GetKeyEvent(); + auto device = libinput_event_get_device(event); + if (sharedKeyEvent != nullptr && device != nullptr) { + bool isCapsLockOn = sharedKeyEvent->GetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY); + bool libinputCapsLockOn = + static_cast(libinput_get_funckey_state(device, MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY)); + + funInputEvent_(event, frameTime); + + if (libinputCapsLockOn != isCapsLockOn) { + // non-caps scenario, if a mismatch is found, sync it now. + libinput_toggle_caps_key(); + } + } else { + MMI_HILOGW("Failed to sync virtual keyboard's Caps state given nullptr of sharedKeyEvent/device."); + funInputEvent_(event, frameTime); + } free(event); } break; } case VKeyboardEventType::UpdateCaps: { for (auto event : keyEvents) { - funInputEvent_(event, frameTime); - free(event); - } - struct libinput_device* device = INPUT_DEV_MGR->GetKeyboardDevice(); - if (device != nullptr) { - std::shared_ptr keyEvent = KeyEventHdr->GetKeyEvent(); - if (keyEvent != nullptr) { - bool isCapsLockOn = keyEvent->GetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY); - - DeviceLedUpdate(device, KeyEvent::CAPS_LOCK_FUNCTION_KEY, !isCapsLockOn); - keyEvent->SetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY, !isCapsLockOn); + std::shared_ptr sharedKeyEvent = KeyEventHdr->GetKeyEvent(); + auto device = libinput_event_get_device(event); + if (sharedKeyEvent != nullptr && device != nullptr) { + bool isCapsLockOn = sharedKeyEvent->GetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY); + bool libinputCapsLockOn = + static_cast(libinput_get_funckey_state(device, MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY)); + + funInputEvent_(event, frameTime); + + if (libinputCapsLockOn == isCapsLockOn) { + libinput_toggle_caps_key(); + } // no need to flip virtual keyboard's caps if it is already flipped. + + sharedKeyEvent->SetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY, !isCapsLockOn); + MultiKeyboardSetLedState(isCapsLockOn); + } else { + MMI_HILOGW("Failed to sync virtual keyboard's Caps state given nullptr of sharedKeyEvent/device."); + funInputEvent_(event, frameTime); } + free(event); } break; } @@ -796,7 +821,6 @@ type:%{private}d, accPressure:%{private}f, longAxis:%{private}d, shortAxis:%{pri && keyEvent != nullptr) { bool oldCapsLockOn = keyEvent->GetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY); libinput_device* device = libinput_event_get_device(event); - int libinputCaps = libinput_get_funckey_state(device, MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY); HandleHWKeyEventForVKeyboard(event); funInputEvent_(event, frameTime); diff --git a/test/facility/libinput_interface/include/libinput_interface.h b/test/facility/libinput_interface/include/libinput_interface.h index 6e189605c0..979911bd67 100644 --- a/test/facility/libinput_interface/include/libinput_interface.h +++ b/test/facility/libinput_interface/include/libinput_interface.h @@ -143,6 +143,8 @@ public: virtual struct libinput_event_keyboard* LibinputEventGetKeyboardEvent (struct libinput_event *event) = 0; virtual uint32_t LibinputEventKeyboardGetKey (struct libinput_event_keyboard *event) = 0; virtual enum libinput_key_state LibinputEventKeyboardGetKeyState (struct libinput_event_keyboard *event) = 0; + virtual int HasEventLedType (struct libinput_device *device) = 0; + virtual int GetFuncKeyState (struct libinput_device *device, unsigned int code) = 0; }; } // namespace MMI } // namespace OHOS diff --git a/test/facility/libinput_interface/src/libinput_interface.cpp b/test/facility/libinput_interface/src/libinput_interface.cpp index bec5f07bc3..90b95cc13a 100644 --- a/test/facility/libinput_interface/src/libinput_interface.cpp +++ b/test/facility/libinput_interface/src/libinput_interface.cpp @@ -338,7 +338,12 @@ int libinput_event_gesture_get_device_coords_y(struct libinput_event_gesture *ev int libinput_has_event_led_type(struct libinput_device *device) { - return 0; + return g_instance->HasEventLedType(device); +} + +int libinput_set_led_state(struct libinput_device *device, unsigned int code, unsigned int state) +{ + return 1; } const char* libinput_device_get_name(struct libinput_device *device) @@ -388,7 +393,11 @@ struct udev_device* libinput_device_get_udev_device(struct libinput_device *devi enum evdev_device_udev_tags libinput_device_get_tags(struct libinput_device* device) { - return EVDEV_UDEV_TAG_INPUT; + if (device == nullptr) { + return EVDEV_UDEV_TAG_INPUT; + } + enum evdev_device_udev_tags tag = static_cast(device->udevDev.tags); + return tag; } int libinput_device_has_capability(struct libinput_device *device, enum libinput_device_capability capability) @@ -433,7 +442,7 @@ int libinput_device_get_size(struct libinput_device *device, double *width, doub int libinput_get_funckey_state(struct libinput_device *device, unsigned int code) { - return 0; + return g_instance->GetFuncKeyState(device, code); } uint32_t libinput_event_pointer_get_finger_count(struct libinput_event_pointer *event) diff --git a/test/facility/mock/include/libinput_mock.h b/test/facility/mock/include/libinput_mock.h index 231b3f341f..149e1cbfc4 100644 --- a/test/facility/mock/include/libinput_mock.h +++ b/test/facility/mock/include/libinput_mock.h @@ -71,6 +71,8 @@ public: MOCK_METHOD(struct libinput_event_keyboard*, LibinputEventGetKeyboardEvent, (struct libinput_event *)); MOCK_METHOD(uint32_t, LibinputEventKeyboardGetKey, (struct libinput_event_keyboard *)); MOCK_METHOD(enum libinput_key_state, LibinputEventKeyboardGetKeyState, (struct libinput_event_keyboard *)); + MOCK_METHOD(int, HasEventLedType, (struct libinput_device *)); + MOCK_METHOD(int, GetFuncKeyState, (struct libinput_device *, unsigned int)); }; } // namespace MMI } // namespace OHOS -- Gitee From f63093814e1bf3a5e325f4994babe92798490e1e Mon Sep 17 00:00:00 2001 From: Zhen Li Date: Mon, 14 Jul 2025 17:26:23 -0400 Subject: [PATCH 02/11] sync caps between keyboards Signed-off-by: Zhen Li --- .../libinput_adapter/src/libinput_adapter.cpp | 61 ++++++++----------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/service/libinput_adapter/src/libinput_adapter.cpp b/service/libinput_adapter/src/libinput_adapter.cpp index 8299f2a267..a558a1d869 100644 --- a/service/libinput_adapter/src/libinput_adapter.cpp +++ b/service/libinput_adapter/src/libinput_adapter.cpp @@ -421,54 +421,41 @@ void LibinputAdapter::HandleVFullKeyboardMessages( void LibinputAdapter::HandleVKeyboardMessage(VKeyboardEventType eventType, std::vector keyEvents, int64_t frameTime) { + bool isCapsLockOn = false; + bool libinputCapsLockOn = false; + if ((eventType == VKeyboardEventType::NormalKeyboardEvent || eventType == VKeyboardEventType::UpdateCaps) && + !keyEvents.empty()) { + // check current caps state. + std::shared_ptr sharedKeyEvent = KeyEventHdr->GetKeyEvent(); + auto device = libinput_event_get_device(keyEvents.front()); + if (sharedKeyEvent != nullptr && device != nullptr) { + isCapsLockOn = sharedKeyEvent->GetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY); + libinputCapsLockOn = + static_cast(libinput_get_funckey_state(device, MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY)); + } + } switch (eventType) { case VKeyboardEventType::NormalKeyboardEvent: { for (auto event : keyEvents) { - // sync system keyevent caps value to libinput value. - std::shared_ptr sharedKeyEvent = KeyEventHdr->GetKeyEvent(); - auto device = libinput_event_get_device(event); - if (sharedKeyEvent != nullptr && device != nullptr) { - bool isCapsLockOn = sharedKeyEvent->GetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY); - bool libinputCapsLockOn = - static_cast(libinput_get_funckey_state(device, MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY)); - - funInputEvent_(event, frameTime); - - if (libinputCapsLockOn != isCapsLockOn) { - // non-caps scenario, if a mismatch is found, sync it now. - libinput_toggle_caps_key(); - } - } else { - MMI_HILOGW("Failed to sync virtual keyboard's Caps state given nullptr of sharedKeyEvent/device."); - funInputEvent_(event, frameTime); - } + funInputEvent_(event, frameTime); free(event); } + + if (libinputCapsLockOn != isCapsLockOn) { + // non-caps scenario, if a mismatch is found, sync it now. + libinput_toggle_caps_key(); + } break; } case VKeyboardEventType::UpdateCaps: { for (auto event : keyEvents) { - std::shared_ptr sharedKeyEvent = KeyEventHdr->GetKeyEvent(); - auto device = libinput_event_get_device(event); - if (sharedKeyEvent != nullptr && device != nullptr) { - bool isCapsLockOn = sharedKeyEvent->GetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY); - bool libinputCapsLockOn = - static_cast(libinput_get_funckey_state(device, MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY)); - - funInputEvent_(event, frameTime); - - if (libinputCapsLockOn == isCapsLockOn) { - libinput_toggle_caps_key(); - } // no need to flip virtual keyboard's caps if it is already flipped. - - sharedKeyEvent->SetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY, !isCapsLockOn); - MultiKeyboardSetLedState(isCapsLockOn); - } else { - MMI_HILOGW("Failed to sync virtual keyboard's Caps state given nullptr of sharedKeyEvent/device."); - funInputEvent_(event, frameTime); - } + funInputEvent_(event, frameTime); free(event); } + + if (libinputCapsLockOn == isCapsLockOn) { + libinput_toggle_caps_key(); + } // no need to flip virtual keyboard's caps if it is already flipped. break; } case VKeyboardEventType::HideCursor: { -- Gitee From 5d49280e7ebd1e2309ba72bec2cfdbc26d2970e6 Mon Sep 17 00:00:00 2001 From: Zhen Li Date: Mon, 14 Jul 2025 17:32:27 -0400 Subject: [PATCH 03/11] sync caps state between keyboards during hot plug in/off Signed-off-by: Zhen Li --- service/libinput_adapter/src/libinput_adapter.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/service/libinput_adapter/src/libinput_adapter.cpp b/service/libinput_adapter/src/libinput_adapter.cpp index a558a1d869..26ed748ade 100644 --- a/service/libinput_adapter/src/libinput_adapter.cpp +++ b/service/libinput_adapter/src/libinput_adapter.cpp @@ -432,6 +432,8 @@ void LibinputAdapter::HandleVKeyboardMessage(VKeyboardEventType eventType, isCapsLockOn = sharedKeyEvent->GetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY); libinputCapsLockOn = static_cast(libinput_get_funckey_state(device, MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY)); + } else { + MMI_HILOGW("Failed to sync virtual keyboard's Caps state given nullptr of keyEvent/device."); } } switch (eventType) { @@ -452,7 +454,10 @@ void LibinputAdapter::HandleVKeyboardMessage(VKeyboardEventType eventType, funInputEvent_(event, frameTime); free(event); } - + + std::shared_ptr keyEvent = KeyEventHdr->GetKeyEvent(); + keyEvent->SetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY, !isCapsLockOn); + MultiKeyboardSetLedState(isCapsLockOn); if (libinputCapsLockOn == isCapsLockOn) { libinput_toggle_caps_key(); } // no need to flip virtual keyboard's caps if it is already flipped. -- Gitee From 9748bf5fbb769164050c0dbf76ca85e5fb283da4 Mon Sep 17 00:00:00 2001 From: Zhen Li Date: Mon, 14 Jul 2025 17:41:11 -0400 Subject: [PATCH 04/11] sync caps state between keyboards during hot plug Signed-off-by: Zhen Li --- service/libinput_adapter/src/libinput_adapter.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/service/libinput_adapter/src/libinput_adapter.cpp b/service/libinput_adapter/src/libinput_adapter.cpp index 26ed748ade..38f0be7a90 100644 --- a/service/libinput_adapter/src/libinput_adapter.cpp +++ b/service/libinput_adapter/src/libinput_adapter.cpp @@ -456,7 +456,9 @@ void LibinputAdapter::HandleVKeyboardMessage(VKeyboardEventType eventType, } std::shared_ptr keyEvent = KeyEventHdr->GetKeyEvent(); - keyEvent->SetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY, !isCapsLockOn); + if (keyEvent != nullptr) { + keyEvent->SetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY, !isCapsLockOn); + } MultiKeyboardSetLedState(isCapsLockOn); if (libinputCapsLockOn == isCapsLockOn) { libinput_toggle_caps_key(); -- Gitee From 01dd518fc81ec8476c2c8e2ffb4547172b279eb3 Mon Sep 17 00:00:00 2001 From: Zhen Li Date: Mon, 14 Jul 2025 19:29:47 -0400 Subject: [PATCH 05/11] sync keyboard caps state during hot plug Signed-off-by: Zhen Li --- service/key_event_normalize/src/key_event_normalize.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/key_event_normalize/src/key_event_normalize.cpp b/service/key_event_normalize/src/key_event_normalize.cpp index b8ce62298a..9c82b42d8f 100644 --- a/service/key_event_normalize/src/key_event_normalize.cpp +++ b/service/key_event_normalize/src/key_event_normalize.cpp @@ -17,7 +17,7 @@ #include #include - +#include "libinput.h" #include "display_manager.h" #include "key_map_manager.h" #include "key_command_handler_util.h" -- Gitee From 50a6376fd607f28a9301ba292c55396410598da6 Mon Sep 17 00:00:00 2001 From: Zhen Li Date: Mon, 14 Jul 2025 20:19:18 -0400 Subject: [PATCH 06/11] sync keyboard caps status. Signed-off-by: Zhen Li --- service/key_event_normalize/src/key_event_normalize.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/service/key_event_normalize/src/key_event_normalize.cpp b/service/key_event_normalize/src/key_event_normalize.cpp index 9c82b42d8f..20a1fadafe 100644 --- a/service/key_event_normalize/src/key_event_normalize.cpp +++ b/service/key_event_normalize/src/key_event_normalize.cpp @@ -17,7 +17,7 @@ #include #include -#include "libinput.h" +#include "libinput_adapter.h" #include "display_manager.h" #include "key_map_manager.h" #include "key_command_handler_util.h" @@ -193,7 +193,7 @@ void KeyEventNormalize::ResetKeyEvent(struct libinput_device* device) // otherwise, set this new device's function key state based on the key event. MMI_HILOGI("Reset new added device's led based on the key event"); for (const auto &funcKey : funcKeys) { - libinput_set_led_state(device, funcKey, keyEvent_->GetFunctionKey(funcKey)); + LibinputAdapter::DeviceLedUpdate(device, funcKey, keyEvent_->GetFunctionKey(funcKey)); } } } -- Gitee From e8ef6e3cd8948ab58f519c380088e756f4426206 Mon Sep 17 00:00:00 2001 From: Zhen Li Date: Mon, 14 Jul 2025 20:19:18 -0400 Subject: [PATCH 07/11] sync keyboard caps status. Signed-off-by: Zhen Li --- service/key_event_normalize/src/key_event_normalize.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/service/key_event_normalize/src/key_event_normalize.cpp b/service/key_event_normalize/src/key_event_normalize.cpp index 9c82b42d8f..994d029cb0 100644 --- a/service/key_event_normalize/src/key_event_normalize.cpp +++ b/service/key_event_normalize/src/key_event_normalize.cpp @@ -17,7 +17,6 @@ #include #include -#include "libinput.h" #include "display_manager.h" #include "key_map_manager.h" #include "key_command_handler_util.h" @@ -183,6 +182,7 @@ void KeyEventNormalize::ResetKeyEvent(struct libinput_device* device) KeyEvent::CAPS_LOCK_FUNCTION_KEY, KeyEvent::SCROLL_LOCK_FUNCTION_KEY }; +#ifdef OHOS_BUILD_ENABLE_VKEYBOARD if (newKeyEventJustCreated) { // if key event just created, set keyevent from this new device. MMI_HILOGI("Reset key event function key state based on the new added device's led"); @@ -196,6 +196,11 @@ void KeyEventNormalize::ResetKeyEvent(struct libinput_device* device) libinput_set_led_state(device, funcKey, keyEvent_->GetFunctionKey(funcKey)); } } +#else // OHOS_BUILD_ENABLE_VKEYBOARD + for (const auto &funcKey : funcKeys) { + keyEvent_->SetFunctionKey(funcKey, libinput_get_funckey_state(device, funcKey)); + } +#endif // OHOS_BUILD_ENABLE_VKEYBOARD } } -- Gitee From 6e9111796da6bd5f841a74e30e925c60f75b8132 Mon Sep 17 00:00:00 2001 From: Zhen Li Date: Mon, 14 Jul 2025 22:19:20 -0400 Subject: [PATCH 08/11] Sync caps among keyboards Signed-off-by: Zhen Li --- service/key_event_normalize/test/key_event_normalize_test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/service/key_event_normalize/test/key_event_normalize_test.cpp b/service/key_event_normalize/test/key_event_normalize_test.cpp index 08ecaeb487..830dda9df5 100644 --- a/service/key_event_normalize/test/key_event_normalize_test.cpp +++ b/service/key_event_normalize/test/key_event_normalize_test.cpp @@ -373,10 +373,12 @@ HWTEST_F(KeyEventNormalizeTest, KeyEventNormalizeTest_ResetKeyEvent_LedOn_004, T // mock: all lights on. EXPECT_CALL(libinputMock, GetFuncKeyState).WillRepeatedly(testing::Return(1)); EXPECT_NO_FATAL_FAILURE(KeyEventHdr->ResetKeyEvent(&libDev)); +#ifdef OHOS_BUILD_ENABLE_VKEYBOARD // keyEvent unchanged: 0, 1, 0 EXPECT_EQ(KeyEventHdr->keyEvent_->GetFunctionKey(KeyEvent::NUM_LOCK_FUNCTION_KEY), false); EXPECT_EQ(KeyEventHdr->keyEvent_->GetFunctionKey(KeyEvent::CAPS_LOCK_FUNCTION_KEY), true); EXPECT_EQ(KeyEventHdr->keyEvent_->GetFunctionKey(KeyEvent::SCROLL_LOCK_FUNCTION_KEY), false); +#endif // OHOS_BUILD_ENABLE_VKEYBOARD } /** -- Gitee From 83a363e05cee5b0385e8b451da7774d57cd9c057 Mon Sep 17 00:00:00 2001 From: Zhen Li Date: Mon, 14 Jul 2025 23:42:59 -0400 Subject: [PATCH 09/11] sync keyboard caps Signed-off-by: Zhen Li --- test/facility/libinput_interface/include/libinput.h | 1 + 1 file changed, 1 insertion(+) diff --git a/test/facility/libinput_interface/include/libinput.h b/test/facility/libinput_interface/include/libinput.h index 225130143e..f1a9da8654 100644 --- a/test/facility/libinput_interface/include/libinput.h +++ b/test/facility/libinput_interface/include/libinput.h @@ -60,6 +60,7 @@ struct libinput_event_joystick_axis_abs_info { enum libinput_event_type { LIBINPUT_EVENT_NONE = 0, + LIBINPUT_EVENT_DEVICE_ADDED, LIBINPUT_EVENT_KEYBOARD_KEY = 300, -- Gitee From f26f6fd853cadd15583c94eea6f4516747cd32bf Mon Sep 17 00:00:00 2001 From: Zhen Li Date: Thu, 17 Jul 2025 09:50:59 -0400 Subject: [PATCH 10/11] sync keyboard caps, fix logs Signed-off-by: Zhen Li --- service/key_event_normalize/src/key_event_normalize.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/key_event_normalize/src/key_event_normalize.cpp b/service/key_event_normalize/src/key_event_normalize.cpp index 5a7a63ce54..8ff0d03f2b 100644 --- a/service/key_event_normalize/src/key_event_normalize.cpp +++ b/service/key_event_normalize/src/key_event_normalize.cpp @@ -17,6 +17,7 @@ #include #include +#include "libinput_adapter.h" #include "display_manager.h" #include "key_map_manager.h" #include "key_command_handler_util.h" @@ -191,7 +192,6 @@ void KeyEventNormalize::ResetKeyEvent(struct libinput_device* device) } } else { // otherwise, set this new device's function key state based on the key event. - MMI_HILOGI("Reset new added device's led based on the key event"); for (const auto &funcKey : funcKeys) { LibinputAdapter::DeviceLedUpdate(device, funcKey, keyEvent_->GetFunctionKey(funcKey)); } -- Gitee From 14ed56a28db46e92d1d812edcb4e82c602c6fa2d Mon Sep 17 00:00:00 2001 From: Zhen Li Date: Thu, 17 Jul 2025 10:11:19 -0400 Subject: [PATCH 11/11] sync keyboard caps, fix logs Signed-off-by: Zhen Li --- service/key_event_normalize/src/key_event_normalize.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/service/key_event_normalize/src/key_event_normalize.cpp b/service/key_event_normalize/src/key_event_normalize.cpp index 8ff0d03f2b..ffe931e791 100644 --- a/service/key_event_normalize/src/key_event_normalize.cpp +++ b/service/key_event_normalize/src/key_event_normalize.cpp @@ -17,7 +17,6 @@ #include #include -#include "libinput_adapter.h" #include "display_manager.h" #include "key_map_manager.h" #include "key_command_handler_util.h" -- Gitee