diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-command.c | 74 | ||||
-rw-r--r-- | src/core/wee-completion.c | 29 | ||||
-rw-r--r-- | src/core/wee-config.c | 93 | ||||
-rw-r--r-- | src/core/wee-config.h | 2 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-key.c | 318 | ||||
-rw-r--r-- | src/gui/gui-key.c | 338 | ||||
-rw-r--r-- | src/gui/gui-key.h | 8 | ||||
-rw-r--r-- | src/plugins/buflist/buflist.c | 22 | ||||
-rw-r--r-- | src/plugins/fset/fset-buffer.c | 31 | ||||
-rw-r--r-- | src/plugins/relay/relay-buffer.c | 4 | ||||
-rw-r--r-- | src/plugins/script/script-buffer.c | 26 | ||||
-rw-r--r-- | src/plugins/xfer/xfer-buffer.c | 4 |
12 files changed, 461 insertions, 488 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 7395c47f0..4232384c2 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -3480,14 +3480,6 @@ COMMAND_CALLBACK(input) gui_input_undo (buffer); else if (string_strcmp (argv[1], "redo") == 0) gui_input_redo (buffer); - else if (string_strcmp (argv[1], "paste_start") == 0) - { - /* do nothing here */ - } - else if (string_strcmp (argv[1], "paste_stop") == 0) - { - /* do nothing here */ - } else { /* @@ -3759,25 +3751,10 @@ COMMAND_CALLBACK(item) void command_key_display (struct t_gui_key *key, struct t_gui_key *default_key) { - char *expanded_name, str_key_name[1024]; - - str_key_name[0] = '\0'; - if (key->key_name && (strcmp (key->key, key->key_name) != 0)) - { - snprintf (str_key_name, sizeof (str_key_name), - "%s -> %s%s", - GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), - GUI_COLOR(GUI_COLOR_CHAT), - key->key_name); - } - - expanded_name = gui_key_expand_legacy (key->key); - if (default_key) { - gui_chat_printf (NULL, " %s%s%s => %s%s %s(%s%s %s%s)", - (expanded_name) ? expanded_name : key->key, - str_key_name, + gui_chat_printf (NULL, " %s%s => %s%s %s(%s%s %s%s)", + key->key, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), GUI_COLOR(GUI_COLOR_CHAT), key->command, @@ -3789,16 +3766,12 @@ command_key_display (struct t_gui_key *key, struct t_gui_key *default_key) } else { - gui_chat_printf (NULL, " %s%s%s => %s%s", - (expanded_name) ? expanded_name : key->key, - str_key_name, + gui_chat_printf (NULL, " %s%s => %s%s", + key->key, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), GUI_COLOR(GUI_COLOR_CHAT), key->command); } - - if (expanded_name) - free (expanded_name); } /* @@ -3919,19 +3892,11 @@ command_key_display_listdiff (int context) int command_key_reset (int context, const char *key) { - char *internal_code; struct t_gui_key *ptr_key, *ptr_default_key, *ptr_new_key; int rc; - internal_code = gui_key_get_internal_code (key); - if (!internal_code) - return WEECHAT_RC_ERROR; - - ptr_key = gui_key_search (gui_keys[context], - internal_code); - ptr_default_key = gui_key_search (gui_default_keys[context], - internal_code); - free (internal_code); + ptr_key = gui_key_search (gui_keys[context], key); + ptr_default_key = gui_key_search (gui_default_keys[context], key); if (ptr_key || ptr_default_key) { @@ -4007,7 +3972,6 @@ command_key_reset (int context, const char *key) COMMAND_CALLBACK(key) { - char *internal_code; struct t_gui_key *ptr_new_key; int old_keys_count, keys_added, i, context, rc; @@ -4078,13 +4042,8 @@ COMMAND_CALLBACK(key) /* display a key binding */ if (argc == 3) { - ptr_new_key = NULL; - internal_code = gui_key_get_internal_code (argv[2]); - if (internal_code) - { - ptr_new_key = gui_key_search (gui_keys[GUI_KEY_CONTEXT_DEFAULT], - internal_code); - } + ptr_new_key = gui_key_search (gui_keys[GUI_KEY_CONTEXT_DEFAULT], + argv[2]); if (ptr_new_key) { gui_chat_printf (NULL, ""); @@ -4096,8 +4055,6 @@ COMMAND_CALLBACK(key) gui_chat_printf (NULL, _("No key found")); } - if (internal_code) - free (internal_code); return WEECHAT_RC_OK; } @@ -4149,11 +4106,7 @@ COMMAND_CALLBACK(key) /* display a key binding */ if (argc == 4) { - ptr_new_key = NULL; - internal_code = gui_key_get_internal_code (argv[3]); - if (internal_code) - ptr_new_key = gui_key_search (gui_keys[context], - internal_code); + ptr_new_key = gui_key_search (gui_keys[context], argv[3]); if (ptr_new_key) { gui_chat_printf (NULL, ""); @@ -4165,8 +4118,6 @@ COMMAND_CALLBACK(key) gui_chat_printf (NULL, _("No key found")); } - if (internal_code) - free (internal_code); return WEECHAT_RC_OK; } @@ -8282,8 +8233,6 @@ command_init () " insert: insert text in command line (escaped chars are allowed, " "see /help print)\n" " send: send text to the buffer\n" - " paste_start: start paste (bracketed paste mode)\n" - " paste_stop: stop paste (bracketed paste mode)\n" "\n" "This command is used by key bindings or plugins."), "return || " @@ -8302,8 +8251,7 @@ command_init () "history_previous || history_next || history_global_previous || " "history_global_next || " "grab_key || grab_key_command || grab_mouse || grab_mouse_area || " - "insert || send || " - "paste_start || paste_stop", + "insert || send", &command_input, NULL, NULL); hook_command ( NULL, "item", @@ -8433,7 +8381,7 @@ command_init () " restore default binding for key alt-r:\n" " /key reset meta-r\n" " key \"tab\" to stop search in buffer:\n" - " /key bindctxt search ctrl-i /input search_stop\n" + " /key bindctxt search tab /input search_stop\n" " middle button of mouse on a nick to retrieve info on nick:\n" " /key bindctxt mouse @item(buffer_nicklist):button3 " "/msg nickserv info ${nick}"), diff --git a/src/core/wee-completion.c b/src/core/wee-completion.c index 85274f8e6..4c5fbb12d 100644 --- a/src/core/wee-completion.c +++ b/src/core/wee-completion.c @@ -1677,7 +1677,6 @@ completion_list_add_keys_codes_cb (const void *pointer, void *data, { int i; struct t_gui_key *ptr_key; - char *expanded_name; /* make C compiler happy */ (void) pointer; @@ -1689,13 +1688,8 @@ completion_list_add_keys_codes_cb (const void *pointer, void *data, { for (ptr_key = gui_keys[i]; ptr_key; ptr_key = ptr_key->next_key) { - expanded_name = gui_key_expand_legacy (ptr_key->key); - gui_completion_list_add ( - completion, - (expanded_name) ? expanded_name : ptr_key->key, - 0, WEECHAT_LIST_POS_SORT); - if (expanded_name) - free (expanded_name); + gui_completion_list_add (completion, ptr_key->key, + 0, WEECHAT_LIST_POS_SORT); } } @@ -1715,7 +1709,6 @@ completion_list_add_keys_codes_for_reset_cb (const void *pointer, void *data, { int i; struct t_gui_key *ptr_key, *ptr_default_key; - char *expanded_name; /* make C compiler happy */ (void) pointer; @@ -1732,13 +1725,8 @@ completion_list_add_keys_codes_for_reset_cb (const void *pointer, void *data, if (!ptr_default_key || (strcmp (ptr_default_key->command, ptr_key->command) != 0)) { - expanded_name = gui_key_expand_legacy (ptr_key->key); - gui_completion_list_add ( - completion, - (expanded_name) ? expanded_name : ptr_key->key, - 0, WEECHAT_LIST_POS_SORT); - if (expanded_name) - free (expanded_name); + gui_completion_list_add (completion, ptr_key->key, + 0, WEECHAT_LIST_POS_SORT); } } @@ -1749,13 +1737,8 @@ completion_list_add_keys_codes_for_reset_cb (const void *pointer, void *data, ptr_key = gui_key_search (gui_keys[i], ptr_default_key->key); if (!ptr_key) { - expanded_name = gui_key_expand_legacy (ptr_default_key->key); - gui_completion_list_add ( - completion, - (expanded_name) ? expanded_name : ptr_default_key->key, - 0, WEECHAT_LIST_POS_SORT); - if (expanded_name) - free (expanded_name); + gui_completion_list_add (completion, ptr_default_key->key, + 0, WEECHAT_LIST_POS_SORT); } } } diff --git a/src/core/wee-config.c b/src/core/wee-config.c index a0a34c196..8aec0eb66 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -1493,6 +1493,79 @@ config_weechat_init_after_read () } /* + * Updates options in configuration file while reading the file. + */ + +struct t_hashtable * +config_weechat_update_cb (const void *pointer, void *data, + struct t_config_file *config_file, + int version_read, + struct t_hashtable *data_read) +{ + const char *ptr_section, *ptr_option; + char *new_option; + int changes; + + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) config_file; + + /* nothing to do if we're already an up-to-date config file */ + if (version_read >= WEECHAT_CONFIG_VERSION) + return NULL; + + changes = 0; + + if (version_read < 2) + { + /* + * changes in v2: + * - new format for keys (eg: meta2-1;3D -> meta-left) + * - keys removed: "meta2-200~" and "meta2-201~" + */ + ptr_section = hashtable_get (data_read, "section"); + ptr_option = hashtable_get (data_read, "option"); + if (ptr_section + && ptr_option + && ((strcmp (ptr_section, "key") == 0) + || (strcmp (ptr_section, "key_search") == 0) + || (strcmp (ptr_section, "key_cursor") == 0) + || (strcmp (ptr_section, "key_mouse") == 0))) + { + if ((strcmp (ptr_option, "meta2-200~") == 0) + || (strcmp (ptr_option, "meta2-201~") == 0)) + { + gui_chat_printf (NULL, + _("Legacy key removed: \"%s\""), + ptr_option); + hashtable_set (data_read, "option", ""); + changes++; + } + else + { + new_option = gui_key_legacy_to_alias (ptr_option); + if (new_option) + { + if (strcmp (ptr_option, new_option) != 0) + { + gui_chat_printf ( + NULL, + _("Legacy key converted: \"%s\" => \"%s\""), + ptr_option, new_option); + hashtable_set (data_read, "option", new_option); + changes++; + } + free (new_option); + } + } + } + } + + return (changes) ? data_read : NULL; +} + +/* * Reloads WeeChat configuration file. * * Returns: @@ -2582,8 +2655,8 @@ config_weechat_key_write_cb (const void *pointer, void *data, const char *section_name) { struct t_gui_key *ptr_key; - char *pos, *expanded_name; - int rc, context; + char *pos; + int context; /* make C compiler happy */ (void) pointer; @@ -2602,17 +2675,10 @@ config_weechat_key_write_cb (const void *pointer, void *data, } for (ptr_key = gui_keys[context]; ptr_key; ptr_key = ptr_key->next_key) { - expanded_name = gui_key_expand_legacy (ptr_key->key); - if (expanded_name) + if (!config_file_write_line (config_file, ptr_key->key, + "\"%s\"", ptr_key->command)) { - rc = config_file_write_line (config_file, - (expanded_name) ? - expanded_name : ptr_key->key, - "\"%s\"", - ptr_key->command); - free (expanded_name); - if (!rc) - return WEECHAT_CONFIG_WRITE_ERROR; + return WEECHAT_CONFIG_WRITE_ERROR; } } @@ -2639,6 +2705,9 @@ config_weechat_init_options () if (!weechat_config_file) return 0; + config_file_set_version (weechat_config_file, WEECHAT_CONFIG_VERSION, + &config_weechat_update_cb, NULL, NULL); + /* debug */ ptr_section = config_file_new_section ( weechat_config_file, "debug", diff --git a/src/core/wee-config.h b/src/core/wee-config.h index cb38034fc..921a06203 100644 --- a/src/core/wee-config.h +++ b/src/core/wee-config.h @@ -31,6 +31,8 @@ struct t_gui_buffer; #define WEECHAT_CONFIG_NAME "weechat" #define WEECHAT_CONFIG_PRIO_NAME "110000|weechat" +#define WEECHAT_CONFIG_VERSION 2 + #define TAB_MAX_WIDTH 64 enum t_config_look_align_end_of_lines diff --git a/src/gui/curses/gui-curses-key.c b/src/gui/curses/gui-curses-key.c index 654934483..87b022f5b 100644 --- a/src/gui/curses/gui-curses-key.c +++ b/src/gui/curses/gui-curses-key.c @@ -56,17 +56,10 @@ void gui_key_default_bind (int context, const char *key, const char *command) { struct t_gui_key *ptr_key; - char *internal_code; - internal_code = gui_key_get_internal_code (key); - if (!internal_code) - return; - - ptr_key = gui_key_search (gui_keys[context], internal_code); + ptr_key = gui_key_search (gui_keys[context], key); if (!ptr_key) gui_key_new (NULL, context, key, command); - - free (internal_code); } /* @@ -81,199 +74,154 @@ gui_key_default_bindings (int context) if (context == GUI_KEY_CONTEXT_DEFAULT) { - BIND(/* <enter> */ "ctrl-m", "/input return"); - BIND(/* <enter> */ "ctrl-j", "/input return"); - BIND(/* m-<enter> */ "meta-ctrl-m", "/input insert \\n"); - BIND(/* <tab> */ "ctrl-i", "/input complete_next"); - BIND(/* s-<tab> */ "meta2-Z", "/input complete_previous"); - BIND(/* ^r */ "ctrl-r", "/input search_text_here"); - BIND(/* <backspace> */ "ctrl-h", "/input delete_previous_char"); - BIND(/* <backspace> */ "ctrl-?", "/input delete_previous_char"); - BIND(/* ^_ */ "ctrl-_", "/input undo"); - BIND(/* m-_ */ "meta-_", "/input redo"); - BIND(/* <del> */ "meta2-3~", "/input delete_next_char"); - BIND(/* ^d */ "ctrl-d", "/input delete_next_char"); - BIND(/* ^w */ "ctrl-w", "/input delete_previous_word_whitespace"); - BIND(/* m-<backspace> */ "meta-ctrl-?", "/input delete_previous_word"); - BIND(/* ^x */ "ctrl-x", "/buffer switch"); - BIND(/* m-x */ "meta-x", "/buffer zoom"); - BIND(/* m-d */ "meta-d", "/input delete_next_word"); - BIND(/* ^k */ "ctrl-k", "/input delete_end_of_line"); - BIND(/* m-r */ "meta-r", "/input delete_line"); - BIND(/* ^t */ "ctrl-t", "/input transpose_chars"); - BIND(/* ^u */ "ctrl-u", "/input delete_beginning_of_line"); - BIND(/* ^y */ "ctrl-y", "/input clipboard_paste"); - BIND(/* <home> */ "meta2-1~", "/input move_beginning_of_line"); - BIND(/* <home> */ "meta2-H", "/input move_beginning_of_line"); - BIND(/* <home> */ "meta2-7~", "/input move_beginning_of_line"); - BIND(/* <home> */ "meta-OH", "/input move_beginning_of_line"); - BIND(/* ^a */ "ctrl-a", "/input move_beginning_of_line"); - BIND(/* <end> */ "meta2-4~", "/input move_end_of_line"); - BIND(/* <end> */ "meta2-F", "/input move_end_of_line"); - BIND(/* <end> */ "meta2-8~", "/input move_end_of_line"); - BIND(/* <end> */ "meta-OF", "/input move_end_of_line"); - BIND(/* ^e */ "ctrl-e", "/input move_end_of_line"); - BIND(/* <left> */ "meta2-D", "/input move_previous_char"); - BIND(/* ^b */ "ctrl-b", "/input move_previous_char"); - BIND(/* <right> */ "meta2-C", "/input move_next_char"); - BIND(/* ^f */ "ctrl-f", "/input move_next_char"); - BIND(/* m-b */ "meta-b", "/input move_previous_word"); - BIND(/* ^<left> */ "meta-Od", "/input move_previous_word"); - BIND(/* ^<left> */ "meta-OD", "/input move_previous_word"); - BIND(/* ^<left> */ "meta2-1;5D", "/input move_previous_word"); - BIND(/* m-f */ "meta-f", "/input move_next_word"); - BIND(/* ^<right> */ "meta-Oc", "/input move_next_word"); - BIND(/* ^<right> */ "meta-OC", "/input move_next_word"); - BIND(/* ^<right> */ "meta2-1;5C", "/input move_next_word"); - BIND(/* <up> */ "meta2-A", "/input history_previous"); - BIND(/* <down> */ "meta2-B", "/input history_next"); - BIND(/* ^<up> */ "meta-Oa", "/input history_global_previous"); - BIND(/* ^<up> */ "meta-OA", "/input history_global_previous"); - BIND(/* ^<up> */ "meta2-1;5A", "/input history_global_previous"); - BIND(/* ^<down> */ "meta-Ob", "/input history_global_next"); - BIND(/* ^<down> */ "meta-OB", "/input history_global_next"); - BIND(/* ^<down> */ "meta2-1;5B", "/input history_global_next"); - BIND(/* m-a */ "meta-a", "/buffer jump smart"); - BIND(/* m-j,m-f */ "meta-jmeta-f", "/buffer -"); - BIND(/* m-j,m-l */ "meta-jmeta-l", "/buffer +"); - BIND(/* m-j,m-r */ "meta-jmeta-r", "/server raw"); - BIND(/* m-j,m-s */ "meta-jmeta-s", "/server jump"); - BIND(/* m-h,m-c */ "meta-hmeta-c", "/hotlist clear"); - BIND(/* m-h,m-m */ "meta-hmeta-m", "/hotlist remove"); - BIND(/* m-h,m-r */ "meta-hmeta-r", "/hotlist restore"); - BIND(/* m-h,m-R */ "meta-hmeta-R", "/hotlist restore -all"); - BIND(/* m-k */ "meta-k", "/input grab_key_command"); - BIND(/* m-s */ "meta-s", "/mute spell toggle"); - BIND(/* m-u */ "meta-u", "/window scroll_unread"); - BIND(/* ^s^u */ "ctrl-sctrl-u", "/allbuf /buffer set unread"); - BIND(/* ^cb */ "ctrl-cb", "/input insert \\x02"); - BIND(/* ^cc */ "ctrl-cc", "/input insert \\x03"); - BIND(/* ^ci */ "ctrl-ci", "/input insert \\x1D"); - BIND(/* ^co */ "ctrl-co", "/input insert \\x0F"); - BIND(/* ^cv */ "ctrl-cv", "/input insert \\x16"); - BIND(/* ^c_ */ "ctrl-c_", "/input insert \\x1F"); - BIND(/* m-<right> */ "meta-meta2-C", "/buffer +1"); - BIND(/* m-<right> */ "meta2-1;3C", "/buffer +1"); - BIND(/* m-<down> */ "meta-meta2-B", "/buffer +1"); - BIND(/* m-<down> */ "meta2-1;3B", "/buffer +1"); - BIND(/* <f6> */ "meta2-17~", "/buffer +1"); - BIND(/* ^n */ "ctrl-n", "/buffer +1"); - BIND(/* m-<left> */ "meta-meta2-D", "/buffer -1"); - BIND(/* m-<left> */ "meta2-1;3D", "/buffer -1"); - BIND(/* m-<up> */ "meta-meta2-A", "/buffer -1"); - BIND(/* m-<up> */ "meta2-1;3A", "/buffer -1"); - BIND(/* <f5> */ "meta2-15~", "/buffer -1"); - BIND(/* <f5> */ "meta2-[E", "/buffer -1"); - BIND(/* ^p */ "ctrl-p", "/buffer -1"); - BIND(/* <pgup> */ "meta2-5~", "/window page_up"); - BIND(/* <pgup> */ "meta2-I", "/window page_up"); - BIND(/* <pgdn> */ "meta2-6~", "/window page_down"); - BIND(/* <pgdn> */ "meta2-G", "/window page_down"); - BIND(/* m-<pgup> */ "meta-meta2-5~", "/window scroll_up"); - BIND(/* m-<pgup> */ "meta2-5;3~", "/window scroll_up"); - BIND(/* m-<pgdn> */ "meta-meta2-6~", "/window scroll_down"); - BIND(/* m-<pgdn> */ "meta2-6;3~", "/window scroll_down"); - BIND(/* m-<home> */ "meta-meta2-1~", "/window scroll_top"); - BIND(/* m-<home> */ "meta-meta2-7~", "/window scroll_top"); - BIND(/* m-<home> */ "meta2-1;3H", "/window scroll_top"); - BIND(/* m-<end> */ "meta-meta2-4~", "/window scroll_bottom"); - BIND(/* m-<end> */ "meta-meta2-8~", "/window scroll_bottom"); - BIND(/* m-<end> */ "meta2-1;3F", "/window scroll_bottom"); - BIND(/* m-n */ "meta-n", "/window scroll_next_highlight"); - BIND(/* m-p */ "meta-p", "/window scroll_previous_highlight"); - BIND(/* m-N */ "meta-N", "/bar toggle nicklist"); - BIND(/* <f9> */ "meta2-20~", "/bar scroll title * -30%"); - BIND(/* <f10> */ "meta2-21~", "/bar scroll title * +30%"); - BIND(/* <f11> */ "meta2-23~", "/bar scroll nicklist * -100%"); - BIND(/* <f12> */ "meta2-24~", "/bar scroll nicklist * +100%"); - BIND(/* c-<f11> */ "meta2-23^", "/bar scroll nicklist * -100%"); - BIND(/* c-<f11> */ "meta2-23;5~", "/bar scroll nicklist * -100%"); - BIND(/* c-<f12> */ "meta2-24^", "/bar scroll nicklist * +100%"); - BIND(/* c-<f12> */ "meta2-24;5~", "/bar scroll nicklist * +100%"); - BIND(/* m-<f11> */ "meta2-23;3~", "/bar scroll nicklist * b"); - BIND(/* m-<f11> */ "meta-meta2-23~", "/bar scroll nicklist * b"); - BIND(/* m-<f12> */ "meta2-24;3~", "/bar scroll nicklist * e"); - BIND(/* m-<f12> */ "meta-meta2-24~", "/bar scroll nicklist * e"); - BIND(/* ^l */ "ctrl-l", "/window refresh"); - BIND(/* <f7> */ "meta2-18~", "/window -1"); - BIND(/* <f8> */ "meta2-19~", "/window +1"); - BIND(/* m-w,m-<up> */ "meta-wmeta-meta2-A", "/window up"); - BIND(/* m-w,m-<up> */ "meta-wmeta2-1;3A", "/window up"); - BIND(/* m-w,m-<down> */ "meta-wmeta-meta2-B", "/window down"); - BIND(/* m-w,m-<down> */ "meta-wmeta2-1;3B", "/window down"); - BIND(/* m-w,m-<right> */ "meta-wmeta-meta2-C", "/window right"); - BIND(/* m-w,m-<right> */ "meta-wmeta2-1;3C", "/window right"); - BIND(/* m-w,m-<left> */ "meta-wmeta-meta2-D", "/window left"); - BIND(/* m-w,m-<left> */ "meta-wmeta2-1;3D", "/window left"); - BIND(/* m-w,m-b */ "meta-wmeta-b", "/window balance"); - BIND(/* m-w,m-s */ "meta-wmeta-s", "/window swap"); - BIND(/* m-z */ "meta-z", "/window zoom"); - BIND(/* m-= */ "meta-=", "/filter toggle"); - BIND(/* m-- */ "meta--", "/filter toggle @"); - BIND(/* m-0 */ "meta-0", "/buffer *10"); - BIND(/* m-1 */ "meta-1", "/buffer *1"); - BIND(/* m-2 */ "meta-2", "/buffer *2"); - BIND(/* m-3 */ "meta-3", "/buffer *3"); - BIND(/* m-4 */ "meta-4", "/buffer *4"); - BIND(/* m-5 */ "meta-5", "/buffer *5"); - BIND(/* m-6 */ "meta-6", "/buffer *6"); - BIND(/* m-7 */ "meta-7", "/buffer *7"); - BIND(/* m-8 */ "meta-8", "/buffer *8"); - BIND(/* m-9 */ "meta-9", "/buffer *9"); - BIND(/* m-< */ "meta-<", "/buffer jump prev_visited"); - BIND(/* m-> */ "meta->", "/buffer jump next_visited"); - BIND(/* m-/ */ "meta-/", "/buffer jump last_displayed"); - BIND(/* m-l */ "meta-l", "/window bare"); - BIND(/* m-m */ "meta-m", "/mute mouse toggle"); - BIND(/* start paste */ "meta2-200~", "/input paste_start"); - BIND(/* end paste */ "meta2-201~", "/input paste_stop"); + BIND("return", "/input return"); + BIND("meta-return", "/input insert \\n"); + BIND("tab", "/input complete_next"); + BIND("shift-tab", "/input complete_previous"); + BIND("ctrl-r", "/input search_text_here"); + BIND("backspace", "/input delete_previous_char"); + BIND("ctrl-_", "/input undo"); + BIND("meta-_", "/input redo"); + BIND("delete", "/input delete_next_char"); + BIND("ctrl-d", "/input delete_next_char"); + BIND("ctrl-w", "/input delete_previous_word_whitespace"); + BIND("meta-backspace", "/input delete_previous_word"); + BIND("ctrl-x", "/buffer switch"); + BIND("meta-x", "/buffer zoom"); + BIND("meta-d", "/input delete_next_word"); + BIND("ctrl-k", "/input delete_end_of_line"); + BIND("meta-r", "/input delete_line"); + BIND("ctrl-t", "/input transpose_chars"); + BIND("ctrl-u", "/input delete_beginning_of_line"); + BIND("ctrl-y", "/input clipboard_paste"); + BIND("home", "/input move_beginning_of_line"); + BIND("ctrl-a", "/input move_beginning_of_line"); + BIND("end", "/input move_end_of_line"); + BIND("ctrl-e", "/input move_end_of_line"); + BIND("left", "/input move_previous_char"); + BIND("ctrl-b", "/input move_previous_char"); + BIND("right", "/input move_next_char"); + BIND("ctrl-f", "/input move_next_char"); + BIND("meta-b", "/input move_previous_word"); + BIND("ctrl-left", "/input move_previous_word"); + BIND("meta-f", "/input move_next_word"); + BIND("ctrl-right", "/input move_next_word"); + BIND("up", "/input history_previous"); + BIND("down", "/input history_next"); + BIND("ctrl-up", "/input history_global_previous"); + BIND("ctrl-down", "/input history_global_next"); + BIND("meta-a", "/buffer jump smart"); + BIND("meta-j,meta-f", "/buffer -"); + BIND("meta-j,meta-l", "/buffer +"); + BIND("meta-j,meta-r", "/server raw"); + BIND("meta-j,meta-s", "/server jump"); + BIND("meta-h,meta-c", "/hotlist clear"); + BIND("meta-h,meta-m", "/hotlist remove"); + BIND("meta-h,meta-r", "/hotlist restore"); + BIND("meta-h,meta-R", "/hotlist restore -all"); + BIND("meta-k", "/input grab_key_command"); + BIND("meta-s", "/mute spell toggle"); + BIND("meta-u", "/window scroll_unread"); + BIND("ctrl-s,ctrl-u", "/allbuf /buffer set unread"); + BIND("ctrl-c,b", "/input insert \\x02"); + BIND("ctrl-c,c", "/input insert \\x03"); + BIND("ctrl-c,i", "/input insert \\x1D"); + BIND("ctrl-c,o", "/input insert \\x0F"); + BIND("ctrl-c,v", "/input insert \\x16"); + BIND("ctrl-c,_", "/input insert \\x1F"); + BIND("meta-right", "/buffer +1"); + BIND("meta-down", "/buffer +1"); + BIND("f6", "/buffer +1"); + BIND("ctrl-n", "/buffer +1"); + BIND("meta-left", "/buffer -1"); + BIND("meta-up", "/buffer -1"); + BIND("f5", "/buffer -1"); + BIND("ctrl-p", "/buffer -1"); + BIND("pgup", "/window page_up"); + BIND("pgdn", "/window page_down"); + BIND("meta-pgup", "/window scroll_up"); + BIND("meta-pgdn", "/window scroll_down"); + BIND("meta-home", "/window scroll_top"); + BIND("meta-end", "/window scroll_bottom"); + BIND("meta-n", "/window scroll_next_highlight"); + BIND("meta-p", "/window scroll_previous_highlight"); + BIND("meta-N", "/bar toggle nicklist"); + BIND("f9", "/bar scroll title * -30%"); + BIND("f10", "/bar scroll title * +30%"); + BIND("f11", "/bar scroll nicklist * -100%"); + BIND("f12", "/bar scroll nicklist * +100%"); + BIND("ctrl-f11", "/bar scroll nicklist * -100%"); + BIND("ctrl-f12", "/bar scroll nicklist * +100%"); + BIND("meta-f11", "/bar scroll nicklist * b"); + BIND("meta-f12", "/bar scroll nicklist * e"); + BIND("ctrl-l", "/window refresh"); + BIND("f7", "/window -1"); + BIND("f8", "/window +1"); + BIND("meta-w,meta-up", "/window up"); + BIND("meta-w,meta-down", "/window down"); + BIND("meta-w,meta-right", "/window right"); + BIND("meta-w,meta-left", "/window left"); + BIND("meta-w,meta-b", "/window balance"); + BIND("meta-w,meta-s", "/window swap"); + BIND("meta-z", "/window zoom"); + BIND("meta-=", "/filter toggle"); + BIND("meta--", "/filter toggle @"); + BIND("meta-0", "/buffer *10"); + BIND("meta-1", "/buffer *1"); + BIND("meta-2", "/buffer *2"); + BIND("meta-3", "/buffer *3"); + BIND("meta-4", "/buffer *4"); + BIND("meta-5", "/buffer *5"); + BIND("meta-6", "/buffer *6"); + BIND("meta-7", "/buffer *7"); + BIND("meta-8", "/buffer *8"); + BIND("meta-9", "/buffer *9"); + BIND("meta-<", "/buffer jump prev_visited"); + BIND("meta->", "/buffer jump next_visited"); + BIND("meta-/", "/buffer jump last_displayed"); + BIND("meta-l", "/window bare"); + BIND("meta-m", "/mute mouse toggle"); /* bind meta-j + {01..99} to switch to buffers # > 10 */ for (i = 1; i < 100; i++) { - snprintf (key_str, sizeof (key_str), "meta-j%02d", i); + snprintf (key_str, sizeof (key_str), "meta-j,%1d,%1d", i / 10, i % 10); snprintf (command, sizeof (command), "/buffer *%d", i); BIND(key_str, command); } } else if (context == GUI_KEY_CONTEXT_SEARCH) { - BIND(/* <enter> */ "ctrl-m", "/input search_stop_here"); - BIND(/* <enter> */ "ctrl-j", "/input search_stop_here"); - BIND(/* ^q */ "ctrl-q", "/input search_stop"); - BIND(/* m-c */ "meta-c", "/input search_switch_case"); - BIND(/* ^r */ "ctrl-r", "/input search_switch_regex"); - BIND(/* <tab> */ "ctrl-i", "/input search_switch_where"); - BIND(/* <up> */ "meta2-A", "/input search_previous"); - BIND(/* <down> */ "meta2-B", "/input search_next"); + BIND("return", "/input search_stop_here"); + BIND("ctrl-q", "/input search_stop"); + BIND("meta-c", "/input search_switch_case"); + BIND("ctrl-r", "/input search_switch_regex"); + BIND("tab", "/input search_switch_where"); + BIND("up", "/input search_previous"); + BIND("down", "/input search_next"); } else if (context == GUI_KEY_CONTEXT_CURSOR) { /* general & move */ - BIND(/* <enter> */ "ctrl-m", "/cursor stop"); - BIND(/* <enter> */ "ctrl-j", "/cursor stop"); - BIND(/* <up> */ "meta2-A", "/cursor move up"); - BIND(/* <down> */ "meta2-B", "/cursor move down"); - BIND(/* <left> */ "meta2-D", "/cursor move left"); - BIND(/* <right> */ "meta2-C", "/cursor move right"); - BIND(/* m-<up> */ "meta-meta2-A", "/cursor move area_up"); - BIND(/* m-<up> */ "meta2-1;3A", "/cursor move area_up"); - BIND(/* m-<down> */ "meta-meta2-B", "/cursor move area_down"); - BIND(/* m-<down> */ "meta2-1;3B", "/cursor move area_down"); - BIND(/* m-<left> */ "meta-meta2-D", "/cursor move area_left"); - BIND(/* m-<left> */ "meta2-1;3D", "/cursor move area_left"); - BIND(/* m-<right> */ "meta-meta2-C", "/cursor move area_right"); - BIND(/* m-<right> */ "meta2-1;3C", "/cursor move area_right"); + BIND("return", "/cursor stop"); + BIND("up", "/cursor move up"); + BIND("down", "/cursor move down"); + BIND("left", "/cursor move left"); + BIND("right", "/cursor move right"); + BIND("meta-up", "/cursor move area_up"); + BIND("meta-down", "/cursor move area_down"); + BIND("meta-left", "/cursor move area_left"); + BIND("meta-right","/cursor move area_right"); /* chat */ - BIND(/* m */ "@chat:m", "hsignal:chat_quote_message;/cursor stop"); - BIND(/* q */ "@chat:q", "hsignal:chat_quote_prefix_message;/cursor stop"); - BIND(/* Q */ "@chat:Q", "hsignal:chat_quote_time_prefix_message;/cursor stop"); + BIND("@chat:m", "hsignal:chat_quote_message;/cursor stop"); + BIND("@chat:q", "hsignal:chat_quote_prefix_message;/cursor stop"); + BIND("@chat:Q", "hsignal:chat_quote_time_prefix_message;/cursor stop"); /* nicklist */ - BIND(/* b */ "@item(buffer_nicklist):b", "/window ${_window_number};/ban ${nick}"); - BIND(/* k */ "@item(buffer_nicklist):k", "/window ${_window_number};/kick ${nick}"); - BIND(/* K */ "@item(buffer_nicklist):K", "/window ${_window_number};/kickban ${nick}"); - BIND(/* q */ "@item(buffer_nicklist):q", "/window ${_window_number};/query ${nick};/cursor stop"); - BIND(/* w */ "@item(buffer_nicklist):w", "/window ${_window_number};/whois ${nick}"); + BIND("@item(buffer_nicklist):b", "/window ${_window_number};/ban ${nick}"); + BIND("@item(buffer_nicklist):k", "/window ${_window_number};/kick ${nick}"); + BIND("@item(buffer_nicklist):K", "/window ${_window_number};/kickban ${nick}"); + BIND("@item(buffer_nicklist):q", "/window ${_window_number};/query ${nick};/cursor stop"); + BIND("@item(buffer_nicklist):w", "/window ${_window_number};/whois ${nick}"); } else if (context == GUI_KEY_CONTEXT_MOUSE) { diff --git a/src/gui/gui-key.c b/src/gui/gui-key.c index 3cd12ae92..ab4515f18 100644 --- a/src/gui/gui-key.c +++ b/src/gui/gui-key.c @@ -70,6 +70,12 @@ char *gui_key_context_string[GUI_KEY_NUM_CONTEXTS] = char *gui_key_focus_string[GUI_KEY_NUM_FOCUS] = { "*", "chat", "bar", "item" }; +char *gui_key_safe_list[] = +{ "ctrl-", "meta-", "meta2-", "shift-", "f0", "f1", "f2", "f3", "f4", "f5", + "f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", "f16", + "f17", "f18", "f19", "f20", "home", "insert", "delete", "end", "pgup", + "pgdn", "up", "down", "right", "left", "tab", NULL }; + int gui_key_debug = 0; /* 1 for key debug: display raw codes, */ /* do not execute associated actions */ @@ -202,11 +208,11 @@ gui_key_grab_init (int grab_command, const char *delay) */ int -gui_key_grab_end_timer_cb (const void *pointer, void *data, - int remaining_calls) +gui_key_grab_end_timer_cb (const void *pointer, void *data, int remaining_calls) { - char *expanded_key, *expanded_key2; + char *key_name, *key_name_alias, *key_utf8; struct t_gui_key *ptr_key; + int rc; /* make C compiler happy */ (void) pointer; @@ -214,38 +220,56 @@ gui_key_grab_end_timer_cb (const void *pointer, void *data, (void) remaining_calls; /* get expanded name (for example: \x01+U => ctrl-u) */ - expanded_key = gui_key_expand_legacy (gui_key_combo_buffer); - if (expanded_key) + rc = gui_key_expand (gui_key_combo_buffer, &key_name, &key_name_alias); + if (rc && key_name && key_name_alias) { /* - * the expanded_key should be valid UTF-8 at this point, + * the key name should be valid UTF-8 at this point, * but some mouse codes can return ISO chars (for coordinates), * then we will convert them to UTF-8 string */ - if (!utf8_is_valid (expanded_key, -1, NULL)) + if (!utf8_is_valid (key_name, -1, NULL)) + { + key_utf8 = string_iconv_to_internal ("iso-8859-1", key_name); + if (key_utf8) + { + free (key_name); + key_name = key_utf8; + } + else + { + /* conversion failed, then just replace invalid chars by '?' */ + utf8_normalize (key_name, '?'); + } + } + if (!utf8_is_valid (key_name_alias, -1, NULL)) { - expanded_key2 = string_iconv_to_internal ("iso-8859-1", - expanded_key); - if (expanded_key2) + key_utf8 = string_iconv_to_internal ("iso-8859-1", key_name_alias); + if (key_utf8) { - free (expanded_key); - expanded_key = expanded_key2; + free (key_name_alias); + key_name_alias = key_utf8; } else { /* conversion failed, then just replace invalid chars by '?' */ - utf8_normalize (expanded_key, '?'); + utf8_normalize (key_name_alias, '?'); } } /* add expanded key to input buffer */ if (gui_current_window->buffer->input) { - gui_input_insert_string (gui_current_window->buffer, expanded_key); + gui_input_insert_string (gui_current_window->buffer, key_name_alias); if (gui_key_grab_command) { /* add command bound to key (if found) */ ptr_key = gui_key_search (gui_keys[GUI_KEY_CONTEXT_DEFAULT], - gui_key_combo_buffer); + key_name); + if (!ptr_key) + { + ptr_key = gui_key_search (gui_keys[GUI_KEY_CONTEXT_DEFAULT], + key_name_alias); + } if (ptr_key) { gui_input_insert_string (gui_current_window->buffer, " "); @@ -256,7 +280,6 @@ gui_key_grab_end_timer_cb (const void *pointer, void *data, 1, /* save undo */ 1); /* stop completion */ } - free (expanded_key); } /* end grab mode */ @@ -271,6 +294,9 @@ gui_key_grab_end_timer_cb (const void *pointer, void *data, /* * Gets internal code from user key name. * + * Note: this function works with legacy keys (WeeChat < 3.9) and should not + * be used any more. + * * Examples: * "ctrl-R" => "\x01" + "r" (lower case enforced for ctrl keys) * "ctrl-r" => "\x01" + "r" @@ -282,7 +308,7 @@ gui_key_grab_end_timer_cb (const void *pointer, void *data, */ char * -gui_key_get_internal_code (const char *key) +gui_key_legacy_internal_code (const char *key) { char **result, str_key[2]; @@ -362,7 +388,7 @@ gui_key_get_internal_code (const char *key) */ char * -gui_key_expand_legacy (const char *key) +gui_key_legacy_expand (const char *key) { char **result; @@ -891,7 +917,7 @@ gui_key_legacy_to_alias (const char *key) if ((key[0] == '@') && strchr (key, ':')) return strdup (key); - key_raw = gui_key_get_internal_code (key); + key_raw = gui_key_legacy_internal_code (key); if (!key_raw) return NULL; @@ -1141,8 +1167,10 @@ gui_key_set_score (struct t_gui_key *key) int gui_key_is_safe (int context, const char *key) { - char *internal_code; - int rc; + int i; + + if (!key || !key[0]) + return 0; /* "@" is allowed at beginning for cursor/mouse contexts */ if ((key[0] == '@') @@ -1152,14 +1180,18 @@ gui_key_is_safe (int context, const char *key) return 1; } - /* check that first char is a ctrl or meta code */ - internal_code = gui_key_get_internal_code (key); - if (!internal_code) - return 0; - rc = (internal_code[0] == '\x01') ? 1 : 0; - free (internal_code); + for (i = 0; gui_key_safe_list[i]; i++) + { + if (strncmp (key, gui_key_safe_list[i], + strlen (gui_key_safe_list[i])) == 0) + { + /* key is safe */ + return 1; + } + } - return rc; + /* key is not safe */ + return 0; } /* @@ -1176,35 +1208,17 @@ gui_key_new (struct t_gui_buffer *buffer, int context, const char *key, const char *command) { struct t_gui_key *new_key; - char *internal_code, *expanded_name, *key_name; if (!key || !command) return NULL; - internal_code = gui_key_get_internal_code (key); - if (!internal_code) - return NULL; - if (!internal_code[0]) - { - free (internal_code); - return NULL; - } - - expanded_name = gui_key_expand_legacy (internal_code); - if (!expanded_name) - { - free (internal_code); - return NULL; - } - - key_name = gui_key_legacy_to_alias (key); - new_key = malloc (sizeof (*new_key)); if (!new_key) return NULL; - new_key->key = internal_code; - new_key->key_name = key_name; + new_key->key = strdup (key); + new_key->chunks = string_split (key, ",", NULL, 0, 0, + &new_key->chunks_count); new_key->command = strdup (command); gui_key_set_areas (new_key); gui_key_set_score (new_key); @@ -1227,16 +1241,14 @@ gui_key_new (struct t_gui_buffer *buffer, int context, const char *key, _("New key binding (context \"%s\"): " "%s%s => %s%s"), gui_key_context_string[context], - expanded_name, + new_key->key, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), GUI_COLOR(GUI_COLOR_CHAT), new_key->command); } (void) hook_signal_send ("key_bind", - WEECHAT_HOOK_SIGNAL_STRING, expanded_name); - - free (expanded_name); + WEECHAT_HOOK_SIGNAL_STRING, new_key->key); return new_key; } @@ -1266,22 +1278,57 @@ gui_key_search (struct t_gui_key *keys, const char *key) } /* + * Compare chunks with key chunks. + * + * Returns: + * 2: exact match + * 1: partial match (key_chunks starts with chunks but is longer) + * 0: no match + */ + +int +gui_key_compare_chunks (const char **chunks, int chunks_count, + const char **key_chunks, int key_chunks_count) +{ + int i; + + for (i = 0; i < chunks_count; i++) + { + if (i >= key_chunks_count) + return 0; + if (strcmp (chunks[i], key_chunks[i]) != 0) + return 0; + } + + return (chunks_count == key_chunks_count) ? 2 : 1; +} + +/* * Searches for a key (maybe part of string) for context default, search or * cursor (not for mouse). * + * If exact match is found, *exact_match is set to 1, otherwise to 0. + * * Returns pointer to key found, NULL if not found. */ struct t_gui_key * -gui_key_search_part (struct t_gui_buffer *buffer, int context, const char *key) +gui_key_search_part (struct t_gui_buffer *buffer, int context, + const char *key, const char *key_alias, + int *exact_match) { struct t_gui_key *ptr_key; - int length_key; + char **chunks, **chunks_alias; + int rc, chunks_count, chunks_alias_count; - if (!key) + if (!key || !exact_match) return NULL; - length_key = utf8_strlen (key); + *exact_match = 0; + + chunks = string_split (key, ",", NULL, 0, 0, &chunks_count); + chunks_alias = (key_alias) ? + string_split (key_alias, ",", NULL, 0, 0, &chunks_alias_count) : NULL; for (ptr_key = (buffer) ? buffer->keys : gui_keys[context]; ptr_key; ptr_key = ptr_key->next_key) @@ -1290,13 +1337,38 @@ gui_key_search_part (struct t_gui_buffer *buffer, int context, const char *key) && ((context != GUI_KEY_CONTEXT_CURSOR) || (ptr_key->key[0] != '@'))) { - if (string_strncmp (ptr_key->key, key, length_key) == 0) - return ptr_key; + rc = gui_key_compare_chunks ((const char **)chunks, + chunks_count, + (const char **)ptr_key->chunks, + ptr_key->chunks_count); + if (rc > 0) + { + if (rc == 2) + *exact_match = 1; + break; + } + if (chunks_alias) + { + rc = gui_key_compare_chunks ((const char **)chunks_alias, + chunks_alias_count, + (const char **)ptr_key->chunks, + ptr_key->chunks_count); + if (rc > 0) + { + if (rc == 2) + *exact_match = 1; + break; + } + } } } - /* key not found */ - return NULL; + if (chunks) + string_free_split (chunks); + if (chunks_alias) + string_free_split (chunks_alias); + + return ptr_key; } /* @@ -1333,7 +1405,6 @@ gui_key_bind_plugin_hashtable_map_cb (void *data, { int *user_data; struct t_gui_key *ptr_key; - char *internal_code; /* make C compiler happy */ (void) hashtable; @@ -1346,16 +1417,11 @@ gui_key_bind_plugin_hashtable_map_cb (void *data, if (strcmp (key, "__quiet") == 0) return; - internal_code = gui_key_get_internal_code (key); - if (internal_code) + ptr_key = gui_key_search (gui_keys[user_data[0]], key); + if (!ptr_key) { - ptr_key = gui_key_search (gui_keys[user_data[0]], internal_code); - if (!ptr_key) - { - if (gui_key_new (NULL, user_data[0], key, value)) - user_data[1]++; - } - free (internal_code); + if (gui_key_new (NULL, user_data[0], key, value)) + user_data[1]++; } } } @@ -1403,58 +1469,34 @@ int gui_key_unbind (struct t_gui_buffer *buffer, int context, const char *key) { struct t_gui_key *ptr_key; - char *internal_code, *expanded_name; - int rc; - - rc = 0; - internal_code = gui_key_get_internal_code (key); - if (!internal_code) - return 0; - if (!internal_code[0]) - { - free (internal_code); + ptr_key = gui_key_search ((buffer) ? buffer->keys : gui_keys[context], + key); + if (!ptr_key) return 0; - } - expanded_name = gui_key_expand_legacy (internal_code); - if (!expanded_name) + if (buffer) { - free (internal_code); - return 0; + gui_key_free (&buffer->keys, &buffer->last_key, + &buffer->keys_count, ptr_key); } - - ptr_key = gui_key_search ((buffer) ? buffer->keys : gui_keys[context], - internal_code); - if (ptr_key) + else { - if (buffer) + if (gui_key_verbose) { - gui_key_free (&buffer->keys, &buffer->last_key, - &buffer->keys_count, ptr_key); - } - else - { - if (gui_key_verbose) - { - gui_chat_printf (NULL, - _("Key \"%s\" unbound (context: \"%s\")"), - expanded_name, - gui_key_context_string[context]); - } - gui_key_free (&gui_keys[context], &last_gui_key[context], - &gui_keys_count[context], ptr_key); + gui_chat_printf (NULL, + _("Key \"%s\" unbound (context: \"%s\")"), + key, + gui_key_context_string[context]); } - (void) hook_signal_send ("key_unbind", - WEECHAT_HOOK_SIGNAL_STRING, - (char *)expanded_name); - rc = 1; + gui_key_free (&gui_keys[context], &last_gui_key[context], + &gui_keys_count[context], ptr_key); } - free (internal_code); - free (expanded_name); + (void) hook_signal_send ("key_unbind", + WEECHAT_HOOK_SIGNAL_STRING, (char *)key); - return rc; + return 1; } /* @@ -1824,14 +1866,14 @@ int gui_key_pressed (const char *key_str) { int i, insert_into_input, context, length, length_key, signal_sent; - int rc, rc_expand; + int rc, rc_expand, exact_match; struct t_gui_key *ptr_key; char *pos, signal_name[128], **commands; - char *key_name_legacy, *key_name, *key_name_alias; + char *key_name, *key_name_alias; + const char *ptr_key_name2; signal_sent = 0; - key_name_legacy = NULL; key_name = NULL; key_name_alias = NULL; @@ -1894,12 +1936,13 @@ gui_key_pressed (const char *key_str) goto end_no_input; } - key_name_legacy = gui_key_expand_legacy (gui_key_combo_buffer); rc_expand = gui_key_expand (gui_key_combo_buffer, - &key_name, - &key_name_alias); + &key_name, &key_name_alias); ptr_key = NULL; + exact_match = 0; + ptr_key_name2 = (string_strcmp (key_name, key_name_alias) != 0) ? + key_name_alias : NULL; context = gui_key_get_current_context (); switch (context) @@ -1908,28 +1951,29 @@ gui_key_pressed (const char *key_str) /* look for key combo in key table for current buffer */ ptr_key = gui_key_search_part (gui_current_window->buffer, GUI_KEY_CONTEXT_DEFAULT, - gui_key_combo_buffer); + key_name, ptr_key_name2, + &exact_match); /* if key is not found for buffer, then look in general table */ if (!ptr_key) - ptr_key = gui_key_search_part (NULL, - GUI_KEY_CONTEXT_DEFAULT, - gui_key_combo_buffer); + ptr_key = gui_key_search_part (NULL, GUI_KEY_CONTEXT_DEFAULT, + key_name, ptr_key_name2, + &exact_match); break; case GUI_KEY_CONTEXT_SEARCH: - ptr_key = gui_key_search_part (NULL, - GUI_KEY_CONTEXT_SEARCH, - gui_key_combo_buffer); + ptr_key = gui_key_search_part (NULL, GUI_KEY_CONTEXT_SEARCH, + key_name, ptr_key_name2, + &exact_match); if (!ptr_key) { - ptr_key = gui_key_search_part (NULL, - GUI_KEY_CONTEXT_DEFAULT, - gui_key_combo_buffer); + ptr_key = gui_key_search_part (NULL, GUI_KEY_CONTEXT_DEFAULT, + key_name, ptr_key_name2, + &exact_match); } break; case GUI_KEY_CONTEXT_CURSOR: - ptr_key = gui_key_search_part (NULL, - GUI_KEY_CONTEXT_CURSOR, - gui_key_combo_buffer); + ptr_key = gui_key_search_part (NULL, GUI_KEY_CONTEXT_CURSOR, + key_name, ptr_key_name2, + &exact_match); break; } @@ -1940,16 +1984,16 @@ gui_key_pressed (const char *key_str) * (in this case, gui_key_combo_buffer is kept and we'll wait for * the next key) */ - if (strcmp (ptr_key->key, gui_key_combo_buffer) == 0) + if (exact_match) { /* exact combo found => execute command */ if (gui_key_debug) { gui_chat_printf ( NULL, - _("debug: \"%s\" -> %s (legacy: %s) -> %s -> \"%s\""), - gui_key_combo_buffer, key_name, key_name_legacy, - key_name_alias, ptr_key->command); + _("debug: \"%s\" -> %s -> %s -> \"%s\""), + gui_key_combo_buffer, key_name, key_name_alias, + ptr_key->command); gui_key_combo_buffer[0] = '\0'; } else @@ -2019,9 +2063,8 @@ gui_key_pressed (const char *key_str) { gui_chat_printf ( NULL, - _("debug: \"%s\" -> %s (legacy: %s) -> %s (no key) -> %s"), - gui_key_combo_buffer, key_name, key_name_legacy, - key_name_alias, + _("debug: \"%s\" -> %s -> %s (no key) -> %s"), + gui_key_combo_buffer, key_name, key_name_alias, (insert_into_input) ? _("insert into input") : _("ignored")); } gui_key_combo_buffer[0] = '\0'; @@ -2042,8 +2085,6 @@ end_no_input: rc = 0; end: - if (key_name_legacy) - free (key_name_legacy); if (key_name) free (key_name); if (key_name_alias) @@ -2067,8 +2108,8 @@ gui_key_free (struct t_gui_key **keys, struct t_gui_key **last_key, /* free memory */ if (key->key) free (key->key); - if (key->key_name) - free (key->key_name); + if (key->chunks) + string_free_split (key->chunks); for (i = 0; i < 2; i++) { if (key->area_name[i]) @@ -2568,7 +2609,6 @@ int gui_key_add_to_infolist (struct t_infolist *infolist, struct t_gui_key *key) { struct t_infolist_item *ptr_item; - char *expanded_key; if (!infolist || !key) return 0; @@ -2577,18 +2617,8 @@ gui_key_add_to_infolist (struct t_infolist *infolist, struct t_gui_key *key) if (!ptr_item) return 0; - if (!infolist_new_var_string (ptr_item, "key_internal", key->key)) + if (!infolist_new_var_string (ptr_item, "key", key->key)) return 0; - expanded_key = gui_key_expand_legacy (key->key); - if (expanded_key) - { - if (!infolist_new_var_string (ptr_item, "key", expanded_key)) - { - free (expanded_key); - return 0; - } - free (expanded_key); - } if (!infolist_new_var_integer (ptr_item, "area_type1", key->area_type[0])) return 0; if (!infolist_new_var_string (ptr_item, "area_name1", key->area_name[0])) diff --git a/src/gui/gui-key.h b/src/gui/gui-key.h index f49653bbe..8bcac6f64 100644 --- a/src/gui/gui-key.h +++ b/src/gui/gui-key.h @@ -54,8 +54,9 @@ enum t_gui_key_focus struct t_gui_key { - char *key; /* raw key (eg: \001w, \001[[1;3D) */ - char *key_name; /* key name (eg: ctrl-w, meta-left) */ + char *key; /* key name (eg: ctrl-w, meta-left) */ + char **chunks; /* key chunks (split on comma) */ + int chunks_count; /* number of chunks */ int area_type[2]; /* type of areas (for cursor/mouse) */ char *area_name[2]; /* name of areas (for cursor/mouse) */ char *area_key; /* key after area (after ":") */ @@ -90,8 +91,7 @@ extern time_t gui_key_last_activity_time; extern void gui_key_init (); extern int gui_key_search_context (const char *context); extern void gui_key_grab_init (int grab_command, const char *delay); -extern char *gui_key_get_internal_code (const char *key); -extern char *gui_key_expand_legacy (const char *key); +extern char *gui_key_legacy_expand (const char *key); extern int gui_key_expand (const char *key, char **key_name, char **key_name_alias); extern char *gui_key_legacy_to_alias (const char *key); diff --git a/src/plugins/buflist/buflist.c b/src/plugins/buflist/buflist.c index a57c2e5b2..145672102 100644 --- a/src/plugins/buflist/buflist.c +++ b/src/plugins/buflist/buflist.c @@ -424,21 +424,13 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) int i; char str_key[256]; char *default_keys[][2] = { - { /* m-B */ "meta-B", "/buflist toggle" }, - { /* <f1> */ "meta-OP", "/bar scroll buflist * -100%" }, - { /* <f1> */ "meta2-11~", "/bar scroll buflist * -100%" }, - { /* <f2> */ "meta-OQ", "/bar scroll buflist * +100%" }, - { /* <f2> */ "meta2-12~", "/bar scroll buflist * +100%" }, - { /* c-<f1> */ "meta2-11^", "/bar scroll buflist * -100%" }, - { /* c-<f1> */ "meta2-1;5P", "/bar scroll buflist * -100%" }, - { /* c-<f2> */ "meta2-12^", "/bar scroll buflist * +100%" }, - { /* c-<f2> */ "meta2-1;5Q", "/bar scroll buflist * +100%" }, - { /* m-<f1> */ "meta-meta-OP", "/bar scroll buflist * b" }, - { /* m-<f1> */ "meta-meta2-11~", "/bar scroll buflist * b" }, - { /* m-<f1> */ "meta2-1;3P", "/bar scroll buflist * b" }, - { /* m-<f2> */ "meta-meta-OQ", "/bar scroll buflist * e" }, - { /* m-<f2> */ "meta-meta2-12~", "/bar scroll buflist * e" }, - { /* m-<f2> */ "meta2-1;3Q", "/bar scroll buflist * e" }, + { "meta-B", "/buflist toggle" }, + { "f1", "/bar scroll buflist * -100%" }, + { "f2", "/bar scroll buflist * +100%" }, + { "ctrl-f1", "/bar scroll buflist * -100%" }, + { "ctrl-f2", "/bar scroll buflist * +100%" }, + { "meta-f1", "/bar scroll buflist * b" }, + { "meta-f2", "/bar scroll buflist * e" }, { NULL, NULL }, }; diff --git a/src/plugins/fset/fset-buffer.c b/src/plugins/fset/fset-buffer.c index 564e60813..f49bfd317 100644 --- a/src/plugins/fset/fset-buffer.c +++ b/src/plugins/fset/fset-buffer.c @@ -1417,29 +1417,28 @@ void fset_buffer_set_keys () { char *keys[][2] = { - { "meta2-A", "/fset -up" }, - { "meta2-B", "/fset -down" }, - { "meta-meta2-1~", "/fset -go 0" }, - { "meta-meta2-4~", "/fset -go end" }, - { "meta2-23~", "/fset -left" }, - { "meta2-24~", "/fset -right" }, + { "up", "/fset -up" }, + { "down", "/fset -down" }, + { "meta-home", "/fset -go 0" }, + { "meta-end", "/fset -go end" }, + { "f11", "/fset -left" }, + { "f12", "/fset -right" }, { "meta-space", "/fset -toggle" }, { "meta--", "/fset -add -1" }, { "meta-+", "/fset -add 1" }, - { "meta-fmeta-r", "/fset -reset" }, - { "meta-fmeta-u", "/fset -unset" }, - { "meta-ctrl-j", "/fset -set" }, - { "meta-ctrl-m", "/fset -set" }, - { "meta-fmeta-n", "/fset -setnew" }, - { "meta-fmeta-a", "/fset -append" }, - { "meta-,", "/fset -mark" }, - { "meta2-a", "/fset -up; /fset -mark" }, - { "meta2-b", "/fset -mark; /fset -down" }, + { "meta-f,meta-r", "/fset -reset" }, + { "meta-f,meta-u", "/fset -unset" }, + { "meta-return", "/fset -set" }, + { "meta-f,meta-n", "/fset -setnew" }, + { "meta-f,meta-a", "/fset -append" }, + { "meta-comma", "/fset -mark" }, + { "shift-up", "/fset -up; /fset -mark" }, + { "shift-down", "/fset -mark; /fset -down" }, { "ctrl-l", "/fset -refresh" }, { "meta-p", "/mute /set fset.look.show_plugins_desc toggle" }, { "meta-v", "/bar toggle " FSET_BAR_NAME }, { "ctrl-x", "/fset -format" }, - { NULL, NULL }, + { NULL, NULL }, }; char str_key[64]; int i; diff --git a/src/plugins/relay/relay-buffer.c b/src/plugins/relay/relay-buffer.c index fdad19cdd..aa72d80a8 100644 --- a/src/plugins/relay/relay-buffer.c +++ b/src/plugins/relay/relay-buffer.c @@ -257,8 +257,8 @@ relay_buffer_open () weechat_buffer_set (relay_buffer, "type", "free"); weechat_buffer_set (relay_buffer, "title", _("List of clients for relay")); - weechat_buffer_set (relay_buffer, "key_bind_meta2-A", "/relay up"); - weechat_buffer_set (relay_buffer, "key_bind_meta2-B", "/relay down"); + weechat_buffer_set (relay_buffer, "key_bind_up", "/relay up"); + weechat_buffer_set (relay_buffer, "key_bind_down", "/relay down"); weechat_buffer_set (relay_buffer, "localvar_set_type", "relay"); } } diff --git a/src/plugins/script/script-buffer.c b/src/plugins/script/script-buffer.c index 349e49ae4..105a9afce 100644 --- a/src/plugins/script/script-buffer.c +++ b/src/plugins/script/script-buffer.c @@ -1090,21 +1090,23 @@ script_buffer_set_callbacks () void script_buffer_set_keys () { - char *keys[][2] = { { "meta-A", "toggleautoload" }, - { "meta-l", "load" }, - { "meta-u", "unload" }, - { "meta-L", "reload" }, - { "meta-i", "install" }, - { "meta-r", "remove" }, - { "meta-h", "hold" }, - { "meta-v", "show" }, - { "meta-d", "showdiff" }, - { NULL, NULL } }; + char *keys[][2] = { + { "meta-A", "toggleautoload" }, + { "meta-l", "load" }, + { "meta-u", "unload" }, + { "meta-L", "reload" }, + { "meta-i", "install" }, + { "meta-r", "remove" }, + { "meta-h", "hold" }, + { "meta-v", "show" }, + { "meta-d", "showdiff" }, + { NULL, NULL }, + }; char str_key[64], str_command[64]; int i; - weechat_buffer_set (script_buffer, "key_bind_meta2-A", "/script up"); - weechat_buffer_set (script_buffer, "key_bind_meta2-B", "/script down"); + weechat_buffer_set (script_buffer, "key_bind_up", "/script up"); + weechat_buffer_set (script_buffer, "key_bind_down", "/script down"); for (i = 0; keys[i][0]; i++) { if (weechat_config_boolean (script_config_look_use_keys)) diff --git a/src/plugins/xfer/xfer-buffer.c b/src/plugins/xfer/xfer-buffer.c index c4195bb49..4c27b5d9f 100644 --- a/src/plugins/xfer/xfer-buffer.c +++ b/src/plugins/xfer/xfer-buffer.c @@ -358,8 +358,8 @@ xfer_buffer_open () weechat_buffer_set (xfer_buffer, "type", "free"); weechat_buffer_set (xfer_buffer, "title", _("Xfer list")); - weechat_buffer_set (xfer_buffer, "key_bind_meta2-A", "/xfer up"); - weechat_buffer_set (xfer_buffer, "key_bind_meta2-B", "/xfer down"); + weechat_buffer_set (xfer_buffer, "key_bind_up", "/xfer up"); + weechat_buffer_set (xfer_buffer, "key_bind_down", "/xfer down"); weechat_buffer_set (xfer_buffer, "localvar_set_type", "xfer"); } } |