1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-14 05:33:03 +01:00

Disallow ctrl+m keybinding and revert to default settings on invalid bindings

Note: Ctrl+m uses the same control sequence as the enter key on many systems
This commit is contained in:
Jfreegman 2016-05-01 14:57:46 -04:00
parent 50f227418b
commit 32442b6286
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
2 changed files with 22 additions and 13 deletions

View File

@ -90,6 +90,7 @@ sounds = {
// Currently supported: Ctrl modified keys, Tab, PAGEUP and PAGEDOWN (case insensitive)
// Note: All printable keys register as input
// Note2: Ctrl+M does not work
keys = {
next_tab="Ctrl+P";
prev_tab="Ctrl+O";

View File

@ -230,11 +230,11 @@ static const struct sound_strings {
};
#endif
static int key_parse(const char** bind){
static int key_parse(const char **bind) {
int len = strlen(*bind);
if (len > 5) {
if(strncasecmp(*bind, "ctrl+", 5) == 0)
if(strncasecmp(*bind, "ctrl+", 5) == 0 && toupper(bind[0][5]) != 'M') /* ctrl+m cannot be used */
return toupper(bind[0][5]) - 'A' + 1;
}
@ -247,6 +247,14 @@ static int key_parse(const char** bind){
return -1;
}
static void set_key_binding(int *key, const char **bind) {
int code = key_parse(bind);
if (code != -1) {
*key = code;
}
}
int settings_load(struct user_settings *s, const char *patharg)
{
config_t cfg[1];
@ -383,27 +391,27 @@ int settings_load(struct user_settings *s, const char *patharg)
if ((setting = config_lookup(cfg, key_strings.self)) != NULL) {
const char* tmp = NULL;
if (config_setting_lookup_string(setting, key_strings.next_tab, &tmp))
s->key_next_tab = key_parse(&tmp);
set_key_binding(&s->key_next_tab, &tmp);
if (config_setting_lookup_string(setting, key_strings.prev_tab, &tmp))
s->key_prev_tab = key_parse(&tmp);
set_key_binding(&s->key_prev_tab, &tmp);
if (config_setting_lookup_string(setting, key_strings.scroll_line_up, &tmp))
s->key_scroll_line_up = key_parse(&tmp);
set_key_binding(&s->key_scroll_line_up, &tmp);
if (config_setting_lookup_string(setting, key_strings.scroll_line_down, &tmp))
s->key_scroll_line_down= key_parse(&tmp);
set_key_binding(&s->key_scroll_line_down, &tmp);
if (config_setting_lookup_string(setting, key_strings.half_page_up, &tmp))
s->key_half_page_up = key_parse(&tmp);
set_key_binding(&s->key_half_page_up, &tmp);
if (config_setting_lookup_string(setting, key_strings.half_page_down, &tmp))
s->key_half_page_down = key_parse(&tmp);
set_key_binding(&s->key_half_page_down, &tmp);
if (config_setting_lookup_string(setting, key_strings.page_bottom, &tmp))
s->key_page_bottom = key_parse(&tmp);
set_key_binding(&s->key_page_bottom, &tmp);
if (config_setting_lookup_string(setting, key_strings.peer_list_up, &tmp))
s->key_peer_list_up = key_parse(&tmp);
set_key_binding(&s->key_peer_list_up, &tmp);
if (config_setting_lookup_string(setting, key_strings.peer_list_down, &tmp))
s->key_peer_list_down = key_parse(&tmp);
set_key_binding(&s->key_peer_list_down, &tmp);
if (config_setting_lookup_string(setting, key_strings.toggle_peerlist, &tmp))
s->key_toggle_peerlist = key_parse(&tmp);
set_key_binding(&s->key_toggle_peerlist, &tmp);
if (config_setting_lookup_string(setting, key_strings.toggle_pastemode, &tmp))
s->key_toggle_pastemode = key_parse(&tmp);
set_key_binding(&s->key_toggle_pastemode, &tmp);
}
#ifdef AUDIO