From 34a7f17956146077b964d68a7e9be5d9a8742086 Mon Sep 17 00:00:00 2001 From: Leftas Date: Sat, 12 Nov 2022 13:12:37 +0200 Subject: [PATCH] Add keyboard led update after keys/mod update --- src/managers/input/InputManager.cpp | 29 +++++++++++++++++++++++++++++ src/managers/input/InputManager.hpp | 2 ++ 2 files changed, 31 insertions(+) diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index adca5b14..93e83035 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -818,6 +818,31 @@ void CInputManager::destroyMouse(wlr_input_device* mouse) { unconstrainMouse(); } + +void CInputManager::updateKeyboardsLeds(wlr_input_device* pKeyboard) { + auto keyboard = wlr_keyboard_from_input_device(pKeyboard); + + if (keyboard->xkb_state == NULL) { + 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& kb : m_lKeyboards) { + if ((kb.isVirtual && shouldIgnoreVirtualKeyboard(&kb)) || kb.keyboard == pKeyboard) + continue; + + wlr_keyboard_led_update(wlr_keyboard_from_input_device(kb.keyboard), leds); + } +} + + void CInputManager::onKeyboardKey(wlr_keyboard_key_event* e, SKeyboard* pKeyboard) { bool passEvent = g_pKeybindManager->onKeyEvent(e, pKeyboard); @@ -834,6 +859,8 @@ void CInputManager::onKeyboardKey(wlr_keyboard_key_event* e, SKeyboard* pKeyboar wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, wlr_keyboard_from_input_device(pKeyboard->keyboard)); wlr_seat_keyboard_notify_key(g_pCompositor->m_sSeat.seat, e->time_msec, e->keycode, e->state); } + + updateKeyboardsLeds(pKeyboard->keyboard); } } @@ -853,6 +880,8 @@ void CInputManager::onKeyboardMod(void* data, SKeyboard* pKeyboard) { wlr_seat_keyboard_notify_modifiers(g_pCompositor->m_sSeat.seat, &MODS); } + updateKeyboardsLeds(pKeyboard->keyboard); + const auto PWLRKB = wlr_keyboard_from_input_device(pKeyboard->keyboard); if (PWLRKB->modifiers.group != pKeyboard->activeLayout) { diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index 18786758..4885277b 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -115,6 +115,8 @@ public: CInputMethodRelay m_sIMERelay; + void updateKeyboardsLeds(wlr_input_device* pKeyboard); + // for shared mods uint32_t accumulateModsFromAllKBs();