From 3518e3ba8aa43e759ad7c65142ebdd328549c967 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sun, 10 Apr 2022 19:54:58 +0200 Subject: [PATCH] added ignore_mod --- src/KeybindManager.cpp | 11 ++++++++++- src/config/ConfigManager.cpp | 8 ++++++++ src/events/events.cpp | 3 ++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/KeybindManager.cpp b/src/KeybindManager.cpp index 18c35b4..b30e336 100644 --- a/src/KeybindManager.cpp +++ b/src/KeybindManager.cpp @@ -7,8 +7,10 @@ #include Keybind* KeybindManager::findKeybindByKey(int mod, xcb_keysym_t keysym) { + const auto IGNOREMODMASK = KeybindManager::modToMask(ConfigManager::getString("ignore_mod")); + for(auto& key : KeybindManager::keybinds) { - if (keysym == key.getKeysym() && mod == key.getMod()) { + if (keysym == key.getKeysym() && (mod == key.getMod() || mod == key.getMod() | IGNOREMODMASK)) { return &key; } } @@ -67,6 +69,13 @@ uint32_t KeybindManager::getKeyCodeFromName(std::string name) { unsigned int KeybindManager::modToMask(std::string mod) { + try { + uint32_t modmask = std::stoi(mod.c_str()); + return modmask; + } catch(...) { + ; // means its not alphanumeric, go ahead + } + unsigned int sum = 0; if (CONTAINS(mod, "SUPER") || CONTAINS(mod, "MOD4")) sum |= XCB_MOD_MASK_4; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 916b652..19ce376 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -20,6 +20,7 @@ void ConfigManager::init() { configValues["intelligent_transients"].intValue = 1; configValues["no_unmap_saving"].intValue = 1; configValues["scratchpad_mon"].intValue = 1; + configValues["ignore_mod"].strValue = "0"; configValues["focus_when_hover"].intValue = 1; @@ -448,6 +449,8 @@ void ConfigManager::applyKeybindsToX() { return; // If we are in the status bar don't do this. } + const auto IGNOREMODMASK = KeybindManager::modToMask(configValues["ignore_mod"].strValue); + Debug::log(LOG, "Applying " + std::to_string(KeybindManager::keybinds.size()) + " keybinds to X."); xcb_ungrab_key(g_pWindowManager->DisplayConnection, XCB_GRAB_ANY, g_pWindowManager->Screen->root, XCB_MOD_MASK_ANY); @@ -457,6 +460,11 @@ void ConfigManager::applyKeybindsToX() { xcb_grab_key(g_pWindowManager->DisplayConnection, 1, g_pWindowManager->Screen->root, keybind.getMod(), KeybindManager::getKeycodeFromKeysym(keybind.getKeysym()), XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); + + // ignore mod + xcb_grab_key(g_pWindowManager->DisplayConnection, 1, g_pWindowManager->Screen->root, + keybind.getMod() | IGNOREMODMASK, KeybindManager::getKeycodeFromKeysym(keybind.getKeysym()), + XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); } xcb_flush(g_pWindowManager->DisplayConnection); diff --git a/src/events/events.cpp b/src/events/events.cpp index 54f7025..f6c9c65 100644 --- a/src/events/events.cpp +++ b/src/events/events.cpp @@ -777,9 +777,10 @@ void Events::eventKeyPress(xcb_generic_event_t* event) { RETURNIFBAR; const auto KEYSYM = KeybindManager::getKeysymFromKeycode(E->detail); + const auto IGNOREDMOD = KeybindManager::modToMask(ConfigManager::getString("ignore_mod")); for (auto& keybind : KeybindManager::keybinds) { - if (keybind.getKeysym() != 0 && keybind.getKeysym() == KEYSYM && keybind.getMod() == E->state) { + if (keybind.getKeysym() != 0 && keybind.getKeysym() == KEYSYM && (keybind.getMod() == E->state || keybind.getMod() | IGNOREDMOD == E->state)) { keybind.getDispatcher()(keybind.getCommand()); return; // TODO: fix duplicating keybinds