From 064e40d25f1265a2d6f00f37c402e5f9e08954aa Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 21 Apr 2022 17:06:43 +0200 Subject: [PATCH] Added unbind keyword --- src/config/ConfigManager.cpp | 13 +++++++++++++ src/config/ConfigManager.hpp | 1 + src/managers/KeybindManager.cpp | 14 +++++++++++--- src/managers/KeybindManager.hpp | 3 ++- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 976c38b5..e80b545d 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -215,6 +215,17 @@ void CConfigManager::handleBind(const std::string& command, const std::string& v g_pKeybindManager->addKeybind(SKeybind{KEY, MOD, HANDLER, COMMAND}); } +void CConfigManager::handleUnbind(const std::string& command, const std::string& value) { + auto valueCopy = value; + + const auto MOD = g_pKeybindManager->stringToModMask(valueCopy.substr(0, valueCopy.find_first_of(","))); + valueCopy = valueCopy.substr(valueCopy.find_first_of(",") + 1); + + const auto KEY = valueCopy; + + g_pKeybindManager->removeKeybind(MOD, KEY); +} + void CConfigManager::handleWindowRule(const std::string& command, const std::string& value) { const auto RULE = value.substr(0, value.find_first_of(",")); const auto VALUE = value.substr(value.find_first_of(",") + 1); @@ -271,6 +282,8 @@ std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std:: handleMonitor(COMMAND, VALUE); } else if (COMMAND == "bind") { handleBind(COMMAND, VALUE); + } else if (COMMAND == "unbind") { + handleUnbind(COMMAND, VALUE); } else if (COMMAND == "workspace") { handleDefaultWorkspace(COMMAND, VALUE); } else if (COMMAND == "windowrule") { diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 2f071a13..4c2c5660 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -86,6 +86,7 @@ private: void handleRawExec(const std::string&, const std::string&); void handleMonitor(const std::string&, const std::string&); void handleBind(const std::string&, const std::string&); + void handleUnbind(const std::string&, const std::string&); void handleWindowRule(const std::string&, const std::string&); void handleDefaultWorkspace(const std::string&, const std::string&); }; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 6d3417fc..06fdf5f4 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -18,7 +18,15 @@ CKeybindManager::CKeybindManager() { } void CKeybindManager::addKeybind(SKeybind kb) { - m_dKeybinds.push_back(kb); + m_lKeybinds.push_back(kb); +} + +void CKeybindManager::removeKeybind(uint32_t mod, const std::string& key) { + for (auto it = m_lKeybinds.begin(); it != m_lKeybinds.end(); ++it) { + if (it->modmask == mod && it->key == key) { + it = m_lKeybinds.erase(it); + } + } } uint32_t CKeybindManager::stringToModMask(std::string mods) { @@ -54,7 +62,7 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t return false; } - for (auto& k : m_dKeybinds) { + for (auto& k : m_lKeybinds) { if (modmask != k.modmask) continue; @@ -126,7 +134,7 @@ void CKeybindManager::killActive(std::string args) { } void CKeybindManager::clearKeybinds() { - m_dKeybinds.clear(); + m_lKeybinds.clear(); } void CKeybindManager::toggleActiveFloating(std::string args) { diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index e262081e..2561c8ad 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -19,13 +19,14 @@ public: bool handleKeybinds(const uint32_t&, const xkb_keysym_t&); void addKeybind(SKeybind); + void removeKeybind(uint32_t, const std::string&); uint32_t stringToModMask(std::string); void clearKeybinds(); std::unordered_map> m_mDispatchers; private: - std::deque m_dKeybinds; + std::list m_lKeybinds; bool handleInternalKeybinds(xkb_keysym_t);