From 4e30a7d6e5ed0c6bc9e5cefaa754ba32cd55226f Mon Sep 17 00:00:00 2001 From: Raheman Vaiya Date: Thu, 28 Apr 2022 01:24:06 -0400 Subject: [PATCH] Process simple swap arguments as key sequences (#184) --- src/keyboard.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/keyboard.c b/src/keyboard.c index 2389555..6434791 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -519,20 +519,44 @@ static long process_descriptor(struct keyboard *kbd, uint8_t code, if (!cache_get(kbd, kbd->last_layer_code, &od, &odl)) { struct layer *oldlayer = &layers[od.args[0].idx]; + od.args[0].idx = d->args[0].idx; - cache_set(kbd, kbd->last_layer_code, d, odl); - cache_set(kbd, code, NULL, 0); + cache_set(kbd, kbd->last_layer_code, &od, odl); - activate_layer(kbd, kbd->last_layer_code, layer); deactivate_layer(kbd, oldlayer); - update_mods(kbd, layer, 0); + activate_layer(kbd, kbd->last_layer_code, layer); - if (macro) - execute_macro(kbd, layer, macro); + if (macro) { + /* + * If we are dealing with a simple macro of the form - + * keep the corresponding key sequence depressed for the duration + * of the swapping key stroke. This is necessary to account for + * pathological input systems (e.g Gnome) which expect a human-scale + * interval between key down/up events. + */ + if (macro->sz == 1 && + macro->entries[0].type == MACRO_KEYSEQUENCE) { + uint8_t code = macro->entries[0].data; + uint8_t mods = macro->entries[0].data >> 8; + + update_mods(kbd, layer, mods); + send_key(kbd, code, 1); + } else { + execute_macro(kbd, layer, macro); + } + } else { + update_mods(kbd, NULL, 0); + } } } else { - deactivate_layer(kbd, layer); - update_mods(kbd, layer, 0); + if (macro && macro->sz == 1 && + macro->entries[0].type == MACRO_KEYSEQUENCE) { + uint8_t code = macro->entries[0].data; + uint8_t mods = macro->entries[0].data >> 8; + + send_key(kbd, code, 0); + update_mods(kbd, NULL, 0); + } } break;