From 37a2725da41e363fcdca12d0374b192cd03905d0 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Wed, 28 Jun 2023 21:24:59 +1200 Subject: 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). --- keybinds.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'keybinds.h') diff --git a/keybinds.h b/keybinds.h index 686eaf8..5c220c2 100644 --- a/keybinds.h +++ b/keybinds.h @@ -2,6 +2,7 @@ #include #include + #include #include #include @@ -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 binds; + Keybind getKeybind(std::string bindString); + void changeMap(int newMapID); + std::map> 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; -- cgit v1.2.3 From ea569d9c9c61eb26f7d325b41d8ac839dc470eec Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Tue, 15 Aug 2023 21:27:51 +1200 Subject: feat: Made the bind modes work Numlock still seems to mess with keybindings. Also switched from storing keybinds with KeySym to KeyCode --- keybinds.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'keybinds.h') diff --git a/keybinds.h b/keybinds.h index 5c220c2..a742240 100644 --- a/keybinds.h +++ b/keybinds.h @@ -13,7 +13,7 @@ #include "util.h" struct Keybind { - KeySym key; + KeyCode key; unsigned int modifiers; bool operator<(const Keybind &o) const; bool operator==(const Keybind &o) const; @@ -28,6 +28,7 @@ struct KeyFunction #define getKeymap(X) \ keyMaps.find(X)->second + class KeybindsModule { public: @@ -35,12 +36,17 @@ public: ~KeybindsModule() = default; const void bind(const CommandArg* argv); const void quitKey(const CommandArg* argv); + const void bindMode(const CommandArg* argv); const void handleKeypress(XKeyEvent e); const void clearKeybinds(); private: Keybind getKeybind(std::string bindString); void changeMap(int newMapID); std::map> keyMaps; + const Keybind emacsBindMode(std::string bindString); + const Keybind normalBindMode(std::string bindString); + std::map bindModes; + const Keybind(KeybindsModule::* bindFunc)(std::string bindString); // Modifier keys to ignore when canceling a keymap KeyCode ignoredKeys[8] = {50, 37, 133, 64, 62, 105, 134, 108}; int currentMapID = 0; -- cgit v1.2.3