commit 5b0ab8be628ecc658a3cc7b76d44342e76fdd72e
parent ecef093def78db374c7960fb3f0d3b55a7913282
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Sat, 23 Jul 2016 12:15:39 +0200
shortcuts: remove any unnecessary classifying of keys
After initialization, the type of a key is never used nor needed
(other than for meta keys).
Diffstat:
5 files changed, 11 insertions(+), 24 deletions(-)
diff --git a/src/global.c b/src/global.c
@@ -340,7 +340,6 @@ void add_to_sclist(int menus, const char *scstring, void (*func)(void), int togg
if (toggle)
s->ordinal = ++counter;
s->keystr = (char *) scstring;
- s->type = strtokeytype(scstring);
assign_keyinfo(s);
#ifdef DEBUG
@@ -400,41 +399,31 @@ functionptrtype func_from_key(int *kbinput)
return NULL;
}
-/* Return the type of command key based on the given string. */
-key_type strtokeytype(const char *str)
-{
- if (str[0] == '^')
- return CONTROL;
- else if (str[0] == 'M')
- return META;
- else if (str[0] == 'F')
- return FKEY;
- else
- return RAWINPUT;
-}
-
/* Assign the info to the shortcut struct.
* Assumes keystr is already assigned, naturally. */
void assign_keyinfo(sc *s)
{
- if (s->type == CONTROL) {
+ s->type = DIRECT;
+
+ if (s->keystr[0] == '^') {
assert(strlen(s->keystr) > 1);
s->seq = s->keystr[1] - 64;
- } else if (s->type == META) {
+ } else if (s->keystr[0] == 'M') {
assert(strlen(s->keystr) > 2);
+ s->type = META;
s->seq = tolower((int) s->keystr[2]);
- } else if (s->type == FKEY) {
+ } else if (s->keystr[0] == 'F') {
assert(strlen(s->keystr) > 1);
s->seq = KEY_F0 + atoi(&s->keystr[1]);
} else /* RAWINPUT */
s->seq = (int) s->keystr[0];
/* Override some keys which don't bind as easily as we'd like. */
- if (s->type == CONTROL && (!strcasecmp(&s->keystr[1], "space")))
+ if (strcasecmp(s->keystr, "^Space") == 0)
s->seq = 0;
- else if (s->type == META && (!strcasecmp(&s->keystr[2], "space")))
+ else if (strcasecmp(s->keystr, "M-Space") == 0)
s->seq = (int) ' ';
- else if (s->type == RAWINPUT) {
+ else {
if (!strcasecmp(s->keystr, "Up"))
s->seq = KEY_UP;
else if (!strcasecmp(s->keystr, "Down"))
diff --git a/src/nano.h b/src/nano.h
@@ -188,7 +188,7 @@ typedef enum {
} update_type;
typedef enum {
- CONTROL, META, FKEY, RAWINPUT
+ DIRECT, META
} key_type;
typedef enum {
diff --git a/src/proto.h b/src/proto.h
@@ -362,7 +362,6 @@ size_t length_of_list(int menu);
const sc *first_sc_for(int menu, void (*func)(void));
int sc_seq_or(void (*func)(void), int defaultval);
functionptrtype func_from_key(int *kbinput);
-key_type strtokeytype(const char *str);
void assign_keyinfo(sc *s);
void print_sclist(void);
void shortcut_init(void);
diff --git a/src/rcfile.c b/src/rcfile.c
@@ -472,7 +472,6 @@ void parse_binding(char *ptr, bool dobind)
newsc->keystr = keycopy;
newsc->menus = menu;
- newsc->type = strtokeytype(newsc->keystr);
assign_keyinfo(newsc);
/* Do not allow rebinding the equivalent of the Escape key. */
diff --git a/src/winio.c b/src/winio.c
@@ -1563,7 +1563,7 @@ int get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
/* And put the corresponding key into the keyboard buffer. */
if (f != NULL) {
const sc *s = first_sc_for(currmenu, f->scfunc);
- unget_kbinput(s->seq, s->type == META, s->type == FKEY);
+ unget_kbinput(s->seq, s->type == META, s->type == DIRECT);
}
return 1;
} else