2017-03-28 22:20:36 +00:00
|
|
|
/* 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/>.
|
|
|
|
*/
|
|
|
|
|
2020-12-26 04:53:12 +00:00
|
|
|
#pragma once
|
2016-12-09 22:49:11 +00:00
|
|
|
|
|
|
|
#include "progmem.h"
|
|
|
|
#include "quantum.h"
|
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 21:07:15 +00:00
|
|
|
#include <stdint.h>
|
2016-12-09 22:49:11 +00:00
|
|
|
|
2016-12-16 19:50:28 +00:00
|
|
|
#ifdef EXTRA_EXTRA_LONG_COMBOS
|
2019-08-30 18:19:03 +00:00
|
|
|
# define MAX_COMBO_LENGTH 32
|
2016-12-16 19:50:28 +00:00
|
|
|
#elif EXTRA_LONG_COMBOS
|
2019-08-30 18:19:03 +00:00
|
|
|
# define MAX_COMBO_LENGTH 16
|
2016-12-16 19:50:28 +00:00
|
|
|
#else
|
2019-08-30 18:19:03 +00:00
|
|
|
# define MAX_COMBO_LENGTH 8
|
2016-12-16 19:50:28 +00:00
|
|
|
#endif
|
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 21:07:15 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2019-08-30 18:19:03 +00:00
|
|
|
const uint16_t *keys;
|
|
|
|
uint16_t keycode;
|
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 21:07:15 +00:00
|
|
|
#ifdef EXTRA_EXTRA_LONG_COMBOS
|
2019-08-30 18:19:03 +00:00
|
|
|
uint32_t state;
|
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 21:07:15 +00:00
|
|
|
#elif EXTRA_LONG_COMBOS
|
2019-08-30 18:19:03 +00:00
|
|
|
uint16_t state;
|
2016-12-16 19:50:28 +00:00
|
|
|
#else
|
2019-08-30 18:19:03 +00:00
|
|
|
uint8_t state;
|
2016-12-10 14:11:59 +00:00
|
|
|
#endif
|
2016-12-09 22:49:11 +00:00
|
|
|
} combo_t;
|
|
|
|
|
2019-08-30 18:19:03 +00:00
|
|
|
#define COMBO(ck, ca) \
|
|
|
|
{ .keys = &(ck)[0], .keycode = (ca) }
|
|
|
|
#define COMBO_ACTION(ck) \
|
|
|
|
{ .keys = &(ck)[0] }
|
2016-12-16 19:50:28 +00:00
|
|
|
|
2016-12-09 22:49:11 +00:00
|
|
|
#define COMBO_END 0
|
2016-12-10 14:11:59 +00:00
|
|
|
#ifndef COMBO_COUNT
|
2019-08-30 18:19:03 +00:00
|
|
|
# define COMBO_COUNT 0
|
2016-12-10 14:11:59 +00:00
|
|
|
#endif
|
2016-12-16 19:50:28 +00:00
|
|
|
#ifndef COMBO_TERM
|
2019-08-30 18:19:03 +00:00
|
|
|
# define COMBO_TERM TAPPING_TERM
|
2016-12-16 19:50:28 +00:00
|
|
|
#endif
|
2016-12-09 22:49:11 +00:00
|
|
|
|
|
|
|
bool process_combo(uint16_t keycode, keyrecord_t *record);
|
2016-12-10 14:11:59 +00:00
|
|
|
void matrix_scan_combo(void);
|
2020-07-16 12:39:01 +00:00
|
|
|
void process_combo_event(uint16_t combo_index, bool pressed);
|
2016-12-09 22:49:11 +00:00
|
|
|
|
2019-07-16 08:37:19 +00:00
|
|
|
void combo_enable(void);
|
|
|
|
void combo_disable(void);
|
|
|
|
void combo_toggle(void);
|
|
|
|
bool is_combo_enabled(void);
|