diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index 31a24793..6b0787bb 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -94,11 +94,14 @@ struct SKeyboard { DYNLISTENER(keyboardMod); DYNLISTENER(keyboardKey); + DYNLISTENER(keyboardKeymap); DYNLISTENER(keyboardDestroy); bool isVirtual = false; bool active = false; + xkb_layout_index_t activeLayout = 0; + std::string name = ""; SStringRuleNames currentRules; diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 95b30587..b002864d 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -441,10 +441,20 @@ void CInputManager::newKeyboard(wlr_input_device* keyboard) { PNEWKEYBOARD->hyprListener_keyboardKey.initCallback(&wlr_keyboard_from_input_device(keyboard)->events.key, &Events::listener_keyboardKey, PNEWKEYBOARD, "Keyboard"); PNEWKEYBOARD->hyprListener_keyboardDestroy.initCallback(&keyboard->events.destroy, &Events::listener_keyboardDestroy, PNEWKEYBOARD, "Keyboard"); + PNEWKEYBOARD->hyprListener_keyboardKeymap.initCallback(&wlr_keyboard_from_input_device(keyboard)->events.keymap, [&](void* owner, void* data) { + const auto PKEYBOARD = (SKeyboard*)owner; + + if (PKEYBOARD == m_pActiveKeyboard) + g_pEventManager->postEvent(SHyprIPCEvent{"activelayout", getActiveLayoutForKeyboard(PKEYBOARD)}, true); // force as this should ALWAYS be sent + + }, PNEWKEYBOARD, "Keyboard"); + if (m_pActiveKeyboard) m_pActiveKeyboard->active = false; m_pActiveKeyboard = PNEWKEYBOARD; + PNEWKEYBOARD->active = true; + applyConfigToKeyboard(PNEWKEYBOARD); wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, wlr_keyboard_from_input_device(keyboard)); @@ -472,6 +482,8 @@ void CInputManager::newVirtualKeyboard(wlr_input_device* keyboard) { m_pActiveKeyboard->active = false; m_pActiveKeyboard = PNEWKEYBOARD; + PNEWKEYBOARD->active = true; + applyConfigToKeyboard(PNEWKEYBOARD); wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, wlr_keyboard_from_input_device(keyboard)); @@ -582,6 +594,9 @@ void CInputManager::applyConfigToKeyboard(SKeyboard* pKeyboard) { xkb_keymap_unref(KEYMAP); xkb_context_unref(CONTEXT); + if (pKeyboard == m_pActiveKeyboard) + g_pEventManager->postEvent(SHyprIPCEvent{"activelayout", getActiveLayoutForKeyboard(pKeyboard)}, true); // force as this should ALWAYS be sent + Debug::log(LOG, "Set the keyboard layout to %s and variant to %s for keyboard \"%s\"", rules.layout, rules.variant, pKeyboard->keyboard->name); } @@ -735,6 +750,15 @@ void CInputManager::onKeyboardMod(void* data, SKeyboard* pKeyboard) { wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, wlr_keyboard_from_input_device(pKeyboard->keyboard)); wlr_seat_keyboard_notify_modifiers(g_pCompositor->m_sSeat.seat, &wlr_keyboard_from_input_device(pKeyboard->keyboard)->modifiers); } + + const auto PWLRKB = wlr_keyboard_from_input_device(pKeyboard->keyboard); + + if (PWLRKB->modifiers.group != pKeyboard->activeLayout) { + pKeyboard->activeLayout = PWLRKB->modifiers.group; + + if (pKeyboard == m_pActiveKeyboard) + g_pEventManager->postEvent(SHyprIPCEvent{"activelayout", getActiveLayoutForKeyboard(pKeyboard)}, true); // force as this should ALWAYS be sent + } } void CInputManager::refocus() {