diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-02-22 21:35:09 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-03-16 20:42:19 +0100 |
commit | 5b5c9afa290bd444514c446ab6184c2ca55d9d72 (patch) | |
tree | 65f5b3da18d616053f63e2fe7edf3d9a46d2202a | |
parent | 1f5c791c37957d8714fb0e7d6e962531790e259b (diff) | |
download | weechat-5b5c9afa290bd444514c446ab6184c2ca55d9d72.zip |
core: add key alt-K (alt+shift+k) to grab raw key and its command
-rw-r--r-- | src/core/wee-command.c | 31 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-key.c | 1 | ||||
-rw-r--r-- | src/gui/gui-input.c | 5 | ||||
-rw-r--r-- | src/gui/gui-input.h | 4 | ||||
-rw-r--r-- | src/gui/gui-key.c | 27 | ||||
-rw-r--r-- | src/gui/gui-key.h | 3 |
6 files changed, 51 insertions, 20 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 4232384c2..0d54f96a7 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -3462,9 +3462,33 @@ COMMAND_CALLBACK(input) else if (string_strcmp (argv[1], "history_global_next") == 0) gui_input_history_global_next (buffer); else if (string_strcmp (argv[1], "grab_key") == 0) - gui_input_grab_key (buffer, 0, (argc > 2) ? argv[2] : NULL); + { + gui_input_grab_key (buffer, + 0, /* raw_key */ + 0, /* command */ + (argc > 2) ? argv[2] : NULL); + } + else if (string_strcmp (argv[1], "grab_raw_key") == 0) + { + gui_input_grab_key (buffer, + 1, /* raw_key */ + 0, /* command */ + (argc > 2) ? argv[2] : NULL); + } else if (string_strcmp (argv[1], "grab_key_command") == 0) - gui_input_grab_key (buffer, 1, (argc > 2) ? argv[2] : NULL); + { + gui_input_grab_key (buffer, + 0, /* raw_key */ + 1, /* command */ + (argc > 2) ? argv[2] : NULL); + } + else if (string_strcmp (argv[1], "grab_raw_key_command") == 0) + { + gui_input_grab_key (buffer, + 1, /* raw_key */ + 1, /* command */ + (argc > 2) ? argv[2] : NULL); + } else if (string_strcmp (argv[1], "grab_mouse") == 0) gui_input_grab_mouse (buffer, 0); else if (string_strcmp (argv[1], "grab_mouse_area") == 0) @@ -8250,7 +8274,8 @@ command_init () "move_next_char || move_previous_word || move_next_word || " "history_previous || history_next || history_global_previous || " "history_global_next || " - "grab_key || grab_key_command || grab_mouse || grab_mouse_area || " + "grab_key || grab_raw_key || grab_raw_key_command || grab_key_command || " + "grab_mouse || grab_mouse_area || " "insert || send", &command_input, NULL, NULL); hook_command ( diff --git a/src/gui/curses/gui-curses-key.c b/src/gui/curses/gui-curses-key.c index 87b022f5b..6d9a544c1 100644 --- a/src/gui/curses/gui-curses-key.c +++ b/src/gui/curses/gui-curses-key.c @@ -120,6 +120,7 @@ gui_key_default_bindings (int context) BIND("meta-h,meta-r", "/hotlist restore"); BIND("meta-h,meta-R", "/hotlist restore -all"); BIND("meta-k", "/input grab_key_command"); + BIND("meta-K", "/input grab_raw_key_command"); BIND("meta-s", "/mute spell toggle"); BIND("meta-u", "/window scroll_unread"); BIND("ctrl-s,ctrl-u", "/allbuf /buffer set unread"); diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c index b80725c8b..7f364cecb 100644 --- a/src/gui/gui-input.c +++ b/src/gui/gui-input.c @@ -1393,10 +1393,11 @@ gui_input_history_global_next (struct t_gui_buffer *buffer) */ void -gui_input_grab_key (struct t_gui_buffer *buffer, int command, const char *delay) +gui_input_grab_key (struct t_gui_buffer *buffer, int raw_key, int command, + const char *delay) { if (buffer->input) - gui_key_grab_init (command, delay); + gui_key_grab_init (raw_key, command, delay); } /* diff --git a/src/gui/gui-input.h b/src/gui/gui-input.h index 6c867dad0..be93805d5 100644 --- a/src/gui/gui-input.h +++ b/src/gui/gui-input.h @@ -70,8 +70,8 @@ extern void gui_input_history_local_previous (struct t_gui_buffer *buffer); extern void gui_input_history_local_next (struct t_gui_buffer *buffer); extern void gui_input_history_global_previous (struct t_gui_buffer *buffer); extern void gui_input_history_global_next (struct t_gui_buffer *buffer); -extern void gui_input_grab_key (struct t_gui_buffer *buffer, int command, - const char *delay); +extern void gui_input_grab_key (struct t_gui_buffer *buffer, int raw_key, + int command, const char *delay); extern void gui_input_grab_mouse (struct t_gui_buffer *buffer, int area); extern void gui_input_insert (struct t_gui_buffer *buffer, const char *args); extern void gui_input_undo (struct t_gui_buffer *buffer); diff --git a/src/gui/gui-key.c b/src/gui/gui-key.c index ab4515f18..eab368a26 100644 --- a/src/gui/gui-key.c +++ b/src/gui/gui-key.c @@ -83,6 +83,7 @@ int gui_key_verbose = 0; /* 1 to see some messages */ char gui_key_combo_buffer[1024]; /* buffer used for combos */ int gui_key_grab = 0; /* 1 if grab mode enabled (alt-k) */ +int gui_key_grab_raw = 0; /* grab raw key code? */ int gui_key_grab_count = 0; /* number of keys pressed in grab mode */ int gui_key_grab_command = 0; /* grab command bound to key? */ int gui_key_grab_delay = 0; /* delay for grab (default is 500) */ @@ -180,12 +181,13 @@ gui_key_get_current_context () */ void -gui_key_grab_init (int grab_command, const char *delay) +gui_key_grab_init (int grab_raw_key, int grab_command, const char *delay) { long milliseconds; char *error; gui_key_grab = 1; + gui_key_grab_raw = grab_raw_key; gui_key_grab_count = 0; gui_key_grab_command = grab_command; @@ -211,6 +213,7 @@ int gui_key_grab_end_timer_cb (const void *pointer, void *data, int remaining_calls) { char *key_name, *key_name_alias, *key_utf8; + const char *ptr_key_name; struct t_gui_key *ptr_key; int rc; @@ -256,29 +259,29 @@ gui_key_grab_end_timer_cb (const void *pointer, void *data, int remaining_calls) utf8_normalize (key_name_alias, '?'); } } + + ptr_key_name = (gui_key_grab_raw) ? key_name : key_name_alias; + /* add expanded key to input buffer */ if (gui_current_window->buffer->input) { - gui_input_insert_string (gui_current_window->buffer, key_name_alias); + gui_input_insert_string (gui_current_window->buffer, ptr_key_name); if (gui_key_grab_command) { /* add command bound to key (if found) */ ptr_key = gui_key_search (gui_keys[GUI_KEY_CONTEXT_DEFAULT], - key_name); - if (!ptr_key) - { - ptr_key = gui_key_search (gui_keys[GUI_KEY_CONTEXT_DEFAULT], - key_name_alias); - } + ptr_key_name); if (ptr_key) { gui_input_insert_string (gui_current_window->buffer, " "); - gui_input_insert_string (gui_current_window->buffer, ptr_key->command); + gui_input_insert_string (gui_current_window->buffer, + ptr_key->command); } } - gui_input_text_changed_modifier_and_signal (gui_current_window->buffer, - 1, /* save undo */ - 1); /* stop completion */ + gui_input_text_changed_modifier_and_signal ( + gui_current_window->buffer, + 1, /* save undo */ + 1); /* stop completion */ } } diff --git a/src/gui/gui-key.h b/src/gui/gui-key.h index 8bcac6f64..c28658761 100644 --- a/src/gui/gui-key.h +++ b/src/gui/gui-key.h @@ -90,7 +90,8 @@ 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 void gui_key_grab_init (int grab_raw_key, int grab_command, + const char *delay); extern char *gui_key_legacy_expand (const char *key); extern int gui_key_expand (const char *key, char **key_name, char **key_name_alias); |