Commit 5b0ab8be authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

shortcuts: remove any unnecessary classifying of keys

After initialization, the type of a key is never used nor needed
(other than for meta keys).
No related merge requests found
Showing with 11 additions and 24 deletions
+11 -24
...@@ -340,7 +340,6 @@ void add_to_sclist(int menus, const char *scstring, void (*func)(void), int togg ...@@ -340,7 +340,6 @@ void add_to_sclist(int menus, const char *scstring, void (*func)(void), int togg
if (toggle) if (toggle)
s->ordinal = ++counter; s->ordinal = ++counter;
s->keystr = (char *) scstring; s->keystr = (char *) scstring;
s->type = strtokeytype(scstring);
assign_keyinfo(s); assign_keyinfo(s);
#ifdef DEBUG #ifdef DEBUG
...@@ -400,41 +399,31 @@ functionptrtype func_from_key(int *kbinput) ...@@ -400,41 +399,31 @@ functionptrtype func_from_key(int *kbinput)
return NULL; 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. /* Assign the info to the shortcut struct.
* Assumes keystr is already assigned, naturally. */ * Assumes keystr is already assigned, naturally. */
void assign_keyinfo(sc *s) void assign_keyinfo(sc *s)
{ {
if (s->type == CONTROL) { s->type = DIRECT;
if (s->keystr[0] == '^') {
assert(strlen(s->keystr) > 1); assert(strlen(s->keystr) > 1);
s->seq = s->keystr[1] - 64; s->seq = s->keystr[1] - 64;
} else if (s->type == META) { } else if (s->keystr[0] == 'M') {
assert(strlen(s->keystr) > 2); assert(strlen(s->keystr) > 2);
s->type = META;
s->seq = tolower((int) s->keystr[2]); s->seq = tolower((int) s->keystr[2]);
} else if (s->type == FKEY) { } else if (s->keystr[0] == 'F') {
assert(strlen(s->keystr) > 1); assert(strlen(s->keystr) > 1);
s->seq = KEY_F0 + atoi(&s->keystr[1]); s->seq = KEY_F0 + atoi(&s->keystr[1]);
} else /* RAWINPUT */ } else /* RAWINPUT */
s->seq = (int) s->keystr[0]; s->seq = (int) s->keystr[0];
/* Override some keys which don't bind as easily as we'd like. */ /* 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; s->seq = 0;
else if (s->type == META && (!strcasecmp(&s->keystr[2], "space"))) else if (strcasecmp(s->keystr, "M-Space") == 0)
s->seq = (int) ' '; s->seq = (int) ' ';
else if (s->type == RAWINPUT) { else {
if (!strcasecmp(s->keystr, "Up")) if (!strcasecmp(s->keystr, "Up"))
s->seq = KEY_UP; s->seq = KEY_UP;
else if (!strcasecmp(s->keystr, "Down")) else if (!strcasecmp(s->keystr, "Down"))
......
...@@ -188,7 +188,7 @@ typedef enum { ...@@ -188,7 +188,7 @@ typedef enum {
} update_type; } update_type;
typedef enum { typedef enum {
CONTROL, META, FKEY, RAWINPUT DIRECT, META
} key_type; } key_type;
typedef enum { typedef enum {
......
...@@ -362,7 +362,6 @@ size_t length_of_list(int menu); ...@@ -362,7 +362,6 @@ size_t length_of_list(int menu);
const sc *first_sc_for(int menu, void (*func)(void)); const sc *first_sc_for(int menu, void (*func)(void));
int sc_seq_or(void (*func)(void), int defaultval); int sc_seq_or(void (*func)(void), int defaultval);
functionptrtype func_from_key(int *kbinput); functionptrtype func_from_key(int *kbinput);
key_type strtokeytype(const char *str);
void assign_keyinfo(sc *s); void assign_keyinfo(sc *s);
void print_sclist(void); void print_sclist(void);
void shortcut_init(void); void shortcut_init(void);
......
...@@ -472,7 +472,6 @@ void parse_binding(char *ptr, bool dobind) ...@@ -472,7 +472,6 @@ void parse_binding(char *ptr, bool dobind)
newsc->keystr = keycopy; newsc->keystr = keycopy;
newsc->menus = menu; newsc->menus = menu;
newsc->type = strtokeytype(newsc->keystr);
assign_keyinfo(newsc); assign_keyinfo(newsc);
/* Do not allow rebinding the equivalent of the Escape key. */ /* 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) ...@@ -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. */ /* And put the corresponding key into the keyboard buffer. */
if (f != NULL) { if (f != NULL) {
const sc *s = first_sc_for(currmenu, f->scfunc); 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; return 1;
} else } else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment