Ignore-modifiers property for capsword

Squashed commit of the following:

commit ba38925b3e471c5fe92763fe026b22c2c9a7b13d
Author: urob <978080+urob@users.noreply.github.com>
Date:   Fri Aug 5 16:05:58 2022 -0400

    Ignore-modifiers property for capsword
This commit is contained in:
urob 2022-08-05 16:58:59 -04:00
parent 134b64ef5b
commit ad69b57c39
7 changed files with 69 additions and 1 deletions

View file

@ -13,6 +13,7 @@
label = "CAPS_WORD";
#binding-cells = <0>;
continue-list = <UNDERSCORE BACKSPACE DELETE>;
ignore-modifiers;
};
};
};

View file

@ -13,3 +13,5 @@ properties:
required: true
mods:
type: int
ignore-modifiers:
type: boolean

View file

@ -32,6 +32,7 @@ struct caps_word_continue_item {
struct behavior_caps_word_config {
zmk_mod_flags_t mods;
bool ignore_modifiers;
uint8_t index;
uint8_t continuations_count;
struct caps_word_continue_item continuations[];
@ -146,7 +147,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) &&
!is_mod(ev->usage_page, ev->keycode) &&
(!is_mod(ev->usage_page, ev->keycode) || !(config->ignore_modifiers)) &&
!caps_word_is_caps_includelist(config, ev->usage_page, ev->keycode,
ev->implicit_modifiers)) {
LOG_DBG("Deactivating caps_word for 0x%02X - 0x%02X", ev->usage_page, ev->keycode);
@ -178,6 +179,7 @@ static int behavior_caps_word_init(const struct device *dev) {
static struct behavior_caps_word_config behavior_caps_word_config_##n = { \
.index = n, \
.mods = DT_INST_PROP_OR(n, mods, MOD_LSFT), \
.ignore_modifiers = DT_INST_PROP(n, ignore_modifiers), \
.continuations = {LISTIFY(DT_INST_PROP_LEN(n, continue_list), BREAK_ITEM, (, ), n)}, \
.continuations_count = DT_INST_PROP_LEN(n, continue_list), \
}; \

View file

@ -0,0 +1,3 @@
s/.*hid_listener_keycode_//p
s/.*hid_implicit_modifiers_//p
s/.*caps_word_enhance_usage/enhance_usage/p

View file

@ -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 0xE1 implicit_mods 0x00 explicit_mods 0x00
press: 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

View file

@ -0,0 +1,35 @@
#include <dt-bindings/zmk/keys.h>
#include <behaviors.dtsi>
#include <dt-bindings/zmk/kscan_mock.h>
&caps_word {
/delete-property/ ignore-modifiers;
};
/ {
keymap {
compatible = "zmk,keymap";
label = "Default keymap";
default_layer {
bindings = <
&caps_word &kp A
&kp LSHFT &none
>;
};
};
};
&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)
>;
};

View file

@ -37,6 +37,18 @@ By default, the caps word will remain active when any alphanumeric character or
};
```
#### Continue on modifiers
By default, the caps word will remain active when any modifiers are pressed. If you
would like to deactivate caps word when modifiers are pressed, you can delete the
`ignored-modifiers` property in your keymap:
```
&caps_word {
/delete-property/ ignore-modifiers;
};
```
#### Applied Modifier(s)
In addition, if you would like _multiple_ modifiers, instead of just `MOD_LSFT`, you can override the `mods` property: