diff options
-rw-r--r-- | src/gui/curses/gui-curses-mouse.c | 6 | ||||
-rw-r--r-- | src/gui/gui-key.c | 69 | ||||
-rw-r--r-- | tests/unit/gui/test-gui-key.cpp | 7 |
3 files changed, 67 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) diff --git a/tests/unit/gui/test-gui-key.cpp b/tests/unit/gui/test-gui-key.cpp index 800f7c4f0..a0fda8141 100644 --- a/tests/unit/gui/test-gui-key.cpp +++ b/tests/unit/gui/test-gui-key.cpp @@ -866,6 +866,7 @@ TEST(GuiKey, LegacyToAlias) /* * Tests functions: + * gui_key_fix_mouse * gui_key_fix */ @@ -882,6 +883,10 @@ TEST(GuiKey, Fix) WEE_TEST_STR("meta-A", gui_key_fix ("meta-A")); WEE_TEST_STR("ctrl-a", gui_key_fix ("ctrl-a")); WEE_TEST_STR("return", gui_key_fix ("return")); + WEE_TEST_STR("@chat:wheelup", gui_key_fix ("@chat:wheelup")); + WEE_TEST_STR("@chat:alt-wheelup", gui_key_fix ("@chat:alt-wheelup")); + WEE_TEST_STR("@chat:ctrl-wheelup", gui_key_fix ("@chat:ctrl-wheelup")); + WEE_TEST_STR("@chat:alt-ctrl-wheelup", gui_key_fix ("@chat:alt-ctrl-wheelup")); /* changes */ WEE_TEST_STR("ctrl-a", gui_key_fix ("ctrl-A")); @@ -889,6 +894,8 @@ TEST(GuiKey, Fix) WEE_TEST_STR("ctrl-c,ctrl-b,A", gui_key_fix ("ctrl-C,ctrl-B,A")); WEE_TEST_STR("space", gui_key_fix (" ")); WEE_TEST_STR("meta-space", gui_key_fix ("meta- ")); + WEE_TEST_STR("meta-[A", gui_key_fix ("meta2-A")); + WEE_TEST_STR("@chat:alt-ctrl-wheelup", gui_key_fix ("@chat:ctrl-alt-wheelup")); } /* |