diff options
| author | BossCode45 <human.cyborg42@gmail.com> | 2024-12-01 19:24:09 +1300 |
|---|---|---|
| committer | BossCode45 <human.cyborg42@gmail.com> | 2024-12-01 19:24:09 +1300 |
| commit | 8dca89a1be23f0de2dd1676b95feb6b46cbdd5f2 (patch) | |
| tree | 7ebc1a5161bbe70d6ab6a0e5353a1a622240c915 /src/keybinds.h | |
| parent | e162dff48c251e262f475de9261f0ecfa0f39dc4 (diff) | |
| parent | 434ec6542d0d79190c6aa7003aac91b03cad4398 (diff) | |
| download | YATwm-8dca89a1be23f0de2dd1676b95feb6b46cbdd5f2.tar.gz YATwm-8dca89a1be23f0de2dd1676b95feb6b46cbdd5f2.zip | |
Merge branch 'IPC'
Diffstat (limited to 'src/keybinds.h')
| -rw-r--r-- | src/keybinds.h | 59 |
1 files changed, 59 insertions, 0 deletions
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 <X11/X.h> +#include <X11/Xlib.h> + +#include <map> +#include <string> +#include <X11/keysym.h> +#include <vector> + +#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<int, std::map<Keybind, KeyFunction>> keyMaps; + const Keybind emacsBindMode(std::string bindString); + const Keybind normalBindMode(std::string bindString); + std::map<std::string, const Keybind(KeybindsModule::*)(std::string bindString)> 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)(); +}; |
