input: fix keyboard leds with multiple keyboards (#7079)

This commit is contained in:
Sungyoon Cho 2024-07-28 19:46:38 +09:00 committed by GitHub
parent bc86afea7e
commit 9b6ae4f77b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 16 deletions

View file

@ -274,9 +274,9 @@ std::string IKeyboard::getActiveLayout() {
return "none"; return "none";
} }
void IKeyboard::updateLEDs() { std::optional<uint32_t> IKeyboard::getLEDs() {
if (xkbState == nullptr) if (xkbState == nullptr)
return; return {};
uint32_t leds = 0; uint32_t leds = 0;
for (uint32_t i = 0; i < LED_COUNT; ++i) { for (uint32_t i = 0; i < LED_COUNT; ++i) {
@ -284,7 +284,16 @@ void IKeyboard::updateLEDs() {
leds |= (1 << i); leds |= (1 << i);
} }
updateLEDs(leds); return leds;
}
void IKeyboard::updateLEDs() {
std::optional<uint32_t> leds = getLEDs();
if (!leds.has_value())
return;
updateLEDs(leds.value());
} }
void IKeyboard::updateLEDs(uint32_t leds) { void IKeyboard::updateLEDs(uint32_t leds) {

View file

@ -5,6 +5,7 @@
#include "../macros.hpp" #include "../macros.hpp"
#include "../helpers/math/Math.hpp" #include "../helpers/math/Math.hpp"
#include <optional>
#include <xkbcommon/xkbcommon.h> #include <xkbcommon/xkbcommon.h>
AQUAMARINE_FORWARD(IKeyboard); AQUAMARINE_FORWARD(IKeyboard);
@ -64,6 +65,7 @@ class IKeyboard : public IHID {
void setKeymap(const SStringRuleNames& rules); void setKeymap(const SStringRuleNames& rules);
void updateXKBTranslationState(xkb_keymap* const keymap = nullptr); void updateXKBTranslationState(xkb_keymap* const keymap = nullptr);
std::string getActiveLayout(); std::string getActiveLayout();
std::optional<uint32_t> getLEDs();
void updateLEDs(); void updateLEDs();
void updateLEDs(uint32_t leds); void updateLEDs(uint32_t leds);
uint32_t getModifiers(); uint32_t getModifiers();

View file

@ -1265,7 +1265,14 @@ void CInputManager::updateKeyboardsLeds(SP<IKeyboard> pKeyboard) {
if (!pKeyboard) if (!pKeyboard)
return; return;
pKeyboard->updateLEDs(); std::optional<uint32_t> leds = pKeyboard->getLEDs();
if (!leds.has_value())
return;
for (auto& k : m_vKeyboards) {
k->updateLEDs(leds.value());
}
} }
void CInputManager::onKeyboardKey(std::any event, SP<IKeyboard> pKeyboard) { void CInputManager::onKeyboardKey(std::any event, SP<IKeyboard> pKeyboard) {