diff --git a/src/core/platforms/WaylandPlatform.cpp b/src/core/platforms/WaylandPlatform.cpp index d6ad3a0..b8d6ef4 100644 --- a/src/core/platforms/WaylandPlatform.cpp +++ b/src/core/platforms/WaylandPlatform.cpp @@ -675,7 +675,8 @@ void CWaylandPlatform::onKey(uint32_t keycode, bool state) { if (state) { const auto SYM = xkb_state_key_get_one_sym(m_waylandState.seatState.xkbState, keycode + 8); - if (SYM == XKB_KEY_Left || SYM == XKB_KEY_Right || SYM == XKB_KEY_Up || SYM == XKB_KEY_Down) { + if (SYM == XKB_KEY_Left || SYM == XKB_KEY_Right || SYM == XKB_KEY_Up || SYM == XKB_KEY_Down || SYM == XKB_KEY_Home || SYM == XKB_KEY_End || SYM == XKB_KEY_KP_Home || + SYM == XKB_KEY_KP_End) { // skip compose e.xkbKeysym = SYM; m_keyboardWindow->keyboardKey(e); diff --git a/tests/unit/core/WaylandPlatform.cpp b/tests/unit/core/WaylandPlatform.cpp index 15b87e5..d147700 100644 --- a/tests/unit/core/WaylandPlatform.cpp +++ b/tests/unit/core/WaylandPlatform.cpp @@ -3,10 +3,65 @@ #include #include +#include +#include #include +#include "../tricks/Tricks.hpp" + using namespace Hyprtoolkit; +TEST(WaylandPlatform, homeEndReachTextbox) { + Tests::Tricks::createBackendSupport(); + + CWaylandPlatform platform; + auto& seat = platform.m_waylandState.seatState; + seat.repeatRate = 0; + seat.xkbContext = xkb_context_new(XKB_CONTEXT_NO_FLAGS); + ASSERT_NE(seat.xkbContext, nullptr); + + const xkb_rule_names names = {.layout = "us"}; + seat.xkbKeymap = xkb_keymap_new_from_names(seat.xkbContext, &names, XKB_KEYMAP_COMPILE_NO_FLAGS); + ASSERT_NE(seat.xkbKeymap, nullptr); + seat.xkbState = xkb_state_new(seat.xkbKeymap); + ASSERT_NE(seat.xkbState, nullptr); + + auto window = makeShared(SWindowCreationData{}); + + const auto TEXT_CONTENT = "should not change"; + + auto textbox = CTextboxBuilder::begin()->defaultText(TEXT_CONTENT)->multiline(false)->commence(); + window->m_keyboardFocus = textbox; + platform.m_keyboardWindow = window; + + size_t keyPresses = 0; + window->m_events.keyboardKey.listenStatic([&](Input::SKeyboardKeyEvent e) { + if (!e.down) + return; + ++keyPresses; + EXPECT_TRUE(e.utf8.empty()); + }); + + const std::array keys = {"END", "HOME", "KP1", "KP7"}; + for (size_t i = 0; i < keys.size(); ++i) { + SCOPED_TRACE(keys[i]); + const auto keycode = xkb_keymap_key_by_name(seat.xkbKeymap, keys[i]); + ASSERT_NE(keycode, XKB_KEYCODE_INVALID); + + const int XKB_WAYLAND_KEYCODE_DIFF = 8; + + platform.onKey(keycode - XKB_WAYLAND_KEYCODE_DIFF, true); + EXPECT_EQ(keyPresses, i + 1); + // The test alternates between END and HOME + const auto expectedPosition = i % 2 == 0 ? textbox->currentText().size() : 0; + EXPECT_EQ(textbox->cursorPos(), expectedPosition); + EXPECT_EQ(seat.repeatKeyEvent.xkbKeysym, xkb_state_key_get_one_sym(seat.xkbState, keycode)); + EXPECT_EQ(textbox->currentText(), TEXT_CONTENT); + platform.onKey(keycode - XKB_WAYLAND_KEYCODE_DIFF, false); + EXPECT_TRUE(seat.pressedKeys.empty()); + } +} + TEST(WaylandPlatform, keyboardEnterReplacesPressedKeys) { CWaylandPlatform platform; @@ -16,9 +71,9 @@ TEST(WaylandPlatform, keyboardEnterReplacesPressedKeys) { std::array keysData = {28, 42}; wl_array keys = { - .size = keysData.size() * sizeof(uint32_t), - .alloc = keysData.size() * sizeof(uint32_t), - .data = keysData.data(), + .size = keysData.size() * sizeof(uint32_t), + .alloc = keysData.size() * sizeof(uint32_t), + .data = keysData.data(), }; platform.onKeyboardEnter(nullptr, &keys);