update key state on key events to have mods working in drm

This commit is contained in:
Vaxry 2024-06-25 18:31:45 +02:00
parent c49ab9e9f3
commit 9ad03ed231
2 changed files with 10 additions and 2 deletions

View file

@ -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
};

View file

@ -1,5 +1,6 @@
#include "Keyboard.hpp"
#include "../defines.hpp"
#include "../Compositor.hpp"
#include <aquamarine/input/Input.hpp>
@ -31,6 +32,13 @@ CKeyboard::CKeyboard(SP<Aquamarine::IKeyboard> keeb) : keyboard(keeb) {
listeners.key = keeb->events.key.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::IKeyboard::SKeyEvent>(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,
.keycode = E.key,