libinput: Fix key mapping
Prevent generating 2 character long 'text' strings with some garbage as second char. This matches how xcb works. Change-Id: I88a248a89c80b0e100c1c4871cfab4f2c287535e Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>bb10
parent
19e61ac290
commit
b409b1a0e4
|
|
@ -180,10 +180,13 @@ void QLibInputKeyboard::processKey(libinput_event_keyboard *e)
|
|||
const uint32_t k = libinput_event_keyboard_get_key(e) + 8;
|
||||
const bool pressed = libinput_event_keyboard_get_key_state(e) == LIBINPUT_KEY_STATE_PRESSED;
|
||||
|
||||
QByteArray chars;
|
||||
chars.resize(1 + xkb_state_key_get_utf8(m_state, k, Q_NULLPTR, 0));
|
||||
xkb_state_key_get_utf8(m_state, k, chars.data(), chars.size());
|
||||
const QString text = QString::fromUtf8(chars);
|
||||
QVarLengthArray<char, 32> chars(32);
|
||||
const int size = xkb_state_key_get_utf8(m_state, k, chars.data(), chars.size());
|
||||
if (Q_UNLIKELY(size + 1 > chars.size())) { // +1 for NUL
|
||||
chars.resize(size + 1);
|
||||
xkb_state_key_get_utf8(m_state, k, chars.data(), chars.size());
|
||||
}
|
||||
const QString text = QString::fromUtf8(chars.constData(), size);
|
||||
|
||||
const xkb_keysym_t sym = xkb_state_key_get_one_sym(m_state, k);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue