plugins/stickykeys: Unlatch modifiers when locking

The state should be either latched or locked, not both
This commit is contained in:
Nicolas Fella 2024-07-16 15:48:16 +02:00
parent 85b5048e72
commit 19bf66c42a
3 changed files with 4 additions and 2 deletions

View file

@ -191,7 +191,7 @@ void StickyKeysTest::testLock()
Test::keyboardKeyPressed(modifierKey, ++timestamp);
QVERIFY(modifierSpy.wait());
QCOMPARE(modifierSpy.first()[0], expectedMods); // verify that mod is depressed
// TODO should it be latched?
QCOMPARE(modifierSpy.first()[1], 0); // verify that mod is unlatched
QCOMPARE(modifierSpy.first()[2], expectedMods); // verify that mod is locked
// release mod, modifier should still be locked
@ -212,6 +212,7 @@ void StickyKeysTest::testLock()
Test::keyboardKeyPressed(modifierKey, ++timestamp);
QVERIFY(modifierSpy.wait());
QCOMPARE(modifierSpy.first()[0], expectedMods); // verify that mod is depressed
QCOMPARE(modifierSpy.first()[1], 0); // verify that mod is unlatched
QCOMPARE(modifierSpy.first()[2], 0); // verify that mod is not locked
Test::keyboardKeyReleased(modifierKey, ++timestamp);

View file

@ -108,6 +108,7 @@ bool StickyKeysFilter::keyEvent(KWin::KeyEvent *event)
// A latched modifier was pressed, lock it
else if (keyState.value() == Latched && m_lockKeys) {
keyState.value() = Locked;
KWin::input()->keyboard()->xkb()->setModifierLatched(keyToModifier(static_cast<Qt::Key>(event->key())), false);
KWin::input()->keyboard()->xkb()->setModifierLocked(keyToModifier(static_cast<Qt::Key>(event->key())), true);
if (m_showNotificationForLockedKeys) {

View file

@ -1086,7 +1086,7 @@ void Xkb::setModifierLocked(KWin::Xkb::Modifier mod, bool locked)
if (mask.size() > modifier) {
mask[modifier] = locked;
m_modifierState.locked = mask.to_ulong();
xkb_state_update_mask(m_state, m_modifierState.depressed, m_modifierState.locked, m_modifierState.locked, 0, 0, m_currentLayout);
xkb_state_update_mask(m_state, m_modifierState.depressed, m_modifierState.latched, m_modifierState.locked, 0, 0, m_currentLayout);
m_modifierState.locked = xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_LOCKED));
}
}