diff options
author | Johan Klokkhammer Helsing <johan.helsing@theqtcompany.com> | 2016-03-16 17:48:41 +0100 |
---|---|---|
committer | Johan Helsing <johan.helsing@theqtcompany.com> | 2016-03-18 09:21:28 +0000 |
commit | 2aac4c81eac8bb2c35362fce04cd2212edfe31e1 (patch) | |
tree | 7ec8f18640515cf437cafe93de6da6e096ad3ef4 | |
parent | 47202ee55978d12e27efb0e3ebbe841fb1af043f (diff) |
Encapsulate conversion from scancodes to Waylands xkb_v1 keymap format
Change-Id: Id2126e6e0e37d0cd64c4dc8476b97e8d0d16b24b
Reviewed-by: Giulio Camuffo <giulio.camuffo@kdab.com>
-rw-r--r-- | src/compositor/compositor_api/qwaylandkeyboard.cpp | 17 | ||||
-rw-r--r-- | src/compositor/compositor_api/qwaylandkeyboard_p.h | 1 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/compositor/compositor_api/qwaylandkeyboard.cpp b/src/compositor/compositor_api/qwaylandkeyboard.cpp index f39bb3e04..65d31fb33 100644 --- a/src/compositor/compositor_api/qwaylandkeyboard.cpp +++ b/src/compositor/compositor_api/qwaylandkeyboard.cpp @@ -174,15 +174,11 @@ void QWaylandKeyboardPrivate::keyboard_release(wl_keyboard::Resource *resource) void QWaylandKeyboardPrivate::keyEvent(uint code, uint32_t state) { - uint key = code - 8; + uint key = toWaylandXkbV1Key(code); if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { keys << key; } else { - for (int i = 0; i < keys.size(); ++i) { - if (keys.at(i) == key) { - keys.remove(i); - } - } + keys.removeAll(key); } } @@ -190,7 +186,7 @@ void QWaylandKeyboardPrivate::sendKeyEvent(uint code, uint32_t state) { uint32_t time = compositor()->currentTimeMsecs(); uint32_t serial = compositor()->nextSerial(); - uint key = code - 8; + uint key = toWaylandXkbV1Key(code); if (focusResource) send_key(focusResource->handle, serial, time, key, state); } @@ -338,6 +334,13 @@ void QWaylandKeyboardPrivate::createXKBState(xkb_keymap *keymap) xkb_state = xkb_state_new(keymap); } +uint QWaylandKeyboardPrivate::toWaylandXkbV1Key(const uint nativeScanCode) +{ + const uint offset = 8; + Q_ASSERT(nativeScanCode >= offset); + return nativeScanCode - offset; +} + void QWaylandKeyboardPrivate::createXKBKeymap() { if (!xkb_context) diff --git a/src/compositor/compositor_api/qwaylandkeyboard_p.h b/src/compositor/compositor_api/qwaylandkeyboard_p.h index 8c61a5bf7..fe0b30dd7 100644 --- a/src/compositor/compositor_api/qwaylandkeyboard_p.h +++ b/src/compositor/compositor_api/qwaylandkeyboard_p.h @@ -107,6 +107,7 @@ private: void createXKBKeymap(); void createXKBState(xkb_keymap *keymap); #endif + static uint toWaylandXkbV1Key(const uint nativeScanCode); QWaylandInputDevice *seat; |