shortcuts: remove any unnecessary classifying of keys
After initialization, the type of a key is never used nor needed (other than for meta keys).master
parent
ecef093def
commit
5b0ab8be62
29
src/global.c
29
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"))
|
||||
|
|
|
@ -188,7 +188,7 @@ typedef enum {
|
|||
} update_type;
|
||||
|
||||
typedef enum {
|
||||
CONTROL, META, FKEY, RAWINPUT
|
||||
DIRECT, META
|
||||
} key_type;
|
||||
|
||||
typedef enum {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue