From ccde653ac2ee1497853af5d9d260562746abc147 Mon Sep 17 00:00:00 2001 From: David Redondo Date: Thu, 18 Jul 2024 10:17:31 +0000 Subject: [PATCH] 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. --- src/plugins/eis/eiscontext.cpp | 18 ++++++++++++++---- src/plugins/eis/eisdevice.h | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/plugins/eis/eiscontext.cpp b/src/plugins/eis/eiscontext.cpp index 51b33670b7..577fe8b050 100644 --- a/src/plugins/eis/eiscontext.cpp +++ b/src/plugins/eis/eiscontext.cpp @@ -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; diff --git a/src/plugins/eis/eisdevice.h b/src/plugins/eis/eisdevice.h index ed24f90a88..d51f6e06b6 100644 --- a/src/plugins/eis/eisdevice.h +++ b/src/plugins/eis/eisdevice.h @@ -26,8 +26,8 @@ public: } void changeDevice(eis_device *device); - std::vector pressedButtons; - std::vector pressedKeys; + QSet pressedButtons; + QSet pressedKeys; std::vector activeTouches; QString sysName() const override;