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