summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSungyoon Cho <sungyoon@sungyooncho.dev>2024-07-28 19:46:38 +0900
committerGitHub <noreply@github.com>2024-07-28 11:46:38 +0100
commit9b6ae4f77b95fef271c2e21abba5e05b4cc47719 (patch)
tree6ffe52a271da61803684009ae6697f8ad5bb1b3b /src
parentbc86afea7e177a7ad4335737417fc0e468698dc4 (diff)
input: fix keyboard leds with multiple keyboards (#7079)
Diffstat (limited to 'src')
-rw-r--r--src/devices/IKeyboard.cpp15
-rw-r--r--src/devices/IKeyboard.hpp28
-rw-r--r--src/managers/input/InputManager.cpp9
3 files changed, 35 insertions, 17 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<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) {
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 <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();
-
- bool active = false;
- bool enabled = true;
+ 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;
// 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<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) {