From 69d17bf4240e41f2b26abd7a46dfd0e754e9ee9e Mon Sep 17 00:00:00 2001 From: FlafyDev Date: Fri, 19 Aug 2022 21:01:51 +0300 Subject: [PATCH 1/2] add input:kb_file --- example/hyprland.conf | 3 +- src/config/ConfigManager.cpp | 47 +++++++++++++++++------------ src/config/ConfigManager.hpp | 3 +- src/config/defaultConfig.hpp | 3 +- src/helpers/WLClasses.hpp | 3 +- src/managers/input/InputManager.cpp | 22 ++++++++++++-- 6 files changed, 55 insertions(+), 26 deletions(-) diff --git a/example/hyprland.conf b/example/hyprland.conf index 506e0e7e..e2732c62 100644 --- a/example/hyprland.conf +++ b/example/hyprland.conf @@ -12,6 +12,7 @@ monitor=,preferred,auto,1 workspace=DP-1,1 input { + kb_file= kb_layout= kb_variant= kb_model= @@ -112,4 +113,4 @@ bind=ALT,9,movetoworkspace,9 bind=ALT,0,movetoworkspace,10 bind=SUPER,mouse_down,workspace,e+1 -bind=SUPER,mouse_up,workspace,e-1 \ No newline at end of file +bind=SUPER,mouse_up,workspace,e-1 diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 5f7725a2..37ea10fc 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -119,6 +119,7 @@ void CConfigManager::setDefaultVars() { configValues["animations:workspaces"].intValue = 1; configValues["input:sensitivity"].floatValue = 0.f; + configValues["input:kb_file"].strValue = STRVAL_EMPTY; configValues["input:kb_layout"].strValue = "us"; configValues["input:kb_variant"].strValue = STRVAL_EMPTY; configValues["input:kb_options"].strValue = STRVAL_EMPTY; @@ -155,6 +156,7 @@ void CConfigManager::setDeviceDefaultVars(const std::string& dev) { auto& cfgValues = deviceConfigs[dev]; cfgValues["sensitivity"].floatValue = 0.f; + cfgValues["kb_file"].strValue = STRVAL_EMPTY; cfgValues["kb_layout"].strValue = "us"; cfgValues["kb_variant"].strValue = STRVAL_EMPTY; cfgValues["kb_options"].strValue = STRVAL_EMPTY; @@ -774,28 +776,13 @@ void CConfigManager::handleSubmap(const std::string& command, const std::string& void CConfigManager::handleSource(const std::string& command, const std::string& rawpath) { static const char* const ENVHOME = getenv("HOME"); - auto value = rawpath; - - if (value.length() < 2) { + if (rawpath.length() < 2) { Debug::log(ERR, "source= path garbage"); - parseError = "source path " + value + " bogus!"; + parseError = "source path " + rawpath + " bogus!"; return; } - if (value[0] == '.') { - auto currentDir = configCurrentPath.substr(0, configCurrentPath.find_last_of('/')); - - if (value[1] == '.') { - auto parentDir = currentDir.substr(0, currentDir.find_last_of('/')); - value.replace(0, 2, parentDir); - } else { - value.replace(0, 1, currentDir); - } - } - - if (value[0] == '~') { - value.replace(0, 1, std::string(ENVHOME)); - } + auto value = absolutePath(rawpath); if (!std::filesystem::exists(value)) { Debug::log(ERR, "source= file doesnt exist"); @@ -889,6 +876,28 @@ std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std:: return parseError; } +std::string CConfigManager::absolutePath(const std::string& rawpath) { + auto value = rawpath; + + if (value[0] == '.') { + auto currentDir = configCurrentPath.substr(0, configCurrentPath.find_last_of('/')); + + if (value[1] == '.') { + auto parentDir = currentDir.substr(0, currentDir.find_last_of('/')); + value.replace(0, 2, parentDir); + } else { + value.replace(0, 1, currentDir); + } + } + + if (value[0] == '~') { + static const char* const ENVHOME = getenv("HOME"); + value.replace(0, 1, std::string(ENVHOME)); + } + + return value; +} + void CConfigManager::applyUserDefinedVars(std::string& line, const size_t equalsPlace) { auto dollarPlace = line.find_first_of('$', equalsPlace); @@ -1379,4 +1388,4 @@ SAnimationPropertyConfig* CConfigManager::getAnimationPropertyConfig(const std:: void CConfigManager::addParseError(const std::string& err) { if (parseError == "") parseError = err; -} \ No newline at end of file +} diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 87cbd956..05e00921 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -101,6 +101,7 @@ public: void ensureDPMS(); std::string parseKeyword(const std::string&, const std::string&, bool dynamic = false); + std::string absolutePath(const std::string&); void addParseError(const std::string&); @@ -159,4 +160,4 @@ private: void handleBlurLS(const std::string&, const std::string&); }; -inline std::unique_ptr g_pConfigManager; \ No newline at end of file +inline std::unique_ptr g_pConfigManager; diff --git a/src/config/defaultConfig.hpp b/src/config/defaultConfig.hpp index 75ec925f..9ecdbbb0 100644 --- a/src/config/defaultConfig.hpp +++ b/src/config/defaultConfig.hpp @@ -20,6 +20,7 @@ autogenerated=1 # remove this line to get rid of the warning on top. monitor=,preferred,auto,1 input { + kb_file= kb_layout= kb_variant= kb_model= @@ -122,4 +123,4 @@ bind=ALT,0,movetoworkspace,10 bind=SUPER,mouse_down,workspace,e+1 bind=SUPER,mouse_up,workspace,e-1 -)#"; \ No newline at end of file +)#"; diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index 6b0787bb..4c769202 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -103,6 +103,7 @@ struct SKeyboard { xkb_layout_index_t activeLayout = 0; std::string name = ""; + std::string xkbFilePath = ""; SStringRuleNames currentRules; int repeatRate = 0; @@ -316,4 +317,4 @@ struct SIMEPopup { bool operator==(const SIMEPopup& other) { return pSurface == other.pSurface; } -}; \ No newline at end of file +}; diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index f8899f62..82889f8a 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -519,6 +519,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"); @@ -526,7 +527,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; } @@ -540,6 +541,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(), @@ -563,7 +565,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 = g_pConfigManager->absolutePath(FILEPATH); + + 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 + " )"); @@ -942,4 +958,4 @@ void CInputManager::disableAllKeyboards(bool virt) { k.active = false; } -} \ No newline at end of file +} From f0ad77251b28fcf48dcaf25f23e3a140d69a4735 Mon Sep 17 00:00:00 2001 From: FlafyDev Date: Fri, 19 Aug 2022 23:18:09 +0300 Subject: [PATCH 2/2] move absolutePath to MiscFunctions --- src/config/ConfigManager.cpp | 24 +----------------------- src/config/ConfigManager.hpp | 5 ++--- src/helpers/MiscFunctions.cpp | 22 ++++++++++++++++++++++ src/helpers/MiscFunctions.hpp | 3 ++- src/managers/input/InputManager.cpp | 2 +- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 37ea10fc..162c8611 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -782,7 +782,7 @@ void CConfigManager::handleSource(const std::string& command, const std::string& return; } - auto value = absolutePath(rawpath); + auto value = absolutePath(rawpath, configCurrentPath); if (!std::filesystem::exists(value)) { Debug::log(ERR, "source= file doesnt exist"); @@ -876,28 +876,6 @@ std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std:: return parseError; } -std::string CConfigManager::absolutePath(const std::string& rawpath) { - auto value = rawpath; - - if (value[0] == '.') { - auto currentDir = configCurrentPath.substr(0, configCurrentPath.find_last_of('/')); - - if (value[1] == '.') { - auto parentDir = currentDir.substr(0, currentDir.find_last_of('/')); - value.replace(0, 2, parentDir); - } else { - value.replace(0, 1, currentDir); - } - } - - if (value[0] == '~') { - static const char* const ENVHOME = getenv("HOME"); - value.replace(0, 1, std::string(ENVHOME)); - } - - return value; -} - void CConfigManager::applyUserDefinedVars(std::string& line, const size_t equalsPlace) { auto dollarPlace = line.find_first_of('$', equalsPlace); diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 05e00921..72eb58f6 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -101,12 +101,13 @@ public: void ensureDPMS(); std::string parseKeyword(const std::string&, const std::string&, bool dynamic = false); - std::string absolutePath(const std::string&); void addParseError(const std::string&); SAnimationPropertyConfig* getAnimationPropertyConfig(const std::string&); + std::string configCurrentPath; + private: std::deque configPaths; // stores all the config paths std::unordered_map configModifyTimes; // stores modify times @@ -116,8 +117,6 @@ private: std::unordered_map animationConfig; // stores all the animations with their set values - std::string configCurrentPath; - std::string currentCategory = ""; // For storing the category of the current item std::string parseError = ""; // For storing a parse error to display later diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index b7285637..b27489ca 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -40,6 +40,28 @@ static const float transforms[][9] = {{ }, }; +std::string absolutePath(const std::string& rawpath, const std::string& currentPath) { + auto value = rawpath; + + if (value[0] == '.') { + auto currentDir = currentPath.substr(0, currentPath.find_last_of('/')); + + if (value[1] == '.') { + auto parentDir = currentDir.substr(0, currentDir.find_last_of('/')); + value.replace(0, 2, parentDir); + } else { + value.replace(0, 1, currentDir); + } + } + + if (value[0] == '~') { + static const char* const ENVHOME = getenv("HOME"); + value.replace(0, 1, std::string(ENVHOME)); + } + + return value; +} + void addWLSignal(wl_signal* pSignal, wl_listener* pListener, void* pOwner, std::string ownerString) { ASSERT(pSignal); ASSERT(pListener); diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp index a40471a9..9f002c20 100644 --- a/src/helpers/MiscFunctions.hpp +++ b/src/helpers/MiscFunctions.hpp @@ -2,6 +2,7 @@ #include "../includes.hpp" +std::string absolutePath(const std::string&, const std::string&); void addWLSignal(wl_signal*, wl_listener*, void* pOwner, std::string ownerString); void wlr_signal_emit_safe(struct wl_signal *signal, void *data); std::string getFormat(const char *fmt, ...); // Basically Debug::log to a string @@ -17,4 +18,4 @@ std::string execAndGet(const char*); float getPlusMinusKeywordResult(std::string in, float relative); -void matrixProjection(float mat[9], int w, int h, wl_output_transform tr); \ No newline at end of file +void matrixProjection(float mat[9], int w, int h, wl_output_transform tr); diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 82889f8a..b35d9064 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -568,7 +568,7 @@ void CInputManager::applyConfigToKeyboard(SKeyboard* pKeyboard) { xkb_keymap * KEYMAP = NULL; if (!FILEPATH.empty()) { - auto path = g_pConfigManager->absolutePath(FILEPATH); + auto path = absolutePath(FILEPATH, g_pConfigManager->configCurrentPath); if (!std::filesystem::exists(path)) { Debug::log(ERR, "input:kb_file= file doesnt exist");