Browse Source

feature(sticky_keys): add quick-release

when quick-release is enabled, the sticky key is released immediately after another key is pressed
xmkb
Okke Formsma 4 years ago committed by Pete Johanson
parent
commit
c925cf02dd
  1. 1
      app/dts/behaviors/sticky_key.dtsi
  2. 2
      app/dts/bindings/behaviors/zmk,behavior-sticky-key.yaml
  3. 6
      app/src/behaviors/behavior_sticky_key.c
  4. 1
      app/tests/sticky-keys/2-sl-dn-up-kcdn-kcup/events.patterns
  5. 8
      app/tests/sticky-keys/2-sl-dn-up-kcdn-kcup/keycode_events.snapshot
  6. 52
      app/tests/sticky-keys/2-sl-dn-up-kcdn-kcup/native_posix.keymap
  7. 2
      app/tests/sticky-keys/8-lsk-osk-combination/events.patterns
  8. 8
      app/tests/sticky-keys/8-lsk-osk-combination/keycode_events.snapshot
  9. 4
      app/tests/sticky-keys/8-lsk-osk-combination/native_posix.keymap

1
app/dts/behaviors/sticky_key.dtsi

@ -19,6 +19,7 @@
#binding-cells = <1>; #binding-cells = <1>;
release-after-ms = <1000>; release-after-ms = <1000>;
bindings = <&mo>; bindings = <&mo>;
quick-release;
}; };
}; };

2
app/dts/bindings/behaviors/zmk,behavior-sticky-key.yaml

@ -13,3 +13,5 @@ properties:
required: true required: true
release-after-ms: release-after-ms:
type: int type: int
quick-release:
type: boolean

6
app/src/behaviors/behavior_sticky_key.c

