From 72ea4107f971d096fd556bdfa70140e65aaf9267 Mon Sep 17 00:00:00 2001 From: Timoyoungster Date: Fri, 14 Jun 2024 02:28:49 +0200 Subject: [PATCH 1/2] fix: adding option to separate implicit mod release from key release This adds a new config value `ZMK_HID_SEPARATE_MOD_RELEASE_REPORT` where, if enabled, the report for a key release is sent separately to the accompanying modifier release signals, which are then sent in a second report. This fixes an issue where certain applications are unable to work with implicitly modified keys (e.g. colon) due to them registering the modifier release prior to the actual key release. Have tested this on my personal keyboard and `wev` now shows the signals in the correct order. => **Previously:** ```LSHIFT (pressed) -> colon (pressed) -> LSHIFT (released) -> **semi**colon (released)``` => **Now:** ```LSHIFT (pressed) -> colon (pressed) -> colon (released) -> LSHIFT (released)``` (This time without accidental files) --- app/Kconfig | 6 ++++++ app/src/hid_listener.c | 13 ++++++++++++- docs/docs/config/system.md | 9 +++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index 5aedd9d9030..3b71020438d 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -113,6 +113,12 @@ config ZMK_HID_INDICATORS Enable HID indicators, used for detecting state of Caps/Scroll/Num Lock, Kata, and Compose. +config ZMK_HID_SEPARATE_MOD_RELEASE_REPORT + bool "Release Modifiers Separately" + help + Send a separate release event for the modifiers, to make sure the release + of the modifier doesn't get recognized before the actual key's release event. + menu "Output Types" config ZMK_USB diff --git a/app/src/hid_listener.c b/app/src/hid_listener.c index 2b8470820a1..2d17a395407 100644 --- a/app/src/hid_listener.c +++ b/app/src/hid_listener.c @@ -66,6 +66,17 @@ static int hid_listener_keycode_released(const struct zmk_keycode_state_changed return err; } +#if IS_ENABLED(CONFIG_ZMK_HID_SEPARATE_MOD_RELEASE_REPORT) + + // send report of normal key release early to fix the issue + // of some programs recognizing the implicit_mod release before the actual key release + err = zmk_endpoints_send_report(ev->usage_page); + if (err < 0) { + LOG_ERR("Failed to send key report for the released keycode (%d)", err); + } + +#endif // IS_ENABLED(CONFIG_ZMK_HID_SEPARATE_MOD_RELEASE_REPORT) + explicit_mods_changed = zmk_hid_unregister_mods(ev->explicit_modifiers); // There is a minor issue with this code. // If LC(A) is pressed, then LS(B), then LC(A) is released, the shift for B will be released @@ -73,7 +84,7 @@ static int hid_listener_keycode_released(const struct zmk_keycode_state_changed // Solving this would require keeping track of which key's implicit modifiers are currently // active and only releasing modifiers at that time. implicit_mods_changed = zmk_hid_implicit_modifiers_release(); - ; + if (ev->usage_page != HID_USAGE_KEY && (explicit_mods_changed > 0 || implicit_mods_changed > 0)) { err = zmk_endpoints_send_report(HID_USAGE_KEY); diff --git a/docs/docs/config/system.md b/docs/docs/config/system.md index 27923453207..cc34219543d 100644 --- a/docs/docs/config/system.md +++ b/docs/docs/config/system.md @@ -29,10 +29,11 @@ Making changes to any of the settings in this section modifies the HID report de ::: -| Config | Type | Description | Default | -| ------------------------------------- | ---- | -------------------------------------------------------------- | ------- | -| `CONFIG_ZMK_HID_INDICATORS` | bool | Enable receipt of HID/LED indicator state from connected hosts | n | -| `CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE` | int | Number of consumer keys simultaneously reportable | 6 | +| Config | Type | Description | Default | +| -------------------------------------------- | ---- | -------------------------------------------------------------- | ------- | +| `CONFIG_ZMK_HID_INDICATORS` | bool | Enable receipt of HID/LED indicator state from connected hosts | n | +| `CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE` | int | Number of consumer keys simultaneously reportable | 6 | +| `CONFIG_ZMK_HID_SEPARATE_MOD_RELEASE_REPORT` | bool | Release the Modifiers separate from and after the modified key | n | Exactly zero or one of the following options may be set to `y`. The first is used if none are set. From 70b907ca1b5f04e77b97c751658d5cff29e44fa9 Mon Sep 17 00:00:00 2001 From: Timoyoungster Date: Fri, 14 Jun 2024 15:23:37 +0200 Subject: [PATCH 2/2] docs: hopefully more clear description of the new setting --- docs/docs/config/system.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/docs/config/system.md b/docs/docs/config/system.md index cc34219543d..5d63ca529f4 100644 --- a/docs/docs/config/system.md +++ b/docs/docs/config/system.md @@ -29,11 +29,11 @@ Making changes to any of the settings in this section modifies the HID report de ::: -| Config | Type | Description | Default | -| -------------------------------------------- | ---- | -------------------------------------------------------------- | ------- | -| `CONFIG_ZMK_HID_INDICATORS` | bool | Enable receipt of HID/LED indicator state from connected hosts | n | -| `CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE` | int | Number of consumer keys simultaneously reportable | 6 | -| `CONFIG_ZMK_HID_SEPARATE_MOD_RELEASE_REPORT` | bool | Release the Modifiers separate from and after the modified key | n | +| Config | Type | Description | Default | +| -------------------------------------------- | ---- | ---------------------------------------------------------------- | ------- | +| `CONFIG_ZMK_HID_INDICATORS` | bool | Enable receipt of HID/LED indicator state from connected hosts | n | +| `CONFIG_ZMK_HID_CONSUMER_REPORT_SIZE` | int | Number of consumer keys simultaneously reportable | 6 | +| `CONFIG_ZMK_HID_SEPARATE_MOD_RELEASE_REPORT` | bool | Send modifier release event **after** non-modifier release event | n | Exactly zero or one of the following options may be set to `y`. The first is used if none are set.