keychron_qmk_firmware/quantum/process_keycode/process_combo.h
Bob bc536b9b6d 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.
2019-04-08 14:07:15 -07:00

62 lines
1.6 KiB
C

/* Copyright 2016 Jack Humbert
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PROCESS_COMBO_H
#define PROCESS_COMBO_H
#include "progmem.h"
#include "quantum.h"
#include <stdint.h>
#ifdef EXTRA_EXTRA_LONG_COMBOS
#define MAX_COMBO_LENGTH 32
#elif EXTRA_LONG_COMBOS
#define MAX_COMBO_LENGTH 16
#else
#define MAX_COMBO_LENGTH 8
#endif
typedef struct {
const uint16_t *keys;
uint16_t keycode;
#ifdef EXTRA_EXTRA_LONG_COMBOS
uint32_t state;
#elif EXTRA_LONG_COMBOS
uint16_t state;
#else
uint8_t state;
#endif
} combo_t;
#define COMBO(ck, ca) \
{ .keys = &(ck)[0], .keycode = (ca) }
#define COMBO_ACTION(ck) \
{ .keys = &(ck)[0] }
#define COMBO_END 0
#ifndef COMBO_COUNT
#define COMBO_COUNT 0
#endif
#ifndef COMBO_TERM
#define COMBO_TERM TAPPING_TERM
#endif
bool process_combo(uint16_t keycode, keyrecord_t *record);
void matrix_scan_combo(void);
void process_combo_event(uint8_t combo_index, bool pressed);
#endif