@ -29,6 +29,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
struct behavior_sticky_key_config { struct behavior_sticky_key_config {
uint32_t release_after_ms; uint32_t release_after_ms;
bool quick_release;
struct zmk_behavior_binding behavior; struct zmk_behavior_binding behavior;
}; };
@ -209,10 +210,12 @@ static int sticky_key_keycode_state_changed_listener(const zmk_event_t *eh) {
} }
if (sticky_key->timer_started) { if (sticky_key->timer_started) {
stop_timer(sticky_key); stop_timer(sticky_key);
if (sticky_key->config->quick_release) {
release_sticky_key_behavior(sticky_key, ev->timestamp);
}
} }
sticky_key->modified_key_usage_page = ev->usage_page; sticky_key->modified_key_usage_page = ev->usage_page;
sticky_key->modified_key_keycode = ev->keycode; sticky_key->modified_key_keycode = ev->keycode;
} else { // key up } else { // key up
if (sticky_key->timer_started && if (sticky_key->timer_started &&
sticky_key->modified_key_usage_page == ev->usage_page && sticky_key->modified_key_usage_page == ev->usage_page &&
@ -269,6 +272,7 @@ static struct behavior_sticky_key_data behavior_sticky_key_data;
#define KP_INST(n) \ #define KP_INST(n) \
static struct behavior_sticky_key_config behavior_sticky_key_config_##n = { \ static struct behavior_sticky_key_config behavior_sticky_key_config_##n = { \
.behavior = _TRANSFORM_ENTRY(0, n).release_after_ms = DT_INST_PROP(n, release_after_ms), \ .behavior = _TRANSFORM_ENTRY(0, n).release_after_ms = DT_INST_PROP(n, release_after_ms), \
.quick_release = DT_INST_PROP(n, quick_release), \
}; \ }; \
DEVICE_AND_API_INIT(behavior_sticky_key_##n, DT_INST_LABEL(n), behavior_sticky_key_init, \ DEVICE_AND_API_INIT(behavior_sticky_key_##n, DT_INST_LABEL(n), behavior_sticky_key_init, \
&behavior_sticky_key_data, &behavior_sticky_key_config_##n, APPLICATION, \ &behavior_sticky_key_data, &behavior_sticky_key_config_##n, APPLICATION, \

1
app/tests/sticky-keys/2-sl-dn-up-kcdn-kcup/events.patterns

@ -0,0 +1 @@
s/.*hid_listener_keycode_//p

8
app/tests/sticky-keys/2-sl-dn-up-kcdn-kcup/keycode_events.snapshot

@ -0,0 +1,8 @@
pressed: usage_page 0x07 keycode 0x1b implicit_mods 0x00 explicit_mods 0x00
pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
released: usage_page 0x07 keycode 0x1b implicit_mods 0x00 explicit_mods 0x00
released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
pressed: usage_page 0x07 keycode 0x1b implicit_mods 0x00 explicit_mods 0x00
pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
released: usage_page 0x07 keycode 0x1b implicit_mods 0x00 explicit_mods 0x00
released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00

52
app/tests/sticky-keys/2-sl-dn-up-kcdn-kcup/native_posix.keymap

@ -0,0 +1,52 @@
#include <dt-bindings/zmk/keys.h>
#include <behaviors.dtsi>
#include <dt-bindings/zmk/kscan-mock.h>
/*
sticky layers should quick-release.
Thus, the second keypress should be on the default layer, not on the lower_layer.
*/
/ {
keymap {
compatible = "zmk,keymap";
label ="Default keymap";
default_layer {
bindings = <
&sk E &sl 1
&kp A &kp B>;
};
lower_layer {
bindings = <
&sk LEFT_CONTROL &kp X
&kp Y &kp Z>;
};
};
};
&kscan {
events = <
/* press sl 1 */
ZMK_MOCK_PRESS(0,1,10)
ZMK_MOCK_RELEASE(0,1,10)
/* press X */
ZMK_MOCK_PRESS(0,1,10)
/* press A */
ZMK_MOCK_PRESS(1,0,10)
ZMK_MOCK_RELEASE(0,1,10)
ZMK_MOCK_RELEASE(1,0,10)
/* repeat test to check if cleanup is done correctly */
/* press sl 1 */
ZMK_MOCK_PRESS(0,1,10)
ZMK_MOCK_RELEASE(0,1,10)
/* press X */
ZMK_MOCK_PRESS(0,1,10)
/* press Y */
ZMK_MOCK_PRESS(1,0,10)
ZMK_MOCK_RELEASE(0,1,10)
ZMK_MOCK_RELEASE(1,0,10)
>;
};

2
app/tests/sticky-keys/8-lsk-osk-combination/events.patterns

@ -1 +1 @@
s/.*hid_listener_keycode_//p s/.*hid_listener_keycode_//p

8
app/tests/sticky-keys/8-lsk-osk-combination/keycode_events.snapshot

@ -1,8 +1,8 @@
pressed: usage_page 0x07 keycode 0xe0 implicit_mods 0x00 explicit_mods 0x00 pressed: usage_page 0x07 keycode 0xe0 implicit_mods 0x00 explicit_mods 0x00
pressed: usage_page 0x07 keycode 0x1c implicit_mods 0x00 explicit_mods 0x00 pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
released: usage_page 0x07 keycode 0xe0 implicit_mods 0x00 explicit_mods 0x00 released: usage_page 0x07 keycode 0xe0 implicit_mods 0x00 explicit_mods 0x00
released: usage_page 0x07 keycode 0x1c implicit_mods 0x00 explicit_mods 0x00 released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
pressed: usage_page 0x07 keycode 0xe0 implicit_mods 0x00 explicit_mods 0x00 pressed: usage_page 0x07 keycode 0xe0 implicit_mods 0x00 explicit_mods 0x00
pressed: usage_page 0x07 keycode 0x1c implicit_mods 0x00 explicit_mods 0x00 pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
released: usage_page 0x07 keycode 0xe0 implicit_mods 0x00 explicit_mods 0x00 released: usage_page 0x07 keycode 0xe0 implicit_mods 0x00 explicit_mods 0x00
released: usage_page 0x07 keycode 0x1c implicit_mods 0x00 explicit_mods 0x00 released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00

4
app/tests/sticky-keys/8-lsk-osk-combination/native_posix.keymap

@ -29,7 +29,7 @@
/* tap sk LEFT_CONTROL */ /* tap sk LEFT_CONTROL */
ZMK_MOCK_PRESS(0,0,10) ZMK_MOCK_PRESS(0,0,10)
ZMK_MOCK_RELEASE(0,0,10) ZMK_MOCK_RELEASE(0,0,10)
/* tap Y */ /* tap A */
ZMK_MOCK_PRESS(1,0,10) ZMK_MOCK_PRESS(1,0,10)
ZMK_MOCK_RELEASE(1,0,10) ZMK_MOCK_RELEASE(1,0,10)
@ -40,7 +40,7 @@
/* tap sk */ /* tap sk */
ZMK_MOCK_PRESS(0,0,10) ZMK_MOCK_PRESS(0,0,10)
ZMK_MOCK_RELEASE(0,0,10) ZMK_MOCK_RELEASE(0,0,10)
/* tap Y */ /* tap A */
ZMK_MOCK_PRESS(1,0,10) ZMK_MOCK_PRESS(1,0,10)
ZMK_MOCK_RELEASE(1,0,10) ZMK_MOCK_RELEASE(1,0,10)
>; >;

Loading…
Cancel
Save