summaryrefslogtreecommitdiff
path: root/keybinds.h
diff options
context:
space:
mode:
authorBossCode45 <human.cyborg42@gmail.com>2023-06-28 21:24:59 +1200
committerBossCode45 <human.cyborg42@gmail.com>2023-06-28 21:24:59 +1200
commit37a2725da41e363fcdca12d0374b192cd03905d0 (patch)
treee2eaa5e14171987e7e06fca21b3d6d9253e80165 /keybinds.h
parent638c3ac10003f66ef4af43f50ee365c9036da0fe (diff)
downloadYATwm-37a2725da41e363fcdca12d0374b192cd03905d0.tar.gz
YATwm-37a2725da41e363fcdca12d0374b192cd03905d0.zip
feat: Added key chording
Probably a hacky mess but oh well. Key chords can be done by seperating binds in string with ` `. You can set the quit bind with `quitkey`, default mod+g. (Chords also exited when pressing unbound keys).
Diffstat (limited to 'keybinds.h')
-rw-r--r--keybinds.h24
1 files changed, 22 insertions, 2 deletions
diff --git a/keybinds.h b/keybinds.h
index 686eaf8..5c220c2 100644
--- a/keybinds.h
+++ b/keybinds.h
@@ -2,6 +2,7 @@
#include <X11/X.h>
#include <X11/Xlib.h>
+
#include <map>
#include <string>
#include <X11/keysym.h>
@@ -14,18 +15,37 @@
struct Keybind {
KeySym key;
unsigned int modifiers;
+ bool operator<(const Keybind &o) const;
+ bool operator==(const Keybind &o) const;
+};
+
+struct KeyFunction
+{
std::string command;
+ int mapID;
};
-class KeybindsModule {
+#define getKeymap(X) \
+ keyMaps.find(X)->second
+
+class KeybindsModule
+{
public:
KeybindsModule(CommandsModule& commandsModule, Config& cfg, Globals& globals, void (*updateMousePos)());
~KeybindsModule() = default;
const void bind(const CommandArg* argv);
+ const void quitKey(const CommandArg* argv);
const void handleKeypress(XKeyEvent e);
const void clearKeybinds();
private:
- std::vector<Keybind> binds;
+ Keybind getKeybind(std::string bindString);
+ void changeMap(int newMapID);
+ std::map<int, std::map<Keybind, KeyFunction>> keyMaps;
+ // Modifier keys to ignore when canceling a keymap
+ KeyCode ignoredKeys[8] = {50, 37, 133, 64, 62, 105, 134, 108};
+ int currentMapID = 0;
+ int nextKeymapID = 1;
+ Keybind exitBind = {42, 0x40};
CommandsModule& commandsModule;
Config& cfg;
Globals& globals;