Add tap_code function (#3784)
[jackhill/qmk/firmware.git] / tmk_core / common / action.h
CommitLineData
a074364c 1/*
2Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#ifndef ACTION_H
18#define ACTION_H
19
20#include <stdint.h>
21#include <stdbool.h>
22#include "keyboard.h"
23#include "keycode.h"
24#include "action_code.h"
25#include "action_macro.h"
26
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/* tapping count and state */
33typedef struct {
34 bool interrupted :1;
35 bool reserved2 :1;
36 bool reserved1 :1;
37 bool reserved0 :1;
38 uint8_t count :4;
39} tap_t;
40
41/* Key event container for recording */
42typedef struct {
43 keyevent_t event;
44#ifndef NO_ACTION_TAPPING
45 tap_t tap;
46#endif
47} keyrecord_t;
48
49/* Execute action per keyevent */
50void action_exec(keyevent_t event);
51
52/* action for key */
53action_t action_for_key(uint8_t layer, keypos_t key);
54
55/* macro */
56const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt);
57
58/* user defined special function */
59void action_function(keyrecord_t *record, uint8_t id, uint8_t opt);
60
acd64aa8 61/* keyboard-specific key event (pre)processing */
bf5c2cce 62bool process_record_quantum(keyrecord_t *record);
ef21a855 63
a074364c 64/* Utilities for actions. */
74344947 65#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
20dd9c03 66extern bool disable_action_cache;
20dd9c03 67#endif
dd378601
JW
68
69/* Code for handling one-handed key modifiers. */
7230923b 70#ifdef SWAP_HANDS_ENABLE
dd378601
JW
71extern bool swap_hands;
72extern const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS];
73#if (MATRIX_COLS <= 8)
74typedef uint8_t swap_state_row_t;
75#elif (MATRIX_COLS <= 16)
76typedef uint16_t swap_state_row_t;
77#elif (MATRIX_COLS <= 32)
78typedef uint32_t swap_state_row_t;
79#else
80#error "MATRIX_COLS: invalid value"
81#endif
82
83void process_hand_swap(keyevent_t *record);
84#endif
85
bf5c2cce
JH
86void process_record_nocache(keyrecord_t *record);
87void process_record(keyrecord_t *record);
88void process_action(keyrecord_t *record, action_t action);
a074364c 89void register_code(uint8_t code);
90void unregister_code(uint8_t code);
26f4e703 91inline void tap_code(uint8_t code) { register_code(code); unregister_code(code); }
a074364c 92void register_mods(uint8_t mods);
93void unregister_mods(uint8_t mods);
94//void set_mods(uint8_t mods);
95void clear_keyboard(void);
96void clear_keyboard_but_mods(void);
97void layer_switch(uint8_t new_layer);
98bool is_tap_key(keypos_t key);
99
5d771039
JW
100#ifndef NO_ACTION_TAPPING
101void process_record_tap_hint(keyrecord_t *record);
102#endif
103
a074364c 104/* debug */
105void debug_event(keyevent_t event);
106void debug_record(keyrecord_t record);
107void debug_action(action_t action);
108
109#ifdef __cplusplus
110}
111#endif
112
113#endif /* ACTION_H */