diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-04-20 12:57:07 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-05-02 16:15:17 +0530 |
| commit | b4b6a646b3a7a7f6c7e990c67f208b76f4b5f748 (patch) | |
| tree | 7f18775a63594acf0187668af63766dd72b9f66f /src/keymap/KeymapEvaluator.hpp | |
| parent | 75157006bf6f1176f64e87695343980b16908bb6 (diff) | |
| download | null-browser-b4b6a646b3a7a7f6c7e990c67f208b76f4b5f748.tar.gz null-browser-b4b6a646b3a7a7f6c7e990c67f208b76f4b5f748.zip | |
Refactor + expose managing mode to inside lua
Diffstat (limited to '')
| -rw-r--r-- | src/keymap/KeymapEvaluator.hpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/keymap/KeymapEvaluator.hpp b/src/keymap/KeymapEvaluator.hpp index 34f4ae5..a7a100b 100644 --- a/src/keymap/KeymapEvaluator.hpp +++ b/src/keymap/KeymapEvaluator.hpp @@ -2,8 +2,8 @@ #include <QWidget> #include <QtCore> -#include <cstdint> #include <functional> +#include <unordered_map> #include "keymap/KeySeqParser.hpp" #include "utils.hpp" @@ -15,7 +15,16 @@ struct KeyMap { KeyAction action; }; -enum KeyMode : uint8_t { Normal, Insert }; +using KeyMode = QString; + +struct KeyModeConfig { + bool passthrough; +}; + +struct KeyModeState { + QList<KeyMap> keymap; + KeyModeConfig config; +}; class KeymapEvaluator : public QObject { Q_OBJECT @@ -28,20 +37,20 @@ public: return keymap_evaluator; } - void add_keymap(KeyMode mode, const QString &key, KeyAction action); + void add_keymap(const KeyMode &mode, const QString &key, KeyAction action); bool evaluate(Qt::KeyboardModifiers modifiers, Qt::Key key); - KeyMode mode_from_string(const QString &mode_string); + void define_mode(const KeyMode &mode, const KeyModeConfig &config); DEFINE_SETTER(set_current_mode, current_mode) DEFINE_GETTER(get_current_mode, current_mode) protected: const QList<KeyMap> *current_mode_keys(); - bool is_insertable_mode(); + bool is_passthrough_mode(); private: - QMap<KeyMode, QList<KeyMap>> modal_keys; + std::unordered_map<KeyMode, KeyModeState> modal_keys; KeySeqParser key_seq_parser; - KeyMode current_mode = KeyMode::Normal; + KeyMode current_mode = "i"; KeySequence active_key_sequence; }; |
