diff options
4 files changed, 53 insertions, 8 deletions
diff --git a/src/compositor/compositor_api/qwaylandcompositor.cpp b/src/compositor/compositor_api/qwaylandcompositor.cpp index 98a0bb7f..7b06a1c0 100644 --- a/src/compositor/compositor_api/qwaylandcompositor.cpp +++ b/src/compositor/compositor_api/qwaylandcompositor.cpp @@ -229,6 +229,11 @@ void QWaylandCompositorPrivate::init() QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::eventDispatcher; QObject::connect(dispatcher, SIGNAL(aboutToBlock()), q, SLOT(processWaylandEvents())); + QObject::connect(static_cast<QGuiApplication *>(QGuiApplication::instance()), + &QGuiApplication::applicationStateChanged, + q, + &QWaylandCompositor::applicationStateChanged); + initializeHardwareIntegration(); initializeSeats(); @@ -1101,6 +1106,17 @@ QVector<QWaylandCompositor::ShmFormat> QWaylandCompositor::additionalShmFormats( return d->shmFormats; } +void QWaylandCompositor::applicationStateChanged(Qt::ApplicationState state) +{ + if (state == Qt::ApplicationInactive) { + auto *seat = defaultSeat(); + if (seat != nullptr) { + QWaylandKeyboardPrivate *keyb = QWaylandKeyboardPrivate::get(seat->keyboard()); + keyb->resetKeyboardState(); + } + } +} + QT_END_NAMESPACE #include "moc_qwaylandcompositor.cpp" diff --git a/src/compositor/compositor_api/qwaylandcompositor.h b/src/compositor/compositor_api/qwaylandcompositor.h index 3be304df..54b45b4c 100644 --- a/src/compositor/compositor_api/qwaylandcompositor.h +++ b/src/compositor/compositor_api/qwaylandcompositor.h @@ -148,6 +148,9 @@ public: public Q_SLOTS: void processWaylandEvents(); +private Q_SLOTS: + void applicationStateChanged(Qt::ApplicationState state); + Q_SIGNALS: void createdChanged(); void socketNameChanged(const QByteArray &socketName); diff --git a/src/compositor/compositor_api/qwaylandkeyboard.cpp b/src/compositor/compositor_api/qwaylandkeyboard.cpp index 97cc3138..4baeaddb 100644 --- a/src/compositor/compositor_api/qwaylandkeyboard.cpp +++ b/src/compositor/compositor_api/qwaylandkeyboard.cpp @@ -202,6 +202,18 @@ void QWaylandKeyboardPrivate::maybeUpdateXkbScanCodeTable() } #endif +void QWaylandKeyboardPrivate::resetKeyboardState() +{ + if (!xkbContext()) + return; + + while (!keys.isEmpty()) { + uint32_t code = fromWaylandKey(keys.first()); + keyEvent(code, WL_KEYBOARD_KEY_STATE_RELEASED); + updateModifierState(code, WL_KEYBOARD_KEY_STATE_RELEASED); + } +} + void QWaylandKeyboardPrivate::updateModifierState(uint code, uint32_t state) { #if QT_CONFIG(xkbcommon) @@ -277,17 +289,29 @@ void QWaylandKeyboardPrivate::maybeUpdateKeymap() #endif } +// 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 subtract 8 before sending the event +// out and add it when mapping back. +#define QTWAYLANDKEYBOARD_XKB_HISTORICAL_OFFSET 8 + +uint QWaylandKeyboardPrivate::fromWaylandKey(const uint key) +{ +#if QT_CONFIG(xkbcommon) + const uint offset = QTWAYLANDKEYBOARD_XKB_HISTORICAL_OFFSET; + return key + offset; +#else + return key; +#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; + const uint offset = QTWAYLANDKEYBOARD_XKB_HISTORICAL_OFFSET; Q_ASSERT(nativeScanCode >= offset); return nativeScanCode - offset; #else diff --git a/src/compositor/compositor_api/qwaylandkeyboard_p.h b/src/compositor/compositor_api/qwaylandkeyboard_p.h index 942e4191..f9abb645 100644 --- a/src/compositor/compositor_api/qwaylandkeyboard_p.h +++ b/src/compositor/compositor_api/qwaylandkeyboard_p.h @@ -83,6 +83,7 @@ public: } uint32_t xkbModsMask() const { return modsDepressed | modsLatched | modsLocked; } void maybeUpdateXkbScanCodeTable(); + void resetKeyboardState(); #endif void keyEvent(uint code, uint32_t state); @@ -105,6 +106,7 @@ private: void createXKBState(xkb_keymap *keymap); #endif static uint toWaylandKey(const uint nativeScanCode); + static uint fromWaylandKey(const uint key); void sendRepeatInfo(); |