diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-03-17 19:18:30 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-03-17 19:18:30 +0100 |
commit | 64a553f91f78391af148874bf7bca1de512d5db7 (patch) | |
tree | 0c0f5febb675b08e910d7c04bfb29f847e3c91eb /src | |
parent | 3640d187b8ea37dfb433ce75902f68f4d3f7cd75 (diff) | |
download | weechat-64a553f91f78391af148874bf7bca1de512d5db7.zip |
core: change order of modifiers in mouse keys
Now the modifiers for mouse keys are in the same order as other keys: `alt-`
then `ctrl-`.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/curses/gui-curses-mouse.c | 6 | ||||
-rw-r--r-- | src/gui/gui-key.c | 69 |
2 files changed, 60 insertions, 15 deletions
diff --git a/src/gui/curses/gui-curses-mouse.c b/src/gui/curses/gui-curses-mouse.c index 33a2d894b..b3786cd3c 100644 --- a/src/gui/curses/gui-curses-mouse.c +++ b/src/gui/curses/gui-curses-mouse.c @@ -50,11 +50,11 @@ char *gui_mouse_wheel_codes[][2] = { { "`", "wheelup" }, { "p", "ctrl-wheelup" }, { "h", "alt-wheelup" }, - { "x", "ctrl-alt-wheelup" }, + { "x", "alt-ctrl-wheelup" }, { "a", "wheeldown" }, { "q", "ctrl-wheeldown" }, { "i", "alt-wheeldown" }, - { "y", "ctrl-alt-wheeldown" }, + { "y", "alt-ctrl-wheeldown" }, { NULL, NULL } }; char *gui_mouse_button_codes[][2] = @@ -73,7 +73,7 @@ char *gui_mouse_button_codes[][2] = { "(", "alt-button1" }, { "*", "alt-button2" }, { ")", "alt-button3" }, - { "8", "ctrl-alt-button1" }, + { "8", "alt-ctrl-button1" }, { NULL, NULL } }; diff --git a/src/gui/gui-key.c b/src/gui/gui-key.c index 0e974bdbd..c2bbff9ab 100644 --- a/src/gui/gui-key.c +++ b/src/gui/gui-key.c @@ -885,20 +885,65 @@ gui_key_legacy_to_alias (const char *key) } /* + * Attempts to fix a key in mouse context (starting with "@area:"): + * - transform "ctrl-alt-" to "alt-ctrl-" + * + * Example: + * "@chat:ctrl-alt-button1" => "@chat:meta-ctrl-wheelup" + */ + +char * +gui_key_fix_mouse (const char *key) +{ + const char *pos; + char **result; + + if (!key) + return NULL; + + if (key[0] != '@') + return strdup (key); + + pos = strchr (key, ':'); + if (!pos) + return strdup (key); + pos++; + + result = string_dyn_alloc (strlen (key) + 1); + if (!result) + return NULL; + + string_dyn_concat (result, key, pos - key); + + if (strncmp (pos, "ctrl-alt-", 9) == 0) + { + string_dyn_concat (result, "alt-ctrl-", -1); + pos += 9; + } + string_dyn_concat (result, pos, -1); + + return string_dyn_free (result, 0); +} + +/* * Attempts to fix key: - * - transform upper case ctrl keys to lower case + * - transform upper case ctrl keys to lower case ("ctrl-A" -> "ctrl-a") * - replace " " by "space" - * - replace "meta2-" by "meta-[". + * - replace "meta2-" by "meta-[" + * - replace "ctrl-alt-" by "alt-ctrl-" (for mouse). * - * Examples: - * "ctrl-a" => "ctrl-a" (unchanged) - * "meta-A" => "meta-A" (unchanged) - * 'return" => "return" (unchanged) - * "ctrl-G" => "ctrl-g" - * "ctrl-C,b" => "ctrl-c,b" - * " " => "space" - * "meta- " => "meta-space" - * "meta2-A" => "meta-[A" + * Examples of valid keys, unchanged: + * "ctrl-a" + * "meta-A" + * "return" + * + * Examples of keys fixed by this function: + * "ctrl-A" => "ctrl-a" + * "ctrl-C,b" => "ctrl-c,b" + * " " => "space" + * "meta- " => "meta-space" + * "meta2-A" => "meta-[A" + * "@chat:ctrl-alt-button1" => "@chat:alt-ctrl-wheelup" * * Note: result must be freed after use. */ @@ -914,7 +959,7 @@ gui_key_fix (const char *key) return NULL; if ((key[0] == '@') && strchr (key, ':')) - return strdup (key); + return gui_key_fix_mouse (key); result = string_dyn_alloc (strlen (key) + 1); if (!result) |