1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

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-`.
This commit is contained in:
Sébastien Helleu
2023-03-17 19:18:30 +01:00
parent 3640d187b8
commit 64a553f91f
3 changed files with 69 additions and 17 deletions
+3 -3
View File
@@ -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 } };
+59 -14
View File
@@ -885,20 +885,65 @@ gui_key_legacy_to_alias (const char *key)
}
/*
* Attempts to fix key:
* - transform upper case ctrl keys to lower case
* - replace " " by "space"
* - replace "meta2-" by "meta-[".
* Attempts to fix a key in mouse context (starting with "@area:"):
* - transform "ctrl-alt-" to "alt-ctrl-"
*
* 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"
* 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 ("ctrl-A" -> "ctrl-a")
* - replace " " by "space"
* - replace "meta2-" by "meta-["
* - replace "ctrl-alt-" by "alt-ctrl-" (for mouse).
*
* 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)
+7
View File
@@ -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"));
}
/*