Skip to content

Commit

Permalink
fix(behaviors): Deactivate caps_word after modified numerics
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matthewtodd committed Dec 22, 2024
1 parent 3f6841c commit e1db2a8
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/src/behaviors/behavior_caps_word.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
s/.*hid_listener_keycode_//p
s/.*hid_implicit_modifiers_//p
s/.*caps_word_enhance_usage/enhance_usage/p
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <dt-bindings/zmk/keys.h>
#include <behaviors.dtsi>
#include <dt-bindings/zmk/kscan_mock.h>
#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)
>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
s/.*hid_listener_keycode_//p
s/.*hid_implicit_modifiers_//p
s/.*caps_word_enhance_usage/enhance_usage/p
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <dt-bindings/zmk/keys.h>
#include <behaviors.dtsi>
#include <dt-bindings/zmk/kscan_mock.h>
#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)
>;
};

0 comments on commit e1db2a8

Please sign in to comment.