From 9ad03ed23147d886b9124a119115cf73d0c68041 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 25 Jun 2024 18:31:45 +0200 Subject: [PATCH] update key state on key events to have mods working in drm --- src/devices/IKeyboard.hpp | 2 +- src/devices/Keyboard.cpp | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/devices/IKeyboard.hpp b/src/devices/IKeyboard.hpp index fec85606..f1f355ec 100644 --- a/src/devices/IKeyboard.hpp +++ b/src/devices/IKeyboard.hpp @@ -57,6 +57,7 @@ class IKeyboard : public IHID { void updateLEDs(uint32_t leds); uint32_t getModifiers(); void updateModifiers(uint32_t depressed, uint32_t latched, uint32_t locked, uint32_t group); + bool updateModifiersState(); // rets whether changed bool active = false; bool enabled = true; @@ -88,5 +89,4 @@ class IKeyboard : public IHID { private: void clearManuallyAllocd(); - bool updateModifiersState(); // rets whether changed }; diff --git a/src/devices/Keyboard.cpp b/src/devices/Keyboard.cpp index 514bef2b..56ec7bfb 100644 --- a/src/devices/Keyboard.cpp +++ b/src/devices/Keyboard.cpp @@ -1,5 +1,6 @@ #include "Keyboard.hpp" #include "../defines.hpp" +#include "../Compositor.hpp" #include @@ -29,7 +30,14 @@ CKeyboard::CKeyboard(SP keeb) : keyboard(keeb) { }); listeners.key = keeb->events.key.registerListener([this](std::any d) { - auto E = std::any_cast(d); + auto E = std::any_cast(d); + + uint32_t xkbKeycode = E.key + 8; + xkb_state_update_key(xkbTranslationState, xkbKeycode, E.pressed ? XKB_KEY_DOWN : XKB_KEY_UP); + + // we have to do this for DRM sessions, as they never send modifiers events + if (g_pCompositor->m_pAqBackend->hasSession()) + updateModifiersState(); keyboardEvents.key.emit(SKeyEvent{ .timeMs = E.timeMs,