From 12c2a2e0c99dffb0c4f6492c14ef90a8b50f615c Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 1 Oct 2024 19:28:24 +0000 Subject: [PATCH] Drop superAsMeta workaround in Xkb::toQtKey The issue was fixed upstream. Technically, it also introduces a new behavior: super keys are interpreted as meta keys now by default. It matches what qtwayland does and, in general, Qt controls handle super keys very poorly. Wayland clients still receive native scan codes, they are not affected by these changes. (cherry picked from commit 805414c071a9ed1531604df85a0684eaafa7f663) Co-authored-by: Vlad Zahorodnii --- autotests/test_xkb.cpp | 6 ++++-- src/input.cpp | 11 +---------- src/xkb.cpp | 10 +++------- src/xkb.h | 3 +-- 4 files changed, 9 insertions(+), 21 deletions(-) diff --git a/autotests/test_xkb.cpp b/autotests/test_xkb.cpp index bbc59259d7..7ab2da3807 100644 --- a/autotests/test_xkb.cpp +++ b/autotests/test_xkb.cpp @@ -89,8 +89,8 @@ static const TransKey g_rgQtToSymX[] = { {XKB_KEY_F33, Qt::Key_F33, Qt::KeyboardModifiers()}, {XKB_KEY_F34, Qt::Key_F34, Qt::KeyboardModifiers()}, {XKB_KEY_F35, Qt::Key_F35, Qt::KeyboardModifiers()}, - {XKB_KEY_Super_L, Qt::Key_Super_L, Qt::KeyboardModifiers()}, - {XKB_KEY_Super_R, Qt::Key_Super_R, Qt::KeyboardModifiers()}, + {XKB_KEY_Super_L, Qt::Key_Meta, Qt::KeyboardModifiers()}, + {XKB_KEY_Super_R, Qt::Key_Meta, Qt::KeyboardModifiers()}, {XKB_KEY_Menu, Qt::Key_Menu, Qt::KeyboardModifiers()}, {XKB_KEY_Hyper_L, Qt::Key_Meta, Qt::KeyboardModifiers()}, {XKB_KEY_Hyper_R, Qt::Key_Meta, Qt::KeyboardModifiers()}, @@ -517,6 +517,8 @@ void XkbTest::testFromQtKey() QFETCH(int, keyQt); QList keys = xkb.keysymsFromQtKey(keyQt); + QEXPECT_FAIL(QByteArray::number(XKB_KEY_Super_L, 16), "keysymsFromQtKey doesn't map super to meta", Continue); + QEXPECT_FAIL(QByteArray::number(XKB_KEY_Super_R, 16), "keysymsFromQtKey doesn't map super to meta", Continue); QEXPECT_FAIL(QByteArray::number(XKB_KEY_Hyper_L, 16), "keysymsFromQtKey doesn't map hyper to meta", Continue); QEXPECT_FAIL(QByteArray::number(XKB_KEY_Hyper_R, 16), "keysymsFromQtKey doesn't map hyper to meta", Continue); #if QT_VERSION < QT_VERSION_CHECK(6, 7, 1) diff --git a/src/input.cpp b/src/input.cpp index 243905f1af..c01a06e102 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1283,16 +1283,7 @@ public: if (!found) { return false; } - auto xkb = input()->keyboard()->xkb(); - Qt::Key key = xkb->toQtKey(xkb->toKeysym(event->nativeScanCode()), - event->nativeScanCode(), - Qt::KeyboardModifiers(), - true /* workaround for QTBUG-62102 */); - QKeyEvent internalEvent(event->type(), key, - event->modifiers(), event->nativeScanCode(), event->nativeVirtualKey(), - event->nativeModifiers(), event->text()); - internalEvent.setAccepted(false); - if (QCoreApplication::sendEvent(found, &internalEvent)) { + if (QCoreApplication::sendEvent(found, event)) { waylandServer()->seat()->setFocusedKeyboardSurface(nullptr); passToWaylandServer(event); return true; diff --git a/src/xkb.cpp b/src/xkb.cpp index 545fa0b31f..750ba6dabe 100644 --- a/src/xkb.cpp +++ b/src/xkb.cpp @@ -944,17 +944,13 @@ QString Xkb::toString(xkb_keysym_t keysym) Qt::Key Xkb::toQtKey(xkb_keysym_t keySym, uint32_t scanCode, - Qt::KeyboardModifiers modifiers, - bool superAsMeta) const + Qt::KeyboardModifiers modifiers) const { // FIXME: passing superAsMeta doesn't have impact due to bug in the Qt function, so handle it below - Qt::Key qtKey = Qt::Key(QXkbCommon::keysymToQtKey(keySym, modifiers, m_state, scanCode + EVDEV_OFFSET, superAsMeta)); + Qt::Key qtKey = Qt::Key(QXkbCommon::keysymToQtKey(keySym, modifiers, m_state, scanCode + EVDEV_OFFSET)); // FIXME: workarounds for symbols currently wrong/not mappable via keysymToQtKey() - if (superAsMeta && (qtKey == Qt::Key_Super_L || qtKey == Qt::Key_Super_R)) { - // translate Super/Hyper keys to Meta if we're using them as the MetaModifier - qtKey = Qt::Key_Meta; - } else if (qtKey > 0xff && keySym <= 0xff) { + if (qtKey > 0xff && keySym <= 0xff) { // XKB_KEY_mu, XKB_KEY_ydiaeresis go here qtKey = Qt::Key(keySym); } diff --git a/src/xkb.h b/src/xkb.h index 4cb7ac6f7d..c41e205338 100644 --- a/src/xkb.h +++ b/src/xkb.h @@ -66,8 +66,7 @@ public: QString toString(xkb_keysym_t keysym); Qt::Key toQtKey(xkb_keysym_t keysym, uint32_t scanCode = 0, - Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers(), - bool superAsMeta = false) const; + Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers()) const; Qt::KeyboardModifiers modifiers() const; Qt::KeyboardModifiers modifiersRelevantForGlobalShortcuts(uint32_t scanCode = 0) const; bool shouldKeyRepeat(quint32 key) const;