diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2022-08-19 22:39:50 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-19 22:39:50 +0200 |
| commit | 223ca6e2868b5a4d59bafecfa597e9b676226c4e (patch) | |
| tree | ab31f800052cb865f4ac91016e5e4b574c63960e /src/managers/input/InputManager.cpp | |
| parent | c2a3896cc9168a12f25a144dada6ecb94fb52b59 (diff) | |
| parent | f0ad77251b28fcf48dcaf25f23e3a140d69a4735 (diff) | |
Merge pull request #548 from FlafyDev/main
add input:kb_file option to use a .xkb file.
Diffstat (limited to 'src/managers/input/InputManager.cpp')
| -rw-r--r-- | src/managers/input/InputManager.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index a0016dba..d6cf00be 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -526,6 +526,7 @@ void CInputManager::applyConfigToKeyboard(SKeyboard* pKeyboard) { const auto NUMLOCKON = HASCONFIG ? g_pConfigManager->getDeviceInt(devname, "numlock_by_default") : g_pConfigManager->getInt("input:numlock_by_default"); + const auto FILEPATH = HASCONFIG ? g_pConfigManager->getDeviceString(devname, "kb_file") : g_pConfigManager->getString("input:kb_file"); const auto RULES = HASCONFIG ? g_pConfigManager->getDeviceString(devname, "kb_rules") : g_pConfigManager->getString("input:kb_rules"); const auto MODEL = HASCONFIG ? g_pConfigManager->getDeviceString(devname, "kb_model") : g_pConfigManager->getString("input:kb_model"); const auto LAYOUT = HASCONFIG ? g_pConfigManager->getDeviceString(devname, "kb_layout") : g_pConfigManager->getString("input:kb_layout"); @@ -533,7 +534,7 @@ void CInputManager::applyConfigToKeyboard(SKeyboard* pKeyboard) { const auto OPTIONS = HASCONFIG ? g_pConfigManager->getDeviceString(devname, "kb_options") : g_pConfigManager->getString("input:kb_options"); try { - if (NUMLOCKON == pKeyboard->numlockOn && REPEATDELAY == pKeyboard->repeatDelay && REPEATRATE == pKeyboard->repeatRate && RULES != "" && RULES == pKeyboard->currentRules.rules && MODEL == pKeyboard->currentRules.model && LAYOUT == pKeyboard->currentRules.layout && VARIANT == pKeyboard->currentRules.variant && OPTIONS == pKeyboard->currentRules.options) { + if (NUMLOCKON == pKeyboard->numlockOn && REPEATDELAY == pKeyboard->repeatDelay && REPEATRATE == pKeyboard->repeatRate && RULES != "" && RULES == pKeyboard->currentRules.rules && MODEL == pKeyboard->currentRules.model && LAYOUT == pKeyboard->currentRules.layout && VARIANT == pKeyboard->currentRules.variant && OPTIONS == pKeyboard->currentRules.options && FILEPATH == pKeyboard->xkbFilePath) { Debug::log(LOG, "Not applying config to keyboard, it did not change."); return; } @@ -547,6 +548,7 @@ void CInputManager::applyConfigToKeyboard(SKeyboard* pKeyboard) { pKeyboard->repeatDelay = REPEATDELAY; pKeyboard->repeatRate = REPEATRATE; pKeyboard->numlockOn = NUMLOCKON; + pKeyboard->xkbFilePath = FILEPATH.c_str(); xkb_rule_names rules = { .rules = RULES.c_str(), @@ -570,7 +572,21 @@ void CInputManager::applyConfigToKeyboard(SKeyboard* pKeyboard) { 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); + xkb_keymap * KEYMAP = NULL; + + if (!FILEPATH.empty()) { + auto path = absolutePath(FILEPATH, g_pConfigManager->configCurrentPath); + + if (!std::filesystem::exists(path)) { + Debug::log(ERR, "input:kb_file= file doesnt exist"); + } else { + KEYMAP = xkb_keymap_new_from_file(CONTEXT, fopen(path.c_str(), "r"), XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS); + } + } + + if (!KEYMAP) { + KEYMAP = xkb_keymap_new_from_names(CONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); + } if (!KEYMAP) { g_pConfigManager->addParseError("Invalid keyboard layout passed. ( rules: " + RULES + ", model: " + MODEL + ", variant: " + VARIANT + ", options: " + OPTIONS + ", layout: " + LAYOUT + " )"); @@ -949,4 +965,4 @@ void CInputManager::disableAllKeyboards(bool virt) { k.active = false; } -}
\ No newline at end of file +} |
