aboutsummaryrefslogtreecommitdiff
path: root/src/binds.h
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2017-11-23 19:13:25 +0000
committerHarry Jeffery <harry@exec64.co.uk>2017-11-23 21:34:11 +0000
commit7f8e941e97459ce83b00de04ecf2c8ac679334c4 (patch)
treeedb33c0a2fede44a37c799a93d05983eb5c042cd /src/binds.h
parent96c320e999927d964fbd128724022e7eeb976b8d (diff)
downloadimv-7f8e941e97459ce83b00de04ecf2c8ac679334c4.tar.gz
Implement key binding logic
This code is *heavily* based on work I previously did for aerc. Since I'm the author of that code, and therefore the copyright holder, I'm able to heavily re-use logic. Of course, because of the differences between termbox and SDL's event logic and key naming features, there's some significant differences in how binds are handled, and how keys are named.
Diffstat (limited to 'src/binds.h')
-rw-r--r--src/binds.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/binds.h b/src/binds.h
new file mode 100644
index 0000000..cf41c74
--- /dev/null
+++ b/src/binds.h
@@ -0,0 +1,40 @@
+#ifndef IMV_BINDS_H
+#define IMV_BINDS_H
+
+#include <SDL2/SDL.h>
+
+struct imv_binds;
+struct list;
+
+enum bind_result {
+ BIND_SUCCESS,
+ BIND_INVALID_KEYS,
+ BIND_INVALID_COMMAND,
+ BIND_CONFLICTS,
+};
+
+/* Create an imv_binds instance */
+struct imv_binds *imv_binds_create(void);
+
+/* Clean up an imv_binds instance */
+void imv_binds_free(struct imv_binds *binds);
+
+/* Create a key binding */
+enum bind_result imv_binds_add(struct imv_binds *binds, const struct list *keys, const char *cmd);
+
+/* Fetch the list of keys pressed so far */
+const struct list *imv_bind_input_buffer(struct imv_binds *binds);
+
+/* Abort the current input key sequence */
+void imv_bind_clear_input(struct imv_binds *binds);
+
+/* Handle an input event, if a bind is triggered, return its command */
+const char *imv_bind_handle_event(struct imv_binds *binds, const SDL_Event *event);
+
+/* Convert a string (such as from a config) to a key list */
+struct list *imv_bind_parse_keys(const char *keys);
+
+/* Convert a key list to a string */
+size_t imv_bind_print_keylist(const struct list *keys, char *buf, size_t len);
+
+#endif