diff options
author | Peter Johanson <peter@peterjohanson.com> | 2021-11-29 19:34:40 +0000 |
---|---|---|
committer | Pete Johanson <peter@peterjohanson.com> | 2021-12-02 07:18:25 -0500 |
commit | 6ef1e7034ffaed14378e6194152269ed9ed5bdd1 (patch) | |
tree | 5d3e3394cbe86e72da42daa1636bbed2a2dc0ab1 /app/src/hid.c | |
parent | c4ad3bc5dcfdf01f86b7538b42b7546487a694b0 (diff) |
fix(hid): Implicit mods on non-key page events
* Properly send the KEY usage page report for modifier changes
when there are state changes to other usages pages that
include implicit modifiers.
Diffstat (limited to 'app/src/hid.c')
-rw-r--r-- | app/src/hid.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/app/src/hid.c b/app/src/hid.c index b524b09..d6c63e1 100644 --- a/app/src/hid.c +++ b/app/src/hid.c @@ -26,14 +26,17 @@ static zmk_mod_flags_t explicit_modifiers = 0; LOG_DBG("Modifiers set to 0x%02X", keyboard_report.body.modifiers); \ } +#define GET_MODIFIERS (keyboard_report.body.modifiers) + zmk_mod_flags_t zmk_hid_get_explicit_mods() { return explicit_modifiers; } int zmk_hid_register_mod(zmk_mod_t modifier) { explicit_modifier_counts[modifier]++; LOG_DBG("Modifier %d count %d", modifier, explicit_modifier_counts[modifier]); WRITE_BIT(explicit_modifiers, modifier, true); + zmk_mod_flags_t current = GET_MODIFIERS; SET_MODIFIERS(explicit_modifiers); - return 0; + return current == GET_MODIFIERS ? 0 : 1; } int zmk_hid_unregister_mod(zmk_mod_t modifier) { @@ -47,26 +50,30 @@ int zmk_hid_unregister_mod(zmk_mod_t modifier) { LOG_DBG("Modifier %d released", modifier); WRITE_BIT(explicit_modifiers, modifier, false); } + zmk_mod_flags_t current = GET_MODIFIERS; SET_MODIFIERS(explicit_modifiers); - return 0; + return current == GET_MODIFIERS ? 0 : 1; } int zmk_hid_register_mods(zmk_mod_flags_t modifiers) { + int ret = 0; for (zmk_mod_t i = 0; i < 8; i++) { if (modifiers & (1 << i)) { - zmk_hid_register_mod(i); + ret += zmk_hid_register_mod(i); } } - return 0; + return ret; } int zmk_hid_unregister_mods(zmk_mod_flags_t modifiers) { + int ret = 0; for (zmk_mod_t i = 0; i < 8; i++) { if (modifiers & (1 << i)) { - zmk_hid_unregister_mod(i); + ret += zmk_hid_unregister_mod(i); } } - return 0; + + return ret; } #if IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_NKRO) @@ -130,13 +137,15 @@ static inline int deselect_keyboard_usage(zmk_key_t usage) { } int zmk_hid_implicit_modifiers_press(zmk_mod_flags_t implicit_modifiers) { + zmk_mod_flags_t current = GET_MODIFIERS; SET_MODIFIERS(explicit_modifiers | implicit_modifiers); - return 0; + return current == GET_MODIFIERS ? 0 : 1; } int zmk_hid_implicit_modifiers_release() { + zmk_mod_flags_t current = GET_MODIFIERS; SET_MODIFIERS(explicit_modifiers); - return 0; + return current == GET_MODIFIERS ? 0 : 1; } int zmk_hid_keyboard_press(zmk_key_t code) { |