process_combo.h (2212B)
1 /* Copyright 2016 Jack Humbert 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 2 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16 17 #pragma once 18 19 #include <stdint.h> 20 #include <stdbool.h> 21 #include "action.h" 22 #include "keycodes.h" 23 #include "quantum_keycodes.h" 24 25 #ifdef EXTRA_SHORT_COMBOS 26 # define MAX_COMBO_LENGTH 6 27 #elif defined(EXTRA_EXTRA_LONG_COMBOS) 28 # define MAX_COMBO_LENGTH 32 29 #elif defined(EXTRA_LONG_COMBOS) 30 # define MAX_COMBO_LENGTH 16 31 #else 32 # define MAX_COMBO_LENGTH 8 33 #endif 34 35 #ifndef COMBO_KEY_BUFFER_LENGTH 36 # define COMBO_KEY_BUFFER_LENGTH MAX_COMBO_LENGTH 37 #endif 38 #ifndef COMBO_BUFFER_LENGTH 39 # define COMBO_BUFFER_LENGTH 4 40 #endif 41 42 typedef struct combo_t { 43 const uint16_t *keys; 44 uint16_t keycode; 45 #ifdef EXTRA_SHORT_COMBOS 46 uint8_t state; 47 #else 48 bool disabled; 49 bool active; 50 # if defined(EXTRA_EXTRA_LONG_COMBOS) 51 uint32_t state; 52 # elif defined(EXTRA_LONG_COMBOS) 53 uint16_t state; 54 # else 55 uint8_t state; 56 # endif 57 #endif 58 } combo_t; 59 60 #define COMBO(ck, ca) {.keys = &(ck)[0], .keycode = (ca)} 61 #define COMBO_ACTION(ck) {.keys = &(ck)[0]} 62 63 #define COMBO_END 0 64 #ifndef COMBO_TERM 65 # define COMBO_TERM 50 66 #endif 67 #ifndef COMBO_HOLD_TERM 68 # define COMBO_HOLD_TERM TAPPING_TERM 69 #endif 70 71 /* check if keycode is only modifiers */ 72 #define KEYCODE_IS_MOD(code) (IS_MODIFIER_KEYCODE(code) || (IS_QK_MODS(code) && !QK_MODS_GET_BASIC_KEYCODE(code))) 73 74 bool process_combo(uint16_t keycode, keyrecord_t *record); 75 void combo_task(void); 76 void process_combo_event(uint16_t combo_index, bool pressed); 77 78 void combo_enable(void); 79 void combo_disable(void); 80 void combo_toggle(void); 81 bool is_combo_enabled(void);