summaryrefslogtreecommitdiffstats
path: root/src/platformsupport
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-08-18 11:51:45 +0200
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-08-21 21:02:56 +0000
commitb409b1a0e423fe690f038ca0140830b13970fa4d (patch)
tree8a6270f182b91cbcb76e5776443a054c6894a0b1 /src/platformsupport
parent19e61ac2907fd453d629d270668139cd1da7e10b (diff)
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>
Diffstat (limited to 'src/platformsupport')
-rw-r--r--src/platformsupport/input/libinput/qlibinputkeyboard.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/platformsupport/input/libinput/qlibinputkeyboard.cpp b/src/platformsupport/input/libinput/qlibinputkeyboard.cpp
index 3bb9107e16..ec7ea7ef0d 100644
--- a/src/platformsupport/input/libinput/qlibinputkeyboard.cpp
+++ b/src/platformsupport/input/libinput/qlibinputkeyboard.cpp
@@ -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);