summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSungyoon Cho <sungyoon@sungyooncho.dev>2024-05-15 00:14:43 +0900
committerGitHub <noreply@github.com>2024-05-14 16:14:43 +0100
commitd0a4a0e0d8ecc0a47c0bcfbf84c090cae8cee7af (patch)
treec30bdc02ec7bd66f1f652c00d11878addacea5dc /src
parent1584679004435d93d5fe2dd794d2aefaa0c9574a (diff)
input: fix modifier and leds (#6062)
Diffstat (limited to 'src')
-rw-r--r--src/devices/IKeyboard.cpp11
-rw-r--r--src/devices/IKeyboard.hpp1
-rw-r--r--src/managers/input/InputManager.cpp28
-rw-r--r--src/managers/input/InputManager.hpp1
-rw-r--r--src/protocols/InputMethodV2.cpp3
5 files changed, 36 insertions, 8 deletions
diff --git a/src/devices/IKeyboard.cpp b/src/devices/IKeyboard.cpp
index 3bd42eac..7e4dd912 100644
--- a/src/devices/IKeyboard.cpp
+++ b/src/devices/IKeyboard.cpp
@@ -131,8 +131,17 @@ void IKeyboard::updateLEDs() {
leds |= (1 << i);
}
+ updateLEDs(leds);
+}
+
+void IKeyboard::updateLEDs(uint32_t leds) {
+ auto keyboard = wlr();
+
+ if (!keyboard || keyboard->xkb_state == nullptr)
+ return;
+
if (isVirtual() && g_pInputManager->shouldIgnoreVirtualKeyboard(self.lock()))
return;
- wlr_keyboard_led_update(wlr(), leds);
+ wlr_keyboard_led_update(keyboard, leds);
}
diff --git a/src/devices/IKeyboard.hpp b/src/devices/IKeyboard.hpp
index d90550da..ec58ff5b 100644
--- a/src/devices/IKeyboard.hpp
+++ b/src/devices/IKeyboard.hpp
@@ -42,6 +42,7 @@ class IKeyboard : public IHID {
void updateXKBTranslationState(xkb_keymap* const keymap = nullptr);
std::string getActiveLayout();
void updateLEDs();
+ void updateLEDs(uint32_t leds);
bool active = false;
bool enabled = true;
diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp
index 1d09dbb9..958fb255 100644
--- a/src/managers/input/InputManager.cpp
+++ b/src/managers/input/InputManager.cpp
@@ -1239,6 +1239,26 @@ void CInputManager::destroyTabletPad(SP<CTabletPad> pad) {
removeFromHIDs(pad);
}
+void CInputManager::updateKeyboardsLeds(SP<IKeyboard> pKeyboard) {
+ if (!pKeyboard)
+ return;
+
+ auto keyboard = pKeyboard->wlr();
+
+ if (!keyboard || keyboard->xkb_state == nullptr)
+ return;
+
+ uint32_t leds = 0;
+ for (uint32_t i = 0; i < WLR_LED_COUNT; ++i) {
+ if (xkb_state_led_index_is_active(keyboard->xkb_state, keyboard->led_indexes[i]))
+ leds |= (1 << i);
+ }
+
+ for (auto& k : m_vKeyboards) {
+ k->updateLEDs(leds);
+ }
+}
+
void CInputManager::onKeyboardKey(std::any event, SP<IKeyboard> pKeyboard) {
if (!pKeyboard->enabled)
return;
@@ -1271,9 +1291,7 @@ void CInputManager::onKeyboardKey(std::any event, SP<IKeyboard> pKeyboard) {
wlr_seat_keyboard_notify_key(g_pCompositor->m_sSeat.seat, e.timeMs, e.keycode, e.state);
}
- for (auto& k : m_vKeyboards) {
- k->updateLEDs();
- }
+ updateKeyboardsLeds(pKeyboard);
}
}
@@ -1299,9 +1317,7 @@ void CInputManager::onKeyboardMod(SP<IKeyboard> pKeyboard) {
wlr_seat_keyboard_notify_modifiers(g_pCompositor->m_sSeat.seat, &MODS);
}
- for (auto& k : m_vKeyboards) {
- k->updateLEDs();
- }
+ updateKeyboardsLeds(pKeyboard);
if (PWLRKB->modifiers.group != pKeyboard->activeLayout) {
pKeyboard->activeLayout = PWLRKB->modifiers.group;
diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp
index 970d53c8..df36b975 100644
--- a/src/managers/input/InputManager.hpp
+++ b/src/managers/input/InputManager.hpp
@@ -114,6 +114,7 @@ class CInputManager {
void updateDragIcon();
void updateCapabilities();
+ void updateKeyboardsLeds(SP<IKeyboard>);
void setClickMode(eClickBehaviorMode);
eClickBehaviorMode getClickMode();
diff --git a/src/protocols/InputMethodV2.cpp b/src/protocols/InputMethodV2.cpp
index d84f6772..9e5c863b 100644
--- a/src/protocols/InputMethodV2.cpp
+++ b/src/protocols/InputMethodV2.cpp
@@ -53,7 +53,8 @@ void CInputMethodKeyboardGrabV2::sendKeyboardData(wlr_keyboard* keyboard) {
close(keymapFD);
- sendMods(0, 0, 0, 0);
+ const auto MODS = keyboard->modifiers;
+ sendMods(MODS.depressed, MODS.latched, MODS.locked, MODS.group);
resource->sendRepeatInfo(keyboard->repeat_info.rate, keyboard->repeat_info.delay);
}