Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/platforms/WaylandPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
61 changes: 58 additions & 3 deletions tests/unit/core/WaylandPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,65 @@
#include <array>

#include <core/platforms/WaylandPlatform.hpp>
#include <hyprtoolkit/element/Textbox.hpp>
#include <window/WaylandWindow.hpp>
#include <xkbcommon/xkbcommon-keysyms.h>

#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<CWaylandWindow>(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<const char*, 4> 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;

Expand All @@ -16,9 +71,9 @@ TEST(WaylandPlatform, keyboardEnterReplacesPressedKeys) {

std::array<uint32_t, 2> 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);
Expand Down
Loading