plugins/eis: Ignore duplicate key and buttons events

Some clients (like xdotool) can send multiple events for the same
key. In some instances the number of presses and releases can even
be mismatched leading to stuck keys. While we clean up pressed keys
when the client vanishes, this doesnt help when it doesnt immediately
disconnect (for example Xwayland keeps client connections live
longer than the actual x client to reuse them).
Also fixes a copy paste mistake where key presses where also written
to buttons.
This commit is contained in:
David Redondo 2024-07-18 10:17:31 +00:00
parent 6ca6308ccd
commit ccde653ac2
2 changed files with 16 additions and 6 deletions

View file

@ -231,9 +231,14 @@ void EisContext::handleEvents()
const bool press = eis_event_button_get_is_press(event);
qCDebug(KWIN_EIS) << device->name() << "button" << button << press;
if (press) {
device->pressedButtons.push_back(button);
if (device->pressedButtons.contains(button)) {
continue;
}
device->pressedButtons.insert(button);
} else {
std::erase(device->pressedButtons, button);
if (!device->pressedButtons.remove(button)) {
continue;
}
}
Q_EMIT device->pointerButtonChanged(button, press ? InputRedirection::PointerButtonPressed : InputRedirection::PointerButtonReleased, currentTime(), device);
break;
@ -285,9 +290,14 @@ void EisContext::handleEvents()
const bool press = eis_event_keyboard_get_key_is_press(event);
qCDebug(KWIN_EIS) << device->name() << "key" << key << press;
if (press) {
device->pressedButtons.push_back(key);
if (device->pressedKeys.contains(key)) {
continue;
}
device->pressedKeys.insert(key);
} else {
std::erase(device->pressedButtons, key);
if (!device->pressedKeys.remove(key)) {
continue;
}
}
Q_EMIT device->keyChanged(key, press ? InputRedirection::KeyboardKeyPressed : InputRedirection::KeyboardKeyReleased, currentTime(), device);
break;

View file

@ -26,8 +26,8 @@ public:
}
void changeDevice(eis_device *device);
std::vector<quint32> pressedButtons;
std::vector<quint32> pressedKeys;
QSet<quint32> pressedButtons;
QSet<quint32> pressedKeys;
std::vector<int> activeTouches;
QString sysName() const override;