From 9b6ae4f77b95fef271c2e21abba5e05b4cc47719 Mon Sep 17 00:00:00 2001 From: Sungyoon Cho Date: Sun, 28 Jul 2024 19:46:38 +0900 Subject: [PATCH] input: fix keyboard leds with multiple keyboards (#7079) --- src/devices/IKeyboard.cpp | 15 ++++++++++++--- src/devices/IKeyboard.hpp | 26 ++++++++++++++------------ src/managers/input/InputManager.cpp | 9 ++++++++- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/devices/IKeyboard.cpp b/src/devices/IKeyboard.cpp index e3517bf1..e05cbd04 100644 --- a/src/devices/IKeyboard.cpp +++ b/src/devices/IKeyboard.cpp @@ -274,9 +274,9 @@ std::string IKeyboard::getActiveLayout() { return "none"; } -void IKeyboard::updateLEDs() { +std::optional IKeyboard::getLEDs() { if (xkbState == nullptr) - return; + return {}; uint32_t leds = 0; for (uint32_t i = 0; i < LED_COUNT; ++i) { @@ -284,7 +284,16 @@ void IKeyboard::updateLEDs() { leds |= (1 << i); } - updateLEDs(leds); + return leds; +} + +void IKeyboard::updateLEDs() { + std::optional leds = getLEDs(); + + if (!leds.has_value()) + return; + + updateLEDs(leds.value()); } void IKeyboard::updateLEDs(uint32_t leds) { diff --git a/src/devices/IKeyboard.hpp b/src/devices/IKeyboard.hpp index 2ff8a190..ad8eaf7e 100644 --- a/src/devices/IKeyboard.hpp +++ b/src/devices/IKeyboard.hpp @@ -5,6 +5,7 @@ #include "../macros.hpp" #include "../helpers/math/Math.hpp" +#include #include AQUAMARINE_FORWARD(IKeyboard); @@ -61,19 +62,20 @@ class IKeyboard : public IHID { std::string rules = ""; }; - void setKeymap(const SStringRuleNames& rules); - void updateXKBTranslationState(xkb_keymap* const keymap = nullptr); - std::string getActiveLayout(); - void updateLEDs(); - 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 - void updateXkbStateWithKey(uint32_t xkbKey, bool pressed); - void updateKeymapFD(); + void setKeymap(const SStringRuleNames& rules); + void updateXKBTranslationState(xkb_keymap* const keymap = nullptr); + std::string getActiveLayout(); + std::optional getLEDs(); + void updateLEDs(); + 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 + void updateXkbStateWithKey(uint32_t xkbKey, bool pressed); + void updateKeymapFD(); - bool active = false; - bool enabled = true; + bool active = false; + bool enabled = true; // if the keymap is overridden by the implementation, // don't try to set keyboard rules anymore, to avoid overwriting the requested one. diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 619bfab7..014de40a 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1265,7 +1265,14 @@ void CInputManager::updateKeyboardsLeds(SP pKeyboard) { if (!pKeyboard) return; - pKeyboard->updateLEDs(); + std::optional leds = pKeyboard->getLEDs(); + + if (!leds.has_value()) + return; + + for (auto& k : m_vKeyboards) { + k->updateLEDs(leds.value()); + } } void CInputManager::onKeyboardKey(std::any event, SP pKeyboard) {