diff options
author | vaxerski <[email protected]> | 2022-06-25 11:50:09 +0200 |
---|---|---|
committer | vaxerski <[email protected]> | 2022-06-25 11:50:09 +0200 |
commit | b46f45befab6e2aa6daba76ec04cec4286eec56b (patch) | |
tree | fbdf3101cc7326196ec31bd213b4df1773da6f50 | |
parent | 3842b1641fb6c8197fbc79eb0e62a66b4f1cb4c1 (diff) | |
download | Hyprland-b46f45befab6e2aa6daba76ec04cec4286eec56b.tar.gz Hyprland-b46f45befab6e2aa6daba76ec04cec4286eec56b.zip |
additional keymap reload safety
-rw-r--r-- | src/helpers/WLClasses.hpp | 2 | ||||
-rw-r--r-- | src/managers/input/InputManager.cpp | 20 |
2 files changed, 18 insertions, 4 deletions
diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index 2a2d3c93..d6282224 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -71,6 +71,8 @@ struct SKeyboard { bool active = false; + xkb_rule_names currentRules; + // For the list lookup bool operator==(const SKeyboard& rhs) { return keyboard == rhs.keyboard; diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index d58a9986..f99c6ab4 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -277,7 +277,7 @@ void CInputManager::newKeyboard(wlr_input_device* keyboard) { m_pActiveKeyboard->active = false; m_pActiveKeyboard = PNEWKEYBOARD; - setKeyboardLayout(); + applyConfigToKeyboard(PNEWKEYBOARD); wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, keyboard->keyboard); @@ -299,6 +299,11 @@ void CInputManager::applyConfigToKeyboard(SKeyboard* pKeyboard) { const auto VARIANT = g_pConfigManager->getString("input:kb_variant"); const auto OPTIONS = g_pConfigManager->getString("input:kb_options"); + if (RULES != "" && RULES == pKeyboard->currentRules.rules && MODEL == pKeyboard->currentRules.model && LAYOUT == pKeyboard->currentRules.layout && VARIANT == pKeyboard->currentRules.variant && OPTIONS == pKeyboard->currentRules.options) { + Debug::log(LOG, "Not applying config to keyboard, it did not change."); + return; + } + xkb_rule_names rules = { .rules = RULES.c_str(), .model = MODEL.c_str(), @@ -306,6 +311,8 @@ void CInputManager::applyConfigToKeyboard(SKeyboard* pKeyboard) { .variant = VARIANT.c_str(), .options = OPTIONS.c_str()}; + pKeyboard->currentRules = rules; + const auto CONTEXT = xkb_context_new(XKB_CONTEXT_NO_FLAGS); if (!CONTEXT) { @@ -313,12 +320,17 @@ void CInputManager::applyConfigToKeyboard(SKeyboard* pKeyboard) { return; } - const auto KEYMAP = xkb_keymap_new_from_names(CONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); + Debug::log(LOG, "Attempting to create a keymap for layout %s with variant %s (rules: %s, model: %s, options: %s)", rules.layout, rules.variant, rules.rules, rules.model, rules.options); + + auto KEYMAP = xkb_keymap_new_from_names(CONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); if (!KEYMAP) { Debug::log(ERR, "Keyboard layout %s with variant %s (rules: %s, model: %s, options: %s) couldn't have been loaded.", rules.layout, rules.variant, rules.rules, rules.model, rules.options); - xkb_context_unref(CONTEXT); - return; + memset(&rules, 0, sizeof(rules)); + + pKeyboard->currentRules = rules; + + KEYMAP = xkb_keymap_new_from_names(CONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); } wlr_keyboard_set_keymap(pKeyboard->keyboard->keyboard, KEYMAP); |