summaryrefslogtreecommitdiff
path: root/keybinds.h
diff options
context:
space:
mode:
authorBossCode45 <human.cyborg42@gmail.com>2023-08-24 12:58:40 +1200
committerBossCode45 <human.cyborg42@gmail.com>2023-08-24 12:58:40 +1200
commit6b5c246a431dcaff119833724137f0716fa2a002 (patch)
tree99ced8d93809cf675b55ea683f28f847e84d9722 /keybinds.h
parent87b7f6c47d8eab8bfe7f126652a88939aac58a6a (diff)
parentd22b5d2363ed8a90960446a209482180f6d27fc0 (diff)
downloadYATwm-6b5c246a431dcaff119833724137f0716fa2a002.tar.gz
YATwm-6b5c246a431dcaff119833724137f0716fa2a002.zip
Merge branch 'keybind-refactor'
Diffstat (limited to 'keybinds.h')
-rw-r--r--keybinds.h32
1 files changed, 29 insertions, 3 deletions
diff --git a/keybinds.h b/keybinds.h
index 686eaf8..a742240 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>
@@ -12,20 +13,45 @@
#include "util.h"
struct Keybind {
- KeySym key;
+ KeyCode 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 bindMode(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;
+ 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;