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 805414c071)

Co-authored-by: Vlad Zahorodnii <vlad.zahorodnii@kde.org>
wilder/Plasma/6.2
Vlad Zahorodnii 1 year ago
parent 5bf03f25a4
commit 12c2a2e0c9
  1. 6
      autotests/test_xkb.cpp
  2. 11
      src/input.cpp
  3. 10
      src/xkb.cpp
  4. 3
      src/xkb.h

@ -89,8 +89,8 @@ static const TransKey g_rgQtToSymX[] = {
{XKB_KEY_F33, Qt::Key_F33, Qt::KeyboardModifiers()}, {XKB_KEY_F33, Qt::Key_F33, Qt::KeyboardModifiers()},
{XKB_KEY_F34, Qt::Key_F34, Qt::KeyboardModifiers()}, {XKB_KEY_F34, Qt::Key_F34, Qt::KeyboardModifiers()},
{XKB_KEY_F35, Qt::Key_F35, Qt::KeyboardModifiers()}, {XKB_KEY_F35, Qt::Key_F35, Qt::KeyboardModifiers()},
{XKB_KEY_Super_L, Qt::Key_Super_L, Qt::KeyboardModifiers()}, {XKB_KEY_Super_L, Qt::Key_Meta, Qt::KeyboardModifiers()},
{XKB_KEY_Super_R, Qt::Key_Super_R, Qt::KeyboardModifiers()}, {XKB_KEY_Super_R, Qt::Key_Meta, Qt::KeyboardModifiers()},
{XKB_KEY_Menu, Qt::Key_Menu, Qt::KeyboardModifiers()}, {XKB_KEY_Menu, Qt::Key_Menu, Qt::KeyboardModifiers()},
{XKB_KEY_Hyper_L, Qt::Key_Meta, Qt::KeyboardModifiers()}, {XKB_KEY_Hyper_L, Qt::Key_Meta, Qt::KeyboardModifiers()},
{XKB_KEY_Hyper_R, Qt::Key_Meta, Qt::KeyboardModifiers()}, {XKB_KEY_Hyper_R, Qt::Key_Meta, Qt::KeyboardModifiers()},
@ -517,6 +517,8 @@ void XkbTest::testFromQtKey()
QFETCH(int, keyQt); QFETCH(int, keyQt);
QList<xkb_keysym_t> keys = xkb.keysymsFromQtKey(keyQt); QList<xkb_keysym_t> 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_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); 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) #if QT_VERSION < QT_VERSION_CHECK(6, 7, 1)

@ -1283,16 +1283,7 @@ public:
if (!found) { if (!found) {
return false; return false;
} }
auto xkb = input()->keyboard()->xkb(); if (QCoreApplication::sendEvent(found, event)) {
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)) {
waylandServer()->seat()->setFocusedKeyboardSurface(nullptr); waylandServer()->seat()->setFocusedKeyboardSurface(nullptr);
passToWaylandServer(event); passToWaylandServer(event);
return true; return true;

@ -944,17 +944,13 @@ QString Xkb::toString(xkb_keysym_t keysym)
Qt::Key Xkb::toQtKey(xkb_keysym_t keySym, Qt::Key Xkb::toQtKey(xkb_keysym_t keySym,
uint32_t scanCode, uint32_t scanCode,
Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers modifiers) const
bool superAsMeta) const
{ {
// FIXME: passing superAsMeta doesn't have impact due to bug in the Qt function, so handle it below // 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() // FIXME: workarounds for symbols currently wrong/not mappable via keysymToQtKey()
if (superAsMeta && (qtKey == Qt::Key_Super_L || qtKey == Qt::Key_Super_R)) { if (qtKey > 0xff && keySym <= 0xff) {
// translate Super/Hyper keys to Meta if we're using them as the MetaModifier
qtKey = Qt::Key_Meta;
} else if (qtKey > 0xff && keySym <= 0xff) {
// XKB_KEY_mu, XKB_KEY_ydiaeresis go here // XKB_KEY_mu, XKB_KEY_ydiaeresis go here
qtKey = Qt::Key(keySym); qtKey = Qt::Key(keySym);
} }

@ -66,8 +66,7 @@ public:
QString toString(xkb_keysym_t keysym); QString toString(xkb_keysym_t keysym);
Qt::Key toQtKey(xkb_keysym_t keysym, Qt::Key toQtKey(xkb_keysym_t keysym,
uint32_t scanCode = 0, uint32_t scanCode = 0,
Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers()) const;
bool superAsMeta = false) const;
Qt::KeyboardModifiers modifiers() const; Qt::KeyboardModifiers modifiers() const;
Qt::KeyboardModifiers modifiersRelevantForGlobalShortcuts(uint32_t scanCode = 0) const; Qt::KeyboardModifiers modifiersRelevantForGlobalShortcuts(uint32_t scanCode = 0) const;
bool shouldKeyRepeat(quint32 key) const; bool shouldKeyRepeat(quint32 key) const;

Loading…
Cancel
Save