From e1db2a845250622650e90e1395384251e42dfaa0 Mon Sep 17 00:00:00 2001 From: Matthew Todd Date: Sun, 22 Dec 2024 12:30:58 -0500 Subject: [PATCH] fix(behaviors): Deactivate caps_word after modified numerics Fixes #2723. The caps_word behavior now strictly honors `[A-Za-z0-9_]` as the default continuation characters. (Previously `!@#$%^&*()` were mistakenly also honored.) I discovered this by trying to use caps_word for comment markers like `FIXME(mt):` and finding that the opening left parenthesis didn't deactivate caps_word. --- app/src/behaviors/behavior_caps_word.c | 7 ++-- .../events.patterns | 3 ++ .../keycode_events.snapshot | 17 ++++++++++ .../native_posix_64.keymap | 32 +++++++++++++++++++ .../events.patterns | 3 ++ .../keycode_events.snapshot | 13 ++++++++ .../native_posix_64.keymap | 30 +++++++++++++++++ 7 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 app/tests/caps-word/deactivate-by-numeric-with-modifiers-explicit/events.patterns create mode 100644 app/tests/caps-word/deactivate-by-numeric-with-modifiers-explicit/keycode_events.snapshot create mode 100644 app/tests/caps-word/deactivate-by-numeric-with-modifiers-explicit/native_posix_64.keymap create mode 100644 app/tests/caps-word/deactivate-by-numeric-with-modifiers-implicit/events.patterns create mode 100644 app/tests/caps-word/deactivate-by-numeric-with-modifiers-implicit/keycode_events.snapshot create mode 100644 app/tests/caps-word/deactivate-by-numeric-with-modifiers-implicit/native_posix_64.keymap diff --git a/app/src/behaviors/behavior_caps_word.c b/app/src/behaviors/behavior_caps_word.c index c3255f12c15..362924fe45c 100644 --- a/app/src/behaviors/behavior_caps_word.c +++ b/app/src/behaviors/behavior_caps_word.c @@ -112,9 +112,10 @@ static bool caps_word_is_alpha(uint8_t usage_id) { return (usage_id >= HID_USAGE_KEY_KEYBOARD_A && usage_id <= HID_USAGE_KEY_KEYBOARD_Z); } -static bool caps_word_is_numeric(uint8_t usage_id) { +static bool caps_word_is_numeric(uint8_t usage_id, uint8_t implicit_modifiers) { return (usage_id >= HID_USAGE_KEY_KEYBOARD_1_AND_EXCLAMATION && - usage_id <= HID_USAGE_KEY_KEYBOARD_0_AND_RIGHT_PARENTHESIS); + usage_id <= HID_USAGE_KEY_KEYBOARD_0_AND_RIGHT_PARENTHESIS && + (implicit_modifiers | zmk_hid_get_explicit_mods()) == 0); } static void caps_word_enhance_usage(const struct behavior_caps_word_config *config, @@ -148,7 +149,7 @@ static int caps_word_keycode_state_changed_listener(const zmk_event_t *eh) { caps_word_enhance_usage(config, ev); - if (!caps_word_is_alpha(ev->keycode) && !caps_word_is_numeric(ev->keycode) && + if (!caps_word_is_alpha(ev->keycode) && !caps_word_is_numeric(ev->keycode, ev->implicit_modifiers) && !is_mod(ev->usage_page, ev->keycode) && !caps_word_is_caps_includelist(config, ev->usage_page, ev->keycode, ev->implicit_modifiers)) { diff --git a/app/tests/caps-word/deactivate-by-numeric-with-modifiers-explicit/events.patterns b/app/tests/caps-word/deactivate-by-numeric-with-modifiers-explicit/events.patterns new file mode 100644 index 00000000000..fa75ab0c7df --- /dev/null +++ b/app/tests/caps-word/deactivate-by-numeric-with-modifiers-explicit/events.patterns @@ -0,0 +1,3 @@ +s/.*hid_listener_keycode_//p +s/.*hid_implicit_modifiers_//p +s/.*caps_word_enhance_usage/enhance_usage/p \ No newline at end of file diff --git a/app/tests/caps-word/deactivate-by-numeric-with-modifiers-explicit/keycode_events.snapshot b/app/tests/caps-word/deactivate-by-numeric-with-modifiers-explicit/keycode_events.snapshot new file mode 100644 index 00000000000..13ed8ee39f9 --- /dev/null +++ b/app/tests/caps-word/deactivate-by-numeric-with-modifiers-explicit/keycode_events.snapshot @@ -0,0 +1,17 @@ +enhance_usage: Enhancing usage 0x04 with modifiers: 0x02 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x02 explicit_mods 0x00 +press: Modifiers set to 0x02 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x00 +pressed: usage_page 0x07 keycode 0xE1 implicit_mods 0x00 explicit_mods 0x00 +press: Modifiers set to 0x02 +pressed: usage_page 0x07 keycode 0x26 implicit_mods 0x00 explicit_mods 0x00 +press: Modifiers set to 0x02 +released: usage_page 0x07 keycode 0x26 implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x02 +released: usage_page 0x07 keycode 0xE1 implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x00 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +press: Modifiers set to 0x00 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x00 diff --git a/app/tests/caps-word/deactivate-by-numeric-with-modifiers-explicit/native_posix_64.keymap b/app/tests/caps-word/deactivate-by-numeric-with-modifiers-explicit/native_posix_64.keymap new file mode 100644 index 00000000000..c03261e4a17 --- /dev/null +++ b/app/tests/caps-word/deactivate-by-numeric-with-modifiers-explicit/native_posix_64.keymap @@ -0,0 +1,32 @@ +#include +#include +#include +#include "../behavior_keymap.dtsi" + +/ { + keymap { + compatible = "zmk,keymap"; + + default_layer { + bindings = < + &caps_word &kp A + &kp LSHFT &kp N9 + >; + }; + }; +}; + +&kscan { + events = < + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,1,10) + ZMK_MOCK_PRESS(1,0,10) + ZMK_MOCK_PRESS(1,1,10) + ZMK_MOCK_RELEASE(1,1,10) + ZMK_MOCK_RELEASE(1,0,10) + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,1,10) + >; +}; diff --git a/app/tests/caps-word/deactivate-by-numeric-with-modifiers-implicit/events.patterns b/app/tests/caps-word/deactivate-by-numeric-with-modifiers-implicit/events.patterns new file mode 100644 index 00000000000..fa75ab0c7df --- /dev/null +++ b/app/tests/caps-word/deactivate-by-numeric-with-modifiers-implicit/events.patterns @@ -0,0 +1,3 @@ +s/.*hid_listener_keycode_//p +s/.*hid_implicit_modifiers_//p +s/.*caps_word_enhance_usage/enhance_usage/p \ No newline at end of file diff --git a/app/tests/caps-word/deactivate-by-numeric-with-modifiers-implicit/keycode_events.snapshot b/app/tests/caps-word/deactivate-by-numeric-with-modifiers-implicit/keycode_events.snapshot new file mode 100644 index 00000000000..7fdb4c30d9a --- /dev/null +++ b/app/tests/caps-word/deactivate-by-numeric-with-modifiers-implicit/keycode_events.snapshot @@ -0,0 +1,13 @@ +enhance_usage: Enhancing usage 0x04 with modifiers: 0x02 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x02 explicit_mods 0x00 +press: Modifiers set to 0x02 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x00 +pressed: usage_page 0x07 keycode 0x26 implicit_mods 0x02 explicit_mods 0x00 +press: Modifiers set to 0x02 +released: usage_page 0x07 keycode 0x26 implicit_mods 0x02 explicit_mods 0x00 +release: Modifiers set to 0x00 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +press: Modifiers set to 0x00 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +release: Modifiers set to 0x00 diff --git a/app/tests/caps-word/deactivate-by-numeric-with-modifiers-implicit/native_posix_64.keymap b/app/tests/caps-word/deactivate-by-numeric-with-modifiers-implicit/native_posix_64.keymap new file mode 100644 index 00000000000..15df41ee09b --- /dev/null +++ b/app/tests/caps-word/deactivate-by-numeric-with-modifiers-implicit/native_posix_64.keymap @@ -0,0 +1,30 @@ +#include +#include +#include +#include "../behavior_keymap.dtsi" + +/ { + keymap { + compatible = "zmk,keymap"; + + default_layer { + bindings = < + &caps_word &kp A + &kp LPAR + >; + }; + }; +}; + +&kscan { + events = < + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,1,10) + ZMK_MOCK_PRESS(1,0,10) + ZMK_MOCK_RELEASE(1,0,10) + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,1,10) + >; +};