diff --git a/autotests/integration/globalshortcuts_test.cpp b/autotests/integration/globalshortcuts_test.cpp --- a/autotests/integration/globalshortcuts_test.cpp +++ b/autotests/integration/globalshortcuts_test.cpp @@ -133,7 +133,6 @@ QVERIFY(triggeredSpy.wait()); // now release the key kwinApp()->platform()->keyboardKeyReleased(KEY_5, timestamp++); - QEXPECT_FAIL("", "BUG 369091", Continue); QVERIFY(!triggeredSpy.wait(500)); kwinApp()->platform()->keyboardKeyReleased(KEY_WAKEUP, timestamp++); diff --git a/keyboard_input.h b/keyboard_input.h --- a/keyboard_input.h +++ b/keyboard_input.h @@ -140,8 +140,12 @@ InputRedirection *m_input; bool m_inited = false; QScopedPointer m_xkb; - QHash m_repeatTimers; QMetaObject::Connection m_activeClientSurfaceChangedConnection; + struct { + quint32 key = 0; + quint32 time = 0; + QTimer *timer = nullptr; + } m_keyRepeat; }; inline diff --git a/keyboard_input.cpp b/keyboard_input.cpp --- a/keyboard_input.cpp +++ b/keyboard_input.cpp @@ -463,17 +463,25 @@ { } -KeyboardInputRedirection::~KeyboardInputRedirection() -{ - qDeleteAll(m_repeatTimers); - m_repeatTimers.clear(); -} +KeyboardInputRedirection::~KeyboardInputRedirection() = default; void KeyboardInputRedirection::init() { Q_ASSERT(!m_inited); m_inited = true; + // setup key repeat + m_keyRepeat.timer = new QTimer(this); + connect(m_keyRepeat.timer, &QTimer::timeout, this, + [this] { + if (waylandServer()->seat()->keyRepeatRate() != 0) { + m_keyRepeat.timer->setInterval(1000 / waylandServer()->seat()->keyRepeatRate()); + } + // TODO: better time + processKey(m_keyRepeat.key, InputRedirection::KeyboardKeyAutoRepeat, m_keyRepeat.time); + } + ); + connect(workspace(), &QObject::destroyed, this, [this] { m_inited = false; }); connect(waylandServer(), &QObject::destroyed, this, [this] { m_inited = false; }); connect(workspace(), &Workspace::clientActivated, this, @@ -615,26 +623,14 @@ device); if (state == InputRedirection::KeyboardKeyPressed) { if (m_xkb->shouldKeyRepeat(key) && waylandServer()->seat()->keyRepeatDelay() != 0) { - QTimer *timer = new QTimer; - timer->setInterval(waylandServer()->seat()->keyRepeatDelay()); - connect(timer, &QTimer::timeout, this, - [this, timer, time, key] { - const int delay = 1000 / waylandServer()->seat()->keyRepeatRate(); - if (timer->interval() != delay) { - timer->setInterval(delay); - } - // TODO: better time - processKey(key, InputRedirection::KeyboardKeyAutoRepeat, time); - } - ); - m_repeatTimers.insert(key, timer); - timer->start(); + m_keyRepeat.timer->setInterval(waylandServer()->seat()->keyRepeatDelay()); + m_keyRepeat.key = key; + m_keyRepeat.time = time; + m_keyRepeat.timer->start(); } } else if (state == InputRedirection::KeyboardKeyReleased) { - auto it = m_repeatTimers.find(key); - if (it != m_repeatTimers.end()) { - delete it.value(); - m_repeatTimers.erase(it); + if (key == m_keyRepeat.key) { + m_keyRepeat.timer->stop(); } }