summaryrefslogtreecommitdiffstats
path: root/src/compositor/compositor_api/qwaylandkeyboard.cpp
diff options
context:
space:
mode:
authorGatis Paeglis <gatis.paeglis@qt.io>2019-01-16 14:42:50 +0100
committerGatis Paeglis <gatis.paeglis@qt.io>2019-04-17 06:28:58 +0000
commit35880c7e1021a379e3cdd4005edd53472b63856c (patch)
tree884a9f8839c712c1be44a080cf3844267bf5176b /src/compositor/compositor_api/qwaylandkeyboard.cpp
parent458bc86f82f8fa6cfd659950549d1d2b36e5e40d (diff)
rework key handling
- Document the magical 8 keycode offset in QKeyEvent::nativeScanCode() - Check if we are working with the expected keymap format. - Rename sendKey() to handleKey() as that is typical naming convention for events that are passed to QWindowSystemInterface. - WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP is in the bundled xml so use it in send_keymap() - Rename toWaylandXkbV1Key() to toWaylandKey() as previous name was incorrect. - Remove "Generic fallback" in keyboard_key() as it was non-functional, you can't expect any useful output when mapping scan code directly to Qt::Key. It was not working in 5.9 (did not check beyond that) and no one has complained. It is safe to assume that the fallback code path is dead and can be dropped. To use HW keyboard with wayland, you need to build with libxkbcommon. We require this on XCB since Qt 5.1.0, so it is not an unreasonable requirement for Wayland. - Cleanup auto-repeat key handling. - Cleanup "#if QT_CONFIG(xkbcommon)" checks. Change-Id: Ie9fcc628621487fb58bc55dd595bf0d51eedfc92 Reviewed-by: Johan Helsing <johan.helsing@qt.io>
Diffstat (limited to 'src/compositor/compositor_api/qwaylandkeyboard.cpp')
-rw-r--r--src/compositor/compositor_api/qwaylandkeyboard.cpp40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/compositor/compositor_api/qwaylandkeyboard.cpp b/src/compositor/compositor_api/qwaylandkeyboard.cpp
index e84eed64a..f66fe3263 100644
--- a/src/compositor/compositor_api/qwaylandkeyboard.cpp
+++ b/src/compositor/compositor_api/qwaylandkeyboard.cpp
@@ -143,7 +143,7 @@ void QWaylandKeyboardPrivate::keyboard_bind_resource(wl_keyboard::Resource *reso
#endif
{
int null_fd = open("/dev/null", O_RDONLY);
- send_keymap(resource->handle, 0 /* WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP */,
+ send_keymap(resource->handle, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP,
null_fd, 0);
close(null_fd);
}
@@ -163,11 +163,8 @@ void QWaylandKeyboardPrivate::keyboard_release(wl_keyboard::Resource *resource)
void QWaylandKeyboardPrivate::keyEvent(uint code, uint32_t state)
{
-#if QT_CONFIG(xkbcommon)
- uint key = toWaylandXkbV1Key(code);
-#else
- uint key = code;
-#endif
+ uint key = toWaylandKey(code);
+
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
keys << key;
} else {
@@ -179,11 +176,7 @@ void QWaylandKeyboardPrivate::sendKeyEvent(uint code, uint32_t state)
{
uint32_t time = compositor()->currentTimeMsecs();
uint32_t serial = compositor()->nextSerial();
-#if QT_CONFIG(xkbcommon)
- uint key = toWaylandXkbV1Key(code);
-#else
- uint key = code;
-#endif
+ uint key = toWaylandKey(code);
if (focusResource)
send_key(focusResource->handle, serial, time, key, state);
}
@@ -284,6 +277,24 @@ void QWaylandKeyboardPrivate::maybeUpdateKeymap()
#endif
}
+uint QWaylandKeyboardPrivate::toWaylandKey(const uint nativeScanCode)
+{
+#if QT_CONFIG(xkbcommon)
+ // In all current XKB keymaps there's a constant offset of 8 (for historical
+ // reasons) from hardware/evdev scancodes to XKB keycodes. On X11, we pass
+ // XKB keycodes (as sent by X server) via QKeyEvent::nativeScanCode. eglfs+evdev
+ // adds 8 for consistency, see qtbase/05c07c7636012ebb4131ca099ca4ea093af76410.
+ // eglfs+libinput also adds 8, for the same reason. Wayland protocol uses
+ // hardware/evdev scancodes, thus we need to minus 8 before sending the event
+ // out.
+ const uint offset = 8;
+ Q_ASSERT(nativeScanCode >= offset);
+ return nativeScanCode - offset;
+#else
+ return nativeScanCode;
+#endif
+}
+
#if QT_CONFIG(xkbcommon)
static int createAnonymousFile(size_t size)
{
@@ -348,13 +359,6 @@ void QWaylandKeyboardPrivate::createXKBState(xkb_keymap *keymap)
qWarning("Failed to create XKB state");
}
-uint QWaylandKeyboardPrivate::toWaylandXkbV1Key(const uint nativeScanCode)
-{
- const uint offset = 8;
- Q_ASSERT(nativeScanCode >= offset);
- return nativeScanCode - offset;
-}
-
void QWaylandKeyboardPrivate::createXKBKeymap()
{
if (!xkbContext())