added ignore_mod

This commit is contained in:
vaxerski 2022-04-10 19:54:58 +02:00
parent 6f5172dd32
commit 3518e3ba8a
3 changed files with 20 additions and 2 deletions

View file

@ -7,8 +7,10 @@
#include <string.h> #include <string.h>
Keybind* KeybindManager::findKeybindByKey(int mod, xcb_keysym_t keysym) { Keybind* KeybindManager::findKeybindByKey(int mod, xcb_keysym_t keysym) {
const auto IGNOREMODMASK = KeybindManager::modToMask(ConfigManager::getString("ignore_mod"));
for(auto& key : KeybindManager::keybinds) { 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; return &key;
} }
} }
@ -67,6 +69,13 @@ uint32_t KeybindManager::getKeyCodeFromName(std::string name) {
unsigned int KeybindManager::modToMask(std::string mod) { 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; unsigned int sum = 0;
if (CONTAINS(mod, "SUPER") || CONTAINS(mod, "MOD4")) sum |= XCB_MOD_MASK_4; if (CONTAINS(mod, "SUPER") || CONTAINS(mod, "MOD4")) sum |= XCB_MOD_MASK_4;

View file

@ -20,6 +20,7 @@ void ConfigManager::init() {
configValues["intelligent_transients"].intValue = 1; configValues["intelligent_transients"].intValue = 1;
configValues["no_unmap_saving"].intValue = 1; configValues["no_unmap_saving"].intValue = 1;
configValues["scratchpad_mon"].intValue = 1; configValues["scratchpad_mon"].intValue = 1;
configValues["ignore_mod"].strValue = "0";
configValues["focus_when_hover"].intValue = 1; 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. 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."); 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); 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, xcb_grab_key(g_pWindowManager->DisplayConnection, 1, g_pWindowManager->Screen->root,
keybind.getMod(), KeybindManager::getKeycodeFromKeysym(keybind.getKeysym()), keybind.getMod(), KeybindManager::getKeycodeFromKeysym(keybind.getKeysym()),
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); 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); xcb_flush(g_pWindowManager->DisplayConnection);

View file

@ -777,9 +777,10 @@ void Events::eventKeyPress(xcb_generic_event_t* event) {
RETURNIFBAR; RETURNIFBAR;
const auto KEYSYM = KeybindManager::getKeysymFromKeycode(E->detail); const auto KEYSYM = KeybindManager::getKeysymFromKeycode(E->detail);
const auto IGNOREDMOD = KeybindManager::modToMask(ConfigManager::getString("ignore_mod"));
for (auto& keybind : KeybindManager::keybinds) { 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()); keybind.getDispatcher()(keybind.getCommand());
return; return;
// TODO: fix duplicating keybinds // TODO: fix duplicating keybinds