diff options
| author | Albert Cervin <albert@acervin.com> | 2022-11-02 22:20:04 +0100 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2022-11-16 23:33:49 +0100 |
| commit | 2f4cb88d5c60f725323739300bb49dfa8923e7d5 (patch) | |
| tree | 6ec22c2be92eff05f18e5919e747faab56e555ad /src/binding.h | |
| download | dged-2f4cb88d5c60f725323739300bb49dfa8923e7d5.tar.gz dged-2f4cb88d5c60f725323739300bb49dfa8923e7d5.tar.xz dged-2f4cb88d5c60f725323739300bb49dfa8923e7d5.zip | |
🎉 And so it begins
Diffstat (limited to 'src/binding.h')
| -rw-r--r-- | src/binding.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/binding.h b/src/binding.h new file mode 100644 index 0000000..260a463 --- /dev/null +++ b/src/binding.h @@ -0,0 +1,43 @@ +#include "keyboard.h" + +struct keymap { + const char *name; + struct binding *bindings; + uint32_t nbindings; + uint32_t capacity; +}; + +enum binding_type { BindingType_Command, BindingType_Keymap }; + +#define BINDING(mod_, c_, command_) \ + (struct binding) { \ + .key = {.mod = mod_, .c = c_}, .type = BindingType_Command, \ + .command = hash_command_name(command_) \ + } + +#define PREFIX(mod_, c_, keymap_) \ + (struct binding) { \ + .key = {.mod = mod_, .c = c_}, .type = BindingType_Keymap, \ + .keymap = keymap_ \ + } + +struct binding { + struct key key; + + uint8_t type; + + union { + uint32_t command; + struct keymap *keymap; + }; +}; + +struct commands; + +struct keymap keymap_create(const char *name, uint32_t capacity); +void keymap_bind_keys(struct keymap *keymap, struct binding *bindings, + uint32_t nbindings); +void keymap_destroy(struct keymap *keymap); + +struct command *lookup_key(struct keymap *keymaps, uint32_t nkeymaps, + struct key *key, struct commands *commands); |
