forked from mirrors/qmk_firmware
a7b2f4233c
* Add macros to extract parameters from keycode values Implement both encoding and decoding for keycodes like TO(layer) or LM(layer, mod) in one place, so that the decoding won't get out of sync with the encoding. While at it, fix some macros for creating keycode values that did not apply the appropriate masks to parameters (and therefore could allow the result to be out of range if a wrong parameter was passed). * keymap_common: Use extraction macros for keycodes * pointing_device_auto_mouse: Use extraction macros for keycodes Fixes #18970. * process_autocorrect: Use extraction macros for keycodes * process_caps_word: Use extraction macros for keycodes (Also fix a minor bug - SH_TG was not handled properly) * process_leader: Use extraction macros for keycodes (Technically the code is not 100% correct, because it always assumes that the LT() or MT() action was a tap, but it's a separate issue that already existed before the keycode changes.) * process_unicode: Use extraction macros for keycodes * process_unicodemap: Use extraction macros for keycodes
85 lines
2.5 KiB
C
85 lines
2.5 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/>.
|
|
*/
|
|
|
|
#ifdef LEADER_ENABLE
|
|
|
|
# include "process_leader.h"
|
|
# include <string.h>
|
|
|
|
# ifndef LEADER_TIMEOUT
|
|
# define LEADER_TIMEOUT 300
|
|
# endif
|
|
|
|
__attribute__((weak)) void leader_start(void) {}
|
|
|
|
__attribute__((weak)) void leader_end(void) {}
|
|
|
|
// Leader key stuff
|
|
bool leading = false;
|
|
uint16_t leader_time = 0;
|
|
|
|
uint16_t leader_sequence[5] = {0, 0, 0, 0, 0};
|
|
uint8_t leader_sequence_size = 0;
|
|
|
|
void qk_leader_start(void) {
|
|
if (leading) {
|
|
return;
|
|
}
|
|
leader_start();
|
|
leading = true;
|
|
leader_time = timer_read();
|
|
leader_sequence_size = 0;
|
|
memset(leader_sequence, 0, sizeof(leader_sequence));
|
|
}
|
|
|
|
bool process_leader(uint16_t keycode, keyrecord_t *record) {
|
|
// Leader key set-up
|
|
if (record->event.pressed) {
|
|
if (leading) {
|
|
# ifndef LEADER_NO_TIMEOUT
|
|
if (timer_elapsed(leader_time) < LEADER_TIMEOUT)
|
|
# endif // LEADER_NO_TIMEOUT
|
|
{
|
|
# ifndef LEADER_KEY_STRICT_KEY_PROCESSING
|
|
if (IS_QK_MOD_TAP(keycode)) {
|
|
keycode = QK_MOD_TAP_GET_TAP_KEYCODE(keycode);
|
|
} else if (IS_QK_LAYER_TAP(keycode)) {
|
|
keycode = QK_LAYER_TAP_GET_TAP_KEYCODE(keycode);
|
|
}
|
|
# endif // LEADER_KEY_STRICT_KEY_PROCESSING
|
|
if (leader_sequence_size < ARRAY_SIZE(leader_sequence)) {
|
|
leader_sequence[leader_sequence_size] = keycode;
|
|
leader_sequence_size++;
|
|
} else {
|
|
leading = false;
|
|
leader_end();
|
|
return true;
|
|
}
|
|
# ifdef LEADER_PER_KEY_TIMING
|
|
leader_time = timer_read();
|
|
# endif
|
|
return false;
|
|
}
|
|
} else {
|
|
if (keycode == QK_LEADER) {
|
|
qk_leader_start();
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
#endif
|