aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2019-03-01 13:33:46 +0000
committerHarry Jeffery <harry@exec64.co.uk>2019-03-01 13:44:29 +0000
commite278e289896c7effb283c6b29c52b918d70251b7 (patch)
treed884be3b66a49c9a0e7e6601c89e32195c62ce75
parent4a2ce2e9ee9453eb429628490b3729d26ba9143f (diff)
downloadimv-e278e289896c7effb283c6b29c52b918d70251b7.tar.gz
binds: Make Double-Escape the key sequence abort
By using escape to abort all key input sequences, it became unbindable despite being documented as so. Make the sequence double-escape to fix this. The downside here is now double-escape is unbindable, but that's unlikely to be an issue. Fixes #147
-rw-r--r--src/binds.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/binds.c b/src/binds.c
index 0647d5a..f8c4597 100644
--- a/src/binds.c
+++ b/src/binds.c
@@ -12,6 +12,7 @@ struct bind_node {
struct imv_binds {
struct bind_node bind_tree;
struct list *keys;
+ bool aborting_sequence;
};
static int compare_node_key(const void* item, const void *key)
@@ -42,7 +43,7 @@ static void destroy_bind_node(struct bind_node *bn)
struct imv_binds *imv_binds_create(void)
{
- struct imv_binds *binds = malloc(sizeof *binds);
+ struct imv_binds *binds = calloc(1, sizeof *binds);
init_bind_node(&binds->bind_tree);
binds->keys = list_create();
return binds;
@@ -245,9 +246,21 @@ void imv_bind_clear_input(struct imv_binds *binds)
struct list *imv_bind_handle_event(struct imv_binds *binds, const SDL_Event *event)
{
- if(event->key.keysym.sym == SDLK_ESCAPE) {
- imv_bind_clear_input(binds);
- return NULL;
+ /* If the user hits Escape twice in a row, treat that as backtracking out
+ * of the current key sequence. */
+ if (event->key.keysym.sym == SDLK_ESCAPE) {
+ if (binds->aborting_sequence) {
+ /* The last thing they hit was escape, so abort the current entry */
+ binds->aborting_sequence = false;
+ imv_bind_clear_input(binds);
+ return NULL;
+ } else {
+ /* Start the aborting sequence */
+ binds->aborting_sequence = true;
+ }
+ } else {
+ /* They didn't hit escape, if they were in an abort sequence, cancel it */
+ binds->aborting_sequence = false;
}
char buffer[128];