From 915532bf8fbda9ba2a36e04fcd6acc67c6c68fa5 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Tue, 1 Oct 2024 14:54:37 +1300 Subject: Restructure --- src/keybinds.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/keybinds.h (limited to 'src/keybinds.h') diff --git a/src/keybinds.h b/src/keybinds.h new file mode 100644 index 0000000..a742240 --- /dev/null +++ b/src/keybinds.h @@ -0,0 +1,59 @@ +#pragma once + +#include +#include + +#include +#include +#include +#include + +#include "commands.h" +#include "config.h" +#include "util.h" + +struct Keybind { + KeyCode key; + unsigned int modifiers; + bool operator<(const Keybind &o) const; + bool operator==(const Keybind &o) const; +}; + +struct KeyFunction +{ + std::string command; + int mapID; +}; + +#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 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; + int nextKeymapID = 1; + Keybind exitBind = {42, 0x40}; + CommandsModule& commandsModule; + Config& cfg; + Globals& globals; + void (*updateMousePos)(); +}; -- cgit v1.2.3