aboutsummaryrefslogtreecommitdiff
path: root/src/binds.c
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2019-06-15 14:28:29 +0100
committerHarry Jeffery <harry@exec64.co.uk>2019-07-03 20:50:19 +0100
commit7c7dc660e587eac1aa3c8b3405eba95ba558e682 (patch)
tree81d12d560b60d397be23c7d132e32a5de30e409a /src/binds.c
parent20e9d23b82f55a751c3cf1166cb59ef26775ee00 (diff)
downloadimv-7c7dc660e587eac1aa3c8b3405eba95ba558e682.tar.gz
Big glfw refactor
I did a lot of this in a very ad-hoc fashion with no proper commit history. As such, the kindest thing to do seemed to be to just squash it into this one commit.
Diffstat (limited to 'src/binds.c')
-rw-r--r--src/binds.c64
1 files changed, 4 insertions, 60 deletions
diff --git a/src/binds.c b/src/binds.c
index f8c4597..07416cf 100644
--- a/src/binds.c
+++ b/src/binds.c
@@ -2,6 +2,7 @@
#include "list.h"
#include <stdbool.h>
+#include <stdio.h>
struct bind_node {
char *key; /* input key to reach this node */
@@ -186,69 +187,17 @@ static enum lookup_result bind_lookup(struct bind_node *node, struct list *keys,
return LOOKUP_PARTIAL;
}
-static int print_event(char *buf, size_t len, const SDL_Event *event)
-{
- /* only accept keydown events */
- if(event->type != SDL_KEYDOWN) {
- buf[0] = 0;
- return 0;
- }
-
- const SDL_KeyboardEvent *kevent = &event->key;
-
- /* filter out modifier keys */
- switch(kevent->keysym.sym) {
- case SDLK_LCTRL:
- case SDLK_RCTRL:
- case SDLK_LALT:
- case SDLK_RALT:
- case SDLK_LSHIFT:
- case SDLK_RSHIFT:
- return 0;
- }
-
- /* Build prefix first: */
- char prefix[32] = {0};
- snprintf(prefix, sizeof prefix, "%s%s%s",
- SDL_GetModState() & KMOD_CTRL ? "Ctrl+" : "",
- SDL_GetModState() & KMOD_ALT ? "Meta+" : "",
- SDL_GetModState() & KMOD_SHIFT ? "Shift+" : "");
-
- /* Try plain old character input */
- const char *keyname = SDL_GetKeyName(kevent->keysym.sym);
- char singlekey[2] = {0};
-
- /* Because '<' and '>' have special meaning in our syntax, and '=', '[', and
- * ']' are restricted within ini files, we rename these. */
- if(!strcmp(keyname, "<")) {
- keyname = "Less";
- } else if(!strcmp(keyname, ">")) {
- keyname = "Greater";
- } else if(!strcmp(keyname, "=")) {
- keyname = "Equals";
- } else if(!strcmp(keyname, "[")) {
- keyname = "LeftSquareBracket";
- } else if(!strcmp(keyname, "]")) {
- keyname = "RightSquareBracket";
- } else if(strlen(keyname) == 1 && isalpha(*keyname)) {
- singlekey[0] = tolower(*keyname);
- keyname = singlekey;
- }
-
- return snprintf(buf, len, "%s%s", prefix, keyname);
-}
-
void imv_bind_clear_input(struct imv_binds *binds)
{
list_deep_free(binds->keys);
binds->keys = list_create();
}
-struct list *imv_bind_handle_event(struct imv_binds *binds, const SDL_Event *event)
+struct list *imv_bind_handle_event(struct imv_binds *binds, const char *event)
{
/* 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 (!strcmp("Escape", event)) {
if (binds->aborting_sequence) {
/* The last thing they hit was escape, so abort the current entry */
binds->aborting_sequence = false;
@@ -263,12 +212,7 @@ struct list *imv_bind_handle_event(struct imv_binds *binds, const SDL_Event *eve
binds->aborting_sequence = false;
}
- char buffer[128];
- if (!print_event(buffer, sizeof(buffer), event)) {
- /* invalid event - do nothing */
- return NULL;
- }
- list_append(binds->keys, strdup(buffer));
+ list_append(binds->keys, strdup(event));
struct list *commands = NULL;
enum lookup_result result = bind_lookup(&binds->bind_tree, binds->keys, &commands);