summaryrefslogtreecommitdiff
path: root/keybinds.cpp
diff options
context:
space:
mode:
authorBossCode45 <human.cyborg42@gmail.com>2023-06-03 21:30:05 +1200
committerBossCode45 <human.cyborg42@gmail.com>2023-06-03 21:30:05 +1200
commite9cc5756dbb0a2d079a7b5e3438d79945f819df5 (patch)
tree3881cb6bed150ef11252ef04a5e11c05d5af05f8 /keybinds.cpp
parent01bc6a33eb235cd10851e2c31b99e6840603ca7d (diff)
downloadYATwm-e9cc5756dbb0a2d079a7b5e3438d79945f819df5.tar.gz
YATwm-e9cc5756dbb0a2d079a7b5e3438d79945f819df5.zip
feat: Keybind updates
Re added the ability to swap super and mod as a config parameter (the ~swapmods~) command). Finally fixed keybinds sometimes not working because of numlock, bitwise & with the modifiers I actually care about.
Diffstat (limited to 'keybinds.cpp')
-rw-r--r--keybinds.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/keybinds.cpp b/keybinds.cpp
index 30b3fd0..85e9e4e 100644
--- a/keybinds.cpp
+++ b/keybinds.cpp
@@ -10,9 +10,10 @@
using std::string, std::cout, std::endl;
-KeybindsModule::KeybindsModule(CommandsModule& commandsModule, Globals& globals)
+KeybindsModule::KeybindsModule(CommandsModule& commandsModule, Config& cfg, Globals& globals)
:commandsModule(commandsModule),
- globals(globals)
+ globals(globals),
+ cfg(cfg)
{
CommandArgType* bindArgs = new CommandArgType[2];
bindArgs[0] = STR;
@@ -23,10 +24,15 @@ KeybindsModule::KeybindsModule(CommandsModule& commandsModule, Globals& globals)
const void KeybindsModule::handleKeypress(XKeyEvent e)
{
if(e.same_screen!=1) return;
+ //cout << "Key Pressed" << endl;
+ //cout << "\tState: " << e.state << endl;
+ //cout << "\tCode: " << XKeysymToString(XKeycodeToKeysym(globals.dpy, e.keycode, 0)) << endl;
//updateMousePos();
+
+ const unsigned int masks = ShiftMask | ControlMask | Mod1Mask | Mod4Mask;
for(Keybind bind : binds)
{
- if(bind.modifiers == e.state && bind.key == XKeycodeToKeysym(globals.dpy, e.keycode, 0))
+ if(bind.modifiers == (e.state & masks) && bind.key == XKeycodeToKeysym(globals.dpy, e.keycode, 0))
{
commandsModule.runCommand(bind.command);
}
@@ -48,11 +54,11 @@ const void KeybindsModule::bind(const CommandArg* argv)
{
if(key == "mod")
{
- bind.modifiers |= Mod1Mask;
+ bind.modifiers |= Mod4Mask >> 3 * cfg.swapSuperAlt;
}
else if(key == "alt")
{
- bind.modifiers |= Mod4Mask;
+ bind.modifiers |= Mod1Mask << 3 * cfg.swapSuperAlt;
}
else if(key == "shift")
{
@@ -74,7 +80,13 @@ const void KeybindsModule::bind(const CommandArg* argv)
}
}
bind.command = argv[1].str;
+ cout << bind.modifiers << endl;
KeyCode c = XKeysymToKeycode(globals.dpy, bind.key);
XGrabKey(globals.dpy, c, bind.modifiers, globals.root, False, GrabModeAsync, GrabModeAsync);
binds.push_back(bind);
}
+
+const void KeybindsModule::clearKeybinds()
+{
+ XUngrabButton(globals.dpy, AnyKey, AnyModifier, globals.root);
+}