summaryrefslogtreecommitdiffstats
path: root/src/compositor/compositor_api/qwaylandkeyboard.cpp
diff options
context:
space:
mode:
authorJohan Klokkhammer Helsing <johan.helsing@theqtcompany.com>2016-03-16 17:48:41 +0100
committerJohan Helsing <johan.helsing@theqtcompany.com>2016-03-18 09:21:28 +0000
commit2aac4c81eac8bb2c35362fce04cd2212edfe31e1 (patch)
tree7ec8f18640515cf437cafe93de6da6e096ad3ef4 /src/compositor/compositor_api/qwaylandkeyboard.cpp
parent47202ee55978d12e27efb0e3ebbe841fb1af043f (diff)
Encapsulate conversion from scancodes to Waylands xkb_v1 keymap format
Change-Id: Id2126e6e0e37d0cd64c4dc8476b97e8d0d16b24b Reviewed-by: Giulio Camuffo <giulio.camuffo@kdab.com>
Diffstat (limited to 'src/compositor/compositor_api/qwaylandkeyboard.cpp')
-rw-r--r--src/compositor/compositor_api/qwaylandkeyboard.cpp17
1 files changed, 10 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)