aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode/process_combo.h
diff options
context:
space:
mode:
authorBob <rsheldiii@gmail.com>2019-04-08 17:07:15 -0400
committerDrashna Jaelre <drashna@live.com>2019-04-08 14:07:15 -0700
commitbc536b9b6d98e5428a28f6e6ba69675bd77b79cc (patch)
tree1a22225476402e824957f77bd801d371a2622ed5 /quantum/process_keycode/process_combo.h
parentf8d365a47847f8e49fde5096aa065dbee08cf728 (diff)
downloadqmk_firmware-bc536b9b6d98e5428a28f6e6ba69675bd77b79cc.tar.gz
qmk_firmware-bc536b9b6d98e5428a28f6e6ba69675bd77b79cc.zip
Switch process_combo to using global register and timer (#2561)
Since combos keep local state about what keys have been previously pressed, when combos are layered, multiple keypresses will register for any key with multiple combos assigned to it. In order to fix this, I switched process_combo to use a global keycode / keyrecord register and timer. When a keypress is consumed by a combo, it gets stored in the register and the timer is updated; when the next keypress takes too long or a key is pressed that isn't part of any combo, the buffer is emitted and the timer reset. This has a few side effects. For instance, I couldn't _not_ fix combo keys printing out of order while also fixing this bug, so combo keys print in order correctly when a combo fails. since combos no longer have local timers, the logic around when combos time out has changed. now that there is a single timer pressing any combo key (including one in a different combo) will reset the timer for all combos, making combo entry a little more lenient. Since combos no longer have local keycode / keyrecord state, there is an edge case where incomplete combo keys can be consumed. if you have a combo for a+s = tab and a combo for b+n = space, if you press a+b+n, only a space will be emitted. This is because when b+n completes successfully, it drops the register.
Diffstat (limited to 'quantum/process_keycode/process_combo.h')
-rw-r--r--quantum/process_keycode/process_combo.h33
1 files changed, 17 insertions, 16 deletions
diff --git a/quantum/process_keycode/process_combo.h b/quantum/process_keycode/process_combo.h
index a5787c9ed..f06d2d345 100644
--- a/quantum/process_keycode/process_combo.h
+++ b/quantum/process_keycode/process_combo.h
@@ -17,33 +17,34 @@
17#ifndef PROCESS_COMBO_H 17#ifndef PROCESS_COMBO_H
18#define PROCESS_COMBO_H 18#define PROCESS_COMBO_H
19 19
20#include <stdint.h>
21#include "progmem.h" 20#include "progmem.h"
22#include "quantum.h" 21#include "quantum.h"
22#include <stdint.h>
23 23
24typedef struct
25{
26 const uint16_t *keys;
27 uint16_t keycode;
28#ifdef EXTRA_EXTRA_LONG_COMBOS 24#ifdef EXTRA_EXTRA_LONG_COMBOS
29 uint32_t state; 25#define MAX_COMBO_LENGTH 32
30#elif EXTRA_LONG_COMBOS 26#elif EXTRA_LONG_COMBOS
31 uint16_t state; 27#define MAX_COMBO_LENGTH 16
32#else 28#else
33 uint8_t state; 29#define MAX_COMBO_LENGTH 8
34#endif 30#endif
35 uint16_t timer; 31
36 bool is_active; 32typedef struct {
37#ifdef COMBO_ALLOW_ACTION_KEYS 33 const uint16_t *keys;
38 keyrecord_t prev_record; 34 uint16_t keycode;
35#ifdef EXTRA_EXTRA_LONG_COMBOS
36 uint32_t state;
37#elif EXTRA_LONG_COMBOS
38 uint16_t state;
39#else 39#else
40 uint16_t prev_key; 40 uint8_t state;
41#endif 41#endif
42} combo_t; 42} combo_t;
43 43
44 44#define COMBO(ck, ca) \
45#define COMBO(ck, ca) {.keys = &(ck)[0], .keycode = (ca)} 45 { .keys = &(ck)[0], .keycode = (ca) }
46#define COMBO_ACTION(ck) {.keys = &(ck)[0]} 46#define COMBO_ACTION(ck) \
47 { .keys = &(ck)[0] }
47 48
48#define COMBO_END 0 49#define COMBO_END 0
49#ifndef COMBO_COUNT 50#ifndef COMBO_COUNT