diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index d95f5a05..d742070a 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -450,7 +450,7 @@ void CConfigManager::handleBind(const std::string& command, const std::string& v } if (KEY != "") - g_pKeybindManager->addKeybind(SKeybind{KEY, MOD, HANDLER, COMMAND, locked}); + g_pKeybindManager->addKeybind(SKeybind{KEY, MOD, HANDLER, COMMAND, locked, m_szCurrentSubmap}); } void CConfigManager::handleUnbind(const std::string& command, const std::string& value) { @@ -507,6 +507,13 @@ void CConfigManager::handleDefaultWorkspace(const std::string& command, const st } } +void CConfigManager::handleSubmap(const std::string& command, const std::string& submap) { + if (submap == "reset") + m_szCurrentSubmap = ""; + else + m_szCurrentSubmap = submap; +} + void CConfigManager::handleSource(const std::string& command, const std::string& rawpath) { static const char* const ENVHOME = getenv("HOME"); @@ -587,6 +594,7 @@ std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std:: else if (COMMAND == "bezier") handleBezier(COMMAND, VALUE); else if (COMMAND == "animation") handleAnimation(COMMAND, VALUE); else if (COMMAND == "source") handleSource(COMMAND, VALUE); + else if (COMMAND == "submap") handleSubmap(COMMAND, VALUE); else configSetValueSafe(currentCategory + (currentCategory == "" ? "" : ":") + COMMAND, VALUE); diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 407ccce4..8c0bd857 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -88,6 +88,8 @@ private: std::string parseError = ""; // For storing a parse error to display later + std::string m_szCurrentSubmap = ""; // For storing the current keybind submap + bool isFirstLaunch = true; // For exec-once std::deque m_dMonitorRules; @@ -113,6 +115,7 @@ private: void handleBezier(const std::string&, const std::string&); void handleAnimation(const std::string&, const std::string&); void handleSource(const std::string&, const std::string&); + void handleSubmap(const std::string&, const std::string&); }; inline std::unique_ptr g_pConfigManager; \ No newline at end of file diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 17c606b9..06075554 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -30,6 +30,7 @@ CKeybindManager::CKeybindManager() { m_mDispatchers["resizeactive"] = resizeActive; m_mDispatchers["cyclenext"] = circleNext; m_mDispatchers["focuswindowbyclass"] = focusWindowByClass; + m_mDispatchers["submap"] = setSubmap; } void CKeybindManager::addKeybind(SKeybind kb) { @@ -76,7 +77,7 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t Debug::log(LOG, "Keybind handling only locked (inhibitor)"); for (auto& k : m_lKeybinds) { - if (modmask != k.modmask || (g_pCompositor->m_sSeat.exclusiveClient && !k.locked)) + if (modmask != k.modmask || (g_pCompositor->m_sSeat.exclusiveClient && !k.locked) || k.submap != m_szCurrentSelectedSubmap) continue; // oMg such performance hit!!11! @@ -935,3 +936,21 @@ void CKeybindManager::focusWindowByClass(std::string clazz) { break; } } + +void CKeybindManager::setSubmap(std::string submap) { + if (submap == "reset" || submap == "") { + m_szCurrentSelectedSubmap = ""; + Debug::log(LOG, "Reset active submap to the default one."); + return; + } + + for (auto& k : g_pKeybindManager->m_lKeybinds) { + if (k.submap == submap) { + m_szCurrentSelectedSubmap = submap; + Debug::log(LOG, "Changed keybind submap to %s", submap.c_str()); + return; + } + } + + Debug::log(ERR, "Cannot set submap %s, submap doesn't exist (wasn't registered!)", submap.c_str()); +} diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index a3dbb8dd..4ebf94a3 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -12,6 +12,7 @@ struct SKeybind { std::string handler = ""; std::string arg = ""; bool locked = false; + std::string submap = ""; }; class CKeybindManager { @@ -29,6 +30,8 @@ public: private: std::list m_lKeybinds; + inline static std::string m_szCurrentSelectedSubmap = ""; + bool handleInternalKeybinds(xkb_keysym_t); // -------------- Dispatchers -------------- // @@ -57,6 +60,7 @@ private: static void resizeActive(std::string); static void circleNext(std::string); static void focusWindowByClass(std::string); + static void setSubmap(std::string); friend class CCompositor; };