From fa20d1342545f3b6871ffe6e2fba963cd8c595ad Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 27 Dec 2021 09:40:37 +0100 Subject: [PATCH] Add support for all x keys --- src/KeybindManager.cpp | 14 ++++++++++++++ src/config/ConfigManager.cpp | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/KeybindManager.cpp b/src/KeybindManager.cpp index 00fccf6..443c639 100644 --- a/src/KeybindManager.cpp +++ b/src/KeybindManager.cpp @@ -18,6 +18,7 @@ uint32_t KeybindManager::getKeyCodeFromName(std::string name) { if (name == "") return 0; + const auto ORIGINALCASENAME = name; transform(name.begin(), name.end(), name.begin(), ::tolower); if (name.length() == 1) { @@ -44,6 +45,19 @@ uint32_t KeybindManager::getKeyCodeFromName(std::string name) { return 0xff54; } else if (name == "space") { return 0x20; + } else { + // unknown key, find in the xmodmap + std::string command = "xmodmap -pk | grep \"(" + ORIGINALCASENAME + ")\""; + std::string returnValue = exec(command.c_str()); + + try { + returnValue = returnValue.substr(returnValue.find_first_of('x') + 1); + returnValue = returnValue.substr(0, returnValue.find_first_of(' ')); + + return std::stoi(returnValue, nullptr, 16); // return hex to int + } catch (...) { + Debug::log(ERR, "Unknown key: " + ORIGINALCASENAME); + } } } diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 33a1769..24992a6 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -120,7 +120,7 @@ void handleBind(const std::string& command, const std::string& value) { if (HANDLER == "workspace") dispatcher = KeybindManager::changeworkspace; if (HANDLER == "togglefloating") dispatcher = KeybindManager::toggleActiveWindowFloating; - if (dispatcher) + if (dispatcher && KEY != 0) KeybindManager::keybinds.push_back(Keybind(KeybindManager::modToMask(MOD), KEY, COMMAND, dispatcher)); }