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";
}
void IKeyboard::updateLEDs() {
std::optional<uint32_t> 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<uint32_t> leds = getLEDs();
if (!leds.has_value())
return;
updateLEDs(leds.value());
}
void IKeyboard::updateLEDs(uint32_t leds) {

View File

@ -5,6 +5,7 @@
#include "../macros.hpp"
#include "../helpers/math/Math.hpp"
#include <optional>
#include <xkbcommon/xkbcommon.h>
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<uint32_t> 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.

View File

@ -1265,7 +1265,14 @@ void CInputManager::updateKeyboardsLeds(SP<IKeyboard> pKeyboard) {
if (!pKeyboard)
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) {